yangys
2024-11-15 d66fe6d46cdbaeb88e68ad96da6deb0b35cd131b
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
package com.qianwen.smartman.modules.mdc.service;
 
import java.util.Map;
 
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;
    
    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());
            
            //存在问题,DeviceStastus,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();
            }
            statusJson.put("preT", preT);
            //statusJson.put("t", System.currentTimeMillis());//时间改为当前)
            map.put(statusDpName, statusJson);//覆盖原来的DeviceStatus
        }
    }
 
}