package com.inkasso.factoring.invoicemanage.web;

import com.inkasso.adapter.response.SuccessResponseData;
import com.inkasso.factoring.common.entity.GridPage;
import com.inkasso.factoring.common.entity.ResponseJson;
import com.inkasso.factoring.file.entity.FileStorage;
import com.inkasso.factoring.file.entity.FileStorageDO;
import com.inkasso.factoring.invoicemanage.entity.InvoiceBasicInfo;
import com.inkasso.factoring.invoicemanage.model.request.EditinvoiceBasicInfoRequest;
import com.inkasso.factoring.invoicemanage.model.request.SearchBusiness;
import com.inkasso.factoring.invoicemanage.model.request.SearchGoodsVo;
import com.inkasso.factoring.invoicemanage.service.InvoiceBasicInfoService;
import com.inkasso.factoring.settlement.entity.SettlementGoodsInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

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

/**
 * @Description : 销售发票控制层
 * @Author : 刘涛
 * @Date: 2022-3-24
 */
@Controller
@RequestMapping("/saleInvoice")
public class InvoiceController {


    @Autowired
    private InvoiceBasicInfoService invoiceBasicInfoService;

    /**
     * 发票管理-列表查询
     *
     * @return
     */
    @RequestMapping("/do_List")
    @ResponseBody
    public Object do_List(@RequestBody SearchBusiness searchBusiness) {
        Object o = invoiceBasicInfoService.findList(searchBusiness);
        return new SuccessResponseData(o);
    }

    /**
     * 保存业务录入销售发票信息
     * 2.0
     *
     * @param invoiceBasicInfo 销售发票添加信息
     * @return
     */
    @RequestMapping("/do_add")
    @ResponseBody
    public Object do_add(@RequestBody InvoiceBasicInfo invoiceBasicInfo) throws IOException {
//        ValidatorUtil.validator(ValidatorEntity.ValidatorType.ADD, invoiceBasicInfo);
        invoiceBasicInfoService.add(invoiceBasicInfo);
        return new SuccessResponseData("发票录入完成");
    }

    /**
     * 更新销售发票
     * 2.0
     *
     * @param invoiceBasicInfo
     * @param request
     * @return
     * @throws IOException
     */
    @RequestMapping("/doUpdate")
    @ResponseBody
//    @OperationLog(operationModule = "销售发票",operationType = OperationTypeEnum.UPDATE,description = "更新销售发票")
    public Object doUpdate(@RequestBody InvoiceBasicInfo invoiceBasicInfo, HttpServletRequest request) throws IOException {
//        ValidatorUtil.validator(ValidatorEntity.ValidatorType.UPDATE, invoiceBasicInfo);
        invoiceBasicInfoService.doUpdate(invoiceBasicInfo,request);
        return new ResponseJson("销售发票更新完成!");
    }
    /**
     * 发票管理-查看接口
     *
     * @return
     */
    @RequestMapping("/do_getDetails")
    @ResponseBody
    public Object do_getDetails(@RequestParam Long id) {
        Object o = invoiceBasicInfoService.getDetail(id);
        return new SuccessResponseData(o);
    }

    /**
     * 获取销售发票金额类型为：货款的货物信息
     * 2.0
     *
     * @param
     * @return
     */
    @PostMapping("/saleSelectGoodsOfPayment")
    @ResponseBody
    public Object saleSelectGoodsOfPayment(@RequestBody  SearchGoodsVo searchGoodsVo) {
        return new SuccessResponseData(invoiceBasicInfoService.saleSelectGoodsOfPayment(searchGoodsVo));
    }

    /**
     * 获取采购发票金额类型为：贴现费用的货物信息
     * 2.0
     *
     * @param searchGoodsVo
     * @return
     */
    @PostMapping("/saleSelectGoodsOfDiscount")
    @ResponseBody
    public Object saleSelectGoodsOfDiscount(@RequestBody SearchGoodsVo searchGoodsVo) {
        return new SuccessResponseData(invoiceBasicInfoService.saleSelectGoodsOfDiscount(searchGoodsVo));
    }

    /**
     * 获取该笔业务对应的开票信息
     * 2.0
     *
     * @param customerId
     * @return
     */
    @GetMapping("/findCustomer")
    @ResponseBody
    public ResponseJson findCustomer(@RequestParam Long customerId, @RequestParam Long businessBasicInfoId) {
        return new ResponseJson(invoiceBasicInfoService.findByCustomer(customerId, businessBasicInfoId));
    }

    /**
     * 一键下载
     * @param id
     * @param response
     */
    @GetMapping("/downloadAllInvoiceFile")
    @ResponseBody
//    @OperationLog(operationModule = "销售发票",operationType = OperationTypeEnum.OTHER,description = "一键下载")
    public void downloadAllInvoiceFile(@RequestParam Long id, HttpServletResponse response) {
        invoiceBasicInfoService.downloadAllInvoiceFile(id, response);
    }



    /**
     *  查看销售发票
     */
    @GetMapping("/showSaleInvoice")
    @ResponseBody
    public Object showSaleInvoice(@RequestParam Long id) {
        List<FileStorage> fileStorageDOS = invoiceBasicInfoService.showSaleInvoice(id);
        return new ResponseJson(fileStorageDOS);
    }

    /**
     * 下载销售发票
     */
    @GetMapping("/downLoadSaleInvoice")
    @ResponseBody
    public void downLoadSaleInvoice(@RequestParam Long id,HttpServletResponse response) {
        invoiceBasicInfoService.downLoadSaleInvoice(id,response);
    }

    /**
     * 根绝核心企业+项目  查询上次  的开票信息 和 备注信息
     */





}
