From 915a2e40175c6390802af1257e57effea5fd02ef Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期二, 06 五月 2025 17:35:32 +0800
Subject: [PATCH] art: 设备管理-看板接口-点检、周保统计接口

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamWeekMaintenanceOrderServiceImpl.java |  105 +++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 87 insertions(+), 18 deletions(-)

diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamWeekMaintenanceOrderServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamWeekMaintenanceOrderServiceImpl.java
index b5396f5..dc69929 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamWeekMaintenanceOrderServiceImpl.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamWeekMaintenanceOrderServiceImpl.java
@@ -3,6 +3,7 @@
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -20,25 +21,24 @@
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.oConvertUtils;
-import org.jeecg.modules.eam.constant.BusinessCodeConst;
-import org.jeecg.modules.eam.constant.OrderCreationMethodEnum;
-import org.jeecg.modules.eam.constant.WeekMaintenanceStatusEnum;
+import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
+import org.jeecg.modules.eam.constant.*;
 import org.jeecg.modules.eam.entity.EamEquipment;
 import org.jeecg.modules.eam.entity.EamWeekMaintenanceOrder;
 import org.jeecg.modules.eam.entity.EamWeekMaintenanceOrderDetail;
 import org.jeecg.modules.eam.mapper.EamWeekMaintenanceOrderMapper;
 import org.jeecg.modules.eam.request.EamWeekMaintenanceQuery;
 import org.jeecg.modules.eam.request.EamWeekMaintenanceRequest;
-import org.jeecg.modules.eam.service.IEamEquipmentService;
-import org.jeecg.modules.eam.service.IEamReportRepairService;
-import org.jeecg.modules.eam.service.IEamWeekMaintenanceOrderDetailService;
-import org.jeecg.modules.eam.service.IEamWeekMaintenanceOrderService;
+import org.jeecg.modules.eam.service.*;
+import org.jeecg.modules.eam.vo.EquipmentInspectionStatistics;
+import org.jeecg.modules.eam.vo.EquipmentMaintenanceStatistics;
 import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness;
 import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService;
 import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI;
 import org.jeecg.modules.flowable.apithird.service.FlowCommonService;
 import org.jeecg.modules.flowable.service.IFlowDefinitionService;
 import org.jeecg.modules.flowable.service.IFlowTaskService;
+import org.jeecg.modules.system.service.IMdcProductionService;
 import org.jeecg.modules.system.service.ISysUserService;
 import org.jeecg.modules.system.vo.UserSelector;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -46,6 +46,7 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.time.LocalDate;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -81,10 +82,18 @@
     private IEamEquipmentService eamEquipmentService;
     @Autowired
     private IEamReportRepairService eamReportRepairService;
