package cn.superdesk.uniorder.service.order.receive.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.superdesk.data.extract.enums.opCenter.OpCenterBizPlatformEnum;
import cn.superdesk.data.extract.enums.opCenter.OpCenterGoodsTypeEnum;
import cn.superdesk.data.extract.enums.opCenter.OpCenterOrderPayStatusEnum;
import cn.superdesk.data.extract.enums.opCenter.OpCenterPlatformAftersaleTypeEnum;
import cn.superdesk.uniorder.common.enums.common.*;
import cn.superdesk.uniorder.common.enums.order.UnifiedOrderCompletStateUtils;
import cn.superdesk.uniorder.common.json.AnJsonUtils;
import cn.superdesk.uniorder.common.lock.zookeeper.annotation.DistributedLock;
import cn.superdesk.uniorder.common.numerical.AnDateHelper;
import cn.superdesk.uniorder.dao.entity.base.UnifiedOrder;
import cn.superdesk.uniorder.dao.entity.base.UnifiedOrderGoods;
import cn.superdesk.uniorder.dao.entity.operationCenter.accounting.*;
import cn.superdesk.uniorder.dao.mapper.base.*;
import cn.superdesk.uniorder.dao.mapper.channel.UnifiedChannelProfitSyncMapper;
import cn.superdesk.uniorder.dao.mapper.channel.UnifiedChannelProfitSyncMapperEx;
import cn.superdesk.uniorder.dao.mapper.operationCenter.OperationCenterPaymentBizMapper;
import cn.superdesk.uniorder.dao.mapper.operationCenter.accounting.UnifiedAccountingOrderCreditMapper;
import cn.superdesk.uniorder.dao.mapper.operationCenter.accounting.UnifiedAccountingOrderGoodsMapper;
import cn.superdesk.uniorder.dao.mapper.operationCenter.accounting.UnifiedAccountingOrderMapper;
import cn.superdesk.uniorder.dao.mapper.unified.UnifiedOrderProfitMapper;
import cn.superdesk.uniorder.dao.mapper.unified.UnifiedOrderProfitMapperEx;
import cn.superdesk.uniorder.dto.param.operation.UnifiedOrderIssuesFlowingParam;
import cn.superdesk.uniorder.dto.receive.consumer.superdeskmall.opcenter.UnifiedFlscAccountingOrderGoodsParam;
import cn.superdesk.uniorder.dto.receive.consumer.superdeskmall.opcenter.UnifiedFlscAccountingOrderParam;
import cn.superdesk.uniorder.dto.receive.consumer.superdeskmall.opcenter.UnifiedFlscOrderCreditParam;
import cn.superdesk.uniorder.dto.receive.consumer.superdeskmall.unified.flsc.UnifiedFlscOrderGoodsReceiveParam;
import cn.superdesk.uniorder.dto.receive.consumer.superdeskmall.unified.flsc.UnifiedFlscOrderReceiveParam;
import cn.superdesk.uniorder.event.CommonEventPublisher;
import cn.superdesk.uniorder.service.order.base.CommonMergeOrderCreditProcessService;
import cn.superdesk.uniorder.service.order.base.CommonMergeOrderGoodsProcessService;
import cn.superdesk.uniorder.service.order.base.CommonOrderProcessService;
import cn.superdesk.uniorder.service.order.base.CommonOrderTransportProcessService;
import cn.superdesk.uniorder.service.order.receive.ReceiveFlscOrderService;
import com.alibaba.fastjson2.JSON;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description: Java类作用描述
 * @Author: linjinyu
 * @CreateDate: 2020/12/9 下午1:38
 * @UpdateUser: linjinyu
 * @UpdateDate: 2020/12/9 下午1:38
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Service
public class ReceiveFlscOrderServiceImpl implements ReceiveFlscOrderService {

    @Autowired
    private UnifiedOrderMapper unifiedOrderMapper;
    @Autowired
    private UnifiedOrderMapperEx unifiedOrderMapperEx;
    @Autowired
    private UnifiedOrderMapperExSupplierDimOrder unifiedOrderMapperExSupplier;
    @Autowired
    private UnifiedOrderGoodsMapper unifiedOrderGoodsMapper;
    @Autowired
    private UnifiedOrderGoodsMapperEx unifiedOrderGoodsMapperEx;

    /****************************************** 退单部分 ******************************************/
    @Autowired
    private UnifiedOrderReturnMapper unifiedOrderReturnMapper;
    @Autowired
    private UnifiedOrderReturnMapperEx unifiedOrderReturnMapperEx;
    @Autowired
    private UnifiedOrderReturnGoodsMapper unifiedOrderReturnGoodsMapper;
    @Autowired
    private UnifiedOrderReturnGoodsMapperEx unifiedOrderReturnGoodsMapperEx;
    /****************************************** 退单部分 ******************************************/

    /****************************************** 分润部分 ******************************************/
    @Autowired
    private UnifiedOrderProfitMapper unifiedOrderProfitMapper;
    @Autowired
    private UnifiedOrderProfitMapperEx unifiedOrderProfitMapperEx;
    @Autowired
    private UnifiedChannelProfitSyncMapper unifiedChannelProfitSyncMapper;
    @Autowired
    private UnifiedChannelProfitSyncMapperEx unifiedChannelProfitSyncMapperEx;
    /****************************************** 分润部分 ******************************************/

    @Autowired
    private CommonOrderProcessService commonOrderProcessService;
    @Autowired
    private CommonMergeOrderGoodsProcessService commonOrderGoodsMergeProcessService;
    @Autowired
    private CommonMergeOrderCreditProcessService commonOrderCreditMergeProcessService;
    @Autowired
    private CommonOrderTransportProcessService commonOrderTransportProcessService;

    @Autowired
    private CommonEventPublisher commonEventPublisher;

    @Autowired
    private Validator validator;

    @Autowired
    private OperationCenterPaymentBizMapper operationCenterPaymentBizMapper;
    @Autowired
    private UnifiedAccountingOrderMapper unifiedAccountingOrderMapper;
    @Autowired
    private UnifiedAccountingOrderGoodsMapper unifiedAccountingOrderGoodsMapper;
    @Autowired
    private UnifiedAccountingOrderCreditMapper unifiedAccountingOrderCreditMapper;

