|
@@ -0,0 +1,237 @@
|
|
|
+package org.jeecg.modules.interlockjob;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
+import org.jeecg.modules.base.entity.InterlockBase;
|
|
|
+import org.jeecg.modules.base.service.IInterlockBaseService;
|
|
|
+import org.jeecg.modules.interlockCountDay.entity.InterlockCountDay;
|
|
|
+import org.jeecg.modules.interlockCountDay.service.IInterlockCountDayService;
|
|
|
+import org.jeecg.modules.interlockCountMonth.entity.InterlockCountMonth;
|
|
|
+import org.jeecg.modules.interlockCountMonth.service.IInterlockCountMonthService;
|
|
|
+import org.jeecg.modules.util.CountType;
|
|
|
+import org.quartz.Job;
|
|
|
+import org.quartz.JobExecutionContext;
|
|
|
+import org.quartz.JobExecutionException;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+
|
|
|
+import javax.management.Query;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+
|
|
|
+ * @author dzc
|
|
|
+ * @date 2024/6/28 15:32
|
|
|
+ * @package org.jeecg.modules.interlockjob
|
|
|
+ * @project interlock_server
|
|
|
+ * @des 联锁 健康等级 仪表状态 投用率 月统计的定时任务
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public class MonthStatisticsJob implements Job {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IInterlockCountDayService countDayService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IInterlockCountMonthService monthService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IInterlockBaseService baseService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
|
|
|
+ LocalDate yesterDate = LocalDate.now().minusMonths(1);
|
|
|
+ String lastmonth = yesterDate.format(formatter);
|
|
|
+
|
|
|
+ String year = lastmonth.split("-")[0];
|
|
|
+
|
|
|
+
|
|
|
+ List<InterlockCountDay> loopHealthLevelList = countDayService.getCountByYearmonth(CountType.LOOPHEALTHLEVEL,lastmonth);
|
|
|
+
|
|
|
+ HashMap<String, List<InterlockCountDay>> loopHealthLevelMap = new HashMap<>();
|
|
|
+
|
|
|
+ ArrayList<InterlockCountMonth> loopHealthLevelResultList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (InterlockCountDay item:loopHealthLevelList) {
|
|
|
+ if (loopHealthLevelMap.containsKey(item.getInterlockSystemId())){
|
|
|
+ loopHealthLevelMap.get(item.getInterlockSystemId()).add(item);
|
|
|
+ }else {
|
|
|
+ ArrayList<InterlockCountDay> countList = new ArrayList<>();
|
|
|
+ countList.add(item);
|
|
|
+ loopHealthLevelMap.put(item.getInterlockSystemId(),countList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String key : loopHealthLevelMap.keySet()) {
|
|
|
+ List<InterlockCountDay> sonList = loopHealthLevelMap.get(key);
|
|
|
+ int countAnum = 0;
|
|
|
+ int countBnum = 0;
|
|
|
+ int countCnum = 0;
|
|
|
+ int countDnum = 0;
|
|
|
+ for (InterlockCountDay item : sonList) {
|
|
|
+ int num = Integer.parseInt(item.getCountNum());
|
|
|
+ switch (item.getCountName()){
|
|
|
+ case "A" :
|
|
|
+ countAnum += num;
|
|
|
+ break;
|
|
|
+ case "B" :
|
|
|
+ countBnum += num;
|
|
|
+ break;
|
|
|
+ case "C" :
|
|
|
+ countCnum += num;
|
|
|
+ break;
|
|
|
+ case "D" :
|
|
|
+ countDnum += num;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String[] arr1 = {"A", "B", "C", "D"};
|
|
|
+ int[] arr2 = {countAnum,countBnum,countCnum,countDnum};
|
|
|
+
|
|
|
+ for (int i = 0; i < arr1.length; i++){
|
|
|
+ InterlockCountMonth interlockCountMonth = new InterlockCountMonth();
|
|
|
+ interlockCountMonth.setDeviceId(sonList.get(0).getDeviceId());
|
|
|
+ interlockCountMonth.setInterlockSystemId(sonList.get(0).getInterlockSystemId());
|
|
|
+ interlockCountMonth.setInterlockName(sonList.get(0).getInterlockName());
|
|
|
+ interlockCountMonth.setCountName(arr1[i]);
|
|
|
+ interlockCountMonth.setCountNum(String.valueOf(arr2[i]));
|
|
|
+ interlockCountMonth.setCountType(CountType.LOOPHEALTHLEVEL);
|
|
|
+ interlockCountMonth.setTime(lastmonth);
|
|
|
+ interlockCountMonth.setYear(year);
|
|
|
+ loopHealthLevelResultList.add(interlockCountMonth);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<InterlockCountDay> interlockStatusList = countDayService.getCountByYearmonth(CountType.INTERLOCKSTATUS,lastmonth);
|
|
|
+
|
|
|
+ HashMap<String, List<InterlockCountDay>> interlockStatusMap = new HashMap<>();
|
|
|
+
|
|
|
+ ArrayList<InterlockCountMonth> interlockStatusResultList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (InterlockCountDay item:interlockStatusList) {
|
|
|
+ if (interlockStatusMap.containsKey(item.getInterlockSystemId())){
|
|
|
+ interlockStatusMap.get(item.getInterlockSystemId()).add(item);
|
|
|
+ }else {
|
|
|
+ ArrayList<InterlockCountDay> countList = new ArrayList<>();
|
|
|
+ countList.add(item);
|
|
|
+ interlockStatusMap.put(item.getInterlockSystemId(),countList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String key : interlockStatusMap.keySet()) {
|
|
|
+ InterlockBase base = baseService.getById(key);
|
|
|
+ String ty = base.getInterlockStatusTyName();
|
|
|
+ String wty = base.getInterlockStatusWtyName();
|
|
|
+ List<InterlockCountDay> sonList = interlockStatusMap.get(key);
|
|
|
+ int countTyNum = 0;
|
|
|
+ int countWtyNum = 0;
|
|
|
+ for (InterlockCountDay item : sonList) {
|
|
|
+ if (ty.equals(item.getCountName())){
|
|
|
+ countTyNum += Integer.parseInt(item.getCountNum());
|
|
|
+ }
|
|
|
+ if (wty.equals(item.getCountName())){
|
|
|
+ countWtyNum += Integer.parseInt(item.getCountNum());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ InterlockCountMonth interlockCountMonthTy = new InterlockCountMonth();
|
|
|
+
|
|
|
+ interlockCountMonthTy.setDeviceId(sonList.get(0).getDeviceId());
|
|
|
+ interlockCountMonthTy.setInterlockSystemId(sonList.get(0).getInterlockSystemId());
|
|
|
+ interlockCountMonthTy.setInterlockName(sonList.get(0).getInterlockName());
|
|
|
+ interlockCountMonthTy.setCountName(ty);
|
|
|
+ interlockCountMonthTy.setCountNum(String.valueOf(countTyNum));
|
|
|
+ interlockCountMonthTy.setCountType(CountType.INTERLOCKSTATUS);
|
|
|
+ interlockCountMonthTy.setTime(lastmonth);
|
|
|
+ interlockCountMonthTy.setYear(year);
|
|
|
+
|
|
|
+ InterlockCountMonth interlockCountMonthWty = new InterlockCountMonth();
|
|
|
+
|
|
|
+ interlockCountMonthWty.setDeviceId(sonList.get(0).getDeviceId());
|
|
|
+ interlockCountMonthWty.setInterlockSystemId(sonList.get(0).getInterlockSystemId());
|
|
|
+ interlockCountMonthWty.setInterlockName(sonList.get(0).getInterlockName());
|
|
|
+ interlockCountMonthWty.setCountName(wty);
|
|
|
+ interlockCountMonthWty.setCountNum(String.valueOf(countWtyNum));
|
|
|
+ interlockCountMonthWty.setCountType(CountType.INTERLOCKSTATUS);
|
|
|
+ interlockCountMonthWty.setTime(lastmonth);
|
|
|
+ interlockCountMonthWty.setYear(year);
|
|
|
+
|
|
|
+ interlockStatusResultList.add(interlockCountMonthTy);
|
|
|
+ interlockStatusResultList.add(interlockCountMonthWty);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ArrayList<InterlockCountMonth> tylResultList = new ArrayList<>();
|
|
|
+
|
|
|
+ HashMap<String, List<InterlockCountMonth>> tylMap = new HashMap<>();
|
|
|
+ for (InterlockCountMonth item:interlockStatusResultList) {
|
|
|
+ if (tylMap.containsKey(item.getInterlockSystemId())){
|
|
|
+ tylMap.get(item.getInterlockSystemId()).add(item);
|
|
|
+ }else {
|
|
|
+ ArrayList<InterlockCountMonth> countList = new ArrayList<>();
|
|
|
+ countList.add(item);
|
|
|
+ tylMap.put(item.getInterlockSystemId(),countList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String key : tylMap.keySet()) {
|
|
|
+ InterlockBase base = baseService.getById(key);
|
|
|
+ String tyName = base.getInterlockStatusTyName();
|
|
|
+ String wtyName = base.getInterlockStatusWtyName();
|
|
|
+ List<InterlockCountMonth> sonList = tylMap.get(key);
|
|
|
+ BigDecimal yty = BigDecimal.valueOf(0);
|
|
|
+ BigDecimal wty = BigDecimal.valueOf(0);
|
|
|
+ BigDecimal tyl = BigDecimal.valueOf(0);
|
|
|
+ for (InterlockCountMonth item : sonList) {
|
|
|
+ if (tyName.equals(item.getCountName())){
|
|
|
+ yty = new BigDecimal(item.getCountNum());
|
|
|
+ }
|
|
|
+ if (wtyName.equals(item.getCountName())){
|
|
|
+ wty = new BigDecimal(item.getCountNum());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BigDecimal total = yty.add(wty);
|
|
|
+ if ((total.compareTo(BigDecimal.valueOf(0)) != 0)){
|
|
|
+ tyl = yty.divide(total,2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
|
|
|
+ }
|
|
|
+
|
|
|
+ InterlockCountMonth interlockCountMonthTyl = new InterlockCountMonth();
|
|
|
+
|
|
|
+ interlockCountMonthTyl.setDeviceId(sonList.get(0).getDeviceId());
|
|
|
+ interlockCountMonthTyl.setInterlockSystemId(key);
|
|
|
+ interlockCountMonthTyl.setInterlockName(sonList.get(0).getInterlockName());
|
|
|
+ interlockCountMonthTyl.setCountName("投用率");
|
|
|
+ interlockCountMonthTyl.setCountNum(String.valueOf(tyl));
|
|
|
+ interlockCountMonthTyl.setCountType(CountType.UTILIZATIONRATE);
|
|
|
+ interlockCountMonthTyl.setTime(lastmonth);
|
|
|
+ interlockCountMonthTyl.setYear(year);
|
|
|
+
|
|
|
+ tylResultList.add(interlockCountMonthTyl);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<InterlockCountMonth> list = Stream.concat(Stream.concat(loopHealthLevelResultList.stream(), interlockStatusResultList.stream()),tylResultList.stream())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ QueryWrapper<InterlockCountMonth> queryWapper = new QueryWrapper<>();
|
|
|
+ queryWapper.eq("time",lastmonth);
|
|
|
+ boolean b = monthService.remove(queryWapper);
|
|
|
+
|
|
|
+ monthService.saveBatch(list);
|
|
|
+ log.info("月统计任务执行成功!");
|
|
|
+ }
|
|
|
+}
|