package com.slodon.b2b2c.bo;

import com.slodon.b2b2c.business.pojo.*;
import com.slodon.b2b2c.core.constant.MemberConst;
import com.slodon.b2b2c.core.constant.OrderConst;
import com.slodon.b2b2c.core.util.StringUtil;
import com.slodon.b2b2c.enums.ProvinceJson;
import com.slodon.b2b2c.enums.StatsConstant;
import com.slodon.b2b2c.enums.TerminalJson;
import com.slodon.b2b2c.goods.pojo.Goods;
import com.slodon.b2b2c.goods.pojo.GoodsBrand;
import com.slodon.b2b2c.member.pojo.Member;
import com.slodon.b2b2c.member.pojo.MemberBalanceRecharge;
import com.slodon.b2b2c.seller.pojo.Store;
import com.slodon.b2b2c.statistics.pojo.MemberBehavior;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.*;

/**
 * 统计基础数据BO
 * 包含一段时间内数据库中的原始数据
 */
@Data
public class StatsBasicDataBO {

    //基础数据
    @ApiModelProperty("统计阶段内订单列表")
    private List<Order> orderList = new ArrayList<>();
    @ApiModelProperty("统计阶段内订单扩展列表")
    private List<OrderExtend> orderExtendList = new ArrayList<>();
    @ApiModelProperty("统计阶段内订单货品列表")
    private List<OrderProduct> orderProductList = new ArrayList<>();
    @ApiModelProperty("统计阶段内订单退货列表")
    private List<OrderReturn> orderReturnList = new ArrayList<>();
    @ApiModelProperty("统计阶段内订单售后单列表")
    private List<OrderAfterService> orderAfterServiceList = new ArrayList<>();
    @ApiModelProperty("统计阶段内商品列表")
    private List<Goods> goodsList = new ArrayList<>();
    @ApiModelProperty("统计阶段内用户行为列表")
    private List<MemberBehavior> memberBehaviorList = new ArrayList<>();
    @ApiModelProperty("统计阶段内会员提交的充值单列表")
    private List<MemberBalanceRecharge> memberBalanceRechargeList = new ArrayList<>();
    @ApiModelProperty("统计阶段内会员列表（有下单|退货|充值行为的会员）")
    private List<Member> memberList = new ArrayList<>();
    @ApiModelProperty("统计阶段内新注册的会员列表(按注册时间算)")
    private List<Member> newMemberList = new ArrayList<>();
    @ApiModelProperty("统计阶段内新增的商品列表（按创建时间算）")
    private List<Goods> newGoodsList = new ArrayList<>();
    @ApiModelProperty("统计阶段内新增的品牌列表(按创建时间算)")
    private List<GoodsBrand> newBrandList = new ArrayList<>();
    @ApiModelProperty("统计阶段内新增的店铺列表(按创建时间算)")
    private List<Store> newStoreList = new ArrayList<>();
    @ApiModelProperty("所有用户注册的行为")
    private List<MemberBehavior> memberRegisterBehaviorList = new ArrayList<>();
    @ApiModelProperty("平台所有店铺列表")
    private List<Store> storeList = new ArrayList<>();

