From ed48aa9f30a87c528f071d06bf6b59d7d15428e9 Mon Sep 17 00:00:00 2001
From: qushaowei <qushaowei@163.com>
Date: 星期一, 26 五月 2025 16:12:55 +0800
Subject: [PATCH] 点检报表后端

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalInfoServiceImpl.java |   82 +++++++++++++++++++++++++++++-----------
 1 files changed, 59 insertions(+), 23 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalInfoServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalInfoServiceImpl.java
index 7d337b3..828202f 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalInfoServiceImpl.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentStatisticalInfoServiceImpl.java
@@ -3,16 +3,13 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.apache.commons.lang.StringUtils;
-import org.jeecg.modules.mdc.entity.Equipment;
-import org.jeecg.modules.mdc.entity.MdcEquipmentRunningSection;
-import org.jeecg.modules.mdc.entity.MdcEquipmentStatisticalInfo;
-import org.jeecg.modules.mdc.entity.MdcSystemParameters;
+import org.jeecg.common.exception.JeecgBootException;
+import org.jeecg.common.system.vo.DictModel;
+import org.jeecg.modules.mdc.entity.*;
 import org.jeecg.modules.mdc.mapper.MdcEquipmentStatisticalInfoMapper;
-import org.jeecg.modules.mdc.service.IEquipmentService;
-import org.jeecg.modules.mdc.service.IMdcEquipmentRunningSectionService;
-import org.jeecg.modules.mdc.service.IMdcEquipmentStatisticalInfoService;
-import org.jeecg.modules.mdc.service.IMdcSystemParametersService;
+import org.jeecg.modules.mdc.service.*;
 import org.jeecg.modules.mdc.util.DateUtils;
+import org.jeecg.modules.system.service.ISysDictService;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -37,6 +34,12 @@
 
     @Resource
     private IMdcSystemParametersService mdcSystemParametersService;
+
+    @Resource
+    private ISysDictService sysDictService;
+
+    @Resource
+    private IEquipmentStatisticalInfoService equipmentStatisticalInfoService;
 
     /**
      * 璁$畻璁惧鍗曟棩杩愯鏁版嵁
@@ -65,7 +68,33 @@
         }
         if (!result.isEmpty()) {
             this.saveBatch(result);
+            List<DictModel> dictList = sysDictService.queryDictItemsByCode("data_synchronization_flag");
+            if (dictList != null && !dictList.isEmpty() && "0".equals(dictList.get(0).getValue())) {
+                List<EquipmentStatisticalInfo> list = this.dataHandle(result);
+                equipmentStatisticalInfoService.saveBatch(list);
+            }
         }
+    }
+
+    @Override
+    public MdcEquipmentStatisticalInfo findMdcEquipmentStatisticalInfo(String equipmentId, String date) {
+        return this.baseMapper.findMdcEquipmentStatisticalInfo(equipmentId, date.replaceAll("-", ""));
+    }
+
+    private List<EquipmentStatisticalInfo> dataHandle(List<MdcEquipmentStatisticalInfo> list) {
+        List<EquipmentStatisticalInfo> result = new ArrayList<>();
+        list.forEach(item -> {
+            EquipmentStatisticalInfo equipmentStatisticalInfo = new EquipmentStatisticalInfo();
+            equipmentStatisticalInfo.setEquipment(item.getEquipmentId());
+            equipmentStatisticalInfo.setTheDate(item.getTheDate());
+            equipmentStatisticalInfo.setClosedLong(item.getCloseLong());
+            equipmentStatisticalInfo.setOpeningLong(item.getOpenLong());
+            equipmentStatisticalInfo.setErroringLong(item.getErrorLong());
+            equipmentStatisticalInfo.setProcessingLong(item.getProcessLong());
+            equipmentStatisticalInfo.setWaitingLong(item.getWaitLong());
+            result.add(equipmentStatisticalInfo);
+        });
+        return result;
     }
 
     private List<MdcEquipmentStatisticalInfo> equipmentStatisticalProcess(Equipment equipment, String dateTime) {
@@ -114,7 +143,12 @@
                     endDate = DateUtils.setTimeForDay(DateUtils.plusTime(now, -1), planTime);
                 }
                 List<MdcEquipmentRunningSection> equipmentRunningSectionList = mdcEquipmentRunningSectionService.listForEquipmentStatisticalInfo(equipment.getEquipmentid(), startDate, endDate);
-                return this.statisticsData(equipmentRunningSectionList, planTime, startDate, endDate, equipment);
+                try {
+                    return this.statisticsData(equipmentRunningSectionList, planTime, startDate, endDate, equipment);
+                } catch (Exception e) {
+                    throw new JeecgBootException("璁惧缂栧彿锛�" + equipment.getEquipmentid());
+                }
+
             } else {
                 //寰呴獙璇�
                 Date end = DateUtils.plusTime(initDate, 1);
@@ -246,20 +280,22 @@
                 long processingLong = 0L;
                 long closedLong = 0L;
                 long errorLong = 0L;
-                for (Map<String, Long> n : dayList) {
-                    long du = n.get("duration");
-                    int status = new Long(n.get("status")).intValue();
-                    if (status == 2) {
-                        waitingLong += du;
-                    }
-                    if (status == 3) {
-                        processingLong += du;
-                    }
-                    if (status == 0) {
-                        closedLong += du;
-                    }
-                    if (status == 22) {
-                        errorLong += du;
+                if (dayList != null && !dayList.isEmpty()) {
+                    for (Map<String, Long> n : dayList) {
+                        long du = n.get("duration");
+                        int status = new Long(n.get("status")).intValue();
+                        if (status == 2) {
+                            waitingLong += du;
+                        }
+                        if (status == 3) {
+                            processingLong += du;
+                        }
+                        if (status == 0) {
+                            closedLong += du;
+                        }
+                        if (status == 22) {
+                            errorLong += du;
+                        }
                     }
                 }
                 equipmentStatisticalInfo.setWaitLong(new BigDecimal(waitingLong));

--
Gitblit v1.9.3