14 小时以前 de1d6cf24efebced674fbaa46123648bf50bd74a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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);
    }
 
}