    //基础数据二次处理
    @ApiModelProperty("1.订单map，以订单号为key，方便搜索")
    private Map<String, Order> orderMap;
    @ApiModelProperty("2.按照商品id将订单货品分组 key为goodsId")
    private Map<Long, List<OrderProduct>> goodsOrderProductMap;
    @ApiModelProperty("3.记录一个退货单map，方便使用退货单号进行查询 key为afsSn")
    private Map<String, OrderReturn> orderReturnMap;
    @ApiModelProperty("4.按照商品id将订退货单分组 key为goodsId")
    private Map<Long, List<OrderReturn>> goodsReturnMap;
    @ApiModelProperty("5.用户行为，按照商品分组 key为goodsId")
    private Map<Long, List<MemberBehavior>> goodsMemberBehaviorMap;
    @ApiModelProperty("6.用户行为，按照店铺分组 key为storeId")
    private Map<Long, List<MemberBehavior>> storeMemberBehaviorMap;
    @ApiModelProperty("7.用户行为，按照会员分组 key为memberId")
    private Map<Integer, List<MemberBehavior>> memberBehaviorMap;
    @ApiModelProperty("8.订单按照会员id分组 key为memberId")
    private Map<Integer, List<Order>> memberOrderMap;
    @ApiModelProperty("9.退货单按照会员id分组 key为memberId")
    private Map<Integer, List<OrderReturn>> memberOrderReturnMap;
    @ApiModelProperty("10.充值单按照会员id分组 key为memberId")
    private Map<Integer, List<MemberBalanceRecharge>> memberBalanceRechargeMap;
    @ApiModelProperty("11.会员-店铺统计分组 key为memberId-storeId")
    private Set<String> memberStoreSet;
    @ApiModelProperty("12.订单按会员id-店铺id分组 key为memberId-storeId")
    private Map<String, List<Order>> memberStoreOrderMap;
    @ApiModelProperty("13.退货单按会员id-店铺id分组 key为memberId-storeId")
    private Map<String, List<OrderReturn>> memberStoreOrderReturnMap;
    @ApiModelProperty("14.所有用户注册的行为map,以会员id为key，方便搜索")
    private Map<Integer, MemberBehavior> memberRegisterBehaviorMap;
    @ApiModelProperty("15.订单按照省份分组 key为provinceCode")
    private Map<String, List<Order>> provinceOrderMap;
    @ApiModelProperty("16.退货单按照省份分组 key为provinceCode")
    private Map<String, List<OrderReturn>> provinceOrderReturnMap;
    @ApiModelProperty("17.各省份新会员数 key为provinceCode")
    private Map<String, Integer> provinceNewMemberNumMap;
    @ApiModelProperty("18.各省份新店铺数 key为provinceCode")
    private Map<String, Integer> provinceNewStoreNumMap;
    @ApiModelProperty("19.订单按照店铺分组 key为storeId")
    private Map<Long, List<Order>> storeOrderMap;
    @ApiModelProperty("20.订单货品按照店铺分组 key为storeId")
    private Map<Long, List<OrderProduct>> storeOrderProductMap;
    @ApiModelProperty("21.退货单按照店铺分组 key为storeId")
    private Map<Long, List<OrderReturn>> storeOrderReturnMap;
    @ApiModelProperty("22.新增商品按照店铺分组 key为storeId")
    private Map<Long, List<Goods>> storeNewGoodsMap;
    @ApiModelProperty("23.订单按照终端分组 key为terminalCode")
    private Map<String, List<Order>> terminalOrderMap;
    @ApiModelProperty("24.用户行为，按照终端分组 key为terminalCode")
    private Map<String, List<MemberBehavior>> terminalMemberBehaviorMap;
    @ApiModelProperty("25.新增会员，按照终端分组 key为terminalCode")
    private Map<String, List<Member>> terminalNewMemberMap;
    @ApiModelProperty("26.各终端充值会员人数map key为terminalCode  Set key为memberId")
    private Map<String, Set<Integer>> terminalRechargeMemberMap;

