/**
 * @filename:SalesContractController 2024-09-03
 * @project KJT v1.0.0 Copyright(c) 2024 wanglang Co. Ltd. All right reserved.
 */
package com.trade.client.trade.salescontract.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.trade.client.trade.salescontract.dto.SalesUploadContractDto;
import com.trade.service.trade.salescontract.dto.SalesCommodityDto;
import com.trade.service.trade.salescontract.dto.SalesCommoditySpidDto;
import com.trade.service.trade.salescontract.vo.ImportCommodityVo;
import org.springframework.web.bind.annotation.*;

import com.trade.client.trade.salescontract.dto.SalesContractInfoDto;
import com.trade.client.trade.salescontract.service.SalesService;
import com.trade.common.core.domain.ResponseResult;
import com.trade.common.core.page.GridPage;
import com.trade.service.trade.salescontract.dto.ContractSearchDto;
import com.trade.service.trade.salescontract.dto.ContractTermsDto;
import com.trade.service.trade.salescontract.vo.SalesContractInfoVo;
import com.trade.service.trade.salescontract.vo.SalesContractVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 说明： 销售合同基础信息API接口层
 * </P>
 * 
 * @version: v1.0.0
 * @author: wanglang
 * @time 2024-09-03
 */
@Api(tags = "销售合同基础信息", value = "销售合同基础信息")
@RestController
@RequestMapping("/salesContract")
public class SalesContractController {

    @Resource
    private SalesService salesService;

    /**
     * 保存销售合同基础信息
     * 
     * @param salesContractInfoDto 基础信息
     * @param request 合同文件信息
     * @return 合同id
     */
    @ApiOperation(value = "保存销售合同基础信息", notes = "保存销售合同基础信息")
    @PostMapping("/save/baseInfo")
    public ResponseResult<Long> saveContractInfo(@RequestBody SalesContractInfoDto salesContractInfoDto,
            HttpServletRequest request) {
        return ResponseResult.success(salesService.saveSalesContract(salesContractInfoDto, request));
    }

    /**
     * 保存销售合同条款
     *
     * @param contractTermsDto 合同条款
     * @return 合同id
     */
    @ApiOperation(value = "保存销售合同条款", notes = "保存销售合同条款")
    @PostMapping("/save/terms")
    public ResponseResult<Long> saveContractTerms(@RequestBody ContractTermsDto contractTermsDto,
            HttpServletResponse response) {
        return ResponseResult.success(salesService.saveContractTerms(contractTermsDto, response));
    }

    /**
     * 获取销售合同
     * 
     * @param contractSearch 合同查询条件
     * @return 销售合同信息
     */
    @ApiOperation(value = "获取销售合同", notes = "获取销售合同")
    @PostMapping("/get/page")
    public ResponseResult<GridPage<SalesContractVo>> getSalesContractPage(
            @RequestBody ContractSearchDto contractSearch) {
        return ResponseResult.success(salesService.getSalesContractPage(contractSearch));
    }

    /**
     * 获取销售合同详情
     * 
     * @param contractId 合同id
     * @return 销售合同信息
     */
    @ApiOperation(value = "获取销售合同详情", notes = "获取销售合同详情")
    @GetMapping("/get/{contractId}")
    public ResponseResult<SalesContractInfoVo> getSalesContractDetails(@PathVariable Long contractId) {
        return ResponseResult.success(salesService.getSalesContractDetails(contractId));
    }

    /**
     * 删除合同
     *
     * @param contractId 合同id
     * @return true/false
     */
    @ApiOperation(value = "删除合同", notes = "删除合同")
    // @DeleteMapping("/delete/{contractId}")
    @GetMapping("/delete/{contractId}")
    public ResponseResult<Boolean> deleteSalesContract(@PathVariable Long contractId) {
        return ResponseResult.success(salesService.deleteSalesContract(contractId));
    }
    // /**
    // * 上传合同
    // *
    // * @param contractId 合同id
    // * @return true/false
    // */
    // @ApiOperation(value = "上传合同文件", notes = "上传合同文件")
    // @GetMapping("/upload/{contractId}")
    // public ResponseResult<Boolean> uploadContract(@PathVariable Long contractId, HttpServletRequest request) {
    // return ResponseResult.success(salesService.uploadContract(contractId, request));
    // }

    /**
     * 上传合同
     *
     * @param salesUploadContractDto 合同信息
     * @return true/false
     */
    @ApiOperation(value = "上传合同文件", notes = "上传合同文件")
    @PostMapping("/upload")
    public ResponseResult<Boolean> uploadContract(@RequestBody SalesUploadContractDto salesUploadContractDto) {
        return ResponseResult.success(salesService.uploadContract(salesUploadContractDto));
    }

    /**
     * 下载销售合同
     *
     * @param contractId 合同id
     * @return true/false
     */
    @ApiOperation(value = "下载销售合同文件", notes = "下载销售合同文件")
    @GetMapping("/download/{contractId}")
    public ResponseResult<Boolean> downloadContract(@PathVariable Long contractId, HttpServletRequest request,
            HttpServletResponse response) {
        return ResponseResult.success(salesService.downloadContract(contractId, request, response));
    }

    /**
     * 导入商品
     *
     * @param file 商品excel
     * @return 商品信息
     */
    @ApiOperation(value = "导入商品", notes = "导入商品")
    @PostMapping("/import/commodity")
    public ResponseResult<ImportCommodityVo> importCommodityFile(@RequestParam("file") MultipartFile file) {
        return ResponseResult.success(salesService.importCommodityFile(file));
    }

    /**
     * 查询小图商品
     *
     * @param name 商品名称
     * @return 商品信息
     */
    @ApiOperation(value = "查询小图商品", notes = "查询小图商品")
    @GetMapping("/get/commodity")
    public ResponseResult<List<SalesCommodityDto>> getXiaoTuCommodityList(String name) {
        return ResponseResult.success(salesService.getXiaoTuCommodityList(name));
    }

    /**
     * 查询小图商品明细
     *
     * @param name 商品名称
     * @return 商品信息
     */
    @ApiOperation(value = "查询小图商品明细", notes = "查询小图商品明细")
    @GetMapping("/get/commoditySpid")
    public ResponseResult<List<SalesCommoditySpidDto>> getXiaoTuCommoditySpidList(String name) {
        return ResponseResult.success(salesService.getXiaoTuCommoditySpidList(name));
    }
    /***
     * 下载模板
     */
    @ApiOperation(value = "下载商品模板", notes = "下载商品模板")
    @GetMapping(value = "/downloadTemplate")
    public ResponseResult<Boolean> downloadDataTemplate(HttpServletRequest request, HttpServletResponse response) {
        return ResponseResult.success(salesService.downloadTemplates(request, response));
    }
}
