From ce93b6e846a9688db550ed40e6718c0e58d524ec Mon Sep 17 00:00:00 2001 From: lyh <925863403@qq.com> Date: 星期一, 17 二月 2025 11:18:36 +0800 Subject: [PATCH] 设备权限 --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java | 79 +++++++++++++++++++++++++++++++++++---- 1 files changed, 71 insertions(+), 8 deletions(-) diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java index b71a4db..39fc70b 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java @@ -3,13 +3,17 @@ import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.commons.lang3.StringUtils; +import org.apache.shiro.SecurityUtils; import org.jeecg.common.api.dto.message.MessageDTO; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.system.api.ISysBaseAPI; +import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.mdc.dto.MdcEquDepDto; import org.jeecg.modules.mdc.dto.MdcEquProDto; @@ -25,6 +29,7 @@ import org.jeecg.modules.mdc.util.FindsEquipmentProductionUtil; import org.jeecg.modules.mdc.vo.*; import org.jeecg.modules.system.entity.*; +import org.jeecg.modules.system.mapper.DncDevicePermissionMapper; import org.jeecg.modules.system.mapper.MdcEquipmentDepartMapper; import org.jeecg.modules.system.mapper.MdcProductionEquipmentMapper; import org.jeecg.modules.system.service.*; @@ -92,6 +97,9 @@ @Resource private ISysParamsService ISysParamsService; + @Resource + private DncDevicePermissionMapper dncDevicePermissionMapper; + @Override public Map<String, String> getDepNamesByEquipmentIds(List<String> equipmentIds) { @@ -139,6 +147,13 @@ } //step.1 淇濆瓨璁惧 this.save(mdcEquipment); + //DNC娣诲姞璁惧鏉冮檺 + LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + String userId = user.getId(); + DncDevicePermission dncDevicePermission=new DncDevicePermission(); + dncDevicePermission.setDeviceId(mdcEquipment.getId()); + dncDevicePermission.setUserId(userId); + dncDevicePermissionMapper.insert(dncDevicePermission); //step.2 淇濆瓨鎵�灞為儴闂� if (oConvertUtils.isNotEmpty(selectedDeparts)) { String[] arr = selectedDeparts.split(","); @@ -155,12 +170,30 @@ mdcProductionEquipmentMapper.insert(mdcProductionEquipment); } } + //step.3 淇濆瓨璁惧瀵瑰簲鐨勪骇绾挎潈闄� + addDevicePermission(mdcEquipment); } @Override @Transactional(rollbackFor = Exception.class) @CacheEvict(value = {"mdc:cache:encrypt:equipment"}, allEntries = true) public void editMdcEquipment(MdcEquipment mdcEquipment) { + if (mdcEquipment.getSystemValue()!=null) { + switch (mdcEquipment.getSystemValue()){ + case "1": + mdcEquipment.setDeviceTypeDnc("1"); + mdcEquipment.setDeviceTypeMdc("0"); + break; + case "2": + mdcEquipment.setDeviceTypeDnc("0"); + mdcEquipment.setDeviceTypeMdc("1"); + break; + case "3": + mdcEquipment.setDeviceTypeDnc("1"); + mdcEquipment.setDeviceTypeMdc("1"); + break; + } + } //step.1 淇敼璁惧鍩虹淇℃伅 this.updateById(mdcEquipment); //step.2 淇敼閮ㄩ棬 @@ -177,6 +210,8 @@ mdcEquipmentDepartMapper.insert(equipmentDepart); } } + //鍒犻櫎鎵�鏈夎澶囨潈闄� + dncDevicePermissionMapper.delete(new QueryWrapper<DncDevicePermission>().lambda().eq(DncDevicePermission::getDeviceId, mdcEquipment.getId())); //step.3 淇敼浜х嚎 String productions = mdcEquipment.getSelectedProduction(); String[] array = {}; @@ -191,6 +226,31 @@ mdcProductionEquipmentMapper.insert(productionEquipment); } } + addDevicePermission(mdcEquipment); + //step.4 淇敼璁惧鏉冮檺 + LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + String userId = user.getId(); + List<DncDevicePermission> dncDevicePermissions=dncDevicePermissionMapper.selectList(new LambdaQueryWrapper<DncDevicePermission>() + .eq(DncDevicePermission::getDeviceId, mdcEquipment.getId()).eq(DncDevicePermission ::getUserId, userId)); + if (CollectionUtils.isEmpty(dncDevicePermissions)){ + DncDevicePermission dncDevicePermission=new DncDevicePermission(); + dncDevicePermission.setDeviceId(mdcEquipment.getId()); + dncDevicePermission.setUserId(userId); + dncDevicePermissionMapper.insert(dncDevicePermission); + } + } + + private void addDevicePermission(MdcEquipment mdcEquipment) { + List<String> productionIds=mdcProductionEquipmentMapper + .selectList(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getEquipmentId, mdcEquipment.getId())) + .stream().map(MdcProductionEquipment::getProductionId).collect(Collectors.toList()); + List<MdcUserProduction> mdcUserProductionList=mdcUserProductionService.queryByProductionIds(productionIds); + mdcUserProductionList.forEach(item->{ + DncDevicePermission devicePermission=new DncDevicePermission(); + devicePermission.setDeviceId(mdcEquipment.getId()); + devicePermission.setUserId(item.getUserId()); + dncDevicePermissionMapper.insert(devicePermission); + }); } @Override @@ -203,7 +263,8 @@ line += mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().eq(MdcEquipmentDepart::getEquipmentId, id)); // 3. 鍒犻櫎璁惧浜х嚎鍏崇郴 line += mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getEquipmentId, id)); - + // 4. 鍒犻櫎璁惧鏉冮檺 + line += dncDevicePermissionMapper.delete(new LambdaQueryWrapper<DncDevicePermission>().eq(DncDevicePermission::getDeviceId, id)); return line != 0; } @@ -244,6 +305,8 @@ @Override public void removeEquipmentForProduction(String productionId, String equipmentId) { mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getProductionId, productionId).eq(MdcProductionEquipment::getEquipmentId, equipmentId)); + //绉婚櫎璁惧鏉冮檺 + dncDevicePermissionMapper.delete(new LambdaQueryWrapper<DncDevicePermission>().eq(DncDevicePermission::getDeviceId, equipmentId)); } @Override @@ -318,7 +381,7 @@ @Override - public List<MdcEquipmentTree> loadTreeListByProduction(String userId,String type) { + public List<MdcEquipmentTree> loadTreeListByProduction(String userId) { //鑾峰彇鎵�鏈変骇绾挎暟鎹� List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder)); //鏍规嵁鐢ㄦ埛id鑾峰彇鎷ユ湁鐨勪骇绾夸俊鎭泦鍚� @@ -335,7 +398,7 @@ //缁勮浜х嚎璁惧鏍� List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list); //濉厖璁惧鏁版嵁 - FillEquipmentByProduction(treeList,type); + FillEquipmentByProduction(treeList); return treeList; } @@ -634,9 +697,9 @@ /** * 浜х嚎璁惧鏍戝~鍏呰澶囨暟鎹� */ - private void FillEquipmentByProduction(List<MdcEquipmentTree> treeList,String type) { + private void FillEquipmentByProduction(List<MdcEquipmentTree> treeList) { for (MdcEquipmentTree mdcEquipmentTree : treeList) { - List<MdcEquipment> equipmentList = this.baseMapper.queryByProductionId(mdcEquipmentTree.getKey(),type); + List<MdcEquipment> equipmentList = this.baseMapper.queryByProductionId(mdcEquipmentTree.getKey()); if (equipmentList != null && !equipmentList.isEmpty()) { for (MdcEquipment mdcEquipment : equipmentList) { MdcEquipmentTree tree = new MdcEquipmentTree().convert(mdcEquipment); @@ -648,7 +711,7 @@ mdcEquipmentTree.setLeaf(false); } if (!mdcEquipmentTree.getChildren().isEmpty()) { - FillEquipmentByProduction(mdcEquipmentTree.getChildren(),type); + FillEquipmentByProduction(mdcEquipmentTree.getChildren()); } } } @@ -856,7 +919,7 @@ * @return */ @Override - public List<MdcEquipmentTree> loadTreeListByProductionIds(String ids,String type) { + public List<MdcEquipmentTree> loadTreeListByProductionIds(String ids) { List<String> productionIds = Arrays.asList(ids.split(",")); //鑾峰彇鎵�鏈変骇绾挎暟鎹� List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder)); @@ -872,7 +935,7 @@ //缁勮浜х嚎璁惧鏍� List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list); //濉厖璁惧鏁版嵁 - FillEquipmentByProduction(treeList,type); + FillEquipmentByProduction(treeList); return treeList; } -- Gitblit v1.9.3