| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.map.MapUtil; |
| | | 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.service.impl.BaseServiceImpl; |
| | | import com.sandu.ximon.admin.dto.LightTaskDto; |
| | | 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.mainboard.MainBoardInvokeSyncService; |
| | | import com.sandu.ximon.admin.param.LightTaskParam; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.utils.TaskOrderUtil; |
| | | 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.mapper.LightTaskMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | |
| | | private final PoleService poleService; |
| | | private final LightTaskPoleRelationService lightTaskPoleRelationService; |
| | | |
| | | |
| | | /** |
| | | * 新增路灯任务 |
| | | */ |
| | |
| | | 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.setCloseOrder(param.getCloseOrder()); |
| | | lightTask.setOpenOrder(param.getOpenOrder()); |
| | | lightTask.setControlOrder(param.getControlOrder()); |
| | |
| | | return responseInnerFrame; |
| | | } |
| | | |
| | | public List<LightTask> listLightTask(int pageNo, int pageSize, String keyword) { |
| | | public List<LightTaskDto> listLightTask(int pageNo, int pageSize, String keyword) { |
| | | LambdaQueryWrapper<LightTask> wrapper = Wrappers.lambdaQuery(LightTask.class); |
| | | if (StrUtil.isNotBlank(keyword)) { |
| | | wrapper.like(LightTask::getTaskName, keyword); |
| | |
| | | } |
| | | |
| | | PageHelper.startPage(pageNo, pageSize); |
| | | return list(wrapper); |
| | | 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; |
| | | } |
| | | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateLightTask(Long taskId, LightTaskParam param) { |
| | |
| | | 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()); |
| | |
| | | |
| | | return true; |
| | | } |
| | | |
| | | public Map<Object, Object> detailLightTask(Long taskId) { |
| | | LightTask lightTask = getById(taskId); |
| | | if(lightTask == null){ |
| | | throw new BusinessException("找不到任务"); |
| | | } |
| | | List<Long> poleIdList = lightTaskPoleRelationService.listPoleIdByTaskId(taskId); |
| | | List<Pole> poles = poleService.listByIds(poleIdList); |
| | | return MapUtil.builder().put("task",lightTask).put("poles",poles).build(); |
| | | } |
| | | } |