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.ContractInfo;
import com.sunxung.factoring.service.financing.contract.ContractMakingService;
import com.sunxung.factoring.service.sys.flowable.FlowableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description : 合同制作Controller
 * @Author : L.Jia
 * @Date: 2024-01-24 09:33
 */
@RestController
@RequestMapping("/contractMaking")
public class ContractMakingController {

    @Autowired
    private ContractMakingService contractMakingService;
    @Autowired
    private FlowableService flowableService;

    /**
     * 跳转到合同制作处理页面
     */
    @GetMapping("/edit")
    public Object edit(Long id) {
        return new ResponseJson(contractMakingService.edit(id));
    }

    /**
     * 编辑合同制作. <br/>
     *
     * @param contractInfo
     * @return
     */
    @PostMapping("/doEdit")
    public Object doEdit(@RequestBody ContractInfo contractInfo) {
        //拾取task
        flowableService.claimTask(contractInfo.getTaskId(), ThreadLocalUtil.getUserId(), ConstantUtil.LEGAL_SPECIALIST);
        return contractMakingService.editContractInfo(contractInfo);
    }

    /**
     * 获取上传的签署合同文件
     */
    @GetMapping("/uploadContractList")
    public Object getUploadContractList(Long id) {
        return new ResponseJson(contractMakingService.getUploadContractList(id));
    }

    /**
     * 获取线上签署文件
     */
    @GetMapping("/electronicList")
    public Object getElectronicSignList(@RequestParam("contractInfoId") Long contractInfoId) {
        return new ResponseJson(contractMakingService.getElectronicSignList(contractInfoId));
    }
}
