chore: seed demo delivery tasks
This commit is contained in:
@@ -2,6 +2,11 @@ package com.linhelp.dev;
|
||||
|
||||
import com.linhelp.delivery.DeliveryUserRequest;
|
||||
import com.linhelp.delivery.DeliveryUserService;
|
||||
import com.linhelp.delivery.DeliveryAssignmentService;
|
||||
import com.linhelp.common.enums.DeliveryMethod;
|
||||
import com.linhelp.express.ExpressOrderRequest;
|
||||
import com.linhelp.express.ExpressOrderResponse;
|
||||
import com.linhelp.express.ExpressOrderService;
|
||||
import com.linhelp.groupbuy.GroupBuyRequest;
|
||||
import com.linhelp.groupbuy.GroupBuyResponse;
|
||||
import com.linhelp.groupbuy.GroupBuyService;
|
||||
@@ -10,6 +15,10 @@ import com.linhelp.notice.BannerService;
|
||||
import com.linhelp.notice.NoticeRequest;
|
||||
import com.linhelp.notice.NoticeResponse;
|
||||
import com.linhelp.notice.NoticeService;
|
||||
import com.linhelp.order.CreateGoodsOrderItemRequest;
|
||||
import com.linhelp.order.CreateGoodsOrderRequest;
|
||||
import com.linhelp.order.GoodsOrderResponse;
|
||||
import com.linhelp.order.GoodsOrderService;
|
||||
import com.linhelp.product.ProductCategoryRequest;
|
||||
import com.linhelp.product.ProductCategoryResponse;
|
||||
import com.linhelp.product.ProductRequest;
|
||||
@@ -19,6 +28,7 @@ import com.linhelp.product.ProductSkuRequest;
|
||||
import com.linhelp.secondhand.SecondGoodsRequest;
|
||||
import com.linhelp.secondhand.SecondGoodsResponse;
|
||||
import com.linhelp.secondhand.SecondGoodsService;
|
||||
import com.linhelp.user.AddressResponse;
|
||||
import com.linhelp.user.AddressRequest;
|
||||
import com.linhelp.user.UserAddressService;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
@@ -45,7 +55,10 @@ public class DevDataInitializer implements ApplicationRunner {
|
||||
private final BannerService bannerService;
|
||||
private final SecondGoodsService secondGoodsService;
|
||||
private final DeliveryUserService deliveryUserService;
|
||||
private final DeliveryAssignmentService deliveryAssignmentService;
|
||||
private final UserAddressService addressService;
|
||||
private final GoodsOrderService goodsOrderService;
|
||||
private final ExpressOrderService expressOrderService;
|
||||
|
||||
public DevDataInitializer(ProductService productService,
|
||||
GroupBuyService groupBuyService,
|
||||
@@ -53,14 +66,20 @@ public class DevDataInitializer implements ApplicationRunner {
|
||||
BannerService bannerService,
|
||||
SecondGoodsService secondGoodsService,
|
||||
DeliveryUserService deliveryUserService,
|
||||
UserAddressService addressService) {
|
||||
DeliveryAssignmentService deliveryAssignmentService,
|
||||
UserAddressService addressService,
|
||||
GoodsOrderService goodsOrderService,
|
||||
ExpressOrderService expressOrderService) {
|
||||
this.productService = productService;
|
||||
this.groupBuyService = groupBuyService;
|
||||
this.noticeService = noticeService;
|
||||
this.bannerService = bannerService;
|
||||
this.secondGoodsService = secondGoodsService;
|
||||
this.deliveryUserService = deliveryUserService;
|
||||
this.deliveryAssignmentService = deliveryAssignmentService;
|
||||
this.addressService = addressService;
|
||||
this.goodsOrderService = goodsOrderService;
|
||||
this.expressOrderService = expressOrderService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -68,17 +87,18 @@ public class DevDataInitializer implements ApplicationRunner {
|
||||
if (!productService.listCategories(COMMUNITY_ID, false).isEmpty()) {
|
||||
return;
|
||||
}
|
||||
seedAddress();
|
||||
AddressResponse address = seedAddress();
|
||||
seedDeliveryUser();
|
||||
List<ProductCategoryResponse> categories = seedCategories();
|
||||
seedProducts(categories);
|
||||
ProductResponse demoProduct = seedProducts(categories);
|
||||
seedDemoDeliveryTasks(address.getId(), demoProduct);
|
||||
seedGroupBuy();
|
||||
seedNotices();
|
||||
seedBanner();
|
||||
seedSecondGoods();
|
||||
}
|
||||
|
||||
private void seedAddress() {
|
||||
private AddressResponse seedAddress() {
|
||||
AddressRequest request = new AddressRequest();
|
||||
request.setTenantId(TENANT_ID);
|
||||
request.setCommunityId(COMMUNITY_ID);
|
||||
@@ -88,7 +108,7 @@ public class DevDataInitializer implements ApplicationRunner {
|
||||
request.setRoom("1201");
|
||||
request.setDetail("东门旁");
|
||||
request.setDefault(true);
|
||||
addressService.create(RESIDENT_USER_ID, request);
|
||||
return addressService.create(RESIDENT_USER_ID, request);
|
||||
}
|
||||
|
||||
private void seedDeliveryUser() {
|
||||
@@ -123,8 +143,8 @@ public class DevDataInitializer implements ApplicationRunner {
|
||||
return productService.createCategory(request);
|
||||
}
|
||||
|
||||
private void seedProducts(List<ProductCategoryResponse> categories) {
|
||||
createProduct(categories.get(0).getId(), "烟台苹果", "/mock/apple.jpg", "脆甜多汁,适合家庭日常补货", "约1kg", 1290, 1590, 80);
|
||||
private ProductResponse seedProducts(List<ProductCategoryResponse> categories) {
|
||||
ProductResponse demoProduct = createProduct(categories.get(0).getId(), "烟台苹果", "/mock/apple.jpg", "脆甜多汁,适合家庭日常补货", "约1kg", 1290, 1590, 80);
|
||||
createProduct(categories.get(0).getId(), "海南香蕉", "/mock/banana.jpg", "当日到货,成熟度适中", "约1.5kg", 990, 1290, 70);
|
||||
createProduct(categories.get(1).getId(), "每日坚果", "/mock/nuts.jpg", "独立小包装,办公室零食", "12包", 2990, 3590, 45);
|
||||
createProduct(categories.get(1).getId(), "海苔脆片", "/mock/seaweed.jpg", "轻食小零嘴", "原味40g", 690, 890, 90);
|
||||
@@ -134,10 +154,11 @@ public class DevDataInitializer implements ApplicationRunner {
|
||||
createProduct(categories.get(3).getId(), "豆浆", "/mock/soy-milk.jpg", "现磨豆浆", "300ml", 350, 500, 120);
|
||||
createProduct(categories.get(4).getId(), "上海青", "/mock/greens.jpg", "新鲜蔬菜,约500g", "约500g", 590, 790, 80);
|
||||
createProduct(categories.get(5).getId(), "抽纸三包装", "/mock/tissue.jpg", "家庭常备日用品", "3包", 1890, 2290, 55);
|
||||
return demoProduct;
|
||||
}
|
||||
|
||||
private void createProduct(Long categoryId, String name, String coverUrl, String description,
|
||||
String skuName, int priceCent, int originPriceCent, int stock) {
|
||||
private ProductResponse createProduct(Long categoryId, String name, String coverUrl, String description,
|
||||
String skuName, int priceCent, int originPriceCent, int stock) {
|
||||
ProductRequest productRequest = new ProductRequest();
|
||||
productRequest.setTenantId(TENANT_ID);
|
||||
productRequest.setCommunityId(COMMUNITY_ID);
|
||||
@@ -158,7 +179,49 @@ public class DevDataInitializer implements ApplicationRunner {
|
||||
skuRequest.setStock(stock);
|
||||
skuRequest.setEnabled(true);
|
||||
productService.addSku(product.getId(), skuRequest);
|
||||
productService.onShelf(product.getId());
|
||||
return productService.onShelf(product.getId());
|
||||
}
|
||||
|
||||
private void seedDemoDeliveryTasks(Long addressId, ProductResponse demoProduct) {
|
||||
GoodsOrderResponse goodsOrder = goodsOrderService.create(RESIDENT_USER_ID, goodsOrder(addressId, demoProduct));
|
||||
goodsOrderService.confirm(goodsOrder.getId());
|
||||
goodsOrderService.markPaid(goodsOrder.getId());
|
||||
GoodsOrderResponse preparedGoodsOrder = goodsOrderService.markPrepared(goodsOrder.getId());
|
||||
deliveryAssignmentService.assignGoodsOrder(preparedGoodsOrder.getId(), 1L);
|
||||
|
||||
ExpressOrderResponse expressOrder = expressOrderService.create(RESIDENT_USER_ID, expressOrder(addressId));
|
||||
expressOrderService.confirm(expressOrder.getId());
|
||||
deliveryAssignmentService.assignExpressOrder(expressOrder.getId(), 1L);
|
||||
}
|
||||
|
||||
private CreateGoodsOrderRequest goodsOrder(Long addressId, ProductResponse demoProduct) {
|
||||
CreateGoodsOrderRequest request = new CreateGoodsOrderRequest();
|
||||
request.setTenantId(TENANT_ID);
|
||||
request.setCommunityId(COMMUNITY_ID);
|
||||
request.setMerchantId(MERCHANT_ID);
|
||||
request.setAddressId(addressId);
|
||||
request.setDeliveryMethod(DeliveryMethod.IMMEDIATE);
|
||||
request.setRemark("Demo:请送到门口");
|
||||
request.setItems(Arrays.asList(new CreateGoodsOrderItemRequest(
|
||||
demoProduct.getId(),
|
||||
demoProduct.getSkus().get(0).getId(),
|
||||
1
|
||||
)));
|
||||
return request;
|
||||
}
|
||||
|
||||
private ExpressOrderRequest expressOrder(Long addressId) {
|
||||
ExpressOrderRequest request = new ExpressOrderRequest();
|
||||
request.setTenantId(TENANT_ID);
|
||||
request.setCommunityId(COMMUNITY_ID);
|
||||
request.setAddressId(addressId);
|
||||
request.setExpressCompany("顺丰速运");
|
||||
request.setPickupCode("A1-2333");
|
||||
request.setPickupAddress("小区东门快递驿站");
|
||||
request.setReceiverPhone("13800001000");
|
||||
request.setPackageCount(2);
|
||||
request.setRemark("Demo:快递较轻,可直接放门口");
|
||||
return request;
|
||||
}
|
||||
|
||||
private void seedGroupBuy() {
|
||||
|
||||
@@ -65,7 +65,7 @@ INSERT INTO product (id, tenant_id, community_id, merchant_id, category_id, name
|
||||
(10, 1, 1, 1, 6, '抽纸三包装', '/mock/tissue.jpg', '家庭常备日用品', '提', 'ON_SHELF');
|
||||
|
||||
INSERT INTO product_sku (id, tenant_id, community_id, product_id, sku_name, price_cent, origin_price_cent, stock, enabled) VALUES
|
||||
(1, 1, 1, 1, '约 1kg', 1290, 1590, 80, 1),
|
||||
(1, 1, 1, 1, '约 1kg', 1290, 1590, 79, 1),
|
||||
(2, 1, 1, 2, '约 1.5kg', 990, 1290, 70, 1),
|
||||
(3, 1, 1, 3, '12 包', 2990, 3590, 45, 1),
|
||||
(4, 1, 1, 4, '原味 40g', 690, 890, 90, 1),
|
||||
@@ -76,6 +76,19 @@ INSERT INTO product_sku (id, tenant_id, community_id, product_id, sku_name, pric
|
||||
(9, 1, 1, 9, '约 500g', 590, 790, 80, 1),
|
||||
(10, 1, 1, 10, '3 包', 1890, 2290, 55, 1);
|
||||
|
||||
INSERT INTO goods_order (id, order_no, tenant_id, community_id, user_id, merchant_id, address_id, delivery_method, status, offline_pay_status, total_amount_cent, remark) VALUES
|
||||
(1, 'GO00000001', 1, 1, 1000, 1, 1, 'IMMEDIATE', 'PENDING_DELIVERY', 'PAID', 1290, 'Demo:请送到门口');
|
||||
|
||||
INSERT INTO goods_order_item (id, tenant_id, community_id, order_id, product_id, sku_id, product_name, sku_name, quantity, price_cent, amount_cent) VALUES
|
||||
(1, 1, 1, 1, 1, 1, '烟台苹果', '约 1kg', 1, 1290, 1290);
|
||||
|
||||
INSERT INTO express_order (id, order_no, tenant_id, community_id, user_id, address_id, express_company, pickup_code, pickup_address, package_count, service_fee_cent, phone, status, offline_pay_status, remark) VALUES
|
||||
(1, 'EO00000001', 1, 1, 1000, 1, '顺丰速运', 'A1-2333', '小区东门快递驿站', 2, 400, '13800001000', 'PENDING_PICKUP', 'UNPAID', 'Demo:快递较轻,可直接放门口');
|
||||
|
||||
INSERT INTO delivery_order (id, tenant_id, community_id, biz_type, biz_order_id, delivery_user_id, status) VALUES
|
||||
(1, 1, 1, 'GOODS_ORDER', 1, 1, 'ASSIGNED'),
|
||||
(2, 1, 1, 'EXPRESS_ORDER', 1, 1, 'ASSIGNED');
|
||||
|
||||
INSERT INTO group_buy (id, tenant_id, community_id, merchant_id, title, cover_url, description, price_cent, origin_price_cent, stock, deadline_at, expected_delivery_at, status) VALUES
|
||||
(1, 1, 1, 1, '今日团购:麒麟西瓜', '/mock/watermelon.jpg', '满 20 份成团,晚饭前送到小区门口', 1990, 2590, 120, DATE_ADD(NOW(), INTERVAL 1 DAY), DATE_ADD(NOW(), INTERVAL 2 DAY), 'ONGOING');
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.linhelp.dev;
|
||||
|
||||
import com.linhelp.delivery.DeliveryUserService;
|
||||
import com.linhelp.delivery.DeliveryAssignmentService;
|
||||
import com.linhelp.groupbuy.GroupBuyService;
|
||||
import com.linhelp.notice.BannerService;
|
||||
import com.linhelp.notice.NoticeService;
|
||||
@@ -29,6 +30,8 @@ class DevDataInitializerTests {
|
||||
private SecondGoodsService secondGoodsService;
|
||||
@Autowired
|
||||
private DeliveryUserService deliveryUserService;
|
||||
@Autowired
|
||||
private DeliveryAssignmentService deliveryAssignmentService;
|
||||
|
||||
@Test
|
||||
void seedsOneCommunityDemoDataForLocalTrial() {
|
||||
@@ -39,5 +42,8 @@ class DevDataInitializerTests {
|
||||
assertThat(bannerService.listEnabled(1L)).hasSize(1);
|
||||
assertThat(secondGoodsService.listPublic(1L, null)).hasSize(1);
|
||||
assertThat(deliveryUserService.requireByUserId(3L).getName()).isEqualTo("配送员小林");
|
||||
assertThat(deliveryAssignmentService.listRiderTasks(1L))
|
||||
.extracting("bizType")
|
||||
.containsExactly("GOODS_ORDER", "EXPRESS_ORDER");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user