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

import lombok.extern.slf4j.Slf4j;

/**
 * 业务单元管理
 *
 * @author dxhy
 */
@RestController
@RequestMapping("/exportCusRzdk")
@Slf4j
public class DomesticExportCustomsRzdkController extends AbstractController {
    @Resource
    private DomesticExportCustomsCkService domesticExportCustomsCkService;

    /**
     * 出口转内销认证 - 海关缴款书手工认证-列表查询
     */
    @PostMapping("/querySgByPage")
    public ResponseEntity<?> querySgByPage(Page page, @RequestBody TdxExportCustomsModelDTO dto) {
        try {
            return ResponseEntity
                .ok(R.ok().put("data", domesticExportCustomsCkService.querySgByPage(page, dto, this.getUserInfo())));
        } catch (Exception e) {
            log.error("报错：", e);
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

    /**
     * 出口转内销认证 - 海关缴款书手工认证-手工抵扣或不抵扣
     */
    @PostMapping("/approveSg")
    public ResponseEntity<?> approveSg(@RequestBody TdxExportCustomsModelDTO dto) {
        try {
            String result = domesticExportCustomsCkService.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("/queryBdkByPage")
    public ResponseEntity<?> queryBdkByPage(Page page, @RequestBody TdxExportCustomsModelDTO dto) {
        try {
            return ResponseEntity
                .ok(R.ok().put("data", domesticExportCustomsCkService.queryBdkByPage(page, dto, this.getUserInfo())));
        } catch (Exception e) {
            log.error("报错:", e);
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

    /**
     * 出口转内销认证 - 海关缴款书认证查询-列表查询
     */
    @PostMapping("/queryRzcxByPage")
    public ResponseEntity<?> queryRzcxByPage(Page page, @RequestBody TdxExportCustomsModelDTO dto) {
        try {
            return ResponseEntity
                .ok(R.ok().put("data", domesticExportCustomsCkService.queryRzcxByPage(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 TdxExportCustomsModelDTO dto) {
        try {
            String result = domesticExportCustomsCkService.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()));
        }
    }
}
