From c9eea9f24aa52ea59dbb8dcf1cb6cf513ddc74a9 Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期五, 25 四月 2025 11:37:32 +0800
Subject: [PATCH] 待机停机维护

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/ScanDowntimeJob.java                 |  220 ++++++++++++++++++------------------
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDowntimeServiceImpl.java |   32 +++++
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcDowntime.java                  |   29 +---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcDowntimeService.java         |    7 +
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcDowntimeController.java    |   18 +-
 5 files changed, 166 insertions(+), 140 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcDowntimeController.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcDowntimeController.java
index e3bc683..ae4d7c1 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcDowntimeController.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcDowntimeController.java
@@ -1,7 +1,7 @@
 package org.jeecg.modules.mdc.controller;
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -9,13 +9,10 @@
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
-import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.system.base.controller.JeecgController;
-import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.modules.mdc.dto.MdcDowntimeDto;
 import org.jeecg.modules.mdc.entity.MdcDowntime;
-import org.jeecg.modules.mdc.entity.MdcEquipmentOvertime;
 import org.jeecg.modules.mdc.service.IMdcDowntimeService;
 import org.jeecg.modules.mdc.vo.MdcDowntimeVo;
 import org.springframework.web.bind.annotation.*;
@@ -73,8 +70,11 @@
     @ApiOperation(value = "寰呮満鍋滄満琛�-娣诲姞", notes = "寰呮満鍋滄満琛�-娣诲姞")
     @PostMapping(value = "/add")
     public Result<?> add(@RequestBody MdcDowntime mdcDowntime) {
-        mdcDowntimeService.save(mdcDowntime);
-        return Result.OK("娣诲姞鎴愬姛锛�");
+        if (StringUtils.isBlank(mdcDowntime.getEquipmentIds())) {
+            return Result.error("鏈�夋嫨璁惧锛岃鎺掓煡");
+        }
+        boolean flag = mdcDowntimeService.saveDowntime(mdcDowntime);
+        return flag ? Result.ok("娣诲姞鎴愬姛") : Result.error("娣诲姞澶辫触");
     }
 
     /**
@@ -87,9 +87,9 @@
     @ApiOperation(value = "寰呮満鍋滄満琛�-缂栬緫", notes = "寰呮満鍋滄満琛�-缂栬緫")
     @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
     public Result<?> edit(@RequestBody MdcDowntime mdcDowntime) {
-        if (mdcDowntime.getReasonId() != null) {
-            mdcDowntime.setStatus(CommonConstant.DOWNTIME_STATUS_1);
-        }
+//        if (mdcDowntime.getReasonId() != null) {
+//            mdcDowntime.setStatus(CommonConstant.DOWNTIME_STATUS_1);
+//        }
         mdcDowntimeService.updateById(mdcDowntime);
         return Result.OK("缂栬緫鎴愬姛!");
     }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcDowntime.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcDowntime.java
index cefff4d..1aff187 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcDowntime.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcDowntime.java
@@ -1,5 +1,6 @@
 package org.jeecg.modules.mdc.entity;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
@@ -42,33 +43,18 @@
     @ApiModelProperty(value = "璁惧鍚嶇О")
     private String equipmentName;
     /**
-     * 寮�濮嬫椂闂�
-     */
-    @Excel(name = "寮�濮嬫椂闂�", width = 20, format = "yyyy-MM-dd HH:mm:ss")
-    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
-    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    @ApiModelProperty(value = "寮�濮嬫椂闂�")
-    private Date startDate;
-    /**
-     * 缁撴潫鏃堕棿
-     */
-    @Excel(name = "缁撴潫鏃堕棿", width = 20, format = "yyyy-MM-dd HH:mm:ss")
-    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
-    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    @ApiModelProperty(value = "缁撴潫鏃堕棿")
-    private Date endDate;
-    /**
      * 鍋滄満鍘熷洜id
      */
     @Excel(name = "鍋滄満鍘熷洜id", width = 15)
     @ApiModelProperty(value = "鍋滄満鍘熷洜id")
     private String reasonId;
