package com.gree.mall.manager.logic.order;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.util.StringUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.gree.mall.manager.bean.admin.AdminUserCom;
import com.gree.mall.manager.bean.order.OrderOldProductDTO;
import com.gree.mall.manager.bean.order.refund.OrderOfflineRefundAddBean;
import com.gree.mall.manager.bean.order.refund.OrderOfflineRefundDetailBean;
import com.gree.mall.manager.bean.order.refund.OrderOfflineRefundItemBean;
import com.gree.mall.manager.bean.order.refund.OrderOfflineRefundVO;
import com.gree.mall.manager.commonmapper.CommonMapper;
import com.gree.mall.manager.enums.ExamineStatusEnum;
import com.gree.mall.manager.enums.OrderRefundTypeEnum;
import com.gree.mall.manager.enums.OrderStatusEnum;
import com.gree.mall.manager.enums.material.DirectFlagEnum;
import com.gree.mall.manager.enums.material.GoodsMaterialStockAccBillTypeEnum;
import com.gree.mall.manager.enums.material.PayTypeEnum;
import com.gree.mall.manager.exception.RemoteServiceException;
import com.gree.mall.manager.logic.common.CommonLogic;
import com.gree.mall.manager.logic.goods.GoodsMaterialStockAccLogic;
import com.gree.mall.manager.logic.goods.JxGoodsLogic;
import com.gree.mall.manager.plus.entity.*;
import com.gree.mall.manager.plus.service.*;
import com.gree.mall.manager.utils.StringUtil;
import com.gree.mall.manager.zfire.bean.ZfireParamBean;
import com.gree.mall.manager.zfire.util.FieldUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 线下销售退货单
 * @author ：lijh
 * @description：TODO
 * @date ：2024/4/16 14:14
 */
@RequiredArgsConstructor
@Slf4j
@Service
public class OrderOfflineRefundLogic {

    private final CommonLogic commonLogic;
    private final OrderRefundLogic orderRefundLogic;
    private final CommonMapper commonMapper;
    private final GoodsSpecService goodsSpecService;
    private final OrderOfflineRefundService orderOfflineRefundService;
    private final OrderOfflineRefundItemService orderOfflineRefundItemService;
    private final OrderOfflineItemCodeService orderOfflineItemCodeService;
    private final OrderInfoService orderInfoService;
    private final OrderDetailService orderDetailService;
    private final OrderRefundService orderRefundService;
    private final JxGoodsLogic jxGoodsLogic;
    private final GoodsMaterialStockAccLogic goodsMaterialStockAccLogic;
    private final OrderDetailCodeService orderDetailCodeService;
    private final OrderOfflineRefundOldItemService orderOfflineRefundOldItemService;
    private final OrderOldProductService orderOldProductService;
    private final OrderOldProductItemService orderOldProductItemService;
    private final OrderDeliveryService orderDeliveryService;
    private final OrderDeliveryDetailService orderDeliveryDetailService;
    private final GoodsSaleLedgerService goodsSaleLedgerService;

