package com.pusong.business.service.approver.impl;

import com.pusong.business.domain.PsApproverRecord;
import com.pusong.business.domain.PsContractInfo;
import com.pusong.business.domain.PsTaskAppoint;
import com.pusong.business.domain.PsTaskMain;
import com.pusong.business.enums.ApproverTypeEnum;
import com.pusong.business.enums.ContractStatusEnum;
import com.pusong.business.enums.TaskStatusEnum;
import com.pusong.business.mapper.PsTaskAppointMapper;
import com.pusong.business.mapper.PsTaskMainMapper;
import com.pusong.business.service.IPsContractInfoService;
import com.pusong.business.service.impl.PsContractInfoServiceImpl;
import com.pusong.common.core.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 任务完成审批
 */
@RequiredArgsConstructor
@Service
@Slf4j
public class TaskFinishApproverServiceImpl extends ApproverAbstractServiceImpl {
    @Override
    public String approverType() {
        return ApproverTypeEnum.TASKFINISH.getCode();
    }
    private final PsTaskAppointMapper taskAppointMapper;


    /**
     * 1 审批成功 任务的状态变为成功
     * @param psApproverRecord 神瀑类
     */
    @Override
    public void success(PsApproverRecord psApproverRecord) {
        PsTaskAppoint info = taskAppointMapper.selectById(psApproverRecord.getBusinessId());
        if(!StringUtils.equals(info.getAppointStatus(),TaskStatusEnum.AppointStatusEnum.CANCEL.getCode())){
            info.setAppointStatus(TaskStatusEnum.AppointStatusEnum.FINISH.getCode());
            info.setFinishDate(new Date());
            taskAppointMapper.updateById(info);
        }
    }

    /**
     * 审批拒绝 任务的状态变为进行中
     * @param psApproverRecord
     */
    @Override
    public void fail(PsApproverRecord psApproverRecord) {
        PsTaskAppoint info = taskAppointMapper.selectById(psApproverRecord.getBusinessId());
        info.setAppointStatus(TaskStatusEnum.ING.getCode());
        taskAppointMapper.updateById(info);
    }
}
