|
|
|
@ -9,11 +9,11 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
public class FormatUtil {
|
|
|
|
|
|
|
|
|
|
public static String mqttFormatTransform(List<Map<String,Object>> list, Map<String,String> fieldMap){
|
|
|
|
|
public static String mqttFormatTransform(List<Map<String, Object>> list, Map<String, String> fieldMap) {
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
|
|
|
|
Map<String,Object> resultMap = new HashMap<String,Object>(){{
|
|
|
|
|
put("AssetList",list.stream().map(e -> recordTransform(e,fieldMap)).collect(Collectors.toList()));
|
|
|
|
|
Map<String, Object> resultMap = new HashMap<String, Object>() {{
|
|
|
|
|
put("AssetList", list.stream().map(e -> recordTransform(e, fieldMap)).collect(Collectors.toList()));
|
|
|
|
|
}};
|
|
|
|
|
|
|
|
|
|
String jsonString = null;
|
|
|
|
@ -25,25 +25,24 @@ public class FormatUtil {
|
|
|
|
|
return jsonString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Map<String,Object> recordTransform(Map<String, Object> record, Map<String, String> fieldMap){
|
|
|
|
|
Map<String,Object> mqttRecord = new TreeMap<>();
|
|
|
|
|
List<Map<String,Object>> attribuiteList = new ArrayList<>();
|
|
|
|
|
for(String key : record.keySet()){
|
|
|
|
|
if(fieldMap.containsKey(key)){
|
|
|
|
|
attribuiteList.add(new HashMap<String,Object>(){{
|
|
|
|
|
public static Map<String, Object> recordTransform(Map<String, Object> record, Map<String, String> fieldMap) {
|
|
|
|
|
Map<String, Object> mqttRecord = new TreeMap<>();
|
|
|
|
|
List<Map<String, Object>> attribuiteList = new ArrayList<>();
|
|
|
|
|
for (String key : record.keySet()) {
|
|
|
|
|
if (fieldMap.containsKey(key)) {
|
|
|
|
|
attribuiteList.add(new HashMap<String, Object>() {{
|
|
|
|
|
put("AttributeCode", fieldMap.get(key));
|
|
|
|
|
put("DataValue",record.get(key));
|
|
|
|
|
put("DataValue", record.get(key));
|
|
|
|
|
}});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mqttRecord.put("AssetCode",record.get("sensorid"));
|
|
|
|
|
mqttRecord.put("AttributeList",attribuiteList);
|
|
|
|
|
String captureTime = record.get("d_time") !=null ? record.get("d_time").toString() : (String) record.get("capturetime").toString();
|
|
|
|
|
mqttRecord.put("Timestamp",Timestamp.valueOf(captureTime).getTime());
|
|
|
|
|
mqttRecord.put("AssetCode", record.get("sensorid"));
|
|
|
|
|
mqttRecord.put("AttributeList", attribuiteList);
|
|
|
|
|
String captureTime = record.get("d_time") != null ? record.get("d_time").toString() : (String) record.get("capturetime").toString();
|
|
|
|
|
mqttRecord.put("Timestamp", Timestamp.valueOf(captureTime).getTime());
|
|
|
|
|
|
|
|
|
|
return mqttRecord;
|
|
|
|
|
return mqttRecord;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|