From bcd90314646203b32f73c89c1c2f89eaa96e2c9f Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期五, 18 七月 2025 18:05:35 +0800
Subject: [PATCH] art: 设备台账-查询需要做技术状态鉴定的设备列表

---
 lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java |  154 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 126 insertions(+), 28 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..5d7a2c8 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,24 +14,22 @@
 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.constant.AssetStatusEnum;
-import org.jeecg.modules.eam.constant.EquipmentMaintenanceStatus;
-import org.jeecg.modules.eam.constant.EquipmentOperationTagEnum;
-import org.jeecg.modules.eam.constant.EquipmentRepairStatus;
+import org.jeecg.modules.eam.constant.*;
 import org.jeecg.modules.eam.entity.EamEquipment;
 import org.jeecg.modules.eam.entity.EamEquipmentExtend;
 import org.jeecg.modules.eam.mapper.EamEquipmentMapper;
 import org.jeecg.modules.eam.request.EamEquipmentQuery;
 import org.jeecg.modules.eam.service.IEamEquipmentExtendService;
 import org.jeecg.modules.eam.service.IEamEquipmentService;
+import org.jeecg.modules.eam.tree.FindsEquipmentEamCenterUtil;
 import org.jeecg.modules.eam.tree.FindsEquipmentProductionUtil;
 import org.jeecg.modules.eam.vo.EamEquipmentTree;
 import org.jeecg.modules.eam.vo.EquipmentSearchResult;
+import org.jeecg.modules.system.entity.BaseFactory;
+import org.jeecg.modules.system.entity.BaseFactoryUser;
 import org.jeecg.modules.system.entity.MdcProduction;
+import org.jeecg.modules.system.service.IBaseFactoryService;
+import org.jeecg.modules.system.service.IBaseFactoryUserService;
 import org.jeecg.modules.system.service.IMdcProductionService;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -40,10 +37,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 +120,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 +164,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 +201,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 +251,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 +295,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 +341,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();
             }
 
         }
@@ -357,6 +404,16 @@
         return eamEquipmentMapper.queryList(queryWrapper);
     }
 
+    @Override
+    public List<EamEquipment> selectTechnicalEquipmentList() {
+        QueryWrapper<EamEquipment> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("e.del_flag", CommonConstant.DEL_FLAG_0);
+        queryWrapper.ne("ext.technology_status", TechnologyStatusEnum.PROHIBITED.name());
+        queryWrapper.isNotNull("ext.technology_check_period");
+        queryWrapper.isNotNull("e.next_technology_check");
+        return this.getBaseMapper().selectTechnicalEquipmentList(queryWrapper);
+    }
+
     /**
      * 鑾峰彇鎵�鏈夌殑浜х嚎id锛堝寘鍚墍鏈変笂绾э級
      */
@@ -372,6 +429,26 @@
                 if (!allProductionIds.contains(mdcProduction.getParentId())) {
                     allProductionIds.add(mdcProduction.getParentId());
                     getAllProductionIds(productionList, mdcProduction.getParentId(), allProductionIds);
+                }
+            }
+        }
+    }
+
+    /**
+     * 鑾峰彇鎵�鏈夌殑浜х嚎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);
                 }
             }
         }
@@ -398,4 +475,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