package com.fdkankan.platform.order.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fdkankan.common.constant.*;
import com.fdkankan.common.exception.BusinessException;
import com.fdkankan.common.user.SSOUser;
import com.fdkankan.common.util.DateUtil;
import com.fdkankan.common.util.FileSizeUtil;
import com.fdkankan.common.util.FileUtils;
import com.fdkankan.common.util.NumberUtils;
import com.fdkankan.pay.alipay.sdk.AlipayService;
import com.fdkankan.pay.wx.WXPayDefaultConfig;
import com.fdkankan.pay.wx.sdk.WXPay;
import com.fdkankan.pay.wx.sdk.WXPayConstants;
import com.fdkankan.platform.goods.common.SkuCache;
import com.fdkankan.platform.goods.entity.*;
import com.fdkankan.platform.goods.service.*;
import com.fdkankan.platform.goods.vo.ResponseGoods;
import com.fdkankan.platform.goods.vo.ResponseGoodsSku;
import com.fdkankan.platform.order.constant.OrderEnum;
import com.fdkankan.platform.order.entity.Invoice;
import com.fdkankan.platform.order.entity.Order;
import com.fdkankan.platform.order.entity.OrderItem;
import com.fdkankan.platform.order.entity.TradeLog;
import com.fdkankan.platform.order.mapper.IOrderMapper;
import com.fdkankan.platform.order.request.RequestPlaceOrder;
import com.fdkankan.platform.order.service.*;
import com.fdkankan.platform.order.vo.ResponseCommerceOrder;
import com.fdkankan.platform.order.vo.ResponseExpansionOrder;
import com.fdkankan.platform.user.entity.UserIncrement;
import com.fdkankan.platform.user.request.*;
import com.fdkankan.platform.user.service.IUserIncrementService;
import com.fdkankan.platform.user.service.IUserService;
import com.fdkankan.platform.user.vo.*;
import com.fdkankan.redis.util.RedisUtil;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author
 * @since 2021-12-24
 */
@Service
public class OrderServiceImpl extends ServiceImpl<IOrderMapper, Order> implements IOrderService {

    public static final Logger log = LoggerFactory.getLogger("programLog");
    @Autowired
    RedisUtil redisUtil;
    @Autowired
    private IOrderItemService orderItemService;
    @Autowired
    private IInvoiceService invoiceService;
    @Autowired
    private IUserService userService;
    @Autowired
    private ICartService cartService;
    @Autowired
    private IGoodsService goodsService;
    @Autowired
    private IGoodsSkuService goodsSkuService;
    @Autowired
    private ICameraService cameraService;
    @Autowired
    private ICameraDetailService cameraDetailService;
    @Autowired
    private ICameraSpaceService cameraSpaceService;
    @Autowired
    private IVirtualOrderService virtualOrderService;
    @Autowired
    private IExpansionOrderService expansionOrderService;
    @Autowired
    private ICommerceOrderService commerceOrderService;
    @Autowired
    private IIncrementOrderService incrementOrderService;
    @Autowired
    private IDownloadOrderService downloadOrderService;
    @Resource
    private AlipayService alipayService;
    @Autowired
    private IUserIncrementService userIncrementService;
    @Autowired
    ITradeLogService tradeLogService;
    @Resource
    private IOrderMapper orderMapper;

    @Override
    public ResponseOrder getOrderDetail(Long orderId) {
        Order order = this.getById(orderId);
        ResponseOrder responseOrder = new ResponseOrder();
        if(order == null || TbStatus.DELETE.code().equals(order.getTbStatus())){
            return responseOrder;
        }
        BeanUtils.copyProperties(order,responseOrder);

        List<ResponseOrderItem> responseOrderItems =orderItemService.getByOrderId(orderId);
        responseOrder.setOrderItems(responseOrderItems);

        Invoice invoice = invoiceService.getByOrderId(orderId);
        if(invoice != null){
            ResponseInvoice responseInvoice = new ResponseInvoice();
            BeanUtils.copyProperties(invoice, responseInvoice);
            responseOrder.setInvoice(responseInvoice);
        }
        return responseOrder;
    }

