| | |
| | | import com.sandu.common.util.SpringContextHolder; |
| | | import com.sandu.ximon.admin.dto.LightTaskDto; |
| | | import com.sandu.ximon.admin.dto.SingleLightOrderDto; |
| | | import com.sandu.ximon.admin.manager.iot.frame.A5Frame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.FrameBuilder; |
| | | import com.sandu.ximon.admin.manager.iot.frame.IRequestFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.request.A5LightTimerReqInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.response.A5LightTimerRespInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.dto.CommonFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.dto.WrapResponseCommonFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.A5OrderEnum; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService; |
| | |
| | | import com.sandu.ximon.dao.domain.LightTaskPoleRelation; |
| | | import com.sandu.ximon.dao.domain.Pole; |
| | | import com.sandu.ximon.dao.enums.DeviceRespStatusEnums; |
| | | import com.sandu.ximon.dao.enums.OrderByEnums; |
| | | import com.sandu.ximon.dao.mapper.LightTaskMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateLightTask(Long taskId, LightTaskParam param) { |
| | | public String updateLightTask(Long taskId, LightTaskParam param) { |
| | | if (StrUtil.length(param.getControlOrder()) % LightTaskParam.REQUEST_ORDER_LENGTH != 0) { |
| | | throw new BusinessException("灯控命令格式不正确"); |
| | | } |
| | |
| | | |
| | | |
| | | 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()); |
| | | |
| | | //newPoleAll集合后面用于存储关系表 |
| | | newPoleAll = newPoleMap.getOrDefault("all", new ArrayList<>()); |
| | | newPoleSuccess = newPoleMap.getOrDefault("success", new ArrayList<>()); |
| | | newPoleFail = newPoleMap.getOrDefault("fail", new ArrayList<>()); |
| | | } |
| | | |
| | | List<LightTaskPoleRelation> oldPoleFail = new ArrayList<>(); |
| | |
| | | } |
| | | |
| | | List<LightTaskPoleRelation> closePoleFail = new ArrayList<>(); |
| | | List<LightTaskPoleRelation> closePoleSuccess = new ArrayList<>(); |
| | | if (CollectionUtil.isNotEmpty(closeLight)) { |
| | | //执行关灯内帧 |
| | | 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) { |
| | | //旧任务中全部发送指令成功,更新原本任务中的数据 |
| | | newLightTask.setTaskId(lightTask.getTaskId()); |
| | | updateById(newLightTask); |
| | | } else { |
| | | save(newLightTask); |
| | | if (!newPoleSuccess.isEmpty() || !oldPoleSuccess.isEmpty()) { |
| | | //有失敗的需要保存旧的任務,新增新的任务数据进行保存 |
| | | save(newLightTask); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | poleCodeList = poleList.stream().map(Pole::getDeviceCode).collect(Collectors.toList()); |
| | | } |
| | | } |
| | | String content = "{任务ID:" + newLightTask.getTaskId() |
| | | + ", 任务名:" + newLightTask.getTaskName() |
| | | + "},{内帧指令" + newLightTask.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); |
| | | /** |
| | | * 编辑路灯任务日志记录结束 |
| | | */ |
| | | |
| | | for (LightTaskPoleRelation bean : newPoleAll) { |
| | | for (LightTaskPoleRelation bean : newPoleSuccess) { |
| | | bean.setTaskId(newLightTask.getTaskId()); |
| | | } |
| | | //成功用新的任务ID |
| | |
| | | } |
| | | |
| | | List<LightTaskPoleRelation> all = new ArrayList<>(); |
| | | all.addAll(newPoleAll); |
| | | all.addAll(newPoleSuccess); |
| | | all.addAll(oldPoleSuccess); |
| | | all.addAll(oldPoleFail); |
| | | all.addAll(closePoleFail); |
| | | |
| | | |
| | | List<Long> allPoleId = new ArrayList<>(); |
| | | allPoleId.addAll(poleIdList); |
| | | allPoleId.addAll(oldList); |
| | | lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, allPoleId)); |
| | | lightTaskPoleRelationService.saveBatch(all); |
| | | 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()); |
| | | } |
| | | |
| | | if (!allPoleId.isEmpty()) { |
| | | lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, allPoleId)); |
| | | |
| | | } |
| | | if (!all.isEmpty()) { |
| | | lightTaskPoleRelationService.saveBatch(all); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 下发路灯任务日志记录开始 |
| | | */ |
| | | String content1 = "{任务ID:" + newLightTask.getTaskId() |
| | | + ", 任务名:" + newLightTask.getTaskName() |
| | | + "}," + " 灯杆ID:" + param.getPoleIdList().toString() |
| | | + " }"; |
| | | String content1 = "{任务ID:" + newLightTask.getTaskId() + ", 任务名:" + newLightTask.getTaskName() + "}," + " 灯杆ID:" + param.getPoleIdList().toString() + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "下发路灯任务", content1); |
| | | /** |
| | | * 下发路灯任务日志记录结束 |
| | | */ |
| | | |
| | | return true; |
| | | // 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("编辑失败"); |
| | | } else if (!closePoleFail.isEmpty() || !oldPoleFail.isEmpty()) { |
| | | return "原任务中存在下发异常,原任务保留,创建新任务进行保存"; |
| | | } else if (!newPoleFail.isEmpty()) { |
| | | return "新任务中存在下发异常,忽略异常操作的灯杆"; |
| | | } else { |
| | | return "操作异常"; |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | return Optional.ofNullable(responseCommonFrame).map(WrapResponseCommonFrame::getResponseInnerFrame).orElse(null); |
| | | } |
| | | |
| | | public List<LightTaskDto> listLightTask(BaseConditionVO conditionVO, String keyword) { |
| | | 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 (conditionVO != null) { |
| | | PageHelper.startPage(conditionVO.getPageNo(), conditionVO.getPageSize()); |
| | | //排序字段 |
| | | String orderByResult = OrderByEnums.LIGHT_TASK_UPDATE_TIME.getCode(); |
| | | //正序、倒叙 |
| | | String orderBySeq = OrderByEnums.ASC.getCode(); |
| | | if (order != null) { |
| | | switch (order) { |
| | | case 1: |
| | | orderByResult = OrderByEnums.LIGHT_TASK_UPDATE_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(conditionVO.getPageNo(), conditionVO.getPageSize(), orderBy); |
| | | List<LightTask> list = list(wrapper); |
| | | |
| | | Page<LightTaskDto> page = new Page<>(); |