feat: sync group buy order delivery status
This commit is contained in:
@@ -5,6 +5,7 @@ import com.linhelp.common.enums.ExpressOrderStatus;
|
|||||||
import com.linhelp.common.exception.BizException;
|
import com.linhelp.common.exception.BizException;
|
||||||
import com.linhelp.express.ExpressOrderResponse;
|
import com.linhelp.express.ExpressOrderResponse;
|
||||||
import com.linhelp.express.ExpressOrderService;
|
import com.linhelp.express.ExpressOrderService;
|
||||||
|
import com.linhelp.groupbuy.GroupBuyOrderService;
|
||||||
import com.linhelp.order.GoodsOrderService;
|
import com.linhelp.order.GoodsOrderService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -18,13 +19,16 @@ public class RiderTaskService {
|
|||||||
private final DeliveryAssignmentService assignmentService;
|
private final DeliveryAssignmentService assignmentService;
|
||||||
private final GoodsOrderService goodsOrderService;
|
private final GoodsOrderService goodsOrderService;
|
||||||
private final ExpressOrderService expressOrderService;
|
private final ExpressOrderService expressOrderService;
|
||||||
|
private final GroupBuyOrderService groupBuyOrderService;
|
||||||
|
|
||||||
public RiderTaskService(DeliveryAssignmentService assignmentService,
|
public RiderTaskService(DeliveryAssignmentService assignmentService,
|
||||||
GoodsOrderService goodsOrderService,
|
GoodsOrderService goodsOrderService,
|
||||||
ExpressOrderService expressOrderService) {
|
ExpressOrderService expressOrderService,
|
||||||
|
GroupBuyOrderService groupBuyOrderService) {
|
||||||
this.assignmentService = assignmentService;
|
this.assignmentService = assignmentService;
|
||||||
this.goodsOrderService = goodsOrderService;
|
this.goodsOrderService = goodsOrderService;
|
||||||
this.expressOrderService = expressOrderService;
|
this.expressOrderService = expressOrderService;
|
||||||
|
this.groupBuyOrderService = groupBuyOrderService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DeliveryOrderResponse> listTasks(Long riderId) {
|
public List<DeliveryOrderResponse> listTasks(Long riderId) {
|
||||||
@@ -44,6 +48,8 @@ public class RiderTaskService {
|
|||||||
goodsOrderService.markDelivering(task.getBizOrderId());
|
goodsOrderService.markDelivering(task.getBizOrderId());
|
||||||
} else if (DeliveryAssignmentService.BIZ_TYPE_EXPRESS_ORDER.equals(task.getBizType())) {
|
} else if (DeliveryAssignmentService.BIZ_TYPE_EXPRESS_ORDER.equals(task.getBizType())) {
|
||||||
startExpressOrder(task.getBizOrderId());
|
startExpressOrder(task.getBizOrderId());
|
||||||
|
} else if (DeliveryAssignmentService.BIZ_TYPE_GROUP_BUY_ORDER.equals(task.getBizType())) {
|
||||||
|
groupBuyOrderService.markDelivering(task.getBizOrderId());
|
||||||
}
|
}
|
||||||
task.setStatus(DeliveryTaskStatus.DELIVERING);
|
task.setStatus(DeliveryTaskStatus.DELIVERING);
|
||||||
task.setUpdatedAt(LocalDateTime.now());
|
task.setUpdatedAt(LocalDateTime.now());
|
||||||
@@ -59,6 +65,8 @@ public class RiderTaskService {
|
|||||||
goodsOrderService.complete(task.getBizOrderId());
|
goodsOrderService.complete(task.getBizOrderId());
|
||||||
} else if (DeliveryAssignmentService.BIZ_TYPE_EXPRESS_ORDER.equals(task.getBizType())) {
|
} else if (DeliveryAssignmentService.BIZ_TYPE_EXPRESS_ORDER.equals(task.getBizType())) {
|
||||||
deliverExpressOrder(task.getBizOrderId(), photoUrl);
|
deliverExpressOrder(task.getBizOrderId(), photoUrl);
|
||||||
|
} else if (DeliveryAssignmentService.BIZ_TYPE_GROUP_BUY_ORDER.equals(task.getBizType())) {
|
||||||
|
groupBuyOrderService.complete(task.getBizOrderId());
|
||||||
}
|
}
|
||||||
task.setDeliveredPhotoUrl(photoUrl);
|
task.setDeliveredPhotoUrl(photoUrl);
|
||||||
task.setStatus(DeliveryTaskStatus.DELIVERED);
|
task.setStatus(DeliveryTaskStatus.DELIVERED);
|
||||||
|
|||||||
@@ -3,6 +3,13 @@ package com.linhelp.delivery;
|
|||||||
import com.linhelp.common.enums.DeliveryMethod;
|
import com.linhelp.common.enums.DeliveryMethod;
|
||||||
import com.linhelp.common.enums.DeliveryTaskStatus;
|
import com.linhelp.common.enums.DeliveryTaskStatus;
|
||||||
import com.linhelp.common.enums.GoodsOrderStatus;
|
import com.linhelp.common.enums.GoodsOrderStatus;
|
||||||
|
import com.linhelp.common.enums.GroupBuyOrderStatus;
|
||||||
|
import com.linhelp.groupbuy.GroupBuyOrderRequest;
|
||||||
|
import com.linhelp.groupbuy.GroupBuyOrderResponse;
|
||||||
|
import com.linhelp.groupbuy.GroupBuyOrderService;
|
||||||
|
import com.linhelp.groupbuy.GroupBuyRequest;
|
||||||
|
import com.linhelp.groupbuy.GroupBuyResponse;
|
||||||
|
import com.linhelp.groupbuy.GroupBuyService;
|
||||||
import com.linhelp.order.CreateGoodsOrderItemRequest;
|
import com.linhelp.order.CreateGoodsOrderItemRequest;
|
||||||
import com.linhelp.order.CreateGoodsOrderRequest;
|
import com.linhelp.order.CreateGoodsOrderRequest;
|
||||||
import com.linhelp.order.GoodsOrderResponse;
|
import com.linhelp.order.GoodsOrderResponse;
|
||||||
@@ -14,6 +21,7 @@ import com.linhelp.user.AddressResponse;
|
|||||||
import com.linhelp.user.UserAddressService;
|
import com.linhelp.user.UserAddressService;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
@@ -45,6 +53,19 @@ class RiderTaskServiceTests {
|
|||||||
assertThat(fixture.goodsOrderService.detail(order.getId()).getStatus()).isEqualTo(GoodsOrderStatus.DELIVERING);
|
assertThat(fixture.goodsOrderService.detail(order.getId()).getStatus()).isEqualTo(GoodsOrderStatus.DELIVERING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void startingGroupBuyOrderTaskMovesGroupBuyOrderToDelivering() {
|
||||||
|
TestFixture fixture = new TestFixture();
|
||||||
|
GroupBuyOrderResponse order = fixture.preparedGroupBuyDeliveryOrder();
|
||||||
|
DeliveryUserResponse rider = fixture.rider(3L, "rider one");
|
||||||
|
DeliveryOrderResponse task = fixture.assignmentService.assignGroupBuyOrder(order.getCommunityId(), order.getId(), rider.getId());
|
||||||
|
|
||||||
|
DeliveryOrderResponse started = fixture.riderTaskService.start(rider.getId(), task.getId());
|
||||||
|
|
||||||
|
assertThat(started.getStatus()).isEqualTo(DeliveryTaskStatus.DELIVERING);
|
||||||
|
assertThat(fixture.groupBuyOrderService.detail(order.getId()).getStatus()).isEqualTo(GroupBuyOrderStatus.DELIVERING);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deliveredTaskStoresPhotoUrl() {
|
void deliveredTaskStoresPhotoUrl() {
|
||||||
TestFixture fixture = new TestFixture();
|
TestFixture fixture = new TestFixture();
|
||||||
@@ -59,15 +80,31 @@ class RiderTaskServiceTests {
|
|||||||
assertThat(delivered.getDeliveredPhotoUrl()).isEqualTo("https://img.test/done.jpg");
|
assertThat(delivered.getDeliveredPhotoUrl()).isEqualTo("https://img.test/done.jpg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deliveredGroupBuyOrderTaskCompletesGroupBuyOrder() {
|
||||||
|
TestFixture fixture = new TestFixture();
|
||||||
|
GroupBuyOrderResponse order = fixture.preparedGroupBuyDeliveryOrder();
|
||||||
|
DeliveryUserResponse rider = fixture.rider(3L, "rider one");
|
||||||
|
DeliveryOrderResponse task = fixture.assignmentService.assignGroupBuyOrder(order.getCommunityId(), order.getId(), rider.getId());
|
||||||
|
fixture.riderTaskService.start(rider.getId(), task.getId());
|
||||||
|
|
||||||
|
DeliveryOrderResponse delivered = fixture.riderTaskService.delivered(rider.getId(), task.getId(), "https://img.test/group-done.jpg");
|
||||||
|
|
||||||
|
assertThat(delivered.getStatus()).isEqualTo(DeliveryTaskStatus.DELIVERED);
|
||||||
|
assertThat(fixture.groupBuyOrderService.detail(order.getId()).getStatus()).isEqualTo(GroupBuyOrderStatus.COMPLETED);
|
||||||
|
}
|
||||||
|
|
||||||
private static class TestFixture {
|
private static class TestFixture {
|
||||||
private final ProductService productService = new ProductService();
|
private final ProductService productService = new ProductService();
|
||||||
private final GoodsOrderService goodsOrderService = new GoodsOrderService(productService);
|
private final GoodsOrderService goodsOrderService = new GoodsOrderService(productService);
|
||||||
|
private final GroupBuyService groupBuyService = new GroupBuyService();
|
||||||
|
private final GroupBuyOrderService groupBuyOrderService = new GroupBuyOrderService(groupBuyService);
|
||||||
private final DeliveryUserService deliveryUserService = new DeliveryUserService();
|
private final DeliveryUserService deliveryUserService = new DeliveryUserService();
|
||||||
private final UserAddressService addressService = new UserAddressService();
|
private final UserAddressService addressService = new UserAddressService();
|
||||||
private final DeliveryAssignmentService assignmentService =
|
private final DeliveryAssignmentService assignmentService =
|
||||||
new DeliveryAssignmentService(deliveryUserService, goodsOrderService, null, null, addressService);
|
new DeliveryAssignmentService(deliveryUserService, goodsOrderService, null, groupBuyOrderService, addressService);
|
||||||
private final RiderTaskService riderTaskService =
|
private final RiderTaskService riderTaskService =
|
||||||
new RiderTaskService(assignmentService, goodsOrderService, null);
|
new RiderTaskService(assignmentService, goodsOrderService, null, groupBuyOrderService);
|
||||||
|
|
||||||
private GoodsOrderResponse preparedDeliveryOrder() {
|
private GoodsOrderResponse preparedDeliveryOrder() {
|
||||||
ProductSkuResponse sku = productService.createDemoSku(1L, 1L, 1L, "500g", 990, 5);
|
ProductSkuResponse sku = productService.createDemoSku(1L, 1L, 1L, "500g", 990, 5);
|
||||||
@@ -84,6 +121,33 @@ class RiderTaskServiceTests {
|
|||||||
return goodsOrderService.markPrepared(order.getId());
|
return goodsOrderService.markPrepared(order.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private GroupBuyOrderResponse preparedGroupBuyDeliveryOrder() {
|
||||||
|
GroupBuyRequest groupBuyRequest = new GroupBuyRequest();
|
||||||
|
groupBuyRequest.setTenantId(1L);
|
||||||
|
groupBuyRequest.setCommunityId(1L);
|
||||||
|
groupBuyRequest.setTitle("Today eggs");
|
||||||
|
groupBuyRequest.setCoverUrl("https://img.test/egg.jpg");
|
||||||
|
groupBuyRequest.setPriceCent(2990);
|
||||||
|
groupBuyRequest.setStock(100);
|
||||||
|
groupBuyRequest.setStartTime(LocalDateTime.now().minusHours(1));
|
||||||
|
groupBuyRequest.setEndTime(LocalDateTime.now().plusDays(1));
|
||||||
|
groupBuyRequest.setPickupAddress("North gate");
|
||||||
|
GroupBuyResponse groupBuy = groupBuyService.create(groupBuyRequest);
|
||||||
|
groupBuyService.start(groupBuy.getId());
|
||||||
|
|
||||||
|
GroupBuyOrderRequest orderRequest = new GroupBuyOrderRequest();
|
||||||
|
orderRequest.setTenantId(1L);
|
||||||
|
orderRequest.setCommunityId(1L);
|
||||||
|
orderRequest.setGroupBuyId(groupBuy.getId());
|
||||||
|
orderRequest.setAddressId(address().getId());
|
||||||
|
orderRequest.setQuantity(2);
|
||||||
|
orderRequest.setDeliveryMethod(DeliveryMethod.IMMEDIATE);
|
||||||
|
|
||||||
|
GroupBuyOrderResponse order = groupBuyOrderService.create(1L, orderRequest);
|
||||||
|
groupBuyOrderService.confirm(order.getId());
|
||||||
|
return groupBuyOrderService.markReady(order.getId());
|
||||||
|
}
|
||||||
|
|
||||||
private AddressResponse address() {
|
private AddressResponse address() {
|
||||||
AddressRequest request = new AddressRequest();
|
AddressRequest request = new AddressRequest();
|
||||||
request.setTenantId(1L);
|
request.setTenantId(1L);
|
||||||
|
|||||||
Reference in New Issue
Block a user