From 724f8ec3bbcf9da50f304f57d8bc9a60ad75ad0a Mon Sep 17 00:00:00 2001 From: lyh <925863403@qq.com> Date: 星期三, 27 八月 2025 18:29:32 +0800 Subject: [PATCH] 修改计算百分比位置 --- lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamSecondMaintenanceOrderAsyncService.java | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 153 insertions(+), 0 deletions(-) diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamSecondMaintenanceOrderAsyncService.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamSecondMaintenanceOrderAsyncService.java new file mode 100644 index 0000000..5c1dadc --- /dev/null +++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamSecondMaintenanceOrderAsyncService.java @@ -0,0 +1,153 @@ +package org.jeecg.modules.eam.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.StrUtil; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.constant.CommonConstant; +import org.jeecg.common.exception.JeecgBootException; +import org.jeecg.common.util.DateUtils; +import org.jeecg.modules.eam.constant.BusinessCodeConst; +import org.jeecg.modules.eam.constant.HfTemplateCategoryEnum; +import org.jeecg.modules.eam.constant.SecondMaintenanceStatusEnum; +import org.jeecg.modules.eam.entity.EamBaseHFCode; +import org.jeecg.modules.eam.entity.EamMaintenanceStandardDetail; +import org.jeecg.modules.eam.entity.EamSecondMaintenanceOrder; +import org.jeecg.modules.eam.entity.EamSecondMaintenanceOrderDetail; +import org.jeecg.modules.eam.mapper.EamSecondMaintenanceOrderMapper; +import org.jeecg.modules.eam.service.IEamBaseHFCodeService; +import org.jeecg.modules.eam.service.IEamFactorySecondMaintPlanService; +import org.jeecg.modules.eam.service.IEamMaintenanceStandardDetailService; +import org.jeecg.modules.eam.service.IEamSecondMaintenanceOrderDetailService; +import org.jeecg.modules.system.service.ISysBusinessCodeRuleService; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.temporal.TemporalAdjusters; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class EamSecondMaintenanceOrderAsyncService { + @Resource + private EamSecondMaintenanceOrderMapper eamSecondMaintenanceOrderMapper; + + @Autowired + private IEamSecondMaintenanceOrderDetailService secondMaintenanceOrderDetailService; + + @Autowired + private IEamMaintenanceStandardDetailService eamMaintenanceStandardDetailService; + + @Autowired + private IEamBaseHFCodeService hfCodeService; + + @Autowired + private ISysBusinessCodeRuleService businessCodeRuleService; + + @Autowired + private IEamFactorySecondMaintPlanService factorySecondMaintPlanService; + + @Async + public void asyncGenerateNextMaintenanceOrder(String orderId) { + try { + log.info("寮�濮嬪紓姝ョ敓鎴愪笅娆″伐鍗曪紝鍘熷伐鍗旾D: {}", orderId); + generateNextOrder(orderId); + log.info("寮傛鐢熸垚涓嬫宸ュ崟瀹屾垚锛屽師宸ュ崟ID: {}", orderId); + } catch (Exception e) { + log.error("寮傛鐢熸垚涓嬫宸ュ崟澶辫触锛屽伐鍗旾D: {}", orderId, e); + // 鍙戦�佸憡璀﹂�氱煡鎴栬繘琛岄噸璇� + } + } + + @Transactional(rollbackFor = Exception.class) + public void generateNextOrder(String orderId) { + EamSecondMaintenanceOrder entity = eamSecondMaintenanceOrderMapper.selectById(orderId); + if (entity == null) { + log.warn("鍘熷伐鍗曚笉瀛樺湪锛孖D: {}", orderId); + return; + } + if (!entity.getMaintenanceStatus().equals(SecondMaintenanceStatusEnum.COMPLETE.name())) { + log.warn("鍘熷伐鍗曠姸鎬佹湭瀹屾垚锛屼笉鐢熸垚涓嬫宸ュ崟锛孖D: {}", orderId); + return; + } + + // 鐢熸垚鏂扮殑宸ュ崟缂栧彿 + String newOrderNum = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.SECOND_MAINTENANCE_CODE_RULE); + if (StrUtil.isEmpty(newOrderNum)) { + throw new JeecgBootException("鐢熸垚宸ュ崟缂栧彿澶辫触"); + } + + EamSecondMaintenanceOrder nextOrder = new EamSecondMaintenanceOrder(); + nextOrder.setOrderNum(newOrderNum); + nextOrder.setEquipmentId(entity.getEquipmentId()); + nextOrder.setStandardId(entity.getStandardId()); + nextOrder.setCreationMethod("AUTO"); + // 璁剧疆淇濆吇鏃ユ湡涓哄師宸ュ崟淇濆吇鏃ユ湡鍔�6涓湀 + nextOrder.setMaintenanceDate(calculateNextMaintenanceDate(entity.getMaintenanceDate())); + // 璁剧疆鎶�鏈姸鎬侀壌瀹氳〃HF缂栫爜 + EamBaseHFCode eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.SECOND_MAINTENANCE.name()); + if (eamBaseHFCode == null) { + throw new JeecgBootException("鏈厤缃妧鏈姸鎬侀壌瀹氳〃鐨凥F缂栫爜锛屾坊鍔犲け璐ワ紒"); + } + nextOrder.setHfCode(eamBaseHFCode.getHfCode()); + nextOrder.setRemark(entity.getRemark()); + nextOrder.setMaintenanceStatus(SecondMaintenanceStatusEnum.WAIT_MAINTENANCE.name()); + nextOrder.setCreationMethod(entity.getCreationMethod()); + nextOrder.setDelFlag(CommonConstant.DEL_FLAG_0); + + // 鎻掑叆鏂板伐鍗� + eamSecondMaintenanceOrderMapper.insert(nextOrder); + + // 澶嶅埗宸ュ崟鏄庣粏 + List<EamMaintenanceStandardDetail> standardDetails = eamMaintenanceStandardDetailService.selectByStandardId(entity.getStandardId()); + if (CollectionUtil.isEmpty(standardDetails)) { + log.warn("鍘熷伐鍗曠殑淇濆吇瑙勮寖鏄庣粏涓虹┖锛屽伐鍗旾D: {}", orderId); + return; + } + + List<EamSecondMaintenanceOrderDetail> orderDetails = standardDetails.stream() + .map(item -> { + EamSecondMaintenanceOrderDetail detail = new EamSecondMaintenanceOrderDetail(); + BeanUtils.copyProperties(item, detail); + detail.setId(null); + detail.setOrderId(nextOrder.getId()); + return detail; + }) + .collect(Collectors.toList()); + + secondMaintenanceOrderDetailService.saveBatch(orderDetails); + + // 鎻掑叆棣栭〉浜屼繚鍏昏鍒� + // 浣跨敤 SimpleDateFormat 鐩存帴鏍煎紡鍖栦负鈥測yyy骞碝M鏈堚�濇牸寮� + SimpleDateFormat sdf = new SimpleDateFormat("yyyy骞碝M鏈�"); + String formattedDate = sdf.format(nextOrder.getMaintenanceDate()); + factorySecondMaintPlanService.add(nextOrder.getEquipmentId(), formattedDate); + } + + + /** + * 璁$畻鍏釜鏈堝悗鐨勫綋鏈堟渶鍚庝竴澶� + * @param currentDate 褰撳墠宸ュ崟鏃ユ湡 + * @return 鍏釜鏈堝悗鐨勫綋鏈堟渶鍚庝竴澶� + */ + private Date calculateNextMaintenanceDate(Date currentDate) { + // 杞崲涓篖ocalDate澶勭悊鏃ユ湡 + LocalDate localDate = DateUtils.dateToLocalDate(currentDate); + // 璁$畻鍏釜鏈堝悗鐨勬棩鏈� + LocalDate sixMonthsLater = localDate.plusMonths(6); + + // 璋冩暣鍒板綋鏈堢殑鏈�鍚庝竴澶� + LocalDate lastDayOfMonth = sixMonthsLater.with(TemporalAdjusters.lastDayOfMonth()); + + // 杞崲鍥濪ate绫诲瀷 + return DateUtils.localDateToDate(lastDayOfMonth); + } + +} -- Gitblit v1.9.3