    /**
     * 商城 订单 正常 同步 已证实为-企业采购-福利内购
     *
     * @param receiveParam
     * @return
     */
    @Transactional
    @Override
    @DistributedLock(name = "#receiveParam.orderSn")
    public UnifiedOrderIssuesFlowingParam kafkaUnifiedOrderReceive(UnifiedFlscOrderReceiveParam receiveParam) {


        UnifiedOrderIssuesFlowingParam callback = new UnifiedOrderIssuesFlowingParam();

        callback.setUid(receiveParam.getUid());
        callback.setProcessResult(CommonProcessResultEnum.正常.getKey());
        callback.setProcessReport("");

        // 如果这个单的价格为 0 为过来还有什么意义呢?
        if (null != receiveParam.getPrice() && receiveParam.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
            commonOrderProcessService.cleanErrorOrder(receiveParam.getOrderSn());
            callback.setProcessResult(CommonProcessResultEnum.异常_数据本身缺失.getKey());
            callback.setProcessReport("订单金额为空");
            return callback;
        }

        // 如果 这个单 没有商品 直接 返回
        if (CollUtil.isEmpty(receiveParam.getGoods())) {
            commonOrderProcessService.cleanErrorOrder(receiveParam.getOrderSn());
            callback.setProcessResult(CommonProcessResultEnum.异常_数据本身缺失.getKey());
            callback.setProcessReport("订单商品为空");
            return callback;
        }


        // 处理订单
        UnifiedOrder unifiedOrderEntity = new UnifiedOrder();
        convertUnifiedOrderReceiveParam2Entity(receiveParam, unifiedOrderEntity);


        // 处理订单 商品
        List<UnifiedOrderGoods> processUnifiedOrderGoodsList = new ArrayList<>();
        List<UnifiedFlscOrderGoodsReceiveParam> unifiedOrderGoodsReceiveParamList = receiveParam.getGoods();

        for (UnifiedFlscOrderGoodsReceiveParam unifiedOrderGoodsReceiveParam : unifiedOrderGoodsReceiveParamList) {

            UnifiedOrderGoods unifiedOrderGoods = new UnifiedOrderGoods();
            convertUnifiedOrderGoodsReceiveParam2Entity(unifiedOrderGoodsReceiveParam, unifiedOrderGoods);
            unifiedOrderGoods.setOrderSn(unifiedOrderEntity.getOrderSn());
            processUnifiedOrderGoodsList.add(unifiedOrderGoods);

        }

        /****************************************** 运费要重构 业务逻辑修改 mark by linjinyu at 20201215 start ******************************************/
        commonOrderTransportProcessService.processTransport(unifiedOrderEntity, processUnifiedOrderGoodsList);
        /****************************************** 运费要重构 业务逻辑修改 mark by linjinyu at 20201215   end ******************************************/

        commonOrderProcessService.processOrderAmount(unifiedOrderEntity, processUnifiedOrderGoodsList, receiveParam.getUid());

        // 状态 -1:已关闭,0:待付款,1:待发货,2:待收货,3:已完成
        UnifiedOrder checkExistUnifiedOrder = unifiedOrderMapperEx.findByOrderSn(unifiedOrderEntity.getOrderSn());


        // 没有的订单id才可以保存
        if (checkExistUnifiedOrder == null) {

            // 没有商品 不保存订单数据
            if (CollUtil.isNotEmpty(processUnifiedOrderGoodsList)) {


                // 保存订单数据
                commonOrderProcessService.attachInsert(unifiedOrderEntity);

                for (UnifiedOrderGoods unifiedOrderGoods : processUnifiedOrderGoodsList) {
                    unifiedOrderGoodsMapper.insert(unifiedOrderGoods);
                }
            }

        } else {


            unifiedOrderEntity.setId(checkExistUnifiedOrder.getId());// 要先set id 在更新

            unifiedOrderEntity.setUpdateTime(DateUtil.date());

            unifiedOrderEntity.setAccountingStateCustomer(checkExistUnifiedOrder.getAccountingStateCustomer());
            unifiedOrderEntity.setAccountingStateSupplier(checkExistUnifiedOrder.getAccountingStateSupplier());

            commonOrderProcessService.attachUpdate(unifiedOrderEntity);


            // 重构 by linjinyu 20200915 start
            commonOrderGoodsMergeProcessService.processUnifiedOrderGoodsBykafkaPushOrderReceive(unifiedOrderEntity, processUnifiedOrderGoodsList, 1);
            // 重构 by linjinyu 20200915   end

        }


        commonEventPublisher.triggerUnifiedOrderProfitCalculationEvent(unifiedOrderEntity);


        log.info("##################### kafkaUnifiedOrderReceive end #####################");

        return callback;
    }

