|
@@ -2,14 +2,13 @@ package com.zcxk.smartcity.data.access.service.impl;
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import com.zcxk.smartcity.data.access.common.CommonConstant;
|
|
|
+import com.zcxk.smartcity.data.access.dto.DeviceData;
|
|
|
import com.zcxk.smartcity.data.access.rabbitmq.WaterMeterDataSender;
|
|
|
+import com.zcxk.smartcity.data.access.repository.DeviceDataRepository;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.logging.Log;
|
|
@@ -112,6 +111,9 @@ public class DeviceDataServiceImpl implements DeviceDataService {
|
|
|
@Resource
|
|
|
WaterMeterDataSender waterMeterDataSender ;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ DeviceDataRepository deviceDataRepository ;
|
|
|
+
|
|
|
@Override
|
|
|
public int savaDeviceData(Device device, DeviceDataBase srcData, ProtocolData data) {
|
|
|
log.info(
|
|
@@ -557,6 +559,15 @@ public class DeviceDataServiceImpl implements DeviceDataService {
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
+ // 将数据保存到MongoDB中
|
|
|
+ try{
|
|
|
+ // 构建DeviceData对象
|
|
|
+ DeviceData deviceData = buildDeviceData(device, dataMap, receiveTime);
|
|
|
+ deviceDataRepository.save(deviceData);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("Device data save mongo failed !",e);
|
|
|
+ }
|
|
|
// 2,判断设备是否水表,如果是水表则保存读数
|
|
|
if(device.getIsWater() == 1) {
|
|
|
// 如果是水表数据则继续将数据发送到抄表队列供抄表服务进行抄表 2020/12/25
|
|
@@ -589,6 +600,37 @@ public class DeviceDataServiceImpl implements DeviceDataService {
|
|
|
return i;
|
|
|
}
|
|
|
|
|
|
+ protected DeviceData buildDeviceData(Device device, Map<String, MeasuringData> dataMap, String receiveTime){
|
|
|
+ DeviceData deviceData = new DeviceData();
|
|
|
+ deviceData.setChannelId(device.getSysId());
|
|
|
+ deviceData.setCommunityId(device.getCommunityId());
|
|
|
+ deviceData.setCustomerId(device.getCustomerId());
|
|
|
+ deviceData.setDateCreate(LocalDateTime.now());
|
|
|
+ deviceData.setDeviceId(device.getId());
|
|
|
+ deviceData.setDeviceNo(device.getDeviceNo());
|
|
|
+ deviceData.setDeviceTypeId(device.getDeviceType());
|
|
|
+ deviceData.setId(idWorker.nextId());
|
|
|
+ deviceData.setLocation(device.getLocDesc());
|
|
|
+ deviceData.setManufacturerId(device.getManufacturerId());
|
|
|
+ deviceData.setReceiveDate(Integer.parseInt(receiveTime.substring(0, 8)));
|
|
|
+ deviceData.setReceiveTime(parserDate(receiveTime));
|
|
|
+ deviceData.setSiteId(device.getSiteId());
|
|
|
+ deviceData.setStatus(1);
|
|
|
+ deviceData.setData(getDeviceMeasuringValueMap(dataMap));
|
|
|
+ deviceData.setBuildingId(device.getBuildingId());
|
|
|
+ return deviceData ;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Map<String,String> getDeviceMeasuringValueMap(Map<String, MeasuringData> dataMap){
|
|
|
+ Map<String,String> measuringValueMap = new HashMap<>(dataMap.size());
|
|
|
+ Iterator<Map.Entry<String, MeasuringData>> iterator = dataMap.entrySet().iterator();
|
|
|
+ while(iterator.hasNext()){
|
|
|
+ Map.Entry<String, MeasuringData> next = iterator.next();
|
|
|
+ measuringValueMap.put(next.getValue().getMeasuringCode(),next.getValue().getMeasuringVaule());
|
|
|
+ }
|
|
|
+ return measuringValueMap ;
|
|
|
+ }
|
|
|
+
|
|
|
protected Map<String, MeasuringData> measuringDataListToMap(List<MeasuringData> measuringDataList) {
|
|
|
Map<String, MeasuringData> map = new HashMap<String, MeasuringData>(measuringDataList.size());
|
|
|
for (MeasuringData data : measuringDataList) {
|