From a3cfd941f3ccb05906ecbe99e6993f96770b51ed Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期四, 10 七月 2025 10:43:05 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java |  139 ++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 115 insertions(+), 24 deletions(-)

diff --git a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
index 570ee6a..00ccb1a 100644
--- a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
+++ b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
@@ -7,7 +7,6 @@
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import io.micrometer.core.instrument.binder.BaseUnits;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.constant.CommonConstant;
@@ -15,10 +14,11 @@
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
-import org.jeecg.modules.eam.base.entity.BaseFactory;
-import org.jeecg.modules.eam.base.entity.BaseFactoryUser;
-import org.jeecg.modules.eam.base.service.IBaseFactoryService;
-import org.jeecg.modules.eam.base.service.IBaseFactoryUserService;
+import org.jeecg.modules.eam.tree.FindsEquipmentEamCenterUtil;
+import org.jeecg.modules.system.entity.BaseFactory;
+import org.jeecg.modules.system.entity.BaseFactoryUser;
+import org.jeecg.modules.system.service.IBaseFactoryService;
+import org.jeecg.modules.system.service.IBaseFactoryUserService;
 import org.jeecg.modules.eam.constant.AssetStatusEnum;
 import org.jeecg.modules.eam.constant.EquipmentMaintenanceStatus;
 import org.jeecg.modules.eam.constant.EquipmentOperationTagEnum;
@@ -40,10 +40,7 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -126,6 +123,32 @@
         return treeList;
     }
 
+    /**
+     * 鑾峰彇EAM涓績涓嬬殑璁惧淇℃伅
+     * @param ids EAM涓績ids
+     * @return
+     */
+    @Override
+    public List<EamEquipmentTree> loadTreeListByEamCenterIds(String ids){
+        List<String> baseFactoryIds = Arrays.asList(ids.split(","));
+        //鑾峰彇鎵�鏈塃AM鏁版嵁
+        List<BaseFactory> baseFactoryList = baseFactoryService.list(new LambdaQueryWrapper<BaseFactory>().eq(BaseFactory::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(BaseFactory::getSorter));
+        List<String> allBaseFactoryIds = new ArrayList<>();
+        //鎵惧埌鎵�鏈変骇绾縤d鐨勪笂绾d
+        if (!baseFactoryIds.isEmpty()) {
+            for (String baseFactoryId : baseFactoryIds) {
+                this.getAllBaseFactoryIds(baseFactoryList, baseFactoryId, allBaseFactoryIds);
+            }
+        }
+        //杩囨护EAM鏁版嵁
+        List<BaseFactory> list = baseFactoryList.stream().filter((BaseFactory baseFactory) -> allBaseFactoryIds.contains(baseFactory.getId())).collect(Collectors.toList());
+        //缁勮EAM璁惧鏍�
+        List<EamEquipmentTree> treeList = FindsEquipmentEamCenterUtil.wrapEquipmentBaseFactoryTreeList(list);
+        //濉厖璁惧鏁版嵁
+        fillEquipmentByBaseFactory(treeList);
+        return treeList;
+    }
+
     @Override
     public IPage<EamEquipment> queryPageList(IPage<EamEquipment> page, EamEquipmentQuery eamEquipment) {
         QueryWrapper<EamEquipment> queryWrapper = new QueryWrapper<>();
@@ -144,11 +167,12 @@
             List<BaseFactoryUser> baseFactoryUserList=baseFactoryUserService.
                     list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId,sysUser.getId()));
             if(!CollectionUtils.isEmpty(baseFactoryUserList)){
-                List<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toList());
-                List<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getFactoryCode).collect(Collectors.toList());
-                queryWrapper.in("e.factory_code", factoryCode);
+                Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
+                Set<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
+                queryWrapper.in("e.factory_org_code", factoryCode);
+            }else {
+                return page;
             }
-
         }
         //鏌ヨ鏉′欢杩囨护
         if (eamEquipment != null) {
@@ -180,6 +204,12 @@
             }
             if (StringUtils.isNotBlank(eamEquipment.getEquipmentCategory())) {
                 queryWrapper.like("e.equipment_category", eamEquipment.getEquipmentCategory());
+            }
+            if (StringUtils.isNotBlank(eamEquipment.getFactoryOrgCode())) {
+                queryWrapper.like("e.factory_org_code", eamEquipment.getFactoryOrgCode());
+            }
+            if (StringUtils.isNotBlank(eamEquipment.getRepairDepartOrgCode())) {
+                queryWrapper.like("e.repair_depart_org_code", eamEquipment.getRepairDepartOrgCode());
             }
             if (StringUtils.isNotBlank(eamEquipment.getId())) {
                 queryWrapper.eq("e.id", eamEquipment.getId());
@@ -224,14 +254,23 @@
         if (sysUser == null) {
             return Collections.emptyList();
         }
-        if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) {
+        if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) {
             //閫夋嫨浜嗚澶囷紝鏍规嵁璁惧id杩囨护璁惧
-            List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(","));
-            queryWrapper.in("equipment_code", equipArr);
+            List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(","));
+            queryWrapper.in("e.equipment_code", equipArr);
         } else {
-            //娌℃湁閫夋嫨璁惧锛屾牴鎹溅闂磋繃婊よ澶�
-            queryWrapper.exists("select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=org_id", sysUser.getId());
+            //娌℃湁閫夋嫨璁惧锛屾牴鎹腑蹇冭繃婊よ澶�
+            List<BaseFactoryUser> baseFactoryUserList=baseFactoryUserService.
+                    list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId,sysUser.getId()));
+            if(!CollectionUtils.isEmpty(baseFactoryUserList)){
+                Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
+                Set<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
+                queryWrapper.in("e.factory_org_code", factoryCode);
+            } else {
+                return Collections.emptyList();
+            }
         }