    /**
     * 接收商城对账订单数据 包含数据检查
     *
     * @param unifiedFlscAccountingOrderParam
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    @DistributedLock(name = "#unifiedFlscAccountingOrderParam.orderSn")
    public UnifiedOrderIssuesFlowingParam kafkaUnifiedFlscAccountingOrderReceive(UnifiedFlscAccountingOrderParam unifiedFlscAccountingOrderParam) {

        log.info("接收商城对账订单数据 数据检查 start");
        UnifiedOrderIssuesFlowingParam callback = handleParamCheck(unifiedFlscAccountingOrderParam);

        log.info("接收商城对账订单数据 数据检查 end, callback:{}", JSON.toJSONString(callback));
        // 如果数据检查不通过 直接返回
        if (!CommonProcessResultEnum.正常.getKey().equals(callback.getProcessResult())) {
            return callback;
        }
        // 判断订单是否已经存在
        UnifiedAccountingOrderExample unifiedAccountingOrderExample = new UnifiedAccountingOrderExample();
        unifiedAccountingOrderExample.createCriteria().andOrderSnEqualTo(unifiedFlscAccountingOrderParam.getOrderSn());
        List<UnifiedAccountingOrder> unifiedAccountingOrderList = unifiedAccountingOrderMapper.selectByExample(unifiedAccountingOrderExample);
        UnifiedAccountingOrder unifiedAccountingOrder;
        if (CollectionUtil.isNotEmpty(unifiedAccountingOrderList)) {
            unifiedAccountingOrder = unifiedAccountingOrderList.get(0);

        } else {
            unifiedAccountingOrder = null;
        }
        if (unifiedAccountingOrder != null) {
            // 订单已经存在，需要根据对账、结算相关状态判断 覆写哪些字段
            handleExistAccountingOrder(unifiedFlscAccountingOrderParam, unifiedAccountingOrder);
        } else {
            // 订单不存在

            // 福利商城推送订单 转换为 运营中心对账订单实体
            UnifiedAccountingOrder accountingOrder = handleFlscAccountingOrder(unifiedFlscAccountingOrderParam);

            // 福利推送订单商品 转换为 运营中心对账订单商品实体
            List<UnifiedAccountingOrderGoods> accountingOrderGoodsList = handleFlscAccountingOrderGoodsList(unifiedFlscAccountingOrderParam);

            // 福利商城推送订单流水 转换为 运营中心对账订单流水实体
            List<UnifiedAccountingOrderCredit> accountingOrderCreditList = handleFlscAccountingOrderCredit(unifiedFlscAccountingOrderParam);
            try {

                // 直接保存订单数据
                unifiedAccountingOrderMapper.insertSelective(accountingOrder);
                // 保存订单商品数据
                for (UnifiedAccountingOrderGoods unifiedAccountingOrderGoods : accountingOrderGoodsList) {
                    unifiedAccountingOrderGoodsMapper.insertSelective(unifiedAccountingOrderGoods);
                }
                // 保存订单流水数据
                for (UnifiedAccountingOrderCredit unifiedAccountingOrderCredit : accountingOrderCreditList) {
                    unifiedAccountingOrderCreditMapper.insertSelective(unifiedAccountingOrderCredit);
                }
            }catch (Exception e) {
                log.info("保存订单数据异常", e);
                throw e;
            }
        }

        return callback;
    }

    /**
     * 处理已存在的对账订单
     *
     * @param unifiedFlscAccountingOrderParam 福利商城推送的对账订单数据
     * @param unifiedAccountingOrder          运营中心数据库中已存在的对账订单实体
     */
    private void handleExistAccountingOrder(UnifiedFlscAccountingOrderParam unifiedFlscAccountingOrderParam, UnifiedAccountingOrder unifiedAccountingOrder) {
        // 如果订单商品数据中 已对账/对账中 的商品
        UnifiedAccountingOrderGoodsExample unifiedAccountingOrderGoodsExample = new UnifiedAccountingOrderGoodsExample();
        unifiedAccountingOrderGoodsExample.createCriteria()
                .andOrderSnEqualTo(unifiedFlscAccountingOrderParam.getOrderSn())
                .andBizPlatformCodeEqualTo(OpCenterBizPlatformEnum.福利商城.getCode())
                .andAccountingStatusIn(Lists.newArrayList(CommonAccountingStateEnum.已对账.getKey(), CommonAccountingStateEnum.对账中.getKey()));
        List<UnifiedAccountingOrderGoods> unifiedOrderGoods = unifiedAccountingOrderGoodsMapper.selectByExample(unifiedAccountingOrderGoodsExample);

        if (CollectionUtil.isEmpty(unifiedOrderGoods)) {
            /**
             * 如果 已对账/对账中 的商品 为空（没有已对账/对账中数据）则直接覆盖更新推送过来的主体数据
             */
            UnifiedAccountingOrder accountingOrder = BeanUtil.copyProperties(unifiedFlscAccountingOrderParam, UnifiedAccountingOrder.class);
            accountingOrder.setId(unifiedAccountingOrder.getId());
            accountingOrder.setUpdateTime(DateUtil.date());
            unifiedAccountingOrderMapper.updateByPrimaryKeySelective(accountingOrder);
            // 订单商品数据 添加个更新时间和更新人
            List<UnifiedAccountingOrderGoods> unifiedAccountingOrderGoods = handleFlscAccountingOrderGoodsList(unifiedFlscAccountingOrderParam);
            List<UnifiedAccountingOrderGoods> orderGoodsCollect = unifiedAccountingOrderGoods.stream().peek(item -> {
                item.setUpdateTime(DateUtil.date());
                item.setUpdateUserId("0");// 这个可以标记下是重推的数据
            }).collect(Collectors.toList());
            // 订单商品 先删除 再新增
            UnifiedAccountingOrderGoodsExample deleteUnifiedAccountingOrderGoodsExample = new UnifiedAccountingOrderGoodsExample();
            deleteUnifiedAccountingOrderGoodsExample.createCriteria()
                    .andOrderSnEqualTo(unifiedFlscAccountingOrderParam.getOrderSn())
                    .andBizPlatformCodeEqualTo(OpCenterBizPlatformEnum.福利商城.getCode());
            unifiedAccountingOrderGoodsMapper.deleteByExample(deleteUnifiedAccountingOrderGoodsExample);
            for (UnifiedAccountingOrderGoods unifiedAccountingOrderGood : orderGoodsCollect) {
                unifiedAccountingOrderGoodsMapper.insertSelective(unifiedAccountingOrderGood);
            }

            // 订单流水数据 添加个更新时间和更新人
            List<UnifiedAccountingOrderCredit> unifiedAccountingOrderCredit = handleFlscAccountingOrderCredit(unifiedFlscAccountingOrderParam);
            List<UnifiedAccountingOrderCredit> orderCreditCollect = unifiedAccountingOrderCredit.stream().peek(item -> {
                item.setUpdateTime(DateUtil.date());
                item.setUpdateUserId("0");// 这个可以标记下是重推的数据
            }).collect(Collectors.toList());
            // 订单流水 先删除 再新增
            UnifiedAccountingOrderCreditExample deleteUnifiedAccountingOrderCreditExample = new UnifiedAccountingOrderCreditExample();
            deleteUnifiedAccountingOrderCreditExample.createCriteria()
                    .andOrderSnEqualTo(unifiedFlscAccountingOrderParam.getOrderSn())
                    .andBizPlatformCodeEqualTo(OpCenterBizPlatformEnum.福利商城.getCode());
            unifiedAccountingOrderCreditMapper.deleteByExample(deleteUnifiedAccountingOrderCreditExample);
            for (UnifiedAccountingOrderCredit unifiedAccountingOrderCredit1 : orderCreditCollect) {
                unifiedAccountingOrderCreditMapper.insertSelective(unifiedAccountingOrderCredit1);
            }
            log.info("福利商城 对账订单已存在，直接覆盖更新主体数据，订单号：{}", unifiedFlscAccountingOrderParam.getOrderSn());
        } else {
            List<UnifiedAccountingOrderGoods> insertGoodsList = new ArrayList<>();
            List<UnifiedAccountingOrderGoods> updateGoodsList = new ArrayList<>();

            List<UnifiedAccountingOrderCredit> insertCreditList = new ArrayList<>();
            List<UnifiedAccountingOrderCredit> updateCreditList = new ArrayList<>();

            /**
             * 订单主体：只覆盖更新接口中“非金额”字段及更新时间；
             */
            String[] orderIgnoreArr = {"orderGoodsAmount", "orderNegotiatedAmount", "orderPrice", "orderSettlementAmount", "orderCostPrice", "transportAmount", "merchantTransportAmount", "discountAmount"};
            UnifiedAccountingOrder accountingOrder = BeanUtil.copyProperties(unifiedFlscAccountingOrderParam, UnifiedAccountingOrder.class, orderIgnoreArr);
            accountingOrder.setId(unifiedAccountingOrder.getId());
            accountingOrder.setUpdateTime(DateUtil.date());
            unifiedAccountingOrderMapper.updateByPrimaryKeySelective(accountingOrder);

            /**
             * “已对账/对账中”订单商品数据：
             * ·订单商品：只覆盖更新接口中“非金额、非商品数量”字段及更新时间，对账状态保持原有状态不变；
             * ·订单流水：只覆盖更新接口中“非金额”字段及更新时间，是否参与结算状态保持原有状态不变；
             *
             * “未对账/不对账”订单商品数据：覆盖更新订单商品和订单流水数据；
             * ·只覆盖更新接口字段的数据，不覆盖非接口字段数据；
             * ·若存在新增订单商品或订单流水数据：按（1）点进行存储；
             *
             * 使用福利商城推送的数据驱动更新，如果不存在的数据就新增，如果推送的数据已存在就修改，如果已存在的数据单推送的数据中没有那就不动这些数据
             */
            for (UnifiedFlscAccountingOrderGoodsParam unifiedFlscAccountingOrderGoodsParam : unifiedFlscAccountingOrderParam.getOrderGoodsList()) {
                // 查询商品是否已存在
                UnifiedAccountingOrderGoodsExample queryOrderGoodsExistExample = new UnifiedAccountingOrderGoodsExample();
                queryOrderGoodsExistExample.createCriteria()
                        .andBizPlatformCodeEqualTo(OpCenterBizPlatformEnum.福利商城.getCode())
                        .andOrderSnEqualTo(unifiedFlscAccountingOrderParam.getOrderSn())
                        .andOrderGoodsIdEqualTo(unifiedFlscAccountingOrderGoodsParam.getOrderGoodsId());
                List<UnifiedAccountingOrderGoods> unifiedAccountingOrderGoodsList = unifiedAccountingOrderGoodsMapper.selectByExample(queryOrderGoodsExistExample);
                if (CollectionUtil.isNotEmpty(unifiedAccountingOrderGoodsList) && unifiedAccountingOrderGoodsList.get(0) != null) {
                    // 存在
                    UnifiedAccountingOrderGoods unifiedAccountingOrderGoodsExistInDB = unifiedAccountingOrderGoodsList.get(0);

                    if (CommonAccountingStateEnum.已对账.getKey().equals(unifiedAccountingOrderGoodsExistInDB.getAccountingStatus()) || CommonAccountingStateEnum.对账中.getKey().equals(unifiedAccountingOrderGoodsExistInDB.getAccountingStatus())) {
                        // 已对账/对账中
                        String[] orderGoodsIgnoreArr = {"quantity", "originalUnitPrice", "originalTotalPrice", "sellingUnitPrice", "sellingTotalPrice", "negotiatedUnitPrice", "negotiatedTotalPrice", "settlementAmount", "costUnitPrice", "costTotalPrice", "discountAmount", "goodsOrderAmount"};
                        UnifiedAccountingOrderGoods accountingOrderGoods = BeanUtil.copyProperties(unifiedFlscAccountingOrderGoodsParam, UnifiedAccountingOrderGoods.class, orderGoodsIgnoreArr);
                        accountingOrderGoods.setId(unifiedAccountingOrderGoodsExistInDB.getId());
                        accountingOrderGoods.setUpdateTime(DateUtil.date());
                        updateGoodsList.add(accountingOrderGoods);
                    } else {
                        // 未对账/不对账
                        UnifiedAccountingOrderGoods unifiedAccountingOrderGoods = handleSingleOrderGoods(unifiedFlscAccountingOrderParam, unifiedFlscAccountingOrderGoodsParam);
                        unifiedAccountingOrderGoods.setId(unifiedAccountingOrderGoodsExistInDB.getId());
                        unifiedAccountingOrderGoods.setUpdateTime(DateUtil.date());
                        updateGoodsList.add(unifiedAccountingOrderGoods);
                    }
                } else {
                    // 不存在
                    UnifiedAccountingOrderGoods unifiedAccountingOrderGoods = handleSingleOrderGoods(unifiedFlscAccountingOrderParam, unifiedFlscAccountingOrderGoodsParam);
                    insertGoodsList.add(unifiedAccountingOrderGoods);
                }
            }
            for (UnifiedFlscOrderCreditParam unifiedFlscOrderCreditParam : unifiedFlscAccountingOrderParam.getOrderCreditList()) {
                // 查询流水是否已存在
                UnifiedAccountingOrderCreditExample queryOrderCreditExistExample = new UnifiedAccountingOrderCreditExample();
                queryOrderCreditExistExample.createCriteria()
                        .andBizPlatformCodeEqualTo(OpCenterBizPlatformEnum.福利商城.getCode())
                        .andOrderSnEqualTo(unifiedFlscAccountingOrderParam.getOrderSn())
                        .andOrderCreditIdEqualTo(unifiedFlscOrderCreditParam.getOrderCreditId())
                        .andOrderGoodsIdEqualTo(unifiedFlscOrderCreditParam.getOrderGoodsId());
                List<UnifiedAccountingOrderCredit> unifiedAccountingOrderCreditList = unifiedAccountingOrderCreditMapper.selectByExample(queryOrderCreditExistExample);
                if (CollectionUtil.isNotEmpty(unifiedAccountingOrderCreditList) && unifiedAccountingOrderCreditList.get(0) != null) {
                    // 流水存在
                    UnifiedAccountingOrderCredit unifiedAccountingOrderCreditExistInDB = unifiedAccountingOrderCreditList.get(0);

                    if (CommonAccountingStateEnum.已对账.getKey().equals(unifiedAccountingOrderCreditExistInDB.getAccountingStatus()) || CommonAccountingStateEnum.对账中.getKey().equals(unifiedAccountingOrderCreditExistInDB.getAccountingStatus())) {
                        // 已对账/对账中
                        String[] orderCreditIgnoreArr = {"orderAmount"};
                        UnifiedAccountingOrderCredit unifiedAccountingOrderCredit = BeanUtil.copyProperties(unifiedFlscOrderCreditParam, UnifiedAccountingOrderCredit.class, orderCreditIgnoreArr);
                        unifiedAccountingOrderCredit.setId(unifiedAccountingOrderCreditExistInDB.getId());
                        unifiedAccountingOrderCredit.setUpdateTime(DateUtil.date());
                        updateCreditList.add(unifiedAccountingOrderCredit);
                    } else {
                        // 未对账/不对账
                        UnifiedAccountingOrderCredit unifiedAccountingOrderCredit = handleSingleOrderCredit(unifiedFlscAccountingOrderParam, unifiedFlscOrderCreditParam);
                        unifiedAccountingOrderCredit.setId(unifiedAccountingOrderCreditExistInDB.getId());
                        unifiedAccountingOrderCredit.setUpdateTime(DateUtil.date());
                        updateCreditList.add(unifiedAccountingOrderCredit);
                    }
                } else {
                    // 流水不存在
                    UnifiedAccountingOrderCredit unifiedAccountingOrderCredit = handleSingleOrderCredit(unifiedFlscAccountingOrderParam, unifiedFlscOrderCreditParam);
                    insertCreditList.add(unifiedAccountingOrderCredit);
                }
            }

            /**
             * 更新 & 新增数据
             */
            if (CollectionUtil.isNotEmpty(updateGoodsList)) {
                for (UnifiedAccountingOrderGoods unifiedAccountingOrderGoods : updateGoodsList) {
                    unifiedAccountingOrderGoodsMapper.updateByPrimaryKeySelective(unifiedAccountingOrderGoods);
                }
            }

            if (CollectionUtil.isNotEmpty(updateCreditList)) {
                for (UnifiedAccountingOrderCredit unifiedAccountingOrderCredit : updateCreditList) {
                    unifiedAccountingOrderCreditMapper.updateByPrimaryKeySelective(unifiedAccountingOrderCredit);
                }
            }

            if (CollectionUtil.isNotEmpty(insertGoodsList)) {
                for (UnifiedAccountingOrderGoods unifiedAccountingOrderGoods : insertGoodsList) {
                    unifiedAccountingOrderGoodsMapper.insertSelective(unifiedAccountingOrderGoods);
                }
            }
            if (CollectionUtil.isNotEmpty(insertCreditList)) {
                for (UnifiedAccountingOrderCredit unifiedAccountingOrderCredit : insertCreditList) {
                    unifiedAccountingOrderCreditMapper.insertSelective(unifiedAccountingOrderCredit);
                }
            }

        }


    }

