From 3423bb9ee5b25d270a00763b69ed73970d790f63 Mon Sep 17 00:00:00 2001 From: Lius <Lius2225@163.com> Date: 星期二, 18 二月 2025 16:43:43 +0800 Subject: [PATCH] update --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDownTimeServiceImpl.java | 70 +++++++++++++++++++++++++++++++++++ 1 files changed, 70 insertions(+), 0 deletions(-) diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDownTimeServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDownTimeServiceImpl.java index ba7b735..c988419 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDownTimeServiceImpl.java +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDownTimeServiceImpl.java @@ -8,10 +8,14 @@ import org.apache.shiro.SecurityUtils; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.modules.mdc.entity.MdcDownTime; +import org.jeecg.modules.mdc.entity.MdcEquipment; +import org.jeecg.modules.mdc.entity.MdcMttrInfo; import org.jeecg.modules.mdc.entity.MdcOeeInfo; import org.jeecg.modules.mdc.mapper.MdcDownTimeMapper; import org.jeecg.modules.mdc.service.IMdcDownTimeService; import org.jeecg.modules.mdc.service.IMdcEquipmentService; +import org.jeecg.modules.mdc.service.IMdcMttrInfoService; +import org.jeecg.modules.mdc.util.DateUtils; import org.jeecg.modules.mdc.vo.MdcDownTimeVo; import org.jeecgframework.poi.excel.def.NormalExcelConstants; import org.jeecgframework.poi.excel.entity.ExportParams; @@ -22,6 +26,10 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -36,6 +44,9 @@ @Resource private IMdcEquipmentService mdcEquipmentService; + + @Resource + private IMdcMttrInfoService mdcMttrInfoService; @Override public IPage<MdcDownTime> pageList(String userId, Page<MdcDownTime> page, MdcDownTimeVo mdcDownTimeVo, HttpServletRequest req) { @@ -160,6 +171,65 @@ */ @Override public void computeMtbf(String month) { + /* + 璁惧骞冲潎鏁呴殰闂撮殧鏈�(MTBF) = (鏃ュ巻鏃堕棿 - 鎬绘晠闅滃仠鏈烘椂闂�) / 鎬绘晠闅滄鏁� + */ + // step.1 + List<MdcMttrInfo> mdcMttrInfos = mdcMttrInfoService.list(new LambdaQueryWrapper<MdcMttrInfo>().eq(MdcMttrInfo::getTheDate, month)); + DateTimeFormatter df = DateTimeFormatter.ofPattern(DateUtils.STR_DATE); + LocalDate parse = LocalDate.parse(month + "-01", df); + int calendarLong = parse.lengthOfMonth() * 24; + if (mdcMttrInfos != null && !mdcMttrInfos.isEmpty()) { + for (MdcMttrInfo mdcMttrInfo : mdcMttrInfos) { + // 鏃ュ巻鏃堕棿 + mdcMttrInfo.setCalendarLong(new BigDecimal(calendarLong)); + // 鎬绘晠闅滃仠鏈烘椂闂� + BigDecimal totalDownLong = this.baseMapper.findTotalDownLong(month); + if (totalDownLong != null) { + mdcMttrInfo.setTotalDownLong(totalDownLong); + } + // 鎬绘晠闅滄鏁� + Integer totalDownCount = this.baseMapper.findTotalDownCount(month); + if (totalDownLong != null) { + mdcMttrInfo.setTotalDownCount(totalDownCount); + } + // MTBF + if (mdcMttrInfo.getTotalDownCount() != 0) { + BigDecimal mtbf = (mdcMttrInfo.getCalendarLong().subtract(mdcMttrInfo.getTotalDownLong())).divide(new BigDecimal(mdcMttrInfo.getTotalDownCount()), 4, RoundingMode.HALF_UP); + mdcMttrInfo.setMtbf(mtbf); + } + } + mdcMttrInfoService.updateBatchById(mdcMttrInfos); + } else { + List<MdcEquipment> equipmentList = mdcEquipmentService.list(); + if (equipmentList != null && !equipmentList.isEmpty()) { + List<MdcMttrInfo> mmi = new ArrayList<>(); + for (MdcEquipment mdcEquipment : equipmentList) { + MdcMttrInfo mdcMttrInfo = new MdcMttrInfo(); + mdcMttrInfo.setEquipmentId(mdcEquipment.getEquipmentId()); + mdcMttrInfo.setTheDate(month); + // 鏃ュ巻鏃堕棿 + mdcMttrInfo.setCalendarLong(new BigDecimal(calendarLong)); + // 鎬绘晠闅滃仠鏈烘椂闂� + BigDecimal totalDownLong = this.baseMapper.findTotalDownLong(month); + if (totalDownLong != null) { + mdcMttrInfo.setTotalDownLong(totalDownLong); + } + // 鎬绘晠闅滄鏁� + Integer totalDownCount = this.baseMapper.findTotalDownCount(month); + if (totalDownLong != null) { + mdcMttrInfo.setTotalDownCount(totalDownCount); + } + // MTBF + if (mdcMttrInfo.getTotalDownCount() != 0) { + BigDecimal mtbf = (mdcMttrInfo.getCalendarLong().subtract(mdcMttrInfo.getTotalDownLong())).divide(new BigDecimal(mdcMttrInfo.getTotalDownCount()), 4, RoundingMode.HALF_UP); + mdcMttrInfo.setMtbf(mtbf); + } + mmi.add(mdcMttrInfo); + } + mdcMttrInfoService.saveBatch(mmi); + } + } } } -- Gitblit v1.9.3