From 0d06048c5d560e301bf17fad476975c8ffffcb56 Mon Sep 17 00:00:00 2001 From: lyh <925863403@qq.com> Date: 星期五, 05 九月 2025 16:07:31 +0800 Subject: [PATCH] 添加三级保养工作计划单生成规则 --- lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java | 181 +++++++++++++++++++++++++++++++++++--------- 1 files changed, 143 insertions(+), 38 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 24afdf3..452d3ab 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,6 +1,7 @@ package org.jeecg.modules.eam.service.impl; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -18,10 +19,12 @@ import org.jeecg.modules.eam.dto.EchartsDto; import org.jeecg.modules.eam.entity.EamEquipment; import org.jeecg.modules.eam.entity.EamEquipmentExtend; +import org.jeecg.modules.eam.entity.EamThirdMaintenanceWorkPlanSheet; 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.service.IEamThirdMaintenanceWorkPlanSheetService; import org.jeecg.modules.eam.tree.FindsEquipmentEamCenterUtil; import org.jeecg.modules.eam.tree.FindsEquipmentProductionUtil; import org.jeecg.modules.eam.vo.EamEquipmentTree; @@ -38,6 +41,9 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.DecimalFormat; import java.util.*; import java.util.stream.Collectors; @@ -60,6 +66,10 @@ private IBaseFactoryUserService baseFactoryUserService; @Autowired private IBaseFactoryService baseFactoryService; + @Autowired + private IEamThirdMaintenanceWorkPlanSheetService eamThirdMaintenanceWorkPlanSheetService; + @Autowired + private IEamEquipmentExtendService iEamEquipmentExtendService; @Override @Transactional(rollbackFor = Exception.class) @@ -80,6 +90,10 @@ eamEquipmentExtend.setRepairStatus(EquipmentRepairStatus.NORMAL.name()); equipmentExtendService.save(eamEquipmentExtend); + // 澶勭悊涓変繚淇濆吇璁″垝锛堜笉鍐嶈繘琛屾棩鏈熸瘮杈冿級 + eamThirdMaintenanceWorkPlanSheetService.createMaintenancePlan(eamEquipment, eamEquipment.getLatestThirdMaintenance()); + eamThirdMaintenanceWorkPlanSheetService.createMaintenancePlan(eamEquipment, eamEquipment.getNextThirdMaintenance()); + //鎻掑叆璁惧灞ュ巻 @EquipmentHistoryLog return eamEquipment; } @@ -90,9 +104,34 @@ */ @Override public EamEquipment updateEquipment(EamEquipment eamEquipment){ - if (eamEquipment == null) { - return null; + if (eamEquipment == null) return null; + + if (eamEquipment.getNextThirdMaintenance() != null && + eamEquipment.getThirdMaintenancePeriod() != null) { + + org.jeecg.common.util.DateUtils.calculateMaintenanceDates( + eamEquipment.getNextThirdMaintenance(), + eamEquipment.getThirdMaintenancePeriod(), + newDate -> eamEquipment.setNextThirdMaintenance(newDate), + latestDate -> eamEquipment.setLatestThirdMaintenance(latestDate) + ); } + + // 鑾峰彇鏃ф暟鎹� + EamEquipmentExtend old = iEamEquipmentExtendService.getById(eamEquipment.getId()); + if (old == null) return null; + + // 鎻愬彇鏂版棫鏃ユ湡閬垮厤閲嶅璁块棶 + Date newLatest = eamEquipment.getLatestThirdMaintenance(); + Date newNext = eamEquipment.getNextThirdMaintenance(); + Date oldLatest = old.getLatestThirdMaintenance(); + Date oldNext = old.getNextThirdMaintenance(); + + // 澶勭悊淇濆吇鏃ユ湡鍙樻洿 + eamThirdMaintenanceWorkPlanSheetService.processMaintenanceDateChange(eamEquipment, oldLatest, newLatest); + eamThirdMaintenanceWorkPlanSheetService.processMaintenanceDateChange(eamEquipment, oldNext, newNext); + + // 鏇存柊涓昏〃鍜屾墿灞曡〃 eamEquipmentMapper.updateById(eamEquipment); EamEquipmentExtend eamEquipmentExtend = new EamEquipmentExtend(); BeanUtils.copyProperties(eamEquipment, eamEquipmentExtend); @@ -156,21 +195,37 @@ if (sysUser == null) { return page; } - 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)){ - 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 { + if (StrUtil.isEmpty(eamEquipment.getProductionCode())){ + 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)){ + 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; + } + } + }else { + //閫氳繃閫夋嫨鐨勮溅闂磋繃婊ゅ搴斾腑蹇� + List<BaseFactory> baseFactoryList = baseFactoryService.list(new LambdaQueryWrapper<BaseFactory>() + .like(BaseFactory::getRemark, eamEquipment.getProductionCode()).eq(BaseFactory::getDelFlag, CommonConstant.DEL_FLAG_0.toString())); + if (CollectionUtils.isEmpty(baseFactoryList)) { return page; } + //缁勮EAM鏁版嵁 + Set<String> factoryCodes= new HashSet<>(); + baseFactoryList.forEach(baseFactory -> { + List<BaseFactory> factoryList=baseFactoryService.queryFactoryByPid(baseFactory.getId()); + factoryCodes.addAll(factoryList.stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet())); + }); + queryWrapper.in("e.factory_org_code", factoryCodes); } //鏌ヨ鏉′欢杩囨护 if (eamEquipment != null) { @@ -187,7 +242,7 @@ queryWrapper.like("e.asset_status", eamEquipment.getAssetStatus()); } if (StringUtils.isNotBlank(eamEquipment.getTechnologyStatus())) { - queryWrapper.like("e.technology_status", eamEquipment.getTechnologyStatus()); + queryWrapper.like("ext.technology_status", eamEquipment.getTechnologyStatus()); } if (StringUtils.isNotBlank(eamEquipment.getOperationSystem())) { queryWrapper.like("e.operation_system", eamEquipment.getOperationSystem()); @@ -368,7 +423,7 @@ queryWrapper.like("e.asset_status", eamEquipment.getAssetStatus()); } if (StringUtils.isNotBlank(eamEquipment.getTechnologyStatus())) { - queryWrapper.like("e.technology_status", eamEquipment.getTechnologyStatus()); + queryWrapper.like("ext.technology_status", eamEquipment.getTechnologyStatus()); } if (StringUtils.isNotBlank(eamEquipment.getOperationSystem())) { queryWrapper.like("e.operation_system", eamEquipment.getOperationSystem()); @@ -429,36 +484,86 @@ } /** + * 鑾峰彇鍙敓鎴愪簩淇濆伐鍗曠殑璁惧鍒楄〃 + */ + @Override + public List<EamEquipment> selectSecondMaintenanceEquipmentList(){ + QueryWrapper<EamEquipment> queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("e.del_flag", CommonConstant.DEL_FLAG_0); + queryWrapper.ne("ext.maintenance_status", MaintenanceStatusEnum.PROHIBITED.name()); + queryWrapper.isNotNull("ext.next_second_maintenance"); + return this.getBaseMapper().selectSecondMaintenanceEquipmentList(queryWrapper); + } + + /** * 璁惧绠$悊棣栭〉-鎶�鏈姸鎬� * @return */ @Override - public List<EchartsDto> echartsList(){ + public List<EchartsDto> echartsList(String productionCode){ + List<EchartsDto> echartsDtoList = new ArrayList<>(); QueryWrapper<EamEquipment> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("e.del_flag", CommonConstant.DEL_FLAG_0); - //鐢ㄦ埛鏁版嵁鏉冮檺 - LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); - if (sysUser == null) { - return null; - } - 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)){ - 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 null; + if (StrUtil.isEmpty(productionCode)) { + //鐢ㄦ埛鏁版嵁鏉冮檺 + LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + if (sysUser == null) { + return echartsDtoList; } + 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)){ + Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet()); + Set<String> factoryCodes= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet()); + queryWrapper.in("e.factory_org_code", factoryCodes); + }else { + return echartsDtoList; + } + } + }else { + //閫氳繃閫夋嫨鐨勮溅闂磋繃婊ゅ搴斾腑蹇� + List<BaseFactory> baseFactoryList = baseFactoryService.list(new LambdaQueryWrapper<BaseFactory>() + .like(BaseFactory::getRemark, productionCode).eq(BaseFactory::getDelFlag, CommonConstant.DEL_FLAG_0.toString())); + if (CollectionUtils.isEmpty(baseFactoryList)) { + return echartsDtoList; + } + //缁勮EAM鏁版嵁 + Set<String> factoryCodes= new HashSet<>(); + baseFactoryList.forEach(baseFactory -> { + List<BaseFactory> factoryList=baseFactoryService.queryFactoryByPid(baseFactory.getId()); + factoryCodes.addAll(factoryList.stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet())); + }); + queryWrapper.in("e.factory_org_code", factoryCodes); } List<String> ids=this.baseMapper.queryList(queryWrapper).stream().map(EamEquipment::getId).collect(Collectors.toList()); - return this.baseMapper.echartsList(ids); + if (ids.isEmpty()) { + return echartsDtoList; + } + echartsDtoList= this.baseMapper.echartsList(ids); + if (!echartsDtoList.isEmpty()) { + for (EchartsDto dto : echartsDtoList) { + if (dto.getTotal() != null && !"0".equals(dto.getTotal())) { + try { + int value = Integer.parseInt(dto.getValue()); + int total = Integer.parseInt(dto.getTotal()); + double percentage = (value * 100.0) / total; + DecimalFormat df = new DecimalFormat("0.00"); + dto.setPercentage(df.format(percentage) + "%"); + } catch (NumberFormatException e) { + dto.setPercentage("0.00%"); + } + } else { + dto.setPercentage("0.00%"); + } + } + } + return echartsDtoList; } /** -- Gitblit v1.9.3