feat: enrich goods delivery task contact info

This commit is contained in:
王鹏
2026-07-07 17:29:06 +08:00
parent d2886fbd8f
commit d9e8234d27
3 changed files with 76 additions and 6 deletions

View File

@@ -9,6 +9,8 @@ import com.linhelp.express.ExpressOrderResponse;
import com.linhelp.express.ExpressOrderService;
import com.linhelp.order.GoodsOrderResponse;
import com.linhelp.order.GoodsOrderService;
import com.linhelp.user.AddressResponse;
import com.linhelp.user.UserAddressService;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
@@ -27,15 +29,18 @@ public class DeliveryAssignmentService {
private final DeliveryUserService deliveryUserService;
private final GoodsOrderService goodsOrderService;
private final ExpressOrderService expressOrderService;
private final UserAddressService addressService;
private final AtomicLong ids = new AtomicLong(1L);
private final Map<Long, DeliveryOrderResponse> tasks = new LinkedHashMap<Long, DeliveryOrderResponse>();
public DeliveryAssignmentService(DeliveryUserService deliveryUserService,
GoodsOrderService goodsOrderService,
ExpressOrderService expressOrderService) {
ExpressOrderService expressOrderService,
UserAddressService addressService) {
this.deliveryUserService = deliveryUserService;
this.goodsOrderService = goodsOrderService;
this.expressOrderService = expressOrderService;
this.addressService = addressService;
}
public synchronized DeliveryOrderResponse assignGoodsOrder(Long goodsOrderId, Long riderId) {
@@ -51,7 +56,7 @@ public class DeliveryAssignmentService {
task.setBizType(BIZ_TYPE_GOODS_ORDER);
task.setBizOrderId(order.getId());
task.setBizOrderNo(order.getOrderNo());
task.setAddress(order.getAddressId() == null ? null : "地址ID " + order.getAddressId());
enrichGoodsContact(task, order);
task.setAmountCent(order.getPayableAmountCent());
task.setRemark(order.getRemark());
tasks.put(task.getId(), task);
@@ -147,6 +152,34 @@ public class DeliveryAssignmentService {
return task;
}
private void enrichGoodsContact(DeliveryOrderResponse task, GoodsOrderResponse order) {
if (order.getAddressId() == null) {
return;
}
AddressResponse address = addressService.detailMine(order.getUserId(), order.getAddressId());
task.setContactName(address.getContactName());
task.setContactPhone(address.getPhone());
task.setAddress(buildDeliveryAddress(address));
}
private String buildDeliveryAddress(AddressResponse address) {
StringBuilder builder = new StringBuilder();
append(builder, address.getBuilding());
append(builder, address.getRoom());
append(builder, address.getDetail());
return builder.toString();
}
private void append(StringBuilder builder, String value) {
if (value == null || value.trim().isEmpty()) {
return;
}
if (builder.length() > 0) {
builder.append(' ');
}
builder.append(value);
}
private DeliveryOrderResponse require(Long id) {
DeliveryOrderResponse task = tasks.get(id);
if (task == null) {