|
@@ -0,0 +1,89 @@
|
|
|
+package com.xlht.xlhtproject.controller;
|
|
|
+
|
|
|
+import com.xlht.xlhtproject.domain.TTbDu;
|
|
|
+import com.xlht.xlhtproject.domain.TXinyiMedicineParam;
|
|
|
+import com.xlht.xlhtproject.mapper.TShuju1Mapper;
|
|
|
+import com.xlht.xlhtproject.mapper.TTbDuMapper;
|
|
|
+import com.xlht.xlhtproject.mapper.TXinyiMedicineParamMapper;
|
|
|
+import com.xlht.xlhtproject.utils.CalculateUtils;
|
|
|
+import com.xlht.xlhtproject.utils.DateUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.net.telnet.TelnetClient;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+import static com.xlht.xlhtproject.enums.MyConstants.LONG_1;
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class ScheduledTasks {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TXinyiMedicineParamMapper tXinyiMedicineParamMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TShuju1Mapper shuju1Mapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CalculateUtils calculateUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TTbDuMapper tTbDuMapper;
|
|
|
+
|
|
|
+ /*@Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES) // 五分钟行一次
|
|
|
+ public void reportCurrentTime() {
|
|
|
+ System.out.println("现在时间: " + System.currentTimeMillis() / 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 使用cron表达式
|
|
|
+ @Scheduled(cron = "0 0/5 15,18 * * ?") // 每天的15点和18点,每隔5分钟执行一次
|
|
|
+ public void fixedRateWithInitialDelay() {
|
|
|
+ System.out.println("通过cron表达式执行的定时任务: " + System.currentTimeMillis() / 1000);
|
|
|
+ }*/
|
|
|
+
|
|
|
+
|
|
|
+ @Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES) // 五分钟行一次 修改数据库的值,跃渊获取然后自动投药
|
|
|
+ public void addMedicine() {
|
|
|
+ log.info("进入了定时投药的逻辑处理--开始");
|
|
|
+ //计算一池和二池的值
|
|
|
+ TXinyiMedicineParam latestRecord = this.tXinyiMedicineParamMapper.getLatestRecord();
|
|
|
+ if(Objects.isNull(latestRecord)){
|
|
|
+ log.error("锡林浩特定时投药处理:没有配置投药信息,无法投药");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //投药(写入数据库)
|
|
|
+ //计算实时的碳源投加量 (2个池子需要分开存)
|
|
|
+ BigDecimal val1 = this.calculateUtils.calculateMedicineByLastRecord(latestRecord, 1);
|
|
|
+ if(!Objects.isNull(val1) && val1.compareTo(BigDecimal.ZERO) < 0){
|
|
|
+ log.info("一池计算得到的碳源投加量是负数,按0处理");
|
|
|
+ val1 = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ BigDecimal val2 = this.calculateUtils.calculateMedicineByLastRecord(latestRecord, 2);
|
|
|
+ if(!Objects.isNull(val2) && val2.compareTo(BigDecimal.ZERO) < 0){
|
|
|
+ log.info("二池计算得到的碳源投加量是负数,按0处理");
|
|
|
+ val2 = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ TTbDu tTbDu = this.tTbDuMapper.selectTTbDuByID(LONG_1);
|
|
|
+ if(Objects.isNull(tTbDu)){
|
|
|
+ log.error("未查询到要写入的数据,初始化数据错误×××××××");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String now = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getNowDate());
|
|
|
+ tTbDu.setC1TjLl(val1);
|
|
|
+ tTbDu.setC1TjLlTime(now);
|
|
|
+ tTbDu.setC2TjLl(val2);
|
|
|
+ tTbDu.setC2TjLlTime(now);
|
|
|
+ this.tTbDuMapper.updateTTbDu(tTbDu);
|
|
|
+ log.info("进入了定时投药的逻辑处理--结束");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|