From 665ffec07abac9fa14e7613fe1c73922a537ff77 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期二, 06 五月 2025 16:00:19 +0800
Subject: [PATCH] art: 设备管理-看板接口-维修统计接口

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamReportRepairServiceImpl.java |  141 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 136 insertions(+), 5 deletions(-)

diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamReportRepairServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamReportRepairServiceImpl.java
index 996b510..3f89858 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamReportRepairServiceImpl.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamReportRepairServiceImpl.java
@@ -1,21 +1,33 @@
 package org.jeecg.modules.eam.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.api.vo.FileUploadResult;
+import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.system.vo.LoginUser;
-import org.jeecg.modules.eam.entity.EamReportRepair;
+import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
+import org.jeecg.modules.eam.constant.*;
+import org.jeecg.modules.eam.entity.*;
 import org.jeecg.modules.eam.mapper.EamReportRepairMapper;
 import org.jeecg.modules.eam.request.EamReportRepairQuery;
+import org.jeecg.modules.eam.service.IEamEquipmentExtendService;
 import org.jeecg.modules.eam.service.IEamReportRepairService;
+import org.jeecg.modules.eam.vo.EquipmentRepairStatistics;
+import org.jeecg.modules.system.service.IMdcProductionService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.transaction.annotation.Transactional;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import javax.annotation.Resource;
+import java.time.LocalDate;
+import java.util.*;
 
 /**
  * @Description: 鏁呴殰鎶ヤ慨
@@ -24,6 +36,11 @@
  */
 @Service
 public class EamReportRepairServiceImpl extends ServiceImpl<EamReportRepairMapper, EamReportRepair> implements IEamReportRepairService {
+
+    @Resource
+    private IEamEquipmentExtendService eamEquipmentExtendService;
+    @Autowired
+    private IMdcProductionService mdcProductionService;
 
     /**
      * 鍒嗛〉鍒楄〃
@@ -46,4 +63,118 @@
         }
         return this.baseMapper.pageList(page, eamReportRepairQuery, sysUser.getId(), equipmentIds);
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.REPORT_REPAIR, businessTable = "eam_report_repair")
+    public EamReportRepair reportRepairFromMaintenance(String equipmentId, String reportUser, List<EamWeekMaintenanceOrderDetail> detailList) {
+        StringBuilder sb = new StringBuilder();
+        detailList.forEach(detail -> {
+            sb.append(detail.getItemCode()).append("銆�");
+            sb.append(detail.getExceptionDescription()).append(";");
+        });
+        EamReportRepair entity = new EamReportRepair();
+        entity.setEquipmentId(equipmentId);
+        entity.setCreateBy(reportUser);
+        entity.setFaultStartTime(new Date());
+        entity.setBreakdownFlag(CommonConstant.DEFAULT_0);
+        entity.setDelFlag(CommonConstant.DEL_FLAG_0);
+        entity.setFaultName("鍛ㄤ繚鎵ц鎶ヤ慨澶勭悊");
+        entity.setFaultDescription(sb.toString());
+        entity.setFaultType(CommonConstant.DEFAULT_1);
+        entity.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name());
+        this.baseMapper.insert(entity);
+        //鏇存柊璁惧缁翠慨鐘舵��
+        eamEquipmentExtendService.updateEquipmentRepairStatus(entity.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name());
+        return entity;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.REPORT_REPAIR, businessTable = "eam_report_repair")
+    public EamReportRepair reportRepairFromInspection(String equipmentId, String reportUser, List<EamInspectionOrderDetail> detailList) {
+        StringBuilder sb = new StringBuilder();
+        detailList.forEach(detail -> {
+            sb.append(detail.getItemCode()).append("銆�");
+            sb.append(detail.getExceptionDescription()).append(";");
+        });
+        EamReportRepair entity = new EamReportRepair();
+        entity.setEquipmentId(equipmentId);
+        entity.setCreateBy(reportUser);
+        entity.setFaultStartTime(new Date());
+        entity.setBreakdownFlag(CommonConstant.DEFAULT_0);
+        entity.setDelFlag(CommonConstant.DEL_FLAG_0);
+        entity.setFaultName("鐐规鎵ц鎶ヤ慨澶勭悊");
+        entity.setFaultDescription(sb.toString());
+        entity.setFaultType(CommonConstant.DEFAULT_1);
+        entity.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name());
+        this.baseMapper.insert(entity);
+        //鏇存柊璁惧缁翠慨鐘舵��
+        eamEquipmentExtendService.updateEquipmentRepairStatus(entity.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name());
+        return entity;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.REPORT_REPAIR, businessTable = "eam_report_repair")
+    public EamReportRepair add(EamReportRepair eamReportRepair) {
+        eamReportRepair.setReportStatus(ReportRepairEnum.WAIT_REPAIR.name());
+        eamReportRepair.setDelFlag(CommonConstant.DEL_FLAG_0);
+        // 闄勪欢澶勭悊
+        if (eamReportRepair.getImageFilesResult() != null) {
+            List<FileUploadResult> imageFilesResult = eamReportRepair.getImageFilesResult();
+            ObjectMapper mapper = new ObjectMapper();
+            try {
+                String referenceFile = mapper.writeValueAsString(imageFilesResult);
+                eamReportRepair.setImageFiles(referenceFile);
+            } catch (JsonProcessingException e) {
+                return null;
+            }
+        }
+        this.baseMapper.insert(eamReportRepair);
+        //鏇存柊璁惧缁翠慨鐘舵��
+        eamEquipmentExtendService.updateEquipmentRepairStatus(eamReportRepair.getEquipmentId(), EquipmentRepairStatus.WAIT_REPAIR.name());
+        return eamReportRepair;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean edit(EamReportRepair eamReportRepair) {
+        // 闄勪欢澶勭悊
+        if (eamReportRepair.getImageFilesResult() != null) {
+            List<FileUploadResult> imageFilesResult = eamReportRepair.getImageFilesResult();
+            ObjectMapper mapper = new ObjectMapper();
+            try {
+                String referenceFile = mapper.writeValueAsString(imageFilesResult);
+                eamReportRepair.setImageFiles(referenceFile);
+            } catch (JsonProcessingException e) {
+                return false;
+            }
+        } else {
+            eamReportRepair.setImageFiles(null);
+        }
+        this.baseMapper.updateById(eamReportRepair);
+        return true;
+    }
+
+    @Override
+    public List<EquipmentRepairStatistics> equipmentRepairStatistics(String productionId, LocalDate firstOfMonth, LocalDate today) {
+        if (StringUtils.isNotBlank(productionId)) {
+            //杞﹂棿缂栫爜涓嶄负绌�
+            List<String> productIds = mdcProductionService.recursionChildren(productionId);
+            if (CollectionUtil.isEmpty(productIds)) {
+                return Collections.emptyList();
+            }
+            List<EquipmentRepairStatistics> list = this.baseMapper.equipmentRepairStatistics(productIds, firstOfMonth.toString(), today.plusDays(1).toString());
+            if (CollectionUtil.isEmpty(list)) {
+                return Collections.emptyList();
+            }
+            return list;
+        }
+        List<EquipmentRepairStatistics> list = this.baseMapper.equipmentRepairStatistics(null, firstOfMonth.toString(), today.plusDays(1).toString());
+        if (CollectionUtil.isEmpty(list)) {
+            return Collections.emptyList();
+        }
+        return list;
+    }
 }

--
Gitblit v1.9.3