From c2dbde3d4826946e7a40fff6efeb08547e4ab75a Mon Sep 17 00:00:00 2001 From: zhangherong <571457620@qq.com> Date: 星期二, 25 三月 2025 14:22:37 +0800 Subject: [PATCH] art: 设备台账-分页查询修改 --- lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java | 133 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 132 insertions(+), 1 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 9122818..779b7c6 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 @@ -1,7 +1,14 @@ package org.jeecg.modules.eam.service.impl; +import cn.hutool.core.collection.CollectionUtil; +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.extension.service.impl.ServiceImpl; +import org.apache.commons.lang3.StringUtils; +import org.apache.shiro.SecurityUtils; import org.jeecg.common.constant.CommonConstant; +import org.jeecg.common.system.vo.LoginUser; import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog; import org.jeecg.modules.eam.constant.AssetStatusEnum; import org.jeecg.modules.eam.constant.EquipmentMaintenanceStatus; @@ -10,13 +17,23 @@ 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.FindsEquipmentProductionUtil; +import org.jeecg.modules.eam.vo.EamEquipmentTree; +import org.jeecg.modules.system.entity.MdcProduction; +import org.jeecg.modules.system.service.IMdcProductionService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; 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.stream.Collectors; /** * @Description: 璁惧鍙拌处 @@ -31,6 +48,8 @@ private EamEquipmentMapper eamEquipmentMapper; @Autowired private IEamEquipmentExtendService equipmentExtendService; + @Autowired + private IMdcProductionService mdcProductionService; @Override @Transactional(rollbackFor = Exception.class) @@ -52,7 +71,119 @@ equipmentExtendService.save(eamEquipmentExtend); - //鎻掑叆璁惧灞ュ巻 TODO + //鎻掑叆璁惧灞ュ巻 @EquipmentHistoryLog return eamEquipment; } + + @Override + public List<EamEquipmentTree> 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)); + List<String> allProductionIds = new ArrayList<>(); + //鎵惧埌鎵�鏈変骇绾縤d鐨勪笂绾d + if (!productionIds.isEmpty()) { + for (String productionId : productionIds) { + this.getAllProductionIds(productionList, productionId, allProductionIds); + } + } + //杩囨护浜х嚎鏁版嵁 + List<MdcProduction> list = productionList.stream().filter((MdcProduction mdcProduction) -> allProductionIds.contains(mdcProduction.getId())).collect(Collectors.toList()); + //缁勮浜х嚎璁惧鏍� + List<EamEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list); + //濉厖璁惧鏁版嵁 + fillEquipmentByProduction(treeList); + return treeList; + } + + @Override + public IPage<EamEquipment> queryPageList(IPage<EamEquipment> page, EamEquipmentQuery eamEquipment) { + QueryWrapper<EamEquipment> queryWrapper = new QueryWrapper<>(); + //鐢ㄦ埛鏉冮檺 + LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + if(sysUser == null){ + return page; + } + queryWrapper.exists("select 1 from mdc_user_production t where t.user_id=? and t.pro_id=e.org_id", sysUser.getId()); + 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())){ + queryWrapper.like("e.org_id", eamEquipment.getOrgId()); + } + if(StringUtils.isNotBlank(eamEquipment.getEquipmentCategory())){ + queryWrapper.like("e.equipment_category", eamEquipment.getEquipmentCategory()); + } + //鎺掑簭 + if(StringUtils.isNotBlank(eamEquipment.getColumn()) && StringUtils.isNotBlank(eamEquipment.getOrder())){ + //queryWrapper.like("column", eamEquipment.getColumn()); + queryWrapper.orderByDesc("e.create_time"); + }else { + queryWrapper.orderByDesc("e.create_time"); + } + }else { + queryWrapper.orderByDesc("e.create_time"); + } + + IPage<EamEquipment> ipage = eamEquipmentMapper.queryPageList(page, queryWrapper); + return ipage; + } + + /** + * 鑾峰彇鎵�鏈夌殑浜х嚎id锛堝寘鍚墍鏈変笂绾э級 + */ + private void getAllProductionIds(List<MdcProduction> productionList, String productionId, List<String> allProductionIds) { + if (!allProductionIds.contains(productionId)) { + allProductionIds.add(productionId); + } + for (MdcProduction mdcProduction : productionList) { + if (StringUtils.isEmpty(mdcProduction.getParentId())) { + continue; + } + if (productionId.equals(mdcProduction.getId())) { + if (!allProductionIds.contains(mdcProduction.getParentId())) { + allProductionIds.add(mdcProduction.getParentId()); + getAllProductionIds(productionList, mdcProduction.getParentId(), allProductionIds); + } + } + } + } + + /** + * 浜х嚎璁惧鏍戝~鍏呰澶囨暟鎹� + */ + private void fillEquipmentByProduction(List<EamEquipmentTree> treeList) { + for (EamEquipmentTree mdcEquipmentTree : treeList) { + List<EamEquipment> equipmentList = eamEquipmentMapper.queryByProductionId(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())) { + fillEquipmentByProduction(mdcEquipmentTree.getChildren()); + } + } + } + } -- Gitblit v1.9.3