package cn.superdesk.uniorder.controller.accounting.customer;

import cn.hutool.core.collection.CollUtil;
import cn.superdesk.uniorder.common.enums.common.CommonAccountingStateEnum;
import cn.superdesk.uniorder.common.excel.ExcelResponse;
import cn.superdesk.uniorder.common.exception.utils.ExceptionUtils;
import cn.superdesk.uniorder.common.json.AnJsonUtils;
import cn.superdesk.uniorder.common.numerical.AnBeanUtils;
import cn.superdesk.uniorder.common.numerical.AnStringUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dao.entity.accounting.unified.customer.AccountingUnifiedCustomer;
import cn.superdesk.uniorder.dto.param.accounting.unified.customer.AccountingUnifiedCustomerCreateSelectedCreditParam;
import cn.superdesk.uniorder.dto.param.accounting.unified.customer.UnifiedCustomerCreateDimGoodsParam;
import cn.superdesk.uniorder.dto.vo.accounting.unified.customer.notyet.CustomerUnAccountingDimGoodsVo;
import cn.superdesk.uniorder.dto.vo.accounting.unified.customer.notyet.UnifiedOrderCustomerHeadSumVo;
import cn.superdesk.uniorder.dubbo.consumer.accounting.customer.AccountingUnifiedCustomerDubboConsumerService;
import cn.superdesk.uniorder.dubbo.consumer.order.base.UnifiedOrderDubboConsumerService;
import cn.superdesk.uniorder.dubbo.consumer.unified.UnifiedCustomerDubboConsumerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Api(value = "客户结算-未对账状态-商品维度", tags = {"客户结算-未对账状态-商品维度"})
@Slf4j
@RestController
@RequestMapping(value = "/accounting/unified/customer/dim/goods/notyet")
public class UnifiedCustomerNotYetDimGoodsController extends BaseController {


	@Autowired
	private UnifiedOrderDubboConsumerService unifiedOrderDubboConsumerService;

	@Autowired
	private UnifiedCustomerDubboConsumerService unifiedCustomerDubboConsumerService;

	@Autowired
	private AccountingUnifiedCustomerDubboConsumerService accountingUnifiedCustomerDubboConsumerService;

	/**
	 * 客户结算-未对账商品
	 *
	 * @return
	 * @url : http://order.avic-s.com/#/vendorUnreconOrder?id=71
	 * <p>
	 * /accounting/unified/customer/dim/goods/notyet/getCustomerUnAccountingDimGoodsList
	 * <p>
	 * 未对账列表分页
	 * , tags = {""}
	 */
	@ApiOperation(value = "客户结算-未对账商品-维度-商品", notes = "前端新添加页面-测试正常")
	@RequestMapping(value = "/getCustomerUnAccountingDimGoodsList", method = RequestMethod.POST)
	@ResponseBody
	public R<List<CustomerUnAccountingDimGoodsVo>> getCustomerUnAccountingDimGoodsList() {

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

		try {

			/****************************************** 1、未对账商品列表支持根据:下单时间OK startTime endTime、订单编号OK orderSn、订单类型OK、企业名称OK serviceNo、下单人姓名OK purchaseUserId purchaseUserName purchasePhone 查询 start ******************************************/
			Map<String, Object> params = new HashMap<>();

			/****************************************** 订单类型 支付方式 订单状态 start ******************************************/
			String serviceNo = getString("serviceNo");
			if (StringUtils.isNotBlank(serviceNo)) {
				List<String> outServices = Arrays.asList(serviceNo);
				params.put("outServices", outServices);
			}

			params.put("payType", getInteger("payType"));
			params.put("payTypeName", getString("payTypeName"));
			params.put("orderState", getInteger("orderState"));
			params.put("orderStateName", getString("orderStateName"));
			/****************************************** 订单类型 支付方式 订单状态 start ******************************************/

//			hasOutVirtId 0 条件忽略
//			hasOutVirtId 1 要有企业
//			hasOutVirtId 2 没有企业
			params.put("hasOutVirtId", getInteger("hasOutVirtId"));

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

			// 下单人 企业
			params.put("purchaseVirtId", getLong("purchaseVirtId"));
			params.put("purchaseVirtName", getString("purchaseVirtName"));

			// 下单人 信息
			params.put("purchaseUserId", getLong("purchaseUserId"));
			params.put("purchaseUserName", getString("purchaseUserName"));
			params.put("purchasePhone", getString("purchasePhone"));


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

			// 订单金额 =
			params.put("amount", getString("amount"));

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

			// 供应商对账状态  未对账 2
			params.put("accountingStateCustomer", CommonAccountingStateEnum.未对账.getKey());

			log.info("请求参数为 : {}", AnJsonUtils.toJson(params));

			result = unifiedOrderDubboConsumerService.getCustomerUnAccountingDimGoodsList(params, getPageNum(), getPageSize(), getToken());

			UnifiedOrderCustomerHeadSumVo supplierUnAccountingDimGoodsHeadSum = unifiedOrderDubboConsumerService.getCustomerUnAccountingDimGoodsHeadSum(getToken(), params);

			result.setHeadData(AnBeanUtils.beanToMap(supplierUnAccountingDimGoodsHeadSum));

		} catch (Exception e) {

			result.setCode(String.valueOf(e.hashCode()));
			result.setSuccess(false);
			result.setMessage(e.getMessage());

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

			e.printStackTrace();
		}
		return result;
	}


