package com.qianwen.smartman.modules.mdc.service;
|
|
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
import java.util.List;
|
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.RowMapper;
|
import org.springframework.stereotype.Service;
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
import com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO;
|
|
@DS("iotdb")
|
@Service
|
public class ProcessParameterHelperService {
|
private static final Logger log = LoggerFactory.getLogger(ProcessParameterHelperService.class);
|
|
@Autowired
|
private JdbcTemplate jdbcTemplate;
|
|
@DS("iotdb")
|
public ProcessParameterVO queryLastParameterLessThenTime(long workstationId,String item,Long time) {
|
|
ProcessParameterVO vo = null;
|
String sql ="select max_time(n) as ts,last_value(n) as n,last_value(v) as v,last_value(workstation_id) as workstationId from root.f2.process_param_"+workstationId+"_"+item+" where time<"+time+" limit 1 align by device";
|
List<ProcessParameterVO> list = jdbcTemplate.query(sql, new RowMapper<ProcessParameterVO>() {
|
|
@Override
|
public ProcessParameterVO mapRow(ResultSet rs, int rowNum) throws SQLException {
|
ProcessParameterVO p = new ProcessParameterVO();
|
Long time = rs.getLong("ts");
|
p.setRealTime(time);
|
p.setCollectItem(rs.getString("n"));
|
p.setValueCollect(rs.getString("v"));
|
|
return p;
|
}
|
|
});
|
if(!list.isEmpty()) {
|
vo = list.get(0);
|
}
|
return vo;
|
}
|
|
/**
|
* 获取工位最新参数值(采集时间应大于指定时间)
|
* @param workstationId
|
* @param item 参数名称,如DeviceStatus/Output
|
* @param time 指定的时间
|
* @return
|
*/
|
@DS("iotdb")
|
public ProcessParameterVO getLastParameterGreaterThenTime(long workstationId,String item,Long time) {
|
|
|
ProcessParameterVO vo = null;
|
String sql ="select max_time(n) as ts,last_value(n) as n,last_value(v) as v,last_value(workstation_id) as workstationId from root.f2.process_param_"+workstationId+"_"+item+" where time>"+time+" limit 1 align by device";
|
List<ProcessParameterVO> list = jdbcTemplate.query(sql, new RowMapper<ProcessParameterVO>() {
|
|
@Override
|
public ProcessParameterVO mapRow(ResultSet rs, int rowNum) throws SQLException {
|
ProcessParameterVO p = new ProcessParameterVO();
|
p.setRealTime(rs.getLong("ts"));
|
p.setCollectItem(rs.getString("n"));
|
p.setValueCollect(rs.getString("v"));
|
|
return p;
|
}
|
|
});
|
if(!list.isEmpty()) {
|
vo = list.get(0);
|
}
|
return vo;
|
|
|
}
|
|
}
|