package com.ruoyi.http.service.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.device.pojo.DeviceLedger;
|
import com.ruoyi.device.service.IDeviceLedgerService;
|
import com.ruoyi.framework.web.controller.BaseController;
|
import com.ruoyi.framework.web.domain.AjaxResult;
|
import com.ruoyi.http.service.impl.RealTimeEnergyConsumptionServiceImpl;
|
import io.swagger.annotations.Api;
|
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.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.ArrayList;
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
@RestController
|
@RequestMapping("/iot")
|
@Api(tags = "数采接口")
|
public class JclyController extends BaseController {
|
|
@Autowired
|
private RealTimeEnergyConsumptionServiceImpl realTimeEnergyConsumptionService;
|
|
@Autowired
|
private IDeviceLedgerService deviceLedgerService;
|
|
/**
|
* 实时获取温湿度,二氧化碳数据
|
*/
|
@GetMapping("/getRealData")
|
public AjaxResult getRealData() {
|
List<DeviceLedger> iotDevices = deviceLedgerService.list(new LambdaQueryWrapper<DeviceLedger>()
|
.eq(DeviceLedger::getIsIotDevice, 1)
|
.isNotNull(DeviceLedger::getExternalCode)
|
.ne(DeviceLedger::getExternalCode, ""));
|
|
Map<String, String> guidDeviceNameMap = iotDevices.stream()
|
.filter(item -> StringUtils.isNotEmpty(item.getExternalCode()))
|
.collect(Collectors.toMap(
|
item -> item.getExternalCode().trim(),
|
item -> StringUtils.isNotEmpty(item.getDeviceName()) ? item.getDeviceName().trim() : "",
|
(oldValue, newValue) -> StringUtils.isNotEmpty(oldValue) ? oldValue : newValue,
|
LinkedHashMap::new
|
));
|
List<String> guidList = new ArrayList<>(guidDeviceNameMap.keySet());
|
|
List<Map<String, String>> maps = realTimeEnergyConsumptionService
|
.getRealData(guidList);
|
for (Map<String, String> item : maps) {
|
String guid = item.get("guid");
|
if (StringUtils.isNotEmpty(guid)) {
|
String deviceName = guidDeviceNameMap.get(guid.trim());
|
if (StringUtils.isNotEmpty(deviceName)) {
|
item.put("deviceName", deviceName);
|
}
|
}
|
}
|
return AjaxResult.success(maps);
|
}
|
|
/**
|
* 获取历史数据
|
*/
|
@GetMapping("/getHistoryData")
|
public AjaxResult getHistoryData(@RequestParam(value = "guid") String guid,
|
@RequestParam(value = "startTime") long startTime,
|
@RequestParam(value = "endTime") long endTime) {
|
List<Map<String, String>> maps = realTimeEnergyConsumptionService.getHistoryData(guid, startTime, endTime);
|
return AjaxResult.success(maps);
|
}
|
|
}
|