|
|
|
@ -4692,131 +4692,136 @@ public class DistributionDeliveryListServiceImpl extends BaseServiceImpl<Distrib
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R loadingStart(DistrilbutionloadingscanDTO distrilbutionloadingscanDTO) { |
|
|
|
|
String method = "#########################DistributionStockArticleController.loadingStart"; |
|
|
|
|
if (Objects.isNull(distrilbutionloadingscanDTO.getDeliveryId())) { |
|
|
|
|
log.error(method + "参数缺失DeliveryId()"); |
|
|
|
|
return Resp.fail("参数缺失,请联系管理员"); |
|
|
|
|
} |
|
|
|
|
BasicdataWarehouseEntity myCurrentWarehouse = warehouseClient.getMyCurrentWarehouse(); |
|
|
|
|
if (Objects.isNull(myCurrentWarehouse)) { |
|
|
|
|
return R.fail(403, "未授权!!!"); |
|
|
|
|
} |
|
|
|
|
WarehouseConfigEntity warehouseConfigEntity = warehouseConfigClient.getWarehouseConfig(myCurrentWarehouse.getId()); |
|
|
|
|
Integer isStrictLoading = 0; |
|
|
|
|
if (!Objects.isNull(warehouseConfigEntity)) { |
|
|
|
|
if (!Objects.isNull(warehouseConfigEntity.getIsStrictLoading())) { |
|
|
|
|
isStrictLoading = warehouseConfigEntity.getIsStrictLoading(); |
|
|
|
|
StringBuilder builder = null; |
|
|
|
|
try { |
|
|
|
|
String method = "#########################DistributionStockArticleController.loadingStart"; |
|
|
|
|
if (Objects.isNull(distrilbutionloadingscanDTO.getDeliveryId())) { |
|
|
|
|
log.error(method + "参数缺失DeliveryId()"); |
|
|
|
|
return Resp.fail("参数缺失,请联系管理员"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
BladeUser user = AuthUtil.getUser(); |
|
|
|
|
//获取当前用户司机
|
|
|
|
|
DistributionDeliveryListEntity distributionDeliveryListEntity = distributionDeliveryListMapper.selectById(distrilbutionloadingscanDTO.getDeliveryId()); |
|
|
|
|
if (DeliveryStatusConstant.yiwancheng.getValue().equals(distributionDeliveryListEntity.getDeliveryStatus())) { |
|
|
|
|
return Resp.scanFail("该任务已完结!", "该任务已完结!"); |
|
|
|
|
} |
|
|
|
|
if (Integer.parseInt(IsOrNoConstant.yes.getValue()) == distributionDeliveryListEntity.getIsStart()) { |
|
|
|
|
return Resp.scanFail("该车次已发车!", "该车次已发车!"); |
|
|
|
|
} |
|
|
|
|
Boolean isDriverFlag = judgeIsDriver(user); |
|
|
|
|
if (Objects.equals(distributionDeliveryListEntity.getKind(), "1")) { |
|
|
|
|
if (!isDriverFlag) { |
|
|
|
|
return Resp.scanFail("当前操作人必须是司机!", "当前操作人必须是司机!"); |
|
|
|
|
BasicdataWarehouseEntity myCurrentWarehouse = warehouseClient.getMyCurrentWarehouse(); |
|
|
|
|
if (Objects.isNull(myCurrentWarehouse)) { |
|
|
|
|
return R.fail(403, "未授权!!!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//统计该配送任务的库存品装车数
|
|
|
|
|
Integer abnormalPackageLoadingNum = distributionLoadscanMapper.statisticsAbnormalLoadingNum(distrilbutionloadingscanDTO.getDeliveryId()); |
|
|
|
|
if (abnormalPackageLoadingNum != 0) { |
|
|
|
|
return Resp.scanFail("存在异常请处理", "存在异常请处理"); |
|
|
|
|
} |
|
|
|
|
String format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()); |
|
|
|
|
String loadingId = distrilbutionloadingscanDTO.getLoadingId(); |
|
|
|
|
Boolean b = false; |
|
|
|
|
Boolean isEnd = false; |
|
|
|
|
//防止司机进行重复发车点击
|
|
|
|
|
Long isRepeat = bladeRedis.get(AuthUtil.getTenantId() + ":warehouseId:" + myCurrentWarehouse.getId() + ":trainNumber:" + distributionDeliveryListEntity.getTrainNumber() + ":driverId:"); |
|
|
|
|
WarehouseConfigEntity warehouseConfigEntity = warehouseConfigClient.getWarehouseConfig(myCurrentWarehouse.getId()); |
|
|
|
|
Integer isStrictLoading = 0; |
|
|
|
|
if (!Objects.isNull(warehouseConfigEntity)) { |
|
|
|
|
if (!Objects.isNull(warehouseConfigEntity.getIsStrictLoading())) { |
|
|
|
|
isStrictLoading = warehouseConfigEntity.getIsStrictLoading(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
BladeUser user = AuthUtil.getUser(); |
|
|
|
|
//获取当前用户司机
|
|
|
|
|
DistributionDeliveryListEntity distributionDeliveryListEntity = distributionDeliveryListMapper.selectById(distrilbutionloadingscanDTO.getDeliveryId()); |
|
|
|
|
if (DeliveryStatusConstant.yiwancheng.getValue().equals(distributionDeliveryListEntity.getDeliveryStatus())) { |
|
|
|
|
return Resp.scanFail("该任务已完结!", "该任务已完结!"); |
|
|
|
|
} |
|
|
|
|
if (Integer.parseInt(IsOrNoConstant.yes.getValue()) == distributionDeliveryListEntity.getIsStart()) { |
|
|
|
|
return Resp.scanFail("该车次已发车!", "该车次已发车!"); |
|
|
|
|
} |
|
|
|
|
Boolean isDriverFlag = judgeIsDriver(user); |
|
|
|
|
if (Objects.equals(distributionDeliveryListEntity.getKind(), "1")) { |
|
|
|
|
if (!isDriverFlag) { |
|
|
|
|
return Resp.scanFail("当前操作人必须是司机!", "当前操作人必须是司机!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//统计该配送任务的库存品装车数
|
|
|
|
|
Integer abnormalPackageLoadingNum = distributionLoadscanMapper.statisticsAbnormalLoadingNum(distrilbutionloadingscanDTO.getDeliveryId()); |
|
|
|
|
if (abnormalPackageLoadingNum != 0) { |
|
|
|
|
return Resp.scanFail("存在异常请处理", "存在异常请处理"); |
|
|
|
|
} |
|
|
|
|
String format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()); |
|
|
|
|
String loadingId = distrilbutionloadingscanDTO.getLoadingId(); |
|
|
|
|
Boolean b = false; |
|
|
|
|
Boolean isEnd = false; |
|
|
|
|
//防止司机进行重复发车点击
|
|
|
|
|
Long isRepeat = bladeRedis.get(AuthUtil.getTenantId() + ":warehouseId:" + myCurrentWarehouse.getId() + ":trainNumber:" + distributionDeliveryListEntity.getTrainNumber() + ":driverId:"); |
|
|
|
|
|
|
|
|
|
if ("1".equals(distributionDeliveryListEntity.getKind())) { |
|
|
|
|
if ("1".equals(distributionDeliveryListEntity.getKind())) { |
|
|
|
|
|
|
|
|
|
DistributionDeliverySelfEntity distributionDeliverySelfEntity = getDriver(distributionDeliveryListEntity, user, distrilbutionloadingscanDTO.getVehicleNub(), isDriverFlag); |
|
|
|
|
distributionDeliverySelfEntity.setDepartureTime(format); |
|
|
|
|
b = distributionDeliverySelfService.updateById(distributionDeliverySelfEntity); |
|
|
|
|
isEnd = isEndDriver(distributionDeliveryListEntity.getId()); |
|
|
|
|
if (Func.isNotEmpty(isRepeat)) { |
|
|
|
|
if (distributionDeliverySelfEntity.getDriverId().equals(isRepeat)) { |
|
|
|
|
return Resp.scanFail("请勿重复发车", "请勿重复发车"); |
|
|
|
|
DistributionDeliverySelfEntity distributionDeliverySelfEntity = getDriver(distributionDeliveryListEntity, user, distrilbutionloadingscanDTO.getVehicleNub(), isDriverFlag); |
|
|
|
|
distributionDeliverySelfEntity.setDepartureTime(format); |
|
|
|
|
b = distributionDeliverySelfService.updateById(distributionDeliverySelfEntity); |
|
|
|
|
isEnd = isEndDriver(distributionDeliveryListEntity.getId()); |
|
|
|
|
if (Func.isNotEmpty(isRepeat)) { |
|
|
|
|
if (distributionDeliverySelfEntity.getDriverId().equals(isRepeat)) { |
|
|
|
|
return Resp.scanFail("请勿重复发车", "请勿重复发车"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
b = distributionDeliveryTripartiteService.update(new UpdateWrapper<DistributionDeliveryTripartiteEntity>().lambda() |
|
|
|
|
.eq(DistributionDeliveryTripartiteEntity::getDeliveryId, distrilbutionloadingscanDTO.getDeliveryId()) |
|
|
|
|
.set(DistributionDeliveryTripartiteEntity::getDepartureTime, format)); |
|
|
|
|
isEnd = true; |
|
|
|
|
} |
|
|
|
|
//处理最后一个司机进行发车
|
|
|
|
|
//判断是否是最后一个司机点发车
|
|
|
|
|
distributionDeliveryListEntity.setIsStart(DeliveryStartStatusConstant.bufenfache.getValue()); |
|
|
|
|
if (isEnd) { |
|
|
|
|
distributionDeliveryListEntity.setIsStart(DeliveryStartStatusConstant.yifache.getValue()); |
|
|
|
|
//进行实际装车和计划数据比对
|
|
|
|
|
if (Integer.parseInt(IsOrNoConstant.yes.getValue()) == isStrictLoading) { |
|
|
|
|
contrastPlanAndLoading(distributionDeliveryListEntity, myCurrentWarehouse); |
|
|
|
|
} |
|
|
|
|
//进行发车日志记录
|
|
|
|
|
} |
|
|
|
|
bladeRedis.setEx(AuthUtil.getTenantId() + ":warehouseId:" + myCurrentWarehouse.getId() + ":trainNumber:" + distributionDeliveryListEntity.getTrainNumber() + ":driverId:", user.getUserId(), 60L * 30L); |
|
|
|
|
//修改主表状态
|
|
|
|
|
distributionDeliveryListEntity.setDeliveryStatus(DeliveryStatusConstant.peisongzhong.getValue()); |
|
|
|
|
baseMapper.updateById(distributionDeliveryListEntity); |
|
|
|
|
//查询配送计划的所有预约总数
|
|
|
|
|
List<DistributionReservationEntity> reservationEntityList = distributionDeliveryListMapper.selectReservationByDeliveryListId(distrilbutionloadingscanDTO.getDeliveryId()); |
|
|
|
|
} else { |
|
|
|
|
b = distributionDeliveryTripartiteService.update(new UpdateWrapper<DistributionDeliveryTripartiteEntity>().lambda() |
|
|
|
|
.eq(DistributionDeliveryTripartiteEntity::getDeliveryId, distrilbutionloadingscanDTO.getDeliveryId()) |
|
|
|
|
.set(DistributionDeliveryTripartiteEntity::getDepartureTime, format)); |
|
|
|
|
isEnd = true; |
|
|
|
|
} |
|
|
|
|
//处理最后一个司机进行发车
|
|
|
|
|
//判断是否是最后一个司机点发车
|
|
|
|
|
distributionDeliveryListEntity.setIsStart(DeliveryStartStatusConstant.bufenfache.getValue()); |
|
|
|
|
if (isEnd) { |
|
|
|
|
distributionDeliveryListEntity.setIsStart(DeliveryStartStatusConstant.yifache.getValue()); |
|
|
|
|
//进行实际装车和计划数据比对
|
|
|
|
|
if (Integer.parseInt(IsOrNoConstant.yes.getValue()) == isStrictLoading) { |
|
|
|
|
contrastPlanAndLoading(distributionDeliveryListEntity, myCurrentWarehouse); |
|
|
|
|
} |
|
|
|
|
//进行发车日志记录
|
|
|
|
|
} |
|
|
|
|
bladeRedis.setEx(AuthUtil.getTenantId() + ":warehouseId:" + myCurrentWarehouse.getId() + ":trainNumber:" + distributionDeliveryListEntity.getTrainNumber() + ":driverId:", user.getUserId(), 60L * 30L); |
|
|
|
|
//修改主表状态
|
|
|
|
|
distributionDeliveryListEntity.setDeliveryStatus(DeliveryStatusConstant.peisongzhong.getValue()); |
|
|
|
|
baseMapper.updateById(distributionDeliveryListEntity); |
|
|
|
|
//查询配送计划的所有预约总数
|
|
|
|
|
List<DistributionReservationEntity> reservationEntityList = distributionDeliveryListMapper.selectReservationByDeliveryListId(distrilbutionloadingscanDTO.getDeliveryId()); |
|
|
|
|
// reservationEntityList.stream().collect(Collectors.reducing(0,DistributionReservationEntity::getReservationNum,Integer::sum));
|
|
|
|
|
StringBuilder builder = new StringBuilder(); |
|
|
|
|
AtomicInteger planCount = new AtomicInteger(); |
|
|
|
|
reservationEntityList.forEach(r -> { |
|
|
|
|
planCount.getAndAdd(r.getReservationNum() + r.getReservationStockListNum()); |
|
|
|
|
}); |
|
|
|
|
if (planCount.get() != 0) { |
|
|
|
|
builder.append("计划" + planCount.get() + "件"); |
|
|
|
|
} |
|
|
|
|
Integer loadingCount = new Integer(0); |
|
|
|
|
//查询配送任务的计划订单装车数
|
|
|
|
|
Integer packageLoadingNum = distributionLoadscanMapper.statisticsLoadingNum(distrilbutionloadingscanDTO.getDeliveryId()); |
|
|
|
|
if (packageLoadingNum != 0) { |
|
|
|
|
loadingCount += packageLoadingNum; |
|
|
|
|
} |
|
|
|
|
Integer inventoryLoadingNum = 0; |
|
|
|
|
if (distributionDeliveryListEntity.getType().equals(DistributionTypeConstant.shipie.getValue())) { |
|
|
|
|
inventoryLoadingNum = distributionLoadscaninvnMapper.statisticsLoadingNum(distrilbutionloadingscanDTO.getDeliveryId()); |
|
|
|
|
if (inventoryLoadingNum != 0) { |
|
|
|
|
loadingCount += inventoryLoadingNum; |
|
|
|
|
builder = new StringBuilder(); |
|
|
|
|
AtomicInteger planCount = new AtomicInteger(); |
|
|
|
|
reservationEntityList.forEach(r -> { |
|
|
|
|
planCount.getAndAdd(r.getReservationNum() + r.getReservationStockListNum()); |
|
|
|
|
}); |
|
|
|
|
if (planCount.get() != 0) { |
|
|
|
|
builder.append("计划" + planCount.get() + "件"); |
|
|
|
|
} |
|
|
|
|
Integer loadingCount = new Integer(0); |
|
|
|
|
//查询配送任务的计划订单装车数
|
|
|
|
|
Integer packageLoadingNum = distributionLoadscanMapper.statisticsLoadingNum(distrilbutionloadingscanDTO.getDeliveryId()); |
|
|
|
|
if (packageLoadingNum != 0) { |
|
|
|
|
loadingCount += packageLoadingNum; |
|
|
|
|
} |
|
|
|
|
Integer inventoryLoadingNum = 0; |
|
|
|
|
if (distributionDeliveryListEntity.getType().equals(DistributionTypeConstant.shipie.getValue())) { |
|
|
|
|
inventoryLoadingNum = distributionLoadscaninvnMapper.statisticsLoadingNum(distrilbutionloadingscanDTO.getDeliveryId()); |
|
|
|
|
if (inventoryLoadingNum != 0) { |
|
|
|
|
loadingCount += inventoryLoadingNum; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (planCount.get() - loadingCount > 0) { |
|
|
|
|
builder.append("未装" + (planCount.get() - packageLoadingNum - inventoryLoadingNum) + "件"); |
|
|
|
|
} |
|
|
|
|
if (loadingCount != 0) { |
|
|
|
|
builder.append("装车" + loadingCount + "件"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (planCount.get() - loadingCount > 0) { |
|
|
|
|
builder.append("未装" + (planCount.get() - packageLoadingNum - inventoryLoadingNum) + "件"); |
|
|
|
|
} |
|
|
|
|
if (loadingCount != 0) { |
|
|
|
|
builder.append("装车" + loadingCount + "件"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
distributionAsyncService.sendTrunkineLog(distributionDeliveryListEntity.getId(), null, AuthUtil.getUser(), warehouseClient.getMyCurrentWarehouse(), 1); |
|
|
|
|
Map mapState = new HashMap(); |
|
|
|
|
mapState.put("messageId", CommonUtil.getUUID()); |
|
|
|
|
mapState.put("messageData", distributionDeliveryListEntity.getId()); |
|
|
|
|
mapState.put("createTime", System.currentTimeMillis()); |
|
|
|
|
try { |
|
|
|
|
rabbitTemplate.convertAndSend(RabbitConstant.BUSINESS_PRE_CONVERSION_DATA_EXCHANGE, RabbitConstant.BUSINESS_PRE_CONVERSION_DATA_ROUTING, mapState, message -> { |
|
|
|
|
message.getMessageProperties() |
|
|
|
|
.setHeader("x-delay", 5000); |
|
|
|
|
return message; |
|
|
|
|
}); |
|
|
|
|
} catch (Exception customerException) { |
|
|
|
|
log.error(">>>>>>>>>>>>>>>>>>>>>>>>>> 消息推送失败~ 请联系管理员! ", customerException); |
|
|
|
|
distributionAsyncService.sendTrunkineLog(distributionDeliveryListEntity.getId(), null, AuthUtil.getUser(), warehouseClient.getMyCurrentWarehouse(), 1); |
|
|
|
|
Map mapState = new HashMap(); |
|
|
|
|
mapState.put("messageId", CommonUtil.getUUID()); |
|
|
|
|
mapState.put("messageData", distributionDeliveryListEntity.getId()); |
|
|
|
|
mapState.put("createTime", System.currentTimeMillis()); |
|
|
|
|
try { |
|
|
|
|
rabbitTemplate.convertAndSend(RabbitConstant.BUSINESS_PRE_CONVERSION_DATA_EXCHANGE, RabbitConstant.BUSINESS_PRE_CONVERSION_DATA_ROUTING, mapState, message -> { |
|
|
|
|
message.getMessageProperties() |
|
|
|
|
.setHeader("x-delay", 5000); |
|
|
|
|
return message; |
|
|
|
|
}); |
|
|
|
|
} catch (Exception customerException) { |
|
|
|
|
log.error(">>>>>>>>>>>>>>>>>>>>>>>>>> 消息推送失败~ 请联系管理员! ", customerException); |
|
|
|
|
} |
|
|
|
|
//发车日志记录
|
|
|
|
|
handleLoadingStartLog(distributionDeliveryListEntity, user, myCurrentWarehouse, builder.toString()); |
|
|
|
|
NodeFanoutMsg<CarStartVO> nodeFanoutMsg = builderNodeFanoutMsgByCarStart(distributionDeliveryListEntity, user); |
|
|
|
|
distributionNodeWorkService.carStart(nodeFanoutMsg, user); |
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
log.error(">>>>>>>>>>>>>>>>>>>>>>>>>> 发车异常", e); |
|
|
|
|
} |
|
|
|
|
//发车日志记录
|
|
|
|
|
handleLoadingStartLog(distributionDeliveryListEntity, user, myCurrentWarehouse, builder.toString()); |
|
|
|
|
NodeFanoutMsg<CarStartVO> nodeFanoutMsg = builderNodeFanoutMsgByCarStart(distributionDeliveryListEntity, user); |
|
|
|
|
distributionNodeWorkService.carStart(nodeFanoutMsg, user); |
|
|
|
|
// 推送数据
|
|
|
|
|
|
|
|
|
|
return Resp.scanSuccess("发车成功", builder.toString()); |
|
|
|
|