    /**
     * 处理单个订单商品
     *
     * @param unifiedFlscAccountingOrderParam
     * @param unifiedFlscAccountingOrderGoodsParam
     * @return
     */
    private UnifiedAccountingOrderGoods handleSingleOrderGoods(UnifiedFlscAccountingOrderParam
                                                                       unifiedFlscAccountingOrderParam, UnifiedFlscAccountingOrderGoodsParam unifiedFlscAccountingOrderGoodsParam) {
        UnifiedAccountingOrderGoods unifiedAccountingOrderGoods = BeanUtil.copyProperties(unifiedFlscAccountingOrderGoodsParam, UnifiedAccountingOrderGoods.class);

        // 业务类型id 取订单的
        unifiedAccountingOrderGoods.setBizTypeId(unifiedFlscAccountingOrderParam.getOrderBizTypeId());
        // 订单编号
        unifiedAccountingOrderGoods.setOrderSn(unifiedFlscAccountingOrderParam.getOrderSn());
        // 订单id
        unifiedAccountingOrderGoods.setOrderId(unifiedFlscAccountingOrderParam.getBizOrderId());
        // 业务平台编码
        unifiedAccountingOrderGoods.setBizPlatformCode(OpCenterBizPlatformEnum.福利商城.getCode());
        unifiedAccountingOrderGoods.setBizPlatformName(OpCenterBizPlatformEnum.福利商城.getName());
        // 订单类型编码
        unifiedAccountingOrderGoods.setOrderTypeCode(unifiedFlscAccountingOrderParam.getOrderTypeCode());
        // 订单时间
        unifiedAccountingOrderGoods.setOrderCreateTime(unifiedFlscAccountingOrderParam.getOrderCreateTime());
        // 完成时间
        unifiedAccountingOrderGoods.setFinishTime(unifiedFlscAccountingOrderParam.getFinishTime());
        // 运营商id
        unifiedAccountingOrderGoods.setOperatorId(unifiedFlscAccountingOrderParam.getOperatorId());
        // 供应商id
        unifiedAccountingOrderGoods.setSupplierId(unifiedFlscAccountingOrderParam.getSupplierId());
        // 运营商默认对账状态
        if (OpCenterGoodsTypeEnum.商户承担运费.getCode().equals(unifiedFlscAccountingOrderGoodsParam.getGoodsTypeId())) {
            // 商户承担运费默认为不对账
            unifiedAccountingOrderGoods.setAccountingStatus(CommonAccountingStateEnum.不对账.getKey());
        } else {
            unifiedAccountingOrderGoods.setAccountingStatus(CommonAccountingStateEnum.未对账.getKey());
        }
        // 创建时间
        unifiedAccountingOrderGoods.setCreateTime(DateUtil.date());
        return unifiedAccountingOrderGoods;
    }


