package com.hzs.sale.order.controller.manager;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.hzs.common.core.annotation.AccessPermissions;
import com.hzs.common.core.annotation.Log;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.enums.*;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.core.utils.StringUtils;
import com.hzs.common.core.utils.poi.ExcelUtil;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.member.base.CuMember;
import com.hzs.common.domain.member.ext.CuMemberExt;
import com.hzs.common.domain.member.ext.CuMemberTeamExt;
import com.hzs.common.domain.sale.ext.SaOrderChargeLogExt;
import com.hzs.common.domain.sale.ext.SaOrderItemsExt;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.common.service.ITransactionCommonService;
import com.hzs.member.base.IMemberServiceApi;
import com.hzs.member.base.IMemberTeamServiceApi;
import com.hzs.sale.order.param.SaOrderChargeLogParam;
import com.hzs.sale.order.service.ISaOrderChargeLogService;
import com.hzs.sale.order.vo.OrderChargeLogVo;
import com.hzs.system.base.IAreaServiceApi;
import com.hzs.system.config.IVertexServiceApi;
import com.hzs.system.config.dto.VertexDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @BelongsProject: hzs_cloud
 * @BelongsPackage: com.hzs.sale.order.controller.manage
 * @Author: yh
 * @CreateTime: 2023-04-11  10:22
 * @Description:
 * @Version: 1.0
 */
@RestController
@RequestMapping("/manage/order-charge-log")
public class SaOrderChargeLogController extends BaseController {

    @Autowired
    private ITransactionCommonService transactionCommonService;
    @Autowired
    private ISaOrderChargeLogService orderChargeLogService;

    @DubboReference
    IVertexServiceApi vertexServiceApi;
    @DubboReference
    IMemberTeamServiceApi memberTeamServiceApi;
    @DubboReference
    IMemberServiceApi memberServiceApi;
    @DubboReference
    IAreaServiceApi areaServiceApi;

