feat: enrich group buy delivery task info

This commit is contained in:
王鹏
2026-07-07 17:34:15 +08:00
parent d9e8234d27
commit 8a293d8323
3 changed files with 82 additions and 9 deletions

View File

@@ -4,9 +4,12 @@ import com.linhelp.common.enums.DeliveryMethod;
import com.linhelp.common.enums.DeliveryTaskStatus;
import com.linhelp.common.enums.ExpressOrderStatus;
import com.linhelp.common.enums.GoodsOrderStatus;
import com.linhelp.common.enums.GroupBuyOrderStatus;
import com.linhelp.common.exception.BizException;
import com.linhelp.express.ExpressOrderResponse;
import com.linhelp.express.ExpressOrderService;
import com.linhelp.groupbuy.GroupBuyOrderResponse;
import com.linhelp.groupbuy.GroupBuyOrderService;
import com.linhelp.order.GoodsOrderResponse;
import com.linhelp.order.GoodsOrderService;
import com.linhelp.user.AddressResponse;
@@ -29,6 +32,7 @@ public class DeliveryAssignmentService {
private final DeliveryUserService deliveryUserService;
private final GoodsOrderService goodsOrderService;
private final ExpressOrderService expressOrderService;
private final GroupBuyOrderService groupBuyOrderService;
private final UserAddressService addressService;
private final AtomicLong ids = new AtomicLong(1L);
private final Map<Long, DeliveryOrderResponse> tasks = new LinkedHashMap<Long, DeliveryOrderResponse>();
@@ -36,10 +40,12 @@ public class DeliveryAssignmentService {
public DeliveryAssignmentService(DeliveryUserService deliveryUserService,
GoodsOrderService goodsOrderService,
ExpressOrderService expressOrderService,
GroupBuyOrderService groupBuyOrderService,
UserAddressService addressService) {
this.deliveryUserService = deliveryUserService;
this.goodsOrderService = goodsOrderService;
this.expressOrderService = expressOrderService;
this.groupBuyOrderService = groupBuyOrderService;
this.addressService = addressService;
}
@@ -56,7 +62,7 @@ public class DeliveryAssignmentService {
task.setBizType(BIZ_TYPE_GOODS_ORDER);
task.setBizOrderId(order.getId());
task.setBizOrderNo(order.getOrderNo());
enrichGoodsContact(task, order);
enrichAddressContact(task, order.getUserId(), order.getAddressId());
task.setAmountCent(order.getPayableAmountCent());
task.setRemark(order.getRemark());
tasks.put(task.getId(), task);
@@ -87,10 +93,23 @@ public class DeliveryAssignmentService {
public synchronized DeliveryOrderResponse assignGroupBuyOrder(Long communityId, Long groupBuyOrderId, Long riderId) {
DeliveryUserResponse rider = deliveryUserService.requireEnabled(riderId);
DeliveryOrderResponse task = createBaseTask(rider.getTenantId(), communityId, rider);
GroupBuyOrderResponse order = groupBuyOrderService.detail(groupBuyOrderId);
if (!communityId.equals(order.getCommunityId())) {
throw new BizException(404, "团购订单不存在");
}
if (DeliveryMethod.SELF_PICKUP.equals(order.getDeliveryMethod())) {
throw new BizException("自提订单无需派单");
}
if (GroupBuyOrderStatus.PENDING_DELIVERY != order.getStatus()) {
throw new BizException("订单未待配送");
}
DeliveryOrderResponse task = createBaseTask(order.getTenantId(), order.getCommunityId(), rider);
task.setBizType(BIZ_TYPE_GROUP_BUY_ORDER);
task.setBizOrderId(groupBuyOrderId);
task.setBizOrderNo("GB" + String.format("%08d", groupBuyOrderId));
task.setBizOrderId(order.getId());
task.setBizOrderNo(order.getOrderNo());
enrichAddressContact(task, order.getUserId(), order.getAddressId());
task.setAmountCent(order.getAmountCent());
task.setRemark(order.getRemark());
tasks.put(task.getId(), task);
return copy(task);
}
@@ -152,11 +171,11 @@ public class DeliveryAssignmentService {
return task;
}
private void enrichGoodsContact(DeliveryOrderResponse task, GoodsOrderResponse order) {
if (order.getAddressId() == null) {
private void enrichAddressContact(DeliveryOrderResponse task, Long userId, Long addressId) {
if (addressId == null) {
return;
}
AddressResponse address = addressService.detailMine(order.getUserId(), order.getAddressId());
AddressResponse address = addressService.detailMine(userId, addressId);
task.setContactName(address.getContactName());
task.setContactPhone(address.getPhone());
task.setAddress(buildDeliveryAddress(address));