| | |
| | | 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 org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.naming.ldap.PagedResultsControl; |
| | | import java.util.*; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @RestController |
| | | @RequestMapping("/iot") |
| | |
| | | @Autowired |
| | | private RealTimeEnergyConsumptionServiceImpl realTimeEnergyConsumptionService; |
| | | |
| | | private final String DEVICE_GUID = "90444196515214284663"; |
| | | |
| | | private final String DEVICE_GUID_2 = "90187099059463151919"; |
| | | |
| | | private final String DEVICE_GUID_3 = "90299548548536240693"; |
| | | |
| | | private final String DEVICE_GUID_4 = "90558670647417764794"; |
| | | |
| | | private final String DEVICE_GUID_5 = "90802100373808917949"; |
| | | |
| | | private final String DEVICE_GUID_6 = "90878497978270816672"; |
| | | @Autowired |
| | | private IDeviceLedgerService deviceLedgerService; |
| | | |
| | | /** |
| | | * 实时获取温湿度,二氧化碳数据 |
| | | */ |
| | | @GetMapping("/getRealData") |
| | | public AjaxResult getRealData() { |
| | | List<Map<String,String>> maps = realTimeEnergyConsumptionService |
| | | .getRealData(Arrays. |
| | | asList(DEVICE_GUID, |
| | | DEVICE_GUID_2, |
| | | DEVICE_GUID_3, |
| | | DEVICE_GUID_4, |
| | | DEVICE_GUID_5, |
| | | DEVICE_GUID_6)); |
| | | 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); |
| | | } |
| | | |
| | |
| | | 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); |
| | | List<Map<String, String>> maps = realTimeEnergyConsumptionService.getHistoryData(guid, startTime, endTime); |
| | | return AjaxResult.success(maps); |
| | | } |
| | | |