| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.collection.ListUtil; |
| | | import cn.hutool.core.map.MapUtil; |
| | | 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; |
| | | 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.manager.iot.frame.IRequestFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.request.A5LightTimerReqInnerFrame; |
| | |
| | | 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.admin.manager.iot.rrpc.util.SupplementUtils; |
| | | 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.LightTask; |
| | | import com.sandu.ximon.dao.domain.LightTaskPoleRelation; |
| | | import com.sandu.ximon.dao.domain.LightTaskQuartz; |
| | | import com.sandu.ximon.dao.domain.Pole; |
| | | import com.sandu.ximon.dao.enums.DeviceRespStatusEnums; |
| | | import com.sandu.ximon.dao.mapper.LightTaskMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | |
| | | * 路灯任务操作 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | @AllArgsConstructor |
| | | public class LightTaskService extends BaseServiceImpl<LightTaskMapper, LightTask> { |
| | | |
| | | |
| | | private final LightTaskQuartzService lightTaskQuartzService; |
| | | private final PoleService poleService; |
| | | private final LightTaskPoleRelationService lightTaskPoleRelationService; |
| | | private final LightTaskMapper lightTaskMapper; |
| | | |
| | | /** |
| | | * 新增路灯任务 |
| | |
| | | if (StrUtil.length(param.getControlOrder()) % LightTaskParam.REQUEST_ORDER_LENGTH != 0) { |
| | | throw new BusinessException("灯控命令格式不正确"); |
| | | } |
| | | int week = 0; |
| | | for (Integer w : param.getWeekList()) { |
| | | week |= w; |
| | | } |
| | | LightTask lightTask = new LightTask(); |
| | | lightTask.setClientId(SecurityUtils.getClientId()); |
| | | lightTask.setTaskName(param.getTaskName()); |
| | | lightTask.setWeek(param.getWeek()); |
| | | 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)) { |
| | | throw new BusinessException("保存路灯任务失败"); |
| | | } |
| | | List<LightTaskQuartz> list = lightTaskQuartzService.addLightTaskQuartz(lightTask); |
| | | if (CollectionUtil.isEmpty(list)) { |
| | | 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()); |
| | | } |
| | | } |
| | | // 添加绑定灯杆 |
| | | if (!lightTaskPoleRelationService.updateLightTaskPoleRelation(lightTask.getTaskId(), param.getPoleIdList())) { |
| | | throw new BusinessException("绑定灯杆失败"); |
| | | } |
| | | String content = "{任务ID:" + lightTask.getTaskId() |
| | | + ", 任务名:" + lightTask.getTaskName() |
| | | + "},{内帧指令" + lightTask.getFramePayload() |
| | | + ", 灯杆ID:" + param.getPoleIdList().toString() |
| | | + ", 控制的灯头地址:" + param.getLightAddress() |
| | | + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "新增路灯任务", content); |
| | | /** |
| | | * 新增路灯任务日志记录结束 |
| | | */ |
| | | |
| | | List<Long> poleIdList = param.getPoleIdList(); |
| | | if (CollectionUtil.isNotEmpty(poleIdList)) { |
| | | List<String> deviceCodeList = poleService.listDeviceCodeByIds(poleIdList); |
| | | if (CollectionUtil.isEmpty(deviceCodeList)) { |
| | | throw new BusinessException("找不到灯杆mac,无法发送定时任务"); |
| | | } |
| | | // 获取定时灯控命令 |
| | | String framePayload = list.get(0).getFramePayload(); |
| | | |
| | | // rrpc 发生定时命令 |
| | | for (String deviceCode : deviceCodeList) { |
| | | sendTimeRRpc(framePayload, deviceCode); |
| | | List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, poleIdList, lightTask.getFramePayload(), param.getLightAddress()); |
| | | |
| | | // 添加绑定灯杆 |
| | | 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); |
| | | /** |
| | | * 下发路灯任务日志记录结束 |
| | | */ |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 发送灯控请求 |
| | | * |
| | | * @param framePayload 灯控参数 |
| | | * @param deviceCode 设备吗 |
| | | * @return 返回帧 |
| | | */ |
| | | public A5LightTimerRespInnerFrame sendTimeRRpc(String framePayload, String deviceCode) { |
| | | IRequestFrame requestFrame = FrameBuilder.builderA5().innerFrame(new A5LightTimerReqInnerFrame(framePayload)) |
| | | .orderType(A5OrderEnum.REQUEST_LIGHT_DATA.getCode()).build(); |
| | | WrapResponseCommonFrame<A5LightTimerRespInnerFrame> responseCommonFrame = MainBoardInvokeSyncService.getInstance() |
| | | .sendRRPC(deviceCode, requestFrame, A5LightTimerRespInnerFrame.class); |
| | | System.out.println("发送结果"); |
| | | A5LightTimerRespInnerFrame responseInnerFrame = responseCommonFrame.getResponseInnerFrame(); |
| | | System.out.println(responseInnerFrame.getResponseStatus()); |
| | | return responseInnerFrame; |
| | | } |
| | | |
| | | public List<LightTask> listLightTask(int pageNo, int pageSize, String keyword) { |
| | | LambdaQueryWrapper<LightTask> wrapper = Wrappers.lambdaQuery(LightTask.class); |
| | | if (StrUtil.isNotBlank(keyword)) { |
| | | wrapper.like(LightTask::getTaskName, keyword); |
| | | } |
| | | Long clientId = SecurityUtils.getClientId(); |
| | | if (clientId != null) { |
| | | wrapper.eq(LightTask::getClientId, clientId); |
| | | } |
| | | |
| | | PageHelper.startPage(pageNo, pageSize); |
| | | return list(wrapper); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | if (lightTask == null) { |
| | | throw new BusinessException("找不到路灯任务"); |
| | | } |
| | | |
| | | int week = 0; |
| | | for (Integer w : param.getWeekList()) { |
| | | week |= w; |
| | | } |
| | | lightTask.setTaskName(param.getTaskName()); |
| | | lightTask.setWeek(param.getWeek()); |
| | | lightTask.setWeek(week); |
| | | 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)); |
| | | |
| | | if (!updateById(lightTask)) { |
| | | throw new BusinessException("编辑任务失败"); |
| | | } |
| | | |
| | | List<LightTaskQuartz> list = lightTaskQuartzService.updateLightTaskQuartz(lightTask); |
| | | if (CollectionUtil.isEmpty(list)) { |
| | | 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:" + taskId |
| | | + ", 任务名:" + lightTask.getTaskName() |
| | | + "},{内帧指令" + lightTask.getFramePayload() |
| | | + ", 灯杆ID:" + param.getPoleIdList().toString() |
| | | + ", 控制的灯头地址:" + param.getLightAddress() |
| | | + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "编辑路灯任务", content); |
| | | /** |
| | | * 编辑路灯任务日志记录结束 |
| | | */ |
| | | |
| | | // 添加绑定灯杆 |
| | | if (!lightTaskPoleRelationService.updateLightTaskPoleRelation(lightTask.getTaskId(), param.getPoleIdList())) { |
| | | throw new BusinessException("绑定灯杆失败"); |
| | | } |
| | | List<Long> poleIdList = param.getPoleIdList(); |
| | | if (CollectionUtil.isNotEmpty(poleIdList)) { |
| | | List<String> deviceCodeList = poleService.listDeviceCodeByIds(poleIdList); |
| | | if (CollectionUtil.isEmpty(deviceCodeList)) { |
| | | throw new BusinessException("找不到灯杆mac,无法发送定时任务"); |
| | | } |
| | | // 获取定时灯控命令 |
| | | String framePayload = list.get(0).getFramePayload(); |
| | | |
| | | // rrpc 发生定时命令 |
| | | for (String deviceCode : deviceCodeList) { |
| | | sendTimeRRpc(framePayload, deviceCode); |
| | | List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, poleIdList, lightTask.getFramePayload(), param.getLightAddress()); |
| | | |
| | | lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getTaskId, lightTask.getTaskId())); |
| | | // 添加绑定灯杆 |
| | | 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); |
| | | /** |
| | | * 下发路灯任务日志记录结束 |
| | | */ |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 发送灯控请求 |
| | | * |
| | | * @param framePayload 灯控参数 |
| | | * @param deviceCode 设备吗 |
| | | * @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(); |
| | | WrapResponseCommonFrame<A5LightTimerRespInnerFrame> responseCommonFrame = MainBoardInvokeSyncService.getInstance() |
| | | .sendRRPC(deviceCode, requestFrame, A5LightTimerRespInnerFrame.class); |
| | | return Optional.ofNullable(responseCommonFrame).map(WrapResponseCommonFrame::getResponseInnerFrame).orElse(null); |
| | | } |
| | | |
| | | public List<LightTaskDto> listLightTask(BaseConditionVO conditionVO, String keyword) { |
| | | 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()); |
| | | }); |
| | | } |
| | | |
| | | if (conditionVO != null) { |
| | | PageHelper.startPage(conditionVO.getPageNo(), conditionVO.getPageSize()); |
| | | } |
| | | List<LightTask> list = list(wrapper); |
| | | |
| | | Page<LightTaskDto> page = new Page<>(); |
| | | BeanUtils.copyProperties(list, page); |
| | | for (LightTask lightTask : list) { |
| | | LightTaskDto lightTaskDto = new LightTaskDto(); |
| | | BeanUtils.copyProperties(lightTask, lightTaskDto); |
| | | lightTaskDto.setWeekList(TaskOrderUtil.parseLightWeek2List(lightTask.getWeek())); |
| | | page.add(lightTaskDto); |
| | | } |
| | | 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, String lightAddress) { |
| | | List<LightTaskPoleRelation> lightTaskPoleRelationList = new ArrayList<>(); |
| | | |
| | | List<Pole> poles = poleService.listByIds(poleIdList); |
| | | if (CollectionUtil.isEmpty(poles)) { |
| | | return null; |
| | | } |
| | | |
| | | for (Pole pole : poles) { |
| | | 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())); |
| | | } |
| | | } catch (BusinessException e) { |
| | | lightTaskPoleRelation.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode()); |
| | | } |
| | | |
| | | lightTaskPoleRelationList.add(lightTaskPoleRelation); |
| | | } |
| | | return lightTaskPoleRelationList; |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | throw new BusinessException("删除任务失败"); |
| | | } |
| | | |
| | | boolean del; |
| | | // 删除绑定灯杆 |
| | | if (!lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getTaskId, 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; |
| | | } |
| | | |
| | | /** |
| | | * 任务详情 |
| | | */ |
| | | public Map<Object, Object> detailLightTask(Long taskId) { |
| | | LightTask lightTask = getById(taskId); |
| | | if (lightTask == null) { |
| | | throw new BusinessException("找不到任务"); |
| | | } |
| | | List<LightTaskStatusAndPole> lightTaskStatusAndPoles = lightTaskPoleRelationService.listPoleAndStatusIdByTaskId(taskId); |
| | | return MapUtil.builder().put("task", lightTask).put("poles", lightTaskStatusAndPoles).build(); |
| | | } |
| | | |
| | | /** |
| | | * 根据任务信息转成帧负荷 |
| | | * |
| | | * @return 路灯定时器列表 |
| | | */ |
| | | private String buildControlFramePayload(String openOrder, String closeOrder, String controlOrder, Integer week) { |
| | | |
| | | // 添加开灯定时器 |
| | | SingleLightOrderDto openLightOrder = TaskOrderUtil.parseLightOrder(openOrder); |
| | | SingleLightOrderDto closeLightOrder = TaskOrderUtil.parseLightOrder(closeOrder); |
| | | String[] controlOrderArray = StrUtil.split(controlOrder, LightTaskParam.REQUEST_ORDER_LENGTH); |
| | | Integer[] weekArrays = TaskOrderUtil.parseLightCronWeek2List(week).toArray(new Integer[0]); |
| | | if (openLightOrder == null || closeLightOrder == null) { |
| | | throw new BusinessException("解析单灯命令失败"); |
| | | } |
| | | if (ArrayUtil.isEmpty(weekArrays)) { |
| | | throw new BusinessException("请设置星期"); |
| | | } |
| | | |
| | | // 删除定时器 |
| | | if (!lightTaskQuartzService.removeLightTaskQuartz(taskIdList)) { |
| | | throw new BusinessException("删除定时器失败"); |
| | | StringBuilder sb = new StringBuilder(); |
| | | String weekHex = SupplementUtils.suppleZero(HexUtil.toHex(week), 2); |
| | | |
| | | // 拼接开灯命令 |
| | | sb.append(weekHex); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(openLightOrder.getHour()), 2)); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(openLightOrder.getMinute()), 2)); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(openLightOrder.getBrightness()), 2)); |
| | | |
| | | // 拼接关灯命令 |
| | | sb.append(weekHex); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(closeLightOrder.getHour()), 2)); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(closeLightOrder.getMinute()), 2)); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(closeLightOrder.getBrightness()), 2)); |
| | | |
| | | // 拼接亮度控灯命令 |
| | | for (String controlOrderStr : controlOrderArray) { |
| | | SingleLightOrderDto controlLightOrder = TaskOrderUtil.parseLightOrder(controlOrderStr); |
| | | if (controlLightOrder != null) { |
| | | sb.append(weekHex); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(controlLightOrder.getHour()), 2)); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(controlLightOrder.getMinute()), 2)); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(controlLightOrder.getBrightness()), 2)); |
| | | } |
| | | } |
| | | |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 下发单个灯杆的任务 |
| | | */ |
| | | public boolean issueLightTask(LightTaskIssueParam param) { |
| | | LightTask lightTask = getById(param.getTaskId()); |
| | | if (lightTask == null) { |
| | | throw new BusinessException("找不到任务"); |
| | | } |
| | | String framePayload = buildControlFramePayload(lightTask.getOpenOrder(), lightTask.getCloseOrder(), lightTask.getControlOrder(), lightTask.getWeek()); |
| | | List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, ListUtil.toList(param.getPoleId()), framePayload, lightTask.getLightAdress()); |
| | | |
| | | /** |
| | | * 下发路灯任务日志记录开始 |
| | | */ |
| | | List<String> poleCodeList = new ArrayList<>(); |
| | | List<Pole> list = SpringContextHolder.getBean(PoleService.class).list(Wrappers.lambdaQuery(Pole.class).eq(Pole::getId, param.getPoleId())); |
| | | if (CollectionUtil.isNotEmpty(list)) { |
| | | poleCodeList = list.stream().map(Pole::getDeviceCode).collect(Collectors.toList()); |
| | | } |
| | | String content = "{任务ID:" + lightTask.getTaskId() |
| | | + ", 任务名:" + lightTask.getTaskName() |
| | | + "}," + " 灯杆ID:" + param.getPoleId() |
| | | + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "下发路灯任务", content); |
| | | /** |
| | | * 下发路灯任务日志记录结束 |
| | | */ |
| | | |
| | | |
| | | if (CollectionUtil.isNotEmpty(lightTaskPoleRelationList)) { |
| | | return lightTaskPoleRelationService.update(lightTaskPoleRelationList.get(0), |
| | | Wrappers.lambdaUpdate(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getPoleId, param.getPoleId()) |
| | | .eq(LightTaskPoleRelation::getTaskId, param.getTaskId())); |
| | | } |
| | | |
| | | |
| | | return true; |
| | | } |
| | | } |