    /**
     * 退货单列表
     * @param zfireParamBean
     * @return
     */
    public IPage<OrderOfflineRefundVO> list(ZfireParamBean zfireParamBean){
        FieldUtils.supplyParam(zfireParamBean,OrderOfflineRefundVO.class,commonLogic.getAdminUser());
        IPage<OrderOfflineRefundVO> page = commonMapper.orderOfflineRefundList(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
        return page;
    }


    /**
     * 保存退货单
     * @param orderOfflineRefundAddBean
     */
    @Transactional
    public void save(OrderOfflineRefundAddBean orderOfflineRefundAddBean){
        AdminUserCom adminUser = commonLogic.getAdminUser();
        if(StringUtils.isBlank(orderOfflineRefundAddBean.getOrderId())){
            throw new RemoteServiceException("订单号不能为空");
        }

        for (OrderOfflineRefundItem orderDeliveryDetail : orderOfflineRefundAddBean.getOrderOfflineRefundItems()) {
            if (orderDeliveryDetail.getRefundNum() < 1)
                throw new RemoteServiceException("退货数量不能小于1");
        }


        //原订单信息
        OrderInfo orderInfo = orderInfoService.getById(orderOfflineRefundAddBean.getOrderId());
        OrderDelivery orderDelivery = orderDeliveryService.getById(orderOfflineRefundAddBean.getDeliveryId());

        List<OrderDeliveryDetail> orderDeliveryDetails = orderDeliveryDetailService.lambdaQuery().eq(OrderDeliveryDetail::getDeliveryId, orderOfflineRefundAddBean.getDeliveryId()).list();
        List<OrderDetail> orderDetails = orderDetailService.lambdaQuery().eq(OrderDetail::getOrderId, orderInfo.getOrderId()).list();
        List<OrderOfflineRefundItem> orderOfflineRefundItems = orderOfflineRefundAddBean.getOrderOfflineRefundItems();
        List<OrderOfflineItemCode> orderOfflineItemCodes = orderOfflineRefundAddBean.getOrderOfflineItemCodes();
        //判断是否存在未完成的维权订单
        Integer count = orderRefundService.lambdaQuery()
                .eq(OrderRefund::getOrderId, orderOfflineRefundAddBean.getOrderId())
                .notIn(OrderRefund::getExamineStatus, ExamineStatusEnum.OK.getKey(), ExamineStatusEnum.FAIL.getKey())
                .count();
        if(count > 0){
            throw new RemoteServiceException("存在未完成的维权订单");
        }
        //判断是否存在未完成的退货单
        Integer count1 = orderOfflineRefundService.lambdaQuery()
                .ne(StringUtils.isNotBlank(orderOfflineRefundAddBean.getId()), OrderOfflineRefund::getId, orderOfflineRefundAddBean.getId())
                .eq(OrderOfflineRefund::getOrderId, orderOfflineRefundAddBean.getOrderId())
                .notIn(OrderOfflineRefund::getExamineStatus, ExamineStatusEnum.OK.getKey(), ExamineStatusEnum.FAIL.getKey())
                .count();
        if(count1 > 0){
            throw new RemoteServiceException("存在未完成的退货单，请先审批");
        }
        //总退货数量
        Integer totalRefundNum = orderOfflineRefundItems.stream()
                .mapToInt(OrderOfflineRefundItem::getRefundNum).sum();
        //总退货金额
        BigDecimal totalRefundAmount = new BigDecimal(0);
        for(OrderOfflineRefundItem item : orderOfflineRefundItems){
            totalRefundAmount = totalRefundAmount.add(item.getRefundAmount().multiply(BigDecimal.valueOf(item.getRefundNum())));
        }
        OrderOfflineRefund orderOfflineRefund = new OrderOfflineRefund();
        orderOfflineRefund.setId(orderOfflineRefundAddBean.getId());
        orderOfflineRefund.setCompanyWechatId(adminUser.getCompanyWechatId());
        orderOfflineRefund.setCompanyWechatName(adminUser.getCompanyName());
        orderOfflineRefund.setOrderId(orderOfflineRefundAddBean.getOrderId());
        orderOfflineRefund.setFileUrls(orderOfflineRefundAddBean.getFileUrls());
        orderOfflineRefund.setRemark(orderOfflineRefundAddBean.getRemark());
        orderOfflineRefund.setTotalRefundNum(totalRefundNum);
        orderOfflineRefund.setTotalRefundAmount(totalRefundAmount);
        orderOfflineRefund.setIsOld(orderOfflineRefundAddBean.getIsOld());
        orderOfflineRefund.setStorageId(orderDelivery.getStorageStockId());
        orderOfflineRefund.setStorageName(orderDelivery.getStorageStockName());

        orderOfflineRefund.setStorageStockId(orderOfflineRefundAddBean.getStorageStockId());
        orderOfflineRefund.setStorageStockName(orderOfflineRefundAddBean.getStorageStockName());
        orderOfflineRefund.setDeliveryId(orderOfflineRefundAddBean.getDeliveryId());
        orderOfflineRefund.insertOrUpdate();

        //订单明细map
        Map<String, OrderDetail> orderDetailMap = orderDetails.stream().collect(Collectors.toMap(v -> v.getOrderDetailId(), Function.identity()));
        Map<String, OrderDeliveryDetail> orderDeliveryDetailMap = orderDeliveryDetails.stream().collect(Collectors.toMap(v -> v.getOrderDetailId(), Function.identity()));
        //已退金额
        BigDecimal retiredAmount = orderDetails.stream().map(OrderDetail::getRefundAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        //当前订单可退总金额
        BigDecimal waitRefundAmount = orderInfo.getPayAmount().subtract(retiredAmount);
        //本次退货单的退货总金额
        BigDecimal itemRefundAmount = BigDecimal.ZERO;
        //商品信息，先删后增
        orderOfflineRefundItemService.lambdaUpdate().eq(OrderOfflineRefundItem::getOrderOfflineRefundId,orderOfflineRefund.getId()).remove();

        //条码信息,先删后增
        orderOfflineItemCodeService.lambdaUpdate().eq(OrderOfflineItemCode::getOrderOfflineRefundId,orderOfflineRefund.getId()).remove();

        for(OrderOfflineRefundItem item : orderOfflineRefundItems){
            if(StringUtils.isBlank(item.getOrderDetailId()) || StringUtils.isBlank(item.getOrderId())
                    || item.getRefundNum() == null || item.getRefundAmount() == null){
                throw new RemoteServiceException("商品信息缺失必要的参数");
            }
            if(item.getRefundNum() < 0 || item.getRefundAmount().doubleValue() < 0){
                throw new RemoteServiceException("退货数量或退货单价不能是负数");
            }
            item.setId(IdWorker.getIdStr());
            item.setOrderOfflineRefundId(orderOfflineRefund.getId());

            OrderDetail orderDetail = orderDetailMap.get(item.getOrderDetailId());
            OrderDeliveryDetail orderDeliveryDetail = orderDeliveryDetailMap.get(item.getOrderDetailId());
            if(orderDeliveryDetail.getSendNum() - orderDeliveryDetail.getRefundNum() < item.getRefundNum()){
                throw new RemoteServiceException("规格型号【"+ orderDetail.getGoodsSpecName()+"】可退货数量不足");
            }

            if(!CollectionUtils.isEmpty(orderOfflineItemCodes)) {
                for (OrderOfflineItemCode orderOfflineItemCode : orderOfflineItemCodes) {
                    orderOfflineItemCode.setOrderOfflineRefundId(orderOfflineRefund.getId());
                    if(StringUtils.equals(orderOfflineItemCode.getGoodsMaterialId(),orderDetail.getGoodsMaterialId())){
                        orderOfflineItemCode.setOrderRefundOfflineItemId(item.getId());
                    }
                }
                orderOfflineItemCodeService.saveBatch(orderOfflineItemCodes);
            }

            //本次退货金额
            itemRefundAmount = itemRefundAmount.add(item.getRefundAmount().multiply(BigDecimal.valueOf(item.getRefundNum())));
        }
        if(waitRefundAmount.doubleValue() < itemRefundAmount.doubleValue()){
            throw new RemoteServiceException("退货总金额超出了本订单的可退金额，请检查");
        }
        orderOfflineRefundItemService.saveBatch(orderOfflineRefundItems);

        //旧机退货

        orderOfflineRefundOldItemService.lambdaUpdate().eq(OrderOfflineRefundOldItem::getOrderOfflineRefundId,orderOfflineRefund.getId()).remove();
        if (!CollectionUtils.isEmpty(orderOfflineRefundAddBean.getIds())){

            if (orderOldProductService.lambdaQuery().in(OrderOldProduct::getId,orderOfflineRefundAddBean.getIds())
                    .eq(OrderOldProduct::getRefund,true).count() > 0) {
                throw new RemoteServiceException("存在已经退货得旧机");
            }

            List<OrderOfflineRefundOldItem> orderOfflineRefundOldItems = new ArrayList<>();
            for (String orderOfflineRefundOldItem : orderOfflineRefundAddBean.getIds()) {
                OrderOldProduct orderOldProduct = orderOldProductService.getById(orderOfflineRefundOldItem);

                OrderOfflineRefundOldItem orderOfflineRefundOldItemAdd = new OrderOfflineRefundOldItem();
                orderOfflineRefundOldItemAdd.setOrderOfflineRefundId(orderOfflineRefund.getId());
                orderOfflineRefundOldItemAdd.setOrderOldProductId(orderOldProduct.getId());
                orderOfflineRefundOldItemAdd.setRefundNum(orderOldProduct.getNum());
                orderOfflineRefundOldItemAdd.setRefundAmount(orderOldProduct.getPayAmount());
                orderOfflineRefundOldItemAdd.setOrderId(orderOldProduct.getOrderId());
                orderOfflineRefundOldItemAdd.setId(null);

                orderOfflineRefundOldItems.add(orderOfflineRefundOldItemAdd);
            }

            orderOfflineRefundOldItemService.saveBatch(orderOfflineRefundOldItems);
        }
    }

    /**
     * 详情
     * @param id
     * @return
     */
    public OrderOfflineRefundDetailBean detail(String id){
        OrderOfflineRefund orderOfflineRefund = orderOfflineRefundService.getById(id);
        //订单
        OrderInfo orderInfo = orderInfoService.getById(orderOfflineRefund.getOrderId());
        //商品详情
        List<OrderOfflineRefundItem> orderOfflineRefundItems = orderOfflineRefundItemService.lambdaQuery().eq(OrderOfflineRefundItem::getOrderOfflineRefundId, id).list();
        List<OrderOfflineRefundItemBean> orderOfflineRefundItemBeans = BeanUtil.copyToList(orderOfflineRefundItems, OrderOfflineRefundItemBean.class);
        for(OrderOfflineRefundItemBean bean : orderOfflineRefundItemBeans){
            OrderDetail orderDetail = orderDetailService.getById(bean.getOrderDetailId());
            if(orderDetail != null){
                bean.setMainName(orderDetail.getMainName());
                bean.setSmallName(orderDetail.getSmallName());
                bean.setGoodsMaterialUnit(orderDetail.getGoodsMaterialUnit());
                bean.setGoodsName(orderDetail.getGoodsName());
                if(StringUtils.isNotBlank(orderDetail.getGoodsMaterialSpecsName())) {
                    bean.setGoodsSpecName(orderDetail.getGoodsMaterialSpecsName());
                }else{
                    bean.setGoodsSpecName(orderDetail.getGoodsSpecName());
                }
                bean.setPrice(orderDetail.getPrice());
                bean.setNum(orderDetail.getNum());
                bean.setPayAmount(orderDetail.getPayAmount());
                bean.setRetiredNum(orderDetail.getRefundNum());
                bean.setRetiredAmount(orderDetail.getRefundAmount());
            }
        }
        //条码
        List<OrderOfflineItemCode> orderOfflineItemCodes = orderOfflineItemCodeService.lambdaQuery()
                .eq(OrderOfflineItemCode::getOrderOfflineRefundId, id).list();

        OrderOfflineRefundDetailBean detailBean = BeanUtil.copyProperties(orderOfflineRefund,OrderOfflineRefundDetailBean.class);
        detailBean.setOrderInfo(orderInfo);
        detailBean.setOrderOfflineRefundItems(orderOfflineRefundItemBeans);
        detailBean.setOrderOfflineItemCodes(orderOfflineItemCodes);

        List<OrderOfflineRefundOldItem> orderOfflineRefundOldItemList = orderOfflineRefundOldItemService.lambdaQuery()
                .eq(OrderOfflineRefundOldItem::getOrderOfflineRefundId, id).list();

        List<OrderOldProductDTO> orderOldProductDTOS = new ArrayList<>();

        for (OrderOfflineRefundOldItem orderOfflineRefundOldItem : orderOfflineRefundOldItemList) {
            List<OrderOldProduct> list = orderOldProductService.lambdaQuery()
                    .eq(OrderOldProduct::getId, orderOfflineRefundOldItem.getOrderOldProductId()).list();


            for (OrderOldProduct orderOldProduct : list) {
                OrderOldProductDTO orderOldProductDTO = BeanUtil.toBean(orderOldProduct, OrderOldProductDTO.class);
                List<OrderOldProductItem> orderOldProductItemList = orderOldProductItemService.lambdaQuery()
                        .eq(OrderOldProductItem::getOrderOldProductId, orderOldProduct.getId()).list();
                orderOldProductDTO.setItemList(orderOldProductItemList);

                orderOldProductDTOS.add(orderOldProductDTO);
            }
        }



        detailBean.setOrderOldProductDTOList(orderOldProductDTOS);


        return detailBean;
    }

    /**
     * 审核
     * @param id
     * @param examineStatusEnum
     * @param remark
     */
    @Transactional
    public void examine(String id,ExamineStatusEnum examineStatusEnum,String remark) throws WxPayException, InterruptedException {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        OrderOfflineRefund orderOfflineRefund = orderOfflineRefundService.getById(id);
        if(!orderOfflineRefund.getExamineStatus().equals(ExamineStatusEnum.WAIT.getKey())){
            throw new RemoteServiceException("非待审核状态不可审批");
        }
        List<OrderOfflineRefundItem> orderOfflineRefundItems = orderOfflineRefundItemService.lambdaQuery().eq(OrderOfflineRefundItem::getOrderOfflineRefundId, id).list();

        orderOfflineRefund.setExamineBy(adminUser.getNickName());
        orderOfflineRefund.setExamineTime(new Date());
        orderOfflineRefund.setExamineStatus(examineStatusEnum.getKey());
        orderOfflineRefund.setExamineRemark(remark);
        orderOfflineRefund.updateById();

        OrderDelivery orderDelivery = orderDeliveryService.getById(orderOfflineRefund.getDeliveryId());

        //订单
        OrderInfo orderInfo = orderInfoService.getById(orderOfflineRefund.getOrderId());

        List<OrderDeliveryDetail> orderDeliveryDetails = orderDeliveryDetailService.lambdaQuery().eq(OrderDeliveryDetail::getDeliveryId, orderOfflineRefund.getDeliveryId()).list();
        List<OrderDetail> orderDetails = orderDetailService.lambdaQuery().eq(OrderDetail::getOrderId, orderOfflineRefund.getOrderId()).list();
        //订单明细map
        Map<String, OrderDetail> orderDetailMap = orderDetails.stream().collect(Collectors.toMap(v -> v.getOrderDetailId(), Function.identity()));
        Map<String, OrderDeliveryDetail> orderDeliveryDetailMap = orderDeliveryDetails.stream().collect(Collectors.toMap(v -> v.getOrderDetailId(), Function.identity()));

        if(examineStatusEnum.getKey().equals(ExamineStatusEnum.OK.getKey())){


            OrderRefund orderRefund = new OrderRefund();
            BeanUtils.copyProperties(orderInfo, orderRefund);
            orderRefund.setOrderRefundId(IdWorker.getIdStr());
            orderRefund.setOrderId(orderInfo.getOrderId());
            orderRefund.setOrderTitle(orderInfo.getOrderTitle());
            orderRefund.setRefundAmount(orderOfflineRefund.getTotalRefundAmount());
            orderRefund.setRefundType(OrderRefundTypeEnum.REFUND_GOODS.toString());
            orderRefund.setOrderStatus(OrderStatusEnum.OVER.toString());
            orderRefund.setCreateTime(new Date());
            //orderRefundService.save(orderRefund);

            for(OrderOfflineRefundItem item : orderOfflineRefundItems) {
                //记录退款信息到订单详情
                OrderDetail orderDetail = orderDetailMap.get(item.getOrderDetailId());
                orderDetail.setRefund(true);
                orderDetail.setRefundAmount(orderDetail.getRefundAmount().add(item.getRefundAmount().multiply(BigDecimal.valueOf(item.getRefundNum()))));
                orderDetail.setRefundNum(orderDetail.getRefundNum() + item.getRefundNum());
                orderDetail.updateById();

                OrderDeliveryDetail orderDeliveryDetail = orderDeliveryDetailMap.get(item.getOrderDetailId());
                orderDeliveryDetail.setRefundNum(orderDeliveryDetail.getRefundNum()+item.getRefundNum());
                orderDeliveryDetail.updateById();

                orderDelivery.setRefundNum(orderDelivery.getRefundNum()+item.getRefundNum());
                orderDelivery.setStatus("REFUND");
                orderDelivery.setRefundId(orderOfflineRefund.getId());
                //回退商品库存
                GoodsSpec goodsSpec = goodsSpecService.getById(orderDetail.getGoodsSpecId());
                if(goodsSpec != null){
                    goodsSpec.setStockNum(goodsSpec.getStockNum() + item.getRefundNum());
                    goodsSpec.updateById();
                }
                //退回的条码
                List<OrderOfflineItemCode> codeList = orderOfflineItemCodeService.lambdaQuery().eq(OrderOfflineItemCode::getOrderRefundOfflineItemId, item.getId()).list();

                log.info("退货"+adminUser.getJoinCode());
                log.info("退货"+codeList.toString());

                if (StringUtil.isEmpty(orderDetail.getGoodsSpecId())){

                }else {
                    GoodsSpec goodsSpecE = goodsSpecService.getById(orderDetail.getGoodsSpecId());

                    if (goodsSpec == null)
                        throw new RemoteServiceException("未找到对应商品规格");

                    orderDetail.setGoodsMaterialId(goodsSpecE.getGoodsCode());
                }

                //回退仓库库存
                if (!StringUtil.isEmpty(orderDetail.getGoodsMaterialId()) && !adminUser.getJoinCode().equals("NO")) {

                    jxGoodsLogic.addMaterialStock(orderDetail.getGoodsMaterialId(), item.getRefundNum(),orderOfflineRefund.getStorageStockId(),orderDelivery.getStorageStockId());
                    goodsMaterialStockAccLogic.add(orderDetail.getGoodsMaterialId(), orderDetail.getPrice(), item.getRefundNum(),
                            DirectFlagEnum.ADD, orderRefund.getOrderId(), GoodsMaterialStockAccBillTypeEnum.E,orderOfflineRefund.getStorageStockId(),orderOfflineRefund.getStorageName());
                    if (adminUser.getJoinCode().equals("CODE")) {
                        //加条码
                        if (!CollectionUtils.isEmpty(codeList))
                            jxGoodsLogic.addCodeAccOffline(codeList,orderOfflineRefund.getStorageStockId());

                    }
                }

            }
            orderDelivery.updateById();
            //线上支付，需退款
            if (orderInfo.getPayTypeId().equals(PayTypeEnum.WECHAT.getKey())) {
                orderRefundLogic.refund(orderRefund);
            }

            List<GoodsSaleLedger> goodsSaleLedgers = goodsSaleLedgerService.lambdaQuery()
                    .eq(GoodsSaleLedger::getDeliveryId, orderDelivery.getDeliveryId()).list();

            for (GoodsSaleLedger goodsSaleLedger : goodsSaleLedgers) {
                goodsSaleLedger.setRefundOrderId(orderRefund.getOrderRefundId());
                goodsSaleLedger.setRefundName(adminUser.getNickName());
                goodsSaleLedger.setRefundTime(new Date());
                goodsSaleLedger.setRefundNum(goodsSaleLedger.getQty());
                goodsSaleLedger.setRefundAmount(goodsSaleLedger.getSaleAmount());
                goodsSaleLedger.updateById();

            }

            refundOver(orderInfo.getOrderId());
        }

    }


    private void refundOver(String orderId){
        List<OrderDetail> orderDetails = orderDetailService.lambdaQuery().eq(OrderDetail::getOrderId, orderId).list();
        Boolean has = false;
        for(OrderDetail orderDetail : orderDetails){
            if(orderDetail.getRefundNum() < orderDetail.getNum()){
                has = true;
            }
        }
        if(!has){
            orderInfoService.lambdaUpdate()
                    .set(OrderInfo::getOrderStatus,OrderStatusEnum.CLOSE.toString())
                    .eq(OrderInfo::getOrderId,orderId).update();
        }
    }



    public List<OrderDetailCode> orderDetailCodes(String orderId){
        List<OrderDetailCode> list = orderDetailCodeService.lambdaQuery().eq(OrderDetailCode::getDeliveryId, orderId).list();
        return list;
    }


}
