package com.jianshui.web.controller.platform;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONObject;
import com.jianshui.common.core.controller.BaseController;
import com.jianshui.common.core.domain.AjaxResult;
import com.jianshui.common.core.page.TableDataInfo;
import com.jianshui.invoice.domain.BillInfo;
import com.jianshui.invoice.domain.Invoice;
import com.jianshui.invoice.mapper.BillInfoMapper;
import com.jianshui.invoice.mapper.InvoiceMapper;
import com.jianshui.platform.dto.CopyBillInfoQueryDTO;
import com.jianshui.platform.dto.DocumentListQueryPDTO;
import com.jianshui.platform.dto.InvoiceAdd.BillInfoPDTO;
import com.jianshui.platform.service.InvoiceAddPService;
import com.jianshui.platform.vo.InvoiceCopyBillinfoListPVO;
import com.jianshui.platform.vo.InvoiceListPVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 发票录入
 * 
 */
@Api(tags={"单据管理"},value = "")
@RestController
@RequestMapping("/platForm/billInfoAdd/")
public class BillInfoAddPController extends BaseController {

    @Autowired
    private InvoiceAddPService addService;

    @Autowired
    private BillInfoMapper billInfoMapper;

    @Autowired
    private InvoiceMapper invoiceMapper;

    @ApiOperation(value = "单据保存",notes = "单据保存请求(支持数电普票、数电专票)")
    @PostMapping( "invoiceSave")
    public AjaxResult invoiceSave(@RequestBody BillInfoPDTO billInfoPDTO) throws Exception {
        return toAjax(addService.invoiceSave(billInfoPDTO));
    }

    @ApiOperation(value = "单据管理列表",notes = "发票管理")
    @GetMapping( "documentList")
    public TableDataInfo documentList(DocumentListQueryPDTO queryPDTO) throws Exception {

        startPage();
        BillInfo billInfo = BeanUtil.copyProperties(queryPDTO,BillInfo.class);
        List<BillInfo> billInfoList = billInfoMapper.selectBillInfoList(billInfo);

        List<InvoiceListPVO> invoiceListPVOS = BeanUtil.copyToList(billInfoList,InvoiceListPVO.class);
        return getDataTable(invoiceListPVOS);
    }

    @ApiOperation(value = "税收分类编码列表",notes = "开发中")
    @PostMapping( "difference")
    public AjaxResult taxClassificationCodeList(@RequestBody JSONObject jsonObject) throws Exception {

        // TODO: 税收分类编码列表

        return AjaxResult.error("功能开发中！");
    }


    @ApiOperation(value = "差额",notes = "开发中")
    @PostMapping( "difference1")
    public AjaxResult difference(@RequestBody JSONObject jsonObject) throws Exception {

        // TODO: 差额：

        return AjaxResult.error("功能开发中！");
    }

    @ApiOperation(value = "复制",notes = "开发中")
    @PostMapping( "copyBillInfo")
    public AjaxResult copyBillInfo(@RequestBody CopyBillInfoQueryDTO copyBillInfoQueryDTO) throws Exception {

        // TODO: 复制：传入选择票种，复制的是已开发票的票种信息。
//        AjaxResult ajaxResult = addService.copyBillInfo(copyBillInfoQueryDTO);

        return AjaxResult.error("功能开发中！");
    }


    @ApiOperation(value = "可复制单据查询",notes = "开发中")
    @GetMapping( "copyBillInfoList")
    public TableDataInfo copyBillInfoList(CopyBillInfoQueryDTO copyBillInfoQueryDTO) throws Exception {

        startPage();
        Invoice invoice = BeanUtil.copyProperties(copyBillInfoQueryDTO,Invoice.class);
        List<Invoice> invoiceList = invoiceMapper.selectInvoiceList(invoice);

        List<InvoiceCopyBillinfoListPVO> invoiceCopyBillinfoListPVOS = BeanUtil.copyToList(invoiceList,InvoiceCopyBillinfoListPVO.class);
        return getDataTable(invoiceCopyBillinfoListPVOS);
    }






}
