|
|
|
@ -19,7 +19,7 @@ package com.logpm.distribution.service.impl;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|
|
|
|
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; |
|
|
|
|
import com.logpm.distribution.dto.DistributionReservationDTO; |
|
|
|
|
import com.logpm.distribution.dto.*; |
|
|
|
|
import com.logpm.distribution.entity.*; |
|
|
|
|
import com.logpm.distribution.excel.DistributionReservationExcel; |
|
|
|
|
import com.logpm.distribution.mapper.DistributionReservationMapper; |
|
|
|
@ -30,6 +30,7 @@ import org.springblade.core.mp.support.Condition;
|
|
|
|
|
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.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
|
@ -67,9 +68,7 @@ public class DistributionReservationServiceImpl extends BaseServiceImpl<Distribu
|
|
|
|
|
|
|
|
|
|
private final IDistributionDeliveryListService distributionDeliveryListService; |
|
|
|
|
|
|
|
|
|
private final IDistributionTripartiteDeliveryService distributionTripartiteDeliveryService; |
|
|
|
|
|
|
|
|
|
private final IDistributionSelfDeliveryService distributionSelfDeliveryService; |
|
|
|
|
|
|
|
|
|
private final IDistributionReservationStockarticleService distributionReservationStockarticleService; |
|
|
|
|
|
|
|
|
@ -190,6 +189,8 @@ public class DistributionReservationServiceImpl extends BaseServiceImpl<Distribu
|
|
|
|
|
BigDecimal fee = initTotal.get().add(reservationEntity.getOtherFee()); |
|
|
|
|
reservationEntity.setFee(fee); |
|
|
|
|
int count = stockArticleCount.get() + stockListCount.get(); |
|
|
|
|
String random = Func.random(13, RandomType.ALL); |
|
|
|
|
reservationEntity.setReservationId(random); |
|
|
|
|
reservationEntity.setReservationNum(count); |
|
|
|
|
distributionReservationMapper.updateById(reservationEntity); |
|
|
|
|
return true; |
|
|
|
@ -211,7 +212,7 @@ public class DistributionReservationServiceImpl extends BaseServiceImpl<Distribu
|
|
|
|
|
String stockUpDate = (String) stockUpInfo.get("stockupDate"); |
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
|
Date date = format.parse(stockUpDate); |
|
|
|
|
String goddsAreaId = (String) stockUpInfo.get("goodsAreaId"); |
|
|
|
|
String goddsAreaId = (String) stockUpInfo.get("stockupArea"); |
|
|
|
|
DistributionStockupEntity stockupEntity = new DistributionStockupEntity(); |
|
|
|
|
stockupEntity.setGoodsAreaId(Long.parseLong(goddsAreaId)); |
|
|
|
|
//设置备货任务指派状态---未指派
|
|
|
|
@ -272,134 +273,124 @@ public class DistributionReservationServiceImpl extends BaseServiceImpl<Distribu
|
|
|
|
|
return distributionReservationVOS; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Transactional |
|
|
|
|
@Override |
|
|
|
|
public R<?> deliveryTask(Map<String, Object> deliveryInfo) { |
|
|
|
|
//获取前端传递的多个预约信息
|
|
|
|
|
String idsStr = (String) deliveryInfo.get("reservationIds"); |
|
|
|
|
String[] ids = idsStr.split(","); |
|
|
|
|
if (Func.isEmpty(ids)) { |
|
|
|
|
log.error("预约参数错误+{" + ids + "}"); |
|
|
|
|
return R.fail("预约信息错误!!!"); |
|
|
|
|
@Transactional |
|
|
|
|
public R<?> deliveryTask(DistributionDeliveryAllocationDTO allocationDTO) { |
|
|
|
|
if (Func.isEmpty(allocationDTO)){ |
|
|
|
|
log.error("参数异常allocationDTO:+{"+allocationDTO+"}"); |
|
|
|
|
return R.fail("服务器正忙!!!"); |
|
|
|
|
} |
|
|
|
|
//判断是自主配送还是三方配送
|
|
|
|
|
String tripartiteSource = (String) deliveryInfo.get("tripartiteSource"); |
|
|
|
|
boolean result = false; |
|
|
|
|
try { |
|
|
|
|
if (Func.isBlank(tripartiteSource)) { |
|
|
|
|
//自主配送
|
|
|
|
|
DistributionSelfDeliveryEntity distributionSelfDeliveryEntity = new DistributionSelfDeliveryEntity(); |
|
|
|
|
distributionSelfDeliveryEntity.setMasterDriverId((String) deliveryInfo.get("masterDriver")); |
|
|
|
|
distributionSelfDeliveryEntity.setReservationIds(idsStr); |
|
|
|
|
distributionSelfDeliveryEntity.setVehicleIds((String) deliveryInfo.get("vehicleIds")); |
|
|
|
|
distributionSelfDeliveryEntity.setSlaveDriverIds((String) deliveryInfo.get("slaveDriver")); |
|
|
|
|
//保存自主配送信息
|
|
|
|
|
result = distributionSelfDeliveryService.save(distributionSelfDeliveryEntity); |
|
|
|
|
//获取自主配送信息id
|
|
|
|
|
Long distributionSelfDeliveryEntityId = distributionSelfDeliveryEntity.getId(); |
|
|
|
|
} else { |
|
|
|
|
//三方配送
|
|
|
|
|
DistributionTripartiteDeliveryEntity distributionTripartiteDeliveryEntity = new DistributionTripartiteDeliveryEntity(); |
|
|
|
|
distributionTripartiteDeliveryEntity.setDriverPhone((String) deliveryInfo.get("driverPhone")); |
|
|
|
|
distributionTripartiteDeliveryEntity.setDriverName((String) deliveryInfo.get("driverName")); |
|
|
|
|
distributionTripartiteDeliveryEntity.setVehicleNum((String) deliveryInfo.get("vehicleNum")); |
|
|
|
|
distributionTripartiteDeliveryEntity.setDeliveryFee(new BigDecimal((String) deliveryInfo.get("deliveryFee"))); |
|
|
|
|
distributionTripartiteDeliveryEntity.setReservationIds(idsStr); |
|
|
|
|
result = distributionTripartiteDeliveryService.save(distributionTripartiteDeliveryEntity); |
|
|
|
|
Long distributionTripartiteDeliveryEntityId = distributionTripartiteDeliveryEntity.getId(); |
|
|
|
|
} |
|
|
|
|
//备货信息构建
|
|
|
|
|
DistributionStockupEntity stockupEntity = new DistributionStockupEntity(); |
|
|
|
|
stockupEntity.setForklift(Long.parseLong((String) deliveryInfo.get("forklift"))); |
|
|
|
|
stockupEntity.setStockupStatus("2"); |
|
|
|
|
stockupEntity.setStockupArea((String) deliveryInfo.get("goodsAreaId")); |
|
|
|
|
stockupEntity.setStockupUser(AuthUtil.getUser().getUserId().toString()); |
|
|
|
|
stockupEntity.setLoader(Long.parseLong((String) deliveryInfo.get("loader"))); |
|
|
|
|
stockupEntity.setAssignStatus("2"); |
|
|
|
|
stockupEntity.setAssignTime(new Date()); |
|
|
|
|
String stockUpdate = (String) deliveryInfo.get("stockupDate"); |
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
|
Date date = format.parse(stockUpdate); |
|
|
|
|
stockupEntity.setStockupDate(date); |
|
|
|
|
//完成对备货任务信息的保存
|
|
|
|
|
result = distributionStockupService.save(stockupEntity); |
|
|
|
|
Long stockupEntityId = stockupEntity.getId(); |
|
|
|
|
StringBuffer reservationIdBuffer = new StringBuffer(); |
|
|
|
|
StringBuffer stockArticleIdBuffer = new StringBuffer(); |
|
|
|
|
AtomicReference<String> warehouseName = new AtomicReference<>(); |
|
|
|
|
AtomicInteger count = new AtomicInteger(); |
|
|
|
|
Arrays.stream(ids).forEach(id -> { |
|
|
|
|
//对预约信息进行备货状态修改
|
|
|
|
|
DistributionReservationEntity reservationEntity = this.getBaseMapper().selectById(id); |
|
|
|
|
String stockupStatus = reservationEntity.getStockupStatus(); |
|
|
|
|
if (!stockupStatus.equals("1")) { |
|
|
|
|
//预约任务处于未备货状态
|
|
|
|
|
//预约信息编号拼接
|
|
|
|
|
reservationIdBuffer.append(reservationEntity.getId()).append(","); |
|
|
|
|
//修改备货状态为待备货
|
|
|
|
|
reservationEntity.setStockupStatus("2"); |
|
|
|
|
this.updateById(reservationEntity); |
|
|
|
|
reservationEntity.setUpdateTime(new Date()); |
|
|
|
|
reservationEntity.setUpdateUser(AuthUtil.getUserId()); |
|
|
|
|
reservationEntity.setIsDeleted(1); |
|
|
|
|
String reservationIds = allocationDTO.getReservationIds(); |
|
|
|
|
//创建备货任务
|
|
|
|
|
DistributionStockupDTO stockup = allocationDTO.getStockup(); |
|
|
|
|
DistributionStockupEntity distributionStockupEntity = Func.copy(stockup, DistributionStockupEntity.class); |
|
|
|
|
distributionStockupEntity.setAssignStatus("1"); |
|
|
|
|
distributionStockupEntity.setAssignTime(new Date()); |
|
|
|
|
distributionStockupEntity.setForklift(Long.parseLong(stockup.getForkliftId())); |
|
|
|
|
distributionStockupEntity.setStockupUser(AuthUtil.getUserId().toString()); |
|
|
|
|
distributionStockupEntity.setStockupStatus("2"); |
|
|
|
|
distributionStockupService.save(distributionStockupEntity); |
|
|
|
|
List<Long> ids = Func.toLongList(reservationIds); |
|
|
|
|
Map<String,Object> map = new HashMap<>(); |
|
|
|
|
//获取备货任务的编号
|
|
|
|
|
Long stockupEntityId = distributionStockupEntity.getId(); |
|
|
|
|
//统计包件数量
|
|
|
|
|
AtomicInteger packageNum = new AtomicInteger(); |
|
|
|
|
//预约订单数量
|
|
|
|
|
AtomicInteger orderNum = new AtomicInteger(); |
|
|
|
|
//预约单号拼接
|
|
|
|
|
StringBuilder reservationId = new StringBuilder(); |
|
|
|
|
//订单编号
|
|
|
|
|
StringBuilder orderIds = new StringBuilder(); |
|
|
|
|
//库存品编号
|
|
|
|
|
StringBuilder stockListId = new StringBuilder(); |
|
|
|
|
//订单自编号
|
|
|
|
|
HashSet<String> hashSet = new HashSet<>(); |
|
|
|
|
ids.forEach(i->{ |
|
|
|
|
//查询备货任务
|
|
|
|
|
map.put("reservationId",i); |
|
|
|
|
QueryWrapper<DistributionStockupInfoEntity> qw = Condition.getQueryWrapper(map, DistributionStockupInfoEntity.class); |
|
|
|
|
DistributionStockupInfoEntity distributionStockupInfoEntity = distributionStockupInfoService.getOne(qw); |
|
|
|
|
if (Func.isEmpty(distributionStockupInfoEntity)){ |
|
|
|
|
//1、预约单不存在备货任务
|
|
|
|
|
//利用中间表建立起预约和备货表之间的关系
|
|
|
|
|
DistributionStockupInfoEntity stockupInfoEntity = new DistributionStockupInfoEntity(); |
|
|
|
|
stockupInfoEntity.setReservationId(i.toString()); |
|
|
|
|
stockupInfoEntity.setStockupId(stockupEntityId.toString()); |
|
|
|
|
distributionStockupInfoService.save(stockupInfoEntity); |
|
|
|
|
}else { |
|
|
|
|
//获取备货任务编号
|
|
|
|
|
String stockupId = distributionStockupInfoEntity.getStockupId(); |
|
|
|
|
DistributionStockupEntity stockupEntity = distributionStockupService.getById(stockupId); |
|
|
|
|
//2、预约单存在备货任务还未指派
|
|
|
|
|
if (Func.equals(stockupEntity.getAssignStatus(),"2")){ |
|
|
|
|
//对原有的备货关系进行修改
|
|
|
|
|
distributionStockupInfoEntity.setStockupId(stockupEntityId.toString()); |
|
|
|
|
distributionStockupInfoService.updateById(distributionStockupInfoEntity); |
|
|
|
|
} |
|
|
|
|
String stockArticleId = reservationEntity.getStockArticleId(); |
|
|
|
|
stockArticleIdBuffer.append(stockArticleId).append(","); |
|
|
|
|
//对预约信息中的订单状态进行修改并且将预约信息从预约列表中清除
|
|
|
|
|
String[] stockArticleIds = stockArticleId.split(","); |
|
|
|
|
for (String articleId : stockArticleIds) { |
|
|
|
|
DistributionStockArticleEntity stockArticleEntity = distributionStockArticleService.getById(articleId); |
|
|
|
|
stockArticleEntity.setState(3); |
|
|
|
|
distributionStockArticleService.updateById(stockArticleEntity); |
|
|
|
|
warehouseName.set(stockArticleEntity.getWarehouse()); |
|
|
|
|
//TODO 统计预约单下订单配送包件数量
|
|
|
|
|
//3、预约单存在备货任务且已指派备货
|
|
|
|
|
//不执行操作
|
|
|
|
|
} |
|
|
|
|
DistributionReservationEntity reservationEntity = this.getById(i); |
|
|
|
|
//预约订单数量
|
|
|
|
|
orderNum.getAndAdd(reservationEntity.getStockArticleId().split(",").length); |
|
|
|
|
//统计包件数量
|
|
|
|
|
packageNum.getAndAdd(reservationEntity.getReservationNum()); |
|
|
|
|
//预约单号拼接
|
|
|
|
|
reservationId.append(reservationEntity.getId()).append(","); |
|
|
|
|
this.updateById(reservationEntity); |
|
|
|
|
//订单自编号拼接
|
|
|
|
|
QueryWrapper<DistributionReservationStockarticleEntity> q = Condition.getQueryWrapper(new HashMap<String, Object>(), DistributionReservationStockarticleEntity.class); |
|
|
|
|
q.lambda().eq(DistributionReservationStockarticleEntity::getReservationId, reservationEntity.getId()); |
|
|
|
|
QueryWrapper<DistributionReservationStocklistEntity> w = Condition.getQueryWrapper(new HashMap<String, Object>(), DistributionReservationStocklistEntity.class); |
|
|
|
|
w.lambda().eq(DistributionReservationStocklistEntity::getReservationId, reservationEntity.getId()); |
|
|
|
|
List<DistributionReservationStockarticleEntity> reservationStockarticleEntityList = distributionReservationStockarticleService.getBaseMapper().selectList(q); |
|
|
|
|
List<DistributionReservationStocklistEntity> reservationStocklistEntityList = distributionReservationStocklistService.getBaseMapper().selectList(w); |
|
|
|
|
if (!Func.isEmpty(reservationStockarticleEntityList)){ |
|
|
|
|
reservationStockarticleEntityList.forEach(r->{ |
|
|
|
|
//查询订单信息,完成对订单的信息修改
|
|
|
|
|
DistributionStockArticleEntity stockArticleEntity = distributionStockArticleService.getById(r.getStockarticleId()); |
|
|
|
|
//拼接订单编号
|
|
|
|
|
orderIds.append(stockArticleEntity.getId()).append(","); |
|
|
|
|
//拼接订单自编号
|
|
|
|
|
hashSet.add(stockArticleEntity.getOrderSelfNumbering()); |
|
|
|
|
if (stockArticleEntity.getHandQuantity()> r.getReservationNum()){ |
|
|
|
|
//这里表示订单下的包件没有进行全部配送
|
|
|
|
|
//修改订单状态为部分配送
|
|
|
|
|
stockArticleEntity.setState(4); |
|
|
|
|
//修改订单的在库数量
|
|
|
|
|
stockArticleEntity.setState(stockArticleEntity.getHandQuantity() - r.getReservationNum()); |
|
|
|
|
//对订单进行修改
|
|
|
|
|
distributionStockArticleService.updateById(stockArticleEntity); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
//构建预约备货中间表信息
|
|
|
|
|
DistributionStockupInfoEntity distributionStockupInfoEntity = new DistributionStockupInfoEntity(); |
|
|
|
|
distributionStockupInfoEntity.setReservationId(reservationEntity.getId().toString()); |
|
|
|
|
distributionStockupInfoEntity.setStockupId(stockupEntityId.toString()); |
|
|
|
|
distributionStockupInfoService.save(distributionStockupInfoEntity); |
|
|
|
|
count.getAndIncrement(); |
|
|
|
|
}); |
|
|
|
|
reservationIdBuffer.deleteCharAt(reservationIdBuffer.length() - 1); |
|
|
|
|
stockupEntity.setIds(reservationIdBuffer.toString()); |
|
|
|
|
result = distributionStockupService.updateById(stockupEntity); |
|
|
|
|
//这里还需要将数据保存至配送列表中
|
|
|
|
|
DistributionDeliveryListEntity distributionDeliveryListEntity = new DistributionDeliveryListEntity(); |
|
|
|
|
distributionDeliveryListEntity.setReservationId(idsStr); |
|
|
|
|
stockArticleIdBuffer.deleteCharAt(stockArticleIdBuffer.length() - 1); |
|
|
|
|
distributionDeliveryListEntity.setOrderId(stockArticleIdBuffer.toString()); |
|
|
|
|
distributionDeliveryListEntity.setWarehouseId(warehouseName.get()); |
|
|
|
|
String masterDriverName = (String) deliveryInfo.get("masterDriverName"); |
|
|
|
|
String slaveDriverNames = (String) deliveryInfo.get("slaveDriverNames"); |
|
|
|
|
if (Func.isBlank(masterDriverName)) { |
|
|
|
|
//这里就是外协配送的方式
|
|
|
|
|
distributionDeliveryListEntity.setDriverName((String) deliveryInfo.get("driverName")); |
|
|
|
|
distributionDeliveryListEntity.setKind("2"); |
|
|
|
|
distributionDeliveryListEntity.setVehicleName((String) deliveryInfo.get("vehicleNum")); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
distributionDeliveryListEntity.setVehicleName((String) deliveryInfo.get("vehicleNums")); |
|
|
|
|
distributionDeliveryListEntity.setVehicleId((String) deliveryInfo.get("vehicleIds")); |
|
|
|
|
distributionDeliveryListEntity.setDriverName(masterDriverName + "," + slaveDriverNames); |
|
|
|
|
distributionDeliveryListEntity.setDriverId((String) deliveryInfo.get("driverIds")); |
|
|
|
|
distributionDeliveryListEntity.setKind("1"); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
distributionDeliveryListEntity.setCustomersNumber(Integer.parseInt(count.toString())); |
|
|
|
|
distributionDeliveryListEntity.setState("1"); |
|
|
|
|
distributionDeliveryListEntity.setLoadingTeamId((String) deliveryInfo.get("loader")); |
|
|
|
|
distributionDeliveryListEntity.setLoadingTeamName((String) deliveryInfo.get("loaderName")); |
|
|
|
|
//TODO 配送的来源,这里是通过预约单转配送
|
|
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
|
log.error("异常错误+{" + e.getMessage() + "}"); |
|
|
|
|
return R.fail("操作失败!!!"); |
|
|
|
|
if (!Func.isEmpty(reservationStocklistEntityList)){ |
|
|
|
|
//对库存品进行操作
|
|
|
|
|
reservationStocklistEntityList.forEach(l->{ |
|
|
|
|
DistributionStockListEntity stockListEntity = distributionStockListService.getById(l.getStocklistId()); |
|
|
|
|
stockListEntity.setQuantityStock(stockListEntity.getQuantityStock() - l.getReservationNum()); |
|
|
|
|
hashSet.add(stockListEntity.getOrderSelfNumbering()); |
|
|
|
|
stockListId.append(stockListEntity.getId()).append(","); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
//操作司机信息
|
|
|
|
|
DistributionDeliveryTripartiteDTO tripartite = allocationDTO.getTripartite(); |
|
|
|
|
if (Func.isEmpty(tripartite)){ |
|
|
|
|
//这里就是自主配送
|
|
|
|
|
}else { |
|
|
|
|
//这里就是三方配送
|
|
|
|
|
List<DistributionDeliverySelfDTO> allocationInfo = allocationDTO.getAllocationInfo(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
return R.status(result); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R<DistributionReservationVO> getReservationInfo(String reservationId) { |
|
|
|
|
//查询出预约信息
|
|
|
|
|