| | |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.HexUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.Page; |
| | | import com.github.pagehelper.PageHelper; |
| | |
| | | private final ClientService clientService; |
| | | private final LightEnergyDataService lightEnergyDataService; |
| | | |
| | | |
| | | /** |
| | | * 新增路灯任务 |
| | | * |
| | | * @param param |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean addLightTask(LightTaskParam param) { |
| | | public String newAddLightTask(LightTaskParam param) { |
| | | if (StrUtil.length(param.getControlOrder()) % LightTaskParam.REQUEST_ORDER_LENGTH != 0) { |
| | | throw new BusinessException("灯控命令格式不正确"); |
| | | } |
| | | // LightTask lightTask = getById(null); |
| | | |
| | | |
| | | int week = 0; |
| | | for (Integer w : param.getWeekList()) { |
| | | week |= w; |
| | | } |
| | | LightTask lightTask = new LightTask(); |
| | | if (SecurityUtils.getClientId() != null) { |
| | | lightTask.setClientId(clientService.getClientId()); |
| | | lightTask.setUserId(SecurityUtils.getUserId()); |
| | | } |
| | | lightTask.setTaskName(param.getTaskName()); |
| | | lightTask.setWeek(week); |
| | | lightTask.setLightAdress(param.getLightAddress()); |
| | | lightTask.setCloseOrder(param.getCloseOrder()); |
| | | lightTask.setOpenOrder(param.getOpenOrder()); |
| | | lightTask.setControlOrder(param.getControlOrder()); |
| | | lightTask.setCreateUser(SecurityUtils.getUsername()); |
| | | lightTask.setFramePayload(buildControlFramePayload(param.getOpenOrder(), param.getCloseOrder(), param.getControlOrder(), week)); |
| | | if (!save(lightTask)) { |
| | | |
| | | LightTask newLightTask = new LightTask(); |
| | | newLightTask.setTaskName(param.getTaskName()); |
| | | |
| | | newLightTask.setClientId(clientService.getClientId()); |
| | | newLightTask.setUserId(SecurityUtils.getUserId()); |
| | | |
| | | newLightTask.setWeek(week); |
| | | newLightTask.setCreateUser(SecurityUtils.getUsername()); |
| | | newLightTask.setControlOrder(param.getControlOrder()); |
| | | newLightTask.setOpenOrder(param.getOpenOrder()); |
| | | newLightTask.setCloseOrder(param.getCloseOrder()); |
| | | newLightTask.setLightAdress(param.getLightAddress()); |
| | | newLightTask.setUpdateTime(LocalDateTime.now()); |
| | | newLightTask.setFramePayload(buildControlFramePayload(param.getOpenOrder(), param.getCloseOrder(), param.getControlOrder(), week)); |
| | | |
| | | if (!save(newLightTask)) { |
| | | throw new BusinessException("保存路灯任务失败"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 新增路灯任务日志记录开始 |
| | | */ |
| | | List<String> poleCodeList = new ArrayList<>(); |
| | | if (CollectionUtil.isNotEmpty(param.getPoleIdList())) { |
| | | List<Pole> poleList = SpringContextHolder.getBean(PoleService.class).listByIds(param.getPoleIdList()); |
| | |
| | | poleCodeList = poleList.stream().map(Pole::getDeviceCode).collect(Collectors.toList()); |
| | | } |
| | | } |
| | | String content = "{任务ID:" + lightTask.getTaskId() + ", 任务名:" + lightTask.getTaskName() + "},{内帧指令" + lightTask.getFramePayload() + ", 灯杆ID:" + param.getPoleIdList().toString() + ", 控制的灯头地址:" + param.getLightAddress() + " }"; |
| | | String content = "{任务ID:" + newLightTask.getTaskId() + ", 任务名:" + newLightTask.getTaskName() + "},{内帧指令" + newLightTask.getFramePayload() + ", 灯杆ID:" + param.getPoleIdList().toString() + ", 控制的灯头地址:" + param.getLightAddress() + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "新增路灯任务", content); |
| | | |
| | | |
| | | //传入的灯杆id集合 |
| | | List<Long> poleIdList = param.getPoleIdList(); |
| | | //记录这些灯杆原先的任务 |
| | | List<LightTaskPoleRelation> oldLightTaskStatusAndPoles; |
| | | if ("FFFF".equals(param.getLightAddress())) { |
| | | oldLightTaskStatusAndPoles = lightTaskPoleRelationService.list(Wrappers.lambdaQuery(LightTaskPoleRelation.class) |
| | | .in(LightTaskPoleRelation::getPoleId, poleIdList).eq(LightTaskPoleRelation::getLightAddress, "0001")); |
| | | List<LightTaskPoleRelation> list = lightTaskPoleRelationService.list(Wrappers.lambdaQuery(LightTaskPoleRelation.class) |
| | | .in(LightTaskPoleRelation::getPoleId, poleIdList).eq(LightTaskPoleRelation::getLightAddress, "0002")); |
| | | oldLightTaskStatusAndPoles.addAll(list); |
| | | } else { |
| | | oldLightTaskStatusAndPoles = lightTaskPoleRelationService.list(Wrappers.lambdaQuery(LightTaskPoleRelation.class) |
| | | .in(LightTaskPoleRelation::getPoleId, poleIdList).eq(LightTaskPoleRelation::getLightAddress, param.getLightAddress())); |
| | | } |
| | | |
| | | /** |
| | | * 新增路灯任务日志记录结束 |
| | | * 重复任务的灯头 |
| | | */ |
| | | List<Long> taskIds = oldLightTaskStatusAndPoles.stream().map(LightTaskPoleRelation::getTaskId).collect(Collectors.toList()); |
| | | List<Long> poleIds = oldLightTaskStatusAndPoles.stream().map(LightTaskPoleRelation::getPoleId).collect(Collectors.toList()); |
| | | //poleIds中重复元素只保留一个 |
| | | taskIds = taskIds.stream().distinct().collect(Collectors.toList()); |
| | | poleIds = poleIds.stream().distinct().collect(Collectors.toList()); |
| | | if (!oldLightTaskStatusAndPoles.isEmpty()) { |
| | | throw new BusinessException("任务中存在已有任务的单灯," + "任务id为{" + taskIds + "}, " |
| | | + "灯杆id为{" + poleIds + "}"); |
| | | } |
| | | |
| | | |
| | | List<LightTaskPoleRelation> newPoleMap = new ArrayList<>(); |
| | | if (!poleIdList.isEmpty()) { |
| | | //新灯杆下发新任务 |
| | | newPoleMap = sendControllerFrame(newLightTask, poleIdList, newLightTask.getFramePayload(), param.getLightAddress()); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 下发路灯任务日志记录开始 |
| | | */ |
| | | |
| | | List<Long> poleIdList = param.getPoleIdList(); |
| | | if (CollectionUtil.isNotEmpty(poleIdList)) { |
| | | String content1 = "{任务ID:" + newLightTask.getTaskId() + ", 任务名:" + newLightTask.getTaskName() + "}," + " 灯杆ID:" + param.getPoleIdList().toString() + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "下发路灯任务", content1); |
| | | /** |
| | | * 下发路灯任务日志记录结束 |
| | | */ |
| | | |
| | | List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, poleIdList, lightTask.getFramePayload(), param.getLightAddress()); |
| | | List<LightTaskPoleRelation> all = new ArrayList<>(); |
| | | all.addAll(newPoleMap); |
| | | int num = (int) newPoleMap.stream().filter(lightTaskPoleRelation -> lightTaskPoleRelation.getIssueStatus() != 0).count(); |
| | | |
| | | // 添加绑定灯杆 |
| | | if (!lightTaskPoleRelationService.saveBatch(lightTaskPoleRelationList)) { |
| | | throw new BusinessException("绑定灯杆失败"); |
| | | } |
| | | |
| | | // 一个灯杆只能使用一个任务,新任务要覆盖旧任务 |
| | | lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, poleIdList).ne(LightTaskPoleRelation::getTaskId, lightTask.getTaskId())); |
| | | |
| | | /** |
| | | * 下发路灯任务日志记录开始 |
| | | */ |
| | | |
| | | String content1 = "{任务ID:" + lightTask.getTaskId() + ", 任务名:" + lightTask.getTaskName() + "}," + " 灯杆ID:" + param.getPoleIdList().toString() + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "下发路灯任务", content1); |
| | | /** |
| | | * 下发路灯任务日志记录结束 |
| | | */ |
| | | //保存新灯杆以及旧灯杆覆盖成功的任务关系 |
| | | if (!all.isEmpty()) { |
| | | lightTaskPoleRelationService.saveBatch(all); |
| | | } |
| | | return true; |
| | | |
| | | if (!param.getPoleIdList().isEmpty() && num == newPoleMap.size()) { |
| | | //所有灯杆都下发失败 新增的任务不保留 |
| | | removeById(newLightTask); |
| | | throw new BusinessException("指令下发失败,请检查灯杆状态后重新新增任务"); |
| | | } else { |
| | | return "任务新增成功"; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String updateLightTask(Long taskId, LightTaskParam param) { |
| | |
| | | |
| | | LightTask newLightTask = new LightTask(); |
| | | newLightTask.setTaskName(param.getTaskName()); |
| | | if (SecurityUtils.getClientId() != null) { |
| | | lightTask.setClientId(clientService.getClientId()); |
| | | lightTask.setUserId(SecurityUtils.getUserId()); |
| | | } |
| | | |
| | | newLightTask.setClientId(clientService.getClientId()); |
| | | newLightTask.setUserId(SecurityUtils.getUserId()); |
| | | |
| | | newLightTask.setWeek(week); |
| | | newLightTask.setCreateUser(SecurityUtils.getUsername()); |
| | | newLightTask.setControlOrder(param.getControlOrder()); |
| | |
| | | |
| | | //编辑后灯杆ID集合 |
| | | List<Long> poleIdList = param.getPoleIdList(); |
| | | if (poleIdList.isEmpty()) { |
| | | throw new BusinessException("编辑任务时请选择灯杆"); |
| | | } |
| | | //记录任务编辑器前灯杆ID集合 |
| | | List<LightTaskStatusAndPole> oldLightTaskStatusAndPoles = lightTaskPoleRelationService.listPoleAndStatusIdByTaskId(taskId); |
| | | List<Long> oldList = oldLightTaskStatusAndPoles.stream().map(LightTaskStatusAndPole::getId).collect(Collectors.toList()); |
| | |
| | | List<Long> closeLight = oldList.stream().filter(poleId -> !param.getPoleIdList().contains(poleId)).collect(Collectors.toList()); |
| | | |
| | | |
| | | //取出覆盖操作的关系信息 |
| | | //记录这些灯杆原先的任务 |
| | | List<LightTaskPoleRelation> oldRelation = new ArrayList<>(); |
| | | if ("FFFF".equals(param.getLightAddress())) { |
| | | // 灯杆中存在其他任务的灯头 |
| | | if (CollectionUtil.isNotEmpty(oldPoleIdList)) { |
| | | oldRelation = lightTaskPoleRelationService.list(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, oldPoleIdList) |
| | | .ne(LightTaskPoleRelation::getTaskId, taskId).eq(LightTaskPoleRelation::getLightAddress, "0001")); |
| | | List<LightTaskPoleRelation> list = lightTaskPoleRelationService.list(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, oldPoleIdList) |
| | | .ne(LightTaskPoleRelation::getTaskId, taskId).eq(LightTaskPoleRelation::getLightAddress, "0002")); |
| | | oldRelation.addAll(list); |
| | | } |
| | | } else { |
| | | if (CollectionUtil.isNotEmpty(oldPoleIdList)) { |
| | | oldRelation = lightTaskPoleRelationService.list(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, oldPoleIdList) |
| | | .ne(LightTaskPoleRelation::getTaskId, taskId).eq(LightTaskPoleRelation::getLightAddress, param.getLightAddress())); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 重复任务的灯头 |
| | | */ |
| | | if (!oldRelation.isEmpty()) { |
| | | List<Long> taskIds = oldRelation.stream().map(LightTaskPoleRelation::getTaskId).collect(Collectors.toList()); |
| | | List<Long> poleIds = oldRelation.stream().map(LightTaskPoleRelation::getPoleId).collect(Collectors.toList()); |
| | | //poleIds中重复元素只保留一个 |
| | | taskIds = taskIds.stream().distinct().collect(Collectors.toList()); |
| | | poleIds = poleIds.stream().distinct().collect(Collectors.toList()); |
| | | throw new BusinessException("任务中存在已有任务的单灯," + "任务id为{" + taskIds + "}, " |
| | | + "灯杆id为{" + poleIds + "}"); |
| | | } |
| | | |
| | | |
| | | List<LightTaskPoleRelation> newPoleAll = new ArrayList<>(); |
| | | List<LightTaskPoleRelation> newPoleSuccess = new ArrayList<>(); |
| | | List<LightTaskPoleRelation> newPoleFail = new ArrayList<>(); |
| | | if (CollectionUtil.isNotEmpty(newPoleIdList)) { |
| | | //新灯杆下发新任务 |
| | | Map<String, List<LightTaskPoleRelation>> newPoleMap = sendControllerFrame(newPoleIdList, lightTask.getFramePayload(), param.getLightAddress()); |
| | | Map<String, List<LightTaskPoleRelation>> newPoleMap = sendControllerFrame(newPoleIdList, newLightTask.getFramePayload(), param.getLightAddress()); |
| | | |
| | | //newPoleAll集合后面用于存储关系表 |
| | | newPoleAll = newPoleMap.getOrDefault("all", new ArrayList<>()); |
| | |
| | | List<LightTaskPoleRelation> oldPoleSuccess = new ArrayList<>(); |
| | | if (CollectionUtil.isNotEmpty(oldPoleIdList)) { |
| | | //覆盖操作灯杆 |
| | | Map<String, List<LightTaskPoleRelation>> oldPoleMap = sendControllerFrame(oldPoleIdList, lightTask.getFramePayload(), param.getLightAddress()); |
| | | Map<String, List<LightTaskPoleRelation>> oldPoleMap = sendControllerFrame(oldPoleIdList, newLightTask.getFramePayload(), param.getLightAddress()); |
| | | oldPoleFail = oldPoleMap.getOrDefault("fail", new ArrayList<>()); |
| | | oldPoleSuccess = oldPoleMap.getOrDefault("success", new ArrayList<>()); |
| | | } |
| | | |
| | | |
| | | List<LightTaskPoleRelation> closePoleFail = new ArrayList<>(); |
| | | List<LightTaskPoleRelation> closePoleSuccess = new ArrayList<>(); |
| | | if (CollectionUtil.isNotEmpty(closeLight)) { |
| | | //执行关灯内帧 |
| | | String framePayloadClose = "7f0000007f173b00"; |
| | | //覆盖操作灯杆 |
| | | System.out.println(closeLight + "closeLight"); |
| | | if (CollectionUtil.isNotEmpty(closeLight) && closeLight != null && closeLight.get(0) != null) { |
| | | //关灯内帧 |
| | | String framePayloadClose = "7F0000007F173B00"; |
| | | //关灯操作灯杆 |
| | | Map<String, List<LightTaskPoleRelation>> closePoleMap = sendControllerFrame(closeLight, framePayloadClose, param.getLightAddress()); |
| | | closePoleFail = closePoleMap.getOrDefault("fail", new ArrayList<>()); |
| | | closePoleSuccess = closePoleMap.getOrDefault("success", new ArrayList<>()); |
| | | } |
| | | |
| | | |
| | | if (closePoleFail.size() == 0 && oldPoleFail.size() == 0) { |
| | | if (closePoleFail.size() == 0) { |
| | | //旧任务中全部发送指令成功,更新原本任务中的数据 |
| | | newLightTask.setTaskId(lightTask.getTaskId()); |
| | | updateById(newLightTask); |
| | | } else { |
| | | if (!newPoleSuccess.isEmpty() || !oldPoleSuccess.isEmpty()) { |
| | | if (!newPoleSuccess.isEmpty()) { |
| | | //有失敗的需要保存旧的任務,新增新的任务数据进行保存 |
| | | save(newLightTask); |
| | | } |
| | |
| | | |
| | | List<LightTaskPoleRelation> all = new ArrayList<>(); |
| | | all.addAll(newPoleSuccess); |
| | | all.addAll(oldPoleFail); |
| | | all.addAll(oldPoleSuccess); |
| | | all.addAll(oldPoleFail); |
| | | all.addAll(closePoleFail); |
| | |
| | | for (LightTaskPoleRelation bean : newPoleSuccess) { |
| | | allPoleId.add(bean.getPoleId()); |
| | | } |
| | | for (LightTaskPoleRelation bean : oldPoleSuccess) { |
| | | allPoleId.add(bean.getPoleId()); |
| | | } |
| | | for (LightTaskPoleRelation bean : oldPoleFail) { |
| | | allPoleId.add(bean.getPoleId()); |
| | | } |
| | | for (LightTaskPoleRelation bean : closePoleSuccess) { |
| | | allPoleId.add(bean.getPoleId()); |
| | | } |
| | | for (LightTaskPoleRelation bean : oldPoleSuccess) { |
| | | allPoleId.add(bean.getPoleId()); |
| | | } |
| | | |
| | |
| | | lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, allPoleId)); |
| | | |
| | | } |
| | | |
| | | if (!all.isEmpty()) { |
| | | lightTaskPoleRelationService.saveBatch(all); |
| | | } |
| | |
| | | * 下发路灯任务日志记录结束 |
| | | */ |
| | | |
| | | if (newPoleFail.isEmpty() && oldPoleFail.isEmpty() && closePoleFail.isEmpty()) { |
| | | if (newPoleFail.isEmpty() && closePoleFail.isEmpty() && oldPoleFail.isEmpty()) { |
| | | return "编辑成功"; |
| | | } else if (newPoleSuccess.isEmpty() && oldPoleSuccess.isEmpty() && closePoleSuccess.isEmpty()) { |
| | | throw new BusinessException("编辑失败,请检查编辑的设备是否在线!"); |
| | | } else if (!closePoleFail.isEmpty() || !oldPoleFail.isEmpty()) { |
| | | } else if (newPoleSuccess.isEmpty() && closePoleSuccess.isEmpty() && oldPoleSuccess.isEmpty()) { |
| | | throw new BusinessException("编辑失败,请检查原有设备和编辑后的设备是否在线!"); |
| | | } else if (!closePoleFail.isEmpty() && !newPoleSuccess.isEmpty() && !oldPoleFail.isEmpty()) { |
| | | return "原任务中存在下发异常,原任务保留,创建新任务进行保存"; |
| | | } else if (!newPoleFail.isEmpty()) { |
| | | } else if (!newPoleFail.isEmpty() && !newPoleSuccess.isEmpty()) { |
| | | return "新任务中存在下发异常,忽略异常操作的灯杆"; |
| | | } else { |
| | | return "操作异常"; |
| | |
| | | */ |
| | | public A5LightTimerRespInnerFrame sendTimeRRpc(String framePayload, String deviceCode, String lightAddress) { |
| | | IRequestFrame requestFrame = FrameBuilder.builderA5().innerFrame(new A5LightTimerReqInnerFrame(framePayload, lightAddress)).orderType(A5OrderEnum.REQUEST_LIGHT_DATA.getCode()).build(); |
| | | System.out.println(requestFrame + " --------requestFrame"); |
| | | |
| | | WrapResponseCommonFrame<A5LightTimerRespInnerFrame> responseCommonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(deviceCode, requestFrame, A5LightTimerRespInnerFrame.class); |
| | | |
| | | System.out.println(responseCommonFrame + " -----------responseCommonFrame"); |
| | | StoreOperationRecordsUtils.storeInnerFrameData(deviceCode, "单灯帧-控灯", requestFrame, responseCommonFrame); |
| | | |
| | | return Optional.ofNullable(responseCommonFrame).map(WrapResponseCommonFrame::getResponseInnerFrame).orElse(null); |
| | | } |
| | | |
| | | 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 = baseMapper.listTask(SecurityUtils.getClientId(),keyword,orderBy); |
| | | List<LightTask> list = baseMapper.listTask(SecurityUtils.getClientId(), keyword, orderBy); |
| | | |
| | | |
| | | Page<LightTaskDto> page = new Page<>(); |
| | |
| | | LightTaskDto lightTaskDto = new LightTaskDto(); |
| | | BeanUtils.copyProperties(lightTask, lightTaskDto); |
| | | lightTaskDto.setWeekList(TaskOrderUtil.parseLightWeek2List(lightTask.getWeek())); |
| | | |
| | | |
| | | //判断灯头是否存在任务 |
| | | List<LightTaskPoleRelation> lightTaskPoleRelationList = lightTaskPoleRelationService.list(Wrappers.<LightTaskPoleRelation>lambdaQuery().eq(LightTaskPoleRelation::getTaskId, lightTask.getTaskId())); |
| | | |
| | | //下发成功的灯杆数量 |
| | | Integer successCount = baseMapper.successCount(lightTaskDto.getTaskId()); |
| | | ///任务中总的灯杆数量 |
| | |
| | | } |
| | | |
| | | for (Pole pole : poles) { |
| | | if (pole.getDeviceCode() == null || pole.getDeviceCode().equals("")) { |
| | | removeById(lightTask.getTaskId()); |
| | | throw new BusinessException("编辑的灯杆或原有任务的灯杆不存在mac,不能下发任务 请检查灯杆是否存在单灯"); |
| | | } |
| | | LightTaskPoleRelation lightTaskPoleRelation = new LightTaskPoleRelation(); |
| | | lightTaskPoleRelation.setPoleId(pole.getId()); |
| | | lightTaskPoleRelation.setTaskId(lightTask.getTaskId()); |
| | | // rrpc 发生定时命令 |
| | | try { |
| | | A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame = sendTimeRRpc(framePayload, pole.getDeviceCode(), lightAddress); |
| | | if (a5LightTimerRespInnerFrame == null) { |
| | | lightTaskPoleRelation.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | } else { |
| | | lightTaskPoleRelation.setIssueStatus(HexUtil.hexToInt(a5LightTimerRespInnerFrame.getResponseStatus())); |
| | | if ("FFFF".equals(lightAddress)) { |
| | | LightTaskPoleRelation lightTaskPoleRelation01 = new LightTaskPoleRelation(); |
| | | lightTaskPoleRelation01.setPoleId(pole.getId()); |
| | | lightTaskPoleRelation01.setTaskId(lightTask.getTaskId()); |
| | | lightTaskPoleRelation01.setLightAddress("0001"); |
| | | |
| | | LightTaskPoleRelation lightTaskPoleRelation02 = new LightTaskPoleRelation(); |
| | | lightTaskPoleRelation02.setPoleId(pole.getId()); |
| | | lightTaskPoleRelation02.setTaskId(lightTask.getTaskId()); |
| | | lightTaskPoleRelation02.setLightAddress("0002"); |
| | | |
| | | // 灯头1 rrpc 发生定时命令 |
| | | try { |
| | | A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame01 = sendTimeRRpc(framePayload, pole.getDeviceCode(), "0001"); |
| | | //灯头1 |
| | | if (a5LightTimerRespInnerFrame01 == null) { |
| | | lightTaskPoleRelation01.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | } else { |
| | | lightTaskPoleRelation01.setIssueStatus(HexUtil.hexToInt(a5LightTimerRespInnerFrame01.getResponseStatus())); |
| | | } |
| | | |
| | | } catch (BusinessException e) { |
| | | lightTaskPoleRelation01.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | } |
| | | } catch (BusinessException e) { |
| | | lightTaskPoleRelation.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | |
| | | // 灯头2 rrpc 发生定时命令 |
| | | try { |
| | | A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame02 = sendTimeRRpc(framePayload, pole.getDeviceCode(), "0002"); |
| | | //灯头2 |
| | | if (a5LightTimerRespInnerFrame02 == null) { |
| | | lightTaskPoleRelation02.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | } else { |
| | | lightTaskPoleRelation02.setIssueStatus(HexUtil.hexToInt(a5LightTimerRespInnerFrame02.getResponseStatus())); |
| | | } |
| | | |
| | | } catch (BusinessException e) { |
| | | lightTaskPoleRelation02.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | } |
| | | |
| | | lightTaskPoleRelationList.add(lightTaskPoleRelation01); |
| | | lightTaskPoleRelationList.add(lightTaskPoleRelation02); |
| | | } else { |
| | | lightTaskPoleRelation.setLightAddress(lightAddress); |
| | | // rrpc 发生定时命令 |
| | | try { |
| | | A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame = sendTimeRRpc(framePayload, pole.getDeviceCode(), lightAddress); |
| | | 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); |
| | | } |
| | | |
| | | lightTaskPoleRelationList.add(lightTaskPoleRelation); |
| | | } |
| | | return lightTaskPoleRelationList; |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | private Map<String, List<LightTaskPoleRelation>> sendControllerFrame(List<Long> poleIdList, String framePayload, String lightAddress) { |
| | | |
| | | System.out.println("framePayload:" + framePayload); |
| | | List<LightTaskPoleRelation> lightTaskPoleRelationList = new ArrayList<>(); |
| | | //成功 |
| | | List<LightTaskPoleRelation> success = new ArrayList<>(); |
| | |
| | | } |
| | | |
| | | for (Pole pole : poles) { |
| | | if (pole.getDeviceCode() == null || pole.getDeviceCode().equals("")) { |
| | | throw new BusinessException("编辑的灯杆或原有任务的灯杆不存在mac,不能下发任务 请检查灯杆是否存在单灯"); |
| | | } |
| | | LightTaskPoleRelation lightTaskPoleRelation = new LightTaskPoleRelation(); |
| | | lightTaskPoleRelation.setPoleId(pole.getId()); |
| | | // lightTaskPoleRelation.setTaskId(lightTask.getTaskId()); |
| | | //关系表插入灯头地址 |
| | | lightTaskPoleRelation.setLightAddress(lightAddress); |
| | | |
| | | |
| | | // rrpc 发生定时命令 |
| | | try { |
| | | A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame = sendTimeRRpc(framePayload, pole.getDeviceCode(), lightAddress); |
| | | if (a5LightTimerRespInnerFrame == null) { |
| | | if ("FFFF".equals(lightAddress)) { |
| | | LightTaskPoleRelation lightTaskPoleRelation01 = new LightTaskPoleRelation(); |
| | | lightTaskPoleRelation01.setPoleId(pole.getId()); |
| | | lightTaskPoleRelation01.setLightAddress("0001"); |
| | | |
| | | LightTaskPoleRelation lightTaskPoleRelation02 = new LightTaskPoleRelation(); |
| | | lightTaskPoleRelation02.setPoleId(pole.getId()); |
| | | lightTaskPoleRelation02.setLightAddress("0002"); |
| | | |
| | | // 灯头1 rrpc 发生定时命令 |
| | | try { |
| | | A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame01 = sendTimeRRpc(framePayload, pole.getDeviceCode(), "0001"); |
| | | //灯头1 |
| | | if (a5LightTimerRespInnerFrame01 == null) { |
| | | lightTaskPoleRelation01.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | fail.add(lightTaskPoleRelation01); |
| | | } else { |
| | | lightTaskPoleRelation01.setIssueStatus(HexUtil.hexToInt(a5LightTimerRespInnerFrame01.getResponseStatus())); |
| | | success.add(lightTaskPoleRelation01); |
| | | } |
| | | |
| | | } catch (BusinessException e) { |
| | | lightTaskPoleRelation01.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | fail.add(lightTaskPoleRelation01); |
| | | } |
| | | |
| | | // 灯头2 rrpc 发生定时命令 |
| | | try { |
| | | A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame02 = sendTimeRRpc(framePayload, pole.getDeviceCode(), "0002"); |
| | | //灯头2 |
| | | if (a5LightTimerRespInnerFrame02 == null) { |
| | | lightTaskPoleRelation02.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | fail.add(lightTaskPoleRelation02); |
| | | } else { |
| | | lightTaskPoleRelation02.setIssueStatus(HexUtil.hexToInt(a5LightTimerRespInnerFrame02.getResponseStatus())); |
| | | success.add(lightTaskPoleRelation02); |
| | | } |
| | | |
| | | } catch (BusinessException e) { |
| | | lightTaskPoleRelation02.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | fail.add(lightTaskPoleRelation02); |
| | | } |
| | | |
| | | lightTaskPoleRelationList.add(lightTaskPoleRelation01); |
| | | lightTaskPoleRelationList.add(lightTaskPoleRelation02); |
| | | } else { |
| | | lightTaskPoleRelation.setLightAddress(lightAddress); |
| | | // rrpc 发生定时命令 |
| | | try { |
| | | A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame = sendTimeRRpc(framePayload, pole.getDeviceCode(), lightAddress); |
| | | if (a5LightTimerRespInnerFrame == null) { |
| | | lightTaskPoleRelation.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | fail.add(lightTaskPoleRelation); |
| | | } else { |
| | | lightTaskPoleRelation.setIssueStatus(HexUtil.hexToInt(a5LightTimerRespInnerFrame.getResponseStatus())); |
| | | success.add(lightTaskPoleRelation); |
| | | } |
| | | } catch (BusinessException e) { |
| | | lightTaskPoleRelation.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | fail.add(lightTaskPoleRelation); |
| | | } else { |
| | | lightTaskPoleRelation.setIssueStatus(HexUtil.hexToInt(a5LightTimerRespInnerFrame.getResponseStatus())); |
| | | success.add(lightTaskPoleRelation); |
| | | } |
| | | } catch (BusinessException e) { |
| | | lightTaskPoleRelation.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | fail.add(lightTaskPoleRelation); |
| | | lightTaskPoleRelationList.add(lightTaskPoleRelation); |
| | | } |
| | | |
| | | lightTaskPoleRelationList.add(lightTaskPoleRelation); |
| | | } |
| | | map.put("success", success); |
| | | map.put("fail", fail); |
| | | map.put("all", lightTaskPoleRelationList); |
| | | log.error("发送控制器帧结果:{}", map); |
| | | return map; |
| | | } |
| | | |
| | |
| | | if (!removeByIds(taskIdList)) { |
| | | 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)); |
| | | }); |
| | | |
| | | /** |
| | | * 删除控灯任务日志记录开始 |