+    @Autowired
+    private IEamEquipmentExtendService eamEquipmentExtendService;
+    @Autowired
+    private IMdcProductionService mdcProductionService;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean addWeekMaintenance(EamWeekMaintenanceRequest request) {
+        EamEquipment equipment = eamEquipmentService.getById(request.getEquipmentId());
+        if (equipment == null) {
+            throw new JeecgBootException("璁惧涓嶅瓨鍦紝娣诲姞澶辫触锛�");
+        }
         EamWeekMaintenanceOrder order = new EamWeekMaintenanceOrder();
         order.setOrderNum(request.getOrderNum());
         order.setEquipmentId(request.getEquipmentId());
@@ -94,7 +103,7 @@
         order.setRemark(request.getRemark());
         //鐘舵�佸垵濮嬪寲
         order.setMaintenanceStatus(WeekMaintenanceStatusEnum.WAIT_MAINTENANCE.name());
-        order.setCreationMethod(OrderCreationMethodEnum.MANUAL.name());
+        order.setCreationMethod(request.getCreationMethod());
         //鍒犻櫎鏍囪
         order.setDelFlag(CommonConstant.DEL_FLAG_0);
         eamWeekMaintenanceOrderMapper.insert(order);
@@ -109,7 +118,7 @@
         //鍒ゆ柇鏄惁瀛樺湪淇濆吇浜� 濡傛灉瀛樺湪鍒欏惎鍔ㄦ祦绋�
         if (StringUtils.isNotBlank(order.getOperator())) {
             //鍚姩娴佺▼
-            flowCommonService.initActBusiness("宸ュ崟鍙�:" + order.getOrderNum() + ";寮�濮嬭繘琛岃澶囧懆淇�",
+            flowCommonService.initActBusiness("宸ュ崟鍙�:" + order.getOrderNum() + ";璁惧缂栧彿: " + equipment.getEquipmentCode() + ";杩涜璁惧鍛ㄤ繚",
                     order.getId(), "IEamWeekMaintenanceOrderService", "week_maintenance_process", null);
             Map<String, Object> variables = new HashMap<>();
             variables.put("dataId", order.getId());
@@ -130,6 +139,8 @@
                 order.setMaintenanceStatus(WeekMaintenanceStatusEnum.UNDER_MAINTENANCE.name());
                 order.setActualStartTime(new Date());
                 eamWeekMaintenanceOrderMapper.updateById(order);
+                //鏇存柊璁惧淇濆吇鐘舵��
+                eamEquipmentExtendService.updateEquipmentMaintenanceStatus(order.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name());
                 return result.isSuccess();
             }
         }
@@ -191,6 +202,10 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean editWeekMaintenance(EamWeekMaintenanceRequest request) {
+        EamEquipment equipment = eamEquipmentService.getById(request.getEquipmentId());
+        if (equipment == null) {
+            throw new JeecgBootException("璁惧涓嶅瓨鍦紝娣诲姞澶辫触锛�");
+        }
         EamWeekMaintenanceOrder entity = eamWeekMaintenanceOrderMapper.selectById(request.getId());
         if (entity == null) {
             throw new JeecgBootException("缂栬緫鐨勬暟鎹凡鍒犻櫎锛岃鍒锋柊閲嶈瘯锛�");
@@ -229,7 +244,7 @@
         //鍒ゆ柇鏄惁瀛樺湪淇濆吇浜� 濡傛灉瀛樺湪鍒欏惎鍔ㄦ祦绋�
         if (StringUtils.isNotBlank(entity.getOperator())) {
             //鍚姩娴佺▼
-            flowCommonService.initActBusiness("宸ュ崟鍙�:" + entity.getOrderNum() + ";寮�濮嬭繘琛岃澶囧懆淇�",
+            flowCommonService.initActBusiness("宸ュ崟鍙�:" + entity.getOrderNum() + ";璁惧缂栧彿: " + equipment.getEquipmentCode() + ";杩涜璁惧鍛ㄤ繚",
                     entity.getId(), "IEamWeekMaintenanceOrderService", "week_maintenance_process", null);
             Map<String, Object> variables = new HashMap<>();
             variables.put("dataId", entity.getId());
@@ -250,8 +265,11 @@
                 entity.setMaintenanceStatus(WeekMaintenanceStatusEnum.UNDER_MAINTENANCE.name());
                 entity.setActualStartTime(new Date());
                 eamWeekMaintenanceOrderMapper.updateById(entity);
+                //鏇存柊璁惧淇濆吇鐘舵��
+                eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name());
                 return result.isSuccess();
             }
+
         }
         return true;
     }
@@ -266,14 +284,21 @@
         if (!WeekMaintenanceStatusEnum.WAIT_MAINTENANCE.name().equals(entity.getMaintenanceStatus())) {
             throw new JeecgBootException("璇ュ伐鍗曞凡杩涜杩囬鍙栵紒");
         }
+        EamEquipment equipment = eamEquipmentService.getById(entity.getEquipmentId());
+        if (equipment == null) {
+            throw new JeecgBootException("璁惧涓嶅瓨鍦紝娣诲姞澶辫触锛�");
+        }
         LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        if(sysUser == null || !BusinessCodeConst.PCR0001.equals(sysUser.getPost())) {
+            throw new JeecgBootException("涓嶆槸鎿嶄綔宸ワ紝鏃犳硶棰嗗彇姝ゅ伐鍗曪紒");
+        }
         entity.setOperator(sysUser.getUsername());
         entity.setMaintenanceStatus(WeekMaintenanceStatusEnum.UNDER_MAINTENANCE.name());
         entity.setActualStartTime(new Date());
         eamWeekMaintenanceOrderMapper.updateById(entity);
 
         //鍚姩娴佺▼
-        flowCommonService.initActBusiness("宸ュ崟鍙�:" + entity.getOrderNum() + ";寮�濮嬭繘琛岃澶囧懆淇�",
+        flowCommonService.initActBusiness("宸ュ崟鍙�:" + entity.getOrderNum() + ";璁惧缂栧彿: " + equipment.getEquipmentCode() + ";杩涜璁惧鍛ㄤ繚",
                 entity.getId(), "IEamWeekMaintenanceOrderService", "week_maintenance_process", null);
         Map<String, Object> variables = new HashMap<>();
         variables.put("dataId", entity.getId());
@@ -290,6 +315,8 @@
         variables.put("NextAssignee", usernames);
         Result result = flowDefinitionService.startProcessInstanceByKey("week_maintenance_process", variables);
         if (result != null) {
+            //鏇存柊璁惧淇濆吇鐘舵��
+            eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name());
             return result.isSuccess();
         }
         return true;
@@ -297,7 +324,8 @@
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public boolean approval(EamWeekMaintenanceRequest request) {
+    @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.WEEK_MAINTENANCE, businessTable = "eam_week_maintenance_order")
+    public EamWeekMaintenanceOrder approval(EamWeekMaintenanceRequest request) {
         EamWeekMaintenanceOrder entity = eamWeekMaintenanceOrderMapper.selectById(request.getId());
         if (entity == null) {
             throw new JeecgBootException("瀹℃壒鐨勬暟鎹凡鍒犻櫎锛岃鍒锋柊閲嶈瘯锛�");
@@ -330,7 +358,7 @@
 
         WeekMaintenanceStatusEnum status = WeekMaintenanceStatusEnum.getInstance(entity.getMaintenanceStatus());
         if (status == null) {
-            return false;
+            return null;
         }
         //娴佺▼鍙橀噺
         Map<String, Object> values = new HashMap<>();
@@ -365,8 +393,13 @@
                 if (CollectionUtil.isNotEmpty(request.getTableDetailList())) {
                     eamWeekMaintenanceOrderDetailService.updateBatchById(request.getTableDetailList());
                 }
+                //鏇存柊璁惧淇濆吇鐘舵��
+                eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.WAIT_CONFIRM.name());
                 break;
             case WAIT_CONFIRM:
+                if (StringUtils.isBlank(equipment.getEquipmentManager())) {
+                    throw new JeecgBootException("璁惧鏈垎閰嶈澶囩鐞嗗憳锛屾棤娉曡繘鍏ヤ笅绾у鎵癸紒");
+                }
                 //鐝粍闀跨‘璁�
                 userApprovalList = new ArrayList<>();
                 userApprovalList.add(equipment.getEquipmentManager());
@@ -381,6 +414,7 @@
                 entity.setConfirmUser(user.getUsername());
                 entity.setConfirmComment(request.getConfirmComment());
                 entity.setConfirmTime(new Date());
+                entity.setConfirmDealType(request.getConfirmDealType());
                 if (CommonConstant.HAS_CANCLE.equals(request.getConfirmDealType())) {
                     //椹冲洖
                     userApprovalList = new ArrayList<>();
@@ -397,7 +431,7 @@
             case WAIT_INITIAL_ACCEPTANCE:
                 userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getOrgId(), BusinessCodeConst.PCR0005);
                 if (CollectionUtil.isEmpty(userSelectors)) {
-                    throw new JeecgBootException("璁惧鏈垎閰嶇粰鐝粍闀匡紝鏃犳硶杩涘叆涓嬬骇瀹℃壒锛�");
+                    throw new JeecgBootException("璁惧鏈垎閰嶇粰璁捐兘閮ㄧ鐞嗗憳锛屾棤娉曡繘鍏ヤ笅绾у鎵癸紒");
                 }
                 userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                 values.put("dataId", entity.getId());
@@ -424,9 +458,9 @@
                 break;
             case WAIT_FINAL_ACCEPTANCE:
                 values.put("dataId", entity.getId());
-                values.put("organization", request.getInitialAcceptanceComment());
-                values.put("comment", request.getInitialAcceptanceComment());
-                request.setComment(request.getInitialAcceptanceComment());
+                values.put("organization", request.getFinalAcceptanceComment());
+                values.put("comment", request.getFinalAcceptanceComment());
+                request.setComment(request.getFinalAcceptanceComment());
                 //璁剧疆entity
                 entity.setMaintenanceStatus(WeekMaintenanceStatusEnum.COMPLETE.name());
                 entity.setFinalAcceptanceUser(user.getUsername());
@@ -443,6 +477,8 @@
                         log.error("JSON杞崲澶辫触锛�" + e.getMessage(), e);
                     }
                 }
