| | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.HexUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.aliyuncs.iot.model.v20180120.BatchGetDeviceStateResponse; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.sandu.common.domain.CommonPage; |
| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | public List<LightBo> listLight(int pageNo, int pageSize, String keyword) { |
| | | Long clientId = SecurityUtils.getClientId(); |
| | | |
| | | PageHelper.startPage(pageNo, pageSize); |
| | | // PageHelper.startPage(pageNo, pageSize); |
| | | |
| | | List<LightBo> listLight = baseMapper.listLight(clientId, keyword); |
| | | |
| | | // 获取最近的上报时间 |
| | | List<String> deviceCodeList = listLight.stream().map(Light::getDeviceCode).collect(Collectors.toList()); |
| | | //拆分list |
| | | List<List<String>> split = CollectionUtil.split(deviceCodeList, 100); |
| | | |
| | | List<BatchGetDeviceStateResponse.DeviceStatus> deviceStatuses=null; |
| | | for (List<String> splist : split) { |
| | | deviceStatuses=MainBoardInvokeSyncService.getInstance().batchGetDeviceState(splist); |
| | | if (deviceStatuses != null) { |
| | | for (LightBo lightBo : listLight) { |
| | | for (BatchGetDeviceStateResponse.DeviceStatus deviceStatus : deviceStatuses) { |
| | | |
| | | if (lightBo.getDeviceCode() != null && lightBo.getDeviceCode().equals(deviceStatus.getDeviceName())) { |
| | | if("ONLINE".equals(deviceStatus.getStatus()) ){ |
| | | lightBo.setOnlineStatus(0); |
| | | }else if("OFFLINE".equals(deviceStatus.getStatus())){ |
| | | lightBo.setOnlineStatus(1); |
| | | }else { |
| | | lightBo.setOnlineStatus(2); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | if (CollectionUtil.isNotEmpty(deviceCodeList)) { |
| | | List<LightReportData> reportDataList = lightReportDataService.getNewestReportByDeviceCode(deviceCodeList); |
| | | for (LightBo lightBo : listLight) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 服务端批量控灯日志记录开始 |
| | | */ |
| | | String content = "{控灯请求:" + paramList.toString() |
| | | + ", 控灯结果:" + resultList.toString() + "}"; |
| | | List<String> codeList = new ArrayList<>(); |
| | | for (LightControlParam bean : paramList) { |
| | | codeList.add(bean.getDeviceCode()); |
| | | } |
| | | StoreOperationRecordsUtils.storeOperationData(codeList, null, "服务端批量控灯", content); |
| | | /** |
| | | * 服务端批量控灯日志记录结束 |
| | | */ |
| | | |
| | | return resultList; |
| | | } |
| | | |
| | |
| | | * |
| | | * @return |
| | | */ |
| | | public Map controlEnergySaving() { |
| | | public List controlEnergySaving() { |
| | | //获取到正在执行的任务列表 |
| | | List<LightTaskDto> lightTaskDtos = SpringContextHolder.getBean(LightTaskService.class).listTask(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | |
| | | |
| | | for (LightTaskDto lightTaskDto : lightTaskDtos) { |
| | | List<Integer> weekList = lightTaskDto.getWeekList(); |
| | | System.out.println(weekList + "==========================="); |
| | | for (Integer one : weekList) { |
| | | switch (one) { |
| | | case 1: |
| | |
| | | |
| | | //获取当前星期几 1-7 |
| | | |
| | | int week = now.getDayOfWeek().getValue(); |
| | | Map map = new HashMap(); |
| | | int currentWeekValue = now.getDayOfWeek().getValue(); |
| | | Map map; |
| | | List<Map> temp = new ArrayList<>(); |
| | | //获取日期 精确到天 |
| | | LocalDateTime localDateTime = now.with(LocalTime.MIN); |
| | | |
| | | |
| | | for (int i = 1; i < 8; i++) { |
| | | week--; |
| | | if (week < 1) { |
| | | week = 7; |
| | | currentWeekValue--; |
| | | if (currentWeekValue < 1) { |
| | | currentWeekValue = 7; |
| | | } |
| | | String format = localDateTime.minusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | map.put(localDateTime.minusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), getlist(week)); |
| | | map = new LinkedHashMap(); |
| | | map.put("time",localDateTime.minusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
| | | map.put("value", getlist(currentWeekValue)); |
| | | temp.add(map); |
| | | } |
| | | |
| | | |
| | | return map; |
| | | return temp; |
| | | } |
| | | |
| | | |
| | |
| | | * |
| | | * @return |
| | | */ |
| | | public Map controlEnergy() { |
| | | public List controlEnergy() { |
| | | //获取到正在执行的任务列表 |
| | | List<LightTaskDto> lightTaskDtos = SpringContextHolder.getBean(LightTaskService.class).listTask(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | |
| | | } |
| | | } |
| | | |
| | | Integer week = now.getDayOfWeek().getValue(); |
| | | |
| | | Map map = new HashMap(); |
| | | Integer currentWeekValue = now.getDayOfWeek().getValue(); |
| | | Map map; |
| | | List<Map> temp = new ArrayList<>(); |
| | | //获取当前日期 格式为yyyy-MM-dd |
| | | LocalDateTime localDateTime = now.with(LocalTime.MIN); |
| | | |
| | | |
| | | for (int i = 1; i < 8; i++) { |
| | | week--; |
| | | if (week < 1) { |
| | | week = 7; |
| | | currentWeekValue--; |
| | | if (currentWeekValue < 1) { |
| | | currentWeekValue = 7; |
| | | } |
| | | map.put(localDateTime.minusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), getlistEnergy(week)); |
| | | map = new LinkedHashMap(); |
| | | map.put("time",localDateTime.minusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
| | | map.put("value", getlistEnergy(currentWeekValue)); |
| | | temp.add(map); |
| | | } |
| | | |
| | | |
| | | return map; |
| | | return temp; |
| | | } |
| | | |
| | | |