Przeglądaj źródła

· 增加首页统计图查看权限
· 增加粮情检查增删改查权限
· 增加仓房信息查看权限
· 增加库存/出库质量增删改查权限

mq 5 lat temu
rodzic
commit
2f973c5be9

+ 6 - 2
app/src/main/java/com/unis/sxzcl/ui/grain_check/GrainCheckHomeFragment.java

@@ -12,6 +12,7 @@ import com.unis.model.DataCallback;
12 12
 import com.unis.model.DepotModel;
13 13
 import com.unis.model.GrainCheckModel;
14 14
 import com.unis.model.HouseModel;
15
+import com.unis.model.PermitConstant;
15 16
 import com.unis.model.ProcessModel;
16 17
 import com.unis.model.UserModel;
17 18
 import com.unis.model.bean.HouseListBean;
@@ -102,8 +103,9 @@ public class GrainCheckHomeFragment extends BaseFragment<FragmentBaseTabPagerBin
102 103
     @Override
103 104
     protected void onFirstShow() {
104 105
 
105
-        // 保管员显示新增
106
-        mBinding.bar.setRightVisible(UserModel.get().isUserRole(RoleType.R_BGY));
106
+        // 有新增权限 且 保管员
107
+        if (UserModel.get().isPermit(PermitConstant.grain_check_add))
108
+            mBinding.bar.setRightVisible(UserModel.get().isUserRole(RoleType.R_BGY));
107 109
 
108 110
         // 切换到用户角色所在的页面
109 111
         mBinding.viewPager.setCurrentItem(getRoleCurrentPage());
@@ -203,6 +205,8 @@ public class GrainCheckHomeFragment extends BaseFragment<FragmentBaseTabPagerBin
203 205
 
204 206
     @Override
205 207
     public void onPageSelected(int position) {
208
+        if (!UserModel.get().isPermit(PermitConstant.grain_check_add)) return;
209
+
206 210
         /**
207 211
          * 登录人是否可以新增
208 212
          * 每个页面所需角色不同

+ 7 - 2
app/src/main/java/com/unis/sxzcl/ui/grain_check/GrainCheckListFragment.java

@@ -5,9 +5,8 @@ import android.view.LayoutInflater;
5 5
 import android.view.ViewGroup;
6 6
 
7 7
 import com.unis.model.DataCallback;
8
-import com.unis.model.DepotModel;
9 8
 import com.unis.model.GrainCheckModel;
10
-import com.unis.model.HouseModel;
9
+import com.unis.model.PermitConstant;
11 10
 import com.unis.model.UserModel;
12 11
 import com.unis.model.bean.grain_check.GrainCheckBean;
13 12
 import com.unis.model.event.GrainCheckEvent;
@@ -139,6 +138,12 @@ public class GrainCheckListFragment extends BaseListFragment<FragmentBaseListBin
139 138
         } else {
140 139
             bundle.putString("pageType", "edit");
141 140
         }
141
+
142
+        // 没有修改权限只能查看
143
+        if (!UserModel.get().isPermit(PermitConstant.grain_check_update)) {
144
+            bundle.putString("pageType", "detail");
145
+        }
146
+
142 147
         bundle.putString("data", getGson().toJson(item));
143 148
         navigation(R.id.grainCheckDetailFragment, bundle);
144 149
     }

+ 6 - 2
app/src/main/java/com/unis/sxzcl/ui/home/HomeFragment.java

@@ -9,6 +9,7 @@ import com.bumptech.glide.Glide;
9 9
 import com.unis.model.AnnounceModel;
10 10
 import com.unis.model.DataCallback;
11 11
 import com.unis.model.NoticeModel;
12
+import com.unis.model.PermitConstant;
12 13
 import com.unis.model.ProcessModel;
13 14
 import com.unis.model.UrlPath;
14 15
 import com.unis.model.UserModel;
@@ -85,8 +86,11 @@ public class HomeFragment extends BaseFragment<FragmentHomeBinding> {
85 86
         // 初始化轮播图
86 87
         initBanner();
87 88
 
88
-        // 初始化企业统计
89
-        initCompanyStats();
89
+        // 有仓房权限
90
+        if (UserModel.get().isPermit(PermitConstant.house)) {
91
+            // 初始化企业统计
92
+            initCompanyStats();
93
+        }
90 94
 
91 95
     }
92 96
 

+ 10 - 3
app/src/main/java/com/unis/sxzcl/ui/house/HouseDetailFragment.java

@@ -7,6 +7,8 @@ import android.view.ViewGroup;
7 7
 import com.unis.model.BasicModel;
8 8
 import com.unis.model.DataCallback;
9 9
 import com.unis.model.HouseModel;
10
+import com.unis.model.PermitConstant;
11
+import com.unis.model.UserModel;
10 12
 import com.unis.model.bean.EnumBean;
11 13
 import com.unis.model.bean.HouseBean;
12 14
 import com.unis.sxzcl.base.BaseListFragment;
@@ -45,6 +47,7 @@ public class HouseDetailFragment extends BaseListFragment<FragmentBaseListBindin
45 47
     private final String T_HOUSE_STATUS = "仓房状态";
46 48
     private final String T_STORAGE = "存储状态";
47 49
     private HouseBean mHouse;
50
+    private boolean mPermit;
48 51
 
49 52
     @Override
50 53
     protected FragmentBaseListBinding getViewBinding(LayoutInflater inflater, ViewGroup container) {
@@ -57,6 +60,7 @@ public class HouseDetailFragment extends BaseListFragment<FragmentBaseListBindin
57 60
 
58 61
         mAdapter = new BaseDetailAdapter();
59 62
         mAdapter.setOnItemClickListener((adapter, view, position) -> {
63
+            if (!mPermit) return;
60 64
             BaseDetailBean item = mAdapter.getData().get(position);
61 65
             String title = item.getTitle();
62 66
             switch (title) {
@@ -80,6 +84,8 @@ public class HouseDetailFragment extends BaseListFragment<FragmentBaseListBindin
80 84
 //        mAdapter.addData(new BaseDetailBean(BaseDetail.TITLE_CONTENT, T_HOUSE_STATUS, "满仓").setDownIcon(true));
81 85
 //        mAdapter.addData(new BaseDetailBean(BaseDetail.TITLE_CONTENT, T_STORAGE, "通风").setDownIcon(true));
82 86
 
87
+        mPermit = UserModel.get().isPermit(PermitConstant.house_update);
88
+
83 89
         onRefresh();
84 90
 
85 91
     }
@@ -97,15 +103,16 @@ public class HouseDetailFragment extends BaseListFragment<FragmentBaseListBindin
97 103
                 if (!isActive()) return;
98 104
                 if (data != null) {
99 105
                     mHouse = data;
106
+
100 107
                     List<BaseDetailBean> list = new ArrayList<>();
101 108
                     list.add(new BaseDetailBean(BaseDetail.TITLE_CONTENT, T_FOOD_TYPE,
102
-                            BasicModel.get().getEnumName(data.getGrainVarieties())).setDownIcon(true));
109
+                            BasicModel.get().getEnumName(data.getGrainVarieties())).setDownIcon(mPermit));
103 110
 
104 111
                     list.add(new BaseDetailBean(BaseDetail.TITLE_CONTENT, T_HOUSE_STATUS,
105
-                            BasicModel.get().getEnumName(data.getStorageStatus())).setDownIcon(true));
112
+                            BasicModel.get().getEnumName(data.getStorageStatus())).setDownIcon(mPermit));
106 113
 
107 114
                     list.add(new BaseDetailBean(BaseDetail.TITLE_CONTENT, T_STORAGE,
108
-                            BasicModel.get().getEnumName(data.getWarehouseStatus())).setDownIcon(true));
115
+                            BasicModel.get().getEnumName(data.getWarehouseStatus())).setDownIcon(mPermit));
109 116
                     mAdapter.setList(list);
110 117
                 }
111 118
                 loadComplete();

+ 1 - 1
app/src/main/java/com/unis/sxzcl/ui/inventory_quality/QuantityQualityDetailFragment.java

@@ -1,4 +1,4 @@
1
-package com.unis.sxzcl.ui.inventory_quality;
1
+package com.unis.sxzcl.ui.quantity_quality;
2 2
 
3 3
 import android.os.Bundle;
4 4
 import android.view.LayoutInflater;

+ 5 - 4
app/src/main/java/com/unis/sxzcl/ui/inventory_quality/QuantityQualityHomeFragment.java

@@ -1,4 +1,4 @@
1
-package com.unis.sxzcl.ui.inventory_quality;
1
+package com.unis.sxzcl.ui.quantity_quality;
2 2
 
3 3
 import android.os.Bundle;
4 4
 import android.view.LayoutInflater;
@@ -11,6 +11,7 @@ import com.google.android.material.tabs.TabLayout;
11 11
 import com.unis.model.BasicModel;
12 12
 import com.unis.model.DepotModel;
13 13
 import com.unis.model.HouseModel;
14
+import com.unis.model.PermitConstant;
14 15
 import com.unis.model.ProcessModel;
15 16
 import com.unis.model.UserModel;
16 17
 import com.unis.model.bean.EnumBean;
@@ -98,7 +99,7 @@ public class QuantityQualityHomeFragment extends BaseFragment<FragmentBaseTabPag
98 99
         // 获取库存质量检查类型
99 100
         if (mWorkType.equals("0")) {
100 101
             mEnumList = BasicModel.get().getEnumList("31");
101
-        }else {
102
+        } else {
102 103
             mEnumList = BasicModel.get().getEnumList("32");
103 104
         }
104 105
         if (mEnumList == null) {
@@ -107,8 +108,8 @@ public class QuantityQualityHomeFragment extends BaseFragment<FragmentBaseTabPag
107 108
         }
108 109
 
109 110
 
110
-        // 保管员显示新增
111
-        mBinding.bar.setRightVisible(UserModel.get().isUserRole(RoleType.R_BGY));
111
+        // 是否有权限新增
112
+        mBinding.bar.setRightVisible(UserModel.get().isPermit(PermitConstant.quantity_add));
112 113
 
113 114
 
114 115
         // 切换到用户角色所在的页面

+ 1 - 1
app/src/main/java/com/unis/sxzcl/ui/inventory_quality/QuantityQualityListAdapter.java

@@ -1,4 +1,4 @@
1
-package com.unis.sxzcl.ui.inventory_quality;
1
+package com.unis.sxzcl.ui.quantity_quality;
2 2
 
3 3
 import android.widget.ImageView;
4 4
 import android.widget.TextView;

+ 12 - 3
app/src/main/java/com/unis/sxzcl/ui/inventory_quality/QuantityQualityListFragment.java

@@ -1,4 +1,4 @@
1
-package com.unis.sxzcl.ui.inventory_quality;
1
+package com.unis.sxzcl.ui.quantity_quality;
2 2
 
3 3
 import android.os.Bundle;
4 4
 import android.view.LayoutInflater;
@@ -7,7 +7,9 @@ import android.view.ViewGroup;
7 7
 import com.unis.model.DataCallback;
8 8
 import com.unis.model.DepotModel;
9 9
 import com.unis.model.HouseModel;
10
+import com.unis.model.PermitConstant;
10 11
 import com.unis.model.QuantityQualityModel;
12
+import com.unis.model.UserModel;
11 13
 import com.unis.model.bean.QuantityQualityBean;
12 14
 import com.unis.sxzcl.R;
13 15
 import com.unis.sxzcl.base.BaseListFragment;
@@ -151,9 +153,16 @@ public class QuantityQualityListFragment extends BaseListFragment<FragmentBaseLi
151 153
      */
152 154
     @Override
153 155
     public void onItemClickListener(QuantityQualityBean item) {
154
-        // 没有状态  或 状态为1时 可修改
155
-        String pageType = item.getSaveState() == null || item.getSaveState().equals("1") ?
156
+        // 检测查看权限
157
+        if (!UserModel.get().isPermit(PermitConstant.quantity_read_single)) return;
158
+
159
+        // 状态为1时 可修改
160
+        String pageType = item.getSaveState() != null || item.getSaveState().equals("1") ?
156 161
                 "edit" : "detail";
162
+        if (!UserModel.get().isPermit(PermitConstant.quantity_update)) {
163
+            // 无权限修改 只能查看
164
+            pageType = "detail";
165
+        }
157 166
         Bundle bundle = new Bundle();
158 167
         bundle.putString(QuantityQualityDetailFragment.key_page_type, pageType);
159 168
         bundle.putString(QuantityQualityDetailFragment.key_info, getGson().toJson(item));

app/src/main/java/com/unis/sxzcl/ui/inventory_quality/库存质量_出库质量.txt → app/src/main/java/com/unis/sxzcl/ui/quantity_quality/库存质量_出库质量.txt


+ 16 - 2
app/src/main/java/com/unis/sxzcl/ui/work_module/WorkModuleBean.java

@@ -14,6 +14,7 @@ import java.util.List;
14 14
  */
15 15
 public class WorkModuleBean extends BaseExpandNode {
16 16
 
17
+    private int permitId;
17 18
     // 图片
18 19
     private int img;
19 20
     // 标题
@@ -26,13 +27,15 @@ public class WorkModuleBean extends BaseExpandNode {
26 27
     public WorkModuleBean() {
27 28
     }
28 29
 
29
-    public WorkModuleBean(String name, List<BaseNode> childList) {
30
+    public WorkModuleBean(int permitId, String name, List<BaseNode> childList) {
31
+        this.permitId = permitId;
30 32
         this.name = name;
31 33
         this.childList = childList;
32 34
         this.isWork = false;
33 35
     }
34 36
 
35
-    public WorkModuleBean(String name, int img) {
37
+    public WorkModuleBean(int permitId, String name, int img) {
38
+        this.permitId = permitId;
36 39
         this.name = name;
37 40
         this.img = img;
38 41
         this.isWork = true;
@@ -78,6 +81,9 @@ public class WorkModuleBean extends BaseExpandNode {
78 81
         return childList;
79 82
     }
80 83
 
84
+    public void setChildList(List<BaseNode> childList) {
85
+        this.childList = childList;
86
+    }
81 87
 
82 88
     public int getImg() {
83 89
         return img;
@@ -90,4 +96,12 @@ public class WorkModuleBean extends BaseExpandNode {
90 96
     public boolean isWork() {
91 97
         return isWork;
92 98
     }
99
+
100
+    public int getPermitId() {
101
+        return permitId;
102
+    }
103
+
104
+    public void setPermitId(int permitId) {
105
+        this.permitId = permitId;
106
+    }
93 107
 }

+ 6 - 0
app/src/main/java/com/unis/sxzcl/ui/work_module/WorkModuleFragment.java

@@ -7,6 +7,7 @@ import android.view.ViewGroup;
7 7
 import androidx.recyclerview.widget.GridLayoutManager;
8 8
 
9 9
 import com.unis.model.DepotModel;
10
+import com.unis.model.PermitConstant;
10 11
 import com.unis.model.UserModel;
11 12
 import com.unis.model.bean.MultiDepotBean;
12 13
 import com.unis.model.bean.user.UserBean;
@@ -123,6 +124,11 @@ public class WorkModuleFragment extends BaseListFragment<FragmentWorkModuleBindi
123 124
             mBinding.barCompany.setText(bean.depotName);
124 125
         }
125 126
 
127
+        // 没仓房权限 隐藏统计
128
+        if (!UserModel.get().isPermit(PermitConstant.house)) {
129
+            mBinding.barRight.setVisibility(View.GONE);
130
+        }
131
+
126 132
         // 刷新功能列表
127 133
         onRefresh();
128 134
     }

+ 45 - 18
app/src/main/java/com/unis/sxzcl/ui/work_module/WorkbenchModel.java

@@ -1,5 +1,8 @@
1 1
 package com.unis.sxzcl.ui.work_module;
2 2
 
3
+import com.chad.library.adapter.base.entity.node.BaseNode;
4
+import com.unis.model.PermitConstant;
5
+import com.unis.model.UserModel;
3 6
 import com.unis.sxzcl.R;
4 7
 
5 8
 import java.util.ArrayList;
@@ -32,7 +35,6 @@ public class WorkbenchModel {
32 35
     public static final String TYPE_JBXX = "基本信息";
33 36
     public static final String TYPE_RYJG = "人员结构";
34 37
 
35
-
36 38
     public static final String TYPE_SLZL = "数量质量";
37 39
     public static final String TYPE_CFXX = "仓房信息";
38 40
     public static final String TYPE_RKZL = "入库质量";
@@ -67,35 +69,34 @@ public class WorkbenchModel {
67 69
     public static final String TYPE_ZCGL = "租仓管理";
68 70
     public static final String TYPE_WTGL = "委托管理";
69 71
 
70
-
71 72
     /**
72
-     * 所有作业功能
73
+     * 创建所有作业功能
73 74
      * 分一级标题 和 二级功能
74 75
      */
75
-    public List<WorkModuleBean> getModuleList() {
76
+    public List<WorkModuleBean> createModuleList() {
76 77
         List<WorkModuleBean> list = new ArrayList<>();
77 78
 
78
-        list.add(new WorkModuleBean(TYPE_JBXX, Arrays.asList(
79
-                new WorkModuleBean(TYPE_RYJG, R.drawable.ic_model_ryjg)
79
+        list.add(new WorkModuleBean(0, TYPE_JBXX, Arrays.asList(
80
+                new WorkModuleBean(0, TYPE_RYJG, R.drawable.ic_model_ryjg)
80 81
         )));
81 82
 
82
-        list.add(new WorkModuleBean(TYPE_SLZL, Arrays.asList(
83
-                new WorkModuleBean(TYPE_CFXX, R.drawable.ic_model_cfxx),
83
+        list.add(new WorkModuleBean(PermitConstant.quantity, TYPE_SLZL, Arrays.asList(
84
+                new WorkModuleBean(PermitConstant.house, TYPE_CFXX, R.drawable.ic_model_cfxx),
84 85
 //                new WorkModuleBean(TYPE_RKZL, R.drawable.ic_model_rkzl),
85
-                new WorkModuleBean(TYPE_KCZL, R.drawable.ic_model_kczl),
86
-                new WorkModuleBean(TYPE_CKZL, R.drawable.ic_model_ckzl)
86
+                new WorkModuleBean(PermitConstant.quantity, TYPE_KCZL, R.drawable.ic_model_kczl),
87
+                new WorkModuleBean(PermitConstant.quantity, TYPE_CKZL, R.drawable.ic_model_ckzl)
87 88
         )));
88 89
 
89
-        list.add(new WorkModuleBean(TYPE_CLGL, Arrays.asList(
90
-                new WorkModuleBean(TYPE_LQJC, R.drawable.ic_model_lqjc),
91
-                new WorkModuleBean(TYPE_JXTF, R.drawable.ic_model_jxtf)
90
+        list.add(new WorkModuleBean(0, TYPE_CLGL, Arrays.asList(
91
+                new WorkModuleBean(PermitConstant.grain_check, TYPE_LQJC, R.drawable.ic_model_lqjc),
92
+                new WorkModuleBean(0, TYPE_JXTF, R.drawable.ic_model_jxtf)
92 93
 //                new WorkModuleBean(TYPE_XZGL, R.drawable.ic_model_xzgl)
93 94
         )));
94 95
 
95
-        list.add(new WorkModuleBean(TYPE_YJGL, Arrays.asList(
96
-                new WorkModuleBean(TYPE_YJCG, R.drawable.ic_model_yjcg),
97
-                new WorkModuleBean(TYPE_YJBG, R.drawable.ic_model_yjbg),
98
-                new WorkModuleBean(TYPE_YJLY, R.drawable.ic_model_yjly)
96
+        list.add(new WorkModuleBean(0, TYPE_YJGL, Arrays.asList(
97
+                new WorkModuleBean(0, TYPE_YJCG, R.drawable.ic_model_yjcg),
98
+                new WorkModuleBean(0, TYPE_YJBG, R.drawable.ic_model_yjbg),
99
+                new WorkModuleBean(0, TYPE_YJLY, R.drawable.ic_model_yjly)
99 100
         )));
100 101
 
101 102
 //        list.add(new WorkModuleBean(TYPE_SSSB, Arrays.asList(
@@ -115,8 +116,34 @@ public class WorkbenchModel {
115 116
 //                new WorkModuleBean(TYPE_ZCGL, R.drawable.ic_model_zcgl),
116 117
 //                new WorkModuleBean(TYPE_WTGL, R.drawable.ic_model_wtgl)
117 118
 //        )));
119
+        return list;
120
+    }
121
+
118 122
 
123
+    /**
124
+     * 获取有权限的功能列表
125
+     */
126
+    public List<WorkModuleBean> getModuleList() {
127
+        List<WorkModuleBean> list = new ArrayList<>();
128
+        for (WorkModuleBean item : createModuleList()) {
129
+            // 判断是否有权限
130
+            if (UserModel.get().isPermit(item.getPermitId())) {
131
+
132
+                List<BaseNode> childList = new ArrayList<>();
133
+                for (BaseNode child : item.getChildNode()) {
134
+                    WorkModuleBean childBean = (WorkModuleBean) child;
135
+                    if (UserModel.get().isPermit(childBean.getPermitId())) {
136
+                        childList.add(childBean);
137
+                    }
138
+                }
139
+
140
+                item.setChildList(childList);
141
+
142
+                list.add(item);
143
+            }
144
+        }
119 145
         return list;
146
+
120 147
     }
121 148
 
122
-}
149
+}

+ 2 - 2
app/src/main/res/navigation/nav_graph.xml

@@ -179,7 +179,7 @@
179 179
             android:label="药品保管详情" />
180 180
         <fragment
181 181
             android:id="@+id/quantityQualityHomeFragment"
182
-            android:name="com.unis.sxzcl.ui.inventory_quality.QuantityQualityHomeFragment"
182
+            android:name="com.unis.sxzcl.ui.quantity_quality.QuantityQualityHomeFragment"
183 183
             android:label="库存质量" >
184 184
             <action
185 185
                 android:id="@+id/action_quantityQualityHomeFragment_to_quantityQualityDetailFragment"
@@ -246,7 +246,7 @@
246 246
         </fragment>
247 247
     <fragment
248 248
         android:id="@+id/quantityQualityDetailFragment"
249
-        android:name="com.unis.sxzcl.ui.inventory_quality.QuantityQualityDetailFragment"
249
+        android:name="com.unis.sxzcl.ui.quantity_quality.QuantityQualityDetailFragment"
250 250
         android:label="库存质量详情" />
251 251
     <fragment
252 252
         android:id="@+id/policyDetailFragment"

+ 74 - 0
model/src/main/java/com/unis/model/PermitConstant.java

@@ -0,0 +1,74 @@
1
+package com.unis.model;
2
+
3
+/**
4
+ * 权限常量
5
+ * 创建人: mQ
6
+ * 创建时间: 2021/2/3 9:21
7
+ */
8
+public class PermitConstant {
9
+
10
+    /******************** 库点 ********************/
11
+    // 库点
12
+    public static final int depot = 101;
13
+    public static final int depot_add = 102;
14
+    public static final int depot_update = 103;
15
+    public static final int depot_del = 104;
16
+    public static final int depot_read = 105;
17
+
18
+
19
+    /******************** 仓房 ********************/
20
+    // 仓房
21
+    public static final int house = 107;
22
+    // 查看
23
+    public static final int house_read = 109;
24
+    // 新增
25
+    public static final int house_add = 110;
26
+    // 修改
27
+    public static final int house_update = 111;
28
+    // 删除
29
+    public static final int house_del = 111;
30
+
31
+
32
+    /******************** 库存/出库质量 ********************/
33
+    // 库存/出库质量
34
+    public static final int quantity = 151;
35
+    // 新增
36
+    public static final int quantity_add = 153;
37
+    // 修改
38
+    public static final int quantity_update = 154;
39
+    // 删除
40
+    public static final int quantity_del = 155;
41
+    // 查看单个对象
42
+    public static final int quantity_read_single = 156;
43
+
44
+
45
+    /******************** 粮情检查 ********************/
46
+    // 粮情检查
47
+    public static final int grain_check = 126;
48
+    // 新增
49
+    public static final int grain_check_add = 131;
50
+    // 修改
51
+    public static final int grain_check_update = 135;
52
+    // 删除
53
+    public static final int grain_check_del = 136;
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+}

+ 1 - 1
model/src/main/java/com/unis/model/UrlPath.java

@@ -42,7 +42,7 @@ public class UrlPath {
42 42
     // 用户信息
43 43
     public static final String user_info = host + "/api/csc-szls-system-manage/user/authority/getById";
44 44
     // 角色权限
45
-    public static final String role_permit = host + "/api/csc-szls-system-manage/role/authority/getByColeId";
45
+    public static final String role_permit = host + "/api/csc-szls-system-manage/role/authority/getAllResource";
46 46
 
47 47
 
48 48
     /****************** 库 ******************/

+ 43 - 8
model/src/main/java/com/unis/model/UserModel.java

@@ -15,6 +15,7 @@ import com.unis.model.bean.user.UserBean;
15 15
 import com.xyxsbj.mylibrary.tool.SPTool;
16 16
 import com.xyxsbj.mylibrary.tool.ToastTool;
17 17
 
18
+import org.jetbrains.annotations.NotNull;
18 19
 import org.json.JSONException;
19 20
 
20 21
 import java.io.File;
@@ -70,7 +71,7 @@ public class UserModel {
70 71
                     protected void onSuccessResult(Response<String> response) throws JSONException {
71 72
                         Gson gson = new Gson();
72 73
                         String dataJson = getDataJson(response.body());
73
-                        LoginBean bean = gson.fromJson(dataJson, LoginBean.class);
74
+                        final LoginBean bean = gson.fromJson(dataJson, LoginBean.class);
74 75
 
75 76
                         // 保存用户信息
76 77
                         String userInfo = gson.toJson(bean.getUser());
@@ -98,10 +99,22 @@ public class UserModel {
98 99
                         // 枚举字典
99 100
                         BasicModel.get().getEnumDic();
100 101
                         // 获取角色权限
101
-                        getPermit();
102
+                        getPermit(new DataCallback<String>() {
103
+                            @Override
104
+                            public void onSuccess(String data) {
105
+                                if (callBack != null)
106
+                                    callBack.onSuccess(bean);
107
+                            }
108
+
109
+                            @Override
110
+                            public void onError(String error) {
111
+                                super.onError(error);
112
+                                if (callBack != null)
113
+                                    callBack.onSuccess(bean);
114
+                            }
115
+                        });
116
+
102 117
 
103
-                        if (callBack != null)
104
-                            callBack.onSuccess(bean);
105 118
                     }
106 119
 
107 120
                     @Override
@@ -212,7 +225,7 @@ public class UserModel {
212 225
         ProcessModel.get().removeSelectTodo();
213 226
 
214 227
         // 移除角色权限
215
-        permitMap = new HashMap<>();
228
+        permitMap = null;
216 229
         SPTool.remove(Constant.KEY_ROLE_PERMIT);
217 230
     }
218 231
 
@@ -352,7 +365,7 @@ public class UserModel {
352 365
     /**
353 366
      * 获取角色权限
354 367
      */
355
-    public void getPermit() {
368
+    public void getPermit(final DataCallback<String> callback) {
356 369
         OkGo.<String>get(UrlPath.role_permit)
357 370
                 .params("id", getUser().getRoleIds())
358 371
                 .execute(new MyStringCallback() {
@@ -361,11 +374,13 @@ public class UserModel {
361 374
                         String json = getDataJson(response);
362 375
                         SPTool.saveString(Constant.KEY_ROLE_PERMIT, json);
363 376
                         getCachePermit();
377
+                        callback.onSuccess(null);
364 378
                     }
365 379
 
366 380
                     @Override
367 381
                     public void onError(Response<String> response) {
368 382
                         super.onError(response);
383
+                        callback.onError(getErrorMsg(response));
369 384
                     }
370 385
                 });
371 386
     }
@@ -375,6 +390,7 @@ public class UserModel {
375 390
      */
376 391
     private Map<Integer, Boolean> getCachePermit() {
377 392
         if (permitMap != null) return permitMap;
393
+        permitMap = new HashMap<>();
378 394
 
379 395
         String json = SPTool.getString(Constant.KEY_ROLE_PERMIT, null);
380 396
         List<Integer> list = new Gson().fromJson(json, new TypeToken<List<Integer>>() {
@@ -391,8 +407,27 @@ public class UserModel {
391 407
     /**
392 408
      * 判断是否有权限
393 409
      */
394
-    public boolean isPermit(int permitId) {
395
-        return getCachePermit().get(permitId);
410
+    public boolean isPermit(@NotNull int... permitId) {
411
+        for (int id : permitId) {
412
+            // 0有权限
413
+            if (id == 0)
414
+                continue;
415
+            // 权限缓存中是否有权限
416
+            if (!getCachePermit().containsKey(id))
417
+                return false;
418
+        }
419
+        return true;
396 420
     }
397 421
 
422
+
423
+
424
+
425
+
426
+
427
+
428
+
429
+
430
+
431
+
432
+
398 433
 }