lyh
2025-01-17 ea704e018a27c26ef6deeaea4adc8a28b4d0b27e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
package org.jeecg.modules.dnc.service.impl;
 
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.dnc.service.*;
import org.jeecg.modules.dnc.ucenter.Department;
import org.jeecg.modules.dnc.utils.ValidateUtil;
 
import org.jeecg.modules.dnc.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
@Service
public class UserPermButtonServiceImpl implements IUserPermButtonService {
    @Autowired
    private IButtonService buttonService;
    @Autowired
    private IProductInfoService productInfoService;
    @Autowired
    private IComponentInfoService componentInfoService;
    @Autowired
    private IPartsInfoService partsInfoService;
    @Autowired
    private IDepartmentService departmentService;
    @Autowired
    private IPermissionStreamService permissionStreamService;
    @Autowired
    private IDeviceInfoService deviceInfoService;
    @Autowired
    private IDevicePermissionService devicePermissionService;
    @Autowired
    private IProcessStreamService processStreamService;
    @Autowired
    private IDeviceGroupService deviceGroupService;
    @Autowired
    private IDevicePermissionStreamService devicePermissionStreamService;
 
    /**
     * 判定产品数节点权限
     * TODO 待完善
     * @param param
     * @param objectId
     * @param userId
     * @return
     */
    @Override
    public Boolean checkObjectValid(String param, String objectId, String userId) {
        if(!ValidateUtil.validateString(param) || !ValidateUtil.validateString(objectId))
            return null;
        if("product".equals(param)) {
            //右键某个产品
            ProductInfo productInfo = productInfoService.getById(objectId);
            if(productInfo == null)
                return null;
            //校验是否有该产品的权限
            boolean b = productInfoService.checkProductPerm(1, objectId);
            if(!b) {
                return null;
            }
            //获取产品所在部门
            List<PermissionStream> departPerms = permissionStreamService.getByProductId(productInfo.getProductId());
            if(departPerms == null || departPerms.isEmpty())
                return false;
            //获取用户所在部门
            Map<String, Department> departmentMap = departmentService.getMapByUserId(userId);
            if(departmentMap == null || departmentMap.isEmpty())
                return null;
            for(PermissionStream stream : departPerms) {
                if(departmentMap.containsKey(stream.getDepartId())) {
                    return true;
                }
            }
        }else if("component".equals(param)) {
            //右键某个部件
            ComponentInfo componentInfo = componentInfoService.getById(objectId);
            if(componentInfo == null)
                return null;
            //校验是否有该部件的权限
            boolean b = productInfoService.checkProductPerm(2, objectId);
            if(!b) {
                return null;
            }
            //获取部件所在部门
            List<PermissionStream> departPerms = permissionStreamService.getByComponentId(componentInfo.getProductId(), componentInfo.getComponentId());
            if(departPerms == null || departPerms.isEmpty())
                return false;
            //获取用户所在部门
            Map<String, Department> departmentMap = departmentService.getMapByUserId(userId);
            if(departmentMap == null || departmentMap.isEmpty())
                return null;
            for(PermissionStream stream : departPerms) {
                if(departmentMap.containsKey(stream.getDepartId())) {
                    return true;
                }
            }
        }else if("parts".equals(param)) {
            //右键某个零件
            PartsInfo partsInfo = partsInfoService.getById(objectId);
            if(partsInfo == null)
                return null;
            //校验是否有该零件的权限
            boolean b = productInfoService.checkProductPerm(3, objectId);
            if(!b) {
                return null;
            }
            //获取部件所在部门
            List<PermissionStream> departPerms = permissionStreamService.getByPartsId(partsInfo.getProductId(), partsInfo.getComponentId(), partsInfo.getPartsId());
            if(departPerms == null || departPerms.isEmpty())
                return false;
            //获取用户所在部门
            Map<String, Department> departmentMap = departmentService.getMapByUserId(userId);
            if(departmentMap == null || departmentMap.isEmpty())
                return null;
            for(PermissionStream stream : departPerms) {
                if(departmentMap.containsKey(stream.getDepartId())) {
                    return true;
                }
            }
        }else if("device".equals(param)) {
            //右键设备
            DeviceInfo deviceInfo = deviceInfoService.getById(objectId);
            if(deviceInfo == null)
                return null;
            //校验是否有该零件的权限
            boolean b = deviceInfoService.checkDevicePerm(2, objectId);
            if(!b) {
                return null;
            }
            if(!ValidateUtil.validateString(deviceInfo.getDepartId()))
                return false;
            //获取用户所在部门
            Map<String, Department> departmentMap = departmentService.getMapByUserId(userId);
            if(departmentMap == null || departmentMap.isEmpty())
                return null;
            if(departmentMap.containsKey(deviceInfo.getDepartId())) {
                return true;
            }
        } else if("device_group".equals(param)) {
            //右键设备
            DeviceGroup deviceGroup = deviceGroupService.getById(objectId);
            if(deviceGroup == null)
                return null;
            //校验是否有该分组的权限
            boolean b = deviceInfoService.checkDevicePerm(1, objectId);
            if(!b) {
                return null;
            }
            //获取部件所在部门
            List<DevicePermissionStream> permissionStreams = devicePermissionStreamService.getDepartPermByGroupId(deviceGroup.getGroupId());
            if(permissionStreams == null || permissionStreams.isEmpty())
                return false;
            //获取用户所在部门
            Map<String, Department> departmentMap = departmentService.getMapByUserId(userId);
            if(departmentMap == null || departmentMap.isEmpty())
                return null;
            for(DevicePermissionStream stream : permissionStreams) {
                if(departmentMap.containsKey(stream.getDepartId())) {
                    return true;
                }
            }
        }
        return null;
    }
 
