package me.zhengjie.modules.dm.activiti;

import me.zhengjie.modules.dm.information.domain.DmInformation;
import me.zhengjie.modules.dm.information.service.DmInformationService;
import me.zhengjie.modules.dm.information.service.dto.DmInformationDto;
import me.zhengjie.modules.dm.informationApproval.domain.DmInformationApproval;
import me.zhengjie.modules.dm.informationApproval.service.DmInformationApprovalService;
import me.zhengjie.utils.SpringContextHolder;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;

/**
 * 审批节点开始前的监听
 */
public class ApproveStartListener implements TaskListener {
    @Override
    public void notify(DelegateTask delegateTask) {
        System.out.println("审批任务开始监听  ApproveStartListener || 审批开始");
        String taskId = delegateTask.getId();
        Long info_id = (Long) delegateTask.getVariable("op_id");
        Integer is_auto = (Integer) delegateTask.getVariable("is_auto");
        System.out.println("taskId : "+taskId);
        System.out.println("param.info_id : "+info_id);
        DmInformationService informationService = SpringContextHolder.getBean(DmInformationService.class);
        DmInformationApprovalService printingApprovalService = SpringContextHolder.getBean(DmInformationApprovalService.class);
        DmInformationDto requestDto = informationService.findById(info_id);
        DmInformation printingRequest = informationService.toEntity(requestDto);
        if("00".equals(printingRequest.getStatus()) || "02".equals(printingRequest.getStatus())){
            //修改审批列表对应事务
            printingApprovalService.resetTask(info_id,delegateTask.getAssignee(),taskId,delegateTask.getProcessInstanceId());
        }
    }
}
