package com.dxhy.core.tab.controller;

import java.nio.charset.StandardCharsets;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.dxhy.core.tab.entity.RequestInfo;
import com.dxhy.core.tab.service.TabService;

import lombok.extern.slf4j.Slf4j;

/**
 * @author user
 */

@RestController
@RequestMapping("tab")
@Slf4j

public class TabController {
    @Resource
    private TabService taxService;

    @RequestMapping(value = "/queryCjTabInfo", method = RequestMethod.POST)
    public Object queryCjTabInfo(HttpServletResponse response, HttpServletRequest request) throws Exception {
        Object returnResult = null;
        String params = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
        log.info("=========采集金额请求参数进来了===========" + params);
        RequestInfo req = JSONObject.parseObject(params, RequestInfo.class);
        returnResult = taxService.queryCjTabInfo(req, request, response);
        return returnResult;
    }

    @RequestMapping(value = "/queryCjTaxTabInfo", method = RequestMethod.POST)
    public Object queryCjTaxTabInfo(HttpServletResponse response, HttpServletRequest request) throws Exception {
        Object returnResult = null;
        String params = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
        log.info("=========采集税额额请求参数进来了===========" + params);
        RequestInfo req = JSONObject.parseObject(params, RequestInfo.class);
        returnResult = taxService.queryCjTaxTabInfo(req, request, response);
        return returnResult;
    }

    @RequestMapping(value = "/queryRzTabInfo", method = RequestMethod.POST)
    public Object queryRzTabInfo(HttpServletResponse response, HttpServletRequest request) throws Exception {
        Object returnResult = null;
        String params = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
        log.info("=========认证请求参数进来了===========" + params);
        RequestInfo req = JSONObject.parseObject(params, RequestInfo.class);
        returnResult = taxService.queryRzTabInfo(req, request, response);
        return returnResult;
    }

    @RequestMapping(value = "/queryQsTabInfo", method = RequestMethod.POST)
    public Object queryQsTabInfo(HttpServletResponse response, HttpServletRequest request) throws Exception {
        Object returnResult = null;
        String params = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
        log.info("=========签收金额请求参数进来了===========" + params);
        RequestInfo req = JSONObject.parseObject(params, RequestInfo.class);
        returnResult =  taxService.queryQsTabInfo(req, request, response);
        return returnResult;
    }

    @RequestMapping(value = "/queryQsTaxTabInfo", method = RequestMethod.POST)
    public Object queryQsTaxTabInfo(HttpServletResponse response, HttpServletRequest request) throws Exception {
        Object returnResult = null;
        String params = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
        log.info("=========签收税额请求参数进来了===========" + params);
        RequestInfo req = JSONObject.parseObject(params, RequestInfo.class);
        returnResult = taxService.queryQsTaxTabInfo(req, request, response);
        return returnResult;
    }

    /**
     * 3个月后逾期未抵扣发票数量接口
     *
     * @author 陈刚扬
     * @date 2020/10/30
     * @param response
     * @param request
     * @return java.lang.Object
     */
    @RequestMapping(value = "/queryYQTabInfo", method = RequestMethod.POST)
    public Object queryYqTabInfo(HttpServletResponse response, HttpServletRequest request) throws Exception {
        Object returnResult = null;
        String params = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
        log.info("=========逾期请求参数进来了===========" + params);
        RequestInfo req = JSONObject.parseObject(params, RequestInfo.class);
        returnResult = taxService.queryYqTabInfo(req, request, response);
        return returnResult;
    }

    /**
     * 异常发票数量接口
     *
     * @author 陈刚扬
     * @date 2020/10/30
     * @param response
     * @param request
     * @return java.lang.String
     */
    @RequestMapping(value = "/queryYCTabInfo", method = RequestMethod.POST)
    public String queryycTabInfo(HttpServletResponse response, HttpServletRequest request) throws Exception {
        String returnResult = null;
        String params = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
        log.info("=========异常发票请求参数进来了===========" + params);
        RequestInfo req = JSONObject.parseObject(params, RequestInfo.class);
        returnResult = taxService.queryYcTabInfo(req, request, response);
        return returnResult;
    }

    /**
     * 跨年普票数量接口
     *
     * @author 陈刚扬
     * @date 2020/10/30
     * @param response
     * @param request
     * @return java.lang.String
     */
    @RequestMapping(value = "/queryPuPiaoTabInfo", method = RequestMethod.POST)
    public String queryPuPiaoTabInfo(HttpServletResponse response, HttpServletRequest request) throws Exception {
        String returnResult = null;
        String params = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
        log.info("=========跨年普票请求参数进来了===========" + params);
        RequestInfo req = JSONObject.parseObject(params, RequestInfo.class);
        returnResult = taxService.queryPuPiaoTabInfo(req, request, response);
        return returnResult;
    }

}
