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;
|
}
|
}
|
}
|