+
         if (StringUtils.isNotBlank(keyword)) {
             queryWrapper.like("equipment_code", keyword);
             queryWrapper.or().like("equipment_name", keyword);
@@ -259,13 +298,22 @@
         if (sysUser == null) {
             return null;
         }
-        if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) {
+        if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) {
             //閫夋嫨浜嗚澶囷紝鏍规嵁璁惧id杩囨护璁惧
-            List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(","));
+            List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(","));
             queryWrapper.in("equipment_code", equipArr);
         } else {
             //娌℃湁閫夋嫨璁惧锛屾牴鎹溅闂磋繃婊よ澶�
-            queryWrapper.exists("select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=org_id", sysUser.getId());
+            List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService.
+                    list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId, sysUser.getId()));
+            if (!CollectionUtils.isEmpty(baseFactoryUserList)) {
+                Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
+                Set<String> factoryCodeList = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
+                queryWrapper.in("factory_org_code", factoryCodeList);
+            } else {
+                return null;
+            }
+
         }
         queryWrapper.eq("equipment_code", equipmentCode);
         queryWrapper.eq("del_flag", CommonConstant.DEL_FLAG_0);
@@ -296,9 +344,11 @@
             List<BaseFactoryUser> baseFactoryUserList=baseFactoryUserService.
                     list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId,sysUser.getId()));
             if(!CollectionUtils.isEmpty(baseFactoryUserList)){
-                List<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toList());
-                List<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getFactoryCode).collect(Collectors.toList());
-                queryWrapper.in("e.factory_code", factoryCode);
+                Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
+                Set<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
+                queryWrapper.in("e.factory_org_code", factoryCode);
+            }else {
+                return Collections.emptyList();
             }
 
         }
@@ -378,6 +428,26 @@
     }
 
     /**
+     * 鑾峰彇鎵�鏈夌殑浜х嚎id锛堝寘鍚墍鏈変笂绾э級
+     */
+    private void getAllBaseFactoryIds(List<BaseFactory> baseFactoryList, String baseFactoryId, List<String> allBaseFactoryIds) {
+        if (!allBaseFactoryIds.contains(baseFactoryId)) {
+            allBaseFactoryIds.add(baseFactoryId);
+        }
+        for (BaseFactory baseFactory : baseFactoryList) {
+            if (StringUtils.isEmpty(baseFactory.getParentId())) {
+                continue;
+            }
+            if (baseFactoryId.equals(baseFactory.getId())) {
+                if (!allBaseFactoryIds.contains(baseFactory.getParentId())) {
+                    allBaseFactoryIds.add(baseFactory.getParentId());
+                    getAllBaseFactoryIds(baseFactoryList, baseFactory.getParentId(), allBaseFactoryIds);
+                }
+            }
+        }
+    }
+
+    /**
      * 浜х嚎璁惧鏍戝~鍏呰澶囨暟鎹�
      */
     private void fillEquipmentByProduction(List<EamEquipmentTree> treeList) {
@@ -398,4 +468,25 @@
         }
     }
 
+    /**
+     * 浜х嚎璁惧鏍戝~鍏呰澶囨暟鎹�
+     */
+    private void fillEquipmentByBaseFactory(List<EamEquipmentTree> treeList) {
+        for (EamEquipmentTree mdcEquipmentTree : treeList) {
+            List<EamEquipment> equipmentList = eamEquipmentMapper.queryByEamCenterId(mdcEquipmentTree.getKey());
+            if (CollectionUtil.isNotEmpty(equipmentList)) {
+                for (EamEquipment mdcEquipment : equipmentList) {
+                    EamEquipmentTree tree = new EamEquipmentTree().convert(mdcEquipment);
+                    tree.setParentId(mdcEquipmentTree.getKey());
+                    tree.setType(2);
+                    mdcEquipmentTree.getChildren().add(tree);
+                }
+                mdcEquipmentTree.setLeaf(false);
+            }
+            if (CollectionUtil.isNotEmpty(mdcEquipmentTree.getChildren())) {
+                fillEquipmentByBaseFactory(mdcEquipmentTree.getChildren());
+            }
+        }
+    }
+
 }

--
Gitblit v1.9.3