package com.sunxung.factoring.web.purchcontractmanagement;

import com.sunxung.factoring.component.annotation.OperationLog;
import com.sunxung.factoring.component.enums.OperationTypeEnum;
import com.sunxung.factoring.entity.ResponseJson;
import com.sunxung.factoring.entity.purchcontractmanagement.PurchSupplementContractSignConclusion;
import com.sunxung.factoring.entity.purchcontractmanagement.vo.PurchContractChangeVo;
import com.sunxung.factoring.service.purchcontractmanagement.IPurchContractSupplementInfoService;
import com.sunxung.factoring.service.purchcontractmanagement.IPurchSupplementContractSignConclusionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @Author Yafan Wang
 * @Date 2023/12/18 20:01
 */
@RequestMapping("/api/purchManagement")
@RestController
public class PurchContractSupplementAipController {

    @Autowired
    IPurchContractSupplementInfoService contractSupplementInfoService;
    @Autowired
    private IPurchSupplementContractSignConclusionService purchSupplementContractSignConclusionService;

    /**
     * 采购合同变更流程处理
     *
     * @return
     */
    @PostMapping("/change/handleProcess")
    @OperationLog(operationModule = "采购合同变更", operationType = OperationTypeEnum.INSERT, description = "采购合同变更提交")
    public Object commitTask(@RequestBody PurchContractChangeVo vo) {
        contractSupplementInfoService.change(vo);
        return new ResponseJson("销售合同录入完成");
    }

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

    /**
     * 签署确认提交
     *
     * @param purchSupplementContractSignConclusion 采购合同Id
     * @return
     */
    @PostMapping("/change/doSign")
    public ResponseJson doSign(@RequestBody PurchSupplementContractSignConclusion purchSupplementContractSignConclusion) throws IOException {
        purchSupplementContractSignConclusionService.sign(purchSupplementContractSignConclusion);
        return new ResponseJson("操作成功！");
    }

    /**
     * 查看历史
     * @param id
     * @return
     */
    @GetMapping("/change/getView")
    public ResponseJson getView(@RequestParam Long id){
        return new ResponseJson(purchSupplementContractSignConclusionService.getView(id));
    }

}