    /**
     * 商城对账订单流水数据 转换为 运营中心对账订单流水实体
     *
     * @param unifiedFlscAccountingOrderParam
     * @return
     */
    private List<UnifiedAccountingOrderCredit> handleFlscAccountingOrderCredit(UnifiedFlscAccountingOrderParam
                                                                                       unifiedFlscAccountingOrderParam) {
        List<UnifiedFlscOrderCreditParam> orderCreditList = unifiedFlscAccountingOrderParam.getOrderCreditList();
        List<UnifiedAccountingOrderCredit> accountingOrderCreditList = new ArrayList<>();
        for (UnifiedFlscOrderCreditParam unifiedFlscOrderCreditParam : orderCreditList) {
            UnifiedAccountingOrderCredit unifiedAccountingOrderCredit = handleSingleOrderCredit(unifiedFlscAccountingOrderParam, unifiedFlscOrderCreditParam);
            accountingOrderCreditList.add(unifiedAccountingOrderCredit);
        }
        return accountingOrderCreditList;
    }

    /**
     * 处理单条流水
     *
     * @param unifiedFlscAccountingOrderParam
     * @param unifiedFlscOrderCreditParam
     * @return
     */
    private UnifiedAccountingOrderCredit handleSingleOrderCredit(UnifiedFlscAccountingOrderParam
                                                                         unifiedFlscAccountingOrderParam, UnifiedFlscOrderCreditParam unifiedFlscOrderCreditParam) {
        UnifiedAccountingOrderCredit unifiedAccountingOrderCredit = BeanUtil.copyProperties(unifiedFlscOrderCreditParam, UnifiedAccountingOrderCredit.class);
        // 业务类型id 取订单的
        unifiedAccountingOrderCredit.setBizTypeId(unifiedFlscAccountingOrderParam.getOrderBizTypeId());
        // 订单编号
        unifiedAccountingOrderCredit.setOrderSn(unifiedFlscAccountingOrderParam.getOrderSn());
        // 订单id
        unifiedAccountingOrderCredit.setOrderId(unifiedFlscAccountingOrderParam.getBizOrderId());
        // 业务平台编码
        unifiedAccountingOrderCredit.setBizPlatformCode(OpCenterBizPlatformEnum.福利商城.getCode());
        unifiedAccountingOrderCredit.setBizPlatformName(OpCenterBizPlatformEnum.福利商城.getName());
        // 订单类型编码
        unifiedAccountingOrderCredit.setOrderTypeCode(unifiedFlscAccountingOrderParam.getOrderTypeCode());
        // 供应商id
        unifiedAccountingOrderCredit.setSupplierId(unifiedFlscAccountingOrderParam.getSupplierId());
        // 平台支付方式 可能和订单的不一样
        Long platformPayTypeId = operationCenterPaymentBizMapper.selectPlatformPayTypeByPlatformCodeAndBizType(OpCenterBizPlatformEnum.福利商城.getCode(), unifiedFlscOrderCreditParam.getBizPayTypeId());
        unifiedAccountingOrderCredit.setPlatformPayTypeId(platformPayTypeId);
        // 订单时间
        unifiedAccountingOrderCredit.setOrderCreateTime(unifiedFlscAccountingOrderParam.getOrderCreateTime());
        // 完成时间
        unifiedAccountingOrderCredit.setFinishTime(unifiedFlscAccountingOrderParam.getFinishTime());
        // 运营商默认对账状态 & 是否参与运营商结算
        if (OpCenterGoodsTypeEnum.商户承担运费.getCode().equals(unifiedFlscOrderCreditParam.getGoodsTypeId())) {
            // 商户承担运费类型商品 默认不对账 不结算
            unifiedAccountingOrderCredit.setAccountingStatus(CommonAccountingStateEnum.不对账.getKey());
            unifiedAccountingOrderCredit.setIsSettlement(CommonSettlementStateEnum.不结算.getKey());
        } else {
            unifiedAccountingOrderCredit.setAccountingStatus(CommonAccountingStateEnum.未对账.getKey());
            unifiedAccountingOrderCredit.setIsSettlement(CommonSettlementStateEnum.未结算.getKey());
        }
        // 订单流水创建时间
        unifiedAccountingOrderCredit.setCreateTime(DateUtil.date());
        // 订单流水更新时间
        unifiedAccountingOrderCredit.setUpdateTime(DateUtil.date());
        return unifiedAccountingOrderCredit;
    }