    /**
     * 获取产品数节点权限
     * TODO 待完善
     * @param param
     * @param flag
     * @param objectId
     * @param relativeParam
     * @param relativeObjectId
     * @return
     */
    @Override
    public List<String> getCurrentUserButtonPerms(String param, Integer flag, String objectId, String relativeParam, String relativeObjectId) {
        if(!ValidateUtil.validateString(param))
            return null;
        if(!ValidateUtil.validateInteger(flag))
            return null;
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = user.getId();
        if(!ValidateUtil.validateString(userId))
            return null;
        List<String> permsList = new ArrayList<>();
        List<String> objectPermsList = new ArrayList<>();
        List<Button> buttonPerms = buttonService.getButtonPerms(userId);
        if(buttonPerms != null && !buttonPerms.isEmpty()) {
            buttonPerms.forEach(item -> {
                permsList.add(item.getButtonPerm());
                objectPermsList.add(item.getButtonPerm());
            });
        }
        if(flag == 1) {
            List<Button> list = buttonService.getMenuButtonPerms(userId, param);
            if(list == null || list.isEmpty())
                return permsList;
            for(Button button : list) {
                if(ValidateUtil.validateString(button.getPermCode())) {
                    permsList.add(button.getPermCode());
                }
            }
        }else if(flag == 2) {
            List<Button> list = buttonService.getObjectButtonPerms(userId, param);
            if(list == null || list.isEmpty())
                return permsList;
            for(Button button : list) {
                if(ValidateUtil.validateString(button.getPermCode())) {
                    objectPermsList.add(button.getPermCode());
                }
            }
            if("product".equals(param)) {
                if(ValidateUtil.validateString(objectId)) {
                    Boolean checkValue = checkObjectValid(param, objectId, userId);
                    return getCurrentPerms(checkValue, permsList, objectPermsList);
                }else {
                    //右键产品结构树空白区
                    return objectPermsList;
                }
            } else if("component".equals(param) || "parts".equals(param)) {
                if(ValidateUtil.validateString(objectId)) {
                    Boolean checkValue = checkObjectValid(param, objectId, userId);
                    return getCurrentPerms(checkValue, permsList, objectPermsList);
                }else {
                    //右键产品结构树空白区
                    return null;
                }
            }else if("process".equals(param) || "document".equals(param) || "file".equals(param)) {
                if(!ValidateUtil.validateString(relativeParam) || !ValidateUtil.validateString(relativeObjectId)) {
                    return null;
                }
                Boolean checkValue = checkObjectValid(relativeParam, relativeObjectId, userId);
                return getCurrentPerms(checkValue, permsList, objectPermsList);
            }else if("device".equals(param)) {
                if(ValidateUtil.validateString(objectId)) {
                    Boolean checkValue = checkObjectValid(param, objectId, userId);
                    return getCurrentPerms(checkValue, permsList, objectPermsList);
                }else {
                    //右键设备空白区
                    return null;
                }
            }else if("device_group".equals(param)) {
                if(ValidateUtil.validateString(objectId)) {
                    //右键设备分组
                    Boolean checkValue = checkObjectValid(param, objectId, userId);
                    return getCurrentPerms(checkValue, permsList, objectPermsList);
                }else {
                    //右键设备树空白区
                    return objectPermsList;
                }
            }else {
                return null;
            }
        }else {
            return null;
        }
        return permsList;
    }
 
    private List<String> getCurrentPerms(Boolean b , List<String> permsList, List<String> objectPermsList) {
        if(b == null)
            return null;
        if(b) {
            return objectPermsList;
        }else {
            return permsList;
        }
    }
}