package com.yfd.platform.modules.patroltask.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfd.platform.config.HttpServerConfig;
import com.yfd.platform.constant.SystemCode;
import com.yfd.platform.modules.basedata.domain.*;
import com.yfd.platform.modules.basedata.mapper.*;
import com.yfd.platform.modules.patroltask.domain.Task;
import com.yfd.platform.modules.patroltask.domain.TaskResult;
import com.yfd.platform.modules.patroltask.domain.TaskTodo;
import com.yfd.platform.modules.patroltask.mapper.TaskMapper;
import com.yfd.platform.modules.patroltask.mapper.TaskResultMapper;
import com.yfd.platform.modules.patroltask.mapper.TaskTodoMapper;
import com.yfd.platform.modules.patroltask.service.ITaskService;
import com.yfd.platform.utils.HttpRESTfulUtils;
import com.yfd.platform.utils.SecurityUtils;
import org.quartz.TriggerUtils;
import org.quartz.impl.triggers.CronTriggerImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

/**
 * <p>
 * 巡视任务表 服务实现类
 * </p>
 *
 * @since 2023-04-08
 */
@Service
@Transactional
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements ITaskService {

    @Resource
    private SubstationMapper substationMapper;

    @Resource
    private SubstationBayMapper substationBayMapper;

    @Resource
    private SubstationMaindeviceMapper substationMaindeviceMapper;

    @Resource
    private SubstationComponentMapper substationComponentMapper;

    @Resource
    private SubstationDeviceMapper substationDeviceMapper;

    @Resource
    private TaskTodoMapper taskTodoMapper;

    @Resource
    private TaskMapper taskMapper;

    @Resource
    private TaskResultMapper taskResultMapper;

    @Resource
    private QuartzMultiTaskManage quartztaskManage;
    @Resource
    private LinkageSignalMapper linkageSignalMapper;
    @Resource
    private HttpServerConfig httpServerConfig;
    @Resource
    private HttpRESTfulUtils httpRESTfulUtils;

    /**********************************
     * 用途说明: 根据变电站Id查询巡视任务
     * 参数说明 stationId
     * 返回值说明: java.util.List<com.yfd.platform.modules.patroltask.domain.Task>
     ***********************************/
    @Override
    public List<Task> getTaskByStationId(String stationId) {
        Substation substation = substationMapper.selectById(stationId);
        if (substation == null) {
            return null;
        }
        String stationCode = substation.getStationCode();
        LambdaQueryWrapper<Task> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Task::getStationCode, stationCode).eq(Task::getDatastatus, "2").eq(Task::getIsenable, "1");
        return this.list(queryWrapper);
    }

    /**********************************
     * 用途说明: 根据Id查询关联信息
     * 参数说明 taskId 任务id
     * 参数说明 deviceLevel 任务类型
     * 返回值说明: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     ***********************************/
    @Override
    public List<Map<String, Object>> getBindInfoById(String id, String deviceLevel) {
        Task task = this.getById(id);
        String deviceList = task.getDeviceList();

        //        String[] split = deviceList.split(",");
        List<Map<String, Object>> mapList = new ArrayList<>();
        if (StrUtil.isBlank(deviceList)) {
            return mapList;
        }
        switch (deviceLevel) {
            case "1":
                mapList.addAll(substationBayMapper.selectMaps(new LambdaQueryWrapper<SubstationBay>().in(SubstationBay::getBayId, StrUtil.split(deviceList, ","))));
                break;
            case "2":
                mapList.addAll(substationMaindeviceMapper.selectMaps(new LambdaQueryWrapper<SubstationMaindevice>().in(SubstationMaindevice::getMainDeviceId, StrUtil.split(deviceList, ","))));
                break;
            case "3":
                mapList.addAll(substationDeviceMapper.selectByIds(deviceList));
                break;
            case "4":
                mapList.addAll(substationComponentMapper.selectMaps(new LambdaQueryWrapper<SubstationComponent>().in(SubstationComponent::getComponentId, StrUtil.split(deviceList, ","))));
                break;
        }
        return mapList;
    }

    /**********************************
     * 用途说明: 新增巡视任务
     * 参数说明 task 巡视任务
     * 返回值说明: boolean
     ***********************************/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addTask(Task task) {
        String id = IdUtil.fastSimpleUUID();
        task.setTaskId(id);
        task.setLastmodifier(SecurityUtils.getCurrentUsername());
        task.setLastmodifydate(new Timestamp(DateUtil.current()));
        task.setIsenable("0");
        task.setDatastatus("1");
        return this.save(task);
    }

    /**********************************
     * 用途说明: 分页查询巡视任务
     * 参数说明 page 分页对象
     * 参数说明 startDate 开始时间
     * 参数说明 endDate 结束时间
     * 参数说明 type 巡视类型
     * 参数说明 taskName 任务名称
     * 参数说明 enable 是否启用
     * 参数说明 taskType 任务类型
     * 参数说明 taskTodoType 任务执行方式
     * 返回值说明: com.baomidou.mybatisplus.extension.plugins.pagination.Page<java.util.Map<java.lang.String,java.lang
     * .Object>>
     ***********************************/
    @Override
    public Page<Map<String, Object>> getTaskList(Page<Map<String, Object>> page,String stationId, String startDate, String endDate,
                                                 String type, String taskName, String enable, String taskType,
                                                 String taskTodoType) throws ParseException {
        Page<Map<String, Object>> mapPage = taskMapper.getTaskList(page,stationId, startDate, endDate, type, taskName, enable,
                taskType, taskTodoType);
        return mapPage;
    }

    /**********************************
     * 用途说明: 根据任务创建待执行计划列表
     * 参数说明 task
     * 返回值说明: void
     ***********************************/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public TaskTodo createRunNowTask(Task task) throws ParseException {
        // 执行类型
        String taskTodoType = task.getTaskTodoType();
        //立即执行
        if ("1".equals(taskTodoType)) {
            Calendar calendar = Calendar.getInstance();
            String planStartTime = DateUtil.formatDateTime(calendar.getTime());
            //避免重复执行冲突
            setToDoTask(task, planStartTime);
        }
        TaskTodo taskTod = taskTodoMapper.selectList(new LambdaQueryWrapper<TaskTodo>().eq(TaskTodo::getTaskId,
                task.getTaskId()).orderByDesc(TaskTodo::getPlanStartTime)).get(0);
        return taskTod;
    }

    /**********************************
     * 用途说明: 发送机巢任务
     * 参数说明 task
     * 返回值说明: com.alibaba.fastjson.JSONObject
     ***********************************/
    private com.alibaba.fastjson.JSONObject sendDockTask(Task task, String planStartTime) {
        String taskTodoType = task.getTaskTodoType();
        //TODO 向机巢发送任务
        String api = "wayline/api/v1/myWayLine/flight-tasks";
        if (StrUtil.isNotBlank(httpServerConfig.getDockServerApp())) {
            api = httpServerConfig.getDockServerApp() + "/" + api;
        }
        Map<String, Object> param = new HashMap<>();
        JSONObject jsonObject = new JSONObject();
        String begin_time = null;
        jsonObject.putOnce("name", task.getTaskName());
        int type = 0;
        List<String> dateList = new ArrayList<>();
        if (!"1".equals(taskTodoType)) {
            type = -1;
            // 将字符串解析为DateTime对象
            DateTime dateTime = DateUtil.parse(planStartTime);

            // 创建日期格式器
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");

            // 分别格式化日期和时间
            dateList.add(dateFormat.format(dateTime));
            begin_time = timeFormat.format(dateTime);
        }
        jsonObject.putOnce(SystemCode.ITEM_BEGIN_TIME.getCode(), begin_time);
        if (dateList.size() > 0) {
            jsonObject.putOnce("day_list", dateList);
        } else {
            jsonObject.putOnce("day_list", null);
        }
        jsonObject.putOnce("task_type", type);
        String dockInfo = task.getDockInfo();
        jsonObject.putAll(JSONUtil.parseObj(dockInfo));
        param.put("params", jsonObject);
        return httpRESTfulUtils.sendHttpPost("json",
                httpServerConfig.getDockServerIp(), httpServerConfig.getDockServerPort(), "", api, param, null);
    }

    /**********************************
     * 用途说明: 根据任务创建待执行计划列表
     * 参数说明 task
     * 返回值说明: void
     ***********************************/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String createTodoTaskList(Task task) throws ParseException {

        // 执行类型
        String taskTodoType = task.getTaskTodoType();

        if ("2".equals(taskTodoType)) {  //定期执行
            String planStartTime = task.getFixedStartTime();//固定时间
            if (StrUtil.isNotEmpty(planStartTime)) {
                return setToDoTask(task, planStartTime);
            }
        }
        if ("3".equals(taskTodoType)) {  //周期执行
            CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
            cronTriggerImpl.setCronExpression(task.getCronValue());
            // 创建一个Calendar对象，获取当前时间，并设置计划生成时段，
            Calendar calendar = Calendar.getInstance();
            Date begindate = calendar.getTime();  //当前时间
            calendar.add(Calendar.DATE, 30); //第30天
            Date enddate = DateUtil.endOfDay(calendar.getTime());
            List<Date> dates = TriggerUtils.computeFireTimesBetween(cronTriggerImpl, null, begindate, enddate);
            String fixedStartTime = task.getFixedStartTime();
            DateTime dateTime = DateUtil.date();
            if (StrUtil.isNotEmpty(fixedStartTime)) {
                dateTime = DateUtil.parse(fixedStartTime);
            }

//            ExecutorService executor = Executors.newFixedThreadPool(10);
//            for (Date plandate : dates) {
//                DateTime finalDateTime = dateTime;
//                executor.submit(() -> {
//                    // 处理开始时间问题
//                    if (finalDateTime.isAfter(plandate)) {
//                        return;
//                    }
//                    if (StrUtil.isNotEmpty(task.getInvalidStartTime()) && StrUtil.isNotEmpty(task.getInvalidEndTime())) {
//                        if (DateUtil.parse(task.getInvalidStartTime()).isBefore(plandate) && DateUtil.parse(task.getInvalidEndTime()).isAfter(plandate)) {
//                            return;
//                        }
//                    }
//                    setToDoTask(task, DateUtil.formatDateTime(plandate));
//                });
//            }
//            // 关闭线程池并等待所有任务完成
//            executor.shutdown();

            for (Date plandate : dates) {
                // 处理开始时间问题
                if (dateTime.isAfter(plandate)) {
                    continue;
                }
                if (StrUtil.isNotEmpty(task.getInvalidStartTime()) && StrUtil.isNotEmpty(task
                        .getInvalidEndTime())) {
                    if (DateUtil.parse(task.getInvalidStartTime()).isBefore(plandate) && DateUtil.parse
                            (task.getInvalidEndTime()).isAfter(plandate)) {
                        continue;
                    }
                }
                setToDoTask(task, DateUtil.formatDateTime(plandate));
            }
        }
        return "";
    }

    @Override
    public void createOnceTodoTask(String taskId) throws ParseException {
        Task task = this.getById(taskId);
        if (task == null) {
            return;
        }
        if ("3".equals(task.getTaskTodoType())) {
            //周期执行
            CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
            cronTriggerImpl.setCronExpression(task.getCronValue());
            // 创建一个Calendar对象，获取当前时间，并设置计划生成时段，
            Calendar calendar = Calendar.getInstance();
            Date begindate = calendar.getTime();  //当前时间
            calendar.add(Calendar.DATE, 30); //第30天
            Date enddate = DateUtil.endOfDay(calendar.getTime());
            List<Date> dates = TriggerUtils.computeFireTimesBetween(cronTriggerImpl, null, begindate, enddate);
            String fixedStartTime = task.getFixedStartTime();
            DateTime dateTime = DateUtil.date();
            if (StrUtil.isNotEmpty(fixedStartTime)) {
                dateTime = DateUtil.parse(fixedStartTime);
            }
            for (Date plandate : dates) {
                // 处理开始时间问题
                if (dateTime.isAfter(plandate)) {
                    continue;
                }
                if (StrUtil.isNotEmpty(task.getInvalidStartTime()) && StrUtil.isNotEmpty(task.getInvalidEndTime())) {
                    if (DateUtil.parse(task.getInvalidStartTime()).isBefore(plandate) && DateUtil.parse
                            (task.getInvalidEndTime()).isAfter(plandate)) {
                        continue;
                    }
                }
                String dateFormat = DateUtil.formatDateTime(plandate);
                Integer integer =
                        taskTodoMapper.selectCount(new LambdaQueryWrapper<TaskTodo>().eq(TaskTodo::getPlanStartTime, dateFormat).eq(TaskTodo::getTaskId, task.getTaskId()));
                if (integer > 0) {
                    continue;
                }
                setToDoTask(task, dateFormat);
                break;
            }
        }
    }

    /**********************************
     * 用途说明: 根据任务创建对应一条代办任务清单，
     * 参数说明 task 任务，planStartTime 计划开始时间 taskTodoType:
     * 返回值说明: void
     ***********************************/
    private String setToDoTask(Task task, String planStartTime) {

        TaskTodo taskTodo = new TaskTodo();
        String dockInfo = task.getDockInfo();

        // ID
        String taskTodoId = IdUtil.fastSimpleUUID();
        taskTodo.setTaskTodoId(taskTodoId);
        if (StrUtil.isNotBlank(dockInfo) && JSONUtil.isTypeJSONObject(dockInfo)) {
            com.alibaba.fastjson.JSONObject jsonObject = sendDockTask(task, planStartTime);
            if (SystemCode.SUCCESS_STATUS_CODE.getCode().equals(jsonObject.getString("code"))) {
                taskTodo.setTaskTodoId(jsonObject.getString("msg"));
            }
        }
        // ID
        taskTodo.setDockInfo(task.getDockInfo());
        // 任务id
        taskTodo.setTaskId(task.getTaskId());
        // 机器人/无人机编码
        taskTodo.setRobotCode(task.getRobotCode());
        // 变电站代码
        taskTodo.setStationCode(task.getStationCode());
        // 巡视类型
        taskTodo.setType(task.getType());
        // 任务名称
        String taskName = task.getTaskName();
        taskTodo.setTaskName(taskName);
        // 任务编码
        String taskCode = task.getTaskCode();
        taskTodo.setTaskCode(taskCode);
        // 任务类型
        String taskType = task.getTaskType();
        taskTodo.setTaskType(taskType);
        // 优先级
        String priority = task.getPriority();
        taskTodo.setPriority(priority);
        // 任务状态：初始为0 待执行
        taskTodo.setTaskState("0");
        // 计划执行时间
        taskTodo.setPlanStartTime(planStartTime);
        // 执行进度：初始为0
        taskTodo.setTaskProgress("0");
        // 监控索引号
        taskTodo.setControlNum(task.getControlNum());
        // 任务类别 1-摄像机任务 2-机器人任务 3-无人机
        taskTodo.setTaskClass(task.getTaskClass());
        // 机器人或者无人绑定的线路ID
        taskTodo.setTaskLineid(task.getTaskLineid());
        // 机器人/无人机编码
        taskTodo.setRobotCode(task.getRobotCode());
        taskTodo.setDeviceFailureNum(0);
        taskTodo.setDeviceDeforeNum(0);
        taskTodo.setDeviceUnusualnum(0);
        // 执行进度：剩余时间
        taskTodo.setTaskEstimatedTime("100");
        // 创建人
        taskTodo.setLastmodifier("定时创建");
        // 创建时间
        taskTodo.setLastmodifydate(new Timestamp(DateUtil.current()));
        // 数据状态： 1 有效
        taskTodo.setDatastatus("1");
        String deviceList = task.getDeviceList();
        //        String[] device = deviceList.split(",");
        List<String> idList = StrUtil.split(deviceList, ",");
        // 绑定类型
        Integer deviceLevel = task.getDeviceLevel();
        List<SubstationDevice> substationDevices = new ArrayList<>();
        switch (deviceLevel) {
            case 1:
                substationDevices.addAll(substationDeviceMapper.selectList(new LambdaQueryWrapper<SubstationDevice>().in(SubstationDevice::getBayId, StrUtil.split(deviceList, ","))));
                break;
            case 2:
                substationDevices.addAll(substationDeviceMapper.selectList(new LambdaQueryWrapper<SubstationDevice>().in(SubstationDevice::getMainDeviceId, StrUtil.split(deviceList, ","))));
                break;
            case 3:
                substationDevices.addAll(substationDeviceMapper.selectByIdList(deviceList));
                break;
            case 4:
                substationDevices.addAll(substationDeviceMapper.selectList(new LambdaQueryWrapper<SubstationDevice>().in(SubstationDevice::getComponentId, StrUtil.split(deviceList, ","))));
                break;
            default:
                break;
        }
        // 巡视点位数量
        // 一键顺控和普通任务区分
        if ("4".equals(task.getTaskType())) {
            LinkageSignal linkageSignal =
                    linkageSignalMapper.selectOne(new LambdaQueryWrapper<LinkageSignal>().eq(LinkageSignal::getControlNum
                            , task.getControlNum()));
            if ("1".equals(linkageSignal.getLinkageType())) {
                int min = Math.min(substationDevices.size(), 3);
                taskTodo.setDeviceSumnum(min);
//                taskTodo.setDeviceSumnum(1);
            } else {
                int sum = 0;
                for (SubstationDevice substationDevice : substationDevices) {
                    String patroldeviceJson = substationDevice.getPatroldeviceJson();
                    JSONArray jsonArray = JSONUtil.parseArray(patroldeviceJson);
                    sum += jsonArray.size();
                }
                taskTodo.setDeviceSumnum(sum);
            }
        } else {
            int sum = 0;
            for (SubstationDevice substationDevice : substationDevices) {
                String patroldeviceJson = substationDevice.getPatroldeviceJson();
                JSONArray jsonArray = JSONUtil.parseArray(patroldeviceJson);
                sum += jsonArray.size();
            }
            taskTodo.setDeviceSumnum(sum);
        }
        //        int sum = 0;
        //        for (SubstationDevice substationDevice : substationDevices) {
        //            String patroldeviceJson = substationDevice.getPatroldeviceJson();
        //            JSONArray jsonArray = JSONUtil.parseArray(patroldeviceJson);
        //            sum += jsonArray.size();
        //        }
        //        taskTodo.setDeviceSumnum(sum);
        // 插入待执行任务（单条）
        taskTodoMapper.insert(taskTodo);

        int ordernum = 0;
        List<TaskResult> results = new ArrayList<>();
        for (SubstationDevice substationDevice : substationDevices) {
            //修改为同一点位非同源任务
            String json = substationDevice.getPatroldeviceJson();
            JSONArray jsonArray = new JSONArray();
            if (JSONUtil.isTypeJSONObject(json)) {
                //赋值到数组中
                jsonArray.add(JSONUtil.parseObj(json));
            } else if (JSONUtil.isTypeJSONArray(json)) {
                jsonArray.addAll(JSONUtil.parseArray(json));
            } else {
                //跳过
                continue;
            }
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jobj = jsonArray.getJSONObject(i);
                TaskResult taskResult = new TaskResult();
                String uuid = IdUtil.fastSimpleUUID();
                taskResult.setResultId(uuid);
                taskResult.setTaskTodoId(taskTodo.getTaskTodoId());
                taskResult.setStationCode(taskTodo.getStationCode());
                // 机器人/无人机编码

                taskResult.setTaskName(taskName);
                taskResult.setTaskCode(taskCode);
                ordernum++;
                taskResult.setOrderNum(ordernum);
                taskResult.setVoiceAnalysisTypeList(substationDevice.getVoiceAnalysisTypeList());
                // 点位id
                String deviceId = substationDevice.getDeviceId();
                taskResult.setDeviceId(deviceId);
                // 点位名称
                String deviceName = substationDevice.getDeviceName();
                taskResult.setDeviceName(deviceName);
                // 部件id
                String componentId = substationDevice.getComponentId();
                taskResult.setComponentId(componentId);
                // 部件名称
                String componentName = substationDevice.getComponentName();
                taskResult.setComponentName(componentName);
                // 区域id
                String areaId = substationDevice.getAreaId();
                taskResult.setAreaId(areaId);
                // 区域名称
                String areaName = substationDevice.getAreaName();
                taskResult.setAreaName(areaName);
                // 间隔id
                String bayId = substationDevice.getBayId();
                taskResult.setBayId(bayId);
                // 间隔名称
                String bayName = substationDevice.getBayName();
                taskResult.setBayName(bayName);
                // 主设备id
                String mainDeviceId = substationDevice.getMainDeviceId();
                taskResult.setMainDeviceId(mainDeviceId);
                // 主设备名称
                String mainDeviceName = substationDevice.getMainDeviceName();
                taskResult.setMainDeviceName(mainDeviceName);
                // 主设备名称
                String recognitionTypeList = substationDevice.getRecognitionTypeList();
                taskResult.setRecognitionType(recognitionTypeList);
                // 单位
                String unit = substationDevice.getUnit();
                taskResult.setUnit(unit);
                // 是否报警
                String isAlarm = substationDevice.getIsAlarm();
                taskResult.setIsAlarm(isAlarm);

                // 相位
                taskResult.setPhase(substationDevice.getPhase());

                //数据来源
                String dataType = substationDevice.getDataType();
                taskResult.setDataType(dataType);
                //摄像头 及预置位
                taskResult.setRobotCode(jobj.getStr("robot_code"));
                //相机参数[{"patroldevice_name":"1","patroldevice_code":"","patroldevice_channelcode":"","patroldevice_pos":"","pos_name":"","baseimage":"","effective_region":[{"x1":"","y1":""},{"x2":"","y2":""}]}]
                taskResult.setPatroldeviceName(jobj.getStr("patroldevice_name"));
                taskResult.setPatroldeviceCode(jobj.getStr("patroldevice_code"));
                String patroldeviceChannelcode = jobj.getStr("patroldevice_channelcode");
                if (StrUtil.isBlank(patroldeviceChannelcode)) {
                    patroldeviceChannelcode = taskResult.getPatroldeviceCode();
                }
                taskResult.setPatroldeviceChannelcode(patroldeviceChannelcode);
                taskResult.setPatroldevicePos(jobj.getStr("patroldevice_pos"));
                taskResult.setPatroldeviceBaseimage(jobj.getStr("device_baseimage"));
                taskResult.setPatroldeviceEffectiveregion(jobj.getStr("effective_region"));
                //创建时间，创建者
                taskResult.setLastmodifier("定时创建");
                taskResult.setLastmodifydate(new Timestamp(DateUtil.current()));
                //初始创建
                taskResult.setDatastatus("1");
                //未执行
                taskResult.setFlag("0");

                //实物ID 待扩展
                taskResult.setMaterialId("");
                //文件类型
                taskResult.setFileType(substationDevice.getSaveTypeList());
                // 新增任务执行结果(初始值)
                //                taskResultMapper.insert(taskResult);
                results.add(taskResult);
            }
        }
        taskResultMapper.batchAdd(results);
        //重点 QuartzTaskManage
        String taskTodoType = task.getTaskTodoType();
        if ("2".equals(taskTodoType) || "3".equals(taskTodoType)) {
            quartztaskManage.addJob(taskTodo);
        }
        return taskTodoId;
    }

    /**********************************
     * 用途说明: 删除大于当前时间的待执行计划列表
     * 参数说明 task
     * 返回值说明: void
     ***********************************/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteTodoTasks(Task task) {
        taskTodoMapper.delete(new LambdaQueryWrapper<TaskTodo>().eq(TaskTodo::getTaskId, task.getTaskId()).isNull(TaskTodo::getStartTime).gt(TaskTodo::getPlanStartTime, DateUtil.now()));
    }

}
