소스 검색

调整定时任务获取时间

wukai 2 달 전
부모
커밋
81be7a095d

+ 24 - 1
jjt-biz/src/main/java/com/jjt/biz/service/impl/ApiServiceImpl.java

@@ -5,7 +5,6 @@ import com.jjt.biz.service.IApiService;
 import com.jjt.biz.service.ITwinDeviceService;
 import com.jjt.biz.vo.*;
 import com.jjt.calc.domain.TwinCalcDay;
-import com.jjt.calc.domain.TwinFormulaInfo;
 import com.jjt.calc.service.ITwinCalcDayService;
 import com.jjt.calc.service.ITwinFormulaInfoService;
 import com.jjt.calc.service.ITwinPanHeadInfoService;
@@ -340,5 +339,29 @@ public class ApiServiceImpl implements IApiService {
         redisCache.setCacheObject(CacheConstants.INDEX_GRAM_MASS, gramMasses);
         redisCache.setCacheObject(CacheConstants.INDEX_GRAM_MASS_DETAIL, gramMassDetails);
         redisCache.setCacheObject(CacheConstants.STOP_DETAIL, stopList);
+
+        calcLength();
+    }
+
+    /**
+     * 统计产量数据
+     */
+    private void calcLength() {
+        IndexData indexData = redisCache.getCacheObject(CacheConstants.INDEX_CALC);
+        IndexEfficiency efficiency = indexData.getEfficiency();
+        TwinCalcDay calcDay = twinCalcDayService.calcLength();
+        efficiency.setTotalLength(calcDay.getLength().floatValue());
+        efficiency.setALength(calcDay.getLengthA().floatValue());
+        efficiency.setBLength(calcDay.getLengthB().floatValue());
+        //界面上重新计算重量 2024-12-25 用总长度除以373
+        BigDecimal tw = calcDay.getLength().divide(BigDecimal.valueOf(373), 2, BigDecimal.ROUND_HALF_UP);
+        BigDecimal aw = calcDay.getLengthA().divide(BigDecimal.valueOf(373), 2, BigDecimal.ROUND_HALF_UP);
+        BigDecimal bw = calcDay.getLengthB().divide(BigDecimal.valueOf(373), 2, BigDecimal.ROUND_HALF_UP);
+        efficiency.setTotalWeight(tw.floatValue());
+        efficiency.setAWeight(aw.floatValue());
+        efficiency.setBWeight(bw.floatValue());
+        redisCache.setCacheObject(CacheConstants.INDEX_CALC, indexData);
     }
+
+
 }

+ 2 - 2
jjt-biz/src/main/java/com/jjt/biz/service/impl/ApiYrServiceImpl.java

