| | |
| | | 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.enums.OrderByEnums; |
| | | import com.sandu.ximon.dao.mapper.LightMapper; |
| | | import com.sandu.ximon.dao.mapper.LightTaskMapper; |
| | | import lombok.AllArgsConstructor; |
| | |
| | | Boolean hasKey = redisService.hasKey(LightKey.REPORT_MAC.key(deviceName)); |
| | | if (!hasKey) { |
| | | int count = count(Wrappers.lambdaQuery(Light.class).eq(Light::getDeviceCode, deviceName)); |
| | | log.info("redis查不到路灯数据{}={}", count, deviceName); |
| | | log.info("redis查不到路灯数据 数量:{}={}", count, deviceName); |
| | | // 当前路灯表没有录入设备吗 |
| | | if (count == 0) { |
| | | Light light = new Light(); |
| | |
| | | light.setLightPercent(heartBeatDataPackage.getLightPercent()); |
| | | light.setLight2Percent(heartBeatDataPackage.getLight2Percent()); |
| | | save(light); |
| | | log.info("新增路灯"); |
| | | } |
| | | redisService.set(LightKey.REPORT_MAC.key(deviceName), 1, LightKey.REPORT_MAC.expireSeconds()); |
| | | log.info("新增路灯"); |
| | | } else { |
| | | Light light = new Light(); |
| | | light.setLightPercent(heartBeatDataPackage.getLightPercent()); |
| | | light.setLight2Percent(heartBeatDataPackage.getLight2Percent()); |
| | | update(light, Wrappers.lambdaUpdate(Light.class).eq(Light::getDeviceCode, deviceName)); |
| | | log.info("更新路灯亮度"); |
| | | boolean update = update(light, Wrappers.lambdaUpdate(Light.class).eq(Light::getDeviceCode, deviceName)); |
| | | log.info("更新路灯亮度 {}", update); |
| | | } |
| | | } |
| | | |
| | |
| | | * |
| | | * @return 返回组合数据dto |
| | | */ |
| | | public List<LightBo> listLight(int pageNo, int pageSize, String keyword) { |
| | | public List<LightBo> listLight(int pageNo, int pageSize, String keyword, Integer order, Integer seq) { |
| | | Long clientId = SecurityUtils.getClientId(); |
| | | |
| | | PageHelper.startPage(pageNo, pageSize); |
| | | //排序字段 |
| | | String orderByResult = "light_id"; |
| | | //正序、倒叙 |
| | | String orderBySeq = OrderByEnums.ASC.getCode(); |
| | | if (order != null) { |
| | | switch (order) { |
| | | case 1: |
| | | orderByResult = OrderByEnums.LIGHT_POLE_NAME.getCode(); |
| | | break; |
| | | case 2: |
| | | orderByResult = OrderByEnums.LIGHT_UPDATE_TIME.getCode(); |
| | | break; |
| | | case 3: |
| | | orderByResult = OrderByEnums.LIGHT_CREATE_TIME.getCode(); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | if (seq != null) { |
| | | switch (seq) { |
| | | case 1: |
| | | orderBySeq = OrderByEnums.ASC.getCode(); |
| | | break; |
| | | case 2: |
| | | orderBySeq = OrderByEnums.DESC.getCode(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | //排序方式 |
| | | String orderBy = orderByResult + " " + orderBySeq; |
| | | |
| | | PageHelper.startPage(pageNo, pageSize, orderBy); |
| | | |
| | | List<LightBo> listLight = baseMapper.listLight(clientId, keyword); |
| | | |
| | |
| | | |
| | | 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(); |
| | |
| | | /** |
| | | * 节能率计算开始 |
| | | */ |
| | | //TODO |
| | | //获取昨天的星期数 |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime yesterday = now.minusDays(1); |
| | |
| | | //判断Task.getWeekList()是否包含昨天的星期数 不包含直接返回0 不进行计算 |
| | | if (Task.getWeekList() != null && !Task.getWeekList().isEmpty()) { |
| | | if (!Task.getWeekList().contains(week)) { |
| | | return BigDecimal.ZERO; |
| | | return new BigDecimal(1); |
| | | } |
| | | } else { |
| | | return BigDecimal.ZERO; |
| | | return new BigDecimal(1); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * 一天的能耗 |
| | | * |
| | | * @param list |
| | | * @param |
| | | * @return |
| | | */ |
| | | public BigDecimal jisuanEnergy(LightTaskDto Task) { |
| | |
| | | // BigDecimal hour = BigDecimal.valueOf((v2.getHour() - v1.getHour())); |
| | | // BigDecimal hour; |
| | | if (v1.getBrightness() == 0) { |
| | | return BigDecimal.ZERO; |
| | | return new BigDecimal(1); |
| | | } |
| | | double hour; |
| | | double min; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 用户拥有的路灯(用于首页数据统计) |
| | | * |
| | | * @return |
| | | */ |
| | | public List<LightBo> listLightOnHome() { |
| | | List<LightBo> listLight; |
| | | if (SecurityUtils.getClientId() != null) { |
| | | listLight = baseMapper.listLight(SecurityUtils.getUserId(), null); |
| | | } else { |
| | | listLight = baseMapper.listLight(null, null); |
| | | } |
| | | return listLight; |
| | | } |
| | | |
| | | /** |
| | | * 获取用户所有的设备码 |
| | | */ |
| | | public CommonPage<String> listDeviceCode(int pageNo, int pageSize, String keyword, String deviceCode) { |
| | | public CommonPage<String> listDeviceCode(int pageNo, int pageSize, String keyword, String deviceCode,String orderBy) { |
| | | List<String> list; |
| | | if (SecurityUtils.getClientId() != null) { |
| | | PageHelper.startPage(pageNo, pageSize); |
| | | list = baseMapper.listCode(SecurityUtils.getUserId(), keyword, deviceCode); |
| | | } else { |
| | | |
| | | PageHelper.startPage(pageNo, pageSize); |
| | | PageHelper.startPage(pageNo, pageSize,orderBy); |
| | | list = baseMapper.listCode(null, keyword, deviceCode); |
| | | } |
| | | |
| | |
| | | lights.forEach(light -> { |
| | | light.setPower1(lightPowerSettingParam.getPower1()); |
| | | light.setPower2(lightPowerSettingParam.getPower2()); |
| | | //存在非0功率 即为存在该灯头 |
| | | if (lightPowerSettingParam.getPower1() != null || lightPowerSettingParam.getPower1() != 0) { |
| | | light.setLight1(1); |
| | | } else if (lightPowerSettingParam.getPower1() == 0) { |
| | | //手动设置灯头功率为0 即不存在该灯头 |
| | | light.setLight1(0); |
| | | } else { |
| | | light.setLight1(0); |
| | | } |
| | | //存在非0功率 即为存在该灯头 |
| | | if (lightPowerSettingParam.getPower2() != null || lightPowerSettingParam.getPower2() != 0) { |
| | | light.setLight2(1); |
| | | } else if (lightPowerSettingParam.getPower2() == 0) { |
| | | //手动设置灯头功率为0 即不存在该灯头 |
| | | light.setLight2(0); |
| | | } else { |
| | | light.setLight2(0); |
| | | } |
| | | light.setLightCount(lightPowerSettingParam.getLightCount()); |
| | | }); |
| | | return updateBatchById(lights); |