适配乌班图新数据格式

This commit is contained in:
zhangyue 2026-05-28 10:44:11 +08:00
parent 3d3e03513a
commit 77602032ab
1 changed files with 9 additions and 2 deletions

View File

@ -71,6 +71,7 @@ public class LhIotUtil {
public static WaterCommonTransVo transData(List<ScEquZhibiao> zhibiaoList, String mqttMessage) { public static WaterCommonTransVo transData(List<ScEquZhibiao> zhibiaoList, String mqttMessage) {
WaterCommonTransVo waterCommonTransVo = new WaterCommonTransVo(); WaterCommonTransVo waterCommonTransVo = new WaterCommonTransVo();
ResponseCmd responseCmd = JSONObject.parseObject(mqttMessage,ResponseCmd.class); ResponseCmd responseCmd = JSONObject.parseObject(mqttMessage,ResponseCmd.class);
int counts = 0; //计数器如果没有任何监测项与配置匹配则放弃此数据
if(responseCmd!=null){ if(responseCmd!=null){
if(responseCmd.getRw_prot()!=null){ if(responseCmd.getRw_prot()!=null){
if("rsp".equals(responseCmd.getRw_prot().getDir())) { if("rsp".equals(responseCmd.getRw_prot().getDir())) {
@ -79,21 +80,23 @@ public class LhIotUtil {
for (ScEquZhibiao scEquZhibiao : zhibiaoList) { for (ScEquZhibiao scEquZhibiao : zhibiaoList) {
eleMap.put(scEquZhibiao.getCode(), scEquZhibiao.getEntityField()); eleMap.put(scEquZhibiao.getCode(), scEquZhibiao.getEntityField());
} }
if (responseCmd.getRw_prot().getR_data()!=null && !responseCmd.getRw_prot().getR_data().isEmpty()) {
if (!responseCmd.getRw_prot().getR_data().isEmpty()) {
//因为数据中不包含时间所以使用当前时间 //因为数据中不包含时间所以使用当前时间
waterCommonTransVo.setDataDateTime(LocalDateTime.now()); waterCommonTransVo.setDataDateTime(LocalDateTime.now());
waterCommonTransVo.setDataGatherType(IotConstants.MARK_REALDATA); waterCommonTransVo.setDataGatherType(IotConstants.MARK_REALDATA);
for (ResponseCmdData rDatum : responseCmd.getRw_prot().getR_data()) { for (ResponseCmdData rDatum : responseCmd.getRw_prot().getR_data()) {
String entityName = eleMap.get(rDatum.getName());//字段名称 String entityName = eleMap.get(rDatum.getName());//字段名称
if (StringUtils.isNotBlank(entityName)) { if (StringUtils.isNotBlank(entityName)) {
TUtil.setFieldValue(waterCommonTransVo, entityName, rDatum.getValue()); TUtil.setFieldValue(waterCommonTransVo, entityName, rDatum.getValue());
counts++;
} else { } else {
log.error("指令:{}----未匹配到监测项目:{}", mqttMessage, rDatum.getName()); log.error("指令:{}----未匹配到监测项目:{}", mqttMessage, rDatum.getName());
} }
} }
} }
} }
log.warn("{}-----------指令解析结果=============={}",mqttMessage,JSONObject.toJSONString(waterCommonTransVo)); log.warn("{}-----------指令解析结果=============={}",mqttMessage,JSONObject.toJSONString(waterCommonTransVo));
}else{ }else{
log.error("----非主动请求数据,跳过解析==============回执:{}",mqttMessage); log.error("----非主动请求数据,跳过解析==============回执:{}",mqttMessage);
@ -104,6 +107,10 @@ public class LhIotUtil {
}else{ }else{
log.error("xxxxxxxxxxxxx解析失败回执格式有误1xxxxxxxxxxxxx"); log.error("xxxxxxxxxxxxx解析失败回执格式有误1xxxxxxxxxxxxx");
} }
if(counts==0){
log.error("xxxxxxxxxx未匹配到监测项丢弃此数据{}xxxxxxxxxxxxxxx",mqttMessage);
return null;
}
return waterCommonTransVo; return waterCommonTransVo;
} }
} }