Преглед на файлове

停机和告警记录修改

wukai преди 1 година
родител
ревизия
2e9d15d1bc

+ 41 - 137
ruoyi-admin/src/main/java/com/ruoyi/biz/domain/TwinCalcStop.java

@@ -1,13 +1,13 @@
 package com.ruoyi.biz.domain;
 
-import java.util.Date;
 import com.fasterxml.jackson.annotation.JsonFormat;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
 import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
-import com.ruoyi.common.core.domain.BaseEntity;
+import lombok.Data;
+
+import java.util.Date;
 
 /**
  * 停机数据统计对象 twin_calc_stop
@@ -16,183 +16,87 @@ import com.ruoyi.common.core.domain.BaseEntity;
  * @date 2024-06-28
  */
 @ApiModel(value = "ITwinCalcStop", description = "停机数据统计")
-public class TwinCalcStop extends BaseEntity
-{
+@Data
+public class TwinCalcStop extends BaseEntity {
     private static final long serialVersionUID = 1L;
 
-    /** ID */
+    /**
+     * ID
+     */
     private Long id;
 
-    /** 设备ID */
+    /**
+     * 设备ID
+     */
     @Excel(name = "设备ID")
     @ApiModelProperty("设备ID")
     private Long deviceId;
 
-    /** 日期 */
+    /**
+     * 日期
+     */
     @JsonFormat(pattern = "yyyy-MM-dd")
     @Excel(name = "日期", width = 30, dateFormat = "yyyy-MM-dd")
     @ApiModelProperty("日期")
     private Date dataDate;
 
-    /** 小时;0-23 */
+    /**
+     * 小时;0-23
+     */
     @Excel(name = "小时;0-23")
     @ApiModelProperty("小时;0-23")
-    private String hour;
+    private Integer hour;
 
-    /** 停机开始时间 */
+    /**
+     * 停机开始时间
+     */
     @JsonFormat(pattern = "yyyy-MM-dd")
     @Excel(name = "停机开始时间", width = 30, dateFormat = "yyyy-MM-dd")
     @ApiModelProperty("停机开始时间")
     private Date startTime;
 
-    /** 停机结束时间 */
+    /**
+     * 停机结束时间
+     */
     @JsonFormat(pattern = "yyyy-MM-dd")
     @Excel(name = "停机结束时间", width = 30, dateFormat = "yyyy-MM-dd")
     @ApiModelProperty("停机结束时间")
     private Date endTime;
 
-    /** 停机类型;1停经片停机,2-CCD停机(相机号+断纱/故障),3-人工停机,4-断电停机,5-设备故障停机,6-落布米数达到停机,7-盘头剩余圈数达到停机 */
+    /**
+     * 停机类型;1停经片停机,2-CCD停机(相机号+断纱/故障),3-人工停机,4-断电停机,5-设备故障停机,6-落布米数达到停机,7-盘头剩余圈数达到停机
+     */
     @Excel(name = "停机类型;1停经片停机,2-CCD停机(相机号+断纱/故障),3-人工停机,4-断电停机,5-设备故障停机,6-落布米数达到停机,7-盘头剩余圈数达到停机")
     @ApiModelProperty("停机类型;1停经片停机,2-CCD停机(相机号+断纱/故障),3-人工停机,4-断电停机,5-设备故障停机,6-落布米数达到停机,7-盘头剩余圈数达到停机")
-    private Long stopType;
+    private Integer stopType;
 
-    /** 创建人 */
+    /**
+     * 创建人
+     */
     @Excel(name = "创建人")
     @ApiModelProperty("创建人")
     private String createdBy;
 
-    /** 创建时间 */
+    /**
+     * 创建时间
+     */
     @JsonFormat(pattern = "yyyy-MM-dd")
     @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd")
     @ApiModelProperty("创建时间")
     private Date createdTime;
 
-    /** 更新人 */
+    /**
+     * 更新人
+     */
     @Excel(name = "更新人")
     @ApiModelProperty("更新人")
     private String updatedBy;
 
-    /** 更新时间 */
+    /**
+     * 更新时间
+     */
     @JsonFormat(pattern = "yyyy-MM-dd")
     @Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd")
     @ApiModelProperty("更新时间")
     private Date updatedTime;
-
-    public void setId(Long id)
-    {
-        this.id = id;
-    }
-
-    public Long getId()
-    {
-        return id;
-    }
-    public void setDeviceId(Long deviceId)
-    {
-        this.deviceId = deviceId;
-    }
-
-    public Long getDeviceId()
-    {
-        return deviceId;
-    }
-    public void setDataDate(Date dataDate)
-    {
-        this.dataDate = dataDate;
-    }
-
-    public Date getDataDate()
-    {
-        return dataDate;
-    }
-    public void setHour(String hour)
-    {
-        this.hour = hour;
-    }
-
-    public String getHour()
-    {
-        return hour;
-    }
-    public void setStartTime(Date startTime)
-    {
-        this.startTime = startTime;
-    }
-
-    public Date getStartTime()
-    {
-        return startTime;
-    }
-    public void setEndTime(Date endTime)
-    {
-        this.endTime = endTime;
-    }
-
-    public Date getEndTime()
-    {
-        return endTime;
-    }
-    public void setStopType(Long stopType)
-    {
-        this.stopType = stopType;
-    }
-
-    public Long getStopType()
-    {
-        return stopType;
-    }
-    public void setCreatedBy(String createdBy)
-    {
-        this.createdBy = createdBy;
-    }
-
-    public String getCreatedBy()
-    {
-        return createdBy;
-    }
-    public void setCreatedTime(Date createdTime)
-    {
-        this.createdTime = createdTime;
-    }
-
-    public Date getCreatedTime()
-    {
-        return createdTime;
-    }
-    public void setUpdatedBy(String updatedBy)
-    {
-        this.updatedBy = updatedBy;
-    }
-
-    public String getUpdatedBy()
-    {
-        return updatedBy;
-    }
-    public void setUpdatedTime(Date updatedTime)
-    {
-        this.updatedTime = updatedTime;
-    }
-
-    public Date getUpdatedTime()
-    {
-        return updatedTime;
-    }
-
-    @Override
-    public String toString() {
-        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("id", getId())
-            .append("deviceId", getDeviceId())
-            .append("dataDate", getDataDate())
-            .append("hour", getHour())
-            .append("startTime", getStartTime())
-            .append("endTime", getEndTime())
-            .append("stopType", getStopType())
-            .append("createdBy", getCreatedBy())
-            .append("createdTime", getCreatedTime())
-            .append("updatedBy", getUpdatedBy())
-            .append("updatedTime", getUpdatedTime())
-            .append("remark", getRemark())
-            .toString();
-    }
 }

+ 10 - 115
ruoyi-admin/src/main/java/com/ruoyi/biz/domain/TwinRecordAlarms.java

@@ -5,8 +5,7 @@ import com.ruoyi.common.annotation.Excel;
 import com.ruoyi.common.core.domain.BaseEntity;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
+import lombok.Data;
 
 import java.util.Date;
 
@@ -16,6 +15,7 @@ import java.util.Date;
  * @author ruoyi
  * @date 2024-06-28
  */
+@Data
 @ApiModel(value = "ITwinRecordAlarms", description = "告警数据记录")
 public class TwinRecordAlarms extends BaseEntity {
     private static final long serialVersionUID = 1L;
@@ -45,7 +45,7 @@ public class TwinRecordAlarms extends BaseEntity {
      */
     @Excel(name = "小时;0-23")
     @ApiModelProperty("小时;0-23")
-    private String hour;
+    private Integer hour;
 
     /**
      * 告警开始时间
@@ -68,9 +68,15 @@ public class TwinRecordAlarms extends BaseEntity {
      */
     @Excel(name = "告警类型;接口对应的编号")
     @ApiModelProperty("告警类型;接口对应的编号")
-    private Long alarmType;
+    private Integer alarmType;
 
     /**
+     * 统计状态
+     */
+    @Excel(name = "统计状态")
+    @ApiModelProperty("统计状态")
+    private String calcStatus;
+    /**
      * 创建人
      */
     @Excel(name = "创建人")
@@ -99,115 +105,4 @@ public class TwinRecordAlarms extends BaseEntity {
     @Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd")
     @ApiModelProperty("更新时间")
     private Date updatedTime;
-
-    public void setId(Long id) {
-        this.id = id;
-    }
-
-    public Long getId() {
-        return id;
-    }
-
-    public void setDeviceId(Long deviceId) {
-        this.deviceId = deviceId;
-    }
-
-    public Long getDeviceId() {
-        return deviceId;
-    }
-
-    public void setDataDate(Date dataDate) {
-        this.dataDate = dataDate;
-    }
-
-    public Date getDataDate() {
-        return dataDate;
-    }
-
-    public void setHour(String hour) {
-        this.hour = hour;
-    }
-
-    public String getHour() {
-        return hour;
-    }
-
-    public void setStartTime(Date startTime) {
-        this.startTime = startTime;
-    }
-
-    public Date getStartTime() {
-        return startTime;
-    }
-
-    public void setEndTime(Date endTime) {
-        this.endTime = endTime;
-    }
-
-    public Date getEndTime() {
-        return endTime;
-    }
-
-    public void setAlarmType(Long alarmType) {
-        this.alarmType = alarmType;
-    }
-
-    public Long getAlarmType() {
-        return alarmType;
-    }
-
-    public void setCreatedBy(String createdBy) {
-        this.createdBy = createdBy;
-    }
-
-    public String getCreatedBy() {
-        return createdBy;
-    }
-
-    public void setCreatedTime(Date createdTime) {
-        this.createdTime = createdTime;
-    }
-
-    public Date getCreatedTime() {
-        return createdTime;
-    }
-
-    public void setUpdatedBy(String updatedBy) {
-        this.updatedBy = updatedBy;
-    }
-
-    public String getUpdatedBy() {
-        return updatedBy;
-    }
-
-    public void setUpdatedTime(Date updatedTime) {
-        this.updatedTime = updatedTime;
-    }
-
-    public Date getUpdatedTime() {
-        return updatedTime;
-    }
-
-    @Override
-    public String toString() {
-        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
-                .append("id", getId())
-                .append("deviceId", getDeviceId())
-                .append("dataDate", getDataDate())
-                .append("hour", getHour())
-                .append("startTime", getStartTime())
-                .append("endTime", getEndTime())
-                .append("alarmType", getAlarmType())
-                .append("createdBy", getCreatedBy())
-                .append("createdTime", getCreatedTime())
-                .append("updatedBy", getUpdatedBy())
-                .append("updatedTime", getUpdatedTime())
-                .append("remark", getRemark())
-                .toString();
-    }
-
-    public Object[] toArray() {
-        Object[] objects = {this.deviceId, this.alarmType, this.startTime};
-        return objects;
-    }
 }

+ 6 - 1
ruoyi-admin/src/main/java/com/ruoyi/biz/domain/TwinRecordStop.java

@@ -69,7 +69,12 @@ public class TwinRecordStop extends BaseEntity {
     @Excel(name = "停机类型;1停经片停机,2-CCD停机(相机号+断纱/故障),3-人工停机,4-断电停机,5-设备故障停机,6-落布米数达到停机,7-盘头剩余圈数达到停机")
     @ApiModelProperty("停机类型;1停经片停机,2-CCD停机(相机号+断纱/故障),3-人工停机,4-断电停机,5-设备故障停机,6-落布米数达到停机,7-盘头剩余圈数达到停机")
     private Integer stopType;
-
+    /**
+     * 统计状态
+     */
+    @Excel(name = "统计状态")
+    @ApiModelProperty("统计状态")
+    private String calcStatus;
     /**
      * 创建人
      */

+ 139 - 107
ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/AsyncServiceImpl.java

@@ -7,7 +7,6 @@ import com.ruoyi.biz.service.IIotService;
 import com.ruoyi.biz.tools.Tools;
 import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.utils.CacheUtils;
-import javafx.util.Pair;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.AsyncResult;
@@ -50,7 +49,6 @@ public class AsyncServiceImpl {
     public Future<Map<String, List<?>>> process(TwinDevice twinDevice, Date date, long startTime, long endTime, int period) {
         Map<String, List<?>> result = new HashMap<>(16);
         List<TwinCalcHour> calcHours = new ArrayList<>();
-        List<TwinRecordAlarms> recordAlarmsList = new ArrayList<>();
         String table = twinDevice.getDevicePath();
         TwinCalcHour hour = new TwinCalcHour();
         hour.setDeviceId(twinDevice.getDeviceId());
@@ -68,41 +66,6 @@ public class AsyncServiceImpl {
         hour.setOpenTime((long) total[3]);
         hour.setCloseTime((long) total[4]);
         calcHours.add(hour);
-//        Map<String, Long> stop = (Map<String, Long>) map.get("stop");
-//        calc2hr.setStop1A(stop.get("stop1_A"));
-//        calc2hr.setStop1B(stop.get("stop1_B"));
-//        calc2hr.setStop2A(stop.get("stop2_A"));
-//        calc2hr.setStop2B(stop.get("stop2_B"));
-//        calc2hr.setStop3A(stop.get("stop3_A"));
-//        calc2hr.setStop3B(stop.get("stop3_B"));
-
-        //        int[] alarms = (int[]) map.get("alarms");
-        //        int alarmsTimes = 0;
-        //        for (int i = 0; i < alarms.length; i++) {
-        //            alarmsTimes += alarms[i];
-        //        }
-        //        calc2hr.setAlarm((long) alarmsTimes);
-        //        calc2hr.setRemark(Arrays.toString(alarms));
-        //
-        //        calc2hrList.add(calc2hr);
-        //        List<Pair<String, Long>> alarmRecord = (List<Pair<String, Long>>) map.get("alarmRecord");
-        //
-        //        String strStop = "stop";
-        //        String strAlarm = "alarm";
-//        alarmRecord.forEach(pair -> {
-//            TwinRecordAlarms recordAlarms = new TwinRecordAlarms();
-//            recordAlarms.setDeviceId(twinDevice.getId());
-//            String key = pair.getKey();
-//            if (key.startsWith(strStop)) {
-//                recordAlarms.setAlarmType(strStop);
-//                recordAlarms.setAlarmCode(Long.parseLong(key.replace(strStop, "")));
-//            } else {
-//                recordAlarms.setAlarmType(strAlarm);
-//                recordAlarms.setAlarmCode(Long.parseLong(key.replace(strAlarm, "")));
-//            }
-//            recordAlarms.setDataTime(new Date(pair.getValue()));
-//            recordAlarmsList.add(recordAlarms);
-//        });
 
         List<TwinPanHeadInfo> panHeadInfo = (List<TwinPanHeadInfo>) map.get("panHead");
         panHeadInfo.forEach(info -> info.setDeviceId(twinDevice.getDeviceId()));
@@ -113,10 +76,16 @@ public class AsyncServiceImpl {
             stop.setDataDate(date);
             stop.setHour(period);
         });
-
+        List<TwinRecordAlarms> alarmRecord = (List<TwinRecordAlarms>) map.get("alarmRecord");
+        alarmRecord.forEach(alarm -> {
+            alarm.setDeviceId(twinDevice.getDeviceId());
+            alarm.setDataDate(date);
+            alarm.setHour(period);
+        });
 
         result.put("calc", calcHours);
         result.put("stopRecord", stopRecord);
+        result.put("alarmRecord", alarmRecord);
         result.put("panHead", panHeadInfo);
         return new AsyncResult<>(result);
     }
@@ -172,25 +141,23 @@ public class AsyncServiceImpl {
         float[] last = new float[1];
         //统计数据,后面2个分别代表0.织造米长 1.重量,2.电量,3.开机时间,4.停机时间
         float[] total = new float[5];
-        //告警数据统计
-        boolean[] lastAlarms = new boolean[26];
         //上一个时间点盘头数据
         int[] lastPanHead = new int[5];
-        //最后一个值为int型,需要单独计算
-        int[] alarmsTimes = new int[27];
         //米克重
         int lastMkz = 0;
         //卷曲幅宽
         float lastFk = 0f;
         int last48 = 0;
-        int old48 = -1;
-        Object d = CacheUtils.get(Constants.IOT_TOKEN, table);
-        if (d != null) {
-            //获取存储的最后一次停机状态值
-            old48 = (int) d;
-        }
+        //上一轮最后一条停机记录
+        JSONArray old = null;
+        //上一轮最后一条告警记录
+//        Object oldV = CacheUtils.get(Constants.IOT_TOKEN, table + "-stop");
+//        if (oldV != null) {
+//            //获取存储的最后一次停机状态值
+//            old = (JSONArray) oldV;
+//        }
         //告警时间记录
-        List<Pair<String, Long>> alarmRecord = new ArrayList<>();
+        List<TwinRecordAlarms> alarmRecord = new ArrayList<>();
         //停机记录
         List<TwinRecordStop> stopRecord = new ArrayList<>();
         //盘头记录
@@ -213,9 +180,6 @@ public class AsyncServiceImpl {
                 lastMkz = da.getInt(8);
                 lastFk = da.getFloat(9);
                 last48 = curr48;
-                for (int j = 0; j < lastAlarms.length; j++) {
-                    lastAlarms[j] = da.getBool(12 + j);
-                }
                 continue;
             }
             //计算电量
@@ -232,34 +196,29 @@ public class AsyncServiceImpl {
                     first[j] = curr[j];
                 }
             }
-
-            calcAlarms(lastAlarms, da, timestamps, values, i, alarmsTimes, alarmRecord);
-            System.err.println(new Date(timestamps.getLong(i)));
-            calcStops(curr48, last48, timestamps.getLong(i), total, stopRecord, old48, i);
+            calcAlarms(values, old, timestamps.getLong(i), alarmRecord, i);
+            calcStops(curr48, last48, timestamps.getLong(i), total, stopRecord, old, i);
 
             //复制数组,设置last值为当前值
             last = curr.clone();
             lastPanHead = currPan.clone();
             lastMkz = da.getInt(8);
             lastFk = da.getFloat(9);
-            for (int j = 0; j < lastAlarms.length; j++) {
-                lastAlarms[j] = da.getBool(12 + j);
-            }
             last48 = curr48;
         }
         //最后再补一次计算
         for (int j = 0; j < first.length; j++) {
             calcTotal(j, last, first, total, lastMkz, lastFk);
         }
+
         //存入最后一条记录的停机状态
-        CacheUtils.put(Constants.IOT_TOKEN, table, last48);
+//        CacheUtils.put(Constants.IOT_TOKEN, table, values.getJSONArray(values.size() - 1));
 
         total[3] = 3600 - total[4];
 
         Map<String, Object> result = new HashMap<>(16);
         result.put("total", total);
         result.put("stopRecord", stopRecord);
-        result.put("alarms", alarmsTimes);
         result.put("alarmRecord", alarmRecord);
         result.put("panHead", panHeadInfo);
         return result;
@@ -315,14 +274,30 @@ public class AsyncServiceImpl {
      * @param time       时间
      * @param total      统计
      * @param stopRecord 记录
+     * @param oldV       上次的最后一条记录的值
+     * @param i          当前时序
      */
-    private void calcStops(int curr, int last, long time, float[] total, List<TwinRecordStop> stopRecord, int old, int i) {
+    private void calcStops(int curr, int last, long time, float[] total, List<TwinRecordStop> stopRecord, JSONArray oldV, int i) {
+        //取消毫秒
+        time = time / 1000 * 1000;
         TwinRecordStop stop = new TwinRecordStop();
-
         //如果第一条记录为0,需要判断之前有木有没有结束时间的停机
-        if (i == 1 && old != -1 && last != old) {
-            stop.setStopType(old);
-            stop.setEndTime(new Date(time));
+        //暂时取消这个判断
+//        if (i == 1 && oldV != null) {
+//            int old = oldV.getInt(7);
+//            if (last != old) {
+//                stop.setStopType(old);
+//                stop.setEndTime(new Date(time));
+//                stopRecord.add(stop);
+//                return;
+//            }
+//        }
+        //如果第一条记录不为0,则直接记录停机开始时间
+        if (i == 1 && curr != 0) {
+            stop = new TwinRecordStop();
+            //记录停机开始时间
+            stop.setStopType(curr);
+            stop.setStartTime(new Date(time));
             stopRecord.add(stop);
             return;
         }
@@ -350,55 +325,112 @@ public class AsyncServiceImpl {
     }
 
     /**
-     * 告警次数计算
+     * 告警计算
+     *
+     * @param values      所有记录
+     * @param old         上次存储的
+     * @param time        当前时间
+     * @param alarmRecord 告警记录
+     * @param i           时序
      */
-    private void calcAlarms(boolean[] lastAlarms, JSONArray da, JSONArray timestamps, JSONArray values, int i,
-                            int[] alarmsTimes, List<Pair<String, Long>> alarmRecord) {
-        int endNum = timestamps.size();
-        if (i + 9 < timestamps.size()) {
-            endNum = i + 9;
+    private void calcAlarms(JSONArray values, JSONArray old, long time, List<TwinRecordAlarms> alarmRecord, int i) {
+        JSONArray curr = values.getJSONArray(i);
+        JSONArray last = values.getJSONArray(i - 1);
+        TwinRecordAlarms recordAlarms;
+        int index = 26;
+        /*暂时取消
+         //        if (i == 1 && old != null) {
+         //            //判断第一条记录为0,并且上一轮存储的值,需要判断之前有没有未结束的告警
+         //            int j = 0;
+         //            for (; j < index; j++) {
+         //                boolean oldV = curr.getBool(j + 12);
+         //                boolean lastV = last.getBool(j + 12);
+         //                if (oldV && !lastV) {
+         //                    recordAlarms = new TwinRecordAlarms();
+         //                    recordAlarms.setAlarmType(j + 1);
+         //                    recordAlarms.setEndTime(new Date(time));
+         //                    alarmRecord.add(recordAlarms);
+         //                }
+         //            }
+         //            //需要单独计算alarm27
+         //            //数据位置
+         //            int pos = j + 12;
+         //            int old27 = curr.getInt(pos);
+         //            //上面已经处理过i=0,所以这里i不可能等于0
+         //            int last27 = last.getInt(pos);
+         //            if (old27 != 0 && last27 == 0) {
+         //                recordAlarms = new TwinRecordAlarms();
+         //                recordAlarms.setAlarmType(j + 1);
+         //                recordAlarms.setEndTime(new Date(time));
+         //                alarmRecord.add(recordAlarms);
+         //            }
+         //        }
+         */
+        boolean[] flags = new boolean[index + 1];
+        for (int kk = 0; i < flags.length; i++) {
+            flags[kk] = true;
+        }
+        if (i == 1) {
+            int j = 0;
+            for (; j < index; j++) {
+                boolean currV = curr.getBool(j + 12);
+                if (currV) {
+                    flags[j] = false;
+                    recordAlarms = new TwinRecordAlarms();
+                    recordAlarms.setAlarmType(j + 1);
+                    recordAlarms.setStartTime(new Date(time));
+                    alarmRecord.add(recordAlarms);
+                }
+            }
+            //需要单独计算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 j = 0;
-        for (; j < lastAlarms.length; j++) {
-            boolean currV = da.getBool(j + 12);
-            if (currV && !lastAlarms[j]) {
-                //如果当前值为true,上一条为false 则记录一次告警(并且后面连续多次为TRUE)
-                boolean numFlag = true;
-                for (int k = i + 1; k < endNum; k++) {
-                    JSONArray nextData = values.getJSONArray(k);
-                    boolean nextV = nextData.getBool(j + 12);
-                    if (!nextV) {
-                        numFlag = false;
-                        break;
-                    }
+        for (; j < index; j++) {
+            if (flags[j]) {
+                boolean currV = curr.getBool(j + 12);
+                boolean lastV = last.getBool(j + 12);
+                if (currV && !lastV) {
+                    recordAlarms = new TwinRecordAlarms();
+                    recordAlarms.setAlarmType(j + 1);
+                    recordAlarms.setStartTime(new Date(time));
+                    alarmRecord.add(recordAlarms);
                 }
-                if (numFlag) {
-                    alarmRecord.add(new Pair<>("alarm" + (j + 1), timestamps.getLong(i)));
-                    alarmsTimes[j] += 1;
+                if (!currV && lastV) {
+                    recordAlarms = new TwinRecordAlarms();
+                    recordAlarms.setAlarmType(j + 1);
+                    recordAlarms.setEndTime(new Date(time));
+                    alarmRecord.add(recordAlarms);
                 }
             }
         }
-        //需要单独计算alarm27
-        //数据位置
-        int pos = j + 12;
-        int alarm27 = da.getInt(pos);
-        //上面已经处理过i=0,所以这里i不可能等于0
-        JSONArray last = values.getJSONArray(i - 1);
-        int last27 = last.getInt(pos);
-        if (alarm27 != 0 && last27 == 0) {
-            //当前值不为0,上一条为0,则记录一次告警(并且后面连续多次为该值)
-            boolean numFlag = true;
-            for (int k = i + 1; k < endNum; k++) {
-                JSONArray nextData = values.getJSONArray(k);
-                int nextV = nextData.getInt(j + 12);
-                if (alarm27 != nextV) {
-                    numFlag = false;
-                    break;
-                }
+        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 (numFlag) {
-                alarmRecord.add(new Pair<>("alarm" + (j + 1), timestamps.getLong(i)));
-                alarmsTimes[j] += 1;
+            if (alarm27 == 0 && last27 != 0) {
+                recordAlarms = new TwinRecordAlarms();
+                recordAlarms.setAlarmType(j + 1);
+                recordAlarms.setEndTime(new Date(time));
+                alarmRecord.add(recordAlarms);
             }
         }
     }

+ 24 - 23
ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/TaskServiceImpl.java

@@ -173,7 +173,7 @@ public class TaskServiceImpl implements ITaskService {
         int period = ldt.getHour();
         List<Object[]> calcHours = new ArrayList<>();
         List<TwinRecordStop> stopList = new ArrayList<>();
-        List<Object[]> recordAlarmsList = new ArrayList<>();
+        List<TwinRecordAlarms> alarmsList = new ArrayList<>();
         List<Object[]> panList = new ArrayList<>();
         Date s = new Date();
         //为了避免多线程同时获取token导致重复执行,先执行一次获取token
@@ -182,11 +182,11 @@ public class TaskServiceImpl implements ITaskService {
         //查询所有在线的设备
         search.setOnline("1");
         List<TwinDevice> list = deviceService.selectTwinDeviceList(search);
-        List<TwinDevice> errList = exec(list, date, startTime, endTime, period, calcHours, stopList, panList);
+        List<TwinDevice> errList = exec(list, date, startTime, endTime, period, calcHours, stopList, panList, alarmsList);
         //重试2次
         int repTimes = 1;
         while (errList.size() != 0) {
-            errList = exec(errList, date, startTime, endTime, period, calcHours, stopList, panList);
+            errList = exec(errList, date, startTime, endTime, period, calcHours, stopList, panList, alarmsList);
             if (repTimes++ > 1) {
                 break;
             }
@@ -194,39 +194,38 @@ public class TaskServiceImpl implements ITaskService {
 
         Date d = new Date();
         log.info("总共消耗:{}ms", d.getTime() - s.getTime());
-//        String sql = "INSERT INTO TWIN_CALC_2HR (" +
-//                "DATA_DATE,TIME_PERIOD,DEVICE_ID,LENGTH_A,OPEN_TIME_A," +
-//                "CLOSE_TIME_A,LENGTH_B,CLOSE_TIME_B,OPEN_TIME_B,WEIGHT," +
-//                "WEIGHT_A,WEIGHT_B,ALARM,STOP1_A,STOP2_A," +
-//                "STOP3_A,STOP1_B,STOP2_B,STOP3_B,REMARK," +
-//                "KWH,KWH_A,KWH_B)" +
-//                " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
+        //1小时统计数据
         String sql = "INSERT INTO TWIN_CALC_HOUR(DATA_DATE,HOUR,DEVICE_ID,KWH,WEIGHT,LENGTH,OPEN_TIME,CLOSE_TIME) VALUES (?,?,?,?,?,?,?,?)";
         jdbcTemplate.batchUpdate(sql, calcHours);
-
-//        sql = "INSERT INTO TWIN_RECORD_ALARMS (DEVICE_ID,ALARM_TYPE,ALARM_CODE,DATA_TIME) VALUES (?,?,?,?)";
-//        jdbcTemplate.batchUpdate(sql, recordAlarmsList);
-
+        //盘头数据
         sql = "INSERT INTO TWIN_PAN_HEAD_INFO (DEVICE_ID,PH_NUM,PH_MAX,RECORD_TIME) VALUES (?,?,?,?)";
         jdbcTemplate.batchUpdate(sql, panList);
         //执行停机记录处理
         stopList.forEach(stop -> {
             if (stop.getStartTime() != null) {
-                jdbcTemplate.update("INSERT INTO TWIN_RECORD_STOP (DEVICE_ID,DATA_DATE,HOUR,START_TIME,STOP_TYPE) VALUES (?,?,?,?,?)", stop.getDeviceId(), stop.getDataDate(), stop.getHour(), stop.getStartTime(), stop.getStopType());
+                jdbcTemplate.update("INSERT INTO TWIN_RECORD_STOP (DEVICE_ID,DATA_DATE,HOUR,START_TIME,STOP_TYPE,CALC_STATUS) VALUES (?,?,?,?,?,?)", stop.getDeviceId(), stop.getDataDate(), stop.getHour(), stop.getStartTime(), stop.getStopType(), "0");
             }
             if (stop.getEndTime() != null) {
-                if (stop.getStopType() == 99) {
-                    jdbcTemplate.update("UPDATE TWIN_RECORD_STOP SET END_TIME=? WHERE DEVICE_ID=? AND END_TIME IS NULL", stop.getEndTime(), stop.getDeviceId());
-                } else {
-                    jdbcTemplate.update("UPDATE TWIN_RECORD_STOP SET END_TIME=? WHERE DEVICE_ID=? AND STOP_TYPE=? AND END_TIME IS NULL", stop.getEndTime(), stop.getDeviceId(), stop.getStopType());
-                }
+                jdbcTemplate.update("UPDATE TWIN_RECORD_STOP SET END_TIME=? WHERE DEVICE_ID=? AND STOP_TYPE=? AND END_TIME IS NULL", stop.getEndTime(), stop.getDeviceId(), stop.getStopType());
             }
-
         });
+        //补一次,所有没有结束时间的为当前结束时间
+        jdbcTemplate.update("UPDATE TWIN_RECORD_STOP SET END_TIME=? WHERE END_TIME IS NULL", new Date(endTime));
+        //执行告警记录处理
+        alarmsList.forEach(alarms -> {
+            if (alarms.getStartTime() != null) {
+                jdbcTemplate.update("INSERT INTO TWIN_RECORD_ALARMS (DEVICE_ID,DATA_DATE,HOUR,START_TIME,ALARM_TYPE,CALC_STATUS) VALUES (?,?,?,?,?,?)", alarms.getDeviceId(), alarms.getDataDate(), alarms.getHour(), alarms.getStartTime(), alarms.getAlarmType(), "0");
+            }
+            if (alarms.getEndTime() != null) {
+                jdbcTemplate.update("UPDATE TWIN_RECORD_ALARMS SET END_TIME=? WHERE DEVICE_ID=? AND ALARM_TYPE=? AND END_TIME IS NULL", alarms.getEndTime(), alarms.getDeviceId(), alarms.getAlarmType());
+            }
+        });
+        //补一次,所有没有结束时间的为当前结束时间
+        jdbcTemplate.update("UPDATE TWIN_RECORD_ALARMS SET END_TIME=? WHERE END_TIME IS NULL", new Date(endTime));
     }
 
 
-    private List<TwinDevice> exec(List<TwinDevice> list, Date date, Long startTime, Long endTime, int period, List<Object[]> calcHourList, List<TwinRecordStop> stopList, List<Object[]> panList) {
+    private List<TwinDevice> exec(List<TwinDevice> list, Date date, Long startTime, Long endTime, int period, List<Object[]> calcHourList, List<TwinRecordStop> stopList, List<Object[]> panList, List<TwinRecordAlarms> alarmsList) {
         List<Future<Map<String, List<?>>>> futureList = new ArrayList<>();
         for (int i = 0; i < list.size(); i++) {
             TwinDevice twinDevice = list.get(i);
@@ -241,11 +240,13 @@ public class TaskServiceImpl implements ITaskService {
                     Map<String, List<?>> map = future.get(10L, TimeUnit.SECONDS);
                     List<TwinCalcHour> calcHours = (List<TwinCalcHour>) map.get("calc");
                     List<TwinRecordStop> stops = (List<TwinRecordStop>) map.get("stopRecord");
+
+                    List<TwinRecordAlarms> alarms = (List<TwinRecordAlarms>) map.get("alarmRecord");
                     List<TwinPanHeadInfo> panHeadInfoList = (List<TwinPanHeadInfo>) map.get("panHead");
 
                     calcHours.forEach(calcHour -> calcHourList.add(calcHour.toArray()));
                     stopList.addAll(stops);
-//                    recordAlarms.forEach(alarm -> recordAlarmsList.add(alarm.toArray()));
+                    alarmsList.addAll(alarms);
                     panHeadInfoList.forEach(pan -> panList.add(pan.toArray()));
                 } catch (TimeoutException e) {
                     errList.add(list.get(futureList.indexOf(future)));

+ 19 - 25
ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/TwinRecordStopServiceImpl.java

@@ -1,94 +1,88 @@
 package com.ruoyi.biz.service.impl;
 
-import java.util.List;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import com.ruoyi.biz.mapper.TwinRecordStopMapper;
 import com.ruoyi.biz.domain.TwinRecordStop;
+import com.ruoyi.biz.mapper.TwinRecordStopMapper;
 import com.ruoyi.biz.service.ITwinRecordStopService;
 import com.ruoyi.common.core.text.Convert;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
 
 /**
  * 停机数据记录Service业务层处理
- * 
+ *
  * @author ruoyi
  * @date 2024-06-28
  */
 @Service
-public class TwinRecordStopServiceImpl implements ITwinRecordStopService 
-{
+public class TwinRecordStopServiceImpl implements ITwinRecordStopService {
     @Autowired
     private TwinRecordStopMapper twinRecordStopMapper;
 
     /**
      * 查询停机数据记录
-     * 
+     *
      * @param id 停机数据记录主键
      * @return 停机数据记录
      */
     @Override
-    public TwinRecordStop selectTwinRecordStopById(Long id)
-    {
+    public TwinRecordStop selectTwinRecordStopById(Long id) {
         return twinRecordStopMapper.selectTwinRecordStopById(id);
     }
 
     /**
      * 查询停机数据记录列表
-     * 
+     *
      * @param twinRecordStop 停机数据记录
      * @return 停机数据记录
      */
     @Override
-    public List<TwinRecordStop> selectTwinRecordStopList(TwinRecordStop twinRecordStop)
-    {
+    public List<TwinRecordStop> selectTwinRecordStopList(TwinRecordStop twinRecordStop) {
         return twinRecordStopMapper.selectTwinRecordStopList(twinRecordStop);
     }
 
     /**
      * 新增停机数据记录
-     * 
+     *
      * @param twinRecordStop 停机数据记录
      * @return 结果
      */
     @Override
-    public int insertTwinRecordStop(TwinRecordStop twinRecordStop)
-    {
+    public int insertTwinRecordStop(TwinRecordStop twinRecordStop) {
         return twinRecordStopMapper.insertTwinRecordStop(twinRecordStop);
     }
 
     /**
      * 修改停机数据记录
-     * 
+     *
      * @param twinRecordStop 停机数据记录
      * @return 结果
      */
     @Override
-    public int updateTwinRecordStop(TwinRecordStop twinRecordStop)
-    {
+    public int updateTwinRecordStop(TwinRecordStop twinRecordStop) {
         return twinRecordStopMapper.updateTwinRecordStop(twinRecordStop);
     }
 
     /**
      * 批量删除停机数据记录
-     * 
+     *
      * @param ids 需要删除的停机数据记录主键
      * @return 结果
      */
     @Override
-    public int deleteTwinRecordStopByIds(String ids)
-    {
+    public int deleteTwinRecordStopByIds(String ids) {
         return twinRecordStopMapper.deleteTwinRecordStopByIds(Convert.toStrArray(ids));
     }
 
     /**
      * 删除停机数据记录信息
-     * 
+     *
      * @param id 停机数据记录主键
      * @return 结果
      */
     @Override
-    public int deleteTwinRecordStopById(Long id)
-    {
+    public int deleteTwinRecordStopById(Long id) {
         return twinRecordStopMapper.deleteTwinRecordStopById(id);
     }
 }

+ 1 - 0
ruoyi-admin/src/main/resources/mapper/biz/TwinDeviceMapper.xml

@@ -38,6 +38,7 @@
             </if>
             <if test="deviceCode != null  and deviceCode != ''">and DEVICE_CODE = #{deviceCode}</if>
             <if test="online != null  and online != ''">and ONLINE = #{online}</if>
+            <if test="deviceId != null  and deviceId != ''">and DEVICE_ID = #{deviceId}</if>
             <if test="devicePath != null  and devicePath != ''">and DEVICE_PATH = #{devicePath}</if>
             <if test="remark != null  and remark != ''">and REMARK = #{remark}</if>
         </where>

+ 9 - 6
ruoyi-admin/src/main/resources/mapper/biz/TwinRecordStopMapper.xml

@@ -3,7 +3,7 @@
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.biz.mapper.TwinRecordStopMapper">
-    
+
     <resultMap type="TwinRecordStop" id="TwinRecordStopResult">
         <result property="id"    column="ID"    />
         <result property="deviceId"    column="DEVICE_ID"    />
@@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="startTime"    column="START_TIME"    />
         <result property="endTime"    column="END_TIME"    />
         <result property="stopType"    column="STOP_TYPE"    />
+        <result property="calcStatus"    column="CALC_STATUS"    />
         <result property="createdBy"    column="CREATED_BY"    />
         <result property="createdTime"    column="CREATED_TIME"    />
         <result property="updatedBy"    column="UPDATED_BY"    />
@@ -25,26 +26,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectTwinRecordStopList" parameterType="TwinRecordStop" resultMap="TwinRecordStopResult">
         <include refid="selectTwinRecordStopVo"/>
-        <where>  
+        <where>
             <if test="deviceId != null "> and DEVICE_ID = #{deviceId}</if>
             <if test="params.beginDataDate != null and params.beginDataDate != '' and params.endDataDate != null and params.endDataDate != ''"> and DATA_DATE between #{params.beginDataDate} and #{params.endDataDate}</if>
             <if test="hour != null  and hour != ''"> and HOUR = #{hour}</if>
             <if test="params.beginStartTime != null and params.beginStartTime != '' and params.endStartTime != null and params.endStartTime != ''"> and START_TIME between #{params.beginStartTime} and #{params.endStartTime}</if>
             <if test="params.beginEndTime != null and params.beginEndTime != '' and params.endEndTime != null and params.endEndTime != ''"> and END_TIME between #{params.beginEndTime} and #{params.endEndTime}</if>
             <if test="stopType != null "> and STOP_TYPE = #{stopType}</if>
+            <if test="calcStatus != null "> and CALC_STATUS = #{calcStatus}</if>
             <if test="createdBy != null  and createdBy != ''"> and CREATED_BY = #{createdBy}</if>
             <if test="createdTime != null "> and CREATED_TIME = #{createdTime}</if>
             <if test="updatedBy != null  and updatedBy != ''"> and UPDATED_BY = #{updatedBy}</if>
             <if test="updatedTime != null "> and UPDATED_TIME = #{updatedTime}</if>
             <if test="remark != null  and remark != ''"> and REMARK = #{remark}</if>
         </where>
+        order by START_TIME
     </select>
-    
+
     <select id="selectTwinRecordStopById" parameterType="Long" resultMap="TwinRecordStopResult">
         <include refid="selectTwinRecordStopVo"/>
         where ID = #{id}
     </select>
-        
+
     <insert id="insertTwinRecordStop" parameterType="TwinRecordStop" useGeneratedKeys="true" keyProperty="id">
         insert into twin_record_stop
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -98,10 +101,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
     <delete id="deleteTwinRecordStopByIds" parameterType="String">
-        delete from twin_record_stop where ID in 
+        delete from twin_record_stop where ID in
         <foreach item="id" collection="array" open="(" separator="," close=")">
             #{id}
         </foreach>
     </delete>
 
-</mapper>
+</mapper>

+ 81 - 0
ruoyi-admin/src/test/java/com/jjt/DataGovernance.java

@@ -0,0 +1,81 @@
+package com.jjt;
+
+import com.ruoyi.RuoYiApplication;
+import com.ruoyi.biz.domain.TwinCalcStop;
+import com.ruoyi.biz.domain.TwinRecordStop;
+import com.ruoyi.biz.service.ITwinCalcStopService;
+import com.ruoyi.biz.service.ITwinRecordStopService;
+import com.ruoyi.common.utils.bean.BeanUtils;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * DataProcess$
+ *
+ * @author wukai
+ * @date 2024/5/7 11:49
+ */
+@SpringBootTest(classes = RuoYiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+public class DataGovernance {
+    @Resource
+    private ITwinRecordStopService stopService;
+    @Resource
+    private ITwinCalcStopService calcStopService;
+    @Resource
+    private JdbcTemplate jdbcTemplate;
+
+    public static void main(String[] args) {
+    }
+
+    @Test
+    void test() {
+        int seconds = 30 * 1000;
+        TwinRecordStop search = new TwinRecordStop();
+        search.setCalcStatus("0");
+//        search.setDeviceId(8l);
+//        search.setStopType(3);
+        List<TwinRecordStop> list = stopService.selectTwinRecordStopList(search);
+        Map<Integer, List<TwinRecordStop>> groupList = list.stream().collect(Collectors.groupingBy(TwinRecordStop::getStopType));
+        List<Object[]> ids = new ArrayList<>();
+        List<TwinRecordStop> recordList = new ArrayList<>();
+        for (Map.Entry<Integer, List<TwinRecordStop>> entry : groupList.entrySet()) {
+            List<TwinRecordStop> temp = entry.getValue();
+            TwinRecordStop lastStop = null;
+            for (int i = 0; i < temp.size() - 1; i++) {
+                TwinRecordStop currStop = temp.get(i);
+                if (lastStop == null) {
+                    lastStop = currStop;
+                } else if (lastStop.getEndTime() != null) {
+                    ids.add(new Object[]{currStop.getId()});
+                    //1.第一轮,下一条开始时间-上一条结束时间小于 seconds 则两条记录合并
+                    if (currStop.getStartTime().getTime() - lastStop.getEndTime().getTime() < seconds) {
+                        lastStop.setEndTime(currStop.getEndTime());
+                    } else {
+                        //2.判断持续时间,如果大于seconds则记录
+                        if (lastStop.getEndTime().getTime() - lastStop.getStartTime().getTime() > seconds) {
+                            recordList.add(lastStop);
+                        }
+                        lastStop = currStop;
+                    }
+                }
+            }
+        }
+
+        recordList.forEach(stop -> {
+            TwinCalcStop v = new TwinCalcStop();
+            BeanUtils.copyProperties(stop, v);
+            v.setId(null);
+            calcStopService.insertTwinCalcStop(v);
+        });
+        String sql = "UPDATE TWIN_RECORD_STOP SET CALC_STATUS='1' WHERE ID=?";
+        jdbcTemplate.batchUpdate(sql, ids);
+    }
+
+}

+ 17 - 9
ruoyi-admin/src/test/java/com/jjt/DataHour.java

@@ -31,16 +31,24 @@ public class DataHour {
     @Test
     public void test() {
         for (int i = 7; i < 24; i++) {
-            taskService.calc("2024-06-25", i);
+            taskService.calc("2024-06-26", i);
+        }
+        for (int i = 0; i < 24; i++) {
+            taskService.calc("2024-06-27", i);
         }
         for (int i = 0; i < 7; i++) {
-            taskService.calc("2024-06-26", i);
+            taskService.calc("2024-06-28", i);
         }
     }
 
+    @Test
+    public void oneTest(){
+        taskService.calc("2024-06-26", 23);
+    }
+
     public static void main(String[] args) {
-        long startTime = 1719244799000l;
-        long endTime = 1719291600000l;
+        long startTime = 1719417445000l;
+        long endTime = 1719417505000l;
 //        asyncService.calc(table, startTime, endTime);
         LocalDateTime start = LocalDateTime.ofInstant(Instant.ofEpochMilli(startTime), ZoneId.systemDefault());
         LocalDateTime end = LocalDateTime.ofInstant(Instant.ofEpochMilli(endTime), ZoneId.systemDefault());
@@ -50,14 +58,14 @@ public class DataHour {
 
     @Test
     public void one() {
-        String table = "root.tl.suxi.knittings8_plc1";
-        long startTime = 1719290930000l;
-        long endTime = 1719291600000l;
+        String table = "root.tl.suxi.knittings6_plc1";
+        long startTime = 1719417444000l;
+        long endTime = 1719417505000l;
         asyncService.calc(table, startTime, endTime);
 
         startTime = 1719291600000l;
-        endTime = 1719295200000l;
-        asyncService.calc(table, startTime, endTime);
+//        endTime = 1719295200000l;
+//        asyncService.calc(table, startTime, endTime);
 //        LocalDateTime start = LocalDateTime.ofInstant(Instant.ofEpochMilli(startTime), ZoneId.systemDefault());
 //        LocalDateTime end = LocalDateTime.ofInstant(Instant.ofEpochMilli(endTime), ZoneId.systemDefault());
 //        taskService.calc4device(start, end);

+ 5 - 4
ruoyi-admin/src/test/java/com/jjt/DeviceTest.java

@@ -28,11 +28,12 @@ public class DeviceTest {
 
     @Test
     void test() {
-        String sql = "update TWIN_DEVICE set online='0' where device_code='C_";
+        String sql = "update TWIN_DEVICE set online=? where device_code=?";
         for (int i = 1; i <= 140; i++) {
-            if (!get(i)) {
-                String xxsql = sql + i + "'";
-                jdbcTemplate.update(xxsql);
+            if (get(i)) {
+                jdbcTemplate.update(sql,1,"C_"+i);
+            }else{
+                jdbcTemplate.update(sql,0,"C_"+i);
             }
         }
     }