package com.sunxung.factoring.web.financing;

import com.sunxung.factoring.component.util.ConstantUtil;
import com.sunxung.factoring.component.util.ThreadLocalUtil;
import com.sunxung.factoring.entity.ResponseJson;
import com.sunxung.factoring.entity.financing.contract.ContractLegalFinalApproval;
import com.sunxung.factoring.service.financing.contract.IContractLegalFinalApprovalService;
import com.sunxung.factoring.service.sys.flowable.FlowableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @Description : 法务终审Controller
 * @Author : L.Jia
 * @Date: 2024-01-24 09:33
 */
@RestController
@RequestMapping("/contractLegalFinalApproval")
public class ContractLegalFinalApprovalController {

    @Autowired
    private IContractLegalFinalApprovalService contractLegalFinalApprovalService;
    @Autowired
    private FlowableService flowableService;

    /**
     * 进入法务终审页面
     *
     * @param id
     * @return
     */
    @GetMapping("/edit")
    public Object edit(Long id) {
        return new ResponseJson(contractLegalFinalApprovalService.getContractLegalFinalApprovalEditData(id));
    }

    /**
     * 法务终审提交
     *
     * @param contractLegalFinalApproval
     * @return
     */
    @PostMapping("/doEdit")
    public Object doEdit(@RequestBody ContractLegalFinalApproval contractLegalFinalApproval) {
        flowableService.claimTask(contractLegalFinalApproval.getTaskId(), ThreadLocalUtil.getUserId(), ConstantUtil.LEGAL_SPECIALIST);
        return contractLegalFinalApprovalService.editContractLegalFinalApproval(contractLegalFinalApproval);
    }

    /**
     * 下载全部电子签合同
     *
     * @param contractInfoId
     */
    @GetMapping("/downloadAll")
    public void downloadAll(Long contractInfoId, HttpServletResponse res) {
        contractLegalFinalApprovalService.downloadAll(contractInfoId, res);
    }
}
