¶Ô±ÈÐÂÎļþ |
| | |
| | | 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); |
| | | } |
| | | } |