yangys
2025-11-18 8e944cfabb253fc2556588e308e282586043f7b0
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
package com.qianwen.smartman.modules.mdc.service;
 
import java.util.Map;
 
import com.qianwen.smartman.modules.mdc.mapper.StateMapper;
import com.qianwen.smartman.modules.mdc.vo.StateVO;
import com.qianwen.smartman.modules.mdc.vo.StatusRecordVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.alibaba.fastjson.JSONObject;
import com.qianwen.smartman.modules.smis.message.dto.TelemetryDataResponseDTO;
import com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO;
import com.qianwen.smartman.modules.mdc.mapper.SuperProcessParameterMapper;
 
 
@Service
public class RealTimeDataService {
    private static final Logger log = LoggerFactory.getLogger(RealTimeDataService.class);
    @Autowired
    private SuperProcessParameterMapper processParamMapper;
 
    @Autowired
    private StateMapper stateMapper;
    
    public final String statusDpName = "DeviceStatus";
    /**
     * 为设备状态增加当前状态的最早时间preT
     * @param workstationId 工位id
     * @param map 工位id对应的所有最新数据
     */
    public void addPreTimeInDeviceStatus(long workstationId,Map<String, Object> map) {
        //找到状态的数据,加入上一个状态的
        
        if(map.containsKey(statusDpName)) {
            TelemetryDataResponseDTO statusDTO = (TelemetryDataResponseDTO) map.get(statusDpName);
            JSONObject statusJson = new JSONObject();
            statusJson.put("t", statusDTO.getT());
            statusJson.put("v", statusDTO.getV());
            
            //存在问题,DeviceStatus,DeviceStatus_n会几乎同时过来
            long preT = statusDTO.getT();
            //最后一条不同值(v)的数据
 
            /*
            ProcessParameterVO diffStatusVO = processParamMapper.lastParameterNotEqValue(workstationId, statusDpName, statusDTO.getV());
 
            ProcessParameterVO tempStatusVO; 
            if(diffStatusVO != null) {
                tempStatusVO = processParamMapper.firstParameterEqValueGtTime(workstationId, statusDpName, statusDTO.getV(), diffStatusVO.getTime().getTime());
            }else {
                tempStatusVO = processParamMapper.firstParameterEqValue(workstationId, statusDpName, statusDTO.getV());
            }
            if(tempStatusVO != null) {
                preT = tempStatusVO.getTime().getTime();
            }*/
            Integer val = Integer.parseInt(statusDTO.getV());
 
            //StateVO diffStatusVO = stateMapper.lastStateNotEqValue(workstationId,val);
            StateVO diffStatusVO = stateMapper.lastStateNotEqValueLtTime(workstationId,val,statusDTO.getT());
            StateVO tempStatusVO;
            if(diffStatusVO != null) {
                tempStatusVO = stateMapper.firstStateEqValueGtTime(workstationId, val, diffStatusVO.getTime());
            }else {
                tempStatusVO = stateMapper.firstStateEqValue(workstationId, val);
            }
            if(tempStatusVO != null) {
                preT = tempStatusVO.getTime();
            }
            statusJson.put("preT", preT);
            //statusJson.put("t", System.currentTimeMillis());//时间改为当前)
            map.put(statusDpName, statusJson);//覆盖原来的DeviceStatus
        }
    }
 
}