package com.cpop.oam.framework.tasks;

import com.cpop.core.utils.SpringUtils;
import com.cpop.oam.business.entity.Task;
import com.cpop.oam.business.entity.TaskWorkOrder;
import com.cpop.oam.business.service.TaskService;
import com.cpop.oam.business.service.TaskWorkOrderService;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import static com.cpop.oam.business.entity.table.TaskTableDef.TASK;

/**
 * 工单暂停回复任务
 * @author DB
 * @version 1.0.0
 * @since 2023-12-21 21:38
 */
public class WorkOrderPauseRecoverTask implements Job {

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 获取工单id
        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        String workOrderId = jobDataMap.getString("WorkOrderId");
        TaskWorkOrderService taskWorkOrderService = SpringUtils.getBean(TaskWorkOrderService.class);
        TaskWorkOrder taskWorkOrder = taskWorkOrderService.getById(workOrderId);
        // 修改任务逾期
        TaskService taskService = SpringUtils.getBean(TaskService.class);
        Task task = taskService.getById(taskWorkOrder.getTaskId());
        if (task.getTaskStatus() == 5) {
            taskService.updateChain().set(TASK.TASK_STATUS, 2).where(TASK.ID.eq(taskWorkOrder.getTaskId())).update();
        }
    }
}
