package cn.superdesk.uniorder.controller.order;

import cn.superdesk.uniorder.common.exception.utils.ExceptionUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.common.rest.response.ResponseResultOuterUtils;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dubbo.consumer.order.base.UnifiedOrderDubboConsumerService;
import cn.superdesk.uniorder.dubbo.consumer.invoice.customer.InvoiceApplyCustomerDubboConsumerService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: Java类作用描述
 * @Author: linjinyu
 * @CreateDate: 2021/3/5 下午4:46
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/3/5 下午4:46
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/order/manager/excel/export")
public class UnifiedOrderManagerExcelExportController extends BaseController {


	@Autowired
	private UnifiedOrderDubboConsumerService         unifiedOrderDubboConsumerService;
	@Autowired
	private InvoiceApplyCustomerDubboConsumerService invoiceApplyDubboConsumerService;


	/**
	 * 订单管理-订单管理-opt 导出报表 excel 2010
	 * HttpServletResponse response
	 * <p>
	 * param response
	 *
	 * @throws IOException
	 * @url /order/manager/excel/export/exportOrderData
	 */
	@ApiOperation(value = "订单管理-订单管理-opt 导出报表 excel 2010", notes = "")
	@RequestMapping(value = "/exportOrderData", method = RequestMethod.POST)
	public R<String> exportOrderData() throws IOException {

		try {

			// 筛选条件
			Map<String, Object> params = new HashMap<>();

			// 订单编号
			params.put("orderSn", getString("orderSn"));

			// 商品名称 搜索 like '%${goodsName}%'
			params.put("goodsName", getString("goodsName"));

			// 项目名称
			params.put("projectId", getString("projectId"));
			params.put("projectName", getString("projectName"));

			// 企业名称
			params.put("purchaseVirtId", getLong("purchaseVirtId"));
			params.put("purchaseVirtName", getString("purchaseVirtName"));

			// 供应商
			params.put("supplierId", getString("supplierId"));
			params.put("supplierName", getString("supplierName"));

			// 订单类型
			params.put("serviceNo", getString("serviceNo"));

			// 订单状态 业务方的 与 订单类型 联动 web/uservice/page
			params.put("orderStateName", getString("orderStateName"));

			// 下单人姓名
			params.put("purchaseUserId", getString("purchaseUserId"));
			params.put("purchaseUserName", getString("purchaseUserName"));
			params.put("purchasePhone", getString("purchasePhone"));

			// 支付方式
			params.put("payType", getString("payType"));

			// 下单时间
			params.put("startTime", getString("startTime"));
			params.put("endTime", getString("endTime"));
			// 查询条件 end


			return new R<String>(unifiedOrderDubboConsumerService.exportExcelOrderManagerGoodsData(getToken(), params));


		} catch (Exception e) {

			log.error(ExceptionUtils.getMessage(e));
			e.printStackTrace();

			return ResponseResultOuterUtils.createErrorResult("500", e.getMessage());
		}


	}


	/**
	 * 订单管理-订单管理-opt 导出成本 excel 2010
	 * <p>
	 * HttpServletResponse response
	 * <p>
	 * param response
	 *
	 * @throws IOException
	 * @url /order/manager/excel/export/exportCostPrice
	 */
	@ApiOperation(value = "订单管理-订单管理-opt 导出成本 excel 2010", notes = "")
	@RequestMapping(value = "/exportCostPrice", method = RequestMethod.POST)
	public R<String> exportCostPrice() throws IOException {
		try {

			// 筛选条件
			Map<String, Object> params = new HashMap<>();

			// 订单编号
			params.put("orderSn", getString("orderSn"));
			// 商品名称 搜索 like '%${goodsName}%'
			params.put("goodsName", getString("goodsName"));

			// 项目名称
			params.put("projectId", getString("projectId"));
			params.put("projectName", getString("projectName"));

			// 企业名称
			params.put("purchaseVirtId", getLong("purchaseVirtId"));
			params.put("purchaseVirtName", getString("purchaseVirtName"));

			// 供应商
			params.put("supplierId", getString("supplierId"));
			params.put("supplierName", getString("supplierName"));

			// 订单类型
			params.put("serviceNo", getString("serviceNo"));

			// 订单状态 业务方的 与 订单类型 联动 web/uservice/page
			params.put("orderStateName", getString("orderStateName"));

			// 下单人姓名
			params.put("purchaseUserId", getString("purchaseUserId"));
			params.put("purchaseUserName", getString("purchaseUserName"));
			params.put("purchasePhone", getString("purchasePhone"));

			// 支付方式
			params.put("payType", getString("payType"));

			// 下单时间
			params.put("startTime", getString("startTime"));
			params.put("endTime", getString("endTime"));

			return new R<String>(unifiedOrderDubboConsumerService.exportExcelOrderManagerGoodsCostPrice(getToken(), params));


		} catch (Exception e) {

			log.error(ExceptionUtils.getMessage(e));
			e.printStackTrace();

			return ResponseResultOuterUtils.createErrorResult("500", e.getMessage());
		}
	}
}