    /**
     * 撤单信息列表
     */
    @AccessPermissions("removeOrderList")
    @Log(module = EOperationModule.CANCEL_ORDER_LIST, business = EOperationBusiness.CANCEL_ORDER_LIST, method = EOperationMethod.SELECT)
    @GetMapping("list")
    public TableDataInfo list(SaOrderChargeLogParam orderChargeLogParam) {
        // 关联编号查询 会员id列表
        List<Long> queryMemberIdList = new ArrayList<>();
        if (StringUtils.isNotBlank(orderChargeLogParam.getRelevancyMemberCode())) {
            // 查询用户安置伞下
            R<CuMember> member = memberServiceApi.getMember(orderChargeLogParam.getRelevancyMemberCode());
            if (member.getData() == null) {
                return getDataTable(new ArrayList<>());
            }
            // 根据id 查询安置人伞下
            R<List<CuMemberExt>> memberExtList = memberServiceApi.queryPlaceSponsorUnderUmbrella(member.getData().getPkId());
            queryMemberIdList = memberExtList.getData().stream().map(mb -> {
                if (orderChargeLogParam.getRelevancyDept() != null && orderChargeLogParam.getRelevancyDept().equals(mb.getPlaceDept())) {
                    return mb.getPkId();
                } else {
                    return mb.getPkId();
                }
            }).collect(Collectors.toList());
        }
        orderChargeLogParam.setMemberIdList(queryMemberIdList);
        orderChargeLogParam.setPkCountry(SecurityUtils.getPkCountry());

        // 创建时间
        if (orderChargeLogParam.getStartCreationTime() != null) {
            orderChargeLogParam.setStartCreationTime(DateUtils.getStartTime(orderChargeLogParam.getStartCreationTime()));
        }
        if (orderChargeLogParam.getEndCreationTime() != null) {
            orderChargeLogParam.setEndCreationTime(DateUtils.getEndTime(orderChargeLogParam.getEndCreationTime()));
        }
        // 支付时间
        if (orderChargeLogParam.getStartPayTime() != null) {
            orderChargeLogParam.setStartPayTime(DateUtils.getStartTime(orderChargeLogParam.getStartPayTime()));
        }
        if (orderChargeLogParam.getEndPayTime() != null) {
            orderChargeLogParam.setEndPayTime(DateUtils.getEndTime(orderChargeLogParam.getEndPayTime()));
        }
        // 终审时间
        if (orderChargeLogParam.getStartLastInstanceDate() != null) {
            orderChargeLogParam.setStartLastInstanceDate(DateUtils.getStartTime(orderChargeLogParam.getStartLastInstanceDate()));
        }
        if (orderChargeLogParam.getEndLastInstanceDate() != null) {
            orderChargeLogParam.setEndLastInstanceDate(DateUtils.getEndTime(orderChargeLogParam.getEndLastInstanceDate()));
        }
        //  撤单时间
        if (orderChargeLogParam.getStartCancelOrderTime() != null) {
            orderChargeLogParam.setStartCancelOrderTime(DateUtils.getStartTime(orderChargeLogParam.getStartCancelOrderTime()));
        }
        if (orderChargeLogParam.getEndCancelOrderTime() != null) {
            orderChargeLogParam.setEndCancelOrderTime(DateUtils.getEndTime(orderChargeLogParam.getEndCancelOrderTime()));
        }

        startPage();
        List<SaOrderChargeLogExt> list = orderChargeLogService.cancellationList(orderChargeLogParam);
        List<OrderChargeLogVo> resultList = new ArrayList<>();

        if (CollectionUtil.isNotEmpty(list)) {
            // 会员团队
            R<List<CuMemberTeamExt>> memberTeamList = memberTeamServiceApi.queryCuMemberTeam(SecurityUtils.getPkCountry());
            Map<Long, CuMemberTeamExt> memberTeamMap = memberTeamList.getData().stream().collect(Collectors.toMap(CuMemberTeamExt::getPkId, Function.identity()));
            // 地区
            R<Map<Integer, String>> areaMap = areaServiceApi.getAreaMap(SecurityUtils.getPkCountry());
            // 体系
            R<List<VertexDTO>> vertexAll = vertexServiceApi.findAll();
            Map<Long, VertexDTO> vertexMap = vertexAll.getData().stream().collect(Collectors.toMap(VertexDTO::getPkId, Function.identity()));

            Map<String, String> transactionMap = transactionCommonService.exportEnumTransaction(EApproveRechargeStatus.values(), EPresaleStatus.values(),
                    ESupplyWay.values(), EDelivery.values(), EOrderStatus.values(), EPlaceDept.values(), ECustomerType.values(), EApprovalBusiness.values(),
                    EOrderType.values(), ETransportType.values(), EYesNo.values(), EShippingChannel.values(), EUnit.values(), ESignSource.values(), EOrderSource.values());

            for (SaOrderChargeLogExt orderChargeLogExt : list) {
                // 订单类型
                orderChargeLogExt.setOrderTypeStr(transactionMap.get(EOrderType.getEnumByValue(orderChargeLogExt.getOrderType()).getKey()));
                // 撤单类型
                if (orderChargeLogExt.getChargeType() != null) {
                    orderChargeLogExt.setChargeTypeStr(transactionMap.get(EApprovalBusiness.getEnumByValue(orderChargeLogExt.getChargeType()).getKey()));
                } else {
                    orderChargeLogExt.setChargeTypeStr(transactionMap.get(EApprovalBusiness.getEnumByValue(EApprovalBusiness.ORDER_CANCEL.getValue()).getKey()));
                }
                OrderChargeLogVo orderChargeLogVo = BeanUtil.copyProperties(orderChargeLogExt, OrderChargeLogVo.class);
                // 2023.11.22 不走签呈也需要添加中间操作表，用于区分部分撤单和调换货物，特殊编号进行隐藏
                if (null != orderChargeLogVo.getApprovalCode() && orderChargeLogVo.getApprovalCode().startsWith(EOrderPrefix.DEFAULT.getValue())) {
                    orderChargeLogVo.setApprovalCode("");
                }
                // 注册类型
                if (orderChargeLogExt.getOrderSource() != null) {
                    orderChargeLogVo.setCustomerTypeStr(transactionMap.get(EOrderSource.getEOrderSource(orderChargeLogExt.getOrderSource()).getKey()));
                }
                // 关联编号
                orderChargeLogVo.setRelevancyMemberCode(orderChargeLogParam.getRelevancyMemberCode());
                // 关联部门
                orderChargeLogVo.setRelevancyDept(orderChargeLogParam.getRelevancyDept());
                if (orderChargeLogParam.getRelevancyDept() != null) {
                    orderChargeLogVo.setRelevancyDeptStr(EPlaceDept.getEPlaceDept(orderChargeLogParam.getRelevancyDept()));
                }
                // 安置部门
                if (orderChargeLogExt.getPlaceDept() != null) {
                    orderChargeLogVo.setPlaceDeptStr(EPlaceDept.getEPlaceDept(orderChargeLogExt.getPlaceDept()));
                }
                // 消费金额(本地币)
                orderChargeLogVo.setOrderAmount(orderChargeLogExt.getOrderAmount());
                orderChargeLogVo.setOrderAchieve(orderChargeLogExt.getOrderAchieve().multiply(orderChargeLogExt.getInExchangeRate()));
                // 消费业绩(美金)
                orderChargeLogVo.setOrderAmountDollar(orderChargeLogExt.getOrderAmount().divide(orderChargeLogExt.getInExchangeRate(), 2, BigDecimal.ROUND_HALF_UP));
                orderChargeLogVo.setOrderAchieveDollar(orderChargeLogExt.getOrderAchieve());
                // 体系
                if (orderChargeLogExt.getPkVertex() != null) {
                    VertexDTO vertexDTO = vertexMap.get(orderChargeLogExt.getPkVertex());
                    if (vertexDTO != null) {
                        orderChargeLogVo.setPkVertex(vertexDTO.getPkId());
                        orderChargeLogVo.setVertexName(vertexDTO.getVertexName());
                    }
                }
                // 团队
                if (orderChargeLogExt.getPkTeamCode() != null) {
                    CuMemberTeamExt cuMemberTeamExt = memberTeamMap.get(orderChargeLogExt.getPkTeamCode());
                    if (cuMemberTeamExt != null) {
                        orderChargeLogVo.setPkTeamCode(cuMemberTeamExt.getPkId());
                        orderChargeLogVo.setPkTeamName(cuMemberTeamExt.getTeamName());
                    }
                }
                // 省
                if (orderChargeLogExt.getRecProvince() != null) {
                    orderChargeLogVo.setRecProvince(orderChargeLogExt.getRecProvince());
                    orderChargeLogVo.setRecProvinceStr(areaMap.getData().get(orderChargeLogExt.getRecProvince().intValue()));
                }
                // 市
                if (orderChargeLogExt.getRecCity() != null) {
                    orderChargeLogVo.setRecCity(orderChargeLogExt.getRecCity());
                    orderChargeLogVo.setRecCityStr(areaMap.getData().get(orderChargeLogExt.getRecCity().intValue()));
                }
                // 区县
                if (orderChargeLogExt.getRecCounty() != null) {
                    orderChargeLogVo.setRecCounty(orderChargeLogExt.getRecCounty());
                    orderChargeLogVo.setRecCountyStr(areaMap.getData().get(orderChargeLogExt.getRecCounty().intValue()));
                }
                // 详细地址
                orderChargeLogVo.setRecAddress(orderChargeLogExt.getRecAddress());
                List<SaOrderItemsExt> item = new ArrayList<>();
                SaOrderItemsExt s = new SaOrderItemsExt();
                s.setProductName(orderChargeLogExt.getProductName());
                s.setQuantity(orderChargeLogExt.getQuantity());
                s.setSpecsName(orderChargeLogExt.getClassifyName());
                item.add(s);
                orderChargeLogVo.setItemList(item);
                // 产品名称
                orderChargeLogVo.setProductNames(orderChargeLogExt.getProductName());
                // 产品规格
                orderChargeLogVo.setSpecsNames(orderChargeLogExt.getClassifyName());
                // 产品数量
                if (orderChargeLogExt.getQuantity() != null) {
                    orderChargeLogVo.setQuantitys(orderChargeLogExt.getQuantity().toString());
                }
                //产品总额(本地币)
                orderChargeLogVo.setPrices(orderChargeLogExt.getPrice().multiply(BigDecimal.valueOf(orderChargeLogExt.getQuantity())));
                // 订单总额(本地币)
                orderChargeLogVo.setOrderTotalAmount(orderChargeLogExt.getOrderAmount());
                //产品总额(美金)
                orderChargeLogVo.setPricesDollar(orderChargeLogExt.getPrice().multiply(BigDecimal.valueOf(orderChargeLogExt.getQuantity())).divide(orderChargeLogExt.getInExchangeRate(), 2, BigDecimal.ROUND_HALF_UP));
                // 产品邮费(美金)
                orderChargeLogVo.setPostageDollar(orderChargeLogExt.getPostage().divide(orderChargeLogExt.getInExchangeRate(), 2, BigDecimal.ROUND_HALF_UP));
                // 订单总额(美金)
                orderChargeLogVo.setOrderTotalAmountDollar(orderChargeLogExt.getOrderAmount().multiply(orderChargeLogExt.getInExchangeRate()));
                // 订单状态
                orderChargeLogVo.setOrderStatusStr(transactionMap.get(EOrderStatus.getEOrderStatus(orderChargeLogExt.getOrderStatus()).getKey()));
                //物流单号
                orderChargeLogVo.setLogisticsCodes(orderChargeLogExt.getLogisticsCode());
                // 物流公司
                orderChargeLogVo.setLogisticsCompanys(orderChargeLogExt.getLogisticsCompany());
                // 发货时间
                orderChargeLogVo.setDeliveryTime(orderChargeLogExt.getDeliveryTime());
                // 发货方式
                if (orderChargeLogExt.getDeliveryWay() != null) {
                    orderChargeLogVo.setDeliveryWayStr(transactionMap.get(EDelivery.getDelivery(orderChargeLogExt.getDeliveryWay()).getKey()));
                }
                //销售方式
                if (orderChargeLogExt.getOperateScope() != null && ESupplyWay.getESupplyWay(orderChargeLogExt.getOperateScope()) != null) {
                    orderChargeLogVo.setOperateScopeStr(transactionMap.get(ESupplyWay.getESupplyWay(orderChargeLogExt.getOperateScope()).getKey()));
                }
                // 运输方式
                List<String> tranList = new ArrayList<>();
                if (orderChargeLogExt.getIsLandTrans() != null && orderChargeLogExt.getIsLandTrans().equals(0)) {
                    tranList.add("陆运");
                } else if (orderChargeLogExt.getIsAirTrans() != null && orderChargeLogExt.getIsAirTrans().equals(0)) {
                    tranList.add("空运");
                } else if (orderChargeLogExt.getIsOceanTrans() != null && orderChargeLogExt.getIsOceanTrans().equals(0)) {
                    tranList.add("海运");
                }
                orderChargeLogVo.setTranTypeStr(StringUtils.join(tranList, ","));
                // 预售状态
                if (orderChargeLogExt.getPreSaleStatus() != null) {
                    orderChargeLogVo.setPreSaleStatusStr(transactionMap.get(EPresaleStatus.getEPresaleStatus(orderChargeLogExt.getPreSaleStatus()).getKey()));
                }
                // 支付方式
                if (orderChargeLogExt.getPayType() != null && EPayType.getEnumByValue(orderChargeLogExt.getPayType()) != null) {
                    orderChargeLogVo.setPayTypeStr(EPayType.getEnumByValue(orderChargeLogExt.getPayType()).getLabel());
                }
                // 撤单人
                orderChargeLogVo.setCreatorName(orderChargeLogExt.getCancelTheOrderName());
                // 终审
                //    orderChargeLogVo.setLastInstanceDate(orderChargeLogExt.getCancelOrderTime());
                orderChargeLogVo.setLastInstanceApprover(orderChargeLogExt.getCancelTheOrderName());
                if (orderChargeLogExt.getApprovalStatus() != null && EApproveRechargeStatus.getApproveRechargeStatus(orderChargeLogExt.getApprovalStatus()) != null) {
                    orderChargeLogVo.setLastInstanceStatus(transactionMap.get(EApproveRechargeStatus.getApproveRechargeStatus(orderChargeLogExt.getApprovalStatus()).getKey()));
                }
                if (orderChargeLogExt.getOrderChargeLogSource() != null && ESignSource.getSignSource(orderChargeLogExt.getOrderChargeLogSource()) != null) {
                    orderChargeLogVo.setOrderChargeLogSourceStr(transactionMap.get(ESignSource.getSignSource(orderChargeLogExt.getOrderChargeLogSource()).getKey()));
                }

                resultList.add(orderChargeLogVo);
            }
        }

        TableDataInfo tableDataInfo = getDataTable(list);
        tableDataInfo.setRows(resultList);
        return tableDataInfo;
    }