+                //鏇存柊璁惧淇濆吇鐘舵��
+                eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.NORMAL.name());
                 break;
         }
         request.setValues(values);
@@ -454,7 +490,40 @@
         }
         //淇濆瓨宸ュ崟
         eamWeekMaintenanceOrderMapper.updateById(entity);
-        return true;
+        return entity;
+    }
+
+    @Override
+    public List<EamWeekMaintenanceOrder> selectUnCompleteOrder(String expiredDate) {
+        LambdaQueryWrapper<EamWeekMaintenanceOrder> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.lt(EamWeekMaintenanceOrder::getMaintenanceDate, expiredDate);
+        List<String> unCompleteStatus = new ArrayList<>();
+        unCompleteStatus.add(WeekMaintenanceStatusEnum.WAIT_MAINTENANCE.name());
+        unCompleteStatus.add(WeekMaintenanceStatusEnum.UNDER_MAINTENANCE.name());
+        queryWrapper.in(EamWeekMaintenanceOrder::getMaintenanceStatus, unCompleteStatus);
+        queryWrapper.orderByAsc(EamWeekMaintenanceOrder::getMaintenanceDate);
+        return eamWeekMaintenanceOrderMapper.selectList(queryWrapper);
+    }
+
+    @Override
+    public List<EquipmentMaintenanceStatistics> equipmentMaintenanceStatistics(String productionId, LocalDate firstOfMonth, LocalDate today) {
+        if (StringUtils.isNotBlank(productionId)) {
+            //杞﹂棿缂栫爜涓嶄负绌�
+            List<String> productIds = mdcProductionService.recursionChildren(productionId);
+            if (CollectionUtil.isEmpty(productIds)) {
+                return Collections.emptyList();
+            }
+            List<EquipmentMaintenanceStatistics> list = this.baseMapper.equipmentMaintenanceStatistics(productIds, firstOfMonth.toString(), today.plusDays(1).toString());
+            if (CollectionUtil.isEmpty(list)) {
+                return Collections.emptyList();
+            }
+            return list;
+        }
+        List<EquipmentMaintenanceStatistics> list = this.baseMapper.equipmentMaintenanceStatistics(null, firstOfMonth.toString(), today.plusDays(1).toString());
+        if (CollectionUtil.isEmpty(list)) {
+            return Collections.emptyList();
+        }
+        return list;
     }
 
     private boolean isUserAuthorized(FlowMyBusiness flowMyBusiness, LoginUser user) {

--
Gitblit v1.9.3