package com.inkasso.factoring.purchManagement.web;


import com.inkasso.factoring.common.entity.ResponseJson;
import com.inkasso.factoring.purchManagement.entity.PurchSupplementContractSignConclusion;
import com.inkasso.factoring.purchManagement.entity.vo.PurchContractChangeVo;
import com.inkasso.factoring.purchManagement.service.ICPurchContractManagementService;
import com.inkasso.factoring.purchManagement.service.ICPurchContractSupplementElectronicInfoService;
import com.inkasso.factoring.purchManagement.service.ICPurchContractSupplementInfoService;
import com.inkasso.factoring.purchManagement.service.IPurchSupplementContractSignConclusionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * <p>
 * 采购合同-补充信息表 变更 前端控制器
 * </p>
 *
 * @author daxian
 * @since 2022-03-14
 */
@Controller
@RequestMapping("/purchContract/change")
public class PurchContractSupplementInfoController {

    @Autowired
    ICPurchContractSupplementInfoService contractSupplementInfoService;

    @Autowired
    ICPurchContractSupplementElectronicInfoService supplementElectronicInfoService;

    @Autowired
    ICPurchContractManagementService purchContractService;

    @Autowired
    private IPurchSupplementContractSignConclusionService purchSupplementContractSignConclusionService;

    /**
     * 跳转采购合同变更页面
     *
     * @param businessKey 采购合同Id
     * @return
     */
    @GetMapping("/add")
    @ResponseBody
    public ResponseJson add(Long businessKey) {
        return new ResponseJson(contractSupplementInfoService.getDetail(businessKey));
    }

    /**
     * 采购合同变更提交
     *
     * @return
     */
    @PostMapping("/doChange")
    @ResponseBody
    public Object doChange(@RequestBody PurchContractChangeVo vo) {
        contractSupplementInfoService.change(vo);
        return new ResponseJson("销售合同录入完成");
    }

    /**
     * 跳转采购合同变更签署页面
     *
     * @param businessKey 采购合同Id
     * @return
     */
    @RequestMapping("/confirm/add/signPage")
    @ResponseBody
    public ResponseJson signPageUnderline(Long businessKey){
        return new ResponseJson(purchSupplementContractSignConclusionService.getDetail(businessKey));
    }

    /**
     * 签署确认
     *
     * @return
     */
    @RequestMapping("/add/sign")
    @ResponseBody
    public ResponseJson doAdd(@RequestBody PurchSupplementContractSignConclusion purchSupplementContractSignConclusion) throws IOException {
        //签署后流程
        purchSupplementContractSignConclusionService.sign(purchSupplementContractSignConclusion);
        return new ResponseJson("签署确认完成");
    }


}