    /**
     * 商城对账订单商品数据 转换为 运营中心对账订单商品实体
     *
     * @param
     * @return
     */
    private List<UnifiedAccountingOrderGoods> handleFlscAccountingOrderGoodsList(UnifiedFlscAccountingOrderParam
                                                                                         accountingOrderParam) {
        List<UnifiedFlscAccountingOrderGoodsParam> orderGoodsList = accountingOrderParam.getOrderGoodsList();
        List<UnifiedAccountingOrderGoods> accountingOrderGoodsList = new ArrayList<>();
        // 遍历构建实体
        for (UnifiedFlscAccountingOrderGoodsParam unifiedFlscAccountingOrderGoodsParam : orderGoodsList) {
            UnifiedAccountingOrderGoods unifiedAccountingOrderGoods = handleSingleOrderGoods(accountingOrderParam, unifiedFlscAccountingOrderGoodsParam);
            accountingOrderGoodsList.add(unifiedAccountingOrderGoods);
        }
        return accountingOrderGoodsList;
    }

    /**
     * 商城对账订单数据 转换为 运营中心对账订单实体
     *
     * @param unifiedFlscAccountingOrderParam
     * @return
     */
    private UnifiedAccountingOrder handleFlscAccountingOrder(UnifiedFlscAccountingOrderParam
                                                                     unifiedFlscAccountingOrderParam) {
        UnifiedAccountingOrder accountingOrder = BeanUtil.copyProperties(unifiedFlscAccountingOrderParam, UnifiedAccountingOrder.class);
        // 业务平台编码
        accountingOrder.setBizPlatformCode(OpCenterBizPlatformEnum.福利商城.getCode());
        accountingOrder.setBizPlatformName(OpCenterBizPlatformEnum.福利商城.getName());
        // 平台支付方式id
        Long platformPayTypeId = operationCenterPaymentBizMapper.selectPlatformPayTypeByPlatformCodeAndBizType(OpCenterBizPlatformEnum.福利商城.getCode(), unifiedFlscAccountingOrderParam.getBizOrderPayTypeId());
        accountingOrder.setPlatformPayTypeId(platformPayTypeId);
        return accountingOrder;
    }

