gis地图接口

This commit is contained in:
wyw
2024-08-12 19:08:17 +08:00
parent d4722842ff
commit 76f1bcaa73
22 changed files with 790 additions and 9 deletions

View File

@ -481,4 +481,25 @@ public class DeviceController extends BaseController
return rspData;
}
/**
* 所有设备点数据
*
* @return
*/
@GetMapping("/devicePointInfo")
@ApiOperation("所有设备点数据")
public AjaxResult devicePointInfo(Device device) {
return AjaxResult.success(deviceService.devicePointInfo(device));
}
/**
* 查询设备历史数据曲线图
*/
@GetMapping("/getDeviceLogAllCurves")
@ApiOperation("查询设备历史数据曲线图")
public AjaxResult getDeviceLogAllCurves(Long deviceId,String beginTime ,String endTime) {
ArrayList<Object> data = deviceService.getDeviceLogAllCurves(deviceId,beginTime ,endTime);
return success(data);
}
}

View File

@ -0,0 +1,48 @@
package com.fastbee.data.controller;
import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.data.service.gis.IGisDeviceService;
import com.fastbee.iot.domain.Device;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "GIS设备")
@RestController
@RequestMapping("/gis/device")
public class GisDeviceController extends BaseController {
@Autowired
private IGisDeviceService gisDeviceService;
/**
* 获取设备数量和列表
*/
@ApiOperation("获取设备数量和列表")
@GetMapping("/totalAndList")
public AjaxResult totalAndList(Device device) {
return AjaxResult.success(gisDeviceService.totalAndList(device));
}
/**
* 根据设备id获取实时数据
*/
@GetMapping(value = "/getRealTimeDataByDevicerId")
public AjaxResult getRealTimeDataByDevicerId(Long deviceId)
{
return success(gisDeviceService.getRealTimeDataByDevicerId(deviceId));
}
/**
* 根据设备id获取流量水量
*/
@GetMapping(value = "/getDeviceLogCurves")
public AjaxResult getDeviceLogCurves(Long deviceId)
{
return success(gisDeviceService.getDeviceLogCurves(deviceId));
}
}

View File

@ -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);
}

View File

@ -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;
}
}