From eec61b51d7b64695d177c7cedd2da49f03f8c26e Mon Sep 17 00:00:00 2001 From: Lius <Lius2225@163.com> Date: 星期四, 13 三月 2025 16:59:17 +0800 Subject: [PATCH] update --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java | 77 +++++++++++++++++++++++++++++++------- 1 files changed, 62 insertions(+), 15 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 84ee56f..d785c97 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,7 +3,9 @@ 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; @@ -18,28 +20,34 @@ import org.jeecg.modules.mdc.dto.MdcEquipmentDetailedDto; import org.jeecg.modules.mdc.dto.MdcEquipmentDto; import org.jeecg.modules.mdc.entity.*; -import org.jeecg.modules.mdc.mapper.DncDevicePermissionMapper; import org.jeecg.modules.mdc.mapper.MdcEquipmentMapper; import org.jeecg.modules.mdc.mapper.MdcTorqueConfigMapper; import org.jeecg.modules.mdc.model.MdcEquipmentTree; import org.jeecg.modules.mdc.service.*; import org.jeecg.modules.mdc.util.DateUtils; +import org.jeecg.modules.mdc.util.DncCopyEquipment; import org.jeecg.modules.mdc.util.FindsEquipmentDepartUtil; 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.*; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.CacheEvict; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.io.File; +import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -96,7 +104,10 @@ private ISysParamsService ISysParamsService; @Resource - private DncDevicePermissionMapper dncDevicePermissionMapper; + private IDncDevicePermissionService iDncDevicePermissionService; + + @Value("${fileNCPath}") + private String fileNCPath; @Override @@ -147,11 +158,7 @@ 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); + iDncDevicePermissionService.addDevicePermission(mdcEquipment.getId(), user.getId()); //step.2 淇濆瓨鎵�灞為儴闂� if (oConvertUtils.isNotEmpty(selectedDeparts)) { String[] arr = selectedDeparts.split(","); @@ -168,6 +175,8 @@ mdcProductionEquipmentMapper.insert(mdcProductionEquipment); } } + //step.3 淇濆瓨璁惧瀵瑰簲鐨勪骇绾挎潈闄� + addDevicePermission(mdcEquipment); } @Override @@ -190,6 +199,14 @@ break; } } + //骞崇Щ璁惧鐩綍涓嬬幇鏈夌粨鏋勪笌鏂囦欢 + //鑾峰彇鍘熸湁缁撴瀯 + String OldPath=""; + String NewPath=""; + List<String> OldStrings=mdcProductionService.findListParentTreeAll(mdcEquipment.getId()); + if (OldStrings != null && !OldStrings.isEmpty()) { + OldPath = fileNCPath+"/"+StringUtils.join(OldStrings.toArray(), "/")+"/"+mdcEquipment.getEquipmentId(); + } //step.1 淇敼璁惧鍩虹淇℃伅 this.updateById(mdcEquipment); //step.2 淇敼閮ㄩ棬 @@ -206,6 +223,8 @@ mdcEquipmentDepartMapper.insert(equipmentDepart); } } + //鍒犻櫎鎵�鏈夎澶囨潈闄� + iDncDevicePermissionService.remove(new QueryWrapper<DncDevicePermission>().lambda().eq(DncDevicePermission::getDeviceId, mdcEquipment.getId())); //step.3 淇敼浜х嚎 String productions = mdcEquipment.getSelectedProduction(); String[] array = {}; @@ -220,6 +239,31 @@ mdcProductionEquipmentMapper.insert(productionEquipment); } } + List<String> NewStrings = mdcProductionService.findListParentTreeAll(mdcEquipment.getId()); + if (NewStrings != null && !NewStrings.isEmpty()) { + NewPath = fileNCPath+"/"+StringUtils.join(NewStrings.toArray(), "/")+"/"+mdcEquipment.getEquipmentId(); + } + // 骞崇ЩOldPath涓嬬殑鏂囦欢鍒癗ewPath涓� + DncCopyEquipment.CopyEquipmentPath(OldPath,NewPath); + //淇濆瓨璁惧瀵瑰簲鐨勪骇绾挎潈闄� + addDevicePermission(mdcEquipment); + //step.4 淇敼璁惧鏉冮檺 + LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + List<DncDevicePermission> dncDevicePermissions=iDncDevicePermissionService.list(new LambdaQueryWrapper<DncDevicePermission>() + .eq(DncDevicePermission::getDeviceId, mdcEquipment.getId()).eq(DncDevicePermission ::getUserId, user.getId())); + if (CollectionUtils.isEmpty(dncDevicePermissions)){ + iDncDevicePermissionService.addDevicePermission(mdcEquipment.getId(), user.getId()); + } + } + + 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->{ + iDncDevicePermissionService.addDevicePermission(mdcEquipment.getId(), item.getUserId()); + }); } @Override @@ -232,7 +276,8 @@ line += mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().eq(MdcEquipmentDepart::getEquipmentId, id)); // 3. 鍒犻櫎璁惧浜х嚎鍏崇郴 line += mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getEquipmentId, id)); - + // 4. 鍒犻櫎璁惧鏉冮檺 + line += iDncDevicePermissionService.remove(new LambdaQueryWrapper<DncDevicePermission>().eq(DncDevicePermission::getDeviceId, id))? 1 : 0; return line != 0; } @@ -273,6 +318,8 @@ @Override public void removeEquipmentForProduction(String productionId, String equipmentId) { mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getProductionId, productionId).eq(MdcProductionEquipment::getEquipmentId, equipmentId)); + //绉婚櫎璁惧鏉冮檺 + iDncDevicePermissionService.remove(new LambdaQueryWrapper<DncDevicePermission>().eq(DncDevicePermission::getDeviceId, equipmentId)); } @Override @@ -347,7 +394,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鑾峰彇鎷ユ湁鐨勪骇绾夸俊鎭泦鍚� @@ -364,7 +411,7 @@ //缁勮浜х嚎璁惧鏍� List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list); //濉厖璁惧鏁版嵁 - FillEquipmentByProduction(treeList,type); + FillEquipmentByProduction(treeList); return treeList; } @@ -663,9 +710,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); @@ -677,7 +724,7 @@ mdcEquipmentTree.setLeaf(false); } if (!mdcEquipmentTree.getChildren().isEmpty()) { - FillEquipmentByProduction(mdcEquipmentTree.getChildren(),type); + FillEquipmentByProduction(mdcEquipmentTree.getChildren()); } } } @@ -885,7 +932,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)); @@ -901,7 +948,7 @@ //缁勮浜х嚎璁惧鏍� List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list); //濉厖璁惧鏁版嵁 - FillEquipmentByProduction(treeList,type); + FillEquipmentByProduction(treeList); return treeList; } -- Gitblit v1.9.3