2021与蓝度共同重构项目,服务端
liuhaonan
2022-04-21 ccac77fc264074c74cd1c9cf374f26aae45458db
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java
@@ -11,6 +11,7 @@
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.ximon.admin.dto.LightTaskDto;
import com.sandu.ximon.admin.dto.SingleLightOrderDto;
@@ -56,6 +57,7 @@
    private final PoleService poleService;
    private final LightTaskPoleRelationService lightTaskPoleRelationService;
    private final LightTaskMapper lightTaskMapper;
    /**
     * 新增路灯任务
@@ -156,17 +158,21 @@
        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);
        }
        Long clientId = SecurityUtils.getClientId();
        if (clientId != null) {
            wrapper.eq(LightTask::getClientId, clientId);
        //不是超管需要筛选
        if (SecurityUtils.getClientId() != null) {
            wrapper.eq(LightTask::getClientId, SecurityUtils.getUserId()).or(w -> {
                w.eq(LightTask::getUserId, SecurityUtils.getUserId());
            });
        }
        PageHelper.startPage(pageNo, pageSize);
        if (conditionVO != null) {
            PageHelper.startPage(conditionVO.getPageNo(), conditionVO.getPageSize());
        }
        List<LightTask> list = list(wrapper);
        Page<LightTaskDto> page = new Page<>();
@@ -179,6 +185,26 @@
        }
        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) {
@@ -222,10 +248,17 @@
            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;
    }