package xiaoqu.home.open.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import xiaoqu.home.open.entity.XxlJobInfo;
import xiaoqu.home.open.model.db2.Holiday;
import xiaoqu.home.open.model.db2.Plan;
import xiaoqu.home.open.model.db2.PlanScenes;
import xiaoqu.home.open.service.RedisService4;
import xiaoqu.home.open.service.RedisService5;
import xiaoqu.home.open.service.db2.HolidayService;
import xiaoqu.home.open.service.db2.PlanScenesService;
import xiaoqu.home.open.service.db2.PlanService;
import xiaoqu.home.open.utils.DateToConverter;
import xiaoqu.home.open.utils.WrapperUtils;
import xiaoqu.home.open.utils.XxlJobUtil;

import java.util.*;

/**
 * 设置禁用时间
 * 生成后续计划时间
 * 计划计次
 */
@Component
@Slf4j(topic = "Controller")
public class PlanTimeTask {


    @Autowired
    private HolidayService holidayService;
    @Autowired
    private PlanService planService;
    @Autowired
    private XxlJobUtil xxlJobUtil;
    @Autowired
    private PlanScenesService planScenesService;
    @Autowired
    private RedisService5 redisService5;

    @Autowired
    RedisService4 redisService4;

    /**
     * 计划起止/设备维护任务禁用
     *
     * @return
     */
    @XxlJob("planDisableTask")
    public ReturnT<String> planDisableTask() {
        String jobParam = XxlJobHelper.getJobParam();
        log.info("【planDisableTask】计划起止" + jobParam);
        if (jobParam != null) {
            String[] params = jobParam.split("--");
//            Map<String, Object> paramMap = new HashMap<String, Object>();
            QueryWrapper<Plan> wrapper = WrapperUtils.getWrapper(false);

            //设备维护类任务
            if (params.length == 2) {
                //start
                if (params[1].equals("1")) {
                    wrapper.eq("action_end_time", params[0]);

                } else if (params[1].equals("0")) {
                    wrapper.eq("action_start_time", params[0]);
                }
                wrapper.eq("status", 1);

                List<Plan> list = planService.list(wrapper);
                if (list.isEmpty()) {
                    //任务调度器任务id
                    String taskId = redisService4.get("planDisableTask:" + params[1] + ":" + params[0]);
                    redisService4.remove("devOpsDisable:" + params[1] + ":" + params[0]);
                    xxlJobUtil.removeTask(Integer.parseInt(taskId));

                }
                for (Plan plan : list) {
                    if (params[1].equals("1")) {
                        if (plan.getActionEndTime().equals(params[0])) {
                            //站点
                            if (plan.getPackageStatus() == 0) {
                                log.info("【planDisableTask】Disable:d:" + plan.getDistrictId() + ":" + plan.getTaskTypeId());

                                redisService4.set("Disable:d:" + plan.getDistrictId() + ":" + plan.getTaskTypeId(), "1");
                                //厕所
                            } else {

                                QueryWrapper<PlanScenes> planscenesWrapper = WrapperUtils.getWrapper(false);
                                planscenesWrapper.eq("plan_id", plan.getId());

                                List<PlanScenes> planSceneslist = planScenesService.list(planscenesWrapper);
                                for (PlanScenes planScenes : planSceneslist) {
                                    if (planScenes.getScenesLevel() == 1) {
                                        log.info("【planDisableTask】Disable:t:" + planScenes.getScenesId() + ":" + plan.getTaskTypeId());
                                        redisService4.set("Disable:t:" + planScenes.getScenesId() + ":" + plan.getTaskTypeId(), "1");
                                    } else {
                                        redisService4.set("Disable:p:" + planScenes.getScenesId() + ":" + plan.getTaskTypeId(), "1");

                                    }

                                }

                            }
                        }
                    } else if (params[1].equals("0")) {
                        if (plan.getActionStartTime().equals(params[0])) {
                            if (plan.getPackageStatus() == 0) {
                                log.info("【planDisableTask】Disable:d:" + plan.getDistrictId() + ":" + plan.getTaskTypeId());
                                redisService4.set("Disable:d:" + plan.getDistrictId() + ":" + plan.getTaskTypeId(), "0");
                                String taskCommand = redisService4.rightPop("RebuildTask:d:" + plan.getDistrictId() + ":" + plan.getTaskTypeId());
                                while (taskCommand != null) {
                                    redisService5.lPush("taskCommand", taskCommand);
                                    taskCommand = redisService4.rightPop("RebuildTask:d:" + plan.getDistrictId() + ":" + plan.getTaskTypeId());
                                }
                                //重新生成任务 待定
//                                String assignmentString = redisTemplate.opsForList().rightPop("RebuildAssignment:d:" + assignmentDisableSetting.getDistrictId() + ":" + assignmentDisableSetting.getAssignmentType());
//                                while (assignmentString != null) {
//                                    Assignment assignment = JSONObject.parseObject(assignmentString, Assignment.class);
//                                    HardwareVar hardwareVarBySncode = hardwareVarService.getHardwareVarBySncode(assignment.getSnCode());
//                                    DistrictStrategy districtStrategy = districtStrategyService.selectByPrimaryKey(assignment.getDistrictId());
//                                    if (assignment.getTypeId() == 8) {
//                                        if (hardwareVarBySncode.getPaperSurplus() < districtStrategy.getWarning()) {
//                                            assignmentService.rebuildAssignment(assignment);
//                                        }
//                                    } else if (assignment.getTypeId() == 9) {
//                                        if (hardwareVarBySncode.getPowerSupply() <= 15) {
//                                            assignmentService.rebuildAssignment(assignment);
//                                        }
//                                    }
//
//
//                                    assignmentString = redisTemplate.opsForList().rightPop("RebuildAssignment:d:" + assignmentDisableSetting.getDistrictId() + ":" + assignmentDisableSetting.getAssignmentType());
//                                }

                            } else {
                                QueryWrapper<PlanScenes> planscenesWrapper = WrapperUtils.getWrapper(false);
                                planscenesWrapper.eq("plan_id", plan.getId());

                                List<PlanScenes> planSceneslist = planScenesService.list(planscenesWrapper);
                                for (PlanScenes planScenes : planSceneslist) {
                                    if (planScenes.getScenesLevel() == 1) {
                                        log.info("【planDisableTask】Disable:t:" + planScenes.getScenesId() + ":" + plan.getTaskTypeId());
                                        redisService4.set("Disable:t:" + planScenes.getScenesId() + ":" + plan.getTaskTypeId(), "0");

                                        String taskCommand = redisService4.rightPop("RebuildTask:t:" + planScenes.getScenesId() + ":" + plan.getTaskTypeId());
                                        while (taskCommand != null) {
                                            redisService5.lPush("taskCommand", taskCommand);
                                            taskCommand = redisService4.rightPop("RebuildTask:t:" + planScenes.getScenesId() + ":" + plan.getTaskTypeId());
                                        }

                                    } else {
                                        redisService4.set("Disable:p:" + planScenes.getScenesId() + ":" + plan.getTaskTypeId(), "0");

                                        String taskCommand = redisService4.rightPop("RebuildTask:p:" + planScenes.getScenesId() + ":" + plan.getTaskTypeId());
                                        while (taskCommand != null) {
                                            redisService5.lPush("taskCommand", taskCommand);
                                            taskCommand = redisService4.rightPop("RebuildTask:p:" + planScenes.getScenesId() + ":" + plan.getTaskTypeId());
                                        }

                                    }
                                }
//                                //重新生成任务
//                                String assignmentString = redisTemplate.opsForList().rightPop("RebuildAssignment:t:" + assignmentDisableSetting.getToiletId() + ":" + assignmentDisableSetting.getAssignmentType());
//                                while (assignmentString != null) {
//                                    Assignment assignment = JSONObject.parseObject(assignmentString, Assignment.class);
//                                    HardwareVar hardwareVarBySncode = hardwareVarService.getHardwareVarBySncode(assignment.getSnCode());
//                                    DistrictStrategy districtStrategy = districtStrategyService.selectByPrimaryKey(assignment.getDistrictId());
//                                    if (assignment.getTypeId() == 8) {
//                                        if (hardwareVarBySncode.getPaperSurplus() < districtStrategy.getWarning()) {
//                                            assignmentService.rebuildAssignment(assignment);
//                                        }
//                                    } else if (assignment.getTypeId() == 9) {
//                                        if (hardwareVarBySncode.getPowerSupply() <= 15) {
//                                            assignmentService.rebuildAssignment(assignment);
//                                        }
//                                    }
//                                    assignmentString = redisTemplate.opsForList().rightPop("RebuildAssignment:d:" + assignmentDisableSetting.getDistrictId() + ":" + assignmentDisableSetting.getAssignmentType());
//                                }
                            }


                        }
                    }
                }
            }

        }

        return ReturnT.SUCCESS;

    }