+
     /**
-     * 鐘舵�侊紙0鏈笂鎶ワ紝1宸蹭笂鎶ワ級
+     * 鍋滄満鏃堕暱
      */
-    @Excel(name = "鐘舵��", width = 15)
-    @ApiModelProperty(value = "鐘舵�侊紙0鏈笂鎶ワ紝1宸蹭笂鎶ワ級")
-    private Integer status = 0;
+    @Excel(name = "鍋滄満鏃堕暱", width = 15)
+    @ApiModelProperty(value = "鍋滄満鏃堕暱")
+    private Integer downLong;
     /**
      * 鏃ユ湡
      */
@@ -82,4 +68,7 @@
     @ApiModelProperty(value = "澶囨敞")
     private String remark;
 
+    @TableField(exist = false)
+    private String equipmentIds;
+
 }
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/ScanDowntimeJob.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/ScanDowntimeJob.java
index eafa8fc..8468390 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/ScanDowntimeJob.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/ScanDowntimeJob.java
@@ -1,110 +1,110 @@
-package org.jeecg.modules.mdc.job;
-
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang.StringUtils;
-import org.jeecg.common.constant.CommonConstant;
-import org.jeecg.modules.mdc.dto.MdcEquipmentWaitSectionDto;
-import org.jeecg.modules.mdc.entity.MdcDowntime;
-import org.jeecg.modules.mdc.entity.MdcEquipmentOvertime;
-import org.jeecg.modules.mdc.entity.MdcEquipmentRunningSection;
-import org.jeecg.modules.mdc.service.IMdcDowntimeService;
-import org.jeecg.modules.mdc.service.IMdcEquipmentRunningSectionService;
-import org.jeecg.modules.mdc.util.DateUtils;
-import org.jeecg.modules.mdc.util.ThrowableUtil;
-import org.jeecg.modules.quartz.entity.QuartzJob;
-import org.jeecg.modules.quartz.entity.SysQuartzLog;
-import org.jeecg.modules.quartz.service.IQuartzJobService;
-import org.jeecg.modules.quartz.service.ISysQuartzLogService;
-import org.jeecg.modules.system.service.ISysAnnouncementService;
-import org.quartz.*;
-
-import javax.annotation.Resource;
-import java.util.Date;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * @Author: Lius
- * @CreateTime: 2025-03-12
- * @Description: 鎵弿鍋滄満浠诲姟
- */
-@PersistJobDataAfterExecution
-@DisallowConcurrentExecution
-@Slf4j
-public class ScanDowntimeJob implements Job {
-
-    /**
-     * 鑻ュ弬鏁板彉閲忓悕淇敼 QuartzJobController涓篃闇�瀵瑰簲淇敼  鏃堕棿锛� yyyyMMdd 渚嬶細 20230414
-     */
-    private String parameter;
-
-    public void setParameter(String parameter) {
-        this.parameter = parameter;
-    }
-
-    @Resource
-    private IQuartzJobService quartzJobService;
-
-    @Resource
-    private ISysAnnouncementService sysAnnouncementService;
-
-    @Resource
-    private ISysQuartzLogService sysQuartzLogService;
-
-    @Resource
-    private IMdcEquipmentRunningSectionService mdcEquipmentRunningSectionService;
-
-    @Resource
-    private IMdcDowntimeService mdcDowntimeService;
-
-    @Override
-    public void execute(JobExecutionContext context) throws JobExecutionException {
-        SysQuartzLog quartzLog = new SysQuartzLog();
-        quartzLog.setCreateTime(new Date());
-        List<QuartzJob> byJobClassName = this.quartzJobService.findByJobClassName(this.getClass().getName());
-        if (byJobClassName != null && !byJobClassName.isEmpty()) {
-            quartzLog.setJobId(byJobClassName.get(0).getId());
-        }
-        quartzLog.setParams(this.parameter);
-        log.info("瀹氭椂鎵弿寰呮満鏃堕暱瓒�20鍒嗛挓璁惧浠诲姟 ScanDowntimeJob start!  鏃堕棿:{}, 鍙傛暟锛歿}", DateUtils.getNow(), this.parameter);
-        long startTime = System.currentTimeMillis();
-        try {
-            String date = "";
-            if (StringUtils.isNotBlank(this.parameter)) {
-                date = DateUtils.format(DateUtils.toDate(this.parameter, DateUtils.STRDATE), DateUtils.STR_DATE);
-
-            } else {
-                date = DateUtils.format(DateUtils.getNow(), DateUtils.STR_DATE);
-            }
-            mdcDowntimeService.remove(new LambdaQueryWrapper<MdcDowntime>().eq(MdcDowntime::getTheDate, date).eq(MdcDowntime::getStatus, CommonConstant.DOWNTIME_STATUS_0));
-
-            List<MdcEquipmentWaitSectionDto> mdcEquipmentRunningSections = mdcEquipmentRunningSectionService.findWaitList(date);
-
-            if (mdcEquipmentRunningSections != null && !mdcEquipmentRunningSections.isEmpty()) {
-                String finalDate = date;
-                List<MdcDowntime> downtimeList = mdcEquipmentRunningSections.stream().map(mdcEquipmentWaitSectionDto -> {
-                    MdcDowntime downtime = new MdcDowntime();
-                    downtime.setEquipmentId(mdcEquipmentWaitSectionDto.getEquipmentId());
-                    downtime.setEquipmentName(mdcEquipmentWaitSectionDto.getEquipmentName());
-                    downtime.setTheDate(finalDate);
-                    downtime.setStartDate(mdcEquipmentWaitSectionDto.getStartTime());
-                    downtime.setEndDate(mdcEquipmentWaitSectionDto.getEndTime());
-                    return downtime;
-                }).collect(Collectors.toList());
-                if (!downtimeList.isEmpty()) {
-                    mdcDowntimeService.saveBatch(downtimeList);
-                }
-            }
-            quartzLog.setIsSuccess(0);
-        } catch (Exception e) {
-            quartzLog.setIsSuccess(-1);
-            quartzLog.setExceptionDetail(ThrowableUtil.getStackTrace(e));
-            // 鍙戦�佹秷鎭�氱煡
-            sysAnnouncementService.jobSendMessage("瀹氭椂鎵弿寰呮満鏃堕暱瓒�20鍒嗛挓璁惧浠诲姟", quartzLog.getExceptionDetail());
-        }
-        long endTime = System.currentTimeMillis();
-        quartzLog.setExecutionTime(Integer.parseInt(String.valueOf(endTime - startTime)));
-        sysQuartzLogService.save(quartzLog);
-    }
-}
+//package org.jeecg.modules.mdc.job;
+//
+//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+//import lombok.extern.slf4j.Slf4j;
+//import org.apache.commons.lang.StringUtils;
+//import org.jeecg.common.constant.CommonConstant;
+//import org.jeecg.modules.mdc.dto.MdcEquipmentWaitSectionDto;
+//import org.jeecg.modules.mdc.entity.MdcDowntime;
+//import org.jeecg.modules.mdc.entity.MdcEquipmentOvertime;
+//import org.jeecg.modules.mdc.entity.MdcEquipmentRunningSection;
+//import org.jeecg.modules.mdc.service.IMdcDowntimeService;
+//import org.jeecg.modules.mdc.service.IMdcEquipmentRunningSectionService;
+//import org.jeecg.modules.mdc.util.DateUtils;
+//import org.jeecg.modules.mdc.util.ThrowableUtil;
+//import org.jeecg.modules.quartz.entity.QuartzJob;
+//import org.jeecg.modules.quartz.entity.SysQuartzLog;
+//import org.jeecg.modules.quartz.service.IQuartzJobService;
+//import org.jeecg.modules.quartz.service.ISysQuartzLogService;
+//import org.jeecg.modules.system.service.ISysAnnouncementService;
+//import org.quartz.*;
+//
+//import javax.annotation.Resource;
+//import java.util.Date;
+//import java.util.List;
+//import java.util.stream.Collectors;
+//
+///**
+// * @Author: Lius
+// * @CreateTime: 2025-03-12
+// * @Description: 鎵弿鍋滄満浠诲姟
+// */
+//@PersistJobDataAfterExecution
+//@DisallowConcurrentExecution
+//@Slf4j
+//public class ScanDowntimeJob implements Job {
+//
+//    /**
+//     * 鑻ュ弬鏁板彉閲忓悕淇敼 QuartzJobController涓篃闇�瀵瑰簲淇敼  鏃堕棿锛� yyyyMMdd 渚嬶細 20230414
+//     */
+//    private String parameter;
+//
+//    public void setParameter(String parameter) {
+//        this.parameter = parameter;
+//    }
+//
+//    @Resource
+//    private IQuartzJobService quartzJobService;
+//
+//    @Resource
+//    private ISysAnnouncementService sysAnnouncementService;
+//
+//    @Resource
+//    private ISysQuartzLogService sysQuartzLogService;
+//
+//    @Resource
+//    private IMdcEquipmentRunningSectionService mdcEquipmentRunningSectionService;
+//
+//    @Resource
+//    private IMdcDowntimeService mdcDowntimeService;
+//
+//    @Override
+//    public void execute(JobExecutionContext context) throws JobExecutionException {
+//        SysQuartzLog quartzLog = new SysQuartzLog();
+//        quartzLog.setCreateTime(new Date());
+//        List<QuartzJob> byJobClassName = this.quartzJobService.findByJobClassName(this.getClass().getName());
+//        if (byJobClassName != null && !byJobClassName.isEmpty()) {
+//            quartzLog.setJobId(byJobClassName.get(0).getId());
+//        }
+//        quartzLog.setParams(this.parameter);
+//        log.info("瀹氭椂鎵弿寰呮満鏃堕暱瓒�20鍒嗛挓璁惧浠诲姟 ScanDowntimeJob start!  鏃堕棿:{}, 鍙傛暟锛歿}", DateUtils.getNow(), this.parameter);
+//        long startTime = System.currentTimeMillis();
+//        try {
+//            String date = "";
+//            if (StringUtils.isNotBlank(this.parameter)) {
+//                date = DateUtils.format(DateUtils.toDate(this.parameter, DateUtils.STRDATE), DateUtils.STR_DATE);
+//
+//            } else {
+//                date = DateUtils.format(DateUtils.getNow(), DateUtils.STR_DATE);
+//            }
+//            mdcDowntimeService.remove(new LambdaQueryWrapper<MdcDowntime>().eq(MdcDowntime::getTheDate, date).eq(MdcDowntime::getStatus, CommonConstant.DOWNTIME_STATUS_0));
+//
+//            List<MdcEquipmentWaitSectionDto> mdcEquipmentRunningSections = mdcEquipmentRunningSectionService.findWaitList(date);
+//
+//            if (mdcEquipmentRunningSections != null && !mdcEquipmentRunningSections.isEmpty()) {
+//                String finalDate = date;
+//                List<MdcDowntime> downtimeList = mdcEquipmentRunningSections.stream().map(mdcEquipmentWaitSectionDto -> {
+//                    MdcDowntime downtime = new MdcDowntime();
+//                    downtime.setEquipmentId(mdcEquipmentWaitSectionDto.getEquipmentId());
+//                    downtime.setEquipmentName(mdcEquipmentWaitSectionDto.getEquipmentName());
+//                    downtime.setTheDate(finalDate);
+//                    downtime.setStartDate(mdcEquipmentWaitSectionDto.getStartTime());
+//                    downtime.setEndDate(mdcEquipmentWaitSectionDto.getEndTime());
+//                    return downtime;
+//                }).collect(Collectors.toList());
+//                if (!downtimeList.isEmpty()) {
+//                    mdcDowntimeService.saveBatch(downtimeList);
+//                }
+//            }
+//            quartzLog.setIsSuccess(0);
+//        } catch (Exception e) {
+//            quartzLog.setIsSuccess(-1);
+//            quartzLog.setExceptionDetail(ThrowableUtil.getStackTrace(e));
+//            // 鍙戦�佹秷鎭�氱煡
+//            sysAnnouncementService.jobSendMessage("瀹氭椂鎵弿寰呮満鏃堕暱瓒�20鍒嗛挓璁惧浠诲姟", quartzLog.getExceptionDetail());
+//        }
+//        long endTime = System.currentTimeMillis();
+//        quartzLog.setExecutionTime(Integer.parseInt(String.valueOf(endTime - startTime)));
+//        sysQuartzLogService.save(quartzLog);
+//    }
+//}
diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcDowntimeService.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcDowntimeService.java
index 80807ff..9fd1735 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcDowntimeService.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcDowntimeService.java
@@ -35,4 +35,11 @@
      * @return
      */
     Integer findPlanTimeDuration(String equipmentId, String validDate, String closeType);
