| | |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils; |
| | | import com.sandu.ximon.admin.utils.TaskOrderUtil; |
| | | import com.sandu.ximon.dao.bo.LightTaskPoleRelationBo; |
| | | import com.sandu.ximon.dao.bo.LightTaskStatusAndPole; |
| | | import com.sandu.ximon.dao.domain.LightEnergyData; |
| | | import com.sandu.ximon.dao.domain.LightTask; |
| | |
| | | import com.sandu.ximon.dao.enums.DeviceRespStatusEnums; |
| | | import com.sandu.ximon.dao.enums.OrderByEnums; |
| | | import com.sandu.ximon.dao.mapper.LightTaskMapper; |
| | | import com.sandu.ximon.dao.mapper.LightTaskPoleRelationMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | * 下发路灯任务日志记录结束 |
| | | */ |
| | | |
| | | // if (oldPoleFail.isEmpty() && closePoleFail.isEmpty()) { |
| | | // //全部成功 |
| | | // return 0; |
| | | // } else if (!closeLight.isEmpty() || !oldPoleFail.isEmpty()) { |
| | | // //关灯失败 或者覆盖任务失败 |
| | | // return 1; |
| | | // } else if (newPoleSuccess.isEmpty() && oldPoleSuccess.isEmpty() && closeSuccess.isEmpty()) { |
| | | // //编辑全部失败 |
| | | // return 2; |
| | | // } else { |
| | | // //其他情况 |
| | | // return -1; |
| | | // } |
| | | |
| | | // if (newPoleFail.isEmpty() && oldPoleFail.isEmpty() && closePoleFail.isEmpty()) { |
| | | // //编辑成功 |
| | | // return 0; |
| | | // } else if (newPoleSuccess.isEmpty() && oldPoleSuccess.isEmpty() && closePoleSuccess.isEmpty()) { |
| | | // //编辑失败 |
| | | // return 1; |
| | | // } else { |
| | | // //在旧任务基础上编辑 |
| | | // if (lightTask.getTaskId().equals(newLightTask.getTaskId())) { |
| | | // //只有旧任务 |
| | | // return 2; |
| | | // } else { |
| | | // //有新任务,有旧任务 |
| | | // return 3; |
| | | // } |
| | | // } |
| | | |
| | | if (newPoleFail.isEmpty() && oldPoleFail.isEmpty() && closePoleFail.isEmpty()) { |
| | | return "编辑成功"; |
| | | } else if (newPoleSuccess.isEmpty() && oldPoleSuccess.isEmpty() && closePoleSuccess.isEmpty()) { |
| | | throw new BusinessException("编辑失败"); |
| | | throw new BusinessException("编辑失败,请检查编辑的设备是否在线!"); |
| | | } else if (!closePoleFail.isEmpty() || !oldPoleFail.isEmpty()) { |
| | | return "原任务中存在下发异常,原任务保留,创建新任务进行保存"; |
| | | } else if (!newPoleFail.isEmpty()) { |
| | |
| | | } |
| | | |
| | | public List<LightTaskDto> listLightTask(BaseConditionVO conditionVO, String keyword, Integer order, Integer seq) { |
| | | LambdaQueryWrapper<LightTask> wrapper = Wrappers.lambdaQuery(LightTask.class); |
| | | if (StrUtil.isNotBlank(keyword)) { |
| | | wrapper.like(LightTask::getTaskName, keyword); |
| | | } |
| | | //不是超管需要筛选 |
| | | if (SecurityUtils.getClientId() != null) { |
| | | wrapper.eq(LightTask::getClientId, SecurityUtils.getUserId()).or(w -> { |
| | | w.eq(LightTask::getUserId, SecurityUtils.getUserId()); |
| | | }); |
| | | } |
| | | |
| | | //排序字段 |
| | | String orderByResult = "task_id"; |
| | |
| | | String orderBy = orderByResult + " " + orderBySeq; |
| | | |
| | | PageHelper.startPage(conditionVO.getPageNo(), conditionVO.getPageSize(), orderBy); |
| | | List<LightTask> list = list(wrapper); |
| | | List<LightTask> list = baseMapper.listTask(SecurityUtils.getClientId(),keyword,orderBy); |
| | | |
| | | |
| | | Page<LightTaskDto> page = new Page<>(); |
| | | BeanUtils.copyProperties(list, page); |
| | |
| | | LightTaskDto lightTaskDto = new LightTaskDto(); |
| | | BeanUtils.copyProperties(lightTask, lightTaskDto); |
| | | lightTaskDto.setWeekList(TaskOrderUtil.parseLightWeek2List(lightTask.getWeek())); |
| | | //下发成功的灯杆数量 |
| | | Integer successCount = baseMapper.successCount(lightTaskDto.getTaskId()); |
| | | ///任务中总的灯杆数量 |
| | | Integer toTalCount = baseMapper.toTalCount(lightTaskDto.getTaskId()); |
| | | if (successCount == null) { |
| | | successCount = 0; |
| | | } |
| | | if (toTalCount == null) { |
| | | toTalCount = 0; |
| | | } |
| | | if (toTalCount == 0) { |
| | | //任务中没有灯杆 |
| | | lightTaskDto.setSyncStatus("未同步"); |
| | | } else { |
| | | //任务中有灯杆 |
| | | if (successCount == 0) { |
| | | //下发成功未0 |
| | | lightTaskDto.setSyncStatus("未同步"); |
| | | } else if (successCount != 0 && successCount < toTalCount) { |
| | | //存在下发成功 但并未全部成功 |
| | | lightTaskDto.setSyncStatus("部分同步"); |
| | | } else if (toTalCount.equals(successCount) && toTalCount != 0 && successCount != 0) { |
| | | //全部成功 |
| | | lightTaskDto.setSyncStatus("已同步"); |
| | | } else { |
| | | //未知类型 |
| | | lightTaskDto.setSyncStatus("同步状态出错"); |
| | | } |
| | | } |
| | | page.add(lightTaskDto); |
| | | } |
| | | return page; |
| | |
| | | throw new BusinessException("删除任务失败"); |
| | | } |
| | | |
| | | boolean del; |
| | | // 删除绑定灯杆 |
| | | // if (!lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).notIn(LightTaskPoleRelation::getTaskId, taskIdList))) { |
| | | // throw new BusinessException("未找到任务/灯杆绑定关系"); |
| | | // } |
| | | // lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getTaskId, taskIdList)); |
| | | taskIdList.forEach(taskId -> { |
| | | lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getTaskId, taskId)); |
| | | }); |
| | | |
| | | /** |
| | | * 删除控灯任务日志记录开始 |
| | | */ |
| | |
| | | */ |
| | | public void energy() { |
| | | List<LightTask> lightTasks = list(Wrappers.lambdaQuery(LightTask.class)); |
| | | for (LightTask lightTask : lightTasks) { |
| | | List<LightTaskPoleRelation> list = SpringContextHolder.getBean(LightTaskPoleRelationService.class).list(Wrappers.lambdaQuery(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getTaskId, lightTask.getTaskId())); |
| | | |
| | | LightTaskDto lightTaskDto = new LightTaskDto(); |
| | | BeanUtils.copyProperties(lightTask, lightTaskDto); |
| | | lightTaskDto.setWeekList(TaskOrderUtil.parseLightWeek2List(lightTask.getWeek())); |
| | | List<Long> taskIdList = new ArrayList<>(); |
| | | for (LightTask bean : lightTasks) { |
| | | taskIdList.add(bean.getTaskId()); |
| | | } |
| | | if (taskIdList.size() != 0) { |
| | | List<LightTaskPoleRelationBo> list = SpringContextHolder.getBean(LightTaskPoleRelationMapper.class).test(taskIdList); |
| | | for (LightTaskPoleRelationBo bean : list) { |
| | | |
| | | BigDecimal energySaving = SpringContextHolder.getBean(LightService.class).jisuan(lightTaskDto); |
| | | BigDecimal energy = SpringContextHolder.getBean(LightService.class).jisuanEnergy(lightTaskDto); |
| | | LightTaskDto lightTaskDto = new LightTaskDto(); |
| | | BeanUtils.copyProperties(bean, lightTaskDto); |
| | | lightTaskDto.setWeekList(TaskOrderUtil.parseLightWeek2List(bean.getWeek())); |
| | | BigDecimal energySaving; |
| | | BigDecimal energy; |
| | | //获取昨天的星期数 |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime yesterday = now.minusDays(1); |
| | | int week = yesterday.getDayOfWeek().getValue(); |
| | | if (!list.isEmpty()) { |
| | | //有绑定灯杆 进行计算 |
| | | if (lightTaskDto.getWeekList().contains(week)) { |
| | | //任务有该星期数 计算 |
| | | energySaving = SpringContextHolder.getBean(LightService.class).jisuan(lightTaskDto); |
| | | energy = SpringContextHolder.getBean(LightService.class).jisuanEnergy(lightTaskDto); |
| | | } else { |
| | | //任务无该星期数 返回 |
| | | energySaving = new BigDecimal(1); |
| | | energy = BigDecimal.ZERO; |
| | | } |
| | | for (int i = 0; i < list.size(); i++) { |
| | | LightTaskPoleRelation relation = list.get(i); |
| | | if (relation.getIssueStatus() != 0) { |
| | | //任务下发失败 返回 |
| | | energySaving = new BigDecimal(1); |
| | | energy = BigDecimal.ZERO; |
| | | } |
| | | } |
| | | } else { |
| | | //未绑定灯杆 直接返回 |
| | | energySaving = new BigDecimal(1); |
| | | energy = BigDecimal.ZERO; |
| | | } |
| | | |
| | | //获取昨天的星期数 |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime yesterday = now.minusDays(1); |
| | | /** |
| | | * 存储数据 |
| | | */ |
| | | |
| | | LightEnergyData lightEnergyData = new LightEnergyData(); |
| | | lightEnergyData.setTaskId(bean.getTaskId()); |
| | | lightEnergyData.setYtdTime(yesterday.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
| | | lightEnergyData.setEnergySaving(energySaving); |
| | | lightEnergyData.setEnergy(energy); |
| | | lightEnergyData.setUserId(bean.getUserId()); |
| | | lightEnergyData.setClientId(bean.getClientId()); |
| | | lightEnergyData.setPoleId(bean.getPoleId()); |
| | | //保存能耗数据到数据库 |
| | | lightEnergyDataService.save(lightEnergyData); |
| | | } |
| | | |
| | | LightEnergyData lightEnergyData = new LightEnergyData(); |
| | | lightEnergyData.setTaskId(lightTask.getTaskId()); |
| | | lightEnergyData.setYtdTime(yesterday.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
| | | lightEnergyData.setEnergySaving(energySaving); |
| | | lightEnergyData.setEnergy(energy); |
| | | lightEnergyData.setUserId(lightTask.getUserId()); |
| | | lightEnergyData.setClientId(lightTask.getClientId()); |
| | | |
| | | //保存能耗数据到数据库 |
| | | lightEnergyDataService.save(lightEnergyData); |
| | | |
| | | System.out.println(lightEnergyData + "---------------"); |
| | | //ID 任务id |
| | | } |
| | | } |
| | | |
| | | } |