|
@@ -1,152 +0,0 @@
|
|
|
-package com.yunfeiyun.agmp.iots.service.impl;
|
|
|
|
|
-
|
|
|
|
|
-import com.yunfeiyun.agmp.common.utils.DateUtils;
|
|
|
|
|
-import com.yunfeiyun.agmp.iot.common.domain.IotDevGeoPoint;
|
|
|
|
|
-import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
|
|
|
|
|
-import com.yunfeiyun.agmp.iot.common.domain.IotDeviceGeoLocation;
|
|
|
|
|
-import com.yunfeiyun.agmp.iot.common.domain.dto.MgUpdateBatchDto;
|
|
|
|
|
-import com.yunfeiyun.agmp.iot.common.service.MongoService;
|
|
|
|
|
-import com.yunfeiyun.agmp.iot.common.util.BigDecimalUtil;
|
|
|
|
|
-import com.yunfeiyun.agmp.iots.service.IotDeviceGeoLocationService;
|
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
-import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
|
|
-import org.springframework.data.mongodb.core.query.Query;
|
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
|
-
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
-
|
|
|
|
|
-@Service
|
|
|
|
|
-public class IotDeviceGeoLocationServiceImpl implements IotDeviceGeoLocationService {
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private MongoService mongoService;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 插入或更新数据
|
|
|
|
|
- */
|
|
|
|
|
- @Override
|
|
|
|
|
- public void insertBatchData(List<IotDeviceGeoLocation> dataList) {
|
|
|
|
|
- if(!dataList.isEmpty()) {
|
|
|
|
|
- mongoService.insertList(IotDeviceGeoLocation.class, dataList);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 更新数据
|
|
|
|
|
- *
|
|
|
|
|
- * @param dataList
|
|
|
|
|
- */
|
|
|
|
|
- @Override
|
|
|
|
|
- public void updateBatchData(List<IotDeviceGeoLocation> dataList) {
|
|
|
|
|
- List<MgUpdateBatchDto> updateBatchDtoList = new ArrayList<>();
|
|
|
|
|
- for(IotDeviceGeoLocation item : dataList) {
|
|
|
|
|
- String devGeoBid = item.getDevGeoBid();
|
|
|
|
|
- IotDevGeoPoint geoPoint = item.getDevGeoLocation();
|
|
|
|
|
- String devGeoUpdateddate = DateUtils.dateTimeNow();
|
|
|
|
|
- String devtypeBid = item.getDevtypeBid();
|
|
|
|
|
-
|
|
|
|
|
- Query query = new Query(Criteria.where("devGeoBid").is(devGeoBid));
|
|
|
|
|
- Map<String, Object> updateField = new HashMap<>();
|
|
|
|
|
- updateField.put("devGeoUpdateddate", devGeoUpdateddate);
|
|
|
|
|
- updateField.put("devtypeBid", devtypeBid);
|
|
|
|
|
- updateField.put("devGeoLocation", geoPoint);
|
|
|
|
|
-
|
|
|
|
|
- MgUpdateBatchDto updateBatchDto = new MgUpdateBatchDto();
|
|
|
|
|
- updateBatchDto.setQuery(query);
|
|
|
|
|
- updateBatchDto.setUpdateField(updateField);
|
|
|
|
|
- updateBatchDtoList.add(updateBatchDto);
|
|
|
|
|
- }
|
|
|
|
|
- if(!updateBatchDtoList.isEmpty()) {
|
|
|
|
|
- mongoService.updateBatch(IotDeviceGeoLocation.class, updateBatchDtoList);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void insertOrUpdateBatchData(List<IotDevice> iotDeviceList) {
|
|
|
|
|
- List<String> devBidList = new ArrayList<>();
|
|
|
|
|
- for(IotDevice iotDevice : iotDeviceList) {
|
|
|
|
|
- BigDecimal devLng = iotDevice.getDevLngalign();
|
|
|
|
|
- BigDecimal devLat = iotDevice.getDevLatalign();
|
|
|
|
|
- if(devLng == null || devLat == null) {
|
|
|
|
|
- devLng = iotDevice.getDevLng();
|
|
|
|
|
- devLat = iotDevice.getDevLat();
|
|
|
|
|
- }
|
|
|
|
|
- if (devLng == null || devLat == null){
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- String devBid = iotDevice.getDevBid();
|
|
|
|
|
- devBidList.add(devBid);
|
|
|
|
|
- }
|
|
|
|
|
- Map<String, IotDeviceGeoLocation> iotDeviceGeoLocationMap = new HashMap<>();
|
|
|
|
|
- if(!devBidList.isEmpty()) {
|
|
|
|
|
- List<IotDeviceGeoLocation> iotDeviceGeoLocationList = selectByDevBidList(devBidList);
|
|
|
|
|
- for(IotDeviceGeoLocation iotDeviceGeoLocation : iotDeviceGeoLocationList) {
|
|
|
|
|
- iotDeviceGeoLocationMap.put(iotDeviceGeoLocation.getDevBid(), iotDeviceGeoLocation);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- List<IotDeviceGeoLocation> updateList = new ArrayList<>();
|
|
|
|
|
- List<IotDeviceGeoLocation> insertList = new ArrayList<>();
|
|
|
|
|
- for(IotDevice iotDevice : iotDeviceList) {
|
|
|
|
|
- BigDecimal devLng = iotDevice.getDevLngalign();
|
|
|
|
|
- BigDecimal devLat = iotDevice.getDevLatalign();
|
|
|
|
|
- if(devLng == null || devLat == null) {
|
|
|
|
|
- devLng = iotDevice.getDevLng();
|
|
|
|
|
- devLat = iotDevice.getDevLat();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- String devBid = iotDevice.getDevBid();
|
|
|
|
|
- IotDeviceGeoLocation iotDeviceGeoLocation = iotDeviceGeoLocationMap.get(devBid);
|
|
|
|
|
- if (iotDeviceGeoLocation == null) {
|
|
|
|
|
- iotDeviceGeoLocation = new IotDeviceGeoLocation();
|
|
|
|
|
- iotDeviceGeoLocation.setDevGeoBid(iotDeviceGeoLocation.getUUId());
|
|
|
|
|
- iotDeviceGeoLocation.setTid(iotDevice.getTid());
|
|
|
|
|
- iotDeviceGeoLocation.setDevBid(devBid);
|
|
|
|
|
- iotDeviceGeoLocation.setDevtypeBid(iotDevice.getDevtypeBid());
|
|
|
|
|
- iotDeviceGeoLocation.setDevGeoCreateddate(DateUtils.dateTimeNow());
|
|
|
|
|
- iotDeviceGeoLocation.setDevGeoUpdateddate(DateUtils.dateTimeNow());
|
|
|
|
|
- IotDevGeoPoint geoPoint = new IotDevGeoPoint();
|
|
|
|
|
- geoPoint.setType("Point");
|
|
|
|
|
-
|
|
|
|
|
- double[] coordinates = new double[2];
|
|
|
|
|
- coordinates[0] = BigDecimalUtil.toDouble(devLng);
|
|
|
|
|
- coordinates[1] = BigDecimalUtil.toDouble(devLat);
|
|
|
|
|
- geoPoint.setCoordinates(coordinates);
|
|
|
|
|
- iotDeviceGeoLocation.setDevGeoLocation(geoPoint);
|
|
|
|
|
-
|
|
|
|
|
- insertList.add(iotDeviceGeoLocation);
|
|
|
|
|
- }else{
|
|
|
|
|
- double[] coordinates = iotDeviceGeoLocation.getDevGeoLocation().getCoordinates();
|
|
|
|
|
- BigDecimal devLngOld = BigDecimalUtil.format(coordinates[0]);
|
|
|
|
|
- BigDecimal devLatOld = BigDecimalUtil.format(coordinates[1]);
|
|
|
|
|
- if(!devLng.equals(devLngOld) || !devLat.equals(devLatOld)) {
|
|
|
|
|
- coordinates[0] = BigDecimalUtil.toDouble(devLng);
|
|
|
|
|
- coordinates[1] = BigDecimalUtil.toDouble(devLat);
|
|
|
|
|
-
|
|
|
|
|
- iotDeviceGeoLocation.getDevGeoLocation().setCoordinates(coordinates);
|
|
|
|
|
- iotDeviceGeoLocation.setDevGeoUpdateddate(DateUtils.dateTimeNow());
|
|
|
|
|
- iotDeviceGeoLocation.setDevtypeBid(iotDevice.getDevtypeBid());
|
|
|
|
|
-
|
|
|
|
|
- updateList.add(iotDeviceGeoLocation);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if(!updateList.isEmpty()) {
|
|
|
|
|
- updateBatchData(updateList);
|
|
|
|
|
- }
|
|
|
|
|
- if(!insertList.isEmpty()) {
|
|
|
|
|
- insertBatchData(insertList);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public List<IotDeviceGeoLocation> selectByDevBidList(List<String> devBidList) {
|
|
|
|
|
- Map<String, Object> params = new HashMap<>();
|
|
|
|
|
- params.put("list_devBid", devBidList);
|
|
|
|
|
- return mongoService.findAll(IotDeviceGeoLocation.class, null);
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|