|
|
|
@ -18,18 +18,23 @@ package com.logpm.distribution.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
|
|
|
|
import com.logpm.distribution.dto.DistributionDeliveryListDTO; |
|
|
|
|
import com.logpm.distribution.dto.*; |
|
|
|
|
import com.logpm.distribution.dto.app.DistributionAppDeliveryListDTO; |
|
|
|
|
import com.logpm.distribution.dto.app.DistrilbutionloadingscanDTO; |
|
|
|
|
import com.logpm.distribution.entity.*; |
|
|
|
|
import com.logpm.distribution.mapper.*; |
|
|
|
|
import com.logpm.distribution.service.IDistributionAsyncService; |
|
|
|
|
import com.logpm.distribution.service.*; |
|
|
|
|
import com.logpm.distribution.vo.*; |
|
|
|
|
import com.logpm.distribution.excel.DistributionDeliveryListExcel; |
|
|
|
|
import com.logpm.distribution.service.IDistributionDeliveryListService; |
|
|
|
|
import com.logpm.distribution.vo.app.*; |
|
|
|
|
import com.logpm.distribution.vo.app.DistributionAppDeliveryListVO; |
|
|
|
|
import com.logpm.distribution.vo.app.DistributionAppDeliverySelfVO; |
|
|
|
|
import com.logpm.distribution.vo.app.DistributionAppLoadscanVO; |
|
|
|
|
import com.logpm.distribution.vo.app.DistributionAppReservationVO; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.log4j.Log4j2; |
|
|
|
|
import net.bytebuddy.implementation.bytecode.Throw; |
|
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
|
import org.springblade.common.serviceConstant.ServiceConstant; |
|
|
|
|
import org.springblade.core.redis.cache.BladeRedis; |
|
|
|
@ -37,6 +42,7 @@ import org.springblade.core.secure.BladeUser;
|
|
|
|
|
import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
|
import org.springblade.core.tool.utils.RandomType; |
|
|
|
|
import org.springblade.system.feign.IDictBizClient; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -49,6 +55,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 配送管理 服务实现类 |
|
|
|
@ -62,20 +70,27 @@ import java.util.stream.Collectors;
|
|
|
|
|
public class DistributionDeliveryListServiceImpl extends BaseServiceImpl<DistributionDeliveryListMapper, DistributionDeliveryListEntity> implements IDistributionDeliveryListService { |
|
|
|
|
private final DistributionDeliveryInfoMapper distributionDeliveryInfoMapper; |
|
|
|
|
private final DistributionReservationMapper distributionReservationMapper; |
|
|
|
|
private final IDistributionReservationStockarticleService distributionReservationStockarticleService; |
|
|
|
|
private final IDistributionReservationPackageService distributionReservationPackageService; |
|
|
|
|
private final DistributionParcelListMapper distributionParcelListMapper; |
|
|
|
|
private final IDistributionParcelListService distributionParcelListService; |
|
|
|
|
private final DistributionLoadscanMapper distributionLoadscanMapper; |
|
|
|
|
private final DistributionLoadscanServiceImpl distributionLoadscanService; |
|
|
|
|
private final DistributionLoadscaninvnServiceImpl distributionLoadscaninvnService; |
|
|
|
|
private final DistributionDeliveryListMapper distributionDeliveryListMapper; |
|
|
|
|
private final DistributionSignforServiceImpl distributionSignforService; |
|
|
|
|
private final DistributionSignforMapper distributionSignforMapper; |
|
|
|
|
private final IDistributionSignforService distributionSignforServicer; |
|
|
|
|
private final DistributionStockArticleMapper distributionStockArticleMapper; |
|
|
|
|
private final DistributionSigndetailServiceImpl distributionSigndetailService; |
|
|
|
|
private final DistributionPackadeliServiceImpl distributionPackadeliService; |
|
|
|
|
private final DistributionDeliverySelfMapper distributionDeliverySelfMapper; |
|
|
|
|
private final IDistributionDeliverySelfService distributionDeliverySelfService; |
|
|
|
|
private final DistributionDeliveryTripartiteMapper distributionDeliveryTripartiteMapper; |
|
|
|
|
private final IDistributionDeliveryTripartiteService distributionDeliveryTripartiteService; |
|
|
|
|
private final DistributionReservationStockarticleMapper distributionReservationStockarticleMapper; |
|
|
|
|
private final DistributionStockupMapper distributionStockupMapper; |
|
|
|
|
private final IDistributionStockupInfoService distributionStockupInfoService; |
|
|
|
|
private final DistributionStockMapper distributionStockMapper; |
|
|
|
|
private final DistributionLoadscaninvnMapper distributionLoadscaninvnMapper; |
|
|
|
|
private final BladeRedis bladeRedis; |
|
|
|
@ -1095,6 +1110,9 @@ public class DistributionDeliveryListServiceImpl extends BaseServiceImpl<Distrib
|
|
|
|
|
deliveryListVO.setReservationInfo(reservationVOS); |
|
|
|
|
//1、查询出订单信息
|
|
|
|
|
List<DistributionStockArticleVO> stockArticleVOS = distributionDeliveryListMapper.getDeliveryStockArticleInfo(id); |
|
|
|
|
stockArticleVOS.forEach(s->{ |
|
|
|
|
//这里查询出订单选取的包件信息
|
|
|
|
|
}); |
|
|
|
|
deliveryListVO.setStockArticleList(stockArticleVOS); |
|
|
|
|
//2、查询出备货信息
|
|
|
|
|
DistributionStockupVO stockupEntity = distributionStockupMapper.getDeliveryStockupInfo(id); |
|
|
|
@ -1142,6 +1160,181 @@ public class DistributionDeliveryListServiceImpl extends BaseServiceImpl<Distrib
|
|
|
|
|
return page.setRecords(distributionAppStockListVOS); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional |
|
|
|
|
public R<?> UpdateDeliveryListInfo(DistributionDeliveryListDTO deliveryListDTO) { |
|
|
|
|
if ( Func.isEmpty(deliveryListDTO)){ |
|
|
|
|
log.error("deliveryListDTO参数异常+{"+deliveryListDTO+"}"); |
|
|
|
|
return R.fail("服务器正忙!!"); |
|
|
|
|
} |
|
|
|
|
//首先对配送任务进行修改
|
|
|
|
|
//查询出配送任务的基本信息
|
|
|
|
|
DistributionDeliveryListEntity deliveryListEntity = this.getById(deliveryListDTO.getId()); |
|
|
|
|
//查询这个配送任务的备货任务
|
|
|
|
|
DistributionStockupVO stockupInfo = distributionStockupMapper.getDeliveryStockupInfo(deliveryListEntity.getId().toString()); |
|
|
|
|
List<DistributionDeliverySelfDTO> allocationInfo = deliveryListDTO.getAllocationInfo(); |
|
|
|
|
String kind = deliveryListEntity.getKind(); |
|
|
|
|
switch (kind){ |
|
|
|
|
case "1": |
|
|
|
|
//对自主配送中的司机信息进行删除
|
|
|
|
|
distributionDeliverySelfMapper.deleteDeliverySelf(deliveryListEntity.getId()); |
|
|
|
|
break; |
|
|
|
|
case "2": |
|
|
|
|
distributionDeliveryTripartiteMapper.deleteDeliveryTripartite(deliveryListEntity.getId()); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if (Func.isEmpty(allocationInfo)){ |
|
|
|
|
//这里就表示是三方配送
|
|
|
|
|
DistributionDeliveryTripartiteDTO tripartite = deliveryListDTO.getTripartite(); |
|
|
|
|
DistributionDeliveryTripartiteEntity tripartiteEntity = Func.copy(tripartite, DistributionDeliveryTripartiteEntity.class); |
|
|
|
|
tripartiteEntity.setDeliveryId(deliveryListEntity.getId()); |
|
|
|
|
distributionDeliveryTripartiteService.save(tripartiteEntity); |
|
|
|
|
deliveryListEntity.setDriverName(tripartiteEntity.getDriverName()); |
|
|
|
|
deliveryListEntity.setVehicleName(tripartiteEntity.getVehicleNum()); |
|
|
|
|
//重新为配送任务的司机进行设置
|
|
|
|
|
}else { |
|
|
|
|
StringBuilder driverNames = new StringBuilder(); |
|
|
|
|
StringBuilder vehicleNubs = new StringBuilder(); |
|
|
|
|
//自主配送
|
|
|
|
|
allocationInfo.forEach(a->{ |
|
|
|
|
DistributionDeliverySelfEntity deliverySelfEntity = Func.copy(a, DistributionDeliverySelfEntity.class); |
|
|
|
|
if (a.getDriverName().equals(deliveryListDTO.getMasterDriverName()) && a.getVehicleNub().equals(deliveryListDTO.getMasterVehicleNub())){ |
|
|
|
|
deliverySelfEntity.setIsMaster(ServiceConstant.IS_MASTER_YES); |
|
|
|
|
} |
|
|
|
|
//自主配送需要对司机名称进行重新拼接
|
|
|
|
|
distributionDeliverySelfService.save(deliverySelfEntity); |
|
|
|
|
driverNames.append(deliverySelfEntity.getDriverName()).append(","); |
|
|
|
|
vehicleNubs.append(deliverySelfEntity.getVehicleNub()).append(","); |
|
|
|
|
}); |
|
|
|
|
//配送任务重新设置司机名称
|
|
|
|
|
deliveryListEntity.setDriverName(driverNames.deleteCharAt(driverNames.length()-1).toString()); |
|
|
|
|
deliveryListEntity.setVehicleName(vehicleNubs.deleteCharAt(vehicleNubs.length()-1).toString()); |
|
|
|
|
} |
|
|
|
|
//对配送进行更改
|
|
|
|
|
// this.updateById(deliveryListEntity);
|
|
|
|
|
//TODO 这里对订单、包件、客户之间的关系进行过滤筛选
|
|
|
|
|
//获取所有订单
|
|
|
|
|
List<DistributionStockArticleDTO> stockArticle = deliveryListDTO.getStockArticle(); |
|
|
|
|
//根据门店进行分组
|
|
|
|
|
Map<String, List<DistributionStockArticleDTO>> storeClient = stockArticle.stream().collect(Collectors.groupingBy(DistributionStockArticleDTO::getStoreName)); |
|
|
|
|
List<DistributionStockArticleDTO> distributionStockArticleDTOS = storeClient.get(""); |
|
|
|
|
Map<String, List<DistributionStockArticleDTO>> mallClient = distributionStockArticleDTOS.stream().collect(Collectors.groupingBy(DistributionStockArticleDTO::getMallName)); |
|
|
|
|
//3、维护订单和客户
|
|
|
|
|
storeClient.forEach((k,v)->mallClient.merge(k,v,(v1,v2)->v2)); |
|
|
|
|
//查询该配送任务下原有的客户
|
|
|
|
|
List<DistributionReservationEntity> reservationEntityList = distributionReservationMapper.getDeliveryReservation(deliveryListEntity.getId()); |
|
|
|
|
//将原客户和新的进行比对,如果有那么则进行客户修改,最后剩下的订单信息都属于是新客户
|
|
|
|
|
Map<String, List<DistributionReservationEntity>> originalClient = reservationEntityList.stream().collect(Collectors.groupingBy(DistributionReservationEntity::getConsignee)); |
|
|
|
|
Date date = new Date(); |
|
|
|
|
mallClient.forEach((k,v)->{ |
|
|
|
|
if (!k.equals("")){ |
|
|
|
|
if (Func.isNotEmpty(originalClient.get(k))){ |
|
|
|
|
//这里实际上就是包件发生了变化
|
|
|
|
|
v.forEach(o->{ |
|
|
|
|
List<DistributionParcelListEntity> packageList = o.getPackageList(); |
|
|
|
|
//删除原来订单和包件之间的关系,建立新的包件和订单之间的关系
|
|
|
|
|
//1、通过客户名称查询出预约信息
|
|
|
|
|
//2、通过预约信息解除该订单下原有的包件信息
|
|
|
|
|
//3、重新建立包件和预约的关联关系
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
originalClient.remove(k); |
|
|
|
|
}else { |
|
|
|
|
DistributionReservationDTO reservation = deliveryListDTO.getReservation(); |
|
|
|
|
DistributionReservationEntity reservationEntity = Func.copy(reservation, DistributionReservationEntity.class); |
|
|
|
|
reservationEntity.setReservationStatus(ServiceConstant.RESERVATION_STATE_WAIT_DELIVERY); |
|
|
|
|
reservationEntity.setConsignee(k); |
|
|
|
|
reservationEntity.setDeliveryAddress(v.get(0).getConsigneeAddress()); |
|
|
|
|
reservationEntity.setDeliveryPhone(v.get(0).getCustomerTelephone()); |
|
|
|
|
reservationEntity.setReservationDate(date); |
|
|
|
|
reservationEntity.setPeriodOfTime(ServiceConstant.RESERVATION_PERIOED_TIME_DAY); |
|
|
|
|
reservationEntity.setServiceNumber(v.get(0).getServiceNumber()); |
|
|
|
|
reservationEntity.setReservationCode(Func.random(13, RandomType.INT)); |
|
|
|
|
reservationEntity.setStockupStatus(ServiceConstant.STOCKUP_STATE_WAIT_EXECUTION); |
|
|
|
|
BladeUser user = AuthUtil.getUser(); |
|
|
|
|
reservationEntity.setCreateUser(user.getUserId()); |
|
|
|
|
reservationEntity.setCreateDept(Long.parseLong(user.getDeptId())); |
|
|
|
|
reservationEntity.setTenantId(AuthUtil.getTenantId()); |
|
|
|
|
reservationEntity.setStatus(1); |
|
|
|
|
reservationEntity.setIsDeleted(0); |
|
|
|
|
//统计订单下包件总数
|
|
|
|
|
AtomicInteger orderTotal = new AtomicInteger(); |
|
|
|
|
//保存新的预约任务
|
|
|
|
|
distributionReservationMapper.insert(reservationEntity); |
|
|
|
|
//订单自编号拼接
|
|
|
|
|
HashSet<String> str = new HashSet<>(); |
|
|
|
|
v.forEach(s->{ |
|
|
|
|
//新增
|
|
|
|
|
//构建预约和订单之间的关系
|
|
|
|
|
List<DistributionParcelListEntity> packageList = s.getPackageList(); |
|
|
|
|
//统计订单下包件总数
|
|
|
|
|
AtomicInteger packageTotal = new AtomicInteger(); |
|
|
|
|
if (packageList.size()>0){ |
|
|
|
|
//完成对选择的包件信息维护
|
|
|
|
|
packageList.forEach(p->{ |
|
|
|
|
DistributionReservationPackageEntity reservationPackageEntity = new DistributionReservationPackageEntity(); |
|
|
|
|
reservationPackageEntity.setStockArticleId(s.getId()); |
|
|
|
|
reservationPackageEntity.setReservationId(reservationEntity.getId()); |
|
|
|
|
reservationPackageEntity.setParceListId(p.getId()); |
|
|
|
|
reservationPackageEntity.setPacketBarCode(p.getPacketBarCode()); |
|
|
|
|
distributionReservationPackageService.save(reservationPackageEntity); |
|
|
|
|
packageTotal.getAndAdd(p.getQuantity()); |
|
|
|
|
}); |
|
|
|
|
}else { |
|
|
|
|
//查询出该订单下的所有包件,完成预约和包件的维护
|
|
|
|
|
QueryWrapper<DistributionParcelListEntity> parcelListEntityQueryWrapper = new QueryWrapper<>(); |
|
|
|
|
parcelListEntityQueryWrapper.lambda().eq(DistributionParcelListEntity::getStockArticleId,s.getId()); |
|
|
|
|
List<DistributionParcelListEntity> distributionParcelListEntityList = distributionParcelListService.getBaseMapper().selectList(parcelListEntityQueryWrapper); |
|
|
|
|
distributionParcelListEntityList.forEach(dp->{ |
|
|
|
|
DistributionReservationPackageEntity reservationPackageEntity = new DistributionReservationPackageEntity(); |
|
|
|
|
reservationPackageEntity.setStockArticleId(s.getId()); |
|
|
|
|
reservationPackageEntity.setReservationId(reservationEntity.getId()); |
|
|
|
|
reservationPackageEntity.setParceListId(dp.getId()); |
|
|
|
|
reservationPackageEntity.setPacketBarCode(dp.getPacketBarCode()); |
|
|
|
|
distributionReservationPackageService.save(reservationPackageEntity); |
|
|
|
|
packageTotal.getAndAdd(dp.getQuantity()); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
//完成预约和订单之间数据关系
|
|
|
|
|
DistributionReservationStockarticleEntity reservationStockarticleEntity = new DistributionReservationStockarticleEntity(); |
|
|
|
|
reservationStockarticleEntity.setReservationNum(packageTotal.get()); |
|
|
|
|
reservationStockarticleEntity.setStockArticleCode(s.getStockArticleCode()); |
|
|
|
|
reservationStockarticleEntity.setIsHaveData(s.getIsHaveData()); |
|
|
|
|
reservationStockarticleEntity.setReservationId(reservationEntity.getId()); |
|
|
|
|
reservationStockarticleEntity.setStockArticleId(s.getId()); |
|
|
|
|
distributionReservationStockarticleService.save(reservationStockarticleEntity); |
|
|
|
|
//统计订单的包件数量
|
|
|
|
|
orderTotal.getAndAdd(reservationStockarticleEntity.getReservationNum()); |
|
|
|
|
str.add(s.getOrderSelfNumbering()); |
|
|
|
|
}); |
|
|
|
|
//对预约信息进行修改
|
|
|
|
|
String s = String.join(",", str); |
|
|
|
|
s = s.replaceFirst(",",""); |
|
|
|
|
reservationEntity.setReservationNum(orderTotal.get()); |
|
|
|
|
reservationEntity.setStockArticleId(s); |
|
|
|
|
reservationEntity.setUpdateUser(user.getUserId()); |
|
|
|
|
reservationEntity.setUpdateTime(new Date()); |
|
|
|
|
distributionReservationMapper.updateById(reservationEntity); |
|
|
|
|
//构建新客户和备货任务之间的关系
|
|
|
|
|
DistributionStockupInfoEntity stockupInfoEntity = new DistributionStockupInfoEntity(); |
|
|
|
|
stockupInfoEntity.setStockupId(stockupInfo.getId()); |
|
|
|
|
stockupInfoEntity.setReservationId(reservationEntity.getId()); |
|
|
|
|
distributionStockupInfoService.save(stockupInfoEntity); |
|
|
|
|
//构建新客户信息和配送任务之间的关系
|
|
|
|
|
DistributionSignforEntity distributionSignforEntity = new DistributionSignforEntity(); |
|
|
|
|
distributionSignforEntity.setReservationId(reservationEntity.getId()); |
|
|
|
|
distributionSignforEntity.setTrainNumber(deliveryListEntity.getTrainNumber()); |
|
|
|
|
distributionSignforEntity.setDeliveryId(deliveryListEntity.getId()); |
|
|
|
|
distributionSignforServicer.save(distributionSignforEntity); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
//删除客户信息
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<DistributionAppDeliverySelfVO> selectDistributionAppDeliverySelfVOList(DistrilbutionloadingscanDTO distrilbutionloadingscanDTO) { |
|
|
|
|
//查询该配送类型
|
|
|
|
|