Browse Source

Merge remote-tracking branch 'origin/master'

ifengouy 2 years ago
parent
commit
44a010b779

+ 6 - 0
app/src/main/java/com/sunwin/visitorapp/BaseApplication.java

@@ -3,10 +3,14 @@ package com.sunwin.visitorapp;
 import android.app.Application;
 import android.content.Context;
 
+import com.sunwin.visitorapp.db.DatabaseManager;
+import com.sunwin.visitorapp.db.UserManagerModel;
 import com.sunwin.visitorapp.utils.CacheUtil;
 import com.sunwin.visitorapp.utils.SystemTTS;
 import com.sunwin.visitorapp.utils.UniversalImageLoaderConfiguration;
 
+import java.util.List;
+
 import timber.log.Timber;
 
 
@@ -31,6 +35,8 @@ public class BaseApplication extends Application {
         Timber.plant(new Timber.DebugTree());
 
         CacheUtil.init(this);
+
+        UserManagerModel.EmptyInit();
 //        OrmDBHelper.init(this);
 //        PresentationManager.checkAndShow(this);
     }

+ 27 - 3
app/src/main/java/com/sunwin/visitorapp/LoginActivity.java

@@ -1,5 +1,6 @@
 package com.sunwin.visitorapp;
 
+import android.annotation.SuppressLint;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
@@ -8,8 +9,16 @@ import android.widget.EditText;
 
 import com.sunwin.visitorapp.activity.HomeAc;
 import com.sunwin.visitorapp.activity.VisitorRegActivity;
+import com.sunwin.visitorapp.db.DatabaseManager;
+import com.sunwin.visitorapp.db.LogModel;
+import com.sunwin.visitorapp.db.UserManagerModel;
+import com.sunwin.visitorapp.manage.RunDataManage;
+import com.sunwin.visitorapp.model.UserModel;
 import com.sunwin.visitorapp.utils.Constant;
 import com.sunwin.visitorapp.utils.SharePrefenceUtils;
+import com.sunwin.visitorapp.utils.ToastUtils;
+
+import java.util.List;
 
 public class LoginActivity extends BaseActivity implements View.OnClickListener {
     private EditText mEtUserName;
@@ -35,6 +44,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
 
     }
 
+    @SuppressLint("NonConstantResourceId")
     @Override
     public void onClick(View view) {
         switch (view.getId()) {
@@ -44,10 +54,24 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener
                 startActivity(intent);
                 break;
             case R.id.btn_login:
-                SharePrefenceUtils.putBoolean(Constant.ISharePrefence.LOGINTAG, true);
-                Intent intent2 = new Intent(this, HomeAc.class);
-                startActivity(intent2);
+                login();
                 break;
         }
     }
+
+    public void login(){
+        String account = mEtUserName.getText().toString().trim();
+        String password = mEtPwd.getText().toString().trim();
+        List<UserManagerModel> list = DatabaseManager.getInstance().getQueryByWhere(UserManagerModel.class,UserManagerModel.Key_account,account,UserManagerModel.Key_password,password);
+
+        if(!list.isEmpty()){
+            RunDataManage.SetLoginUser(list.get(0));
+            LogModel.AddLog(LogModel.Type.UserLoginIn);
+            SharePrefenceUtils.putBoolean(Constant.ISharePrefence.LOGINTAG, true);
+            Intent intent2 = new Intent(this, HomeAc.class);
+            startActivity(intent2);
+        }else{
+            ToastUtils.showToast("用户名或密码错误");
+        }
+    }
 }

+ 0 - 1
app/src/main/java/com/sunwin/visitorapp/SplashActivity.java

@@ -58,7 +58,6 @@ public class SplashActivity extends AppCompatActivity {
         authApi = new AuthApi();
         initData();
         myHandler.sendEmptyMessageDelayed(0, 500);
-
         PullDataService.enqueueWork(this, new Intent());
     }
 

+ 25 - 0
app/src/main/java/com/sunwin/visitorapp/activity/HomeAc.java

@@ -16,9 +16,11 @@ import androidx.fragment.app.FragmentTransaction;
 import com.sunwin.visitorapp.BaseActivity;
 import com.sunwin.visitorapp.LoginActivity;
 import com.sunwin.visitorapp.R;
+import com.sunwin.visitorapp.db.LogModel;
 import com.sunwin.visitorapp.fragment.HomeFr;
 import com.sunwin.visitorapp.fragment.RegTypeFragment;
 import com.sunwin.visitorapp.fragment.VisitSignFragment;
+import com.sunwin.visitorapp.manage.RunDataManage;
 import com.sunwin.visitorapp.utils.Constant;
 import com.sunwin.visitorapp.utils.NetUtils;
 import com.sunwin.visitorapp.utils.PopupWindowHelper;