    @XxlJob("planCreateTask")
    public ReturnT<String> planCreateTask() {
        String planId = XxlJobHelper.getJobParam();
        if (planId != null) {
            log.info("【planCreateTask】定时计划" + planId);
            Plan plan = planService.getById(planId);
            if (plan == null || plan.getSoftDelete() != 0) {
                log.info("【planCreateTask】计划不存在：" + planId);
                return ReturnT.SUCCESS;
            }
            Date date = new Date();
            if (plan.getType() == 2) {
                if (plan.getStatus() == 1) {
                    log.info("【planCreateTask】指派计划中止id：" + planId);
                    return ReturnT.SUCCESS;
                }
                redisService4.lPush("PlanTaskQueue", plan.getId().toString());
                plan.setStatus(2);
                planService.updateById(plan);
                log.info("【planCreateTask】指派计划结束id：" + planId);
            } else if (plan.getType() == 0) {
                if (plan.getStatus() == 1) {
                    log.info("【planCreateTask】例行计划中止id：" + planId);
                    return ReturnT.SUCCESS;
                }
                Boolean curFlag = true;
                if (plan.getEndTime() != null) {
                    if (date.getTime() > plan.getEndTime().getTime()) {
                        log.info("【planCreateTask】例行计划结束id：" + planId);
                        plan.setStatus(2);
                        planService.updateById(plan);

                        return ReturnT.SUCCESS;
                    }
                }
                String dateString = DateToConverter.getFormattedDate(date, 0);
                QueryWrapper<Holiday> wrapper = WrapperUtils.getWrapper(false);
                wrapper.eq("holiday_date", dateString);
                List<Holiday> holidaylist = holidayService.list(wrapper);
                String nextDate = null;
                //重复方式1  周期重复
                if (plan.getCircleStatus() == 1) {
                    Integer circleType = plan.getCircleType();
                    switch (circleType) {
                        //天
                        case 0:
                            nextDate = DateToConverter.getDateAddOrSub(5, 1, date);
                            break;
                        //周
                        case 1:
                            try {
                                if (plan.getCircleNo() != null && !plan.getCircleNo().trim().equals("")) {
                                    String dayofWeek = DateToConverter.getDayofWeek(date);
                                    String[] split = plan.getCircleNo().split(",");
                                    String nextNo = null;
                                    int nextIndex = 0;
                                    for (int i = 0; i < split.length; i++) {
                                        if (split[i].equals(dayofWeek)) {

                                            if (i != split.length - 1) {
                                                nextIndex = i + 1;
                                            }
                                        }

                                        if (Integer.parseInt(split[i]) > Integer.parseInt(dayofWeek) && nextIndex == 0) {
                                            nextIndex = i;
                                        }
                                    }
                                    nextNo = split[nextIndex];
                                    nextDate = DateToConverter.nextDayOfWeek(Integer.parseInt(nextNo));
                                    //这次的任务是否应该生成
                                    if (!plan.getCircleNo().contains(dayofWeek)) {
                                        curFlag = false;
                                    }
                                }
                            } catch (NumberFormatException e) {
                                nextDate = null;
                                e.printStackTrace();
                            }
                            break;
                        //月
                        case 2:
                            if (plan.getCircleNo() != null && !plan.getCircleNo().trim().equals("")) {
                                Boolean curDayFlag = false;
                                String dayofMOnth = DateToConverter.getCurDayOfMonth();
                                String[] split = plan.getCircleNo().split(",");
                                String nextNo = null;
                                String nextDay = null;
                                int nextIndex = -1;
                                int nextDayIndex = 0;
                                for (int i = 0; i < split.length; i++) {
                                    if (split[i].equals(dayofMOnth)) {
                                        if (i != split.length - 1) {
                                            nextIndex = i + 1;
                                        }
                                    }
                                    if (Integer.parseInt(dayofMOnth) < Integer.parseInt(split[i]) && nextDay == null) {
                                        nextDay = split[i];
                                    }
                                    if (split[i].equals(dayofMOnth)) {
                                        curDayFlag = true;
                                    }
                                }
                                //如果下一次是月末
                                if (nextDay != null && nextDay.equals("99")) {
                                    nextDate = DateToConverter.nextDayOfMonth(Integer.parseInt(nextDay));
                                    String today = DateToConverter.getFormattedDate(date, 0);
                                    //如果今天是月末
                                    if (today.equals(nextDate)) {
                                        nextIndex = 0;
                                        curDayFlag = true;
                                    }
                                }


                                if (nextIndex >= 0) {
                                    nextNo = split[nextIndex];

                                } else {
                                    nextNo = split[0];
                                }
                                nextDate = DateToConverter.nextDayOfMonth(Integer.parseInt(nextNo));

                                //这次的任务是否应该生成
                                if (!curDayFlag) {
                                    curFlag = false;
                                }
                            }
                            break;
                        default:
                            break;
                    }


                    //重复方式2 间隔重复
                } else if (plan.getCircleStatus() == 2) {
                    Integer circleType = plan.getCircleType();
                    String circleNo = plan.getCircleNo();
                    String timeString = null;
                    if (circleNo != null) {
                        try {
                            int i = Integer.parseInt(circleNo) + 1;
                            switch (circleType) {
                                //天
                                case 0:
                                    timeString = DateToConverter.getDateAddOrSub(5, i, date);
                                    break;
                                //周
                                case 1:
                                    timeString = DateToConverter.getDateAddOrSub(4, i, date);

                                    break;
                                //月
                                case 2:
                                    timeString = DateToConverter.getDateAddOrSub(2, i, date);
                                    break;
                                default:
                                    break;

                            }
                        } catch (NumberFormatException e) {
                            log.info("【planCreateTask】重复方式2异常，planId：" + planId);
                            e.printStackTrace();

                        }
                    }
                    if (timeString != null) {
                        nextDate = timeString.substring(0, 10);
                    }

                } else if (plan.getCircleStatus() == 0) {
                    redisService4.lPush("PlanTaskQueue", plan.getId().toString());
                    plan.setStatus(2);
                    planService.updateById(plan);
                    log.info("【planCreateTask】不重复计划结束id：" + planId);
                    return ReturnT.SUCCESS;
                }
                if (nextDate != null) {
                    if (plan.getActionStartTime() == null || plan.getActionStartTime().trim().equals("")) {
                        nextDate = nextDate + " 00:00:00";
                    } else {
                        nextDate = nextDate + " " + plan.getActionStartTime() + ":00";
                    }
                    Date nextCron = DateToConverter.parseDate(nextDate, 5);
                    //是否删除旧的？
                    String oldtaskId = redisService4.get("Plan:" + plan.getType() + ":" + plan.getId());
                    if (oldtaskId != null) {
                        xxlJobUtil.pause(Integer.parseInt(oldtaskId));
                    }
                    setXxlJobInfo(plan, nextCron);
                    log.info("【planCreateTask】生成新调度器id：" + planId);

                } else {
                    log.info("【planCreateTask】不生成新调度器id：" + planId);

                }

                if (!holidaylist.isEmpty()) {
                    Holiday holiday = holidaylist.get(0);
                    //跳过节假日
                    if (plan.getEliminateType() == 1) {
                        if (holiday.getType() == 1 || holiday.getType() == 2) {
                            log.info("【planCreateTask】跳过节假日planid：" + planId);
                            return ReturnT.SUCCESS;
                        }
                        //跳过工作日
                    } else if (plan.getEliminateType() == 2) {
                        if (holiday.getType() == 0 || holiday.getType() == 3) {
                            log.info("【planCreateTask】跳过工作日planid：" + planId);
                            return ReturnT.SUCCESS;
                        }
                    }
                }

                if (curFlag) {
                    redisService4.lPush("PlanTaskQueue", planId);
                }

//                String planId = redisService4.rightPop("PlanTaskQueue");

                //巡检计划
            } else if (plan.getType() == 5) {
                Boolean curFlag = true;

                if(plan.getCircleStatus()==0){
                    plan.setStatus(2);
                }else{
                    if(plan.getStartStatus()==1){
                        try {
                            if (plan.getEndTime().getTime()<date.getTime()){
                                plan.setStatus(2);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    String nextDate = null;

                    //计算下次任务时间
                    Integer circleType = plan.getCircleType();
                    switch (circleType) {
                        //天
                        case 0:
                            nextDate = DateToConverter.getDateAddOrSub(5, 1, date);
                            break;
                        //周
                        case 1:
                            try {
                                if (plan.getCircleNo() != null && !plan.getCircleNo().trim().equals("")) {
                                    String dayofWeek = DateToConverter.getDayofWeek(date);
                                    String[] split = plan.getCircleNo().split(",");
                                    String nextNo = null;
                                    int nextIndex = 0;
                                    for (int i = 0; i < split.length; i++) {
                                        if (split[i].equals(dayofWeek)) {

                                            if (i != split.length - 1) {
                                                nextIndex = i + 1;
                                            }
                                        }

                                        if (Integer.parseInt(split[i]) > Integer.parseInt(dayofWeek) && nextIndex == 0) {
                                            nextIndex = i;
                                        }
                                    }
                                    nextNo = split[nextIndex];
                                    nextDate = DateToConverter.nextDayOfWeek(Integer.parseInt(nextNo));
                                    //这次的任务是否应该生成
                                    if (!plan.getCircleNo().contains(dayofWeek)) {
                                        curFlag = false;
                                    }
                                }
                            } catch (NumberFormatException e) {
                                nextDate = null;
                                e.printStackTrace();
                            }
                            break;
                        //月
                        case 2:
                            if (plan.getCircleNo() != null && !plan.getCircleNo().trim().equals("")) {
                                Boolean curDayFlag = false;
                                String dayofMOnth = DateToConverter.getCurDayOfMonth();
                                String[] split = plan.getCircleNo().split(",");
                                String nextNo = null;
                                String nextDay = null;
                                int nextIndex = -1;
                                int nextDayIndex = 0;
                                for (int i = 0; i < split.length; i++) {
                                    if (split[i].equals(dayofMOnth)) {
                                        if (i != split.length - 1) {
                                            nextIndex = i + 1;
                                        }
                                    }
                                    if (Integer.parseInt(dayofMOnth) < Integer.parseInt(split[i]) && nextDay == null) {
                                        nextDay = split[i];
                                    }
                                    if (split[i].equals(dayofMOnth)) {
                                        curDayFlag = true;
                                    }
                                }
                                //如果下一次是月末
                                if (nextDay != null && nextDay.equals("99")) {
                                    nextDate = DateToConverter.nextDayOfMonth(Integer.parseInt(nextDay));
                                    String today = DateToConverter.getFormattedDate(date, 0);
                                    //如果今天是月末
                                    if (today.equals(nextDate)) {
                                        nextIndex = 0;
                                        curDayFlag = true;
                                    }
                                }


                                if (nextIndex >= 0) {
                                    nextNo = split[nextIndex];

                                } else {
                                    nextNo = split[0];
                                }
                                nextDate = DateToConverter.nextDayOfMonth(Integer.parseInt(nextNo));

                                //这次的任务是否应该生成
                                if (!curDayFlag) {
                                    curFlag = false;
                                }
                            }
                            break;
                        default:
                            break;
                    }
                    nextDate= nextDate+" "+plan.getActionStartTime()+":00";
                    Date nextCron = DateToConverter.parseDate(nextDate, 5);
                    setXxlJobInfo(plan, nextCron);
                }
                if(curFlag){
                    redisService4.lPush("PlanTaskQueue", plan.getId().toString());
                }
            }


        }
        return ReturnT.SUCCESS;
    }

    /**
     * 人次任务触发
     */
    @Scheduled(cron = "* * * * * ?")
    public void planActionCount2Task() {
        String positionIdString = redisService5.leftPop("PlanCountQueue");
        while (positionIdString != null) {
            Set<String> planIds = redisService4.setMembers("UserCount:p:" + positionIdString);
            Iterator<String> iterator = planIds.iterator();
            while (iterator.hasNext()) {
                String planId = iterator.next();
                String planTimes = redisService4.get("UserCount:p:" + positionIdString + ":" + planId);
                if (planTimes != null) {
                    if (planTimes.equals("0")) {
                        //已触发过，下一次
                        continue;
                    } else {
                        Integer curTimes = Integer.parseInt(planTimes);
                        if (curTimes == 1) {
                            //插入生成任务队列
                            redisService4.lPush("PlanTaskQueue", planId);
                        }
                        curTimes--;
                        redisService4.set("UserCount:p:" + positionIdString + ":" + planId, curTimes.toString());
                    }
                } else {
                    //清除无用计划redis标记     String planTimes = redisService4.get("UserCount:p:" + positionIdString + ":" + planId);
//                    //组内计划
                    redisService4.removeSetValue("UserCount:p:" + positionIdString, planId);
//                    //计划记次
                    redisService4.remove("UserCount:p:" + positionIdString + ":" + planId);
                    //有计划标记，但是无计次
                    redisService4.lPush("PlanTaskQueue", planId);

                }
            }
            positionIdString = redisService5.leftPop("PlanCountQueue");
        }
    }

    @Scheduled(cron = "* * * * * ?")
    public void inspectPlanTaskCreate() {
        String planId = redisService4.rightPop("InspectPlanCreateQueue");
        while (planId != null) {
            Plan plan = planService.getById(planId);
            String oldtaskId = redisService4.get("Plan:" + plan.getType() + ":" + planId);
            if (oldtaskId != null) {
                xxlJobUtil.pause(Integer.parseInt(oldtaskId));
                Date startTime = plan.getStartTime();
                Date curdate = new Date();
                String surDate = DateToConverter.getFormattedDate(curdate, 0);
                String oldTime = DateToConverter.getFormattedDate(startTime, 5);
                String oldDate = DateToConverter.getFormattedDate(startTime, 0);
                String newTimeStr = oldTime.replace(oldDate, surDate);
                Date newTime = DateToConverter.parseDate(newTimeStr, 5);
                if(curdate.getTime()<newTime.getTime()){
                    plan.setStartTime(newTime);
                }
            }
            Date date = new Date();
            setXxlJobInfo(plan, plan.getStartTime());
            log.info("【inspectPlanTaskCreate】生成新调度器id：" + planId);
            planId = redisService4.rightPop("InspectPlanCreateQueue");
        }
    }

    /**
     * @return
     */
    private Boolean setXxlJobInfo(Plan plan, Date date) {
        String jobName = "计划创建任务";
        String time = null;
        //生成任务触发时间
        //计划任务

        time = DateToConverter.getCron(date);
        XxlJobInfo jobInfo2 = new XxlJobInfo();
        jobInfo2.setAddTime(new Date());
        jobInfo2.setAuthor("后台创建");
        jobInfo2.setExecutorBlockStrategy("SERIAL_EXECUTION");
        jobInfo2.setExecutorFailRetryCount(0);
        jobInfo2.setExecutorHandler("planCreateTask");
        jobInfo2.setExecutorParam(plan.getId().toString());
        jobInfo2.setExecutorRouteStrategy("ROUND");// 轮训
        jobInfo2.setExecutorTimeout(3000);
        jobInfo2.setGlueRemark("GLUE代码初始化");
        jobInfo2.setGlueType("BEAN");
        jobInfo2.setScheduleType("CRON");
        jobInfo2.setMisfireStrategy("DO_NOTHING");
        jobInfo2.setScheduleConf(time);
        jobInfo2.setJobDesc(jobName + plan.getId());
        String returns = xxlJobUtil.addAndStart(jobInfo2);
        JSONObject returnJsonObject = JSON.parseObject(returns);
        int code = returnJsonObject.getIntValue("code");
        if (code == 200) {
            String taskId = returnJsonObject.getString("content");
            redisService4.set("Plan:" + plan.getType() + ":" + plan.getId(), taskId);
            return true;
        } else {
            // 否则关掉上个任务
            return false;
        }
    }


//        Set<ZSetOperations.TypedTuple<String>> activityBegin = redisTemplate.opsForZSet().rangeByScoreWithScores("ActivityBegin", 0, time);
//        redisTemplate.opsForZSet().add("ActivityBegin", activity.getId().toString(), activity.getBeginTime().getTime());
//
//        return ReturnT.SUCCESS;


}
