From 23855599412c4d61b38d78f0f3abd3430a48b5b1 Mon Sep 17 00:00:00 2001 From: zhangherong <571457620@qq.com> Date: 星期三, 25 六月 2025 11:51:38 +0800 Subject: [PATCH] Merge branch 'mdc_hyjs_master' --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/CollectEquipmentDataMonthJob.java | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 177 insertions(+), 0 deletions(-) diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/CollectEquipmentDataMonthJob.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/CollectEquipmentDataMonthJob.java new file mode 100644 index 0000000..07bbabf --- /dev/null +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/CollectEquipmentDataMonthJob.java @@ -0,0 +1,177 @@ +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.MdcEquipmentStatisticalDto; +import org.jeecg.modules.mdc.entity.MdcEquipment; +import org.jeecg.modules.mdc.entity.MdcEquipmentStatisticalInfoMonth; +import org.jeecg.modules.mdc.entity.MdcEquipmentStatisticalShiftInfoMonth; +import org.jeecg.modules.mdc.service.*; +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.Job; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * @Author: Lius + * @CreateTime: 2025-03-24 + * @Description: 缁熻鏈堟眹鎬绘暟鎹� + */ +@Slf4j +public class CollectEquipmentDataMonthJob 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 IMdcEquipmentStatisticalInfoMonthService mdcEquipmentStatisticalInfoMonthService; + + @Resource + private IMdcEquipmentStatisticalInfoService mdcEquipmentStatisticalInfoService; + + @Resource + private IMdcEquipmentStatisticalShiftInfoMonthService mdcEquipmentStatisticalShiftInfoMonthService; + + @Resource + private IMdcEquipmentStatisticalShiftInfoService mdcEquipmentStatisticalShiftInfoService; + + @Resource + private IMdcEquipmentService mdcEquipmentService; + + @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(String.format("缁熻鏈堟眹鎬绘暟鎹� param: %s CollectEquipmentDataMonthJob 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.STRYEARMONTH), DateUtils.STRYEARMONTH); + } else { + date = DateUtils.format(DateUtils.addMonth(-1, DateUtils.getNow()), DateUtils.STRYEARMONTH); + } + mdcEquipmentStatisticalInfoMonthService.remove(new LambdaQueryWrapper<MdcEquipmentStatisticalInfoMonth>().eq(MdcEquipmentStatisticalInfoMonth::getTheMonth, date)); + mdcEquipmentStatisticalShiftInfoMonthService.remove(new LambdaQueryWrapper<MdcEquipmentStatisticalShiftInfoMonth>().eq(MdcEquipmentStatisticalShiftInfoMonth::getTheMonth, date)); + + // step.1 鑾峰彇璁惧鍒楄〃 + List<MdcEquipment> mdcEquipmentList = mdcEquipmentService.list(); + List<MdcEquipmentStatisticalInfoMonth> mdcEquipmentStatisticalInfoMonthList = new ArrayList<>(); + List<MdcEquipmentStatisticalShiftInfoMonth> mdcEquipmentStatisticalShiftInfoMonthList = new ArrayList<>(); + if (mdcEquipmentList != null && !mdcEquipmentList.isEmpty()) { + for (MdcEquipment mdcEquipment : mdcEquipmentList) { + // step.2 姹囨��24灏忔椂鍒╃敤鐜囨暟鎹� + MdcEquipmentStatisticalDto mdcEquipmentStatisticalDto = mdcEquipmentStatisticalInfoService.findByEquipmentAndMonth(mdcEquipment.getEquipmentId(), date); + MdcEquipmentStatisticalInfoMonth mdcEquipmentStatisticalInfoMonth = new MdcEquipmentStatisticalInfoMonth(); + mdcEquipmentStatisticalInfoMonth.setEquipmentId(mdcEquipment.getEquipmentId()); + mdcEquipmentStatisticalInfoMonth.setTheMonth(date); + if (mdcEquipmentStatisticalDto != null) { + mdcEquipmentStatisticalInfoMonth.setCloseLong(mdcEquipmentStatisticalDto.getCloseLong().intValue()); + mdcEquipmentStatisticalInfoMonth.setErrorLong(mdcEquipmentStatisticalDto.getErrorLong().intValue()); + mdcEquipmentStatisticalInfoMonth.setOpenLong(mdcEquipmentStatisticalDto.getOpenLong().intValue()); + mdcEquipmentStatisticalInfoMonth.setProcessLong(mdcEquipmentStatisticalDto.getProcessLong().intValue()); + mdcEquipmentStatisticalInfoMonth.setWaitLong(mdcEquipmentStatisticalDto.getWaitLong().intValue()); + mdcEquipmentStatisticalInfoMonth.setOpenRate(mdcEquipmentStatisticalDto.getOpenLong().divide((new BigDecimal("864").multiply(mdcEquipmentStatisticalDto.getDayNum())), 4, RoundingMode.HALF_UP)); + mdcEquipmentStatisticalInfoMonth.setStartRate(mdcEquipmentStatisticalDto.getOpenLong().compareTo(BigDecimal.ZERO) > 0 ? mdcEquipmentStatisticalDto.getProcessLong().divide(mdcEquipmentStatisticalDto.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); + mdcEquipmentStatisticalInfoMonth.setUtilizationRate(mdcEquipmentStatisticalDto.getProcessLong().divide((new BigDecimal("864").multiply(mdcEquipmentStatisticalDto.getDayNum())), 4, RoundingMode.HALF_UP)); + mdcEquipmentStatisticalInfoMonth.setFaultLong(mdcEquipmentStatisticalDto.getFaultLong().intValue()); + mdcEquipmentStatisticalInfoMonth.setFaultRate(mdcEquipmentStatisticalDto.getFaultRate()); + mdcEquipmentStatisticalInfoMonth.setRemoveFaultRate(mdcEquipmentStatisticalDto.getRemoveFaultRate()); + mdcEquipmentStatisticalInfoMonth.setRemoveFaultRunLong(mdcEquipmentStatisticalDto.getRemoveFaultRunLong().intValue()); + } + mdcEquipmentStatisticalInfoMonthList.add(mdcEquipmentStatisticalInfoMonth); + // step.3 姹囨�荤彮娆″埄鐢ㄧ巼鏁版嵁 + MdcEquipmentStatisticalDto mdcEquipmentShiftStatisticalDto = mdcEquipmentStatisticalShiftInfoService.findByEquipmentAndMonth(mdcEquipment.getEquipmentId(), date); + MdcEquipmentStatisticalShiftInfoMonth mdcEquipmentShiftInfoMonth = new MdcEquipmentStatisticalShiftInfoMonth(); + mdcEquipmentShiftInfoMonth.setEquipmentId(mdcEquipment.getEquipmentId()); + mdcEquipmentShiftInfoMonth.setTheMonth(date); + mdcEquipmentShiftInfoMonth.setShiftType(CommonConstant.SHIFT_TYPE_1); + if (mdcEquipmentShiftStatisticalDto != null) { + mdcEquipmentShiftInfoMonth.setCloseLong(mdcEquipmentShiftStatisticalDto.getCloseLong().intValue()); + mdcEquipmentShiftInfoMonth.setTotalLong(mdcEquipmentShiftStatisticalDto.getTotalLong().intValue()); + mdcEquipmentShiftInfoMonth.setOpenLong(mdcEquipmentShiftStatisticalDto.getOpenLong().intValue()); + mdcEquipmentShiftInfoMonth.setErrorLong(mdcEquipmentShiftStatisticalDto.getErrorLong().intValue()); + mdcEquipmentShiftInfoMonth.setWaitLong(mdcEquipmentShiftStatisticalDto.getWaitLong().intValue()); + mdcEquipmentShiftInfoMonth.setProcessLong(mdcEquipmentShiftStatisticalDto.getProcessLong().intValue()); + mdcEquipmentShiftInfoMonth.setUtilizationRate(mdcEquipmentShiftStatisticalDto.getTotalLong().compareTo(BigDecimal.ZERO) > 0 ? mdcEquipmentShiftStatisticalDto.getProcessLong().divide(mdcEquipmentShiftStatisticalDto.getTotalLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); + mdcEquipmentShiftInfoMonth.setStartRate(mdcEquipmentShiftStatisticalDto.getOpenLong().compareTo(BigDecimal.ZERO) > 0 ? mdcEquipmentShiftStatisticalDto.getProcessLong().divide(mdcEquipmentShiftStatisticalDto.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); + mdcEquipmentShiftInfoMonth.setOpenRate(mdcEquipmentShiftStatisticalDto.getTotalLong().compareTo(BigDecimal.ZERO) > 0 ? mdcEquipmentShiftStatisticalDto.getOpenLong().divide(mdcEquipmentShiftStatisticalDto.getTotalLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); + } + mdcEquipmentStatisticalShiftInfoMonthList.add(mdcEquipmentShiftInfoMonth); + // step.4 姹囨�诲悇鐝鍒╃敤鐜囨暟鎹� + List<MdcEquipmentStatisticalDto> essdList = mdcEquipmentStatisticalShiftInfoService.findShiftByEquipmentAndMonth(mdcEquipment.getEquipmentId(), date); + if (essdList != null && !essdList.isEmpty()) { + for (MdcEquipmentStatisticalDto equipmentStatisticalDto : essdList) { + MdcEquipmentStatisticalShiftInfoMonth equipmentStatisticalShiftInfoMonth = new MdcEquipmentStatisticalShiftInfoMonth(); + equipmentStatisticalShiftInfoMonth.setEquipmentId(mdcEquipment.getEquipmentId()); + equipmentStatisticalShiftInfoMonth.setTheMonth(date); + equipmentStatisticalShiftInfoMonth.setShiftType(CommonConstant.SHIFT_TYPE_2); + equipmentStatisticalShiftInfoMonth.setCloseLong(equipmentStatisticalDto.getCloseLong().intValue()); + equipmentStatisticalShiftInfoMonth.setTotalLong(equipmentStatisticalDto.getTotalLong().intValue()); + equipmentStatisticalShiftInfoMonth.setOpenLong(equipmentStatisticalDto.getOpenLong().intValue()); + equipmentStatisticalShiftInfoMonth.setErrorLong(equipmentStatisticalDto.getErrorLong().intValue()); + equipmentStatisticalShiftInfoMonth.setWaitLong(equipmentStatisticalDto.getWaitLong().intValue()); + equipmentStatisticalShiftInfoMonth.setProcessLong(equipmentStatisticalDto.getProcessLong().intValue()); + equipmentStatisticalShiftInfoMonth.setUtilizationRate(equipmentStatisticalDto.getTotalLong().compareTo(BigDecimal.ZERO) > 0 ? equipmentStatisticalDto.getProcessLong().divide(equipmentStatisticalDto.getTotalLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); + equipmentStatisticalShiftInfoMonth.setStartRate(equipmentStatisticalDto.getOpenLong().compareTo(BigDecimal.ZERO) > 0 ? equipmentStatisticalDto.getProcessLong().divide(equipmentStatisticalDto.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); + equipmentStatisticalShiftInfoMonth.setOpenRate(equipmentStatisticalDto.getTotalLong().compareTo(BigDecimal.ZERO) > 0 ? equipmentStatisticalDto.getOpenLong().divide(equipmentStatisticalDto.getTotalLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); + mdcEquipmentStatisticalShiftInfoMonthList.add(equipmentStatisticalShiftInfoMonth); + } + } + } + } + if (!mdcEquipmentStatisticalInfoMonthList.isEmpty()) { + mdcEquipmentStatisticalInfoMonthService.saveBatch(mdcEquipmentStatisticalInfoMonthList); + } + if (!mdcEquipmentStatisticalShiftInfoMonthList.isEmpty()) { + mdcEquipmentStatisticalShiftInfoMonthService.saveBatch(mdcEquipmentStatisticalShiftInfoMonthList); + } + 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); + } + + +} -- Gitblit v1.9.3