gis地图接口
This commit is contained in:
@ -0,0 +1,13 @@
|
||||
package com.fastbee.data.service.gis;
|
||||
|
||||
import com.fastbee.common.model.vo.iot.GisDeviceListVo;
|
||||
import com.fastbee.iot.domain.Device;
|
||||
|
||||
public interface IGisDeviceService {
|
||||
|
||||
public GisDeviceListVo totalAndList(Device device);
|
||||
|
||||
Object getRealTimeDataByDevicerId(Long deviceId);
|
||||
|
||||
Object getDeviceLogCurves(Long deviceId);
|
||||
}
|
@ -0,0 +1,260 @@
|
||||
package com.fastbee.data.service.gis.impl;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fastbee.common.model.vo.TreeItemVo;
|
||||
import com.fastbee.common.model.vo.iot.GisDeviceListVo;
|
||||
import com.fastbee.common.utils.DateUtils;
|
||||
import com.fastbee.common.utils.SecurityUtils;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.data.service.gis.IGisDeviceService;
|
||||
import com.fastbee.iot.domain.Device;
|
||||
import com.fastbee.iot.domain.DeviceLog;
|
||||
import com.fastbee.iot.domain.Product;
|
||||
import com.fastbee.iot.domain.ThingsModel;
|
||||
import com.fastbee.iot.mapper.DeviceMapper;
|
||||
import com.fastbee.iot.mapper.ProductMapper;
|
||||
import com.fastbee.iot.service.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class GisDeviceServiceImpl implements IGisDeviceService {
|
||||
|
||||
private final DeviceMapper deviceMapper;
|
||||
private final ProductMapper productMapper;
|
||||
|
||||
@Autowired
|
||||
public IDeviceService iDeviceService;
|
||||
@Autowired
|
||||
public IProductService iProductService;
|
||||
@Autowired
|
||||
private IDeviceLogService logService;
|
||||
|
||||
// @Resource
|
||||
// DeviceInfoCacheService deviceInfoCacheService;
|
||||
@Autowired
|
||||
private IAlertService iAlertService;
|
||||
@Autowired
|
||||
private IThingsModelService thingsModelService;
|
||||
|
||||
public GisDeviceServiceImpl(@Qualifier("deviceMapper") DeviceMapper deviceMapper, @Qualifier("productMapper") ProductMapper productMapper) {
|
||||
this.deviceMapper = deviceMapper;
|
||||
this.productMapper = productMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GisDeviceListVo totalAndList(Device device) {
|
||||
List<Product> productEntities = productMapper.selectProductList(new Product());
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
List<TreeItemVo> productContainDeviceListVos = new ArrayList<>();
|
||||
int count = 0;
|
||||
int onLineCount = 0;
|
||||
GisDeviceListVo deviceListVo = new GisDeviceListVo();
|
||||
for (Product productEntity : productEntities) {
|
||||
TreeItemVo treeItemVo = new TreeItemVo();
|
||||
treeItemVo.setId(1000000 + productEntity.getProductId());
|
||||
treeItemVo.setName(productEntity.getProductName());
|
||||
List<Device> deviceEntities = new ArrayList<>();
|
||||
Device deviceEntity = new Device();
|
||||
deviceEntity.setProductId(productEntity.getProductId());
|
||||
deviceEntity.setStatus(device.getStatus());
|
||||
deviceEntity.setDeviceNameOrSerialNumber(device.getDeviceNameOrSerialNumber());
|
||||
if (userId.equals(1L)) {
|
||||
deviceEntities = deviceMapper.selectDeviceListNotUser(deviceEntity);
|
||||
} else {
|
||||
deviceEntities = deviceMapper.selectDeviceList(deviceEntity);
|
||||
}
|
||||
count += deviceEntities.size();
|
||||
List<TreeItemVo> treeItemVoList = new ArrayList<>();
|
||||
for (Device deviceEntity1 : deviceEntities) {
|
||||
TreeItemVo devItem = new TreeItemVo();
|
||||
devItem.setName(deviceEntity1.getDeviceName());
|
||||
devItem.setId(deviceEntity1.getDeviceId());
|
||||
devItem.setStatus(deviceEntity1.getStatus());
|
||||
devItem.setLatitude(deviceEntity1.getLatitude() != null ?deviceEntity1.getLatitude().floatValue():null);
|
||||
devItem.setLongitude(deviceEntity1.getLongitude()!= null ?deviceEntity1.getLongitude().floatValue():null);
|
||||
treeItemVoList.add(devItem);
|
||||
if (deviceEntity1.getStatus() == 3) {
|
||||
onLineCount++;
|
||||
}
|
||||
}
|
||||
treeItemVo.setChildren(treeItemVoList);
|
||||
productContainDeviceListVos.add(treeItemVo);
|
||||
}
|
||||
deviceListVo.setProductContainDeviceList(productContainDeviceListVos);
|
||||
deviceListVo.setCount(count);
|
||||
deviceListVo.setOnLineCount(onLineCount);
|
||||
return deviceListVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRealTimeDataByDevicerId(Long deviceId) {
|
||||
HashMap<String, Object> rMap = new HashMap<String, Object>() {
|
||||
};
|
||||
if (deviceId == null) {
|
||||
throw new RuntimeException("请上传devicerId");
|
||||
}
|
||||
Device device = iDeviceService.selectDeviceByDeviceId(deviceId);
|
||||
if (device == null) {
|
||||
throw new RuntimeException("未查到该设备");
|
||||
}
|
||||
ThingsModel thingsModel1 = new ThingsModel();
|
||||
thingsModel1.setProductId(device.getProductId());
|
||||
List<ThingsModel> thingsModelEntities = thingsModelService.selectThingsModelList(thingsModel1);
|
||||
// List<ThingsModelValueItem> thingsModelValueItems = deviceInfoCacheService.getDeviceInfoCache(device.getDeviceId());
|
||||
// List<ThingsModelValueItem> thingsModelValueItems = deviceInfoCacheService.getCacheDeviceStatus(device.getProductId(),
|
||||
// device.getSerialNumber());
|
||||
DateTime dateTime = DateUtil.date(new Date());
|
||||
List<DeviceLog> deviceLogsAll = new ArrayList<>();
|
||||
List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
|
||||
setSerialNumber(device.getSerialNumber());
|
||||
setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
|
||||
setEndTime(DateUtil.endOfDay(dateTime).toString());
|
||||
}});
|
||||
if (deviceLogs != null) {
|
||||
deviceLogsAll.addAll(deviceLogs);
|
||||
}
|
||||
|
||||
Map<String, List<DeviceLog>> collect = deviceLogsAll.stream().sorted(Comparator
|
||||
.comparing(DeviceLog::getCreateTime, Comparator
|
||||
.nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
|
||||
for (ThingsModel thingsModel : thingsModelEntities) {
|
||||
HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
|
||||
put("upType", 0);
|
||||
put("identifier", thingsModel.getIdentifier());
|
||||
put("unit", "");
|
||||
put("value", 0);
|
||||
put("name", thingsModel.getModelName());
|
||||
}};
|
||||
// {"max": 100, "min": 0, "step": 1, "type": "decimal", "unit": "m/s"}
|
||||
if(StringUtils.isNotEmpty(thingsModel.getSpecs())){
|
||||
String specs = thingsModel.getSpecs();
|
||||
JSONObject parse = (JSONObject) JSON.parse(specs);
|
||||
if(parse.containsKey("unit")){
|
||||
hashMap.put("unit", parse.get("unit"));
|
||||
}
|
||||
}
|
||||
|
||||
if (hashMap.size() > 1) {
|
||||
List<DeviceLog> deviceLogs1 = collect.get(thingsModel.getIdentifier());
|
||||
if (deviceLogs1 != null) {
|
||||
if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) == Float.parseFloat(deviceLogs1.get(1).getLogValue()))
|
||||
{
|
||||
hashMap.put("upType", 1);
|
||||
} else if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) < Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
|
||||
hashMap.put("upType", -1);
|
||||
}
|
||||
hashMap.put("value", deviceLogs1.get(0).getLogValue());
|
||||
}
|
||||
} else if (hashMap.size() > 0) {
|
||||
List<DeviceLog> deviceLogs2 = collect.get(thingsModel.getIdentifier());
|
||||
if (deviceLogs2 != null) {
|
||||
hashMap.put("value", deviceLogs2.get(0).getLogValue());
|
||||
}
|
||||
}
|
||||
rMap.put(thingsModel.getIdentifier(), hashMap);
|
||||
}
|
||||
return rMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDeviceLogCurves(Long deviceId) {
|
||||
if (deviceId == null) {
|
||||
throw new RuntimeException("请上传deviceId");
|
||||
}
|
||||
|
||||
Device device = iDeviceService.selectDeviceByDeviceId(deviceId);
|
||||
if (device == null) {
|
||||
throw new RuntimeException("未查到该设备");
|
||||
}
|
||||
// List<AlertEntity> alertList = getAlertListForDevice(deviceId, device.getProductId());
|
||||
// List<DeviceAlertDto> waterLevelAlert = new ArrayList<>();
|
||||
// List<DeviceAlertDto> rainfallAlert = new ArrayList<>();
|
||||
//
|
||||
// if (!alertList.isEmpty()) {
|
||||
// alertList.forEach(alert -> parseAlert(alert, waterLevelAlert, rainfallAlert));
|
||||
// }
|
||||
Map<String, Object> sumFlow = getDataList(device, "dataSumFlow");
|
||||
Map<String, Object> insFlow = getDataList(device, "dataInsFlow");
|
||||
Map<String, Object> rMap = new HashMap<>();
|
||||
rMap.put("time", insFlow.get("time"));
|
||||
rMap.put("sumFlow", sumFlow.get("data"));
|
||||
rMap.put("insFlow", insFlow.get("data"));
|
||||
// rMap.put("sumFlowAlert", waterLevelAlert);
|
||||
// rMap.put("insFlowAlert", rainfallAlert);
|
||||
return rMap;
|
||||
}
|
||||
|
||||
// private List<AlertEntity> getAlertListForDevice(Long deviceId, Long productId) {
|
||||
// AlertEntity alert = new AlertEntity();
|
||||
// alert.setDeviceId(deviceId);
|
||||
// alert.setProductId(productId);
|
||||
// return iAlertService.selectAlertList(alert);
|
||||
// }
|
||||
|
||||
// private void parseAlert(AlertEntity alert, List<DeviceAlertDto> waterLevelAlert, List<DeviceAlertDto> rainfallAlert) {
|
||||
// JSONArray triggers = JSON.parseArray(alert.getTriggers());
|
||||
// for (Object obj : triggers) {
|
||||
// Map<String, Object> trigger = (Map<String, Object>) obj;
|
||||
// Float value = Float.valueOf(trigger.get("value").toString());
|
||||
// if (alert.getAlertType() == 1) {
|
||||
// waterLevelAlert.add(new DeviceAlertDto(alert.getAlertName(), "#FF0000", value));
|
||||
// } else if (alert.getAlertType() == 2) {
|
||||
// rainfallAlert.add(new DeviceAlertDto(alert.getAlertName(), "#FFFF00", value));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private HashMap<String, Object> getDataList(Device device, String identity) {
|
||||
HashMap<String, Object> dataListMap = new HashMap<>();
|
||||
HashMap<String, Object> kvHashMap = new HashMap<>();
|
||||
kvHashMap.put("identity", identity);
|
||||
kvHashMap.put("serialNumber", device.getSerialNumber());
|
||||
Date endTime = new Date();
|
||||
kvHashMap.put("endTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,endTime));
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
calendar.add(Calendar.HOUR,-23);
|
||||
kvHashMap.put("beginTime",DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH,calendar.getTime())+":00:00");
|
||||
List<HashMap<String, Object>> reMap = logService.selectDayData(kvHashMap);
|
||||
Map<String, Map<String, Object>> create_time = new HashMap<>();
|
||||
if (reMap != null) {
|
||||
create_time = reMap.stream().collect(Collectors.toMap(t -> {
|
||||
return DateUtil.date((LocalDateTime) t.get("create_time")).toString("HH");
|
||||
}, t -> t, (t, t1) -> t1));
|
||||
}
|
||||
DateTime date = DateUtil.date();
|
||||
ArrayList<Object> jiangyvliang = new ArrayList<>();
|
||||
ArrayList<Object> time = new ArrayList<>();
|
||||
dataListMap.put("time", time);
|
||||
dataListMap.put("data", jiangyvliang);
|
||||
for (int i = 0; i < 24; i++) {
|
||||
String s = DateUtil.offsetHour(DateUtil.offsetHour(date, -23), i).toString("HH");
|
||||
time.add(s);
|
||||
Map<String, Object> map = create_time.get(s);
|
||||
if (map != null) {
|
||||
if(identity.equals("dataSumFlow")){
|
||||
jiangyvliang.add(Float.parseFloat(create_time.get(s).get("maxLogValue").toString())
|
||||
- Float.parseFloat(create_time.get(s).get("minLogValue").toString()));
|
||||
}else{
|
||||
jiangyvliang.add(create_time.get(s).get("avgLogValue"));
|
||||
}
|
||||
} else {
|
||||
jiangyvliang.add(0);
|
||||
}
|
||||
}
|
||||
return dataListMap;
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user