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.GridPage;
import com.sunxung.factoring.entity.ResponseJson;
import com.sunxung.factoring.entity.purchcontractmanagement.vo.PurchContractVo;
import com.sunxung.factoring.entity.purchcontractmanagement.vo.SearchGoods;
import com.sunxung.factoring.service.purchcontractmanagement.PurchContractElectronicInfoService;
import com.sunxung.factoring.service.purchcontractmanagement.PurchContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description : 采购合同管理控制层
 * @Author : JiaYf
 * @Date: 2021-09-14 11:50
 */
@Controller
@RequestMapping("/purchContract")
public class PurchContractController {

    @Autowired
    private PurchContractService purchContractService;
    @Autowired
    private PurchContractElectronicInfoService purchContractElectronicInfoService;


//    /**
//     * 业务发起采购合同变更
//     *
//     * @param id 采购合同管理主键Id
//     * @return
//     */
//    @GetMapping("/doChange")
//    @ResponseBody
//    public Object doChange(Long id) {
//        purchContractService.change(id);
//        return new ResponseJson("销售合同录入完成");
//    }


    @RequestMapping("/delete")
    @ResponseBody
    @OperationLog(operationModule = "采购合同",operationType = OperationTypeEnum.OTHER,description = "删除")
    public ResponseJson deleteContract(Long id){
        purchContractService.deleteContract(id);
        return new ResponseJson("删除成功！");
    }

    /**
     * 一键下载
     * @param id
     * @param response
     */
    @GetMapping("/downloadAllPurchFile")
    @OperationLog(operationModule = "采购合同",operationType = OperationTypeEnum.OTHER,description = "一键下载")
    public void downloadAllPurchFile(Long id, HttpServletResponse response){
        purchContractService.downloadAllPurchFile(id,response);
    }

    /**
     * 下载出证
     *
     * @param id
     * @param res
     * @return
     */
    @GetMapping("/downloadReportUrl")
    @ResponseBody
    @OperationLog(operationModule = "采购合同",operationType = OperationTypeEnum.OTHER,description = "下载采购合同出证文件")
    public ResponseEntity<Object> downloadPurchReport(Long id, HttpServletResponse res) throws IOException {
        return purchContractElectronicInfoService.downloadReportUrl(id, res);
    }

}
