package com.dxhy.domestic.controller;

import java.util.Objects;

import javax.annotation.Resource;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dxhy.common.constant.CommonConstants;
import com.dxhy.common.controller.AbstractController;
import com.dxhy.common.utils.R;
import com.dxhy.domestic.model.dto.TdxExportCustomsModelDTO;
import com.dxhy.domestic.model.dto.TdxExportInvoiceModelDTO;
import com.dxhy.domestic.service.count.DomesticCustomsExportCountService;
import com.dxhy.domestic.service.count.DomesticInvoiceExportCountService;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 统计查询-转内销发票查询 转内销缴款书查询
 *
 * @author dxhy
 */
@RestController
@RequestMapping("/countExport")
@Slf4j
public class DomesticInvoiceExportCountController extends AbstractController {

    @Resource
    private DomesticInvoiceExportCountService domesticInvoiceExportCountService;

    @Resource
    private DomesticCustomsExportCountService icustomsExportCountService;

    @PostMapping("/queryExportInvoiceList")
    @ApiOperation(value = "转内销发票查询")
    public ResponseEntity<R> queryExportInvoiceList(Page<Object> page, @RequestBody TdxExportInvoiceModelDTO dto) {
        try {
            dto.setUserInfo(getUserInfo());
            return ResponseEntity
                .ok(R.ok().put("data", domesticInvoiceExportCountService.queryExportInvoiceList(page, dto)));
        } catch (Exception e) {
           log.info("业务处理异常：{}", e);
            log.error("", e);
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

    @PostMapping("/queryExportCustomsList")
    @ApiOperation(value = "转内销缴款书查询")
    public ResponseEntity<R> queryExportCustomsList(Page<Object> page, @RequestBody TdxExportCustomsModelDTO dto) {
        try {
            dto.setUserInfo(getUserInfo());
            return ResponseEntity.ok(Objects
                .requireNonNull(R.ok().put("data", icustomsExportCountService.queryExportCustomsList(page, dto))));
        } catch (Exception e) {
           log.info("业务处理异常：{}", e);
            log.error("", e);
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

}
