Lius
2025-04-25 c9eea9f24aa52ea59dbb8dcf1cb6cf513ddc74a9
待机停机维护
已修改5个文件
306 ■■■■ 文件已修改
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcDowntimeController.java 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcDowntime.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/ScanDowntimeJob.java 220 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcDowntimeService.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDowntimeServiceImpl.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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("编辑成功!");
    }
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;
}
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);
//    }
//}
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);
}
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());