增加电压、温度等推送

This commit is contained in:
weidong 2024-06-28 11:18:48 +08:00
parent e651f0ed12
commit e7cdb46ff2
3 changed files with 38 additions and 5 deletions

View File

@ -35,12 +35,20 @@ public class KingMaData {
Data data1; Data data1;
Data data2; Data data2;
Data data3; Data data3;
Data data4;
Data data5;
Data data6;
public Phys(Double e, Double n, Double d){ public Phys(Double e, Double n, Double d){
data1 = new Data("data1","mm",e); data1 = new Data("data1","mm",e);
data2 = new Data("data2","mm",n); data2 = new Data("data2","mm",n);
data3 = new Data("data3","mm",d); data3 = new Data("data3","mm",d);
} }
public void setSensorData(Double voltage, Double rssi, Double temperature){
data4 = new Data("data4","V",voltage);
data5 = new Data("data5","dB",rssi);
data6 = new Data("data6","°C",temperature);
}
} }
} }

View File

@ -25,7 +25,7 @@ public class Forwarder {
int totalSendNum = 0; int totalSendNum = 0;
int fwdCycleMinutes = 30; int fwdCycleMinutes = 30;
static boolean isFwdTableInit = false; static boolean isFwdTableInit = true;//false;
@Autowired @Autowired
private GnssDeviceMapper deviceMapper; private GnssDeviceMapper deviceMapper;

View File

@ -1,13 +1,13 @@
package com.imdroid.beidou_fwd.task; package com.imdroid.beidou_fwd.task;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.imdroid.beidou_fwd.entity.KingMaData; import com.imdroid.beidou_fwd.entity.KingMaData;
import com.imdroid.common.util.GsonUtil; import com.imdroid.common.util.GsonUtil;
import com.imdroid.common.util.HttpUtils; import com.imdroid.common.util.HttpUtils;
import com.imdroid.common.util.NumberUtils; import com.imdroid.common.util.NumberUtils;
import com.imdroid.secapi.dto.*; import com.imdroid.secapi.dto.*;
import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
@ -40,6 +40,9 @@ public class KingMaForwarder extends Forwarder{
Map<String, String> header; Map<String, String> header;
LocalDateTime lastTokenTime = LocalDateTime.now(); LocalDateTime lastTokenTime = LocalDateTime.now();
@Autowired
GnssStatusMsgMapper statusMsgMapper;
@PostConstruct @PostConstruct
void registerMe(){ void registerMe(){
init(FORWARDER_NAME, data_host,3,true,60); init(FORWARDER_NAME, data_host,3,true,60);
@ -47,7 +50,8 @@ public class KingMaForwarder extends Forwarder{
/** /**
* 每半小时转发GNSS解算结果 * 每半小时转发GNSS解算结果
*/ */
@Scheduled(cron = "0 0 0/1 * * ?") // 每小时执行一次 //@Scheduled(cron = "0 0 0/1 * * ?") // 每小时执行一次
@Scheduled(cron = "0 0/5 * * * ?") // 每30分钟执行一次
private void forwardGnss() { private void forwardGnss() {
logger.info("kingma forwardGnss"); logger.info("kingma forwardGnss");
forwardCurrentGnss(); forwardCurrentGnss();
@ -93,6 +97,15 @@ public class KingMaForwarder extends Forwarder{
lastTokenTime = nowTime; lastTokenTime = nowTime;
} }
// 获取最近一小时的状态消息
// 获取温湿度
QueryWrapper<GnssStatusMsg> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("tenantid",tenantId);
queryWrapper.le("createtime",sentTime);
queryWrapper.ge("createtime",sentTime.minusMinutes(fwdCycleMinutes));
queryWrapper.orderByDesc("createtime");
List<GnssStatusMsg> statusMsgs = statusMsgMapper.selectList(queryWrapper);
List<KingMaData> dataList = new ArrayList<>(records.size()); List<KingMaData> dataList = new ArrayList<>(records.size());
for(GnssCalcData locationRecord: records) { for(GnssCalcData locationRecord: records) {
@ -105,18 +118,30 @@ public class KingMaForwarder extends Forwarder{
NumberUtils.scale(locationRecord.getRpose(), 2), NumberUtils.scale(locationRecord.getRpose(), 2),
NumberUtils.scale(locationRecord.getRposn(), 2), NumberUtils.scale(locationRecord.getRposn(), 2),
NumberUtils.scale(locationRecord.getRposd(), 2))); NumberUtils.scale(locationRecord.getRposd(), 2)));
for(GnssStatusMsg msg:statusMsgs){
if(msg.getDeviceid().equals(locationRecord.getDeviceid())){
if(msg.getVoltage()!=null && msg.getRssi()!=null && msg.getTemperature()!=null) {
data.getPhys().setSensorData(
NumberUtils.scale((double) (msg.getVoltage() / 1000), 1),
NumberUtils.scale((double) (msg.getRssi()), 0),
NumberUtils.scale((double) (msg.getTemperature()), 1));
}
break;
}
}
dataList.add(data); dataList.add(data);
sendNum++; sendNum++;
} }
String json = GsonUtil.toJson(dataList); String json = GsonUtil.toJson(dataList);
logger.info(json);
String result = HttpUtils.postJson(data_host,header,json); String result = HttpUtils.postJson(data_host,header,json);
logger.info("project " + projectId + ": push calculation result to Kingma"); logger.info("project " + projectId + ": push calculation result to Kingma");
logger.info(json);
logger.info("result: "+result); logger.info("result: "+result);
JSONObject obj = (JSONObject) JSONObject.parse(result); JSONObject obj = (JSONObject) JSONObject.parse(result);
String msg = obj.getString("message"); String msg = obj.getString("message");
if(msg.equals("Success")) return sendNum; if(msg.equals("Success")) return sendNum;
else return 0; else return 0;
//return sendNum;
} }
} }