| | |
| | | import com.sandu.ximon.dao.domain.LightTask; |
| | | import com.sandu.ximon.dao.domain.LightTaskPoleRelation; |
| | | import com.sandu.ximon.dao.domain.Pole; |
| | | import com.sandu.ximon.dao.enums.IssueStatusEnums; |
| | | import com.sandu.ximon.dao.enums.DeviceRespStatusEnums; |
| | | import com.sandu.ximon.dao.mapper.LightTaskMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | @AllArgsConstructor |
| | | public class LightTaskService extends BaseServiceImpl<LightTaskMapper, LightTask> { |
| | | |
| | | |
| | | // private final LightTaskQuartzService lightTaskQuartzService; |
| | | private final PoleService poleService; |
| | | private final LightTaskPoleRelationService lightTaskPoleRelationService; |
| | | |
| | | |
| | | /** |
| | | * 新增路灯任务 |
| | |
| | | if (!save(lightTask)) { |
| | | throw new BusinessException("保存路灯任务失败"); |
| | | } |
| | | // List<LightTaskQuartz> list = lightTaskQuartzService.addLightTaskQuartz(lightTask); |
| | | // if (CollectionUtil.isEmpty(list)) { |
| | | // throw new BusinessException("添加定时任务失败"); |
| | | // } |
| | | |
| | | List<Long> poleIdList = param.getPoleIdList(); |
| | | if (CollectionUtil.isNotEmpty(poleIdList)) { |
| | | |
| | | List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, poleIdList,lightTask.getFramePayload()); |
| | | List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, poleIdList, lightTask.getFramePayload()); |
| | | |
| | | // 添加绑定灯杆 |
| | | if (!lightTaskPoleRelationService.saveBatch(lightTaskPoleRelationList)) { |
| | |
| | | throw new BusinessException("编辑任务失败"); |
| | | } |
| | | |
| | | // List<LightTaskQuartz> list = lightTaskQuartzService.updateLightTaskQuartz(lightTask); |
| | | // if (CollectionUtil.isEmpty(list)) { |
| | | // throw new BusinessException("编辑定时任务失败"); |
| | | // } |
| | | |
| | | List<Long> poleIdList = param.getPoleIdList(); |
| | | if (CollectionUtil.isNotEmpty(poleIdList)) { |
| | | |
| | | List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, poleIdList,lightTask.getFramePayload()); |
| | | List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, poleIdList, lightTask.getFramePayload()); |
| | | |
| | | lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getTaskId, lightTask.getTaskId())); |
| | | // 添加绑定灯杆 |
| | |
| | | if (StrUtil.isNotBlank(keyword)) { |
| | | wrapper.like(LightTask::getTaskName, keyword); |
| | | } |
| | | Long clientId = SecurityUtils.getClientId(); |
| | | if (clientId != null) { |
| | | wrapper.eq(LightTask::getClientId, clientId); |
| | | //不是超管需要筛选 |
| | | if (SecurityUtils.getClientId() != null) { |
| | | wrapper.eq(LightTask::getClientId, SecurityUtils.getUserId()).or(w -> { |
| | | w.eq(LightTask::getUserId, SecurityUtils.getUserId()); |
| | | }); |
| | | } |
| | | |
| | | PageHelper.startPage(pageNo, pageSize); |
| | |
| | | return page; |
| | | } |
| | | |
| | | |
| | | // 每个路灯发送控制帧 返回关联列表 |
| | | private List<LightTaskPoleRelation> sendControllerFrame(LightTask lightTask, List<Long> poleIdList,String framePayload) { |
| | | private List<LightTaskPoleRelation> sendControllerFrame(LightTask lightTask, List<Long> poleIdList, String framePayload) { |
| | | List<LightTaskPoleRelation> lightTaskPoleRelationList = new ArrayList<>(); |
| | | |
| | | List<Pole> poles = poleService.listByIds(poleIdList); |
| | |
| | | } |
| | | |
| | | for (Pole pole : poles) { |
| | | // rrpc 发生定时命令 |
| | | A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame = sendTimeRRpc(framePayload, pole.getDeviceCode()); |
| | | |
| | | LightTaskPoleRelation lightTaskPoleRelation = new LightTaskPoleRelation(); |
| | | lightTaskPoleRelation.setPoleId(pole.getId()); |
| | | lightTaskPoleRelation.setTaskId(lightTask.getTaskId()); |
| | | if (a5LightTimerRespInnerFrame == null) { |
| | | lightTaskPoleRelation.setIssueStatus(IssueStatusEnums.OTHER_ERROR.getCode()); |
| | | } else { |
| | | lightTaskPoleRelation.setIssueStatus(HexUtil.hexToInt(a5LightTimerRespInnerFrame.getResponseStatus())); |
| | | // rrpc 发生定时命令 |
| | | try { |
| | | A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame = sendTimeRRpc(framePayload, pole.getDeviceCode()); |
| | | if (a5LightTimerRespInnerFrame == null) { |
| | | lightTaskPoleRelation.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | } else { |
| | | lightTaskPoleRelation.setIssueStatus(HexUtil.hexToInt(a5LightTimerRespInnerFrame.getResponseStatus())); |
| | | } |
| | | } catch (BusinessException e) { |
| | | lightTaskPoleRelation.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | } |
| | | |
| | | lightTaskPoleRelationList.add(lightTaskPoleRelation); |
| | | } |
| | | return lightTaskPoleRelationList; |
| | |
| | | throw new BusinessException("删除任务失败"); |
| | | } |
| | | |
| | | boolean del; |
| | | // 删除绑定灯杆 |
| | | if (!lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getTaskId, taskIdList))) { |
| | | throw new BusinessException("删除绑定灯杆失败"); |
| | | } |
| | | |
| | | // // 删除定时器 |
| | | // if (!lightTaskQuartzService.removeLightTaskQuartz(taskIdList)) { |
| | | // throw new BusinessException("删除定时器失败"); |
| | | // 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)); |
| | | } |
| | | ); |
| | | |
| | | return true; |
| | | } |
| | |
| | | |
| | | /** |
| | | * 下发单个灯杆的任务 |
| | | * |
| | | * @param param |
| | | * @return |
| | | */ |
| | | public boolean issueLightTask(LightTaskIssueParam param) { |
| | | LightTask lightTask = getById(param.getTaskId()); |
| | |
| | | throw new BusinessException("找不到任务"); |
| | | } |
| | | String framePayload = buildControlFramePayload(lightTask.getOpenOrder(), lightTask.getCloseOrder(), lightTask.getControlOrder(), lightTask.getWeek()); |
| | | List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, ListUtil.toList(param.getPoleId()),framePayload); |
| | | List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, ListUtil.toList(param.getPoleId()), framePayload); |
| | | if (CollectionUtil.isNotEmpty(lightTaskPoleRelationList)) { |
| | | return lightTaskPoleRelationService.update(lightTaskPoleRelationList.get(0), |
| | | Wrappers.lambdaUpdate(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getPoleId, param.getPoleId()) |