+
+    /**
+     * 娣诲姞
+     * @param mdcDowntime
+     * @return
+     */
+    boolean saveDowntime(MdcDowntime mdcDowntime);
 }
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 8826b16..c7dff38 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
@@ -6,17 +6,21 @@
 import org.apache.commons.lang3.StringUtils;
 import org.jeecg.modules.mdc.dto.MdcDowntimeDto;
 import org.jeecg.modules.mdc.entity.MdcDowntime;
+import org.jeecg.modules.mdc.entity.MdcEquipment;
+import org.jeecg.modules.mdc.entity.MdcStandardProcessDuration;
 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.util.DateUtils;
 import org.jeecg.modules.mdc.vo.MdcDowntimeVo;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -62,12 +66,38 @@
         List<MdcDowntime> mdcDowntimeList = this.baseMapper.findPlanTimeDuration(equipmentId, validDate, closeType);
         if (mdcDowntimeList != null && !mdcDowntimeList.isEmpty()) {
             for (MdcDowntime mdcDowntime : mdcDowntimeList) {
-                result = DateUtils.differentMinutes(mdcDowntime.getStartDate(), mdcDowntime.getEndDate()) + result;
+//                Date startDate = DateUtils.toDate(mdcDowntime.getTheDate() + " " + mdcDowntime.getStartTime(), DateUtils.STR_DATE_TIME_SMALL);
+//                Date endDate = DateUtils.toDate(mdcDowntime.getTheDate() + " " + mdcDowntime.getEndTime(), DateUtils.STR_DATE_TIME_SMALL);
+                result = mdcDowntime.getDownLong() + result;
             }
         }
         return result;
     }
 
+    /**
+     * 娣诲姞
+     * @param mdcDowntime
+     * @return
+     */
+    @Override
+    public boolean saveDowntime(MdcDowntime mdcDowntime) {
+        boolean result = false;
+        String[] equipmentIds = mdcDowntime.getEquipmentIds().split(",");
+        for (String equipmentId : equipmentIds) {
+            MdcEquipment mdcEquipment = mdcEquipmentService.findEquipmentNameByEquipmentId(equipmentId);
+            MdcDowntime downtime = new MdcDowntime();
+            BeanUtils.copyProperties(mdcDowntime, downtime);
+            downtime.setEquipmentId(mdcEquipment.getEquipmentId());
+            downtime.setEquipmentName(mdcEquipment.getEquipmentName());
+            boolean b = super.save(downtime);
+            if (b) {
+                result = true;
+            }
+        }
+
+        return result;
+    }
+
     private List<String> getEquipmentIds(String userId, MdcDowntimeVo mdcDowntimeVo) {
         if (StringUtils.isNotEmpty(mdcDowntimeVo.getEquipmentId())) {
             return Collections.singletonList(mdcDowntimeVo.getEquipmentId());

--
Gitblit v1.9.3