From f2f8241dd52ef12ec109f6f4f0f13042055338ac Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期五, 14 二月 2025 14:55:56 +0800
Subject: [PATCH] 修改指派设备 修改设备结构树权限 优化查询 优化排序

---
 lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceInfoServiceImpl.java |  145 +++++++++++++++++++++++++++---------------------
 1 files changed, 81 insertions(+), 64 deletions(-)

diff --git a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceInfoServiceImpl.java b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceInfoServiceImpl.java
index 60a0d52..d55f9d9 100644
--- a/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceInfoServiceImpl.java
+++ b/lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/DeviceInfoServiceImpl.java
@@ -1,6 +1,7 @@
 package org.jeecg.modules.dnc.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.system.vo.LoginUser;
@@ -14,7 +15,13 @@
 import org.jeecg.modules.dnc.ucenter.UserDepartExt;
 import org.jeecg.modules.dnc.utils.ValidateUtil;
 import org.jeecg.modules.dnc.entity.*;
+import org.jeecg.modules.mdc.entity.MdcEquipment;
+import org.jeecg.modules.mdc.service.IMdcEquipmentService;
+import org.jeecg.modules.mdc.service.IMdcProductionEquipmentService;
+import org.jeecg.modules.system.entity.MdcProduction;
+import org.jeecg.modules.system.entity.MdcProductionEquipment;
 import org.jeecg.modules.system.entity.SysUser;
+import org.jeecg.modules.system.service.IMdcProductionService;
 import org.jeecg.modules.system.service.ISysUserService;
 import org.jeecg.modules.dnc.response.DeviceCode;
 import org.jeecg.modules.dnc.response.DeviceGroupCode;
@@ -55,6 +62,12 @@
     private IProductInfoService productInfoService;
     @Autowired
     private INcLogInfoService iNcLogInfoService;
+    @Autowired
+    private IMdcProductionService mdcProductionService;
+    @Autowired
+    private IMdcEquipmentService mdcEquipmentService;
+    @Autowired
+    private IMdcProductionEquipmentService mdcProductionEquipmentService;
 
     @Override
     @Transactional(rollbackFor = {Exception.class})
