package cn.lili.modules.order.order.serviceimpl; import cn.hutool.core.util.ArrayUtil; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; import cn.lili.modules.order.order.entity.dos.OrderPackage; import cn.lili.modules.order.order.entity.dos.OrderPackageItem; import cn.lili.modules.order.order.entity.vo.OrderPackageVO; import cn.lili.modules.order.order.mapper.OrderPackageMapper; import cn.lili.modules.order.order.service.OrderPackageItemService; import cn.lili.modules.order.order.service.OrderPackageService; import cn.lili.modules.system.entity.dos.Logistics; import cn.lili.modules.system.entity.vo.Traces; import cn.lili.modules.system.service.LogisticsService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; /** * 订单包裹业务层实现 * * @author Chopper * @since 2020/11/17 7:38 下午 */ @Service @Transactional(rollbackFor = Exception.class) public class OrderPackageServiceImpl extends ServiceImpl implements OrderPackageService { @Autowired private OrderPackageItemService orderpackageItemService; @Autowired private LogisticsService logisticsService; @Override public List orderPackageList(String orderSn) { return this.list(new LambdaQueryWrapper().eq(OrderPackage::getOrderSn, orderSn)); } @Override public List getOrderPackageVOList(String orderSn) { List orderPackages = this.orderPackageList(orderSn); if (orderPackages == null){ throw new ServiceException(ResultCode.ORDER_PACKAGE_NOT_EXIST); } List orderPackageVOS = new ArrayList<>(); orderPackages.forEach(orderPackage -> { OrderPackageVO orderPackageVO = new OrderPackageVO(orderPackage); // 获取子订单包裹详情 List orderPackageItemList = orderpackageItemService.getOrderPackageItemListByPno(orderPackage.getPackageNo()); orderPackageVO.setOrderPackageItemList(orderPackageItemList); String str = orderPackage.getConsigneeMobile(); str = str.substring(str.length() - 4); //不需要取是否打开的可能存在现在不发送快递需要查询物流信息 List list = logisticsService.list(Wrappers.lambdaQuery() .eq(Logistics::getCode, orderPackage.getLogisticsCode())); String logisticsId = orderPackage.getLogisticsCode(); if (ArrayUtil.isNotEmpty(list)) { logisticsId = list.get(0).getId(); } Traces traces = logisticsService.getLogisticTrack(logisticsId, orderPackage.getLogisticsNo(), str); orderPackageVO.setTraces(traces); orderPackageVOS.add(orderPackageVO); }); return orderPackageVOS; } }