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 departPerms = permissionStreamService.getByProductId(productInfo.getProductId()); if(departPerms == null || departPerms.isEmpty()) return false; //获取用户所在部门 Map 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 departPerms = permissionStreamService.getByComponentId(componentInfo.getProductId(), componentInfo.getComponentId()); if(departPerms == null || departPerms.isEmpty()) return false; //获取用户所在部门 Map 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 departPerms = permissionStreamService.getByPartsId(partsInfo.getProductId(), partsInfo.getComponentId(), partsInfo.getPartsId()); if(departPerms == null || departPerms.isEmpty()) return false; //获取用户所在部门 Map 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 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 permissionStreams = devicePermissionStreamService.getDepartPermByGroupId(deviceGroup.getGroupId()); if(permissionStreams == null || permissionStreams.isEmpty()) return false; //获取用户所在部门 Map 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 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 permsList = new ArrayList<>(); List objectPermsList = new ArrayList<>(); List