@@ -77,14 +79,27 @@ public class HomeAc extends BaseActivity implements View.OnClickListener, RegTyp
         Intent intent = null;
         switch (view.getId()) {
             case R.id.MenuItemRecord://记录
+
+                if(!RunDataManage.CanVisitorRecord()) {
+                    ToastUtils.showToast(R.string.no_permission);
+                    return;
+                }
                 startActivity(new Intent(mContext, VisitLogActivity.class));
                 break;
             case R.id.MenuItemSign://签到
+                if(!RunDataManage.CanVisitorSignIn()) {
+                    ToastUtils.showToast(R.string.no_permission);
+                    return;
+                }
                 showHome(false);
                 updateTitle("访客签到");
                 replaceFragment(VisitSignFragment.newInstance(1));
                 break;
             case R.id.MenuItemRegister://登记
+                if(!RunDataManage.CanVisitorRegister()) {
+                    ToastUtils.showToast(R.string.no_permission);
+                    return;
+                }
                 showHome(false);
                 updateTitle("访客登记");
                 replaceFragment(RegTypeFragment.newInstance(this));
@@ -93,11 +108,19 @@ public class HomeAc extends BaseActivity implements View.OnClickListener, RegTyp
 //                startActivity(intent);
                 break;
             case R.id.MenuItemLeave://签离
+                if(!RunDataManage.CanVisitorSignOut()) {
+                    ToastUtils.showToast(R.string.no_permission);
+                    return;
+                }
                 showHome(false);
                 updateTitle("访客签离");
                 replaceFragment(VisitSignFragment.newInstance(2));
                 break;
             case R.id.MenuItemCheck://核验
+                if(!RunDataManage.CanVisitorCheck()) {
+                    ToastUtils.showToast(R.string.no_permission);
+                    return;
+                }
                 ToastUtils.showToast("开发中...");
                 break;
             case R.id.ImageSetting:
@@ -105,6 +128,8 @@ public class HomeAc extends BaseActivity implements View.OnClickListener, RegTyp
                 break;
             case R.id.tv_loginOut:
                 SharePrefenceUtils.putBoolean(Constant.ISharePrefence.LOGINTAG, false);
+                LogModel.AddLog(LogModel.Type.UserLoginOut);
+                RunDataManage.SetLoginUser(null);
                 startActivity(new Intent(mContext, LoginActivity.class));
                 finish();
                 break;

+ 1 - 1
app/src/main/java/com/sunwin/visitorapp/db/BlackUserModel.java

@@ -9,7 +9,7 @@ public class BlackUserModel {
 
     // 指定自增,每个对象需要有一个主键
     @PrimaryKey(AssignType.AUTO_INCREMENT)
-    private int id;
+    private long id;
 
     public String name;
 

+ 16 - 6
app/src/main/java/com/sunwin/visitorapp/db/DatabaseManager.java

@@ -34,7 +34,12 @@ public class DatabaseManager {
     public <T> long insert(T t) {
         return liteOrm.save(t);
     }
-
+    public <T> long save(T t) {
+        return liteOrm.save(t);
+    }
+    public <T> long insertNew(T t) {
+        return liteOrm.insert(t);
+    }
     /**
      * 插入所有记录
      *
@@ -72,6 +77,10 @@ public class DatabaseManager {
     }
 
 
+
+    public <T> T getQueryById(Class<T> cla, long id) {
+        return liteOrm.<T>queryById(id,cla);
+    }
     /**
      * 查询  某字段 等于 Value的值
      *
@@ -80,13 +89,14 @@ public class DatabaseManager {
      * @param value
      * @return
      */
-    public <T> List<T> getQueryByWhere(Class<T> cla, String field, String[] value) {
-        return liteOrm.<T>query(new QueryBuilder(cla).where(field + "=?", value));
+    public <T> List<T> getQueryByWhere(Class<T> cla, String field, Object... value) {
+        return liteOrm.<T>query(new QueryBuilder<T>(cla).where(field + "=?", value));
     }
-
-    public <T> List<T> getQueryByLike(Class<T> cla, String field, String[] value) {
-        return liteOrm.<T>query(new QueryBuilder(cla).where(field + " like ?", value));
+    public <T> List<T> getQueryByWhere(Class<T> cla, String field0, Object value0, String field1, Object value1) {
+        return liteOrm.<T>query(new QueryBuilder<T>(cla).whereEquals(field0 , value0).whereAppendAnd().whereEquals(field1 , value1));
     }
+
+
     /**
      * 查询  某字段 等于 Value的值  可以指定从1-20,就是分页
      * @param cla

+ 36 - 0
app/src/main/java/com/sunwin/visitorapp/db/LogModel.java

@@ -0,0 +1,36 @@
+package com.sunwin.visitorapp.db;
+
+import com.litesuits.orm.db.annotation.PrimaryKey;
+import com.litesuits.orm.db.enums.AssignType;
+import com.sunwin.visitorapp.manage.RunDataManage;
+
+import java.util.Date;
+
+public class LogModel {
+    public enum Type{
+
+        UserLoginIn,UserLoginOut,
+        UserSearch,UserEdit,UserDelete,
+        BlackListSearch,BlackListEdit,BlackListDelete,
+        RoleSearch,RoleEdit,RoleDelete,
+
+
+    }
+    @PrimaryKey(AssignType.AUTO_INCREMENT)
+    public long id;
+
+    public String name;
+
+
+    public long time;
+
+    public Type type;
+
+    public static void AddLog(Type type){
+        LogModel model = new LogModel();
+        model.name = RunDataManage.GetLoginUser()!=null?RunDataManage.GetLoginUser().name:"位置";
+        model.time = new Date().getTime();
+        model.type = type;
+        DatabaseManager.getInstance().insertNew(model);
+    }
+}

+ 47 - 0
app/src/main/java/com/sunwin/visitorapp/db/RoleModel.java

@@ -0,0 +1,47 @@
+package com.sunwin.visitorapp.db;
+
+import com.litesuits.orm.db.annotation.PrimaryKey;
+import com.litesuits.orm.db.annotation.Table;
+import com.litesuits.orm.db.enums.AssignType;
+
+@Table("PermissionRole")
+public class RoleModel {
+
+
+    @PrimaryKey(AssignType.AUTO_INCREMENT)
+    public long id;
+
+    public String name;
+
+    public String remark;
+
+    public boolean p_black_user;
+    public boolean p_visitor_record;
+    public boolean p_visitor_check;
+    public boolean p_visitor_register;
+    public boolean p_visitor_sign_in;
+    public boolean p_visitor_sign_out;
+
+    public String labelPermission(){
+        StringBuilder builder = new StringBuilder();
+        if(p_visitor_register){
+            builder.append("访客登记;");
+        }
+        if(p_visitor_record){
+            builder.append("访客记录;");
+        }
+        if(p_visitor_sign_in){
+            builder.append("访客签到;");
+        }
+        if(p_visitor_sign_out){
+            builder.append("访客签离;");
+        }
+        if(p_visitor_check){
+            builder.append("自助核验;");
+        }
+        if(p_black_user){
+            builder.append("黑名单;");
+        }
+        return builder.toString();
+    }
+}

+ 31 - 2
app/src/main/java/com/sunwin/visitorapp/db/UserManagerModel.java

@@ -1,25 +1,54 @@
 package com.sunwin.visitorapp.db;
 
+import com.litesuits.orm.db.annotation.Column;
 import com.litesuits.orm.db.annotation.PrimaryKey;
 import com.litesuits.orm.db.annotation.Table;
 import com.litesuits.orm.db.enums.AssignType;
 
+import java.util.List;
+
 @Table("UserManager")
 public class UserManagerModel {
 
+    public static void EmptyInit(){
+        List<UserManagerModel> userManagerModelList = DatabaseManager.getInstance().getQueryAll(UserManagerModel.class);
+        if(userManagerModelList.isEmpty()){
+            RoleModel roleModel = new RoleModel();
+            roleModel.name = "admin";
+            roleModel.p_visitor_register = true;
+            roleModel.p_visitor_check = true;
+            roleModel.p_visitor_sign_out = true;
+            roleModel.p_visitor_sign_in = true;
+            roleModel.p_visitor_record = true;
+            roleModel.p_black_user = true;
+            long roleId=  DatabaseManager.getInstance().insertNew(roleModel);
+            UserManagerModel userManagerModel = new UserManagerModel();
+            userManagerModel.name = "admin";
+            userManagerModel.account = "admin";
+            userManagerModel.password = "123456";
+            userManagerModel.role_id = roleId;
+            DatabaseManager.getInstance().insertNew(userManagerModel);
+        }
+    }
+
+    public static final String Key_account = "account";
+
+    public static final String Key_password = "password";
     // 指定自增,每个对象需要有一个主键
     @PrimaryKey(AssignType.AUTO_INCREMENT)
-    private int id;
+    public long id;
 
+    @Column(Key_account)
     public String account;
 
+    @Column(Key_password)
     public String password;
 
     public String name;
 
     public int status = 1;
 
-    public String permission;
+    public long role_id;
 
     public long last_login_time;
 

+ 114 - 0
app/src/main/java/com/sunwin/visitorapp/fragment/RoleManageFr.java

@@ -1,25 +1,139 @@
 package com.sunwin.visitorapp.fragment;
 
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.net.Uri;
 import android.os.Bundle;
+import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.CheckBox;
+import android.widget.EditText;
+import android.widget.ImageView;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+import androidx.appcompat.app.AlertDialog;
 import androidx.fragment.app.Fragment;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
 
+import com.bumptech.glide.Glide;
+import com.github.gzuliyujiang.imagepicker.ImagePicker;
+import com.github.gzuliyujiang.imagepicker.PickCallback;
 import com.sunwin.visitorapp.R;
+import com.sunwin.visitorapp.adapter.BaseRecyclerAdapter;
+import com.sunwin.visitorapp.adapter.BaseViewHolder;
+import com.sunwin.visitorapp.db.BlackUserModel;
+import com.sunwin.visitorapp.db.DatabaseManager;
+import com.sunwin.visitorapp.db.RoleModel;
+import com.sunwin.visitorapp.db.UserManagerModel;
+import com.sunwin.visitorapp.manage.RunDataManage;
+import com.sunwin.visitorapp.utils.FileUtil;
+import com.sunwin.visitorapp.utils.ToastUtils;
+
+import java.io.File;
 
 public class RoleManageFr extends Fragment {
 
     private View root;
+    private Context context;
+    private BaseRecyclerAdapter<RoleModel> adapter;
     @Nullable
     @Override
     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
 
         if(root==null)root = inflater.inflate(R.layout.fr_role_manage,container,false);
+        context = root.getContext();
+        RecyclerView RecyclerBlackList = root.findViewById(R.id.RecyclerRoleList);
+        adapter = new BaseRecyclerAdapter<RoleModel>() {
+            @Override
+            protected View getLayoutView(ViewGroup parent, int viewType) {
+                return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rolelist,parent,false);
+            }
+
+            @SuppressLint("UseCompatLoadingForDrawables")
+            @Override
+            public void bind(int position, RoleModel data, BaseViewHolder holder, int viewType) {
+                holder.setText(R.id.TextName,data.name);
+                holder.setText(R.id.TextRemark,data.remark);
+                holder.setText(R.id.TextPermission,data.labelPermission());
+                holder.getView(R.id.ButtonDelete).setOnClickListener(v->{
+                    new AlertDialog.Builder(holder.itemView.getContext()).setTitle("提示").setMessage("确定删除吗?").setPositiveButton("确定", (dialog, which) -> {
+                        DatabaseManager.getInstance().delete(data);
+                        refreshData();
+                    }).setNegativeButton("取消",null).create().show();
+                });
+                holder.getView(R.id.ButtonEdit).setOnClickListener(v->{
+                    createDialog(holder.itemView.getContext(), (ViewGroup) holder.itemView,data);
+                });
 
+            }
+        };
+        RecyclerBlackList.setAdapter(adapter);
+        RecyclerBlackList.setLayoutManager(new LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false));
+//        RecyclerBlackList.addItemDecoration(new RVLinearItemDecoration.Builder(root.getContext()).color(R.color.ColorGray).dashWidth(2).create());
+        refreshData();
+        root.findViewById(R.id.ButtonAdd).setOnClickListener(v->{
+            createDialog(context,container,new RoleModel());
+        });
+        EditText EditSearchKey = root.findViewById(R.id.EditSearchKey);
+        root.findViewById(R.id.ButtonSearch).setOnClickListener(v->{
+            search(EditSearchKey.getText().toString().trim());
+        });
         return root;
     }
+    private void refreshData(){
+        adapter.setList(DatabaseManager.getInstance().getQueryAll(RoleModel.class));
+    }
+    private void search(String key){
+        adapter.setList(DatabaseManager.getInstance().getQueryByWhere(RoleModel.class,"name",key));
+    }
+    private void createDialog(Context context, ViewGroup parent, RoleModel model){
+        View dialog_root = LayoutInflater.from(context).inflate(R.layout.dialog_role_edit,parent,false);
+        EditText editName = dialog_root.findViewById(R.id.EditName);
+        editName.setText(model.name);
+        EditText EditRemark = dialog_root.findViewById(R.id.EditRemark);
+        EditRemark.setText(model.remark);
+        CheckBox CheckBlackList = dialog_root.findViewById(R.id.CheckBlackList);
+        CheckBlackList.setChecked(model.p_black_user);
+        CheckBox CheckVisitorRecord = dialog_root.findViewById(R.id.CheckVisitorRecord);
+        CheckVisitorRecord.setChecked(model.p_visitor_record);
+        CheckBox CheckVisitorCheck = dialog_root.findViewById(R.id.CheckVisitorCheck);
+        CheckVisitorCheck.setChecked(model.p_visitor_check);
+        CheckBox CheckVisitorRegister = dialog_root.findViewById(R.id.CheckVisitorRegister);
+        CheckVisitorRegister.setChecked(model.p_visitor_register);
+        CheckBox CheckVisitorSignIn = dialog_root.findViewById(R.id.CheckVisitorSignIn);
+        CheckVisitorSignIn.setChecked(model.p_visitor_sign_in);
+        CheckBox CheckVisitorSignOut = dialog_root.findViewById(R.id.CheckVisitorSignOut);
+        CheckVisitorSignOut.setChecked(model.p_visitor_sign_out);
+        AlertDialog dialog = new AlertDialog.Builder(root.getContext()).setTitle("添加黑名单")
+                .setView(dialog_root)
+                .create();
+
+
+        dialog_root.findViewById(R.id.ButtonSure).setOnClickListener(b->{
+
+            if(TextUtils.isEmpty(editName.getText().toString().trim())){
+                ToastUtils.showToast("名称不为空");
+                return;
+            }
+            model.name = editName.getText().toString().trim();
+            model.remark = EditRemark.getText().toString().trim();
+            model.p_black_user = CheckBlackList.isChecked();
+            model.p_visitor_register = CheckVisitorRegister.isChecked();
+            model.p_visitor_record = CheckVisitorRecord.isChecked();
+            model.p_visitor_check = CheckVisitorCheck.isChecked();
+            model.p_visitor_sign_in = CheckVisitorSignIn.isChecked();
+            model.p_visitor_sign_out = CheckVisitorSignOut.isChecked();
+            DatabaseManager.getInstance().save(model);
+            if(RunDataManage.GetLoginRole()!=null&&RunDataManage.GetLoginRole().id==model.id){
+                RunDataManage.RefreshLoginUser();
+            }
+            refreshData();
+            dialog.dismiss();
+        });
+        dialog.show();
+    }
 }

+ 50 - 20
app/src/main/java/com/sunwin/visitorapp/fragment/UserManageFr.java

@@ -2,19 +2,14 @@ package com.sunwin.visitorapp.fragment;
 
 import android.annotation.SuppressLint;
 import android.content.Context;
-import android.content.DialogInterface;
-import android.net.Uri;
 import android.os.Bundle;
 import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.EditText;
-import android.widget.ImageView;
-import android.widget.Spinner;
 import android.widget.TextView;
 
-import androidx.annotation.ContentView;
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.appcompat.app.AlertDialog;
@@ -22,11 +17,6 @@ import androidx.fragment.app.Fragment;
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.recyclerview.widget.RecyclerView;
 
-import com.bumptech.glide.Glide;
-import com.github.gzuliyujiang.calendarpicker.CalendarPicker;
-import com.github.gzuliyujiang.calendarpicker.OnSingleDatePickListener;
-import com.github.gzuliyujiang.imagepicker.ImagePicker;
-import com.github.gzuliyujiang.imagepicker.PickCallback;
 import com.github.gzuliyujiang.wheelpicker.DatimePicker;
 import com.github.gzuliyujiang.wheelpicker.OptionPicker;
 import com.github.gzuliyujiang.wheelpicker.annotation.DateMode;
@@ -38,19 +28,22 @@ import com.github.gzuliyujiang.wheelpicker.entity.DateEntity;
 import com.github.gzuliyujiang.wheelpicker.entity.DatimeEntity;
 import com.github.gzuliyujiang.wheelpicker.entity.TimeEntity;
 import com.github.gzuliyujiang.wheelpicker.widget.DatimeWheelLayout;
+import com.github.gzuliyujiang.wheelpicker.widget.OptionWheelLayout;
+import com.github.gzuliyujiang.wheelview.contract.WheelFormatter;
 import com.sunwin.visitorapp.R;
 import com.sunwin.visitorapp.adapter.BaseRecyclerAdapter;
 import com.sunwin.visitorapp.adapter.BaseViewHolder;
-import com.sunwin.visitorapp.db.BlackUserModel;
 import com.sunwin.visitorapp.db.DatabaseManager;
+import com.sunwin.visitorapp.db.RoleModel;
 import com.sunwin.visitorapp.db.UserManagerModel;
-import com.sunwin.visitorapp.utils.FileUtil;
+import com.sunwin.visitorapp.manage.RunDataManage;
+import com.sunwin.visitorapp.utils.GsonUtil;
 import com.sunwin.visitorapp.utils.TimeUtils;
 import com.sunwin.visitorapp.utils.ToastUtils;
 
 import java.util.Calendar;
 import java.util.Date;
-import java.util.Objects;
+import java.util.List;
 
 import timber.log.Timber;
 
@@ -78,7 +71,8 @@ public class UserManageFr extends Fragment {
                 holder.setText(R.id.TextAccount,data.account);
                 holder.setText(R.id.TextName,data.name);
                 holder.setText(R.id.TextStatus,statusLabelList[data.status]);
-                holder.setText(R.id.TextPermission,String.valueOf(data.permission));
+                RoleModel role = DatabaseManager.getInstance().getQueryById(RoleModel.class,data.role_id);
+                holder.setText(R.id.TextPermission,role!=null?role.name:"暂无");
                 holder.setText(R.id.TextLastLoginTime,String.valueOf(data.last_login_time));
                 holder.getView(R.id.ButtonEdit).setOnClickListener(v->{
                     createDialog(context,container,data);
@@ -88,7 +82,6 @@ public class UserManageFr extends Fragment {
                         DatabaseManager.getInstance().delete(data);
                         refreshData();
                     }).setNegativeButton("取消",null).create().show();
-
                 });
 
             }
@@ -112,7 +105,7 @@ public class UserManageFr extends Fragment {
     }
 
     private void search(String key){
-        adapter.setList(DatabaseManager.getInstance().getQueryByLike(UserManagerModel.class,"name",new String[]{key}));
+        adapter.setList(DatabaseManager.getInstance().getQueryByWhere(UserManagerModel.class,"name",key));
     }
 
 
@@ -127,7 +120,34 @@ public class UserManageFr extends Fragment {
         EditText EditPassword = dialog_root.findViewById(R.id.EditPassword);
         EditPassword.setText(model.password);
         EditText EditConfirmPassword = dialog_root.findViewById(R.id.EditConfirmPassword);
+        EditConfirmPassword.setText(model.password);
+        TextView TextRole = dialog_root.findViewById(R.id.TextRole);
+        List<RoleModel> roleModels = DatabaseManager.getInstance().getQueryAll(RoleModel.class);
+        RoleModel userRole = DatabaseManager.getInstance().getQueryById(RoleModel.class,model.role_id);
+        if(userRole!=null){
+            TextRole.setText(userRole.name);
+            TextRole.setTag(userRole.id);
+        }
+        TextRole.setOnClickListener(v->{
+            OptionPicker picker = new OptionPicker(requireActivity());
+            picker.setData((Object[]) roleModels.toArray());
+
+            picker.setDefaultValue(userRole);
+            picker.getTitleView().setText("用户角色");
+            picker.getWheelLayout().getWheelView().setFormatter(item -> ((RoleModel)item).name);
+
+
+            picker.setOnOptionPickedListener((position, item) -> {
+//                    model.status = position;
+                RoleModel roleModel = (RoleModel) item;
+                TextRole.setTag(roleModel.id);
+                TextRole.setText(roleModel.name);
+            });
+//            picker.getWheelView().setStyle(R.style.WheelStyleDemo);
+            picker.show();
+        });
         TextView TextStatus = dialog_root.findViewById(R.id.TextStatus);
+        TextStatus.setTag(model.status);
         TextStatus.setText(statusLabelList[model.status]);
         TextStatus.setOnClickListener(v->{
             OptionPicker picker = new OptionPicker(requireActivity());
@@ -137,7 +157,8 @@ public class UserManageFr extends Fragment {
             picker.setOnOptionPickedListener(new OnOptionPickedListener() {
                 @Override
                 public void onOptionPicked(int position, Object item) {
-                    model.status = position;
+
+                    TextStatus.setTag(position);
                     TextStatus.setText((String)item);
                 }
             });
@@ -148,6 +169,7 @@ public class UserManageFr extends Fragment {
         if(model.valid_time<0){
             TextValidTime.setText("无过期时间");
         }else {
+            TextValidTime.setTag(model.valid_time);
             TextValidTime.setText(TimeUtils.stampToTime(model.valid_time));
         }
 
@@ -165,7 +187,8 @@ public class UserManageFr extends Fragment {
                     calendar.set(Calendar.DAY_OF_MONTH,day);
                     calendar.set(Calendar.HOUR_OF_DAY,hour);
                     calendar.set(Calendar.MINUTE,minute);
-                    model.valid_time = calendar.getTimeInMillis();
+
+                    TextValidTime.setTag(calendar.getTimeInMillis());
                     TextValidTime.setText(TimeUtils.stampToTime(calendar.getTimeInMillis()));
                 }
             });
@@ -206,11 +229,18 @@ public class UserManageFr extends Fragment {
             }
             model.account = EditAccount.getText().toString().trim();
             model.name = EditName.getText().toString().trim();
-
             model.password = EditPassword.getText().toString().trim();
+            if( TextRole.getTag()!=null)model.role_id = (long) TextRole.getTag();
+            if( TextStatus.getTag()!=null)model.status = (int) TextStatus.getTag();
+            if( TextValidTime.getTag()!=null)model.valid_time = (long) TextValidTime.getTag();
+
 //            model.status = TextView.getSelectedItemPosition();
 //            model.valid_time = TextValidTime.getText().toString().trim();
-            DatabaseManager.getInstance().insert(model);
+            Timber.e(GsonUtil.toJson(model));
+            DatabaseManager.getInstance().save(model);
+            if(RunDataManage.GetLoginUser()!=null&&RunDataManage.GetLoginUser().id==model.id){
+                RunDataManage.RefreshLoginUser();
+            }
             refreshData();
             dialog.dismiss();
         });

+ 69 - 0
app/src/main/java/com/sunwin/visitorapp/manage/RunDataManage.java

@@ -0,0 +1,69 @@
+package com.sunwin.visitorapp.manage;
+
+import com.sunwin.visitorapp.db.DatabaseManager;
+import com.sunwin.visitorapp.db.RoleModel;
+import com.sunwin.visitorapp.db.UserManagerModel;
+import com.sunwin.visitorapp.model.UserModel;
+import com.sunwin.visitorapp.utils.GsonUtil;
+import com.sunwin.visitorapp.utils.SharePrefenceUtils;
+
+public class RunDataManage {
+    private static  String Key_loginUser = "Key_loginUser";
+    private static UserManagerModel loginUser;
+    private static RoleModel roleModel;
+
+
+    public static void RefreshLoginUser(){
+
+        roleModel = null;
+        if(loginUser==null)return;
+        loginUser = DatabaseManager.getInstance().getQueryById(UserManagerModel.class,loginUser.id);
+    }
+    public static void SetLoginUser(UserManagerModel loginUser){
+        SharePrefenceUtils.putString(Key_loginUser,GsonUtil.toJson(loginUser));
+        RunDataManage.loginUser = loginUser;
+    }
+
+    public static UserManagerModel GetLoginUser(){
+        if(loginUser==null){
+            String value = SharePrefenceUtils.getString(Key_loginUser,null);
+            loginUser = GsonUtil.getObject(value,UserManagerModel.class);
+        }
+        return loginUser;
+    }
+
+
+    public static synchronized RoleModel GetLoginRole(){
+        if(GetLoginUser()==null)return roleModel;
+        if(roleModel == null){
+            roleModel = DatabaseManager.getInstance().getQueryById(RoleModel.class,GetLoginUser().role_id);
+        }
+        return roleModel;
+    }
+
+    public static boolean CanVisitorCheck(){
+        if(GetLoginRole()==null)return false;
+        return GetLoginRole().p_visitor_check;
+    }
+    public static boolean CanBlackList(){
+        if(GetLoginRole()==null)return false;
+        return GetLoginRole().p_black_user;
+    }
+    public static boolean CanVisitorRecord(){
+        if(GetLoginRole()==null)return false;
+        return GetLoginRole().p_visitor_record;
+    }
+    public static boolean CanVisitorSignIn(){
+        if(GetLoginRole()==null)return false;
+        return GetLoginRole().p_visitor_sign_in;
+    }
+    public static boolean CanVisitorSignOut(){
+        if(GetLoginRole()==null)return false;
+        return GetLoginRole().p_visitor_sign_out;
+    }
+    public static boolean CanVisitorRegister(){
+        if(GetLoginRole()==null)return false;
+        return GetLoginRole().p_visitor_register;
+    }
+
+}

+ 104 - 0
app/src/main/res/layout/dialog_role_edit.xml

@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="500dp"
+    android:focusableInTouchMode="true"
+    android:focusable="true"
+    android:padding="20dp"
+    android:layout_height="wrap_content">
+
+    <LinearLayout
+        android:layout_marginVertical="10dp"
+        android:orientation="horizontal"
+        android:layout_width="match_parent"
+        android:gravity="center_vertical"
+        android:layout_height="wrap_content">
+        <TextView
+            style="@style/StyleTextContent"
+            android:layout_width="150dp"
+            android:text="角色名称"
+            />
+        <EditText
+            android:id="@+id/EditName"
+            android:layout_weight="1"
+            android:layout_width="0dp"
+            style="@style/StyleInputContent"
+            android:layout_height="wrap_content"/>
+    </LinearLayout>
+    <LinearLayout
+        android:layout_marginVertical="10dp"
+        android:orientation="horizontal"
+        android:layout_width="match_parent"
+        android:gravity="center_vertical"
+        android:layout_height="wrap_content">
+        <TextView
+            style="@style/StyleTextContent"
+            android:layout_width="150dp"
+            android:text="备注"
+            />
+        <EditText
+            android:id="@+id/EditRemark"
+            android:layout_weight="1"
+            android:layout_width="0dp"
+            style="@style/StyleInputContent"
+            android:layout_height="wrap_content"/>
+    </LinearLayout>
+    <LinearLayout
+        android:layout_marginVertical="10dp"
+        android:orientation="horizontal"
+        android:layout_width="match_parent"
+        android:gravity="center_vertical"
+        android:layout_height="wrap_content">
+        <TextView
+            style="@style/StyleTextContent"
+            android:layout_width="150dp"
+            android:text="权限"
+            />
+        <LinearLayout
+            android:orientation="vertical"
+            android:layout_weight="1"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content">
+
+            <CheckBox
+                android:id="@+id/CheckVisitorRecord"
+                android:text="访客记录"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"/>
+            <CheckBox
+                android:id="@+id/CheckVisitorRegister"
+                android:text="访客登记"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"/>
+            <CheckBox
+                android:id="@+id/CheckVisitorSignIn"
+                android:text="访客签到"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"/>
+            <CheckBox
+                android:id="@+id/CheckVisitorSignOut"
+                android:text="访客签离"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"/>
+            <CheckBox
+                android:id="@+id/CheckVisitorCheck"
+                android:text="快速核验"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"/>
+            <CheckBox
+                android:id="@+id/CheckBlackList"
+                android:text="黑名单"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"/>
+        </LinearLayout>
+    </LinearLayout>
+    <Button
+        android:id="@+id/ButtonSure"
+        android:layout_gravity="center_horizontal"
+        style="@style/ButtonPrimary"
+        android:layout_width="match_parent"
+        android:textAlignment="center"
+        android:layout_margin="10dp"
+        android:text="提交"
+        />
+</LinearLayout>

+ 1 - 0
app/src/main/res/layout/dialog_user_manger.xml

@@ -121,6 +121,7 @@
             android:layout_width="0dp"
             style="@style/StyleInputContent"
 
+            android:hint="请选择角色"
             android:layout_height="wrap_content"/>
     </LinearLayout>
     <LinearLayout

+ 42 - 0
app/src/main/res/layout/fr_role_manage.xml

@@ -11,6 +11,7 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content">
         <Button
+            android:id="@+id/ButtonAdd"
             style="@style/ButtonPrimaryLarge"
 
             app:layout_constraintStart_toStartOf="parent"
@@ -36,10 +37,12 @@
                 android:text="角色名"
                 />
             <EditText
+                android:id="@+id/EditSearchKey"
                 android:layout_width="150dp"
                 style="@style/StyleInputContent"
                 android:layout_height="wrap_content"/>
             <Button
+                android:id="@+id/ButtonSearch"
                 style="@style/ButtonPrimaryLarge"
                 android:layout_width="wrap_content"
                 android:textAlignment="center"
@@ -49,7 +52,46 @@
         </LinearLayout>
     </androidx.constraintlayout.widget.ConstraintLayout>
 
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:gravity="center_vertical"
+        android:layout_margin="1dp"
+        android:padding="10dp">
+
+        <TextView
+            android:text="角色名称"
+            android:id="@+id/TextName"
+            style="@style/StyleTextContent"
+            android:layout_width="0dp"
+            android:layout_weight="0.5"
+            />
+        <TextView
+            android:text="权限"
+            android:id="@+id/TextPermission"
+            style="@style/StyleTextContent"
+            android:layout_width="0dp"
+            android:layout_weight="1"
+            />
+        <TextView
+            android:text="备注"
+            android:id="@+id/TextRemark"
+            style="@style/StyleTextContent"
+            android:layout_width="0dp"
+            android:layout_weight="0.5"
+            />
+
+        <TextView
+            android:text="操作"
+            style="@style/StyleTextContent"
+            android:layout_width="0dp"
+            android:layout_weight="1"
+            />
+
+    </LinearLayout>
     <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/RecyclerRoleList"
         android:layout_marginVertical="10dp"
         android:layout_width="match_parent"
         android:layout_height="0dp"

+ 48 - 0
app/src/main/res/layout/item_rolelist.xml

@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:orientation="horizontal"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:gravity="center_vertical"
+    android:background="@drawable/border_gary"
+    android:layout_margin="1dp"
+    android:padding="10dp">
+
+    <TextView
+        android:id="@+id/TextName"
+        style="@style/StyleTextContent"
+        android:layout_width="0dp"
+        android:layout_weight="0.5"
+        />
+    <TextView
+        android:id="@+id/TextPermission"
+        style="@style/StyleTextContent"
+        android:layout_width="0dp"
+        android:layout_weight="1"
+        />
+    <TextView
+        android:id="@+id/TextRemark"
+        style="@style/StyleTextContent"
+        android:layout_width="0dp"
+        android:layout_weight="0.5"
+        />
+
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="0dp"
+        android:layout_weight="1"
+        android:gravity="center"
+        android:layout_height="wrap_content">
+        <Button
+            android:id="@+id/ButtonEdit"
+            android:text="编辑"
+            android:layout_marginEnd="10dp"
+            style="@style/ButtonPrimary"/>
+        <Button
+            android:id="@+id/ButtonDelete"
+            android:text="删除"
+            style="@style/ButtonPrimary"/>
+    </LinearLayout>
+
+</LinearLayout>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -9,4 +9,5 @@
     <string name="have_readed_id_card">身份证已经读取完成,请收回身份证</string>
     <string name="veriface_hint">请正对屏幕</string>
     <string name="usb_unauthorized">usb未授权</string>
+    <string name="no_permission">无权限</string>
 </resources>