@@ -208,19 +221,19 @@
         if(!ValidateUtil.validateString(userId))
             ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
         if(nodeType == 1) {
-            DeviceGroup en = deviceGroupService.getById(paramId);
-            if(en == null) {
+            MdcProduction mdcProduction=mdcProductionService.getById(paramId);
+            if(mdcProduction == null) {
                 ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_NOT_EXIST);
             }
-            DeviceGroupPermission permission = deviceGroupPermissionService.getByUserIdAndGroupId(userId, en.getGroupId());
+            DeviceGroupPermission permission = deviceGroupPermissionService.getByUserIdAndGroupId(userId, mdcProduction.getId());
             if(permission == null)
                 return false;
             return true;
         }else if(nodeType == 2) {
-            DeviceInfo deviceInfo = super.getById(paramId);
-            if(deviceInfo == null)
+            MdcEquipment mdcEquipment = mdcEquipmentService.getById(paramId);
+            if(mdcEquipment == null)
                 ExceptionCast.cast(DeviceCode.DEVICE_NOT_EXIST);
-            DevicePermission permission = devicePermissionService.getByUserIdAndDeviceId(userId, deviceInfo.getDeviceId());
+            DevicePermission permission = devicePermissionService.getByUserIdAndDeviceId(userId, mdcEquipment.getId());
             if(permission == null)
                 return false;
             return true;
@@ -270,43 +283,43 @@
             ExceptionCast.cast(CommonCode.INVALID_PARAM);
         if(relativeFlag == 1 && nodeType == 1) {
             //鍒嗛厤鍒嗙粍鏉冮檺鎵嶅彲鍚戜笅浼犻�掔敤鎴�
-            DeviceGroup deviceGroup = deviceGroupService.getById(paramId);
-            if(deviceGroup == null) {
+            MdcProduction mdcProduction= mdcProductionService.getById(paramId);
+            if(mdcProduction == null) {
                 ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_NOT_EXIST);
             }
-            boolean b1 = checkDevicePerm(1, deviceGroup.getGroupId());
+            boolean b1 = checkDevicePerm(1, mdcProduction.getId());
             if(!b1) {
                 ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
             }
-            b1 = deviceGroupService.assignAddUser(deviceGroup, userList);
+            b1 = deviceGroupPermissionService.assignAddUser(mdcProduction, userList);
             if(!b1) {
                 ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
             }
             //鑾峰彇鍒嗙粍涓嬫墍鏈夌殑瀛愬垎缁�
-            List<DeviceGroup> childrenList = deviceGroupService.getChildrenByParentId(deviceGroup.getGroupId());
+            List<MdcProduction> childrenList = mdcProductionService.queryProdByPid(mdcProduction.getId());
             List<String> childrenIds = new ArrayList<>();
             if(childrenList != null && !childrenList.isEmpty()) {
                 childrenList.forEach(item -> {
-                    childrenIds.add(item.getGroupId());
-                    boolean b = checkDevicePerm(1, item.getGroupId());
+                    childrenIds.add(item.getId());
+                    boolean b = checkDevicePerm(1, item.getId());
                     if(b) {
-                        b = deviceGroupService.assignAddUser(item, userList);
+                        b = deviceGroupPermissionService.assignAddUser(mdcProduction, userList);
                         if(!b) {
                             ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
                         }
                     }
                 });
             }
-            List<DeviceInfo> deviceInfoList = null;
+            List<MdcEquipment> mdcEquipmentList = null;
             if(childrenIds.isEmpty()) {
-                deviceInfoList = getByGroupId(deviceGroup.getGroupId());
+                mdcEquipmentList =mdcProductionEquipmentService.queryEquipmentsOfProduction(mdcProduction.getId());
             }else {
-                childrenIds.add(deviceGroup.getGroupId());
-                deviceInfoList = getByGroupIdList(childrenIds);
+                childrenIds.add(mdcProduction.getId());
+                mdcEquipmentList = mdcProductionEquipmentService.queryEquipmentsOfProductions(childrenIds);
             }
-            if(deviceInfoList != null && !deviceInfoList.isEmpty()) {
-                deviceInfoList.forEach(item -> {
-                    boolean b = checkDevicePerm(2, item.getDeviceId());
+            if(mdcEquipmentList != null && !mdcEquipmentList.isEmpty()) {
+                mdcEquipmentList.forEach(item -> {
+                    boolean b = checkDevicePerm(2, item.getId());
                     if(b) {
                         b = assignAddUser(item, userList);
                         if(!b)
@@ -318,29 +331,29 @@
         }else if(relativeFlag == 2) {
             if(nodeType == 1) {
                 //鍒嗘壒鍒嗙粍鏉冮檺
-                DeviceGroup deviceGroup = deviceGroupService.getById(paramId);
-                if(deviceGroup == null) {
+                MdcProduction mdcProduction = mdcProductionService.getById(paramId);
+                if(mdcProduction == null) {
                     ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_NOT_EXIST);
                 }
-                boolean b = checkDevicePerm(1, deviceGroup.getGroupId());
+                boolean b = checkDevicePerm(1, mdcProduction.getId());
                 if(!b) {
                     ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
                 }
-                b = deviceGroupService.assignAddUser(deviceGroup, userList);
+                b = deviceGroupPermissionService.assignAddUser(mdcProduction, userList);
                 if(!b) {
                     ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
                 }
                 return true;
             }else if(nodeType == 2) {
                 //鍒嗛厤璁惧鏉冮檺
-                DeviceInfo deviceInfo = super.getById(paramId);
-                if(deviceInfo == null)
+                MdcEquipment mdcEquipment=mdcEquipmentService.getById(paramId);
+                if(mdcEquipment == null)
                     ExceptionCast.cast(DeviceCode.DEVICE_NOT_EXIST);
-                boolean b = checkDevicePerm(2, deviceInfo.getDeviceId());
+                boolean b = checkDevicePerm(2, mdcEquipment.getId());
                 if(!b) {
                     ExceptionCast.cast(DeviceCode.DEVICE_USER_PERM_ERROR);
                 }
-                b = assignAddUser(deviceInfo, userList);
+                b = assignAddUser(mdcEquipment, userList);
                 if(!b) {
                     ExceptionCast.cast(DeviceCode.DEVICE_USER_PERM_ERROR);
                 }
@@ -352,25 +365,27 @@
 
     @Override
     @Transactional(rollbackFor = {Exception.class})
-    public boolean assignAddUser(DeviceInfo deviceInfo, Collection<SysUser> userList) {
-        if(deviceInfo == null || userList == null || userList.isEmpty())
+    public boolean assignAddUser(MdcEquipment mdcEquipment, Collection<SysUser> userList) {
+        if(mdcEquipment == null || userList == null || userList.isEmpty())
             ExceptionCast.cast(CommonCode.INVALID_PARAM);
+        MdcProductionEquipment mdcProductionEquipment=mdcProductionEquipmentService
+                .list(new QueryWrapper<MdcProductionEquipment>().eq("equipment_id",mdcEquipment.getId())).get(0);
         List<DevicePermission> permissionList = new ArrayList<>();
         List<DevicePermissionStream> permissionStreamList = new ArrayList<>();
         userList.forEach(item -> {
-            DevicePermission en = devicePermissionService.getByUserIdAndDeviceId(item.getId(), deviceInfo.getDeviceId());
+            DevicePermission en = devicePermissionService.getByUserIdAndDeviceId(item.getId(), mdcEquipment.getId());
             if(en == null) {
                 en = new DevicePermission();
                 en.setUserId(item.getId());
-                en.setDeviceId(deviceInfo.getDeviceId());
+                en.setDeviceId(mdcEquipment.getId());
                 permissionList.add(en);
             }
-            DevicePermissionStream stream = devicePermissionStreamService.getByDeviceIdAndUserId(deviceInfo.getGroupId(), deviceInfo.getDeviceId(), item.getId());
+            DevicePermissionStream stream = devicePermissionStreamService.getByDeviceIdAndUserId(mdcProductionEquipment.getId(), mdcEquipment.getId(), item.getId());
             if(stream == null) {
                 stream = new DevicePermissionStream();
                 stream.setUserId(item.getId());
-                stream.setGroupId(deviceInfo.getGroupId());
-                stream.setDeviceId(deviceInfo.getDeviceId());
+                stream.setGroupId(mdcProductionEquipment.getId());
+                stream.setDeviceId(mdcEquipment.getId());
                 permissionStreamList.add(stream);
             }
         });
@@ -391,23 +406,25 @@
 
     @Override
     @Transactional(rollbackFor = {Exception.class})
-    public boolean assignRemoveUser(DeviceInfo deviceInfo, Collection<SysUser> userList) {
-        if(deviceInfo == null || userList == null || userList.isEmpty())
+    public boolean assignRemoveUser(MdcEquipment mdcEquipment, Collection<SysUser> userList) {
+        if(mdcEquipment == null || userList == null || userList.isEmpty())
             ExceptionCast.cast(CommonCode.INVALID_PARAM);
+        MdcProductionEquipment mdcProductionEquipment=mdcProductionEquipmentService
+                .list(new QueryWrapper<MdcProductionEquipment>().eq("equipment_id",mdcEquipment.getId())).get(0);
         List<DevicePermission> permissionList = new ArrayList<>();
         List<DevicePermissionStream> permissionStreamList = new ArrayList<>();
         userList.forEach(item -> {
-            DevicePermission en = devicePermissionService.getByUserIdAndDeviceId(item.getId(), deviceInfo.getDeviceId());
+            DevicePermission en = devicePermissionService.getByUserIdAndDeviceId(item.getId(), mdcEquipment.getId());
             if(en != null) {
                 permissionList.add(en);
             }
-            DevicePermissionStream stream = devicePermissionStreamService.getByDeviceIdAndUserId(deviceInfo.getGroupId(), deviceInfo.getDeviceId(), item.getId());
+            DevicePermissionStream stream = devicePermissionStreamService.getByDeviceIdAndUserId(mdcProductionEquipment.getId(), mdcEquipment.getId(), item.getId());
             if(stream != null) {
                 permissionStreamList.add(stream);
             }
         });
         //鏍¢獙娓呯┖鐢ㄦ埛鏉冮檺
-        List<DevicePermission> existList = devicePermissionService.getByDeviceId(deviceInfo.getDeviceId());
+        List<DevicePermission> existList = devicePermissionService.getByDeviceId(mdcEquipment.getId());
         if(existList.size() <= permissionList.size())
             ExceptionCast.cast(DeviceCode.DEVICE_USER_NONE);
         if(!permissionList.isEmpty()) {
@@ -456,43 +473,43 @@
             ExceptionCast.cast(CommonCode.INVALID_PARAM);
         if(relativeFlag == 1 && nodeType == 1) {
             //鍒嗛厤鍒嗙粍鏉冮檺鎵嶅彲鍚戜笅浼犻�掔敤鎴�
-            DeviceGroup deviceGroup = deviceGroupService.getById(paramId);
-            if(deviceGroup == null) {
+            MdcProduction mdcProduction=mdcProductionService.getById(paramId);
+            if(mdcProduction == null) {
                 ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_NOT_EXIST);
             }
-            boolean b1 = checkDevicePerm(1, deviceGroup.getGroupId());
+            boolean b1 = checkDevicePerm(1, mdcProduction.getId());
             if(!b1) {
                 ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
             }
-            b1 = deviceGroupService.assignRemoveUser(deviceGroup, userList);
+            b1 = deviceGroupPermissionService.assignRemoveUser(mdcProduction, userList);
             if(!b1) {
                 ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
             }
             //鑾峰彇鍒嗙粍涓嬫墍鏈夌殑瀛愬垎缁�
-            List<DeviceGroup> childrenList = deviceGroupService.getChildrenByParentId(deviceGroup.getGroupId());
+            List<MdcProduction> childrenList = mdcProductionService.queryProdByPid(mdcProduction.getId());
             List<String> childrenIds = new ArrayList<>();
             if(childrenList != null && !childrenList.isEmpty()) {
                 childrenList.forEach(item -> {
-                    childrenIds.add(item.getGroupId());
-                    boolean b = checkDevicePerm(1, item.getGroupId());
+                    childrenIds.add(item.getId());
+                    boolean b = checkDevicePerm(1, item.getId());
                     if(b) {
-                        b = deviceGroupService.assignRemoveUser(item, userList);
+                        b = deviceGroupPermissionService.assignRemoveUser(mdcProduction, userList);
                         if(!b) {
                             ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
                         }
                     }
                 });
             }
-            List<DeviceInfo> deviceInfoList = null;
+            List<MdcEquipment> mdcEquipmentList = null;
             if(childrenIds.isEmpty()) {
-                deviceInfoList = getByGroupId(deviceGroup.getGroupId());
+                mdcEquipmentList =mdcProductionEquipmentService.queryEquipmentsOfProduction(mdcProduction.getId());
             }else {
-                childrenIds.add(deviceGroup.getGroupId());
-                deviceInfoList = getByGroupIdList(childrenIds);
+                childrenIds.add(mdcProduction.getId());
+                mdcEquipmentList = mdcProductionEquipmentService.queryEquipmentsOfProductions(childrenIds);
             }
-            if(deviceInfoList != null && !deviceInfoList.isEmpty()) {
-                deviceInfoList.forEach(item -> {
-                    boolean b = checkDevicePerm(2, item.getDeviceId());
+            if(mdcEquipmentList != null && !mdcEquipmentList.isEmpty()) {
+                mdcEquipmentList.forEach(item -> {
+                    boolean b = checkDevicePerm(2, item.getId());
                     if(b) {
                         b = assignRemoveUser(item, userList);
                         if(!b)
@@ -504,29 +521,29 @@
         }else if(relativeFlag == 2) {
             if(nodeType == 1) {
                 //鍒嗘壒鍒嗙粍鏉冮檺
-                DeviceGroup deviceGroup = deviceGroupService.getById(paramId);
-                if(deviceGroup == null) {
+                MdcProduction mdcProduction = mdcProductionService.getById(paramId);
+                if(mdcProduction == null) {
                     ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_NOT_EXIST);
                 }
-                boolean b = checkDevicePerm(1, deviceGroup.getGroupId());
+                boolean b = checkDevicePerm(1, mdcProduction.getId());
                 if(!b) {
                     ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
                 }
-                b = deviceGroupService.assignRemoveUser(deviceGroup, userList);
+                b = deviceGroupPermissionService.assignRemoveUser(mdcProduction, userList);
                 if(!b) {
                     ExceptionCast.cast(DeviceGroupCode.DEVICE_GROUP_PERM_ERROR);
                 }
                 return true;
             }else if(nodeType == 2) {
                 //鍒嗛厤璁惧鏉冮檺
-                DeviceInfo deviceInfo = super.getById(paramId);
-                if(deviceInfo == null)
+                MdcEquipment mdcEquipment=mdcEquipmentService.getById(paramId);
+                if(mdcEquipment == null)
                     ExceptionCast.cast(DeviceCode.DEVICE_NOT_EXIST);
-                boolean b = checkDevicePerm(2, deviceInfo.getDeviceId());
+                boolean b = checkDevicePerm(2, mdcEquipment.getId());
                 if(!b) {
                     ExceptionCast.cast(DeviceCode.DEVICE_USER_PERM_ERROR);
                 }
-                b = assignRemoveUser(deviceInfo, userList);
+                b = assignRemoveUser(mdcEquipment, userList);
                 if(!b) {
                     ExceptionCast.cast(DeviceCode.DEVICE_USER_PERM_ERROR);
                 }

--
Gitblit v1.9.3