    /**
     * 基础数据二次处理
     */
    public void basicDataTreatment() {
        //会员map，方便搜索
        Map<Integer/*memberId*/, Member> memberMap = new HashMap<>();
        this.memberList.forEach(member -> memberMap.put(member.getMemberId(), member));

        //1.订单map，以订单号为key，方便搜索
        Map<String/*orderSn*/, Order> orderMap = new HashMap<>();
        //8.订单按照会员id分组
        Map<Integer/*memberId*/, List<Order>> memberOrderMap = new HashMap<>();
        //11.会员-店铺统计分组
        Set<String/*memberId-storeId*/> memberStoreSet = new HashSet<>();
        //12.订单按会员id-店铺id分组
        Map<String/*memberId-storeId*/, List<Order>> memberStoreOrderMap = new HashMap<>();
        //19.订单按照店铺分组
        Map<Long/*storeId*/, List<Order>> storeOrderMap = new HashMap<>();
        //23.订单按照终端分组
        Map<String/*terminalCode*/, List<Order>> terminalOrderMap = new HashMap<>();
        this.orderList.forEach(order -> {
            orderMap.put(order.getOrderSn(), order);

            //按照会员id分组
            if (memberOrderMap.containsKey(order.getMemberId())) {
                memberOrderMap.get(order.getMemberId()).add(order);
            } else {
                List<Order> list = new ArrayList<>();
                list.add(order);
                memberOrderMap.put(order.getMemberId(), list);
            }

            String memberStoreId = order.getMemberId() + "-" + order.getStoreId();
            //会员-店铺统计分组
            memberStoreSet.add(memberStoreId);

            //订单按会员id-店铺id分组
            if (memberStoreOrderMap.containsKey(memberStoreId)) {
                memberStoreOrderMap.get(memberStoreId).add(order);
            } else {
                List<Order> list = new ArrayList<>();
                list.add(order);
                memberStoreOrderMap.put(memberStoreId, list);
            }

            //订单按照店铺分组
            if (storeOrderMap.containsKey(order.getStoreId())) {
                storeOrderMap.get(order.getStoreId()).add(order);
            } else {
                List<Order> list = new ArrayList<>();
                list.add(order);
                storeOrderMap.put(order.getStoreId(), list);
            }
        });
        this.orderExtendList.forEach(orderExtend -> {
            Order order = orderMap.get(orderExtend.getOrderSn());
            //订单按照终端分组
            String terminalCode = this.getOrderTerminalCode(orderExtend.getOrderFrom());
            if (terminalOrderMap.containsKey(terminalCode)) {
                terminalOrderMap.get(terminalCode).add(order);
            } else {
                List<Order> list = new ArrayList<>();
                list.add(order);
                terminalOrderMap.put(terminalCode, list);
            }
        });
        this.orderMap = orderMap;
        this.memberOrderMap = memberOrderMap;
        this.memberStoreOrderMap = memberStoreOrderMap;
        this.storeOrderMap = storeOrderMap;
        this.terminalOrderMap = terminalOrderMap;

        //2.按照商品id将订单货品分组
        Map<Long/*goodsId*/, List<OrderProduct>> goodsOrderProductMap = new HashMap<>();
        //20.订单货品按照店铺分组
        Map<Long/*storeId*/, List<OrderProduct>> storeOrderProductMap = new HashMap<>();
        this.orderProductList.forEach(orderProduct -> {
            //按照商品id将订单货品分组
            if (goodsOrderProductMap.containsKey(orderProduct.getGoodsId())) {
                goodsOrderProductMap.get(orderProduct.getGoodsId()).add(orderProduct);
            } else {
                List<OrderProduct> list = new ArrayList<>();
                list.add(orderProduct);
                goodsOrderProductMap.put(orderProduct.getGoodsId(), list);
            }

            //订单货品按照店铺分组
            if (storeOrderProductMap.containsKey(orderProduct.getStoreId())) {
                storeOrderProductMap.get(orderProduct.getStoreId()).add(orderProduct);
            } else {
                List<OrderProduct> list = new ArrayList<>();
                list.add(orderProduct);
                storeOrderProductMap.put(orderProduct.getStoreId(), list);
            }
        });
        this.goodsOrderProductMap = goodsOrderProductMap;
        this.storeOrderProductMap = storeOrderProductMap;

        //3.记录一个退货单map，方便使用退货单号进行查询
        Map<String/*afsSn*/, OrderReturn> orderReturnMap = new HashMap<>();
        //9.退货单按照会员id分组
        Map<Integer/*memberId*/, List<OrderReturn>> memberOrderReturnMap = new HashMap<>();
        //13.退货单按会员id-店铺id分组
        Map<String/*memberId-storeId*/, List<OrderReturn>> memberStoreOrderReturnMap = new HashMap<>();
        //21.退货单按照店铺分组
        Map<Long/*storeId*/, List<OrderReturn>> storeOrderReturnMap = new HashMap<>();
        this.getOrderReturnList().forEach(orderReturn -> {
            orderReturnMap.put(orderReturn.getAfsSn(), orderReturn);

            //退货单按照会员id分组
            if (memberOrderReturnMap.containsKey(orderReturn.getMemberId())) {
                memberOrderReturnMap.get(orderReturn.getMemberId()).add(orderReturn);
            } else {
                List<OrderReturn> list = new ArrayList<>();
                list.add(orderReturn);
                memberOrderReturnMap.put(orderReturn.getMemberId(), list);
            }

            String memberStoreId = orderReturn.getMemberId() + "-" + orderReturn.getStoreId();
            //会员-店铺统计分组
            memberStoreSet.add(memberStoreId);

            //退货单按会员id-店铺id分组
            if (memberStoreOrderReturnMap.containsKey(memberStoreId)) {
                memberStoreOrderReturnMap.get(memberStoreId).add(orderReturn);
            } else {
                List<OrderReturn> list = new ArrayList<>();
                list.add(orderReturn);
                memberStoreOrderReturnMap.put(memberStoreId, list);
            }

            //退货单按照店铺分组
            if (storeOrderReturnMap.containsKey(orderReturn.getStoreId())) {
                storeOrderReturnMap.get(orderReturn.getStoreId()).add(orderReturn);
            } else {
                List<OrderReturn> list = new ArrayList<>();
                list.add(orderReturn);
                storeOrderReturnMap.put(orderReturn.getStoreId(), list);
            }
        });
        this.orderReturnMap = orderReturnMap;
        this.memberOrderReturnMap = memberOrderReturnMap;
        this.memberStoreSet = memberStoreSet;
        this.memberStoreOrderReturnMap = memberStoreOrderReturnMap;
        this.storeOrderReturnMap = storeOrderReturnMap;

        //4.按照商品id将订退货单分组
        Map<Long/*goodsId*/, List<OrderReturn>> goodsReturnMap = new HashMap<>();
        this.orderAfterServiceList.forEach(afterService -> {
            if (goodsReturnMap.containsKey(afterService.getGoodsId())) {
                goodsReturnMap.get(afterService.getGoodsId()).add(orderReturnMap.get(afterService.getAfsSn()));
            } else {
                List<OrderReturn> list = new ArrayList<>();
                list.add(orderReturnMap.get(afterService.getAfsSn()));
                goodsReturnMap.put(afterService.getGoodsId(), list);
            }
        });
        this.goodsReturnMap = goodsReturnMap;

        Map<Long/*goodsId*/, List<MemberBehavior>> goodsMemberBehaviorMap = new HashMap<>();
        Map<Long/*storeId*/, List<MemberBehavior>> storeMemberBehaviorMap = new HashMap<>();
        Map<Integer/*memberId*/, List<MemberBehavior>> memberBehaviorMap = new HashMap<>();
        //24.用户行为，按照终端分组
        Map<String/*terminalCode*/, List<MemberBehavior>> terminalMemberBehaviorMap = new HashMap<>();
        this.memberBehaviorList.forEach(memberBehavior -> {
            //5.用户行为，按照商品分组
            Long goodsId = memberBehavior.getGoodsId();
            if (!StringUtil.isNullOrZero(goodsId)) {
                if (goodsMemberBehaviorMap.containsKey(goodsId)) {
                    goodsMemberBehaviorMap.get(goodsId).add(memberBehavior);
                } else {
                    List<MemberBehavior> list = new ArrayList<>();
                    list.add(memberBehavior);
                    goodsMemberBehaviorMap.put(goodsId, list);
                }
            }

            //6.用户行为，按照店铺分组
            Long storeId = memberBehavior.getStoreId();
            if (!StringUtil.isNullOrZero(storeId)) {
                if (storeMemberBehaviorMap.containsKey(storeId)) {
                    storeMemberBehaviorMap.get(storeId).add(memberBehavior);
                } else {
                    List<MemberBehavior> list = new ArrayList<>();
                    list.add(memberBehavior);
                    storeMemberBehaviorMap.put(storeId, list);
                }
            }

            //7.用户行为，按照会员分组
            Integer memberId = memberBehavior.getMemberId();
            if (!StringUtil.isNullOrZero(memberId)) {
                if (memberBehaviorMap.containsKey(memberId)) {
                    memberBehaviorMap.get(memberId).add(memberBehavior);
                } else {
                    List<MemberBehavior> list = new ArrayList<>();
                    list.add(memberBehavior);
                    memberBehaviorMap.put(memberId, list);
                }
            }

            //用户行为，按照终端分组
            if (!StringUtils.isEmpty(memberBehavior.getSource())) {
                if (terminalMemberBehaviorMap.containsKey(memberBehavior.getSource())) {
                    terminalMemberBehaviorMap.get(memberBehavior.getSource()).add(memberBehavior);
                } else {
                    List<MemberBehavior> list = new ArrayList<>();
                    list.add(memberBehavior);
                    terminalMemberBehaviorMap.put(memberBehavior.getSource(), list);
                }
            }
        });
        this.goodsMemberBehaviorMap = goodsMemberBehaviorMap;
        this.storeMemberBehaviorMap = storeMemberBehaviorMap;
        this.memberBehaviorMap = memberBehaviorMap;
        this.terminalMemberBehaviorMap = terminalMemberBehaviorMap;

        //10.充值单按照会员id分组
        Map<Integer/*memberId*/, List<MemberBalanceRecharge>> memberBalanceRechargeMap = new HashMap<>();
        this.memberBalanceRechargeList.forEach(memberBalanceRecharge -> {
            if (memberBalanceRechargeMap.containsKey(memberBalanceRecharge.getMemberId())) {
                memberBalanceRechargeMap.get(memberBalanceRecharge.getMemberId()).add(memberBalanceRecharge);
            } else {
                List<MemberBalanceRecharge> list = new ArrayList<>();
                list.add(memberBalanceRecharge);
                memberBalanceRechargeMap.put(memberBalanceRecharge.getMemberId(), list);
            }
        });
        this.memberBalanceRechargeMap = memberBalanceRechargeMap;

        //14.所有用户注册的行为map,以会员id为key，方便搜索
        Map<Integer/*会员id*/, MemberBehavior> memberRegisterBehaviorMap = new HashMap<>();
        memberRegisterBehaviorList.forEach(memberBehavior -> {
            memberRegisterBehaviorMap.put(memberBehavior.getMemberId(), memberBehavior);
        });
        this.memberRegisterBehaviorMap = memberRegisterBehaviorMap;

        //15.订单按照省份分组
        Map<String/*provinceCode*/, List<Order>> provinceOrderMap = new HashMap<>();
        memberOrderMap.forEach((memberId, list) -> {
            //默认省份
            String provinceCode = "";
            if (memberRegisterBehaviorMap.containsKey(memberId)) {
                //埋点中有该会员的注册信息
                provinceCode = memberRegisterBehaviorMap.get(memberId).getProvinceCode();
            }
            provinceCode = ProvinceJson.provinceMap.containsKey(provinceCode) ? provinceCode : ProvinceJson.defaultProvinceCode;

            //构造省份订单
            if (!provinceOrderMap.containsKey(provinceCode)) {
                provinceOrderMap.put(provinceCode,new ArrayList<>());
            }
            provinceOrderMap.get(provinceCode).addAll(list);
        });
        this.provinceOrderMap = provinceOrderMap;

        //16.退货单按照省份分组
        Map<String/*provinceCode*/, List<OrderReturn>> provinceOrderReturnMap = new HashMap<>();
        memberOrderReturnMap.forEach((memberId, list) -> {
            //默认省份
            String provinceCode = "";
            if (memberRegisterBehaviorMap.containsKey(memberId)) {
                //埋点中有该会员的注册信息
                provinceCode = memberRegisterBehaviorMap.get(memberId).getProvinceCode();
            }
            provinceCode = ProvinceJson.provinceMap.containsKey(provinceCode) ? provinceCode : ProvinceJson.defaultProvinceCode;

            //构造省份退货单
            if (!provinceOrderReturnMap.containsKey(provinceCode)) {
                provinceOrderReturnMap.put(provinceCode, new ArrayList<>());
            }
            provinceOrderReturnMap.get(provinceCode).addAll(list);
        });
        this.provinceOrderReturnMap = provinceOrderReturnMap;

        //17.各省份新会员数
        Map<String/*provinceCode*/, Integer> provinceNewMemberNumMap = new HashMap<>();
        //25.新增会员，按照终端分组
        Map<String/*terminalCode*/, List<Member>> terminalNewMemberMap = new HashMap<>();
        this.newMemberList.forEach(member -> {
            //默认省份
            String provinceCode = "";
            if (memberRegisterBehaviorMap.containsKey(member.getMemberId())) {
                //埋点中有该会员的注册信息
                provinceCode = memberRegisterBehaviorMap.get(member.getMemberId()).getProvinceCode();
            }
            provinceCode = ProvinceJson.provinceMap.containsKey(provinceCode) ? provinceCode : ProvinceJson.defaultProvinceCode;

            //构造省份新增会员数
            provinceNewMemberNumMap.put(provinceCode, provinceNewMemberNumMap.getOrDefault(provinceCode, 0) + 1);

            //新增会员，按照终端分组
            String memberTerminalCode = this.getMemberTerminalCode(member);
            if (terminalNewMemberMap.containsKey(memberTerminalCode)) {
                terminalNewMemberMap.get(memberTerminalCode).add(member);
            } else {
                List<Member> list = new ArrayList<>();
                list.add(member);
                terminalNewMemberMap.put(memberTerminalCode, list);
            }
        });
        this.provinceNewMemberNumMap = provinceNewMemberNumMap;
        this.terminalNewMemberMap = terminalNewMemberMap;

        //18.各省份新店铺数
        Map<String/*provinceCode*/, Integer> provinceNewStoreNumMap = new HashMap<>();
        this.newStoreList.forEach(store -> {
            //默认省份
            String provinceCode = StringUtils.isEmpty(store.getProvinceCode()) ? ProvinceJson.defaultProvinceCode : store.getProvinceCode();
            provinceCode = ProvinceJson.provinceMap.containsKey(provinceCode) ? provinceCode : ProvinceJson.defaultProvinceCode;

            //构造省份新增会员数
            provinceNewStoreNumMap.put(provinceCode, provinceNewStoreNumMap.getOrDefault(provinceCode, 0) + 1);
        });
        this.provinceNewStoreNumMap = provinceNewStoreNumMap;

        //22.新增商品按照店铺分组
        Map<Long/*storeId*/, List<Goods>> storeNewGoodsMap = new HashMap<>();
        this.newGoodsList.forEach(goods -> {
            //新增商品按照店铺分组
            if (storeNewGoodsMap.containsKey(goods.getStoreId())) {
                storeNewGoodsMap.get(goods.getStoreId()).add(goods);
            } else {
                List<Goods> list = new ArrayList<>();
                list.add(goods);
                storeNewGoodsMap.put(goods.getStoreId(), list);
            }
        });
        this.storeNewGoodsMap = storeNewGoodsMap;

        //26.各终端充值会员人数map
        Map<String/*terminalCode*/, Set<Integer/*memberId*/>> terminalRechargeMemberMap = new HashMap<>();
        memberBalanceRechargeMap.forEach((memberId, rechargeList) -> {
            String memberTerminalCode = this.getMemberTerminalCode(memberMap.get(memberId));
            if (terminalRechargeMemberMap.containsKey(memberTerminalCode)) {
                terminalRechargeMemberMap.get(memberTerminalCode).add(memberId);
            } else {
                Set<Integer> set = new HashSet<>();
                set.add(memberId);
                terminalRechargeMemberMap.put(memberTerminalCode, set);
            }
        });
        this.terminalRechargeMemberMap = terminalRechargeMemberMap;

    }