    /**
     * 导出
     */
    @PostMapping("export")
    public void list(SaOrderChargeLogParam orderChargeLogParam, HttpServletResponse response) {
        // 关联编号查询 会员id列表
        List<Long> queryMemberIdList = new ArrayList<>();
        if (StringUtils.isNotBlank(orderChargeLogParam.getRelevancyMemberCode())) {
            // 查询用户安置伞下
            R<CuMember> member = memberServiceApi.getMember(orderChargeLogParam.getRelevancyMemberCode());
            if (member.getData() == null) {
                ExcelUtil<OrderChargeLogVo> util = new ExcelUtil<>(OrderChargeLogVo.class);
                util.exportExcel(response, new ArrayList<>(), "撤单信息导出");
            }
            // 根据id 查询安置人伞下
            R<List<CuMemberExt>> memberExtList = memberServiceApi.queryPlaceSponsorUnderUmbrella(member.getData().getPkId());
            queryMemberIdList = memberExtList.getData().stream().map(mb -> {
                if (orderChargeLogParam.getRelevancyDept() != null && orderChargeLogParam.getRelevancyDept().equals(mb.getPlaceDept())) {
                    return mb.getPkId();
                } else {
                    return mb.getPkId();
                }
            }).collect(Collectors.toList());
        }
        orderChargeLogParam.setMemberIdList(queryMemberIdList);
        orderChargeLogParam.setPkCountry(SecurityUtils.getPkCountry());
        // 创建时间
        if (orderChargeLogParam.getStartCreationTime() != null) {
            orderChargeLogParam.setStartCreationTime(DateUtils.getStartTime(orderChargeLogParam.getStartCreationTime()));
        }
        if (orderChargeLogParam.getEndCreationTime() != null) {
            orderChargeLogParam.setEndCreationTime(DateUtils.getEndTime(orderChargeLogParam.getEndCreationTime()));
        }
        // 支付时间
        if (orderChargeLogParam.getStartPayTime() != null) {
            orderChargeLogParam.setStartPayTime(DateUtils.getStartTime(orderChargeLogParam.getStartPayTime()));
        }
        if (orderChargeLogParam.getEndPayTime() != null) {
            orderChargeLogParam.setEndPayTime(DateUtils.getEndTime(orderChargeLogParam.getEndPayTime()));
        }
        // 终审时间
        if (orderChargeLogParam.getStartLastInstanceDate() != null) {
            orderChargeLogParam.setStartLastInstanceDate(DateUtils.getStartTime(orderChargeLogParam.getStartLastInstanceDate()));
        }
        if (orderChargeLogParam.getEndLastInstanceDate() != null) {
            orderChargeLogParam.setEndLastInstanceDate(DateUtils.getEndTime(orderChargeLogParam.getEndLastInstanceDate()));
        }
        //  撤单时间
        if (orderChargeLogParam.getStartCancelOrderTime() != null) {
            orderChargeLogParam.setStartCancelOrderTime(DateUtils.getStartTime(orderChargeLogParam.getStartCancelOrderTime()));
        }
        if (orderChargeLogParam.getEndCancelOrderTime() != null) {
            orderChargeLogParam.setEndCancelOrderTime(DateUtils.getEndTime(orderChargeLogParam.getEndCancelOrderTime()));
        }

        List<SaOrderChargeLogExt> list = orderChargeLogService.cancellationList(orderChargeLogParam);
        List<OrderChargeLogVo> resultList = new ArrayList<>();

        if (CollectionUtil.isNotEmpty(list)) {
            // 会员团队
            R<List<CuMemberTeamExt>> memberTeamList = memberTeamServiceApi.queryCuMemberTeam(SecurityUtils.getPkCountry());
            Map<Long, CuMemberTeamExt> memberTeamMap = memberTeamList.getData().stream().collect(Collectors.toMap(CuMemberTeamExt::getPkId, Function.identity()));
            // 地区
            R<Map<Integer, String>> areaMap = areaServiceApi.getAreaMap(SecurityUtils.getPkCountry());
            // 体系
            R<List<VertexDTO>> vertexAll = vertexServiceApi.findAll();
            Map<Long, VertexDTO> vertexMap = vertexAll.getData().stream().collect(Collectors.toMap(VertexDTO::getPkId, Function.identity()));

            Map<String, String> transactionMap = transactionCommonService.exportEnumTransaction(EApproveRechargeStatus.values(), EPresaleStatus.values(),
                    ESupplyWay.values(), EDelivery.values(), EOrderStatus.values(), EPlaceDept.values(), ECustomerType.values(), EApprovalBusiness.values(),
                    EOrderType.values(), ETransportType.values(), EYesNo.values(), EShippingChannel.values(), EUnit.values(), ESignSource.values(), EOrderSource.values());

            for (SaOrderChargeLogExt orderChargeLogExt : list) {
                // 订单类型
                orderChargeLogExt.setOrderTypeStr(transactionMap.get(EOrderType.getEnumByValue(orderChargeLogExt.getOrderType()).getKey()));
                // 撤单类型
                if (orderChargeLogExt.getChargeType() != null) {
                    orderChargeLogExt.setChargeTypeStr(transactionMap.get(EApprovalBusiness.getEnumByValue(orderChargeLogExt.getChargeType()).getKey()));
                } else {
                    orderChargeLogExt.setChargeTypeStr(transactionMap.get(EApprovalBusiness.getEnumByValue(EApprovalBusiness.ORDER_CANCEL.getValue()).getKey()));
                }
                OrderChargeLogVo orderChargeLogVo = BeanUtil.copyProperties(orderChargeLogExt, OrderChargeLogVo.class);
                // 2023.11.22 不走签呈也需要添加中间操作表，用于区分部分撤单和调换货物，特殊编号进行隐藏
                if (null != orderChargeLogVo.getApprovalCode() && orderChargeLogVo.getApprovalCode().startsWith(EOrderPrefix.DEFAULT.getValue())) {
                    orderChargeLogVo.setApprovalCode("");
                }
                // 注册类型
                if (orderChargeLogExt.getOrderSource() != null) {
                    orderChargeLogVo.setCustomerTypeStr(transactionMap.get(EOrderSource.getEOrderSource(orderChargeLogExt.getOrderSource()).getKey()));
                }
                // 关联编号
                orderChargeLogVo.setRelevancyMemberCode(orderChargeLogParam.getRelevancyMemberCode());
                // 关联部门
                orderChargeLogVo.setRelevancyDept(orderChargeLogParam.getRelevancyDept());
                if (orderChargeLogParam.getRelevancyDept() != null) {
                    orderChargeLogVo.setRelevancyDeptStr(EPlaceDept.getEPlaceDept(orderChargeLogParam.getRelevancyDept()));
                }
                // 安置部门
                if (orderChargeLogExt.getPlaceDept() != null) {
                    orderChargeLogVo.setPlaceDeptStr(EPlaceDept.getEPlaceDept(orderChargeLogExt.getPlaceDept()));
                }
                // 消费金额(本地币)
                orderChargeLogVo.setOrderAmount(orderChargeLogExt.getOrderAmount());
                orderChargeLogVo.setOrderAchieve(orderChargeLogExt.getOrderAchieve().multiply(orderChargeLogExt.getInExchangeRate()));
                // 消费业绩(美金)
                orderChargeLogVo.setOrderAmountDollar(orderChargeLogExt.getOrderAmount().divide(orderChargeLogExt.getInExchangeRate(), 2, BigDecimal.ROUND_HALF_UP));
                orderChargeLogVo.setOrderAchieveDollar(orderChargeLogExt.getOrderAchieve());

                // 体系
                if (orderChargeLogExt.getPkVertex() != null) {
                    VertexDTO vertexDTO = vertexMap.get(orderChargeLogExt.getPkVertex());
                    if (vertexDTO != null) {
                        orderChargeLogVo.setPkVertex(vertexDTO.getPkId());
                        orderChargeLogVo.setVertexName(vertexDTO.getVertexName());
                    }
                }
                // 团队
                if (orderChargeLogExt.getPkTeamCode() != null) {
                    CuMemberTeamExt cuMemberTeamExt = memberTeamMap.get(orderChargeLogExt.getPkTeamCode());
                    if (cuMemberTeamExt != null) {
                        orderChargeLogVo.setPkTeamCode(cuMemberTeamExt.getPkId());
                        orderChargeLogVo.setPkTeamName(cuMemberTeamExt.getTeamName());
                    }
                }
                // 省
                if (orderChargeLogExt.getRecProvince() != null) {
                    orderChargeLogVo.setRecProvince(orderChargeLogExt.getRecProvince());
                    orderChargeLogVo.setRecProvinceStr(areaMap.getData().get(orderChargeLogExt.getRecProvince().intValue()));
                }
                // 市
                if (orderChargeLogExt.getRecCity() != null) {
                    orderChargeLogVo.setRecCity(orderChargeLogExt.getRecCity());
                    orderChargeLogVo.setRecCityStr(areaMap.getData().get(orderChargeLogExt.getRecCity().intValue()));
                }
                // 区县
                if (orderChargeLogExt.getRecCounty() != null) {
                    orderChargeLogVo.setRecCounty(orderChargeLogExt.getRecCounty());
                    orderChargeLogVo.setRecCountyStr(areaMap.getData().get(orderChargeLogExt.getRecCounty().intValue()));
                }
                // 详细地址
                orderChargeLogVo.setRecAddress(orderChargeLogExt.getRecAddress());
                List<SaOrderItemsExt> item = new ArrayList<>();
                SaOrderItemsExt s = new SaOrderItemsExt();
                s.setProductName(orderChargeLogExt.getProductName());
                s.setQuantity(orderChargeLogExt.getQuantity());
                s.setSpecsName(orderChargeLogExt.getClassifyName());
                item.add(s);
                orderChargeLogVo.setItemList(item);
                // 产品名称
                orderChargeLogVo.setProductNames(orderChargeLogExt.getProductName());
                // 产品规格
                orderChargeLogVo.setSpecsNames(orderChargeLogExt.getClassifyName());
                // 产品数量
                if (orderChargeLogExt.getQuantity() != null) {
                    orderChargeLogVo.setQuantitys(orderChargeLogExt.getQuantity().toString());
                }
                //产品总额(本地币)
                orderChargeLogVo.setPrices(orderChargeLogExt.getPrice().multiply(BigDecimal.valueOf(orderChargeLogExt.getQuantity())));
                // 订单总额(本地币)
                orderChargeLogVo.setOrderTotalAmount(orderChargeLogExt.getOrderAmount());
                //产品总额(美金)
                orderChargeLogVo.setPricesDollar(orderChargeLogExt.getPrice().multiply(BigDecimal.valueOf(orderChargeLogExt.getQuantity())).divide(orderChargeLogExt.getInExchangeRate(), 2, BigDecimal.ROUND_HALF_UP));
                // 产品邮费(美金)
                orderChargeLogVo.setPostageDollar(orderChargeLogExt.getPostage().divide(orderChargeLogExt.getInExchangeRate(), 2, BigDecimal.ROUND_HALF_UP));
                // 订单总额(美金)
                //          orderChargeLogVo.setOrderTotalAmountDollar(orderChargeLogExt.getOrderAmount().multiply(orderChargeLogExt.getInExchangeRate()));
                orderChargeLogVo.setOrderTotalAmountDollar(orderChargeLogVo.getOrderAmountDollar());
                // 订单状态
                orderChargeLogVo.setOrderStatusStr(transactionMap.get(EOrderStatus.getEOrderStatus(orderChargeLogExt.getOrderStatus()).getKey()));
                //物流单号
                orderChargeLogVo.setLogisticsCodes(orderChargeLogExt.getLogisticsCode());
                // 物流公司
                orderChargeLogVo.setLogisticsCompanys(orderChargeLogExt.getLogisticsCompany());
                // 发货时间
                orderChargeLogVo.setDeliveryTime(orderChargeLogExt.getDeliveryTime());
                // 发货方式
                if (orderChargeLogExt.getDeliveryWay() != null) {
                    orderChargeLogVo.setDeliveryWayStr(transactionMap.get(EDelivery.getDelivery(orderChargeLogExt.getDeliveryWay()).getKey()));
                }
                //销售方式
                if (orderChargeLogExt.getOperateScope() != null && ESupplyWay.getESupplyWay(orderChargeLogExt.getOperateScope()) != null) {
                    orderChargeLogVo.setOperateScopeStr(transactionMap.get(ESupplyWay.getESupplyWay(orderChargeLogExt.getOperateScope()).getKey()));
                }
                // 运输方式
                List<String> tranList = new ArrayList<>();
                if (orderChargeLogExt.getIsLandTrans() != null && orderChargeLogExt.getIsLandTrans().equals(0)) {
                    tranList.add("陆运");
                } else if (orderChargeLogExt.getIsAirTrans() != null && orderChargeLogExt.getIsAirTrans().equals(0)) {
                    tranList.add("空运");
                } else if (orderChargeLogExt.getIsOceanTrans() != null && orderChargeLogExt.getIsOceanTrans().equals(0)) {
                    tranList.add("海运");
                }
                orderChargeLogVo.setTranTypeStr(StringUtils.join(tranList, ","));
                // 预售状态
                if (orderChargeLogExt.getPreSaleStatus() != null) {
                    orderChargeLogVo.setPreSaleStatusStr(transactionMap.get(EPresaleStatus.getEPresaleStatus(orderChargeLogExt.getPreSaleStatus()).getKey()));
                }
                // 支付方式
                if (orderChargeLogExt.getPayType() != null && EPayType.getEnumByValue(orderChargeLogExt.getPayType()) != null) {
                    orderChargeLogVo.setPayTypeStr(EPayType.getEnumByValue(orderChargeLogExt.getPayType()).getLabel());
                }
                // 撤单人
                orderChargeLogVo.setCreatorName(orderChargeLogExt.getCancelTheOrderName());
                // 终审
                //  orderChargeLogVo.setLastInstanceDate(orderChargeLogExt.getCancelOrderTime());
                orderChargeLogVo.setLastInstanceApprover(orderChargeLogExt.getCancelTheOrderName());
                if (orderChargeLogExt.getApprovalStatus() != null && EApproveRechargeStatus.getApproveRechargeStatus(orderChargeLogExt.getApprovalStatus()) != null) {
                    orderChargeLogVo.setLastInstanceStatus(transactionMap.get(EApproveRechargeStatus.getApproveRechargeStatus(orderChargeLogExt.getApprovalStatus()).getKey()));
                }
                if (orderChargeLogExt.getOrderChargeLogSource() != null && ESignSource.getSignSource(orderChargeLogExt.getOrderChargeLogSource()) != null) {
                    orderChargeLogVo.setOrderChargeLogSourceStr(transactionMap.get(ESignSource.getSignSource(orderChargeLogExt.getOrderChargeLogSource()).getKey()));
                }
                resultList.add(orderChargeLogVo);
            }
        }

        ExcelUtil<OrderChargeLogVo> util = new ExcelUtil<>(OrderChargeLogVo.class);
        util.exportExcel(response, resultList, "撤单信息导出");
    }
}

