package cn.superdesk.uniorder.controller.invoice.common;

import cn.superdesk.uniorder.common.constants.ResponseMsgConstants;
import cn.superdesk.uniorder.common.exception.utils.ExceptionUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dao.entity.invoice.common.InvoiceTaxRate;
import cn.superdesk.uniorder.dao.entity.invoice.common.InvoiceType;
import cn.superdesk.uniorder.dubbo.consumer.unified.UnifiedCustomerDubboConsumerService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 拉出来的公共
 * @Author: linjinyu
 * @CreateDate: 2021/3/31 下午12:18
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/3/31 下午12:18
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Api(value = "[开票发票]-公共-税率|发票种类", tags = {"[开票发票]-公共-税率|发票种类"})
@Slf4j
@RestController
@RequestMapping("/invoice/common")
public class InvoiceCommonController extends BaseController {

	@Autowired
	private UnifiedCustomerDubboConsumerService unifiedCustomerDubboConsumerService;

	/**
	 * 发票申请管理-税率列表
	 *
	 * @param
	 * @return
	 */
	@PostMapping("/taxdata")
	@ResponseBody
	public R<List<InvoiceTaxRate>> invoiceTaxRateList() {

		R<List<InvoiceTaxRate>> result = new R<>();

		try {
			Map<String, Object>  params = new HashMap<>();
			List<InvoiceTaxRate> taxs   = unifiedCustomerDubboConsumerService.getInvoiceTaxDataList(params);
			result.setData(taxs);
			result.setSuccess(true);

		} catch (Exception e) {

			result.setSuccess(false);
			result.setMessage(ResponseMsgConstants.ERROR_UNKNOW);
			log.error(ExceptionUtils.getMessage(e));
			e.printStackTrace();
		}
		return result;
	}

	/**
	 * 发票种类-列表
	 *
	 * @param
	 * @return
	 */
	@PostMapping("/invtypedata")
	@ResponseBody
	public R<List<InvoiceType>> invoiceTypeList() {

		R<List<InvoiceType>> result = new R<>();

		try {
			Map<String, Object> params = new HashMap<>();
			List<InvoiceType>   invs   = unifiedCustomerDubboConsumerService.getInvoiceTypeList(params);
			result.setData(invs);
			result.setSuccess(true);

		} catch (Exception e) {

			result.setSuccess(false);
			result.setMessage(ResponseMsgConstants.ERROR_UNKNOW);
			log.error(ExceptionUtils.getMessage(e));
			e.printStackTrace();
		}

		return result;
	}
}
