瀏覽代碼

大经编机取数修改

wukai 4 周之前
父節點
當前提交
09c32403cc

+ 64 - 0
jjt-admin/src/test/java/com/jjt/task/DjbTest.java

@@ -0,0 +1,64 @@
+package com.jjt.task;
+
+import com.jjt.JjtApplication;
+import com.jjt.biz.domain.TwinDevice;
+import com.jjt.biz.service.IApiService;
+import com.jjt.biz.service.ITwinDeviceService;
+import com.jjt.calc.service.ITwinCalcDayService;
+import com.jjt.emp.service.ITwinEmpCalcService;
+import com.jjt.utils.AsyncService;
+import com.jjt.utils.IotService;
+import com.jjt.utils.Tools;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import javax.annotation.Resource;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+/**
+ * DataProcess$
+ *
+ * @author wukai
+ * @date 2024/5/7 11:49
+ */
+@SpringBootTest(classes = JjtApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class DjbTest {
+    @Resource
+    private IApiService apiService;
+
+    @Resource
+    private ITwinDeviceService deviceService;
+    @Resource
+    private AsyncService asyncService;
+    @Resource
+    private ITwinCalcDayService dayService;
+    @Resource
+    private ITwinEmpCalcService empCalcService;
+    @Resource
+    private IotService iotService;
+
+
+    @Test
+    public void test() throws ExecutionException, InterruptedException {
+        LocalDateTime ldt = Tools.currWholeTime();
+        //上一个小时
+        ldt = ldt.minusHours(1);
+        //开始时间需要向前取一秒
+        LocalDateTime start = ldt.minusSeconds(1);
+        LocalDateTime end = ldt.plusHours(1);
+        iotService.setToken();
+        TwinDevice twinDevice = deviceService.selectTwinDeviceByDeviceId(175L);
+        List<Future<Map<String, List<?>>>> futureList = new ArrayList<>();
+        Future<Map<String, List<?>>> future = asyncService.process(twinDevice, start, end);
+        futureList.add(future);
+        // 等待异步任务完成
+        future.get();
+    }
+
+}
+

+ 76 - 66
jjt-biz/src/main/java/com/jjt/biz/service/impl/ApiServiceImpl.java

@@ -121,7 +121,7 @@ public class ApiServiceImpl implements IApiService {
                 weekData.setAKwh(ws.getAValue());
                 weekData.setBKwh(ws.getBValue());
                 weekData.setKwh(ws.getTotalValue());
-            }else{
+            } else {
                 weekData.setAKwh(BigDecimal.ZERO);
                 weekData.setBKwh(BigDecimal.ZERO);
                 weekData.setKwh(BigDecimal.ZERO);
@@ -191,54 +191,26 @@ public class ApiServiceImpl implements IApiService {
                 }
                 float speed = (float) map.get("Capacity_data_1");
                 int stopStatus = (int) map.get("Capacity_data_48");
+                Object data4 = map.get("Capacity_data_4");
+                if (device.getDeviceCode().startsWith("D_")) {
+                    speed = (float) map.get("Capacity_data_117");
+                    stopStatus = (int) map.get("Capacity_data_118");
+                    data4 = map.get("Capacity_data_110");
+                }
                 sdVO.setStop(stopStatus);
                 sdVO.setSpeed(speed);
                 stopList.add(sdVO);
-                //处理配方明细数据
-                FormulaDetail detail = new FormulaDetail(map);
-                formulaDetail.add(detail);
-
-                TwinFormulaInfo formulaInfo = new TwinFormulaInfo(map);
-                formulaInfos.add(formulaInfo);
-                //处理送经量数据
-                WarpRunIn warpRunIn = new WarpRunIn(map);
-                warpList.add(warpRunIn);
-                //处理平方米克重明细数据
-                GramMassDetail gramMassDetail = new GramMassDetail(map);
-                gramMassDetails.add(gramMassDetail);
 
-                int data4 = (int) map.get("Capacity_data_4");
-                if (data4 == 0) {
+                if (data4 instanceof Integer && (Integer) data4 == 0 || data4 instanceof Float && (Float) data4 == 0f) {
                     //Capacity_data_4,如果设定落布米数为0,则证明当前数据无效
                     //不能跟上面判断合并,不然报空指针
                     continue;
                 }
-                for (int i = 0; i < Tools.ALLOW_ALARM.length; i++) {
-                    //允许的告警编号
-                    boolean flag = (boolean) map.get("Alarm_unit_" + Tools.ALLOW_ALARM[i]);
-                    if (flag) {
-                        IndexAlarm indexAlarm = new IndexAlarm();
-                        indexAlarm.setCode(device.getDeviceCode());
-                        indexAlarm.setName(device.getDeviceName());
-                        indexAlarm.setType(i);
-                        alarmList.add(indexAlarm);
-                    }
-                }
-
-                int alarm27 = (int) map.get("Alarm_unit_27");
-                IndexAlarm indexAlarm;
-                if (alarm27 != 0) {
-                    indexAlarm = new IndexAlarm();
-                    indexAlarm.setCode(device.getDeviceCode());
-                    indexAlarm.setName(device.getDeviceName());
-                    indexAlarm.setType(27);
-                    alarmList.add(indexAlarm);
-                }
-
 
-                indexAlarm = new IndexAlarm();
-                indexAlarm.setCode(device.getDeviceCode());
-                indexAlarm.setName(device.getDeviceName());
+                //停机统计--start
+                IndexAlarm stopCalc = new IndexAlarm();
+                stopCalc.setCode(device.getDeviceCode());
+                stopCalc.setName(device.getDeviceName());
                 int alarmType = 0;
                 if (speed > 0f || stopStatus == 0) {
                     onlineNum++;
@@ -268,39 +240,77 @@ public class ApiServiceImpl implements IApiService {
                 }
 
                 if (alarmType != 0) {
-                    indexAlarm.setType(alarmType);
-                    alarmList.add(indexAlarm);
+                    stopCalc.setType(alarmType);
+                    alarmList.add(stopCalc);
                 }
+                //停机统计--end
+
+                IndexPan pan = new IndexPan();
+                pan.setCode(device.getDeviceCode());
+                pan.setName(device.getDeviceName());
+                if (device.getDeviceCode().startsWith("C_")) {
+                    //处理配方明细数据
+                    FormulaDetail detail = new FormulaDetail(map);
+                    formulaDetail.add(detail);
+
+                    TwinFormulaInfo formulaInfo = new TwinFormulaInfo(map);
+                    formulaInfos.add(formulaInfo);
+                    //处理送经量数据
+                    WarpRunIn warpRunIn = new WarpRunIn(map);
+                    warpList.add(warpRunIn);
+                    //处理平方米克重明细数据
+                    GramMassDetail gramMassDetail = new GramMassDetail(map);
+                    gramMassDetails.add(gramMassDetail);
 
-                int[] curr = new int[5];
-                int[] max = new int[5];
-                float[] panPercent = new float[5];
-                boolean panFlag = false;
-                for (int i = 0; i < curr.length; i++) {
-                    int pos = 15 + i;
-                    curr[i] = (int) map.get("Capacity_data_" + pos);
-                    if (curr[i] < 200) {
-                        //盘头小于200圈
-                        panFlag = true;
+
+                    for (int i = 0; i < Tools.ALLOW_ALARM.length; i++) {
+                        //允许的告警编号
+                        boolean flag = (boolean) map.get("Alarm_unit_" + Tools.ALLOW_ALARM[i]);
+                        if (flag) {
+                            IndexAlarm indexAlarm = new IndexAlarm();
+                            indexAlarm.setCode(device.getDeviceCode());
+                            indexAlarm.setName(device.getDeviceName());
+                            indexAlarm.setType(i);
+                            alarmList.add(indexAlarm);
+                        }
                     }
-                    String key = device.getDeviceId() + "_" + (i + 1);
-                    max[i] = 15000;
-                    if (panMap.get(key) != null) {
-                        max[i] = Math.toIntExact(panMap.get(key));
+
+                    int alarm27 = (int) map.get("Alarm_unit_27");
+                    if (alarm27 != 0) {
+                        IndexAlarm indexAlarm = new IndexAlarm();
+                        indexAlarm.setCode(device.getDeviceCode());
+                        indexAlarm.setName(device.getDeviceName());
+                        indexAlarm.setType(27);
+                        alarmList.add(indexAlarm);
                     }
 
-                    panPercent[i] = BigDecimal.valueOf(curr[i] * 100L).divide(BigDecimal.valueOf(max[i]), 2, RoundingMode.HALF_UP).floatValue();
-                    if (panPercent[i] > 100) {
-                        panPercent[i] = 100;
+                    int[] curr = new int[5];
+                    int[] max = new int[5];
+                    float[] panPercent = new float[5];
+                    boolean panFlag = false;
+                    for (int i = 0; i < curr.length; i++) {
+                        int pos = 15 + i;
+                        curr[i] = (int) map.get("Capacity_data_" + pos);
+                        if (curr[i] < 200) {
+                            //盘头小于200圈
+                            panFlag = true;
+                        }
+                        String key = device.getDeviceId() + "_" + (i + 1);
+                        max[i] = 15000;
+                        if (panMap.get(key) != null) {
+                            max[i] = Math.toIntExact(panMap.get(key));
+                        }
+
+                        panPercent[i] = BigDecimal.valueOf(curr[i] * 100L).divide(BigDecimal.valueOf(max[i]), 2, RoundingMode.HALF_UP).floatValue();
+                        if (panPercent[i] > 100) {
+                            panPercent[i] = 100;
+                        }
                     }
+                    if (panFlag) {
+                        stopPan++;
+                    }
+                    pan.setPanPercent(panPercent);
                 }
-                if (panFlag) {
-                    stopPan++;
-                }
-                IndexPan pan = new IndexPan();
-                pan.setCode(device.getDeviceCode());
-                pan.setName(device.getDeviceName());
-                pan.setPanPercent(panPercent);
                 panList.add(pan);
             }
         } catch (InterruptedException | ExecutionException e) {

+ 1 - 10
jjt-biz/src/main/java/com/jjt/calc/service/impl/TwinCalcHourServiceImpl.java

@@ -188,7 +188,7 @@ public class TwinCalcHourServiceImpl implements ITwinCalcHourService {
         //查询所有在线的设备
         search.setOnline("1");
         //TODO 临时设置单个设备,上线需取消
-//        search.setDeviceId(75L);
+//        search.setDeviceId(175L);
         List<TwinDevice> list = deviceService.selectTwinDeviceList(search);
         List<TwinDevice> errList = exec(list, start, end);
         //重试2次
@@ -225,7 +225,6 @@ public class TwinCalcHourServiceImpl implements ITwinCalcHourService {
         List<TwinCalcHour> calcList = new ArrayList<>();
         List<TwinRecordStop> stopList = new ArrayList<>();
         List<TwinRecordAlarms> alarmList = new ArrayList<>();
-        List<TwinPanHeadInfo> panList = new ArrayList<>();
         List<TwinCalcHourSpec> specList = new ArrayList<>();
         try {
             for (Future<Map<String, List<?>>> future : futureList) {
@@ -238,8 +237,6 @@ public class TwinCalcHourServiceImpl implements ITwinCalcHourService {
                     stopList.addAll(stops);
                     List<TwinRecordAlarms> alarms = (List<TwinRecordAlarms>) map.get("alarmRecord");
                     alarmList.addAll(alarms);
-                    List<TwinPanHeadInfo> pans = (List<TwinPanHeadInfo>) map.get("panHead");
-                    panList.addAll(pans);
                     List<TwinCalcHourSpec> specs = (List<TwinCalcHourSpec>) map.get("specList");
                     specList.addAll(specs);
                 } catch (TimeoutException e) {
@@ -257,12 +254,6 @@ public class TwinCalcHourServiceImpl implements ITwinCalcHourService {
                 sqlSession.commit();
             }
 
-            if (panList.size() > 0) {
-                TwinPanHeadInfoMapper mapper = sqlSession.getMapper(TwinPanHeadInfoMapper.class);
-                panList.forEach(mapper::insertTwinPanHeadInfo);
-                sqlSession.commit();
-            }
-
             if (stopList.size() > 0) {
                 TwinRecordStopMapper mapper = sqlSession.getMapper(TwinRecordStopMapper.class);
                 stopList.forEach(mapper::insertTwinRecordStop);

+ 144 - 135
jjt-biz/src/main/java/com/jjt/utils/AsyncService.java

@@ -3,7 +3,10 @@ package com.jjt.utils;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import com.jjt.biz.domain.TwinDevice;
-import com.jjt.calc.domain.*;
+import com.jjt.calc.domain.TwinCalcHour;
+import com.jjt.calc.domain.TwinCalcHourSpec;
+import com.jjt.calc.domain.TwinRecordAlarms;
+import com.jjt.calc.domain.TwinRecordStop;
 import com.jjt.common.utils.DateUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.scheduling.annotation.Async;
@@ -14,7 +17,6 @@ import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.LocalDateTime;
-import java.time.ZoneOffset;
 import java.util.*;
 import java.util.concurrent.Future;
 import java.util.stream.Collectors;
@@ -31,25 +33,34 @@ public class AsyncService {
     @Resource
     private IotService iotService;
     /**
-     * 字段列表,方便看下标
+     * 小经编字段列表,方便看下标
      */
-    private final String[] fields = {"Capacity_data_2", "Capacity_data_37", "Capacity_data_38", "Capacity_data_39", "Capacity_data_42",
-            "Capacity_data_43", "Capacity_data_44", "Capacity_data_48", "Formula_data_3", "Formula_data_13",
-            "Capacity_data_36", "Capacity_data_41", "Alarm_unit_1", "Alarm_unit_2", "Alarm_unit_3",
+    private final String[] xFields = {
+            "Capacity_data_1", "Capacity_data_2", "Capacity_data_15", "Capacity_data_16", "Capacity_data_17",
+            "Capacity_data_18", "Capacity_data_19", "Capacity_data_48",
+            "Formula_data_3", "Formula_data_15", "Formula_data_24", "Alarm_unit_1",
+            "Alarm_unit_10", "Alarm_unit_11", "Alarm_unit_12", "Alarm_unit_13", "Alarm_unit_14",
+            "Alarm_unit_15", "Alarm_unit_16", "Alarm_unit_17", "Alarm_unit_18", "Alarm_unit_19",
+            "Alarm_unit_2", "Alarm_unit_20", "Alarm_unit_21", "Alarm_unit_22", "Alarm_unit_23",
+            "Alarm_unit_24", "Alarm_unit_25", "Alarm_unit_26", "Alarm_unit_27", "Alarm_unit_3",
             "Alarm_unit_4", "Alarm_unit_5", "Alarm_unit_6", "Alarm_unit_7", "Alarm_unit_8",
-            "Alarm_unit_9", "Alarm_unit_10", "Alarm_unit_11", "Alarm_unit_12", "Alarm_unit_13",
-            "Alarm_unit_14", "Alarm_unit_15", "Alarm_unit_16", "Alarm_unit_17", "Alarm_unit_18",
-            "Alarm_unit_19", "Alarm_unit_20", "Alarm_unit_21", "Alarm_unit_22", "Alarm_unit_23",
-            "Alarm_unit_24", "Alarm_unit_25", "Alarm_unit_26", "Alarm_unit_27", "Capacity_data_33",
-            "Capacity_data_15", "Capacity_data_16", "Capacity_data_17", "Capacity_data_18", "Capacity_data_19",
-            "Capacity_data_34", "Formula_data_24", "Formula_data_15", "Capacity_data_1"
+            "Alarm_unit_9"
+    };
+
+    /**
+     * 大经编字段列表,方便看下标
+     */
+    private final String[] dFields = {
+            "Capacity_data_117 AS Capacity_data_1", "Capacity_data_177 AS Capacity_data_2", "Capacity_data_15", "Capacity_data_16", "Capacity_data_17",
+            "Capacity_data_18", "Capacity_data_19", "Capacity_data_118 AS Capacity_data_48",
+            "Formula_data_43 AS Formula_data_3", "Formula_data_55 AS Formula_data_15", "Capacity_data_112 AS Formula_data_24"
     };
 
 
     /**
      * 字段列表,方便查找位置
      */
-    private final List<String> fieldList = Arrays.stream(fields).collect(Collectors.toList());
+    private final List<String> fieldList = Arrays.stream(xFields).collect(Collectors.toList());
 
     @Async("threadPoolTaskExecutor")
     public Future<Map<String, Object>> currData(TwinDevice twinDevice) {
@@ -83,20 +94,15 @@ public class AsyncService {
     public Future<Map<String, List<?>>> process(TwinDevice twinDevice, LocalDateTime start, LocalDateTime end) {
         //开始时间都减了一秒的,这里要加回来,用于计算时段等数据
         LocalDateTime ldt = start.plusSeconds(1);
-        Date date = Date.from(ldt.toLocalDate().atStartOfDay(ZoneOffset.of("+8")).toInstant());
-        Long startTime = start.toInstant(ZoneOffset.of("+8")).toEpochMilli();
-        Long endTime = end.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+        Date date = DateUtils.toDate(ldt.toLocalDate());
         int period = ldt.getHour();
         Map<String, List<?>> result = new HashMap<>(16);
         List<TwinCalcHour> calcHours = new ArrayList<>();
-        String table = twinDevice.getDevicePath();
         TwinCalcHour hour = new TwinCalcHour();
         hour.setDeviceId(twinDevice.getDeviceId());
         hour.setDataDate(date);
         hour.setHour(period);
-
-        Map<String, Object> map = calc(table, startTime, endTime);
-
+        Map<String, Object> map = calc(twinDevice, start, end);
 
         //0.已织造米数  1.总能耗 2.总重量 3.开机时间 4.关机时间
         float[] total = (float[]) map.get("total");
@@ -107,9 +113,6 @@ public class AsyncService {
         hour.setCloseTime((long) total[4]);
         calcHours.add(hour);
 
-        List<TwinPanHeadInfo> panHeadInfo = (List<TwinPanHeadInfo>) map.get("panHead");
-        panHeadInfo.forEach(info -> info.setDeviceId(twinDevice.getDeviceId()));
-
         List<TwinCalcHourSpec> specs = (List<TwinCalcHourSpec>) map.get("specList");
         specs.forEach(spec -> {
             spec.setDeviceId(twinDevice.getDeviceId());
@@ -180,7 +183,6 @@ public class AsyncService {
         result.put("calc", calcHours);
         result.put("stopRecord", newStopRecord);
         result.put("alarmRecord", newAlarmRecord);
-        result.put("panHead", panHeadInfo);
         result.put("specList", specs);
         return new AsyncResult<>(result);
     }
@@ -188,25 +190,28 @@ public class AsyncService {
 
     /**
      * //    0        Capacity_data_2	已织造米数
-     * //    1        Capacity_data_37	A班组开机时间
-     * //    2        Capacity_data_38	A班组停机时间
-     * //    3        Capacity_data_39	A班当前产量
-     * //    4        Capacity_data_42	B班组开机时间
-     * //    5        Capacity_data_43	B班组停机时间
-     * //    6        Capacity_data_44	B班当前产量
      * //    7        Capacity_data_48	停机状态
      * //    8        Formula_data_3	米克重
      * //    9        Formula_data_13	卷曲幅宽
      */
-    public Map<String, Object> calc(String table, long startTime, long endTime) {
+    public Map<String, Object> calc(TwinDevice twinDevice, LocalDateTime start, LocalDateTime end) {
+        //为true表示小经编,false表示大经编
+        boolean flag = twinDevice.getDeviceCode().startsWith("C_");
+        String table = twinDevice.getDevicePath();
+        String[] fields = xFields;
+        if (!flag) {
+            fields = dFields;
+        }
         String sql = "select %s from %s where time>%s and time <=%s";
-        sql = String.format(sql, String.join(",", fields), table, startTime, endTime);
+        sql = String.format(sql, String.join(",", fields), table, DateUtils.parseIso(start), DateUtils.parseIso(end));
         long s = System.currentTimeMillis();
         JSONObject jsonObject = iotService.query(sql);
         long e = System.currentTimeMillis();
-        log.info("接口耗时:{}ms,table:{},time:{}", e - s, table, DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date(endTime)));
+        log.info("接口耗时:{}ms,table:{},time:{}", e - s, table, end);
         JSONObject data = jsonObject.getJSONObject("data");
         JSONArray values = data.getJSONArray("values");
+        values = mergedValues(values);
+
         JSONArray timestamps = data.getJSONArray("timestamps");
         //初始时间点数据
         //0-data2,1-data37,2-data38,3-data39,4-data42,5-data-43,6data-44
@@ -218,112 +223,138 @@ public class AsyncService {
         float[] last = new float[3];
         //统计数据,后面2个分别代表0.织造米长,1.电量 2.重量,3.开机时间,4.停机时间
         float[] total = new float[5];
-        //上一个时间点盘头数据
-        int[] lastPanHead = new int[5];
         //米克重
         int lastMkz = 0;
-        //卷曲幅宽
-        float lastFk = 0f;
         //毛高
         float lastHeight = 0f;
         //上次密度记录的米长
         float lastSpecLength = 0f;
-        //开始不为0的电能
-        //不为0的电能结束
-        float startKwh = 0f, endKwh = 0f;
         int last48 = 0;
         //告警时间记录
         List<TwinRecordAlarms> alarmRecord = new ArrayList<>();
         //停机记录
         List<TwinRecordStop> stopRecord = new ArrayList<>();
-        //盘头记录
-        List<TwinPanHeadInfo> panHeadInfo = new ArrayList<>();
 
         for (int i = 0; i < values.size(); i++) {
             JSONArray da = values.getJSONArray(i);
-            //0-data2,1-data37,2-data38,3-data39,4-data42,5-data-43,6data-44
-            //当前时间数据 米长,正向电能,牵拉密度
-            float[] curr = {da.getFloat(fieldList.indexOf("Capacity_data_2")), da.getFloat(fieldList.indexOf("Capacity_data_34")), da.getFloat(fieldList.indexOf("Formula_data_24"))};
-            int[] currPan = {da.getInt(fieldList.indexOf("Capacity_data_15")), da.getInt(fieldList.indexOf("Capacity_data_16")), da.getInt(fieldList.indexOf("Capacity_data_17")),
-                    da.getInt(fieldList.indexOf("Capacity_data_18")), da.getInt(fieldList.indexOf("Capacity_data_19"))};
-            int curr48 = da.getInt(7);
+            //当前时间数据 米长,正向电能,牵拉密度 2025-06-19 取消电量计算没必要了
+            float[] curr = {da.getFloat(fieldList.indexOf("Capacity_data_2")), 0f, da.getFloat(fieldList.indexOf("Formula_data_24"))};
+            int curr48 = da.getInt(fieldList.indexOf("Capacity_data_48"));
 
             if (i == 0) {
                 //第一次数据是上次最后一条,只做记录用,不做处理
                 first = curr.clone();
                 last = curr.clone();
-                lastPanHead = currPan.clone();
-                lastMkz = da.getInt(8);
-                lastFk = da.getFloat(9);
+                lastMkz = da.getInt(fieldList.indexOf("Formula_data_3"));
                 lastHeight = da.getFloat(fieldList.indexOf("Formula_data_15"));
                 last48 = curr48;
-                startKwh = da.getFloat(fieldList.indexOf("Capacity_data_34"));
                 continue;
             }
 
-            //计算盘头
-            calcPan(currPan, lastPanHead, panHeadInfo, timestamps.getLong(i));
-            //计算规格米长
             if (last[2] != curr[2]) {
                 calcSpec(total[0], lastSpecLength, last[2], lastMkz, lastHeight, specList);
                 lastSpecLength = total[0];
             }
-            //处理电量跳点
-            float currKwh = da.getFloat(fieldList.indexOf("Capacity_data_34"));
-            if (startKwh == 0) {
-                startKwh = currKwh;
-            }
-
-            if (currKwh != 0f) {
-                endKwh = currKwh;
-            }
-
-//            for (int j = 0; j < first.length; j++) {
             //如果当前值为小于上一个,且上一个值不为0,则计算
             //因为会出现数据波动,停机再启动之后的第一个点不为0,为0.00几几几的
             //计算累加类的数据
             //这里只计算米长
             if (curr[0] < last[0] && last[0] != 0f) {
-                calcTotal(0, last, first, total, lastMkz, lastFk);
+//                calcTotal(0, last, first, total, lastMkz, lastFk);
+                calcTotal(0, last, first, total, lastMkz);
                 first[0] = curr[0];
             }
-//            }
-            calcAlarms(values, timestamps.getLong(i), alarmRecord, i);
+            if (flag) {
+                calcAlarms(values, timestamps.getLong(i), alarmRecord, i);
+            }
             calcStops(curr48, last48, timestamps.getLong(i), total, stopRecord, i);
 
             //复制数组,设置last值为当前值
             last = curr.clone();
-            lastPanHead = currPan.clone();
-            if (da.getInt(8) != 0) {
-                lastMkz = da.getInt(8);
+            if (da.getInt(fieldList.indexOf("Formula_data_3")) != 0) {
+                lastMkz = da.getInt(fieldList.indexOf("Formula_data_3"));
             }
-            lastFk = da.getFloat(9);
             lastHeight = da.getFloat(fieldList.indexOf("Formula_data_15"));
             last48 = curr48;
         }
-        //最后再补一次计算
-//        for (int j = 0; j < first.length; j++) {
-//            //这里米长和电量都要计算
-//            calcTotal(j, last, first, total, lastMkz, lastFk);
-//        }
         //还是只计算米长
-        calcTotal(0, last, first, total, lastMkz, lastFk);
-        calcSpec(total[0], lastSpecLength, last[2], lastMkz, lastHeight, specList);
-        //计算电量
-        total[1] = endKwh - startKwh;
+        calcTotal(0, last, first, total, lastMkz);
 
+        calcSpec(total[0], lastSpecLength, last[2], lastMkz, lastHeight, specList);
         total[3] = 3600 - total[4];
 
         Map<String, Object> result = new HashMap<>(16);
         result.put("total", total);
         result.put("stopRecord", stopRecord);
         result.put("alarmRecord", alarmRecord);
-        result.put("panHead", panHeadInfo);
         result.put("specList", specList);
         return result;
     }
 
     /**
+     * 处理数据 一会这儿有,一会那个有的情况
+     *
+     * @param values 原始数据
+     */
+    private JSONArray mergedValues(JSONArray values) {
+        /*
+         * 合并values数组中的数据,将缺失的数据补全
+         * 1. 遍历values数组,从第二条记录开始(第一条作为基准)
+         * 2. 将后续记录中非空的字段值补到第一条记录的对应位置
+         * 3. 当第一条记录所有字段都非空时停止处理
+         */
+        JSONArray mergedValues = new JSONArray();
+        JSONArray firstValues = values.getJSONArray(0);
+        for (int i = 1; i < values.size(); i++) {
+            JSONArray curr = values.getJSONArray(i);
+            // 遍历当前记录的每个字段
+            for (int j = 0; j < curr.size(); j++) {
+                // 如果当前字段有值且第一条记录的对应字段为空,则补充值
+                if (curr.get(j) != null && !curr.get(j).toString().isEmpty()
+                        && (firstValues.get(j) == null || firstValues.get(j).toString().isEmpty())) {
+                    firstValues.set(j, curr.get(j));
+                }
+            }
+
+            // 检查第一条记录是否所有字段都已补全
+            boolean isAll = true;
+            for (Object firstValue : firstValues) {
+                if (firstValue == null || firstValue.toString().isEmpty()) {
+                    isAll = false;
+                    break;
+                }
+            }
+
+            // 如果所有字段都已补全,则停止处理
+            if (isAll) {
+                break;
+            }
+        }
+
+
+        for (int i = 0; i < values.size(); i++) {
+            JSONArray curr = values.getJSONArray(i);
+            JSONArray merged = new JSONArray();
+            if (i > 0) {
+                // 取前一条记录作为基准
+                JSONArray prev = mergedValues.getJSONArray(i - 1);
+                for (int j = 0; j < curr.size(); j++) {
+                    if (curr.get(j) != null && !curr.get(j).toString().isEmpty()) {
+                        merged.add(curr.get(j));
+                    } else {
+                        merged.add(prev.get(j));
+                    }
+                }
+            } else {
+                // 第一条记录直接使用
+                merged = curr;
+            }
+            mergedValues.add(merged);
+        }
+        return mergedValues;
+    }
+
+    /**
      * 按规格计算米长
      *
      * @param len         当前米长
@@ -344,28 +375,6 @@ public class AsyncService {
         specList.add(spec);
     }
 
-    /**
-     * 计算盘头信息
-     * 数组 分别是GB1-GB5
-     *
-     * @param currPan     当前剩余圈数
-     * @param lastPanHead 上一条记录剩余圈数
-     * @param panHeadInfo info
-     * @param time        时间戳
-     */
-    private void calcPan(int[] currPan, int[] lastPanHead, List<TwinPanHeadInfo> panHeadInfo, Long time) {
-        //如果当前记录大于上一条记录,则证明是重新叫料了,需要记录下当前值
-        for (int i = 0; i < currPan.length; i++) {
-            if (currPan[i] > lastPanHead[i]) {
-                TwinPanHeadInfo info = new TwinPanHeadInfo();
-                info.setRecordTime(new Date(time));
-                info.setPhNum((long) (i + 1));
-                info.setPhMax((long) currPan[i]);
-                panHeadInfo.add(info);
-            }
-        }
-    }
-
 
     /**
      * 停机次数计算
@@ -446,15 +455,15 @@ public class AsyncService {
             }
             //需要单独计算alarm27
             //数据位置
-            int pos = j + 12;
-            int curr27 = curr.getInt(pos);
-            if (curr27 != 0) {
-                flags[j] = false;
-                recordAlarms = new TwinRecordAlarms();
-                recordAlarms.setAlarmType(j + 1);
-                recordAlarms.setStartTime(new Date(time));
-                alarmRecord.add(recordAlarms);
-            }
+//            int pos = j + 12;
+//            int curr27 = curr.getInt(pos);
+//            if (curr27 != 0) {
+//                flags[j] = false;
+//                recordAlarms = new TwinRecordAlarms();
+//                recordAlarms.setAlarmType(j + 1);
+//                recordAlarms.setStartTime(new Date(time));
+//                alarmRecord.add(recordAlarms);
+//            }
         }
         int j = 0;
         for (; j < index; j++) {
@@ -478,32 +487,32 @@ public class AsyncService {
                 }
             }
         }
-        if (flags[j]) {
-            //需要单独计算alarm27
-            //数据位置
-            int pos = j + 12;
-            int alarm27 = curr.getInt(pos);
-            //上面已经处理过i=0,所以这里i不可能等于0
-            int last27 = last.getInt(pos);
-            if (alarm27 != 0 && last27 == 0) {
-                recordAlarms = new TwinRecordAlarms();
-                recordAlarms.setAlarmType(j + 1);
-                recordAlarms.setStartTime(new Date(time));
-                alarmRecord.add(recordAlarms);
-            }
-            if (alarm27 == 0 && last27 != 0) {
-                recordAlarms = new TwinRecordAlarms();
-                recordAlarms.setAlarmType(j + 1);
-                recordAlarms.setEndTime(new Date(time));
-                alarmRecord.add(recordAlarms);
-            }
-        }
+//        if (flags[j]) {
+//            //需要单独计算alarm27
+//            //数据位置
+//            int pos = j + 12;
+//            int alarm27 = curr.getInt(pos);
+//            //上面已经处理过i=0,所以这里i不可能等于0
+//            int last27 = last.getInt(pos);
+//            if (alarm27 != 0 && last27 == 0) {
+//                recordAlarms = new TwinRecordAlarms();
+//                recordAlarms.setAlarmType(j + 1);
+//                recordAlarms.setStartTime(new Date(time));
+//                alarmRecord.add(recordAlarms);
+//            }
+//            if (alarm27 == 0 && last27 != 0) {
+//                recordAlarms = new TwinRecordAlarms();
+//                recordAlarms.setAlarmType(j + 1);
+//                recordAlarms.setEndTime(new Date(time));
+//                alarmRecord.add(recordAlarms);
+//            }
+//        }
     }
 
     /**
      * 重量计算 提取公共方法
      */
-    private void calcTotal(int j, float[] last, float[] first, float[] total, int lastMkz, float lastFk) {
+    private void calcTotal(int j, float[] last, float[] first, float[] total, int lastMkz) {
         float v = last[j] - first[j];
         total[j] += v;
         if (j == 0) {

+ 13 - 2
jjt-common/src/main/java/com/jjt/common/utils/DateUtils.java

@@ -24,6 +24,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
     public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
 
     public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
+    public static String YYYY_MM_DD_T_HH_MM_SS = "yyyy-MM-dd'T'HH:mm:ss";
 
     private static String[] parsePatterns = {
             "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
@@ -195,7 +196,17 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
      */
     public static String parseTimeToStr(LocalDateTime time) {
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateUtils.YYYY_MM_DD_HH_MM_SS);
-        String str = time.format(formatter);
-        return str;
+        return time.format(formatter);
+    }
+
+    /**
+     * LocalDateTime转字符串
+     *
+     * @param time 转换前的时间
+     * @return 字符串
+     */
+    public static String parseIso(LocalDateTime time) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateUtils.YYYY_MM_DD_T_HH_MM_SS);
+        return time.format(formatter);
     }
 }