From 42e68faca0756d44b7c880c9876810ee47d6e92b Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期一, 17 二月 2025 17:57:25 +0800
Subject: [PATCH] 1.DNC模块,设备结构树权限分配优化与修改bug 2.MDC模块,设备编辑车间同步平移设备send目录 3.优化原有指派设备代码

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java |  157 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 140 insertions(+), 17 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 1937aa0..66a807d 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;
@@ -21,27 +25,29 @@
 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.MdcEquipmentDepart;
-import org.jeecg.modules.system.entity.MdcProduction;
-import org.jeecg.modules.system.entity.MdcProductionEquipment;
-import org.jeecg.modules.system.entity.SysDepart;
+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.IMdcProductionService;
-import org.jeecg.modules.system.service.IMdcUserProductionService;
-import org.jeecg.modules.system.service.ISysDepartService;
-import org.jeecg.modules.system.service.ISysUserDepartService;
+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;
@@ -94,6 +100,15 @@
     @Resource
     private IMdcOverrunAlarmService mdcOverrunAlarmService;
 
+    @Resource
+    private ISysParamsService ISysParamsService;
+
+    @Resource
+    private DncDevicePermissionMapper dncDevicePermissionMapper;
+
+    @Value("${fileNCPath}")
+    private String fileNCPath;
+
 
     @Override
     public Map<String, String> getDepNamesByEquipmentIds(List<String> equipmentIds) {
@@ -114,8 +129,40 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void saveMdcEquipment(MdcEquipment mdcEquipment, String selectedDeparts, String selectedProduction) {
+        if (mdcEquipment.getSystemValue()!=null) {
+            switch (mdcEquipment.getSystemValue()){
+                case "1":
+                    mdcEquipment.setDeviceTypeDnc("1");
+                    break;
+                case "2":
+                    mdcEquipment.setDeviceTypeMdc("1");
+                    break;
+                case "3":
+                    mdcEquipment.setDeviceTypeDnc("1");
+                    mdcEquipment.setDeviceTypeMdc("1");
+                    break;
+            }
+        }else {
+            //鑾峰彇绯荤粺绫诲瀷
+            SysParams sysParams = ISysParamsService.getSysPramBySettingKey("system_type");
+            //MDC绯荤粺
+            if ("-1".equals(sysParams.getSettingValue())){
+                mdcEquipment.setDeviceTypeMdc("1");
+            }
+            //DNC绯荤粺
+            if ("1".equals(sysParams.getSettingValue())) {
+                mdcEquipment.setDeviceTypeDnc("1");
+            }
+        }
         //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(",");
@@ -132,12 +179,38 @@
                 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;
+            }
+        }
+        //骞崇Щ璁惧鐩綍涓嬬幇鏈夌粨鏋勪笌鏂囦欢
+        //鑾峰彇鍘熸湁缁撴瀯
+        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 淇敼閮ㄩ棬
@@ -154,6 +227,8 @@
                 mdcEquipmentDepartMapper.insert(equipmentDepart);
             }
         }
+        //鍒犻櫎鎵�鏈夎澶囨潈闄�
+        dncDevicePermissionMapper.delete(new QueryWrapper<DncDevicePermission>().lambda().eq(DncDevicePermission::getDeviceId, mdcEquipment.getId()));
         //step.3 淇敼浜х嚎
         String productions = mdcEquipment.getSelectedProduction();
         String[] array = {};
@@ -168,6 +243,38 @@
                 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();
+        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
@@ -180,7 +287,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;
     }
 
@@ -221,6 +329,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
@@ -295,7 +405,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鑾峰彇鎷ユ湁鐨勪骇绾夸俊鎭泦鍚�
@@ -312,7 +422,7 @@
         //缁勮浜х嚎璁惧鏍�
         List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
         //濉厖璁惧鏁版嵁
-        FillEquipmentByProduction(treeList,type);
+        FillEquipmentByProduction(treeList);
         return treeList;
     }
 
@@ -611,9 +721,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);
@@ -625,7 +735,7 @@
                 mdcEquipmentTree.setLeaf(false);
             }
             if (!mdcEquipmentTree.getChildren().isEmpty()) {
-                FillEquipmentByProduction(mdcEquipmentTree.getChildren(),type);
+                FillEquipmentByProduction(mdcEquipmentTree.getChildren());
             }
         }
     }
@@ -734,7 +844,20 @@
             List<String> productionIds = mdcProductionService.recursionChildren(mdcEquipment.getProductionName());
             mdcEquipment.setProductionIds(productionIds);
         }
-        return this.baseMapper.pageList(page, mdcEquipment);
+        IPage<MdcEquipment> equipmentIPage= this.baseMapper.pageList(page, mdcEquipment);
+        equipmentIPage.getRecords().forEach(item->{
+            if (("1").equals(item.getDeviceTypeDnc())&&("1").equals(item.getDeviceTypeMdc())){
+                item.setSystemValue("3");
+            }else {
+                if (("1").equals(item.getDeviceTypeDnc())){
+                    item.setSystemValue("1");
+                }
+                if (("1").equals(item.getDeviceTypeMdc())){
+                    item.setSystemValue("2");
+                }
+            }
+        });
+        return equipmentIPage;
     }
 
     /**
@@ -820,7 +943,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));
@@ -836,7 +959,7 @@
         //缁勮浜х嚎璁惧鏍�
         List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
         //濉厖璁惧鏁版嵁
-        FillEquipmentByProduction(treeList,type);
+        FillEquipmentByProduction(treeList);
         return treeList;
     }
 

--
Gitblit v1.9.3