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 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); map.put(statusDpName, statusJson);//覆盖原来的DeviceStatus } } }