package com.dxhy.domestic.controller;

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.TdxExportInvoiceModelDTO;
import com.dxhy.domestic.service.ckzrz.DomesticExportInvoiceCkService;

import lombok.extern.slf4j.Slf4j;

/**
 * 出口转内销
 *
 * @author dxhy
 */
@RestController
@RequestMapping("/exportVatRzdk")
@Slf4j
public class DomesticExportInvoiceRzdkController extends AbstractController {
    @Resource
    private DomesticExportInvoiceCkService tDxExportInvoiceService;

    /**
     * 出口转内销认证 -增值税发票手工认证-列表查询
     */
    @PostMapping("/queryVatSgrz")
    public ResponseEntity<?> queryVatSgrz(Page page, @RequestBody TdxExportInvoiceModelDTO dto) {
        try {
            return ResponseEntity
                .ok(R.ok().put("data", tDxExportInvoiceService.queryVatSgrz(page, dto, this.getUserInfo())));
        } catch (Exception e) {
           log.info("业务处理异常：{}", e);
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

    /**
     * 出口转内销认证 -增值税发票手工认证-手工抵扣或不抵扣
     */
    @PostMapping("/approveSg")
    public ResponseEntity<?> approveSg(@RequestBody TdxExportInvoiceModelDTO dto) {
        try {
            String result = tDxExportInvoiceService.approveSg(dto, this.getUserInfo());
            return ResponseEntity.ok(R.ok().put("data", result));
        } catch (Exception e) {
           log.info("业务处理异常：{}", e);
            return ResponseEntity.ok(R.error(e.getMessage()));
        }
    }

    /**
     * 出口转内销认证 -设置增值税发票不抵扣-列表查询
     */
    @PostMapping("/queryVatBdk")
    public ResponseEntity<?> queryVatBdk(Page page, @RequestBody TdxExportInvoiceModelDTO dto) {
        try {
            return ResponseEntity
                .ok(R.ok().put("data", tDxExportInvoiceService.queryVatBdk(page, dto, this.getUserInfo())));
        } catch (Exception e) {
           log.info("业务处理异常：{}", e);
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

    /**
     * 出口转内销认证 -增值税发票认证查询-列表查询
     */
    @PostMapping("/queryVatRzcx")
    public ResponseEntity<?> queryVatRzcx(Page page, @RequestBody TdxExportInvoiceModelDTO dto) {
        try {
            return ResponseEntity
                .ok(R.ok().put("data", tDxExportInvoiceService.queryVatRzcx(page, dto, this.getUserInfo())));
        } catch (Exception e) {
           log.info("业务处理异常：{}", e);
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

    /**
     * 出口转内销认证 -增值税发票认证查询-撤销抵扣或撤销不抵扣
     */
    @PostMapping("/approveCxrz")
    public ResponseEntity<?> approveCxrz(@RequestBody TdxExportInvoiceModelDTO dto) {
        try {
            String result = tDxExportInvoiceService.approveCxrz(dto, this.getUserInfo());
            return ResponseEntity.ok(R.ok().put("data", result));
        } catch (Exception e) {
           log.info("业务处理异常：{}", e);
            return ResponseEntity.ok(R.error(e.getMessage()));
        }
    }

}
