| | |
| | | import com.github.pagehelper.Page; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | 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.FrameBuilder; |
| | |
| | | import com.sandu.ximon.admin.param.LightTaskIssueParam; |
| | | import com.sandu.ximon.admin.param.LightTaskParam; |
| | | 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.LightTaskStatusAndPole; |
| | | import com.sandu.ximon.dao.domain.Light; |
| | | import com.sandu.ximon.dao.domain.LightTask; |
| | | import com.sandu.ximon.dao.domain.LightTaskPoleRelation; |
| | | import com.sandu.ximon.dao.domain.Pole; |
| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | |
| | | |
| | | private final PoleService poleService; |
| | | private final LightTaskPoleRelationService lightTaskPoleRelationService; |
| | | private final LightTaskMapper lightTaskMapper; |
| | | |
| | | /** |
| | | * 新增路灯任务 |
| | |
| | | lightTask.setClientId(SecurityUtils.getClientId()); |
| | | 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)); |
| | | String framePayload = buildControlFramePayload(param.getOpenOrder(), param.getCloseOrder(), param.getControlOrder(), week); |
| | | lightTask.setFramePayload(framePayload); |
| | | if (!save(lightTask)) { |
| | | throw new BusinessException("保存路灯任务失败"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 新增路灯任务日志记录开始 |
| | | */ |
| | | List<String> poleCodeList = new ArrayList<>(); |
| | | if (CollectionUtil.isNotEmpty(param.getPoleIdList())) { |
| | | List<Pole> poleList = SpringContextHolder.getBean(PoleService.class).listByIds(param.getPoleIdList()); |
| | | if (CollectionUtil.isNotEmpty(poleList)) { |
| | | poleCodeList = poleList.stream().map(Pole::getDeviceCode).collect(Collectors.toList()); |
| | | } |
| | | } |
| | | String content = "{任务ID:" + lightTask.getTaskId() |
| | | + ", 任务名:" + lightTask.getTaskName() |
| | | + "},{内帧指令" + lightTask.getFramePayload() |
| | | + ", 灯杆ID:" + param.getPoleIdList().toString() |
| | | + ", 控制的灯头地址:" + param.getLightAddress() |
| | | + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(poleCodeList.toString(), null, "新增路灯任务", content, poleCodeList.toString()); |
| | | /** |
| | | * 新增路灯任务日志记录结束 |
| | | */ |
| | | |
| | | 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(), param.getLightAddress()); |
| | | |
| | | // 添加绑定灯杆 |
| | | if (!lightTaskPoleRelationService.saveBatch(lightTaskPoleRelationList)) { |
| | |
| | | |
| | | // 一个灯杆只能使用一个任务,新任务要覆盖旧任务 |
| | | lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, poleIdList).ne(LightTaskPoleRelation::getTaskId, lightTask.getTaskId())); |
| | | |
| | | /** |
| | | * 下发路灯任务日志记录开始 |
| | | */ |
| | | |
| | | String content1 = "{任务ID:" + lightTask.getTaskId() |
| | | + ", 任务名:" + lightTask.getTaskName() |
| | | + "},{内帧指令" + lightTask.getFramePayload() |
| | | + ", 灯杆ID:" + param.getPoleIdList().toString() |
| | | + ", 控制的灯头地址:" + param.getLightAddress() |
| | | + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(poleCodeList.toString(), null, "下发路灯任务", content1, poleCodeList.toString()); |
| | | /** |
| | | * 下发路灯任务日志记录结束 |
| | | */ |
| | | } |
| | | return true; |
| | | } |
| | |
| | | lightTask.setControlOrder(param.getControlOrder()); |
| | | lightTask.setOpenOrder(param.getOpenOrder()); |
| | | lightTask.setCloseOrder(param.getCloseOrder()); |
| | | lightTask.setLightAdress(param.getLightAddress()); |
| | | lightTask.setUpdateTime(LocalDateTime.now()); |
| | | lightTask.setFramePayload(buildControlFramePayload(param.getOpenOrder(), param.getCloseOrder(), param.getControlOrder(), week)); |
| | | |
| | |
| | | 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(), param.getLightAddress()); |
| | | |
| | | lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getTaskId, lightTask.getTaskId())); |
| | | // 添加绑定灯杆 |
| | |
| | | * @param deviceCode 设备吗 |
| | | * @return 返回帧 |
| | | */ |
| | | public A5LightTimerRespInnerFrame sendTimeRRpc(String framePayload, String deviceCode) { |
| | | IRequestFrame requestFrame = FrameBuilder.builderA5().innerFrame(new A5LightTimerReqInnerFrame(framePayload)) |
| | | 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(); |
| | | WrapResponseCommonFrame<A5LightTimerRespInnerFrame> responseCommonFrame = MainBoardInvokeSyncService.getInstance() |
| | | .sendRRPC(deviceCode, requestFrame, A5LightTimerRespInnerFrame.class); |
| | | return Optional.ofNullable(responseCommonFrame).map(WrapResponseCommonFrame::getResponseInnerFrame).orElse(null); |
| | | } |
| | | |
| | | public List<LightTaskDto> listLightTask(int pageNo, int pageSize, String keyword) { |
| | | public List<LightTaskDto> listLightTask(BaseConditionVO conditionVO, String keyword) { |
| | | LambdaQueryWrapper<LightTask> wrapper = Wrappers.lambdaQuery(LightTask.class); |
| | | if (StrUtil.isNotBlank(keyword)) { |
| | | wrapper.like(LightTask::getTaskName, keyword); |
| | |
| | | }); |
| | | } |
| | | |
| | | PageHelper.startPage(pageNo, pageSize); |
| | | if (conditionVO != null) { |
| | | PageHelper.startPage(conditionVO.getPageNo(), conditionVO.getPageSize()); |
| | | } |
| | | List<LightTask> list = list(wrapper); |
| | | |
| | | Page<LightTaskDto> page = new Page<>(); |
| | |
| | | return page; |
| | | } |
| | | |
| | | /** |
| | | * 执行中的路灯任务 |
| | | * |
| | | * @return |
| | | */ |
| | | public List<LightTaskDto> listTask() { |
| | | Long clientId = SecurityUtils.getClientId(); |
| | | List<LightTask> lightTasks = lightTaskMapper.listLightTask(clientId); |
| | | Page<LightTaskDto> page = new Page<>(); |
| | | BeanUtils.copyProperties(lightTasks, page); |
| | | for (LightTask lightTask : lightTasks) { |
| | | LightTaskDto lightTaskDto = new LightTaskDto(); |
| | | BeanUtils.copyProperties(lightTask, lightTaskDto); |
| | | lightTaskDto.setWeekList(TaskOrderUtil.parseLightWeek2List(lightTask.getWeek())); |
| | | page.add(lightTaskDto); |
| | | } |
| | | return page; |
| | | } |
| | | |
| | | |
| | | // 每个路灯发送控制帧 返回关联列表 |
| | | private List<LightTaskPoleRelation> sendControllerFrame(LightTask lightTask, List<Long> poleIdList, String framePayload) { |
| | | private List<LightTaskPoleRelation> sendControllerFrame(LightTask lightTask, List<Long> poleIdList, String framePayload, String lightAddress) { |
| | | List<LightTaskPoleRelation> lightTaskPoleRelationList = new ArrayList<>(); |
| | | |
| | | List<Pole> poles = poleService.listByIds(poleIdList); |
| | |
| | | lightTaskPoleRelation.setTaskId(lightTask.getTaskId()); |
| | | // rrpc 发生定时命令 |
| | | try { |
| | | A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame = sendTimeRRpc(framePayload, pole.getDeviceCode()); |
| | | A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame = sendTimeRRpc(framePayload, pole.getDeviceCode(), lightAddress); |
| | | if (a5LightTimerRespInnerFrame == null) { |
| | | lightTaskPoleRelation.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | } else { |
| | |
| | | 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, lightTask.getLightAdress()); |
| | | if (CollectionUtil.isNotEmpty(lightTaskPoleRelationList)) { |
| | | return lightTaskPoleRelationService.update(lightTaskPoleRelationList.get(0), |
| | | Wrappers.lambdaUpdate(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getPoleId, param.getPoleId()) |