@@ -103,8 +103,8 @@ public class ApiYrServiceImpl implements IApiYrService {
         AtomicInteger open = new AtomicInteger();
         //处理印花机运行数据
         List<TwinCalcHourYhj> calcList = redisCache.getCacheObject(CacheConstants.YHJ_TODAY);
-        Map<Integer, List<TwinCalcHourYhj>> calcListByDevice = calcList.stream()
-                .collect(Collectors.groupingBy(TwinCalcHourYhj::getDeviceId));
+//        Map<Integer, List<TwinCalcHourYhj>> calcListByDevice = calcList.stream()
+//                .collect(Collectors.groupingBy(TwinCalcHourYhj::getDeviceId));
 
         Map<Integer, Map<String, AbstractMap.SimpleEntry<Integer, BigDecimal>>> sumByDeviceAndTeam = calcList.stream()
                 .collect(Collectors.groupingBy(

+ 8 - 0
jjt-biz/src/main/java/com/jjt/calc/service/ITwinCalcDayService.java

@@ -82,6 +82,7 @@ public interface ITwinCalcDayService {
      * @return 结果
      */
     List<TwinCalcDay> selectTwinCalcDayListByMonth(String month);
+
     /**
      * 查询指定日期及之后的数据
      *
@@ -98,4 +99,11 @@ public interface ITwinCalcDayService {
      * @return 列表
      */
     List<TwinCalcDay> selectTwinCalcDayListByTime(Date sd, Date ed);
+
+    /**
+     * 计算上一个小时至现在的产量
+     *
+     * @return 结果
+     */
+    TwinCalcDay calcLength();
 }

+ 74 - 0
jjt-biz/src/main/java/com/jjt/calc/service/impl/TwinCalcDayServiceImpl.java

@@ -1,5 +1,7 @@
 package com.jjt.calc.service.impl;
 
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
 import com.jjt.biz.domain.TwinDevice;
 import com.jjt.biz.service.ITwinDeviceService;
 import com.jjt.calc.domain.TwinCalcAlarms;
@@ -13,6 +15,7 @@ import com.jjt.calc.service.ITwinCalcHourService;
 import com.jjt.calc.service.ITwinCalcStopService;
 import com.jjt.common.utils.DateUtils;
 import com.jjt.utils.AsyncService;
+import com.jjt.utils.IotService;
 import com.jjt.utils.Tools;
 import javafx.util.Pair;
 import org.apache.ibatis.session.ExecutorType;
@@ -56,6 +59,8 @@ public class TwinCalcDayServiceImpl implements ITwinCalcDayService {
     private AsyncService asyncService;
     @Resource
     private SqlSessionFactory factory;
+    @Resource
+    private IotService iotService;
 
     /**
      * 查询日统计数据
@@ -361,4 +366,73 @@ public class TwinCalcDayServiceImpl implements ITwinCalcDayService {
     public List<TwinCalcDay> selectTwinCalcDayListByTime(Date sd, Date ed) {
         return twinCalcDayMapper.selectTwinCalcDayListByTime(sd, ed);
     }
+
+    /**
+     * 计算上一个小时至现在的产量
+     *
+     * @return 结果
+     */
+    @Override
+    public TwinCalcDay calcLength() {
+        //计算统计时间
+        Pair<Date, Date> pair = Tools.calcToday();
+        Date sTime = pair.getKey();
+        Date eTime = pair.getValue();
+        List<TwinCalcHour> hourList = hourService.selectTwinCalcHourListByDate(sTime, eTime);
+
+        // 按照deviceId、density、mick、team,并统计每组的length总和
+        //按照deviceId分组统计
+        Map<Long, BigDecimal> resultMap = hourList.stream().collect(Collectors.groupingBy(TwinCalcHour::getDeviceId, Collectors.reducing(BigDecimal.ZERO, TwinCalcHour::getLength, BigDecimal::add)));
+        TwinCalcDay calcDay = new TwinCalcDay(sTime);
+        if (hourList.size() > 0) {
+            calcDay.calcHours(hourList);
+        }
+        List<TwinCalcHour> hours = new ArrayList<>();
+        TwinCalcHour lastHour = hourService.lastHour();
+        LocalDate localDate = DateUtils.toLocalDate(lastHour.getDataDate());
+        LocalDateTime start = LocalDateTime.of(localDate, LocalTime.MIN).plusHours(lastHour.getHour() + 1);
+
+        //为了避免多线程同时获取token导致重复执行,先执行一次获取token
+        TwinDevice search = new TwinDevice();
+        //查询所有在线的设备
+        search.setOnline("1");
+        List<TwinDevice> list = deviceService.selectTwinDeviceList(search);
+        List<String> fields = new ArrayList<>();
+        String fieldStr = "SUM(CASE WHEN DIFF(%s.Capacity_data_2)>0 THEN DIFF(%s.Capacity_data_2) ELSE 0 END) as %s";
+        list.forEach(device -> {
+            String code = device.getDevicePath().replace("root.tl.suxi.", "");
+            String field = String.format(fieldStr, code, code, "length_" + device.getDeviceId());
+            fields.add(field);
+        });
+        String sql = "select %s from root.tl.suxi where time>%s and time <=%s";
+        sql = String.format(sql, String.join(",", fields), DateUtils.parseIso(start), DateUtils.parseIso(LocalDateTime.now()));
+        iotService.query(sql);
+        JSONObject jsonObject = iotService.query(sql);
+        JSONObject data = jsonObject.getJSONObject("data");
+        JSONArray values = data.getJSONArray("values");
+        double totalV = 0d;
+        if (values.size() > 0) {
+            for (int j = 0; j < values.size(); j++) {
+                JSONArray da = values.getJSONArray(j);
+                for (int i = 0; i < da.size(); i++) {
+                    double v = da.getDouble(i);
+                    if (v > 0d) {
+                        totalV += v;
+                    }
+                }
+            }
+        }
+        BigDecimal length = calcDay.getLength().add(BigDecimal.valueOf(totalV));
+        calcDay.setLength(length);
+        if (start.getHour() >= 7 && start.getHour() < 19) {
+            //A班
+            BigDecimal lengthA = calcDay.getLengthA().add(BigDecimal.valueOf(totalV));
+            calcDay.setLengthA(lengthA);
+        } else {
+            //B班
+            BigDecimal lengthB = calcDay.getLengthB().add(BigDecimal.valueOf(totalV));
+            calcDay.setLengthB(lengthB);
+        }
+        return calcDay;
+    }
 }

+ 8 - 7
jjt-biz/src/main/java/com/jjt/task/IndexTask.java

@@ -31,13 +31,6 @@ public class IndexTask {
      */
     public void curr() {
         apiService.curr();
-    }
-
-    /**
-     * 统计当天数据
-     */
-
-    public void today() {
         try {
             yhjService.today();
         } catch (Exception e) {
@@ -53,6 +46,14 @@ public class IndexTask {
         } catch (Exception e) {
             e.printStackTrace();
         }
+    }
+
+    /**
+     * 统计当天数据
+     */
+
+    public void today() {
+
         apiService.today();
     }