    /**
     * 接收商城对账订单数据 数据检查
     *
     * @param unifiedFlscAccountingOrderParam
     * @return
     */
    private UnifiedOrderIssuesFlowingParam handleParamCheck(UnifiedFlscAccountingOrderParam
                                                                    unifiedFlscAccountingOrderParam) {
        UnifiedOrderIssuesFlowingParam callback = new UnifiedOrderIssuesFlowingParam();
        callback.setUid(unifiedFlscAccountingOrderParam.getUid());
        callback.setProcessResult(CommonProcessResultEnum.正常.getKey());
        callback.setProcessReport("");

        // 换货和维修的售后数据无需同步推送
        if (OpCenterPlatformAftersaleTypeEnum.换货.getCode().equals(unifiedFlscAccountingOrderParam.getPlatformAftersaleTypeId()) || OpCenterPlatformAftersaleTypeEnum.维修.getCode().equals(unifiedFlscAccountingOrderParam.getPlatformAftersaleTypeId())) {
            callback.setProcessResult(CommonProcessResultEnum.异常_程序检查.getKey());
            callback.setProcessReport("换货和维修的售后数据无需同步推送");
            return callback;
        }

        // 校验参数
        Set<ConstraintViolation<UnifiedFlscAccountingOrderParam>> validate = validator.validate(unifiedFlscAccountingOrderParam);

        // 如果不为空 则校验不通过
        if (!validate.isEmpty()) {
            // 这里校验出来的问题可能有多条，只取第一条记录就行了，反正都是不通过
            ConstraintViolation<UnifiedFlscAccountingOrderParam> next = validate.iterator().next();
            callback.setProcessResult(CommonProcessResultEnum.异常_程序检查.getKey());
            callback.setProcessReport(next.getMessage());
            return callback;
        }

        // 增加订单流水数据的支付状态检查，必须全部为已支付
        List<UnifiedFlscOrderCreditParam> orderCreditList = unifiedFlscAccountingOrderParam.getOrderCreditList();
        for (UnifiedFlscOrderCreditParam unifiedFlscOrderCreditParam : orderCreditList) {
            if (!OpCenterOrderPayStatusEnum.已支付.getCode().equals(unifiedFlscOrderCreditParam.getPayStatusId())) {
                callback.setProcessResult(CommonProcessResultEnum.异常_程序检查.getKey());
                callback.setProcessReport("非已支付（已退款）状态的订单流水不允许入库");
                return callback;
            }
        }

        return callback;
    }

    /**
     * 转换程序 order
     *
     * @param unifiedFlscOrderReceiveParam
     * @param unifiedOrderEntity
     */
    public void convertUnifiedOrderReceiveParam2Entity(UnifiedFlscOrderReceiveParam
                                                               unifiedFlscOrderReceiveParam, UnifiedOrder unifiedOrderEntity) {


        // 设定 订单来源
        unifiedOrderEntity.setServiceNo(CommonServiceNoEnum.getServiceNoByServiceId(unifiedFlscOrderReceiveParam.getOrderType()));
        unifiedOrderEntity.setServiceName(CommonServiceNoEnum.getServiceNameByServiceId(unifiedFlscOrderReceiveParam.getOrderType()));

        unifiedOrderEntity.setOrderType(CommonOrderTypeEnum.订单.getKey());

        unifiedOrderEntity.setOrderSn(unifiedFlscOrderReceiveParam.getOrderSn());
        unifiedOrderEntity.setOrderSnOutTrade(unifiedFlscOrderReceiveParam.getOrderSn());

        unifiedOrderEntity.setAmount(unifiedFlscOrderReceiveParam.getPrice());
        unifiedOrderEntity.setCostAmount(BigDecimal.ZERO);



        //		unifiedOrderEntity.setOrderState(unifiedFlscOrderReceiveParam.getOrderState());
        //		unifiedOrderEntity.setOrderStateName(SuperDeskMallOrderStatusEnum.getDesc(unifiedFlscOrderReceiveParam.getOrderState()));
        //		unifiedOrderEntity.setPayType(unifiedFlscOrderReceiveParam.getPayType());
        //		unifiedOrderEntity.setPayTypeName(UnifiedOrderPayTypeEnum.get(unifiedFlscOrderReceiveParam.getPayType()).getDesc());
        //		unifiedOrderEntity.setPayState(2);//

        unifiedOrderEntity.setOrderState(unifiedFlscOrderReceiveParam.getOrderState());
        unifiedOrderEntity.setOrderStateName(unifiedFlscOrderReceiveParam.getOrderStateName());

        unifiedOrderEntity.setPayType(unifiedFlscOrderReceiveParam.getPayType());
        unifiedOrderEntity.setPayTypeName(unifiedFlscOrderReceiveParam.getPayTypeName());

        unifiedOrderEntity.setPayState(ObjectUtil.isNull(unifiedFlscOrderReceiveParam.getPayState()) ? 2 : unifiedFlscOrderReceiveParam.getPayState());
        unifiedOrderEntity.setPayStateName(unifiedFlscOrderReceiveParam.getPayStateName());



        // 处理 deleted
        unifiedOrderEntity.setCompletState(
                UnifiedOrderCompletStateUtils.convertBySuperDeskMallOrderStatus(
                        unifiedFlscOrderReceiveParam.getOrderState(),
                        unifiedFlscOrderReceiveParam.getDeleted()
                )
        );


        Map<String, String> otherParams = new HashMap<>();
        otherParams.put("sendTime", AnDateHelper.parseDateToStrFormat(unifiedFlscOrderReceiveParam.getSendTime(), AnDateHelper.DATE_TIME_STRING));
        unifiedOrderEntity.setOtherParams(otherParams.toString());

        unifiedOrderEntity.setCreateUserId(null);
        unifiedOrderEntity.setUpdateUserId(1L);

        unifiedOrderEntity.setCreateTime(unifiedFlscOrderReceiveParam.getCreateTime());
        /****************************************** 加三个时间 start ******************************************/
        unifiedOrderEntity.setPayTime(unifiedFlscOrderReceiveParam.getPayTime());
        unifiedOrderEntity.setSendTime(unifiedFlscOrderReceiveParam.getSendTime());
        unifiedOrderEntity.setFinishTime(unifiedFlscOrderReceiveParam.getFinishTime());
        /****************************************** 加三个时间 start ******************************************/
        unifiedOrderEntity.setUpdateTime(unifiedFlscOrderReceiveParam.getFinishTime());

        unifiedOrderEntity.setProjectId(unifiedFlscOrderReceiveParam.getOrganizationId());
        unifiedOrderEntity.setProjectName(unifiedFlscOrderReceiveParam.getOrganizationName());

        unifiedOrderEntity.setPurchaseUserId(unifiedFlscOrderReceiveParam.getRealNameId());
        unifiedOrderEntity.setPurchaseUserName(unifiedFlscOrderReceiveParam.getRealName());
        unifiedOrderEntity.setPurchasePhone(unifiedFlscOrderReceiveParam.getMobile());

        unifiedOrderEntity.setPurchaseVirtId(unifiedFlscOrderReceiveParam.getEnterpriseId());
        unifiedOrderEntity.setPurchaseVirtName(unifiedFlscOrderReceiveParam.getEnterpriseName());

        unifiedOrderEntity.setOrderLockingCustomer(CommonAccountingLockingEnum.正常.getKey());
        unifiedOrderEntity.setOrderLockingSupplier(CommonAccountingLockingEnum.正常.getKey());

        unifiedOrderEntity.setAccountingStateCustomer(CommonAccountingStateEnum.未对账.getKey());
        unifiedOrderEntity.setAccountingStateSupplier(CommonAccountingStateEnum.未对账.getKey());

        unifiedOrderEntity.setSaleId(unifiedFlscOrderReceiveParam.getMerchId());
        unifiedOrderEntity.setSaleName(unifiedFlscOrderReceiveParam.getMerchName());


        unifiedOrderEntity.setSettlementType(2);
        unifiedOrderEntity.setSourceChannel(1);
        unifiedOrderEntity.setAppraiseState(2);

        unifiedOrderEntity.setTransportAmount(unifiedFlscOrderReceiveParam.getDispatchPrice());
        unifiedOrderEntity.setTransportMerchantAssumeAmount(unifiedFlscOrderReceiveParam.getDispatchPriceJd());

        /****************************************** 代客专用 Excel 导入后台账号 start mark by linjinyu at 20201221 ******************************************/
        unifiedOrderEntity.setOperAccount(unifiedFlscOrderReceiveParam.getOperAccount());
        unifiedOrderEntity.setOperName(unifiedFlscOrderReceiveParam.getOperName());
        /****************************************** 代客专用 Excel 导入后台账号   end mark by linjinyu at 20201221 ******************************************/

        unifiedOrderEntity.setUserType("2");
        unifiedOrderEntity.setUserName("系统");

        //		unifiedOrderEntity.setRecUserId(); // 没有
        unifiedOrderEntity.setRecUserName(unifiedFlscOrderReceiveParam.getAddressRealName());
        unifiedOrderEntity.setRecUserPhone(unifiedFlscOrderReceiveParam.getAddressMobile());
        unifiedOrderEntity.setRecAddress(unifiedFlscOrderReceiveParam.getAddressAddress());

        unifiedOrderEntity.setRemarks(unifiedFlscOrderReceiveParam.getRemark());

    }