	/***
	 *
	 *
	 * /accounting/unified/customer/notyet/exportuaccountdata
	 *
	 * http://192.168.1.223:8089/web/accounting/unified/customer/notyet/exportuaccountdata?orderIds=55032,55031&token=eyJhbGciOiJIUzI1NiJ9.eyJzYWxlaWQiOm51bGwsInZpcnRJZHMiOm51bGwsIm91dExvZ2luIjoiMCIsInVzZXJOYW1lIjoid2FuZ3N5Iiwicm9sZVR5cGUiOiIxIiwib2NpZCI6bnVsbCwiZXhwIjoxNjAxMDAwNzgyLCJ1c2VySWQiOiI2MCIsImlhdCI6MTYwMDkxNDM4Mn0.2L-ZP_c2fdgREcvSVMpLa_HWjoKCY0RLGFnx2BtJoiQ
	 * @return
	 */
	@Deprecated
	@ApiOperation(value = "客户结算-未对账商品 opt 导出报表(弃用)-维度-商品", notes = "客户结算-未对账商品 opt 导出报表(弃用)-维度-商品")
	@RequestMapping(value = "/exportCustomerUnAccountingDimGoodsList", method = RequestMethod.GET)
	public void exportCustomerUnAccountingDimGoodsList(HttpServletResponse response) throws IOException {

		try {
			Map<String, Object> params = new HashMap<>();

			String unifiedOrderGoodsIdsStr = getString("unifiedOrderGoodsIds");

			if (StringUtils.isNotBlank(unifiedOrderGoodsIdsStr)) {

				List<Long> unifiedOrderGoodsIds = AnStringUtils.stringArrayConvertToLongList(unifiedOrderGoodsIdsStr, ",");

				if (CollUtil.isNotEmpty(unifiedOrderGoodsIds)) {
					// 订单商品 过来统一订单后的 unifiedOrderGoodsIds
					params.put("unifiedOrderGoodsIds", unifiedOrderGoodsIds);
				} else {
					return;
				}

			} else {


				/****************************************** 订单类型 支付方式 订单状态 start ******************************************/
				String serviceNo = getString("serviceNo");
				if (StringUtils.isNotBlank(serviceNo)) {
					List<String> outServices = Arrays.asList(serviceNo);
					params.put("outServices", outServices);
				}

				params.put("payType", getInteger("payType"));
				params.put("payTypeName", getString("payTypeName"));
				params.put("orderState", getInteger("orderState"));
				params.put("orderStateName", getString("orderStateName"));
				/****************************************** 订单类型 支付方式 订单状态 start ******************************************/

				// hasOutVirtId 0 条件忽略
				// hasOutVirtId 1 要有企业
				// hasOutVirtId 2 没有企业
				params.put("hasOutVirtId", getInteger("hasOutVirtId"));

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

				// 下单人 企业
				params.put("purchaseVirtId", getLong("purchaseVirtId"));
				params.put("purchaseVirtName", getString("purchaseVirtName"));

				// 下单人 信息
				params.put("purchaseUserId", getLong("purchaseUserId"));
				params.put("purchaseUserName", getString("purchaseUserName"));
				params.put("purchasePhone", getString("purchasePhone"));


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

				// 订单金额 =
				params.put("amount", getString("amount"));

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

				// 供应商对账状态  未对账 2
				params.put("accountingStateCustomer", CommonAccountingStateEnum.未对账.getKey());
			}

			log.info("客户结算-未对账订单 opt 导出报表 (未对账列表-导出) params: \n{}", AnJsonUtils.toJson(params));

			// 这个是从订单维度过来的方法 之前是因为 是 订单维度 的 列表显示 所以不能共用方法,现在这个加的 商品维度 的 列表显示 ,所以是能共用了,这个先屏蔽
//            List<UnifiedOrderCustomerNotCheckDetail2GoodsVo> excelResult = unifiedOrderDubboConsumerService.getCustomerUnAccountingDetailDimOrder2Goods(getToken(), params);

			List<CustomerUnAccountingDimGoodsVo> dataList = unifiedOrderDubboConsumerService.getCustomerUnAccountingDimGoodsList(params, getToken());

			String[] field = {
					"orderSn", "saleName", "purchaseVirtName",
					"purchaseUserName", "purchasePhone",
					"goodsId", "goodsName", "cateNameLv1", "cateNameLv2", "cateNameLv3", "selfOption", "unit", "quantity", "costPrice", "goodsCostAmount", "price", "goodsAmount",
					"taxRate", "taxCode",
					"createTime", "orderStateName",
					"expressCompany", "expressSn", "recUserName", "recUserPhone", "recAddress",
					"updateTime",
					"remarks"
			};

			String[] fieldZhCn = {
					"订单编号", "供应商名称", "企业名称",
					"下单人姓名", "下单人手机号",
					"商品Id", "商品名称", "一级分类", "二级分类", "三级分类", "商品规格", "单位", "数量", "成本单价(元)", "成本总价(元)", "销售单价(元)", "销售总价(元)",
					"税率%", "税务编码",
					"下单时间", "订单状态",
					"快递公司", "快递单号", "收货人", "收货手机号", "收货地址",
					"更新时间",
					"备注"
			};

			ExcelResponse.out(dataList, fieldZhCn, field, "未对账商品", "客户结算" + "_" + "未对账商品", response);

		} catch (Exception e) {

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

	}


	/***
	 * 客户结算-未对账商品-opt 导出表格-新版
	 *
	 * @throws IOException
	 */
	@ApiOperation(value = "客户结算-未对账商品 opt 导出报表(异步)-维度-商品", notes = "客户结算-未对账商品 opt 导出报表(异步)-维度-商品")
	@RequestMapping(value = "/exportExcelAccountingCustomerNotYetDimGoods", method = RequestMethod.POST)
	public R<String> exportExcelAccountingCustomerNotYetDimGoods() throws IOException {


		Map<String, Object> params = new HashMap<>();

		String unifiedOrderGoodsIdsStr = getString("unifiedOrderGoodsIds");

		if (StringUtils.isNotBlank(unifiedOrderGoodsIdsStr)) {

			List<Long> unifiedOrderGoodsIds = AnStringUtils.stringArrayConvertToLongList(unifiedOrderGoodsIdsStr, ",");

			if (CollUtil.isNotEmpty(unifiedOrderGoodsIds)) {
				// 订单商品 过来统一订单后的 unifiedOrderGoodsIds
				params.put("unifiedOrderGoodsIds", unifiedOrderGoodsIds);
			} else {
				return new R<String>("没有选择商品");
			}

		} else {

			/****************************************** 订单类型 支付方式 订单状态 start ******************************************/

			String serviceNo = getString("serviceNo");
			if (StringUtils.isNotBlank(serviceNo)) {
				List<String> outServices = Arrays.asList(serviceNo);
				params.put("outServices", outServices);
			}

			params.put("payType", getInteger("payType"));
			params.put("payTypeName", getString("payTypeName"));
			params.put("orderState", getInteger("orderState"));
			params.put("orderStateName", getString("orderStateName"));

			/****************************************** 订单类型 支付方式 订单状态 start ******************************************/

			// hasOutVirtId 0 条件忽略
			// hasOutVirtId 1 要有企业
			// hasOutVirtId 2 没有企业
			params.put("hasOutVirtId", getInteger("hasOutVirtId"));

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

			// 下单人 企业
			params.put("purchaseVirtId", getLong("purchaseVirtId"));
			params.put("purchaseVirtName", getString("purchaseVirtName"));

			// 下单人 信息
			params.put("purchaseUserId", getLong("purchaseUserId"));
			params.put("purchaseUserName", getString("purchaseUserName"));
			params.put("purchasePhone", getString("purchasePhone"));


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

			// 订单金额 =
			params.put("amount", getString("amount"));

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

			// 供应商对账状态  未对账 2
			params.put("accountingStateCustomer", CommonAccountingStateEnum.未对账.getKey());
		}

		log.info("客户结算-未对账商品-opt 导出表格-新版 params: \n{}", AnJsonUtils.toJson(params));

//		getCustomerUnAccountingDimGoodsList
		return new R<String>(unifiedOrderDubboConsumerService.exportExcelAccountingCustomerNotYetDimGoods(params, getToken()));

	}

	@ApiOperation(value = "客户结算-创建结算单-预览")
	@RequestMapping(value = "/createAccountingPreview", method = RequestMethod.POST)
	@ResponseBody
	public R<List<CustomerUnAccountingDimGoodsVo>> createAccountingPreview(

//			String ids
//			@ModelAttribute List<AccountingScoreCustomerCreateSelectedCreditParam> selectCredits
			String selectGoodsids
	) {

		log.info("createAccountingPreview params {}", selectGoodsids);

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

		try {

			List<AccountingUnifiedCustomerCreateSelectedCreditParam> credits = AnJsonUtils.toList(selectGoodsids, AccountingUnifiedCustomerCreateSelectedCreditParam.class);

			if (CollUtil.isEmpty(credits)) {
				result.setSuccess(false);
				result.setMessage("请选择至少 1 条流水！");
				return result;
			}

			List<String> unifiedOrderGoodsIds = credits.stream()
					.map(s -> s.getUnifiedOrderGoodsId().toString())
					.collect(Collectors.toList());

			Map<String, Object> params = new HashMap<>();
			params.put("ids", unifiedOrderGoodsIds.toArray());

			result = unifiedOrderDubboConsumerService.getCustomerUnAccountingDimGoodsList(params, 0, 99999, getToken());

			createAccountingCheck(result);

			if (!result.isSuccess()) {
				return result;
			}

			for (CustomerUnAccountingDimGoodsVo vo : result.getData()) {
				vo.setAccountingStateCustomerName(CommonAccountingStateEnum.getDesc(vo.getAccountingStateCustomer()));

//				vo.setInvoiceApplyStatusName(UnifiedOrderCreditInvoiceApplyStatusEnum.getDesc(vo.getInvoiceApplyStatus()));
//				vo.setInvoiceMakeStatusName(UnifiedOrderCreditInvoiceMakeStatusEnum.getDesc(vo.getInvoiceMakeStatus()));
//				vo.setBackStatusName(UnifiedOrderCreditBackStatusEnum.getDesc(vo.getBackStatus()));
			}


		} catch (Exception e) {

			result.setCode(String.valueOf(e.hashCode()));
			result.setSuccess(false);
			result.setMessage("系统查找失败！");

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

		}

		return result;
	}

	private void createAccountingCheck(R<List<CustomerUnAccountingDimGoodsVo>> result) {

		log.info("createAccountingCheck \n{}", AnJsonUtils.toJson(result));

		// TODO 检查这些商品是不是同一个
		// 订单类型
		// 企业

		// 基准
		CustomerUnAccountingDimGoodsVo benchmark = null;

		for (CustomerUnAccountingDimGoodsVo iterator : result.getData()) {


			if (null == benchmark) {

				benchmark = iterator;

			} else {
				log.info(AnJsonUtils.toJson(iterator));

				if (!iterator.getServiceNo().equals(benchmark.getServiceNo())) {
					result.setSuccess(false);
					result.setMessage("订单类型 不唯一,请重新生成！");
				}
				if (iterator.getPurchaseVirtId() == null) {
					result.setSuccess(false);
					result.setMessage("企业信息 缺失,请重新生成！");
				}
				if (!iterator.getPurchaseVirtId().equals(benchmark.getPurchaseVirtId())) {
					result.setSuccess(false);
					result.setMessage("企业信息 不唯一,请重新生成！");
				}
			}


		}
	}

	/***
	 * 客户结算-未对账商品-创建对账单-维度-商品 @RequestBody
	 * createBills
	 * @return
	 */
	@ApiOperation(value = "客户结算-未对账商品-创建对账单-维度-商品", notes = "")
	@RequestMapping(value = "/createStatementOfAccount", method = RequestMethod.POST)
	@ResponseBody
	public R<AccountingUnifiedCustomer> createStatementOfAccount(@RequestBody UnifiedCustomerCreateDimGoodsParam params) {

		R<AccountingUnifiedCustomer> result = new R<>();

		try {

			AccountingUnifiedCustomer statementOfAccount = accountingUnifiedCustomerDubboConsumerService.opCreateAccountingDimGoods(getToken(), params);

			if (statementOfAccount == null) {
				result.setCode(400);
				result.setSuccess(false);
				result.setMessage("服务号不存在！");
				return result;
			}

			result.setData(statementOfAccount);

		} catch (Exception e) {

			result.setCode(String.valueOf(e.hashCode()));
			result.setSuccess(false);
			result.setMessage(e.getMessage());

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

		return result;
	}

	/***
	 * 客户结算-对账单-opt btn 编辑对账
	 * 客户结算-对账单-opt btn 查看详情
	 * /getgoods
	 * @return
	 */
//	@ApiOperation(value = "客户结算-对账单-opt btn 编辑对账 | opt btn 查看详情-维度-商品", notes = "未整改")
//	@RequestMapping(value = "/statementOfAccountDetail", method = RequestMethod.POST)
//	@ResponseBody
//	public R<List<CustomerUnAccountingDimGoodsVo>> statementOfAccountDetail() {
//
//
//		/****************************************** 检验 mark by linjinyu at 20210105 start ******************************************/
//		String accountingOrderSn = AnStringUtils.getString(getString("accountingOrderSn"));
//		if (StringUtils.isBlank(accountingOrderSn)) {
//			return ResponseResultUtil.createErrorResult("500", "参考缺失:对账单编号");
//		}
//
//
//		R<List<CustomerUnAccountingDimGoodsVo>> result = new R<>();
//
//		try {
//			Map<String, Object> params = new HashMap<>();
//
//			params.put("accountingOrderSn", accountingOrderSn);
//
//			List<CustomerUnAccountingDimGoodsVo> unifiedOrderGoodsOfStatementOfAccountList = unifiedOrderDubboConsumerService.getCustomerStatementOfAccountDetailDimGoods2Goods(params);
//
//			result.setData(unifiedOrderGoodsOfStatementOfAccountList);
//
//		} catch (Exception e) {
//
//			result.setCode(String.valueOf(e.hashCode()));
//			result.setSuccess(false);
//			result.setMessage(e.getMessage());
//
//			log.error(ExceptionUtils.getMessage(e));
//			e.printStackTrace();
//		}
//		return result;
//	}

	/**
	 * 客户结算-未对账订单-对账单详情-详情导出
	 * /exportgoods
	 * @return
	 */
//	@ApiOperation(value = "客户结算-未对账商品-对账单详情-详情导出-维度-商品", notes = "未整改")
//	@RequestMapping(value = "/exportStatementOfAccountDetail", method = RequestMethod.GET)
//	public void exportStatementOfAccountDetail(HttpServletResponse response) throws IOException {
//
//		try {
//
//			String accountingOrderSn = getString("accountingOrderSn");
//
//			Map<String, Object> params = new HashMap<>();
//			params.put("accountingOrderSn", accountingOrderSn);
//
//			log.info("客户结算-未对账订单-对账单详情-详情导出 params: \n{}", JsonUtils.toJson(params));
//
//			List<CustomerUnAccountingDimGoodsVo> unifiedOrderGoodsOfStatementOfAccountList = unifiedOrderDubboConsumerService.getCustomerStatementOfAccountDetailDimGoods2Goods(params);
//
////            for (UnifiedOrderGoodsOfStatementOfAccount goodsInfo : unifiedOrderGoodsOfStatementOfAccountList) {
////
////                /****************************************** 企业采购 情况 start ******************************************/
//////				String [] arrAddress = goodsInfo.getRecAddress().split(" ");
//////
//////				goodsInfo.setAddressProvince(arrAddress[0]);
//////				goodsInfo.setAddressCity(arrAddress[1]);
//////				goodsInfo.setAddressArea(arrAddress[2]);
//////				goodsInfo.setAddressTown(arrAddress[3]);
//////				goodsInfo.setAddressAddress(arrAddress[4]);
////
////                /****************************************** 企业采购 情况   end ******************************************/
////
////                /****************************************** 福利内购 情况 start ******************************************/
////                /****************************************** 福利内购 情况   end ******************************************/
////
////                /****************************************** 代客下单 情况 start ******************************************/
////                // 20200916_提出人_燕璐_超级前台_统一订单生产环境_对账单_详情_导出问题.md 问题排查出来了
//////				大概是2020年4月的时候 运营提出 代客下单 excel 导入时 会带有 手填地址
//////				当最终用了这个地址而没有选用商城过来的地址的情况
//////				地址为 安徽省合肥市包河区云谷路与环湖北路交叉口安徽创新馆 导致拆分时出错了
//////				之前为 安徽 合肥市 滨湖新区 成都路1888号中国农业银行安徽分行
//////				是有空格分开的
////                /****************************************** 代客下单 情况   end ******************************************/
////
////                /****************************************** 楼内闪送 情况 start ******************************************/
//////				goodsInfo.setAddressAddress(goodsInfo.getRecAddress());// eg : 公寓6号楼B区四川美术学院六号楼
////                /****************************************** 楼内闪送 情况   end ******************************************/
////
////                if (StringUtils.isNotBlank(goodsInfo.getRecAddress())) {
////
////                    String[] arrAddress = goodsInfo.getRecAddress().split(" ");
////                    if (arrAddress.length >= 5) {
////                        goodsInfo.setAddressProvince(arrAddress[0]);
////                        goodsInfo.setAddressCity(arrAddress[1]);
////                        goodsInfo.setAddressArea(arrAddress[2]);
////                        goodsInfo.setAddressTown(arrAddress[3]);
////                        goodsInfo.setAddressAddress(arrAddress[4]);
////                    } else {
////                        goodsInfo.setAddressAddress(goodsInfo.getRecAddress());
////                    }
////
////                }
////
////            }
//
////            String[] field = {
////                    "purchaseUserId", "purchaseUserName", "purchasePhone", "recUserName", "recUserPhone", "addressProvince", "addressCity", "addressArea", "addressTown", "addressAddress",
////                    "orderSn", "saleName", "purchaseVirtName",
////                    "goodsId",
////                    "goodsName", "cateNameLv3", "unit", "quantity",
////                    "costPrice", "costAmount",
////                    "price", "amount",
////                    "createTime",
////                    "expressCompany", "expressSn", "transportAmount"
////            };
////
////            String[] fieldZhCn = {
////                    "用户账号", "下单人", "下单人电话", "收货人", "收货人电话", "省", "市", "区", "街道", "详细地址",// add 20200819
////                    "订单编号", "供应商名称", "企业名称",
////                    "商品SKU",// add 20200819
////                    "商品名称", "商品规格", "单位", "数量",
////                    "成本单价", "成本总价",
////                    "销售单价", "销售总价",// add 20200819
////                    "下单时间",
////                    "物流公司", "物流单号", "运费",// add 20200819
////            };
//
//			String[] field = {
//					"orderSn", "saleName", "purchaseVirtName",
//					"purchaseUserName", "purchasePhone",
//					"goodsId", "goodsName", "cateNameLv1", "cateNameLv2", "cateNameLv3", "", "unit", "quantity", "costPrice", "goodsCostAmount", "price", "goodsAmount",
//					"taxRate", "taxCode",
//					"createTime", "orderStateName",
//					"expressCompany", "expressSn", "recUserName", "recUserPhone", "recAddress",
//					"updateTime",
//					"remarks"
//			};
//
//			String[] fieldZhCn = {
//					"订单编号", "供应商名称", "企业名称",
//					"下单人姓名", "下单人手机号",
//					"商品Id", "商品名称", "一级分类", "二级分类", "三级分类", "商品规格", "单位", "数量", "成本单价(元)", "成本总价(元)", "销售单价(元)", "销售总价(元)",
//					"税率%", "税务编码",
//					"下单时间", "订单状态",
//					"快递公司", "快递单号", "收货人", "收货手机号", "收货地址",
//					"更新时间",
//					"备注"
//			};
//
//			HSSFWorkbook workbook = ExcelUtils.createWorkbook(unifiedOrderGoodsOfStatementOfAccountList, fieldZhCn, field, "客户结算-对账单详情(商品维度)");
//			//准备将Excel的输出流通过response输出到页面下载
//			//二进制输出流
//			response.setContentType("application/octet-stream");
//			response.setCharacterEncoding("UTF-8");
//			//这后面可以设置导出Excel的名称,此例中名为student.xls
//			response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("客户结算-对账单详情(商品维度)_", "UTF-8") + accountingOrderSn + "_.xls");
//			//刷新缓冲
//			response.flushBuffer();
//
//			//workbook将Excel写入到response的输出流中,供页面下载
//			workbook.write(response.getOutputStream());
//
//		} catch (Exception e) {
//
//			log.error(ExceptionUtils.getMessage(e));
//			e.printStackTrace();
//		}
//
//	}
}