    @Override
    public Page<ResponseOrder> getOrders(RequestOrder param, String token) {
        SSOUser ssoUser = userService.getSSOUserByToken(token);
        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Order::getTbStatus,TbStatus.VALID.code());
        queryWrapper.lambda().eq(Order::getUserId,ssoUser.getId());
        queryWrapper.lambda().eq(Order::getPaymentStatus, OrderEnum.PaymentStatus.paid);
        queryWrapper.lambda().orderByDesc(Order::getOrderTime);
        Page<Order> orderPage = this.page(new Page<>(param.getPageNum(),param.getPageSize()), queryWrapper);

        List<ResponseOrder> voList = orderPage.getRecords().parallelStream().map(order -> {
            ResponseOrder vo = new ResponseOrder();
            BeanUtils.copyProperties(order, vo);
            return vo;
        }).collect(Collectors.toList());
        Page<ResponseOrder> voPage = new Page<ResponseOrder>(param.getPageNum(), param.getPageSize());
        voPage.setTotal(orderPage.getTotal());
        voPage.setRecords(voList);
        return voPage;
    }

    @Override
    public String cancelOrder(RequestOrder param, String token) {
        Order order = this.getById(param.getOrderId());
        order.setOrderStatus(OrderEnum.OrderStatus.invalid.name());
        order.setTbStatus(TbStatus.DELETE.code());
        if(!this.updateById(order)){
            throw  new BusinessException(ErrorCode.ERROR_MSG);
        }
        return ServerCode.SUCCESS.message();
    }

    @Override
    public String receiptOrder(RequestOrder param, String token) {
        Order orderEntity = this.getById(param.getOrderId());
        orderEntity.setShippingStatus(OrderEnum.ShippingStatus.received.name());
        orderEntity.setOrderStatus(OrderEnum.OrderStatus.completed.name());
        if(!this.updateById(orderEntity)){
            throw  new BusinessException(ErrorCode.ERROR_MSG);
        }
        return ServerCode.SUCCESS.message();
    }

    @Override
    public ResponseInvoice getInvoiceDetail(RequestOrder param, String token) {
        List<ResponseOrderItem> responseOrderItems = orderItemService.getByOrderId(param.getOrderId());
        StringBuilder sb = new StringBuilder();
        if (responseOrderItems != null && responseOrderItems.size() > 0){
            for (ResponseOrderItem vo : responseOrderItems){
                sb.append(vo.getGoodsCount()).append("*").append(vo.getGoodsName()).append("  ");
            }
        }
        Invoice invoice = invoiceService.getByOrderId(param.getOrderId());
        ResponseInvoice responseInvoice= new ResponseInvoice();
        if (invoice != null){
            responseInvoice = new ResponseInvoice();
            responseInvoice.setType(invoice.getType());
            responseInvoice.setTitle(invoice.getTitle());
            responseInvoice.setDescription(sb.toString());
        }
        return responseInvoice;
    }

    @Override
    public ResponseOrder placeOrder(RequestPlaceOrder order, String token) {
        SSOUser ssoUser = userService.getSSOUserByToken(token);
        // 删除购物车
        String cartIdsStr = "";
        RequestCart[] carts = order.getGoods();
        for (int i = 0; i < carts.length; i++){
            cartIdsStr += carts[i].getId();
            if (i != carts.length - 1) cartIdsStr += ",";
        }
        RequestCart param = new RequestCart();
        param.setIds(cartIdsStr);
        cartService.removeCarts(param,token);
        // 下单
        List<OrderItem> orderItemEntities = new ArrayList<>();
        OrderItem orderItemEntity = null;
        int goodsTotalCount = 0;
        BigDecimal goodsAmount = new BigDecimal(0);

        for(RequestCart requestCart : order.getGoods()){
            goodsTotalCount += requestCart.getGoodsCount();
            ResponseGoods responseGoods = goodsService.getByGoodsId(requestCart.getGoodsId());
            ResponseGoodsSku sku = goodsSkuService.getVoBySkuSn(requestCart.getSkuSn());
            if(responseGoods == null || sku == null){
                continue;
            }
            orderItemEntity = new OrderItem();
            orderItemEntity.setExpressNum(null);
            orderItemEntity.setGoodsPrice(order.getAbroad() == 0 ? sku.getPrice() : sku.getDollarPrice());
            orderItemEntity.setGoodsId(requestCart.getGoodsId());
            orderItemEntity.setShippingStatus(OrderEnum.ShippingStatus.unshipped.name());
            orderItemEntity.setExpressName("顺丰速运");
            orderItemEntity.setGoodsCount(requestCart.getGoodsCount());
            orderItemEntity.setGoodsName(responseGoods.getName());
            orderItemEntity.setGoodsSn(responseGoods.getGoodsSn());
            if (StringUtils.isNotEmpty(requestCart.getSkuSn())){
                orderItemEntity.setSkuSn(requestCart.getSkuSn());
            }
            orderItemEntities.add(orderItemEntity);
            goodsAmount = goodsAmount.add(orderItemEntity.getGoodsPrice().multiply(new BigDecimal(orderItemEntity.getGoodsCount())));
        }
        Order orderEntity = new Order();
        orderEntity.setOrderSn(NumberUtils.getOrderSn());
        orderEntity.setOrderTime(new Date());
        orderEntity.setOrderStatus(OrderEnum.OrderStatus.unprocessed.name());
        orderEntity.setPaymentStatus(OrderEnum.PaymentStatus.unpaid.name());
        orderEntity.setShippingStatus(OrderEnum.ShippingStatus.unshipped.name());
        orderEntity.setPaymentTypeName(order.getPayType());
        orderEntity.setUserId(ssoUser.getId());
        orderEntity.setGoodsTotalCount(goodsTotalCount);
        orderEntity.setGoodsAmount(goodsAmount);
        orderEntity.setTotalAmount(goodsAmount);
        orderEntity.setPaidAmount(BigDecimal.ZERO);
        orderEntity.setExpressAmount(BigDecimal.ZERO);
        orderEntity.setDeliveryTypeName("快递运输");
        if (order.getReceiver() != null){
            orderEntity.setShipAddress(order.getReceiver().getShipAddress());
            orderEntity.setShipAreaPath(order.getReceiver().getShipAreaPath());
            orderEntity.setShipMobile(order.getReceiver().getShipMobile());
            orderEntity.setShipName(order.getReceiver().getShipName());
        }
        orderEntity.setAbroad(order.getAbroad());
        if(!this.save(orderEntity)){
            throw new BusinessException(ErrorCode.ERROR_MSG);
        }
        for (OrderItem itemEntity : orderItemEntities) {
            itemEntity.setOrderId(orderEntity.getId());
            if(!orderItemService.save(itemEntity)){
                throw new BusinessException(ErrorCode.ERROR_MSG);
            }
        }
        ResponseOrder responseOrder = new ResponseOrder();
        BeanUtils.copyProperties(orderEntity, responseOrder);

        // 添加发票信息
        if (order.getInvoice() != null && StringUtils.isNotEmpty(order.getInvoice().getInvoiceType())){
            order.setOrderId(orderEntity.getId());
            order.getInvoice().setAmount(responseOrder.getTotalAmount().toString());
            invoiceService.saveInvoiceByOrder(ssoUser.getId(),order);
        }
        return responseOrder;
    }

    @Override
    public ResponseVirtualOrder rechargeOrder(RequestCamera param, String token) {
        SSOUser ssoUser = userService.getSSOUserByToken(token);
        Camera camera = cameraService.getById(param.getCameraId());
        if(camera == null){
            throw new BusinessException(CameraConstant.FAILURE_6003);
        }
        CameraDetail cameraDetail = cameraDetailService.getByCameraId(param.getCameraId());
        int sub = Integer.valueOf(cameraDetail.getBalance()) + param.getPoints();
        if (sub > Constant.MAXPOINTS) {
            throw new BusinessException(CameraConstant.FAILURE_6004);
        }
        return virtualOrderService.saveByCamera(ssoUser.getId(),param);
    }

    @Override
    public ResponseExpansionOrder expansionOrder(RequestExpansionOrder order, String token) {
        SSOUser ssoUser = userService.getSSOUserByToken(token);
        //支付美金，只能paypal支付
        if(order.getAbroad() == 1 && order.getPayType() != 2){
            throw new BusinessException(ErrorCode.FAILURE_CODE_8004);
        }
        ResponseGoodsSku sku = goodsSkuService.getVoBySkuSn(order.getSkuSn());
        if(sku == null ){
            throw new BusinessException(ErrorCode.ERROR_MSG);
        }
        int delay = 0;
        int dateNum = 0;
        double spaceSize = 0;
        //基础容量10G
        long baseSpace = 10;
        List<CameraSpace> cameraSpaceEntityList = cameraSpaceService.getListByCameraId(order.getCameraId());
        for(CameraSpace cameraSpaceEntity : cameraSpaceEntityList){
            dateNum = DateUtil.daysBetween(new Date(), cameraSpaceEntity.getSpaceEndTime());
            if(dateNum > 0){
                spaceSize = FileSizeUtil.formetFileSize(cameraSpaceEntity.getSpace(), FileSizeUtil.SIZETYPE_GB);
                //时间换算，（剩余天数*旧容量）/新容量 = 延期天数
                if((dateNum * (spaceSize - baseSpace)) % (sku.getUnitSize() - baseSpace) > 0){
                    //无法整除天数+1
                    delay += ((dateNum * (spaceSize - baseSpace)) / (sku.getUnitSize() - baseSpace)) + 1;
                }else {
                    delay += (dateNum * (spaceSize - baseSpace)) / (sku.getUnitSize() - baseSpace);
                }
            }
        }
        return expansionOrderService.saveByOrderParam(ssoUser.getId(), order, order.getAbroad() == 0 ?  sku.getPrice() : sku.getDollarPrice(),
                sku.getUnit(), sku.getUnitSize(), sku.getMonth(), delay);
    }

    @Override
    public ResponseCommerceOrder commerceOrder(RequestCommerceOrder param, String token) {
        SSOUser ssoUser = userService.getSSOUserByToken(token);
        ResponseGoodsSku sku = goodsSkuService.getVoBySkuSn(param.getSkuSn());
        return commerceOrderService.saveByOrderParam(ssoUser.getId(), param, param.getAbroad() == 0 ?  sku.getPrice() : sku.getDollarPrice());
    }

    @Override
    public ResponseIncrementOrder incrementOrder(RequestIncrementOrder order, String token) {
        SSOUser ssoUser = userService.getSSOUserByToken(token);
        //支付美金，只能paypal支付
        if(order.getAbroad() == 1 && order.getPayType() != 2){
            throw new BusinessException(ErrorCode.FAILURE_CODE_8004);
        }
        ResponseGoodsSku sku = goodsSkuService.getVoBySkuSn(order.getSkuSn());
        return incrementOrderService.saveByOrderParam(ssoUser.getId(), order, order.getAbroad() == 0 ?  sku.getPrice() : sku.getDollarPrice());
    }

    @Override
    public ResponseDownloadOrder downloadOrder(RequestIncrementOrder order, String token) {
        SSOUser ssoUser = userService.getSSOUserByToken(token);
        //支付美金，只能paypal支付
        if(order.getAbroad() == 1 && order.getPayType() != 2){
            throw new BusinessException(ErrorCode.FAILURE_CODE_8004);
        }
        ResponseGoodsSku sku = goodsSkuService.getVoBySkuSn(order.getSkuSn());
        return downloadOrderService.saveByOrderParam(ssoUser.getId(), order, order.getAbroad() == 0 ?  sku.getPrice() : sku.getDollarPrice());
    }

    @Override
    public Boolean queryOrderStatus(RequestVirtualOrder order, String token) throws Exception{
        Boolean success = false;
        String orderSn = order.getOrderSn();
        switch (order.getOrderType()){
            case 0:
                orderSn += "_entity";break;
            case 1:
                orderSn += "_recharge";break;
            case 2:
                orderSn += "_expansion";break;
            case 3:
                orderSn += "_commerce";break;
            case 4:
                orderSn += "_increment";break;
            case 5:
                orderSn += "_download";break;
        }
        switch (order.getPayType()){
            // 微信
            case 0:
                String orderSnE = redisUtil.get(orderSn);
                log.warn("out_trade_no：" + orderSnE);
                if (StringUtils.isNotEmpty(orderSnE)){
                    Map<String, String> data = new HashMap<String, String>();
                    data.put("out_trade_no", orderSnE);
                    WXPayDefaultConfig config = new WXPayDefaultConfig();
                    WXPay wxPay = new WXPay(config);
                    Map<String, String> resp = wxPay.orderQuery(data);
                    if (resp.get("trade_state") != null && resp.get("trade_state").equals(WXPayConstants.SUCCESS)) {
                        redisUtil.del(orderSnE);
                        String pngPath = ConstantFilePath.BASE_PATH + ConstantFilePath.WEIXIN_QRCODE_FOLDER + orderSn + ".png";
                        FileUtils.deleteFile(pngPath);
                        success = true;
                    }
                }
                break;
            // 支付宝
            case 1:
                log.warn("alipay out_trade_no：" + orderSn);
                String type = alipayService.tradeQuery(orderSn);
                log.warn("alipay type：" + type);
                if ("SUCCESS".equals(type)){
                    success = true;
                }
                break;
            // paypal
            case 2:
                orderSn = orderSn.split("_")[0];
                log.warn("paypal out_trade_no：" + orderSn);
                Order byOrderSn = this.getByOrderSn(orderSn);
                if (byOrderSn!=null && OrderEnum.PaymentStatus.paid.name().equals(byOrderSn.getPaymentStatus())){
                    success = true;
                }
                break;
        }
        return success;
    }

    @Override
    public ResponseGoods getExpansionPrice(RequestCamera camera, String token) {
        String skuStr = SkuCache.skusMap.get(String.valueOf(camera.getDateType()));
        if (StringUtils.isEmpty(skuStr)){
            skuStr = SkuCache.skusMap.get("1");
        }
        String[] skus = skuStr.split(",");
        List<ResponseGoodsSku> skusList = new ArrayList<>();
        Long goodsId = null;
        for (String sku : skus){
            GoodsSku goodsSkuEntity = goodsSkuService.getBySkuSn(sku);
            if (goodsSkuEntity != null){
                ResponseGoodsSku responseGoodsSku = new ResponseGoodsSku();
                BeanUtils.copyProperties(goodsSkuEntity, responseGoodsSku);
                if (StringUtils.isNotEmpty(responseGoodsSku.getDescription())){
                    try {
                        JSONObject o = JSONObject.parseObject(responseGoodsSku.getDescription());
                        responseGoodsSku.setUnit(o.getString("容量"));
                    }catch (Exception e){}
                }
                skusList.add(responseGoodsSku);
                goodsId = goodsSkuEntity.getGoodsId();
            }
        }
        Goods goodsEntity = goodsService.getById(goodsId);
        ResponseGoods responseGoods = new ResponseGoods();
        BeanUtils.copyProperties(goodsEntity, responseGoods);
        responseGoods.setSkuList(skusList);
        DateTime dateTime = new DateTime();
        //camera.getDateType() = 2 为年，其余为月
        if (camera.getDateType() != 2){
            dateTime = dateTime.plusDays(31 * skusList.get(0).getMonth());
        }else{
            dateTime = dateTime.plusYears(1);
        }
        responseGoods.setDeadLine(dateTime.toDate().getTime());
        return responseGoods;
    }

    @Override
    public ResponseGoodsSku getIncrementOrDownloadPrice(RequestCamera camera, String token) {
        if(camera.getDateType() == null){
            throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
        }
        if(camera.getDateType() != 5 && camera.getDateType() != 6){
            throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
        }
        DateTime dateTime = new DateTime();
        if(camera.getUserIncrementId() != null){
            UserIncrement userIncrementEntity = userIncrementService.getById(camera.getUserIncrementId());
            if(userIncrementEntity != null && userIncrementEntity.getIncrementEndTime().getTime() > new Date().getTime()){
                dateTime = new DateTime(userIncrementEntity.getIncrementEndTime());
            }
        }
        ResponseGoodsSku responseGoodsSku = goodsSkuService.getIncrementOrDownloadPrice(camera);
        //1年期限
        dateTime = dateTime.plusYears(1);
        responseGoodsSku.setDeadLine(dateTime.toDate().getTime());
        return responseGoodsSku;
    }

    @Override
    public Order getByOrderSn(String orderSn) {
        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Order::getTbStatus,TbStatus.VALID.code());
        queryWrapper.lambda().eq(Order::getOrderSn,orderSn);
        List<Order> list = this.list(queryWrapper);
        if(list == null || list.size()<=0){
            return null;
        }
        return list.get(0);
    }

    @Override
    public boolean paySuccessEntityOrder(String orderSn, String tradeNo, int paymentTypeName) {
        LambdaUpdateWrapper<Order> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(Order::getPaymentTypeName,paymentTypeName)
                .set(Order::getTradeNum,tradeNo)
                .set(Order::getPaymentStatus,OrderEnum.PaymentStatus.paid.name())
                .eq(Order::getTbStatus,TbStatus.VALID.code())
                .eq(Order::getOrderSn,orderSn);
        return this.update(updateWrapper);
    }

    @Override
    public Integer queryOrderCountByToday() {
        return orderMapper.queryOrderCountByToday();
    }

    @Override
    public BigDecimal queryTurnoverByToday() {
        return orderMapper.queryTurnoverByToday();
    }

    @Override
    public BigDecimal queryTurnoverByMonth() {
        return orderMapper.queryTurnoverByMonth();
    }

    @Override
    public BigDecimal queryTurnoverByLastMonth() {
        return orderMapper.queryTurnoverByLastMonth();
    }

    @Override
    public Integer queryAllPayOrdersCount() {
        return orderMapper.queryAllPayOrdersCount();
    }

    @Override
    public BigDecimal queryAllTurnoverByOrder() {
        return orderMapper.queryAllTurnoverByOrder();
    }

    @Override
    public Integer queryOrderCountByShippingStatus(String unshipped) {
        return orderMapper.queryOrderCountByShippingStatus(unshipped);
    }

    @Override
    public List<ResponseOrder> queryTrendOrder() {
        return orderMapper.queryTrendOrder();
    }

    @Override
    public Page<ResponseOrder> getPageVoByParam(RequestOrder param) {
        Page<ResponseOrder> pageVo = new Page<>(param.getPageNum(), param.getPageSize());
        param.setOrderBy("order_time desc");
        return  orderMapper.getListByParam(pageVo,param);
    }

    @Override
    public String confirmOrderDelivery(RequestOrder param) throws Exception {
        Order dbOrder = getById(param.getOrderId());
        String orderItemIds = param.getOrderItemIds();
        if(dbOrder == null || StringUtils.isEmpty(param.getOrderItemIds())){
            throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
        }
        TradeLog tradeLogEntity = tradeLogService.getByOrderSn(dbOrder.getOrderSn());
        if (tradeLogEntity == null){
            throw new BusinessException(-1,"订单错误，请联系管理员");
        }
        tradeLogEntity.setTradeTime(new Date());
        tradeLogService.updateById(tradeLogEntity);
        String[] ids = orderItemIds.split(",");
        for (String itemId : ids){
            OrderItem orderItem = orderItemService.getById(Long.valueOf(itemId));
            if (orderItem != null){
                orderItem.setExpressName(param.getExpressName());
                orderItem.setExpressNum(param.getExpressNum());
                orderItem.setShippingStatus(OrderEnum.ShippingStatus.shipped.name());
                orderItemService.updateById(orderItem);
            }
        }
        Integer orderCount1 = orderItemService.getCountByOrderIdAndShipped(param.getOrderId(),OrderEnum.ShippingStatus.shipped.name());
        Integer orderCount = orderItemService.getCountByOrderId(param.getOrderId());
        if(orderCount1.equals(orderCount)){
            dbOrder.setShippingStatus(OrderEnum.ShippingStatus.shipped.name());
        }else {
            dbOrder.setShippingStatus(OrderEnum.ShippingStatus.partReshiped.name());
        }
        dbOrder.setOrderStatus(OrderEnum.OrderStatus.processed.name());
        updateById(dbOrder);
        return ServerCode.SUCCESS.message();
    }
}
