From b46815639664c65d31f6f852c4bf403f6ba0c3ea Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期五, 26 一月 2024 10:04:49 +0800
Subject: [PATCH] 加班管理功能调整

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/RunningEquipmentStatusJob.java |  150 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 150 insertions(+), 0 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/RunningEquipmentStatusJob.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/RunningEquipmentStatusJob.java
new file mode 100644
index 0000000..6c79675
--- /dev/null
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/job/RunningEquipmentStatusJob.java
@@ -0,0 +1,150 @@
+package org.jeecg.modules.mdc.job;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.dto.message.MessageDTO;
+import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.common.system.api.ISysBaseAPI;
+import org.jeecg.common.system.vo.DictModel;
+import org.jeecg.modules.mdc.entity.MdcEquipment;
+import org.jeecg.modules.mdc.service.IMdcEquipmentRunningSectionService;
+import org.jeecg.modules.mdc.service.IMdcEquipmentService;
+import org.jeecg.modules.mdc.service.MdcEfficiencyReportService;
+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.jeecg.modules.system.service.ISysDictService;
+import org.quartz.*;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.LocalDate;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author Lius
+ * @Description: 鍒╃敤鐜囨甯稿�硷紝璁惧鐘舵�侀暱鏈熸棤鍙樺寲鎶ヨ
+ * @date 2024/1/17 14:10
+ */
+@PersistJobDataAfterExecution
+@DisallowConcurrentExecution
+@Slf4j
+public class RunningEquipmentStatusJob implements Job {
+
+    @Resource
+    private IQuartzJobService quartzJobService;
+
+    @Resource
+    private ISysQuartzLogService sysQuartzLogService;
+
+    @Resource
+    private ISysAnnouncementService sysAnnouncementService;
+
+    @Resource
+    private IMdcEquipmentService mdcEquipmentService;
+
+    @Resource
+    private ISysDictService sysDictService;
+
+    @Resource
+    private MdcEfficiencyReportService mdcEfficiencyReportService;
+
+    @Resource
+    private ISysBaseAPI sysBaseApi;
+
+    @Resource
+    private IMdcEquipmentRunningSectionService mdcEquipmentRunningSectionService;
+
+    @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("璁惧鐘舵�侀暱鏈熸棤鍙樺寲鎶ヨ浠诲姟 RunningEquipmentStatusJob start!  鏃堕棿:" + DateUtils.getNow());
+        long startTime = System.currentTimeMillis();
+        try {
+            List<MdcEquipment> equipmentList = mdcEquipmentService.list(new LambdaQueryWrapper<>());
+            //List<MdcEquipment> equipmentList = mdcEquipmentService.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, "2140198"));
+            // 鑾峰彇鍒╃敤鐜囧垽瀹氬ぉ鏁�
+            List<DictModel> dictModelList1 = sysDictService.queryEnableDictItemsByCode(CommonConstant.DICT_EQUIPMENT_RATE_JUDGE);
+            Integer equipmentRateJudge = 5;
+            if (dictModelList1 != null && !dictModelList1.isEmpty()) {
+                equipmentRateJudge = Integer.valueOf(dictModelList1.get(0).getValue());
+            }
+            // 鑾峰彇鍒╃敤鐜囨甯稿��
+            List<DictModel> dictModelList2 = sysDictService.queryEnableDictItemsByCode(CommonConstant.DICT_EQUIPMENT_SPEED_JUDGE);
+            Integer equipmentRateNormal = 20;
+            if (dictModelList2 != null && !dictModelList2.isEmpty()) {
+                equipmentRateNormal = Integer.valueOf(dictModelList2.get(0).getValue());
+            }
+            // 鑾峰彇璁惧鐘舵�佸ぉ鏁�
+            List<DictModel> dictModelList3 = sysDictService.queryEnableDictItemsByCode(CommonConstant.DICT_EQUIPMENT_RATE_NORMAL);
+            Integer equipmentStatusJudge = 5;
+            if (dictModelList3 != null && !dictModelList3.isEmpty()) {
+                equipmentStatusJudge = Integer.valueOf(dictModelList3.get(0).getValue());
+            }
+            for (MdcEquipment mdcEquipment : equipmentList) {
+                // 鍒ゆ柇鍒╃敤鐜�
+                String date = DateUtils.format(DateUtils.toDate(LocalDate.now().plusDays(-equipmentRateJudge).toString(), DateUtils.STR_DATE), DateUtils.STRDATE);
+                List<BigDecimal> efficiencyRateList = mdcEfficiencyReportService.getEfficiencyRate(mdcEquipment.getEquipmentId(), date);
+                if (efficiencyRateList != null && !efficiencyRateList.isEmpty()) {
+                    boolean flag = true;
+                    for (BigDecimal processLong : efficiencyRateList) {
+                        BigDecimal efficiencyRate = processLong.divide(new BigDecimal("86400"), 4, RoundingMode.HALF_UP);
+                        if (efficiencyRate.compareTo(new BigDecimal(equipmentRateNormal)) > -1) {
+                            flag = false;
+                        }
+                    }
+                    if (flag) {
+                        // 涓婃姤
+                        MessageDTO messageDTO = new MessageDTO();
+                        messageDTO.setCategory("棰勮娑堟伅");
+                        messageDTO.setFromUser("admin");
+                        messageDTO.setToUser("admin");
+                        messageDTO.setContent("璁惧缂栧彿涓� [" + mdcEquipment.getEquipmentId() + "] 鐨勮澶囧埄鐢ㄧ巼浣庝簬姝e父鍊兼姤璀︼紒");
+                        sysBaseApi.sendSysAnnouncement(messageDTO);
+                    }
+                }
+                // 鍒ゆ柇璁惧鐘舵��
+                Date date1 = DateUtils.toDate(LocalDate.now().plusDays(-equipmentStatusJudge).toString(), DateUtils.STR_DATE);
+                List<Integer> sectionList = mdcEquipmentRunningSectionService.getDataList(mdcEquipment.getEquipmentId(), date1);
+                if (sectionList != null && !sectionList.isEmpty() && sectionList.size() > 1) {
+                    boolean flag = true;
+                    Integer integer = sectionList.get(0);
+                    for (Integer integer1 : sectionList) {
+                        if (!integer.equals(integer1)) {
+                            flag = false;
+                        }
+                    }
+                    if (flag) {
+                        // 涓婃姤
+                        MessageDTO messageDTO = new MessageDTO();
+                        messageDTO.setCategory("棰勮娑堟伅");
+                        messageDTO.setFromUser("admin");
+                        messageDTO.setToUser("admin");
+                        messageDTO.setContent("璁惧缂栧彿涓� [" + mdcEquipment.getEquipmentId() + "] 鐨勮澶囩姸鎬侀暱鏈熸棤鍙樺寲鎶ヨ锛�");
+                        sysBaseApi.sendSysAnnouncement(messageDTO);
+                    }
+                }
+            }
+            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