    /**
     * 获取会员统计终端编码
     *
     * @param member
     * @return
     */
    private String getMemberTerminalCode(Member member) {
        if (StringUtils.isEmpty(member.getRegisterChannel())) {
            return TerminalJson.defaultTerminalCode;
        }
        switch (member.getRegisterChannel()) {
            case MemberConst.MEMBER_FROM_PC:
                return StatsConstant.TERMINAL_PC;
            case MemberConst.MEMBER_FROM_H5:
                return StatsConstant.TERMINAL_H5;
            case MemberConst.MEMBER_FROM_Android:
                return StatsConstant.TERMINAL_ANDROID;
            case MemberConst.MEMBER_FROM_IOS:
                return StatsConstant.TERMINAL_IOS;
            case MemberConst.MEMBER_FROM_WXMALL:
                return StatsConstant.TERMINAL_WX_XCX;
            case MemberConst.MEMBER_FROM_BDXCX:
                return StatsConstant.TERMINAL_BD_XCX;
            case MemberConst.MEMBER_FROM_ALIXCX:
                return StatsConstant.TERMINAL_ALI_XCX;
            case MemberConst.MEMBER_FROM_DYXCX:
                return StatsConstant.TERMINAL_DY_XCX;
            default:
                return TerminalJson.defaultTerminalCode;
        }
    }

