From c89ca4524fa8311ebb415a2f225d2f95da780603 Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期一, 03 三月 2025 11:23:53 +0800
Subject: [PATCH] 车间选择列表

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcRepairInfoServiceImpl.java |   63 ++++++++++++++++++++++++++++++-
 1 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcRepairInfoServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcRepairInfoServiceImpl.java
index e41073a..ddb71d0 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcRepairInfoServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcRepairInfoServiceImpl.java
@@ -7,10 +7,12 @@
 import org.apache.commons.lang.StringUtils;
 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.MdcRepairInfo;
 import org.jeecg.modules.mdc.mapper.MdcRepairInfoMapper;
 import org.jeecg.modules.mdc.service.IMdcEquipmentService;
+import org.jeecg.modules.mdc.service.IMdcMttrInfoService;
 import org.jeecg.modules.mdc.service.IMdcRepairInfoService;
 import org.jeecg.modules.mdc.vo.MdcRepairInfoVo;
 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
@@ -22,6 +24,8 @@
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -36,6 +40,9 @@
 
     @Resource
     private IMdcEquipmentService mdcEquipmentService;
+
+    @Resource
+    private IMdcMttrInfoService mdcMttrInfoService;
 
     /**
      * 鍒嗛〉鍒楄〃
@@ -153,7 +160,7 @@
         ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
         List<MdcRepairInfo> repairInfos = this.baseMapper.selectList(queryWrapper);
         // 瀵煎嚭鏂囦欢鍚嶇О
-        mv.addObject(NormalExcelConstants.FILE_NAME,  "璁惧缁翠慨鏃堕暱鍒楄〃");
+        mv.addObject(NormalExcelConstants.FILE_NAME, "璁惧缁翠慨鏃堕暱鍒楄〃");
         mv.addObject(NormalExcelConstants.CLASS, MdcRepairInfo.class);
         LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("璁惧缁翠慨鏃堕暱琛ㄦ暟鎹�", "瀵煎嚭浜�:" + user.getRealname(), "璁惧缁翠慨鏃堕暱鏁版嵁"));
@@ -161,4 +168,56 @@
         mv.addObject(NormalExcelConstants.DATA_LIST, repairInfos);
         return mv;
     }
+
+    /**
+     * 璁$畻MTTR
+     *
+     * @param month
+     */
+    @Override
+    public void computeMttr(String month) {
+        /*
+        璁惧骞冲潎淇悊鏃堕棿(MTTR) = 鎬荤淮淇椂闂� / 鎬荤淮淇鏁�
+         */
+        List<MdcMttrInfo> mdcMttrInfos = mdcMttrInfoService.list(new LambdaQueryWrapper<MdcMttrInfo>().eq(MdcMttrInfo::getTheDate, month));
+        if (mdcMttrInfos != null && !mdcMttrInfos.isEmpty()) {
+            for (MdcMttrInfo mdcMttrInfo : mdcMttrInfos) {
+                // 鎬荤淮淇椂闂�
+                BigDecimal totalRepairLong = this.baseMapper.findTotalRepairLong(month);
+                mdcMttrInfo.setTotalRepairLong(totalRepairLong);
+                // 鎬荤淮淇鏁�
+                Integer totalRepairCount = this.baseMapper.findTotalRepairCount(month);
+                mdcMttrInfo.setTotalRepairCount(totalRepairCount);
+                // MTTR
+                if (mdcMttrInfo.getTotalRepairCount() != 0) {
+                    BigDecimal mttr = mdcMttrInfo.getTotalRepairLong().divide(new BigDecimal(mdcMttrInfo.getTotalDownCount()), 4, RoundingMode.HALF_UP);
+                    mdcMttrInfo.setMttr(mttr);
+                }
+            }
+            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);
+                    // 鎬荤淮淇椂闂�
+                    BigDecimal totalRepairLong = this.baseMapper.findTotalRepairLong(month);
+                    mdcMttrInfo.setTotalRepairLong(totalRepairLong);
+                    // 鎬荤淮淇鏁�
+                    Integer totalRepairCount = this.baseMapper.findTotalRepairCount(month);
+                    mdcMttrInfo.setTotalRepairCount(totalRepairCount);
+                    // MTTR
+                    if (mdcMttrInfo.getTotalRepairCount() != 0) {
+                        BigDecimal mttr = mdcMttrInfo.getTotalRepairLong().divide(new BigDecimal(mdcMttrInfo.getTotalDownCount()), 4, RoundingMode.HALF_UP);
+                        mdcMttrInfo.setMttr(mttr);
+                    }
+                    mmi.add(mdcMttrInfo);
+                }
+                mdcMttrInfoService.saveBatch(mmi);
+            }
+        }
+    }
 }

--
Gitblit v1.9.3