    /**
     * 转换程序 goods
     *
     * @param unifiedOrderGoodsReceiveParam
     * @param unifiedOrderGoods
     */
    public void convertUnifiedOrderGoodsReceiveParam2Entity(UnifiedFlscOrderGoodsReceiveParam
                                                                    unifiedOrderGoodsReceiveParam, UnifiedOrderGoods unifiedOrderGoods) {


        unifiedOrderGoods.setGoodsId(unifiedOrderGoodsReceiveParam.getGoodsId());
        unifiedOrderGoods.setOutSnapshotOrderGoodsId(unifiedOrderGoodsReceiveParam.getOrderGoodsId());

        unifiedOrderGoods.setGoodsType(CommonOrderGoodsTypeEnum.商品.getKey());
        unifiedOrderGoods.setDirection(CommonDirectionEnum.正向.getKey());

        unifiedOrderGoods.setGoodsLockingCustomer(CommonAccountingLockingEnum.正常.getKey());
        unifiedOrderGoods.setGoodsLockingSupplier(CommonAccountingLockingEnum.正常.getKey());

        unifiedOrderGoods.setAccountingStateCustomer(CommonAccountingStateEnum.未对账.getKey());
        unifiedOrderGoods.setAccountingStateSupplier(CommonAccountingStateEnum.未对账.getKey());

        unifiedOrderGoods.setGoodsName(unifiedOrderGoodsReceiveParam.getTitle());

        Map<String, String> goodsParams = new HashMap<>();
        goodsParams.put("taxCode", unifiedOrderGoodsReceiveParam.getTaxCode());
        goodsParams.put("fiscalCode", unifiedOrderGoodsReceiveParam.getFiscalCode());
        unifiedOrderGoods.setGoodsParams(AnJsonUtils.toJson(goodsParams));


        // 关联问题 TAPD_ID_1000681_ 订单管理-导出报表-导出成本EXCEL中添加商品单位(添加至商品数量列后面).md
        // add by linjinyu 20200514 算了就这样修改吧
        unifiedOrderGoods.setUnit(StrUtil.isBlank(unifiedOrderGoodsReceiveParam.getUnit()) ? CommonOrderGoodsUnitEnum.项.getDesc() : unifiedOrderGoodsReceiveParam.getUnit());

        // 销售价 单价
        unifiedOrderGoods.setPrice(unifiedOrderGoodsReceiveParam.getUnitPrice());
        // add costprice 成本价
        unifiedOrderGoods.setCostPrice(unifiedOrderGoodsReceiveParam.getCostPrice());
        // 数量
        unifiedOrderGoods.setQuantity(unifiedOrderGoodsReceiveParam.getTotal());

        // 业务系统 的 订单sn
        //		unifiedOrderGoods.setOrderSn(unifiedOrder.getOrderSn());

        /************************************** update by linjinjy 20200904 20200723_林志鹏_税率,退款格式.docx **************************************/
        unifiedOrderGoods.setFiscalCode(unifiedOrderGoodsReceiveParam.getFiscalCode());
        unifiedOrderGoods.setTaxCode(unifiedOrderGoodsReceiveParam.getTaxCode());
        unifiedOrderGoods.setTaxRate(unifiedOrderGoodsReceiveParam.getTaxRate());
        /************************************** update by linjinjy 20200904 20200723_林志鹏_税率,退款格式.docx **************************************/

        /****************************************** 三级分类 20200904 by linjinyu 20200904_林志鹏_三极分类 ******************************************/
        unifiedOrderGoods.setCateIdLv1(unifiedOrderGoodsReceiveParam.getCateIdLv1());
        unifiedOrderGoods.setCateIdLv2(unifiedOrderGoodsReceiveParam.getCateIdLv2());
        unifiedOrderGoods.setCateIdLv3(unifiedOrderGoodsReceiveParam.getCateIdLv3());
        unifiedOrderGoods.setCateNameLv1(unifiedOrderGoodsReceiveParam.getCateNameLv1());
        unifiedOrderGoods.setCateNameLv2(unifiedOrderGoodsReceiveParam.getCateNameLv2());
        unifiedOrderGoods.setCateNameLv3(unifiedOrderGoodsReceiveParam.getCateNameLv3());
        /****************************************** 三级分类 20200904 by linjinyu 20200904_林志鹏_三极分类 ******************************************/

        unifiedOrderGoods.setCreateUserId(1L);
        unifiedOrderGoods.setCreateTime(DateUtil.date());
        unifiedOrderGoods.setUpdateUserId(1L);
        unifiedOrderGoods.setUpdateTime(DateUtil.date());

    }
}
