| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.HexUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.sandu.common.domain.CommonPage; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.redis.RedisService; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.common.util.SpringContextHolder; |
| | | import com.sandu.ximon.admin.dto.LightTaskDto; |
| | | import com.sandu.ximon.admin.manager.iot.frame.A5Frame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightHeartbeatReportInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.request.A5LightBrightnessReqInnerFrame; |
| | |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.A5OrderEnum; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService; |
| | | import com.sandu.ximon.admin.param.LightControlParam; |
| | | import com.sandu.ximon.admin.param.LightPowerSettingParam; |
| | | import com.sandu.ximon.admin.param.LightRemarkParam; |
| | | import com.sandu.ximon.admin.redis.LightKey; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.vo.ControlLightCommandVO; |
| | | import com.sandu.ximon.dao.bo.LightBo; |
| | | import com.sandu.ximon.dao.bo.PoleTaskLightPowerBo; |
| | | import com.sandu.ximon.dao.domain.Light; |
| | | import com.sandu.ximon.dao.domain.LightReportData; |
| | | import com.sandu.ximon.dao.domain.Pole; |
| | | import com.sandu.ximon.dao.domain.PoleBinding; |
| | | import com.sandu.ximon.dao.enums.DeviceRespStatusEnums; |
| | | import com.sandu.ximon.dao.mapper.LightMapper; |
| | | import com.sandu.ximon.dao.mapper.LightTaskMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.*; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | List<LightReportData> reportDataList = lightReportDataService.getNewestReportByDeviceCode(deviceCodeList); |
| | | for (LightBo lightBo : listLight) { |
| | | deviceCodeList.forEach(code -> { |
| | | PoleBinding bind = bindingService.getPoleIdByMac(code); |
| | | if (bind != null && lightBo.getDeviceCode().equals(bind.getDeviceCode())) { |
| | | Long poleId = bind.getPoleId(); |
| | | Pole pole = poleService.getById(poleId); |
| | | lightBo.setPoleId(pole.getId()); |
| | | lightBo.setPoleCode(pole.getDeviceCode()); |
| | | lightBo.setPoleName(pole.getPoleName()); |
| | | } |
| | | } |
| | | ); |
| | | PoleBinding bind = bindingService.getPoleIdByMac(code); |
| | | if (bind != null && lightBo.getDeviceCode().equals(bind.getDeviceCode())) { |
| | | Long poleId = bind.getPoleId(); |
| | | Pole pole = poleService.getById(poleId); |
| | | lightBo.setPoleId(pole.getId()); |
| | | lightBo.setPoleCode(pole.getDeviceCode()); |
| | | lightBo.setPoleName(pole.getPoleName()); |
| | | } |
| | | }); |
| | | for (LightReportData lightReportData : reportDataList) { |
| | | if (StrUtil.equals(lightBo.getDeviceCode(), lightReportData.getDeviceCode())) { |
| | | lightBo.setReportTime(lightReportData.getCreateTime()); |
| | | lightBo.setReportTime(lightReportData.getCreateTime1()); |
| | | break; |
| | | } |
| | | } |
| | |
| | | |
| | | List<Map<String, Object>> resultList = new ArrayList<>(); |
| | | for (LightControlParam param : paramList) { |
| | | A5LightBrightnessReqInnerFrame lightControlFrame = new A5LightBrightnessReqInnerFrame(param.getBrightness()); |
| | | A5LightBrightnessReqInnerFrame lightControlFrame = new A5LightBrightnessReqInnerFrame(param.getBrightness(), param.getLightAddress()); |
| | | A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_LIGHT_DATA.getCode(), lightControlFrame); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | try { |
| | | map.put("deviceCode", param.getDeviceCode()); |
| | | WrapResponseCommonFrame<A5LightBrightnessRespInnerFrame> frame = MainBoardInvokeSyncService.getInstance() |
| | | .sendRRPC(param.getDeviceCode(), a5Frame, A5LightBrightnessRespInnerFrame.class); |
| | | WrapResponseCommonFrame<A5LightBrightnessRespInnerFrame> frame = MainBoardInvokeSyncService.getInstance().sendRRPC(param.getDeviceCode(), a5Frame, A5LightBrightnessRespInnerFrame.class); |
| | | if (frame == null) { |
| | | map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | resultList.add(map); |
| | |
| | | * @return |
| | | */ |
| | | public Map controlEnergySaving() { |
| | | Long clientId = SecurityUtils.getClientId(); |
| | | List<LightBo> listLight = baseMapper.listLight(clientId, null); |
| | | List<String> deviceCodeList = listLight.stream().map(LightBo::getDeviceCode).collect(Collectors.toList()); |
| | | //获取到正在执行的任务列表 |
| | | List<LightTaskDto> lightTaskDtos = SpringContextHolder.getBean(LightTaskService.class).listTask(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | |
| | | //获取用户最近7天的单灯数据 |
| | | List<LightReportData> reportDataList = lightReportDataService.list(Wrappers.<LightReportData>lambdaQuery() |
| | | .in(LightReportData::getDeviceCode, deviceCodeList) |
| | | .ge(LightReportData::getCreateTime, DateUtil.offsetDay(new Date(), -7)) |
| | | .orderByDesc(LightReportData::getCreateTime)); |
| | | List<LightTaskDto> list1 = new ArrayList<>(); |
| | | List<LightTaskDto> list2 = new ArrayList<>(); |
| | | List<LightTaskDto> list3 = new ArrayList<>(); |
| | | List<LightTaskDto> list4 = new ArrayList<>(); |
| | | List<LightTaskDto> list5 = new ArrayList<>(); |
| | | List<LightTaskDto> list6 = new ArrayList<>(); |
| | | List<LightTaskDto> list7 = new ArrayList<>(); |
| | | |
| | | |
| | | if (CollectionUtil.isEmpty(reportDataList)) { |
| | | throw new BusinessException("没有路灯数据"); |
| | | for (LightTaskDto lightTaskDto : lightTaskDtos) { |
| | | List<Integer> weekList = lightTaskDto.getWeekList(); |
| | | System.out.println(weekList + "==========================="); |
| | | for (Integer one : weekList) { |
| | | switch (one) { |
| | | case 1: |
| | | list1.add(lightTaskDto); |
| | | break; |
| | | case 2: |
| | | list2.add(lightTaskDto); |
| | | break; |
| | | case 4: |
| | | list3.add(lightTaskDto); |
| | | break; |
| | | case 8: |
| | | list4.add(lightTaskDto); |
| | | break; |
| | | case 16: |
| | | list5.add(lightTaskDto); |
| | | break; |
| | | case 32: |
| | | list6.add(lightTaskDto); |
| | | break; |
| | | case 64: |
| | | list7.add(lightTaskDto); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | } |
| | | |
| | | Integer week = now.getDayOfWeek().getValue(); |
| | | |
| | | Map map = new HashMap(); |
| | | map.put("7", reportDataList); |
| | | |
| | | |
| | | for (int i = 1; i < 8; i++) { |
| | | week--; |
| | | if (week < 1) { |
| | | week = 7; |
| | | } |
| | | map.put(i, "周" + week); |
| | | map.put(i, getlist(week)); |
| | | } |
| | | |
| | | |
| | | return map; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 单灯能耗 |
| | | * |
| | | * @return |
| | | */ |
| | | public Map controlEnergy() { |
| | | //获取到正在执行的任务列表 |
| | | List<LightTaskDto> lightTaskDtos = SpringContextHolder.getBean(LightTaskService.class).listTask(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | |
| | | List<LightTaskDto> list1 = new ArrayList<>(); |
| | | List<LightTaskDto> list2 = new ArrayList<>(); |
| | | List<LightTaskDto> list3 = new ArrayList<>(); |
| | | List<LightTaskDto> list4 = new ArrayList<>(); |
| | | List<LightTaskDto> list5 = new ArrayList<>(); |
| | | List<LightTaskDto> list6 = new ArrayList<>(); |
| | | List<LightTaskDto> list7 = new ArrayList<>(); |
| | | |
| | | for (LightTaskDto lightTaskDto : lightTaskDtos) { |
| | | List<Integer> weekList = lightTaskDto.getWeekList(); |
| | | System.out.println(weekList + "==========================="); |
| | | for (Integer one : weekList) { |
| | | switch (one) { |
| | | case 1: |
| | | list1.add(lightTaskDto); |
| | | break; |
| | | case 2: |
| | | list2.add(lightTaskDto); |
| | | break; |
| | | case 4: |
| | | list3.add(lightTaskDto); |
| | | break; |
| | | case 8: |
| | | list4.add(lightTaskDto); |
| | | break; |
| | | case 16: |
| | | list5.add(lightTaskDto); |
| | | break; |
| | | case 32: |
| | | list6.add(lightTaskDto); |
| | | break; |
| | | case 64: |
| | | list7.add(lightTaskDto); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | } |
| | | |
| | | Integer week = now.getDayOfWeek().getValue(); |
| | | |
| | | Map map = new HashMap(); |
| | | |
| | | |
| | | for (int i = 1; i < 8; i++) { |
| | | week--; |
| | | if (week < 1) { |
| | | week = 7; |
| | | } |
| | | map.put(i, getlistEnergy(week)); |
| | | } |
| | | |
| | | |
| | | return map; |
| | | } |
| | | |
| | | |
| | | public BigDecimal getlist(Integer week) { |
| | | |
| | | Long clientId = SecurityUtils.getClientId(); |
| | | // List<LightBo> listLight = baseMapper.listLight(clientId, null); |
| | | // List<String> deviceCodeList = listLight.stream().map(LightBo::getDeviceCode).collect(Collectors.toList()); |
| | | |
| | | //获取到正在执行的任务列表 |
| | | List<LightTaskDto> lightTaskDtos = SpringContextHolder.getBean(LightTaskService.class).listTask(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | |
| | | List<LightTaskDto> list1 = new ArrayList<>(); |
| | | List<LightTaskDto> list2 = new ArrayList<>(); |
| | | List<LightTaskDto> list3 = new ArrayList<>(); |
| | | List<LightTaskDto> list4 = new ArrayList<>(); |
| | | List<LightTaskDto> list5 = new ArrayList<>(); |
| | | List<LightTaskDto> list6 = new ArrayList<>(); |
| | | List<LightTaskDto> list7 = new ArrayList<>(); |
| | | |
| | | for (LightTaskDto lightTaskDto : lightTaskDtos) { |
| | | List<Integer> weekList = lightTaskDto.getWeekList(); |
| | | System.out.println(weekList + "==========================="); |
| | | for (Integer one : weekList) { |
| | | switch (one) { |
| | | case 1: |
| | | list1.add(lightTaskDto); |
| | | break; |
| | | case 2: |
| | | list2.add(lightTaskDto); |
| | | break; |
| | | case 4: |
| | | list3.add(lightTaskDto); |
| | | break; |
| | | case 8: |
| | | list4.add(lightTaskDto); |
| | | break; |
| | | case 16: |
| | | list5.add(lightTaskDto); |
| | | break; |
| | | case 32: |
| | | list6.add(lightTaskDto); |
| | | break; |
| | | case 64: |
| | | list7.add(lightTaskDto); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | } |
| | | if (week == 1) { |
| | | return jisuan(list1); |
| | | } else if (week == 2) { |
| | | return jisuan(list2); |
| | | } else if (week == 3) { |
| | | return jisuan(list3); |
| | | } else if (week == 4) { |
| | | return jisuan(list4); |
| | | } else if (week == 5) { |
| | | return jisuan(list5); |
| | | } else if (week == 6) { |
| | | return jisuan(list6); |
| | | } else if (week == 7) { |
| | | return jisuan(list7); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public BigDecimal getlistEnergy(Integer week) { |
| | | |
| | | Long clientId = SecurityUtils.getClientId(); |
| | | // List<LightBo> listLight = baseMapper.listLight(clientId, null); |
| | | // List<String> deviceCodeList = listLight.stream().map(LightBo::getDeviceCode).collect(Collectors.toList()); |
| | | |
| | | //获取到正在执行的任务列表 |
| | | List<LightTaskDto> lightTaskDtos = SpringContextHolder.getBean(LightTaskService.class).listTask(); |
| | | |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | |
| | | List<LightTaskDto> list1 = new ArrayList<>(); |
| | | List<LightTaskDto> list2 = new ArrayList<>(); |
| | | List<LightTaskDto> list3 = new ArrayList<>(); |
| | | List<LightTaskDto> list4 = new ArrayList<>(); |
| | | List<LightTaskDto> list5 = new ArrayList<>(); |
| | | List<LightTaskDto> list6 = new ArrayList<>(); |
| | | List<LightTaskDto> list7 = new ArrayList<>(); |
| | | |
| | | for (LightTaskDto lightTaskDto : lightTaskDtos) { |
| | | List<Integer> weekList = lightTaskDto.getWeekList(); |
| | | System.out.println(weekList + "==========================="); |
| | | for (Integer one : weekList) { |
| | | switch (one) { |
| | | case 1: |
| | | list1.add(lightTaskDto); |
| | | break; |
| | | case 2: |
| | | list2.add(lightTaskDto); |
| | | break; |
| | | case 4: |
| | | list3.add(lightTaskDto); |
| | | break; |
| | | case 8: |
| | | list4.add(lightTaskDto); |
| | | break; |
| | | case 16: |
| | | list5.add(lightTaskDto); |
| | | break; |
| | | case 32: |
| | | list6.add(lightTaskDto); |
| | | break; |
| | | case 64: |
| | | list7.add(lightTaskDto); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | } |
| | | if (week == 1) { |
| | | return jisuanEnergy(list1); |
| | | } else if (week == 2) { |
| | | return jisuanEnergy(list2); |
| | | } else if (week == 3) { |
| | | return jisuanEnergy(list3); |
| | | } else if (week == 4) { |
| | | return jisuanEnergy(list4); |
| | | } else if (week == 5) { |
| | | return jisuanEnergy(list5); |
| | | } else if (week == 6) { |
| | | return jisuanEnergy(list6); |
| | | } else if (week == 7) { |
| | | return jisuanEnergy(list7); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 一天的节能率 |
| | | * |
| | | * @param list |
| | | * @return |
| | | */ |
| | | public BigDecimal jisuan(List<LightTaskDto> list) { |
| | | final BigDecimal[] bigDecimalResult = {new BigDecimal(0.00)}; |
| | | final BigDecimal[] bigEnergy = {new BigDecimal(0.00)}; |
| | | /** |
| | | * 节能率计算开始 |
| | | */ |
| | | list.forEach(Task -> { |
| | | // List<BigDecimal> saving = new ArrayList<>(); |
| | | ControlLightCommandVO startTime = parseSwitchLightCommand(Task.getOpenOrder()); |
| | | ControlLightCommandVO endTime = parseSwitchLightCommand(Task.getCloseOrder()); |
| | | //存放节能率 |
| | | //获取到单灯任务的节能率 |
| | | if (Task.getControlOrder() != null) {//有控等指令 拆分计算 |
| | | List<ControlLightCommandVO> controlLightCommandVOS = parseControlLightCommand(Task.getControlOrder()); |
| | | |
| | | |
| | | for (int i = 0; i < controlLightCommandVOS.size(); i++) { |
| | | BigDecimal bigDecimal = calculateEnergySaving(startTime, controlLightCommandVOS.get(i)); |
| | | BigDecimal bigEnergy1 = calculateEnergyConsumption(startTime, controlLightCommandVOS.get(i)); |
| | | if (controlLightCommandVOS.size() == (i + 1)) { |
| | | BigDecimal bigDecimal1 = calculateEnergySaving(controlLightCommandVOS.get(i), endTime); |
| | | BigDecimal bigEnergy2 = calculateEnergyConsumption(controlLightCommandVOS.get(i), endTime); |
| | | |
| | | System.out.println(bigDecimal1 + "==========================="); |
| | | System.out.println(bigEnergy + "时长*亮度==========================="); |
| | | // saving.add(bigDecimal1); |
| | | bigDecimalResult[0] = bigDecimalResult[0].add(bigDecimal1); |
| | | bigEnergy[0] = bigEnergy[0].add(bigEnergy2); |
| | | break; |
| | | } |
| | | startTime = controlLightCommandVOS.get(i); |
| | | // saving.add(bigDecimal); |
| | | bigDecimalResult[0] = bigDecimalResult[0].add(bigDecimal); |
| | | bigEnergy[0] = bigEnergy[0].add(bigEnergy1); |
| | | } |
| | | } else {//无控灯指令 直接计算 |
| | | BigDecimal bigDecimal = calculateEnergySaving(startTime, endTime); |
| | | BigDecimal Energy = calculateEnergyConsumption(startTime, endTime); |
| | | // saving.add(bigDecimal); |
| | | bigDecimalResult[0] = bigDecimalResult[0].add(bigDecimal); |
| | | bigEnergy[0] = bigEnergy[0].add(Energy); |
| | | } |
| | | }); |
| | | return bigDecimalResult[0]; |
| | | |
| | | /** |
| | | * 节能率计算结束 |
| | | */ |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 一天的能耗 |
| | | * |
| | | * @param list |
| | | * @return |
| | | */ |
| | | public BigDecimal jisuanEnergy(List<LightTaskDto> list) { |
| | | //存放能耗 |
| | | final BigDecimal[] bigEnergy = {new BigDecimal(0.00)}; |
| | | /** |
| | | * 节能率计算开始 |
| | | */ |
| | | list.forEach(Task -> { |
| | | List<PoleTaskLightPowerBo> poleTaskLightPowerBos = SpringContextHolder.getBean(LightTaskMapper.class).listLightTaskByTaskId(Task.getTaskId()); |
| | | ControlLightCommandVO startTime = parseSwitchLightCommand(Task.getOpenOrder()); |
| | | ControlLightCommandVO endTime = parseSwitchLightCommand(Task.getCloseOrder()); |
| | | //获取到单灯任务的节能率 |
| | | if (!Task.getControlOrder().isEmpty()) {//有控等指令 拆分计算 |
| | | List<ControlLightCommandVO> controlLightCommandVOS = parseControlLightCommand(Task.getControlOrder()); |
| | | |
| | | |
| | | for (int i = 0; i < controlLightCommandVOS.size(); i++) { |
| | | //得到时长*亮度 |
| | | BigDecimal bigEnergy1 = calculateEnergyConsumption(startTime, controlLightCommandVOS.get(i)); |
| | | if (controlLightCommandVOS.size() == (i + 1)) { |
| | | BigDecimal bigEnergy2 = calculateEnergyConsumption(controlLightCommandVOS.get(i), endTime); |
| | | |
| | | System.out.println(bigEnergy + "时长*亮度==========================="); |
| | | |
| | | //计算能耗(总 时长*亮度*功率) |
| | | BigDecimal totalEnergy = totalEnergy(bigEnergy2, Task.getLightAdress(), poleTaskLightPowerBos); |
| | | // saving.add(bigDecimal1); |
| | | bigEnergy[0] = bigEnergy[0].add(totalEnergy); |
| | | break; |
| | | } |
| | | startTime = controlLightCommandVOS.get(i); |
| | | //计算能耗(总 时长*亮度*功率) |
| | | BigDecimal totalEnergy = totalEnergy(bigEnergy1, Task.getLightAdress(), poleTaskLightPowerBos); |
| | | bigEnergy[0] = bigEnergy[0].add(totalEnergy); |
| | | } |
| | | } else {//无控灯指令 直接计算 |
| | | BigDecimal bigDecimal = calculateEnergySaving(startTime, endTime); |
| | | //计算能耗(部分 时长*亮度) |
| | | BigDecimal Energy = calculateEnergyConsumption(startTime, endTime); |
| | | //计算能耗(总 时长*亮度*功率) |
| | | BigDecimal totalEnergy = totalEnergy(Energy, Task.getLightAdress(), poleTaskLightPowerBos); |
| | | // saving.add(bigDecimal); |
| | | bigEnergy[0] = bigEnergy[0].add(totalEnergy); |
| | | } |
| | | }); |
| | | return bigEnergy[0]; |
| | | |
| | | /** |
| | | * 计算能耗结束 |
| | | */ |
| | | } |
| | | |
| | | private BigDecimal totalEnergy(BigDecimal bigEnergy2, String lightAdress, List<PoleTaskLightPowerBo> poleTaskLightPowerBos) { |
| | | |
| | | //poleTaskLightPowerBos 包含该任务所有的灯的功率 |
| | | //计算功率之和 |
| | | BigDecimal totalPower = new BigDecimal(0.00); |
| | | if ("FFFF".equals(lightAdress)) { |
| | | int totalPower1 = poleTaskLightPowerBos.stream().mapToInt(PoleTaskLightPowerBo::getPower1).sum(); |
| | | int totalPower2 = poleTaskLightPowerBos.stream().mapToInt(PoleTaskLightPowerBo::getPower2).sum(); |
| | | totalPower = new BigDecimal(totalPower1 + totalPower2); |
| | | } else if ("0001".equals(lightAdress)) { |
| | | int totalPower1 = poleTaskLightPowerBos.stream().mapToInt(PoleTaskLightPowerBo::getPower1).sum(); |
| | | totalPower = new BigDecimal(totalPower1); |
| | | } else if ("0002".equals(lightAdress)) { |
| | | int totalPower2 = poleTaskLightPowerBos.stream().mapToInt(PoleTaskLightPowerBo::getPower2).sum(); |
| | | totalPower = new BigDecimal(totalPower2); |
| | | } else { |
| | | return null; |
| | | } |
| | | return totalPower.multiply(bigEnergy2); |
| | | } |
| | | |
| | | /** |
| | | * 解析开关灯指令 |
| | | */ |
| | | public ControlLightCommandVO parseSwitchLightCommand(String command) { |
| | | char[] chars = command.toCharArray(); |
| | | ControlLightCommandVO vo = new ControlLightCommandVO(); |
| | | if (chars.length == 7) { |
| | | int hour = Integer.valueOf(command.substring(0, 2)); |
| | | int min = Integer.valueOf(command.substring(2, 4)); |
| | | int brightness = Integer.valueOf(command.substring(4, 7)); |
| | | vo.setHour(hour); |
| | | vo.setMin(min); |
| | | vo.setBrightness(brightness); |
| | | } |
| | | return vo; |
| | | } |
| | | |
| | | /** |
| | | * 解析控灯指令 |
| | | */ |
| | | public List<ControlLightCommandVO> parseControlLightCommand(String command) { |
| | | char[] chars = command.toCharArray(); |
| | | int i = chars.length / 7; |
| | | |
| | | List<ControlLightCommandVO> list = new ArrayList<>(); |
| | | |
| | | for (int j = 0; j < i; j++) { |
| | | int hour = Integer.valueOf(command.substring(0 + (j * 7), 2 + (j * 7))); |
| | | int min = Integer.valueOf(command.substring(2 + (j * 7), 4 + (j * 7))); |
| | | int brightness = Integer.valueOf(command.substring(4 + (j * 7), 7 + (j * 7))); |
| | | ControlLightCommandVO vo = new ControlLightCommandVO(); |
| | | vo.setHour(hour); |
| | | vo.setMin(min); |
| | | vo.setBrightness(brightness); |
| | | list.add(vo); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | //计算节能率 |
| | | public BigDecimal calculateEnergySaving(ControlLightCommandVO v1, ControlLightCommandVO v2) { |
| | | |
| | | BigDecimal hour = BigDecimal.valueOf((v2.getHour() - v1.getHour())); |
| | | BigDecimal min = BigDecimal.valueOf((v2.getMin() - v1.getMin()) / 60); |
| | | BigDecimal totalTime = (hour.add(min)); |
| | | |
| | | BigDecimal energySaving = BigDecimal.valueOf((100 - v1.getBrightness())).divide(BigDecimal.valueOf(100)).multiply(totalTime).divide(BigDecimal.valueOf(24), 2); |
| | | System.out.println(energySaving); |
| | | return energySaving; |
| | | } |
| | | |
| | | |
| | | //计算能耗(部分 时长*亮度) |
| | | public BigDecimal calculateEnergyConsumption(ControlLightCommandVO v1, ControlLightCommandVO v2) { |
| | | //计算时长 |
| | | BigDecimal hour; |
| | | if (v2.getHour() > v1.getHour()){ |
| | | hour = BigDecimal.valueOf((v2.getHour() - v1.getHour())); |
| | | }else if (v2.getHour() < v1.getHour()) { |
| | | hour = BigDecimal.valueOf((v2.getHour() + 24 - v1.getHour())); |
| | | } else { |
| | | hour = BigDecimal.valueOf(0); |
| | | } |
| | | BigDecimal min = BigDecimal.valueOf((v2.getMin() - v1.getMin()) / 60); |
| | | BigDecimal totalTime = (hour.add(min)); |
| | | //计算亮灯时长*亮度 |
| | | BigDecimal energyConsumption = totalTime.multiply(BigDecimal.valueOf(v1.getBrightness())); |
| | | return energyConsumption; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 用户拥有的路灯 |
| | |
| | | * @return |
| | | */ |
| | | public List<Light> listLight() { |
| | | Long clientId = SecurityUtils.getClientId(); |
| | | List<LightBo> listLight = baseMapper.listLight(clientId, null); |
| | | List<LightBo> listLight; |
| | | if (SecurityUtils.getClientId() != null) { |
| | | listLight = baseMapper.listLight(SecurityUtils.getUserId(), null); |
| | | } else { |
| | | listLight = baseMapper.listLight(null, null); |
| | | } |
| | | List<Light> lightList = new ArrayList<>(); |
| | | for (LightBo bean : listLight) { |
| | | Light light = getLight(bean.getDeviceCode()); |
| | |
| | | return lightList; |
| | | } |
| | | |
| | | /** |
| | | * 获取用户所有的设备码 |
| | | */ |
| | | public CommonPage<String> listDeviceCode(int pageNo, int pageSize, String keyword, String deviceCode) { |
| | | List<String> list; |
| | | if (SecurityUtils.getClientId() != null) { |
| | | PageHelper.startPage(pageNo, pageSize); |
| | | list = baseMapper.listCode(SecurityUtils.getUserId(), keyword, deviceCode); |
| | | } else { |
| | | |
| | | PageHelper.startPage(pageNo, pageSize); |
| | | list = baseMapper.listCode(null, keyword, deviceCode); |
| | | } |
| | | |
| | | return CommonPage.restPage(list); |
| | | } |
| | | |
| | | public boolean setPower(LightPowerSettingParam lightPowerSettingParam) { |
| | | if (lightPowerSettingParam.getLightIds().size() == 0) { |
| | | throw new BusinessException("灯杆ID不能为空"); |
| | | } |
| | | List<Light> lights = listByIds(lightPowerSettingParam.getLightIds()); |
| | | lights.forEach(light -> { |
| | | light.setPower1(lightPowerSettingParam.getPower1()); |
| | | light.setPower2(lightPowerSettingParam.getPower2()); |
| | | light.setLightCount(lightPowerSettingParam.getLightCount()); |
| | | }); |
| | | return updateBatchById(lights); |
| | | } |
| | | } |