From f6bcf1ba29b88c32b23def2bd6f3cee08905ce07 Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期二, 08 七月 2025 21:17:46 +0800
Subject: [PATCH] 修改设备查询

---
 lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java |  197 +++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 180 insertions(+), 17 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 19c81b7..0d3a6d7 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<>();
@@ -146,9 +169,8 @@
             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);
+                queryWrapper.in("e.factory_org_code", factoryCode);
             }
-
         }
         //鏌ヨ鏉′欢杩囨护
         if (eamEquipment != null) {
@@ -224,14 +246,21 @@
         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)){
+                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_org_code", factoryCode);
+            }
         }
+
         if (StringUtils.isNotBlank(keyword)) {
             queryWrapper.like("equipment_code", keyword);
             queryWrapper.or().like("equipment_name", keyword);
@@ -265,12 +294,105 @@
             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::getFactoryCode).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);
 
         return eamEquipmentMapper.selectOne(queryWrapper);
+    }
+
+    /**
+     * 璁惧鍙拌处瀵煎嚭
+     * @param eamEquipment
+     * @return
+     */
+    @Override
+    public List<EamEquipment> exportList(EamEquipmentQuery eamEquipment){
+        QueryWrapper<EamEquipment> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("e.del_flag", CommonConstant.DEL_FLAG_0);
+        //鐢ㄦ埛鏁版嵁鏉冮檺
+        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        if (sysUser == null) {
+            return new ArrayList<>();
+        }
+        if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) {
+            //閫夋嫨浜嗚澶囷紝鏍规嵁璁惧id杩囨护璁惧
+            List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(","));
+            queryWrapper.in("e.equipment_code", equipArr);
+        } else {
+            //娌℃湁閫夋嫨璁惧锛屾牴鎹腑蹇冭繃婊よ澶�
+            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_org_code", factoryCode);
+            }
+
+        }
+        //鏌ヨ鏉′欢杩囨护
+        if (eamEquipment != null) {
+            if (StringUtils.isNotBlank(eamEquipment.getEquipmentCode())) {
+                queryWrapper.like("e.equipment_code", eamEquipment.getEquipmentCode());
+            }
+            if (StringUtils.isNotBlank(eamEquipment.getEquipmentName())) {
+                queryWrapper.like("e.equipment_name", eamEquipment.getEquipmentName());
+            }
+            if (StringUtils.isNotBlank(eamEquipment.getEquipmentImportance())) {
+                queryWrapper.eq("e.equipment_importance", eamEquipment.getEquipmentImportance());
+            }
+            if (StringUtils.isNotBlank(eamEquipment.getAssetStatus())) {
+                queryWrapper.like("e.asset_status", eamEquipment.getAssetStatus());
+            }
+            if (StringUtils.isNotBlank(eamEquipment.getTechnologyStatus())) {
+                queryWrapper.like("e.technology_status", eamEquipment.getTechnologyStatus());
+            }
+            if (StringUtils.isNotBlank(eamEquipment.getOperationSystem())) {
+                queryWrapper.like("e.operation_system", eamEquipment.getOperationSystem());
+            }
+            if (StringUtils.isNotBlank(eamEquipment.getOrgId())) {
+                //杞﹂棿缂栫爜涓嶄负绌�
+                List<String> productIds = mdcProductionService.recursionChildren(eamEquipment.getOrgId());
+                if (CollectionUtil.isNotEmpty(productIds)) {
+                    //涓嶅仛绛涢��
+                    queryWrapper.in("e.org_id", productIds);
+                }
+            }
+            if (StringUtils.isNotBlank(eamEquipment.getEquipmentCategory())) {
+                queryWrapper.like("e.equipment_category", eamEquipment.getEquipmentCategory());
+            }
+            if (StringUtils.isNotBlank(eamEquipment.getId())) {
+                queryWrapper.eq("e.id", eamEquipment.getId());
+            }
+            //鎺掑簭
+            if (StringUtils.isNotBlank(eamEquipment.getColumn()) && StringUtils.isNotBlank(eamEquipment.getOrder())) {
+                //queryWrapper.like("column", eamEquipment.getColumn());
+                String column = eamEquipment.getColumn();
+                if (column.endsWith(CommonConstant.DICT_TEXT_SUFFIX)) {
+                    column = column.substring(0, column.lastIndexOf(CommonConstant.DICT_TEXT_SUFFIX));
+                }
+                if (DataBaseConstant.SQL_ASC.equalsIgnoreCase(eamEquipment.getOrder())) {
+                    queryWrapper.orderByAsc("e." + oConvertUtils.camelToUnderline(column));
+                } else {
+                    queryWrapper.orderByDesc("e." + oConvertUtils.camelToUnderline(column));
+                }
+            } else {
+                queryWrapper.orderByDesc("e.create_time");
+            }
+        } else {
+            queryWrapper.orderByDesc("e.create_time");
+        }
+        return eamEquipmentMapper.queryList(queryWrapper);
     }
 
     /**
@@ -294,6 +416,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) {
@@ -314,4 +456,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