    /**
     * 获取订单统计终端编码
     *
     * @param orderFrom 订单来源
     * @return 对应终端编码
     */
    private String getOrderTerminalCode(Integer orderFrom) {
        if (StringUtils.isEmpty(orderFrom)) {
            return TerminalJson.defaultTerminalCode;
        }
        switch (orderFrom) {
            case OrderConst.ORDER_FROM_PC:
                return StatsConstant.TERMINAL_PC;
            case OrderConst.ORDER_FROM_H5:
                return StatsConstant.TERMINAL_H5;
            case OrderConst.ORDER_FROM_Android:
                return StatsConstant.TERMINAL_ANDROID;
            case OrderConst.ORDER_FROM_IOS:
                return StatsConstant.TERMINAL_IOS;
            case OrderConst.ORDER_FROM_WXMALL:
                return StatsConstant.TERMINAL_WX_XCX;
            case OrderConst.ORDER_FROM_BDXCX:
                return StatsConstant.TERMINAL_BD_XCX;
            case OrderConst.ORDER_FROM_ALIXCX:
                return StatsConstant.TERMINAL_ALI_XCX;
            case OrderConst.ORDER_FROM_DYXCX:
                return StatsConstant.TERMINAL_DY_XCX;
            default:
                return TerminalJson.defaultTerminalCode;
        }
    }
}
