From 7389eaa9dfccf6765fc9b3c62b258625292181c3 Mon Sep 17 00:00:00 2001 From: Lius <Lius2225@163.com> Date: 星期二, 07 十一月 2023 16:16:39 +0800 Subject: [PATCH] 自动生成设备工作日历任务 --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/MdcBigScreenEquipmentDto.java | 2 + lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/GenerateDeviceCalendarJob.java | 62 +++++++++++++++++++++++++++++++ lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcDeviceCalendarService.java | 6 +++ lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDeviceCalendarServiceImpl.java | 42 +++++++++++++++++++++ lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcWorkshopInfoMapper.xml | 3 + 5 files changed, 114 insertions(+), 1 deletions(-) diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/MdcBigScreenEquipmentDto.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/MdcBigScreenEquipmentDto.java index d10b4c9..4817b6b 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/MdcBigScreenEquipmentDto.java +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/dto/MdcBigScreenEquipmentDto.java @@ -21,6 +21,8 @@ private Integer equipmentStatus; + private String equId; + /** * 鍧愭爣-宸� */ diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/GenerateDeviceCalendarJob.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/GenerateDeviceCalendarJob.java new file mode 100644 index 0000000..dd1f9b7 --- /dev/null +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/GenerateDeviceCalendarJob.java @@ -0,0 +1,62 @@ +package org.jeecg.modules.mdc.job; + +import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.util.DateUtils; +import org.jeecg.modules.mdc.service.IMdcDeviceCalendarService; +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.Job; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + +/** + * @author Lius + * @date 2023/11/6 17:45 + */ +@Slf4j +public class GenerateDeviceCalendarJob implements Job { + + @Resource + private IQuartzJobService quartzJobService; + + @Resource + private ISysQuartzLogService sysQuartzLogService; + + @Resource + private ISysAnnouncementService sysAnnouncementService; + + @Resource + private IMdcDeviceCalendarService mdcDeviceCalendarService; + + @Override + public void execute(JobExecutionContext jobExecutionContext) 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()); + } + log.info("瀹氭椂鐢熸垚璁惧宸ヤ綔鏃ュ巻浠诲姟 GenerateDeviceCalendarJob start! 鏃堕棿:" + DateUtils.now()); + long startTime = System.currentTimeMillis(); + try { + mdcDeviceCalendarService.generateDeviceCalendar(); + quartzLog.setIsSuccess(0); + } catch (Exception e) { + quartzLog.setIsSuccess(-1); + quartzLog.setExceptionDetail(ThrowableUtil.getStackTrace(e)); + // 鍙戦�佹秷鎭�氱煡 + sysAnnouncementService.jobSendMessage("瀹氭椂鐢熸垚鍙屼紤鏃ヤ换鍔�", 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/mapper/xml/MdcWorkshopInfoMapper.xml b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcWorkshopInfoMapper.xml index 1a0ecf1..f0f340f 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcWorkshopInfoMapper.xml +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcWorkshopInfoMapper.xml @@ -14,7 +14,8 @@ mew.coordinate_left coordinateLeft, mew.coordinate_top coordinateTop, mew.vw vw, - mew.vh vh + mew.vh vh, + me.id equId FROM EquipmentLog a INNER JOIN ( SELECT EquipmentID, MAX ( CollectTime ) 'maxgdtime' FROM EquipmentLog GROUP BY EquipmentID ) b ON a.EquipmentID= b.EquipmentID diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcDeviceCalendarService.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcDeviceCalendarService.java index a8a00ee..4c2ce4a 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcDeviceCalendarService.java +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/IMdcDeviceCalendarService.java @@ -66,4 +66,10 @@ * @return */ BigDecimal computeShiftTimeCount(String shiftSubId, String equipmentId, String validDate); + + /** + * 鐢熸垚璁惧宸ヤ綔鏃ュ巻 + */ + void generateDeviceCalendar(); + } diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDeviceCalendarServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDeviceCalendarServiceImpl.java index 5d3eec2..06d005d 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDeviceCalendarServiceImpl.java +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDeviceCalendarServiceImpl.java @@ -6,11 +6,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.commons.lang3.StringUtils; import org.jeecg.modules.mdc.entity.MdcDeviceCalendar; +import org.jeecg.modules.mdc.entity.MdcEquipment; import org.jeecg.modules.mdc.entity.MdcShiftSub; +import org.jeecg.modules.mdc.entity.MdcVacationManagement; import org.jeecg.modules.mdc.mapper.MdcDeviceCalendarMapper; import org.jeecg.modules.mdc.service.IMdcDeviceCalendarService; import org.jeecg.modules.mdc.service.IMdcEquipmentService; import org.jeecg.modules.mdc.service.IMdcShiftSubService; +import org.jeecg.modules.mdc.service.IMdcVacationManagementService; import org.jeecg.modules.mdc.vo.EquipmentCalendarVo; import org.jeecg.modules.mdc.vo.MdcDeviceCalendarQueryVo; import org.jeecg.modules.mdc.vo.MdcDeviceCalendarVo; @@ -20,6 +23,7 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -37,6 +41,9 @@ private IMdcEquipmentService mdcEquipmentService; @Resource private IMdcShiftSubService mdcShiftSubService; + + @Resource + private IMdcVacationManagementService mdcVacationManagementService; /** * 鍒嗛〉鍒楄〃鏌ヨ @@ -178,4 +185,39 @@ return new BigDecimal(shiftCount).multiply(new BigDecimal("8")).multiply(new BigDecimal("60")); } + /** + * 鑷姩鐢熸垚璁惧宸ヤ綔鏃ュ巻 + */ + @Override + public void generateDeviceCalendar() { + // 鏆傚畾姣忓ぉ鏅氫笂11鐐规墽琛� + //鏌ヨ榛樿鐝埗 + List<MdcDeviceCalendarVo> acquiesceShift = this.baseMapper.findAcquiesceShift(); + // 鑾峰彇鏄庢棩鏃ユ湡 + String localDate = LocalDate.now().plusDays(1).toString(); + // 鑾峰彇璁惧鍒楄〃 + List<MdcEquipment> equipmentList = mdcEquipmentService.list(); + List<MdcDeviceCalendar> result = new ArrayList<>(); + for (MdcEquipment mdcEquipment : equipmentList) { + List<MdcDeviceCalendar> list = super.list(new LambdaQueryWrapper<MdcDeviceCalendar>().eq(MdcDeviceCalendar::getEquipmentId, mdcEquipment.getEquipmentId()).eq(MdcDeviceCalendar::getEffectiveDate, localDate.replaceAll("-", ""))); + if (list == null || list.isEmpty()) { + List<MdcVacationManagement> vacationManagementList = mdcVacationManagementService.list(new LambdaQueryWrapper<MdcVacationManagement>().eq(MdcVacationManagement::getEquipmentId, mdcEquipment.getEquipmentId()).eq(MdcVacationManagement::getVacationDate, localDate)); + if (vacationManagementList == null || vacationManagementList.isEmpty()) { + String effectiveDate = localDate.replaceAll("-", ""); + for (MdcDeviceCalendarVo mdcDeviceCalendarVo : acquiesceShift) { + MdcDeviceCalendar mdcDeviceCalendar = new MdcDeviceCalendar(); + mdcDeviceCalendar.setEquipmentId(mdcEquipment.getEquipmentId()); + mdcDeviceCalendar.setEffectiveDate(effectiveDate); + mdcDeviceCalendar.setShiftId(mdcDeviceCalendarVo.getShiftId()); + mdcDeviceCalendar.setShiftSubId(mdcDeviceCalendarVo.getShiftSubId()); + result.add(mdcDeviceCalendar); + } + } + } + } + if (!result.isEmpty()) { + super.saveBatch(result); + } + } + } -- Gitblit v1.9.3