yangys
2024-09-03 52ff3bda72646a532c3297e4843bc4d5aee8b949
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.qianwen.mdc.collect.handler;
 
import java.util.Arrays;
import java.util.Date;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import com.qianwen.mdc.collect.cache.WorkstationCache;
import com.qianwen.mdc.collect.dto.PackedTelemetryData;
import com.qianwen.mdc.collect.entity.iotdb.DeviceState;
import com.qianwen.mdc.collect.entity.mgr.GlobalWcsOfRps;
import com.qianwen.mdc.collect.enums.FeedbackTimePointEnum;
import com.qianwen.mdc.collect.service.DeviceStateService;
 
@Component
public class DeviceStatusDataHandler implements TelemetryDataHandler {
    private static final Logger log = LoggerFactory.getLogger(DeviceStatusDataHandler.class);
    @Autowired
    private WorkstationCache workstationCache;
    //@Autowired
    //private IotDBSessionConfig iotdbCfg;
    //@Autowired
    //private IotDBCommonService iotDBCommonService;
    @Autowired
    private DeviceStateService deviceStateService;
    @Override
    public void handleData(PackedTelemetryData data) {
        DeviceState state = new DeviceState();
        state.setTime(data.getTime());
        state.setCalendarCode(data.getCalendarCode());
        
        state.setFactoryDate(data.getFactoryDate());
        state.setFactoryMonth(data.getFactoryMonth());
        state.setFactoryWeek(data.getFactoryWeek());
        state.setFactoryYear(data.getFactoryYear());
        state.setIsFixPoint(false);
        state.setIsSync(false);
        state.setIsDeleted(false);
        
        state.setEmployeeId(workstationCache.getBelongToEmployeeForWorkstation(data.getWorkstationId(), new Date(data.getTime())));
        
        state.setFeedbackPointType(FeedbackTimePointEnum.NO_FEED_BACK_POINT.getValue());
        //WorkstationState propertyData = (WorkstationState) Objects.requireNonNull(BeanUtil.copy(entity, WorkstationState.class));
        state.setValueCollect(Integer.valueOf(data.getValue()));
        state.setWcs(state.getValueCollect());
        state.setWorkstationId(data.getWorkstationId());
        
        state.setShiftIndex(data.getShiftIndex());
        state.setShiftTimeType(data.getShiftTimeType());
        fillWorkStationCondition(data, state);
       
        //insertState(state);
        deviceStateService.saveDeviceStates(Arrays.asList(state));
        
        log.info("状态聚合聚合完成:数据");
    }
    
    private void fillWorkStationCondition(PackedTelemetryData data, DeviceState state) {
        GlobalWcsOfRps wcsOfRps = workstationCache.getWorkstationWcsSetting(data.getWorkstationId(), data.getValue());
        log.info("工况以及绩效信息:{}" ,wcsOfRps);
 
        state.setRps(Integer.valueOf(wcsOfRps.getRps()));
        state.setIsPlan(Integer.valueOf(wcsOfRps.getIsPlan()));
        //log.info("获取包装工况以及绩效信息" + JsonUtil.toJson(workstationState));
       
    }
    /*
    void insertState(DeviceState state){
        String deviceId = IOTDBConstant.DB_PREFIX+IOTDBConstant.TEMPLATE_STATE+"_"+state.getWorkstationId();
        try {
            iotDBCommonService.setTemmplateIfNotSet(IOTDBConstant.TEMPLATE_STATE, deviceId);
            
            List<MeasurementSchema> schemas = new ArrayList<>();
            
            schemas.add(new MeasurementSchema("workstation_id", TSDataType.INT64));
            schemas.add(new MeasurementSchema("value_collect", TSDataType.INT32));
            schemas.add(new MeasurementSchema("calendar_code", TSDataType.TEXT));
            schemas.add(new MeasurementSchema("factory_year", TSDataType.INT32));
            schemas.add(new MeasurementSchema("factory_month", TSDataType.INT32));
            schemas.add(new MeasurementSchema("factory_week", TSDataType.INT32));
            schemas.add(new MeasurementSchema("factory_date", TSDataType.INT32));
            schemas.add(new MeasurementSchema("shift_index", TSDataType.INT32));
            schemas.add(new MeasurementSchema("shift_time_type", TSDataType.INT32));
            schemas.add(new MeasurementSchema("wcs", TSDataType.INT32));
            schemas.add(new MeasurementSchema("rps", TSDataType.INT32));
            
            schemas.add(new MeasurementSchema("is_fix_point", TSDataType.BOOLEAN));
            schemas.add(new MeasurementSchema("is_sync", TSDataType.BOOLEAN));
            
            schemas.add(new MeasurementSchema("is_plan", TSDataType.INT32));
            schemas.add(new MeasurementSchema("feedback_point_type", TSDataType.INT32));
            schemas.add(new MeasurementSchema("feedback_id", TSDataType.INT64));
            schemas.add(new MeasurementSchema("is_deleted", TSDataType.BOOLEAN));
            schemas.add(new MeasurementSchema("employee_id", TSDataType.INT64));
            
            
            Tablet tablet = new Tablet(deviceId, schemas);
            int rowIndex = tablet.rowSize++;
            
            tablet.timestamps[rowIndex] = state.getTime();
            tablet.addValue("workstation_id", rowIndex, state.getWorkstationId());
            tablet.addValue("value_collect", rowIndex, state.getValueCollect());
            tablet.addValue("calendar_code", rowIndex, state.getCalendarCode());
            tablet.addValue("factory_year", rowIndex, state.getFactoryYear());
            tablet.addValue("factory_month", rowIndex, state.getFactoryMonth());
            tablet.addValue("factory_week", rowIndex, state.getFactoryWeek());
            tablet.addValue("factory_date", rowIndex, state.getFactoryDate());
            tablet.addValue("shift_index", rowIndex, state.getShiftIndex());//TODO null
            tablet.addValue("shift_time_type", rowIndex, state.getShiftTimeType());//TODO null
            tablet.addValue("wcs", rowIndex, state.getWcs());
            tablet.addValue("rps", rowIndex, state.getRps());
            
            tablet.addValue("is_fix_point", rowIndex,state.getIsFixPoint());
            tablet.addValue("is_sync", rowIndex, state.getIsSync());
            
            tablet.addValue("is_plan", rowIndex, state.getIsPlan());
            tablet.addValue("feedback_point_type", rowIndex, state.getFeedbackPointType());
            tablet.addValue("feedback_id", rowIndex, state.getFeedbackId());
            tablet.addValue("is_deleted", rowIndex, state.getIsDeleted());
            tablet.addValue("employee_id", rowIndex, state.getEmployeeId());
            
            iotdbCfg.getSessionPool().insertAlignedTablet(tablet);
            
            log.info("状态汇总完成");
        } catch (Exception e) {
            log.error("聚合产量IODDB入库失败", e);
        }
    }*/
}