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

import com.alibaba.fastjson.JSON;
import com.pusong.business.domain.PsApproverRecord;
import com.pusong.business.domain.PsContractInfo;
import com.pusong.business.domain.bo.PsContractBusinessBo;
import com.pusong.business.domain.bo.PsContractBusinessDetailBo;
import com.pusong.business.domain.bo.PsContractInfoBo;
import com.pusong.business.domain.vo.PsContractInfoVo;
import com.pusong.business.enums.ApproverTypeEnum;
import com.pusong.business.enums.CommonStatusEnum;
import com.pusong.business.service.IPsContractBusinessService;
import com.pusong.business.service.IPsContractInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 回传合同审批
 */
@RequiredArgsConstructor
@Service
@Slf4j
public class RolbackApproverServiceImpl extends ApproverAbstractServiceImpl {
    @Override
    public String approverType() {
        return ApproverTypeEnum.ROLBACK.getCode();
    }
    private final IPsContractBusinessService businessService;
    private final IPsContractInfoService contractInfoService;

    /**
     * 1 审批成功修改回传状态，并把回传的合同ossid放入合同表
     * @param psApproverRecord 神瀑类
     */
    @Override
    public void success(PsApproverRecord psApproverRecord) {
        //1查询源数据
        PsContractInfo psContractInfo = new PsContractInfo();
        psContractInfo.setContractCode(psApproverRecord.getContractCode());
        psContractInfo.setRollBackStatus(CommonStatusEnum.SUCCESS.getCode());
        psContractInfo.setRollBackPdf(Long.valueOf(psApproverRecord.getUpdateData()));
        contractInfoService.updateByCode(psContractInfo);
    }

    @Override
    public void fail(PsApproverRecord psApproverRecord) {
        PsContractInfo info = new PsContractInfo();
        info.setContractCode(psApproverRecord.getContractCode());
        info.setRollBackStatus(CommonStatusEnum.FAIL.getCode());
        contractInfoService.updateByCode(info);
    }
}
