Commit e9cbe472 by dxh

[null-null]:空字符串不上报iot

parent 51c36799
package com.jln.system.web.action.mqtt; package com.jln.system.web.action.mqtt;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.serializer.SerializerFeature;
import com.google.gson.JsonObject;
import com.jln.common.utils.EmptyUtil; import com.jln.common.utils.EmptyUtil;
import com.jln.system.web.action.mqtt.pojo.dto.JsonDataDto; import com.jln.system.web.action.mqtt.pojo.dto.JsonDataDto;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -15,7 +12,6 @@ import org.springframework.data.domain.Sort; ...@@ -15,7 +12,6 @@ import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
...@@ -65,58 +61,6 @@ public class Base64decrypt { ...@@ -65,58 +61,6 @@ public class Base64decrypt {
return map; return map;
} }
/* private Map findMongo1(String deviceId,int start,int end) {
int i = (int)Math.ceil((double) start/50);
int j =(int) Math.ceil((double) end/50);
System.out.println();
String tableName = "";
Map map = null;
DateTimeFormatter fmDate = DateTimeFormatter.ofPattern("yyyyMM");
String yearMonth = LocalDate.now().format(fmDate);
for(int x = i; x<=j; x++){
try {
if(x<10){
tableName = deviceId + "0" +x + yearMonth;
}else{
tableName = deviceId + x + yearMonth;
}
//从mongodb查询
Query query = new Query();
query.limit(1);
query.with(Sort.by(
Sort.Order.desc("time")
));
if(x==j){
for (int a=start;a<=end;a++){
query.fields().include("d"+a);
}
}else{
for (int a=start;a<=x*50;a++){
query.fields().include("d"+a);
}
}
query.fields().include("time");
List<JSONObject> objectList = mongoTemplate.find(query, JSONObject.class, tableName);
//mongdb最新数据时间
Long time = Long.valueOf(objectList.get(0).toJavaObject(Map.class).get("time").toString());
//当前时间
long millis = Calendar.getInstance().getTimeInMillis();
//如果当前时间-最新上报数据的时间<设置关机范围,那么直接给
if ((millis - time) < jugeTime && !ObjectUtils.isEmpty(objectList)) {
JSONObject jsonObject = objectList.get(0);
if(!EmptyUtil.isEmpty(map)){
map.putAll(jsonObject.toJavaObject(Map.class));
}else{
map = jsonObject.toJavaObject(Map.class);
}
}
} catch (Exception e) {
return map;
}
}
return map;
}*/
/** /**
* 机器人测试 * 机器人测试
...@@ -149,6 +93,9 @@ public class Base64decrypt { ...@@ -149,6 +93,9 @@ public class Base64decrypt {
Map<String,Object> sites = new HashMap<>(); Map<String,Object> sites = new HashMap<>();
for (Map.Entry<String, Object> stringObjectEntry : objectMap.entrySet()) { for (Map.Entry<String, Object> stringObjectEntry : objectMap.entrySet()) {
Map<String,Object> properites = new HashMap<>(); Map<String,Object> properites = new HashMap<>();
if(EmptyUtil.isEmpty(stringObjectEntry.getValue())){
continue;
}
properites.put(stringObjectEntry.getKey(),stringObjectEntry.getValue()); properites.put(stringObjectEntry.getKey(),stringObjectEntry.getValue());
properites.put("ts",millis); properites.put("ts",millis);
allDto.add(properites); allDto.add(properites);
...@@ -164,12 +111,20 @@ public class Base64decrypt { ...@@ -164,12 +111,20 @@ public class Base64decrypt {
JSONObject jsonObject = JSONObject.parseObject(value); JSONObject jsonObject = JSONObject.parseObject(value);
Map<String,Object> keyValue = new HashMap<>(); Map<String,Object> keyValue = new HashMap<>();
for (Map.Entry<String, Object> objectEntry : jsonObject.entrySet()) { for (Map.Entry<String, Object> objectEntry : jsonObject.entrySet()) {
keyValue.put(String.valueOf(objectEntry.getValue()),mongoMap.get(objectEntry.getValue())==null?"":mongoMap.get(objectEntry.getValue())); Object zhi = mongoMap.get(objectEntry.getValue());
if(zhi==null || zhi.equals("")){
continue;
}
keyValue.put(String.valueOf(objectEntry.getValue()),zhi);
} }
treeMap.put(stringObjectEntry.getKey(),keyValue==null?"":keyValue); treeMap.put(stringObjectEntry.getKey(),keyValue);
}catch (Exception e){ }catch (Exception e){
Map<String,Object> keyValue = new HashMap<>(); Map<String,Object> keyValue = new HashMap<>();
keyValue.put(String.valueOf(stringObjectEntry.getValue()),mongoMap.get(stringObjectEntry.getValue())==null?"":mongoMap.get(stringObjectEntry.getValue())); Object zhi = mongoMap.get(stringObjectEntry.getValue());
if(zhi==null || zhi.equals("")){
continue;
}
keyValue.put(String.valueOf(stringObjectEntry.getValue()),zhi);
keyValue.put("ts",millis); keyValue.put("ts",millis);
allDto.add(keyValue); allDto.add(keyValue);
} }
...@@ -188,11 +143,6 @@ public class Base64decrypt { ...@@ -188,11 +143,6 @@ public class Base64decrypt {
} }
reportDto.put("reported", allDto); reportDto.put("reported", allDto);
JSONObject jsonObj=new JSONObject(reportDto);
String s =jsonObj.toString();
String str = JSONObject.toJSONString(jsonObj, SerializerFeature.WriteMapNullValue);
System.out.println("輸出Json:"+str);
return reportDto; return reportDto;
} }
......
package com.jln.system.web.action.mqtt; package com.jln.system.web.action.mqtt;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.serializer.SerializerFeature;
import com.jln.common.utils.EmptyUtil;
import com.jln.system.web.action.mqtt.pojo.dto.*; import com.jln.system.web.action.mqtt.pojo.dto.*;
import com.jln.system.web.action.mqtt.pojo.vo.StaticData; import com.jln.system.web.action.mqtt.pojo.vo.StaticData;
import com.jln.system.web.action.mqtt.server.EoStatisticsService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -38,9 +35,6 @@ public class MqttStartClient { ...@@ -38,9 +35,6 @@ public class MqttStartClient {
@Autowired @Autowired
private Base64decrypt base64decrypt; private Base64decrypt base64decrypt;
@Autowired
private EoStatisticsService eoStatisticsService;
private static Logger logger = LoggerFactory.getLogger(MqttStartClient.class); private static Logger logger = LoggerFactory.getLogger(MqttStartClient.class);
...@@ -51,15 +45,8 @@ public class MqttStartClient { ...@@ -51,15 +45,8 @@ public class MqttStartClient {
* @return * @return
*/ */
public Integer resolveSk(String skFileUrl) { public Integer resolveSk(String skFileUrl) {
// Map<String, Object> skReportDto = new HashMap<>();
String skFileValue = readSkFileToList(skFileUrl); String skFileValue = readSkFileToList(skFileUrl);
/* if (skFileValue.isEmpty()) {
return skReportDto;
}*/
JSONObject jsonObject = JSONObject.parseObject(skFileValue); JSONObject jsonObject = JSONObject.parseObject(skFileValue);
//skReportDto.put("cmdId", "10");
//skReportDto.put("version", jsonObject.getInteger("version"));
//skReportDto.put("sequenceId", 1);
return jsonObject.getInteger("version"); return jsonObject.getInteger("version");
} }
......
...@@ -4,28 +4,17 @@ import com.alibaba.fastjson.JSONArray; ...@@ -4,28 +4,17 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.jln.common.utils.EmptyUtil; import com.jln.common.utils.EmptyUtil;
import com.jln.system.web.action.mqtt.pojo.dto.JsonDataDto; import com.jln.system.web.action.mqtt.pojo.dto.JsonDataDto;
import com.jln.system.web.action.mqtt.server.SendMqttServer;
import com.jln.system.web.action.mqtt.util.FlieUrlUtil; import com.jln.system.web.action.mqtt.util.FlieUrlUtil;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
//@Component
public class InitHander implements CommandLineRunner { public class InitHander implements CommandLineRunner {
@Autowired
private SendMqttServer sendMqttServer;
@Override @Override
public void run(String... args){ public void run(String... args){
//List<JsonDataDto> jsonDataDtoList = analysisJsonParm();
//sendMqttServer.sendMqtt(jsonDataDtoList);
} }
public List<JsonDataDto> analysisJsonParm(MultipartFile file) throws IOException { public List<JsonDataDto> analysisJsonParm(MultipartFile file) throws IOException {
...@@ -33,10 +22,11 @@ public class InitHander implements CommandLineRunner { ...@@ -33,10 +22,11 @@ public class InitHander implements CommandLineRunner {
String jsonStr = FlieUrlUtil.readJsonField(file); String jsonStr = FlieUrlUtil.readJsonField(file);
//String jsonStr = strJson();//模拟数据 //String jsonStr = strJson();//模拟数据
List<JsonDataDto> jsonDataDtoList = new ArrayList<>(); List<JsonDataDto> jsonDataDtoList = new ArrayList<>();
List<Map<String,Object>> tree = new ArrayList<>();
List<JSONObject> list = JSONObject.parseObject(JSONArray.parseArray(jsonStr).toString(), List.class); List<JSONObject> list = JSONObject.parseObject(JSONArray.parseArray(jsonStr).toString(), List.class);
list.forEach(j->{ list.forEach(j->{
JsonDataDto jsonDataDto = new JsonDataDto(); JsonDataDto jsonDataDto = new JsonDataDto();
List<Map<String,Object>> tree = new ArrayList<>();
List<JSONObject> mongdbTableList= JSONObject.parseObject(j.getJSONObject("reported").getJSONArray("singleField").toString(), List.class); List<JSONObject> mongdbTableList= JSONObject.parseObject(j.getJSONObject("reported").getJSONArray("singleField").toString(), List.class);
jsonDataDto.setCmdId(Integer.parseInt(j.get("cmdId").toString())); jsonDataDto.setCmdId(Integer.parseInt(j.get("cmdId").toString()));
jsonDataDto.setMongdbTableb(j.get("mongdbTableb").toString()); jsonDataDto.setMongdbTableb(j.get("mongdbTableb").toString());
......
...@@ -5,7 +5,6 @@ import com.jln.common.enums.MqttEnum; ...@@ -5,7 +5,6 @@ import com.jln.common.enums.MqttEnum;
import com.jln.system.web.action.mqtt.MqttStartClient; import com.jln.system.web.action.mqtt.MqttStartClient;
import com.jln.system.web.action.mqtt.XBMqttDataUtil; import com.jln.system.web.action.mqtt.XBMqttDataUtil;
import com.jln.system.web.action.mqtt.mapper.ScadaBiMapper; import com.jln.system.web.action.mqtt.mapper.ScadaBiMapper;
import com.jln.system.web.action.mqtt.pojo.dto.JsonDataDto; import com.jln.system.web.action.mqtt.pojo.dto.JsonDataDto;
import com.jln.system.web.action.mqtt.pojo.vo.BldzCclmVo; import com.jln.system.web.action.mqtt.pojo.vo.BldzCclmVo;
import com.jln.system.web.action.mqtt.server.SendMqttServer; import com.jln.system.web.action.mqtt.server.SendMqttServer;
...@@ -13,7 +12,6 @@ import lombok.extern.slf4j.Slf4j; ...@@ -13,7 +12,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
...@@ -113,12 +111,11 @@ public class SendMqttServerImpl implements SendMqttServer { ...@@ -113,12 +111,11 @@ public class SendMqttServerImpl implements SendMqttServer {
while (true) { while (true) {
try { try {
dtoList.forEach(t->{ dtoList.forEach(t->{
//Map<String, String> dongtaishuju = jgqgj("正常数据设备"); Long start = System.currentTimeMillis();
//if (dongtaishuju != null && dongtaishuju.size() > 0) { mqttStartClient.jqr(t, xbMqttDataUtil);
mqttStartClient.jqr(t, xbMqttDataUtil); Long end = System.currentTimeMillis();
//} System.out.println("-----------耗时:------------"+(end-start)/1000);
}); });
Thread.sleep(sleepTime); Thread.sleep(sleepTime);
} catch (InterruptedException e) { } catch (InterruptedException e) {
continue; continue;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论