yangys
2024-10-09 7ef593e1e3c35aaeecf9318f0b3941230d3ed002
collect/src/main/java/com/qianwen/mdc/collect/service/DeviceStateAggregateNoFeedbackService.java
@@ -39,6 +39,8 @@
   private IotDBSessionConfig iotdbConfig;
    @Autowired
   private IotDBCommonService iotDBCommonService;
    private static final int MAX_COUNT = 1000;
    public List<AggregateState> stateAggregateForSpecialTimeRange(Long workstationId, StateAggregateTimeDTO timeRange, List<DeviceState> effectiveStateList) {
       //按timeRange查询时间区间内的状态数据,除了已删除的,其他数据都查出来了
@@ -62,14 +64,6 @@
     * @param effectTimeRangeList
     */
    public void handlerAggregateState(List<AggregateState> result, Long workstationId, StateAggregateTimeDTO timeRange) {
       /*
        if (Func.isNotEmpty(result)) {
            Map<String, List> stringListMap = CommonUtil.groupList(getFinallyAggregateStateList(result, workstationId, effectTimeRangeList), CommonConstant.MAX_RECORDS_FOR_SQL_LENGTH.intValue());
            stringListMap.forEach(k, v -> {
                this.workstationAggregateStateMapper.batchSave(workstationId, v);
            });
        }*/
       if(result.isEmpty()) {
          return;
       }
@@ -93,7 +87,7 @@
      schemas.add(new MeasurementSchema("rps", TSDataType.INT32));
      //schemas.add(new MeasurementSchema("is_sync", TSDataType.BOOLEAN));
      schemas.add(new MeasurementSchema("is_plan", TSDataType.INT32));//TODO 这个属性应该是GlobalWcsOfRps中的值,如何填写?
      //schemas.add(new MeasurementSchema("feedback_id", TSDataType.INT64));
      schemas.add(new MeasurementSchema("is_deleted", TSDataType.BOOLEAN));
      schemas.add(new MeasurementSchema("employee_id", TSDataType.INT64));
      
@@ -104,41 +98,63 @@
      
      Tablet tablet = new Tablet(deviceId, schemas);
      tablet.rowSize = aggStates.size();
      AggregateState aggState;
      int tblIndex = 0;
      for(int i=0;i<aggStates.size();i++) {
         aggState = aggStates.get(i);
         tablet.addTimestamp(i, aggState.getTime());
         tablet.addValue("workstation_id", i, aggState.getWorkstationId());
         tablet.addValue("value_collect", i, aggState.getValueCollect());
         tablet.addValue("end_time", i, aggState.getEndTime());
         tablet.addValue("duration_collect", i, aggState.getDurationCollect());
         tablet.addValue("calendar_code", i, aggState.getCalendarCode());
         tablet.addValue("factory_year", i, aggState.getFactoryYear());
         tablet.addValue("factory_month", i, aggState.getFactoryMonth());
         tablet.addValue("factory_week", i, aggState.getFactoryWeek());
         tablet.addValue("factory_date", i, aggState.getFactoryDate());
         tablet.addValue("shift_index", i, aggState.getShiftIndex());
         tablet.addValue("shift_time_type", i, aggState.getShiftTimeType());
         tablet.addValue("wcs", i, aggState.getWcs());
         tablet.addValue("rps", i, aggState.getRps());
         tablet.addTimestamp(tblIndex, aggState.getTime());
         tablet.addValue("workstation_id", tblIndex, aggState.getWorkstationId());
         tablet.addValue("value_collect", tblIndex, aggState.getValueCollect());
         tablet.addValue("end_time", tblIndex, aggState.getEndTime());
         tablet.addValue("duration_collect", tblIndex, aggState.getDurationCollect());
         tablet.addValue("calendar_code", tblIndex, aggState.getCalendarCode());
         tablet.addValue("factory_year", tblIndex, aggState.getFactoryYear());
         tablet.addValue("factory_month", tblIndex, aggState.getFactoryMonth());
         tablet.addValue("factory_week", tblIndex, aggState.getFactoryWeek());
         tablet.addValue("factory_date", tblIndex, aggState.getFactoryDate());
         tablet.addValue("shift_index", tblIndex, aggState.getShiftIndex());
         tablet.addValue("shift_time_type", tblIndex, aggState.getShiftTimeType());
         tablet.addValue("wcs", tblIndex, aggState.getWcs());
         tablet.addValue("rps", tblIndex, aggState.getRps());
         
         tablet.addValue("is_plan", i, aggState.getIsPlan());
         //tablet.addValue("feedback_id", i, aggState.getFeedbackId());
         tablet.addValue("is_deleted", i, aggState.getIsDeleted());
         tablet.addValue("employee_id", i, aggState.getEmployeeId());
         tablet.addValue("is_plan", tblIndex, aggState.getIsPlan());
         tablet.addValue("is_deleted", tblIndex, aggState.getIsDeleted());
         tablet.addValue("employee_id", tblIndex, aggState.getEmployeeId());
         tblIndex++;
         if(tblIndex >= MAX_COUNT) {
            try {
               //每个工位批量插入一次数据
               this.iotdbConfig.getSessionPool().insertAlignedTablet(tablet);
               log.info("保存聚合状态完成tblIndex={}",tblIndex);
               tablet.reset();
               tblIndex = 0;
            } catch (Exception e) {
               log.error("保存固定点数据异常",e);
            }
         }
         
      }
      try {
         this.iotdbConfig.getSessionPool().insertAlignedTablet(tablet);
         log.info("保存聚合状态完成");
      } catch (Exception e) {
         log.error("保存聚合状态数据异常",e);
      }
      if(tblIndex > 0) {
         try {
            //每个工位批量插入一次数据
            this.iotdbConfig.getSessionPool().insertAlignedTablet(tablet);
            log.info("保存聚合状态完成finaltblIndex={}",tblIndex);
            tablet.reset();
            tblIndex = 0;
         } catch (Exception e) {
            log.error("保存固定点数据异常",e);
         }
      }
         
    }
    
    private List<AggregateState> getFinallyAggregateStateList(List<AggregateState> result, Long workstationId, StateAggregateTimeDTO timeRange) {
       /*
        List<StateAggregateTimeDTO> effectTimeRangeList2 = effectTimeRangeList.stream().filter(x -> {