yangys
2024-10-09 7ef593e1e3c35aaeecf9318f0b3941230d3ed002
collect/src/main/java/com/qianwen/mdc/collect/service/DeviceStateService.java
@@ -94,9 +94,68 @@
         
         Tablet tablet = new Tablet(deviceId, schemas);
         
         states = entry.getValue();
         tablet.rowSize = states.size();
         DeviceState state;
         final int MAX_COUNT = 1000;
         //int currentIdx = 0;
         int tblIndex = 0;
         for(int i=0; i < states.size(); i++) {
            state = states.get(i);
            tablet.addTimestamp(tblIndex, state.getTime());
            tablet.addValue("workstation_id", tblIndex, state.getWorkstationId());
            tablet.addValue("value_collect", tblIndex, state.getValueCollect());
            tablet.addValue("calendar_code", tblIndex, state.getCalendarCode());
            tablet.addValue("factory_year", tblIndex, state.getFactoryYear());
            tablet.addValue("factory_month", tblIndex, state.getFactoryMonth());
            tablet.addValue("factory_week", tblIndex, state.getFactoryWeek());
            tablet.addValue("factory_date", tblIndex, state.getFactoryDate());
            tablet.addValue("shift_index", tblIndex, state.getShiftIndex());
            tablet.addValue("shift_time_type", tblIndex, state.getShiftTimeType());
            tablet.addValue("wcs", tblIndex, state.getWcs());
            tablet.addValue("rps", tblIndex, state.getRps());
            tablet.addValue("is_fix_point", tblIndex, state.getIsFixPoint());
            tablet.addValue("is_sync", tblIndex, state.getIsSync());
            tablet.addValue("is_plan", tblIndex, state.getIsPlan());
            tablet.addValue("feedback_point_type", tblIndex, state.getFeedbackPointType());
            tablet.addValue("feedback_id", tblIndex, state.getFeedbackId());
            tablet.addValue("is_deleted", tblIndex, state.getIsDeleted());
            tablet.addValue("employee_id", tblIndex, state.getEmployeeId());
            tblIndex++;
            if(tblIndex >= MAX_COUNT) {
               try {
                  //每个工位批量插入一次数据
                  this.iotdbConfig.getSessionPool().insertAlignedTablet(tablet);
                  log.info("保存设备状态完成");
                  tablet.reset();
                  tblIndex = 0;
               } catch (Exception e) {
                  log.error("保存固定点数据异常",e);
               }
            }
         }
         if(tblIndex > 0) {
            try {
               //每个工位批量插入一次数据
               this.iotdbConfig.getSessionPool().insertAlignedTablet(tablet);
               log.info("保存设备状态完成2");
               tablet.reset();
               tblIndex = 0;
            } catch (Exception e) {
               log.error("保存固定点数据异常",e);
            }
         }
         /*
         for(int i=0;i<states.size();i++) {
            state = states.get(i);
            tablet.addTimestamp(i, state.getTime());
@@ -119,14 +178,8 @@
            tablet.addValue("feedback_id", i, state.getFeedbackId());
            tablet.addValue("is_deleted", i, state.getIsDeleted());
            tablet.addValue("employee_id", i, state.getEmployeeId());
         }
         try {
            //每个工位批量插入一次数据
            this.iotdbConfig.getSessionPool().insertAlignedTablet(tablet);
         } catch (Exception e) {
            log.error("保存固定点数据异常",e);
         }
         }*/
         
      }
    }