From 0faa7f298823b5f6f2c7641cedf532a6fca4ea56 Mon Sep 17 00:00:00 2001 From: irving Date: Sat, 1 Nov 2025 23:55:28 -0400 Subject: [PATCH] =?UTF-8?q?test(apitest):=20=E5=AE=8C=E5=96=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=B5=8B=E8=AF=95=E6=95=B0=E6=8D=AE=E6=92=AD=E7=A7=8D?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/apitest/ApiTestDataSeeder.java | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/play-admin/src/main/java/com/starry/admin/common/apitest/ApiTestDataSeeder.java b/play-admin/src/main/java/com/starry/admin/common/apitest/ApiTestDataSeeder.java index 85dedfc..df0f17e 100644 --- a/play-admin/src/main/java/com/starry/admin/common/apitest/ApiTestDataSeeder.java +++ b/play-admin/src/main/java/com/starry/admin/common/apitest/ApiTestDataSeeder.java @@ -7,13 +7,19 @@ import com.starry.admin.modules.clerk.module.entity.PlayClerkUserInfoEntity; import com.starry.admin.modules.clerk.service.IPlayClerkCommodityService; import com.starry.admin.modules.clerk.service.IPlayClerkLevelInfoService; import com.starry.admin.modules.clerk.service.IPlayClerkUserInfoService; +import com.starry.admin.modules.custom.mapper.PlayCustomGiftInfoMapper; +import com.starry.admin.modules.custom.module.entity.PlayCustomGiftInfoEntity; import com.starry.admin.modules.custom.module.entity.PlayCustomUserInfoEntity; +import com.starry.admin.modules.custom.service.IPlayCustomGiftInfoService; import com.starry.admin.modules.custom.service.IPlayCustomUserInfoService; import com.starry.admin.modules.personnel.module.entity.PlayPersonnelGroupInfoEntity; import com.starry.admin.modules.personnel.service.IPlayPersonnelGroupInfoService; +import com.starry.admin.modules.shop.mapper.PlayClerkGiftInfoMapper; +import com.starry.admin.modules.shop.module.entity.PlayClerkGiftInfoEntity; import com.starry.admin.modules.shop.module.entity.PlayCommodityAndLevelInfoEntity; import com.starry.admin.modules.shop.module.entity.PlayCommodityInfoEntity; import com.starry.admin.modules.shop.module.entity.PlayGiftInfoEntity; +import com.starry.admin.modules.shop.service.IPlayClerkGiftInfoService; import com.starry.admin.modules.shop.service.IPlayCommodityAndLevelInfoService; import com.starry.admin.modules.shop.service.IPlayCommodityInfoService; import com.starry.admin.modules.shop.service.IPlayGiftInfoService; @@ -78,7 +84,11 @@ public class ApiTestDataSeeder implements CommandLineRunner { private final IPlayCommodityAndLevelInfoService commodityAndLevelInfoService; private final IPlayGiftInfoService giftInfoService; private final IPlayClerkCommodityService clerkCommodityService; + private final IPlayClerkGiftInfoService playClerkGiftInfoService; private final IPlayCustomUserInfoService customUserInfoService; + private final IPlayCustomGiftInfoService playCustomGiftInfoService; + private final PlayClerkGiftInfoMapper playClerkGiftInfoMapper; + private final PlayCustomGiftInfoMapper playCustomGiftInfoMapper; private final PasswordEncoder passwordEncoder; private final WxTokenService wxTokenService; @@ -93,7 +103,11 @@ public class ApiTestDataSeeder implements CommandLineRunner { IPlayCommodityAndLevelInfoService commodityAndLevelInfoService, IPlayGiftInfoService giftInfoService, IPlayClerkCommodityService clerkCommodityService, + IPlayClerkGiftInfoService playClerkGiftInfoService, IPlayCustomUserInfoService customUserInfoService, + IPlayCustomGiftInfoService playCustomGiftInfoService, + PlayClerkGiftInfoMapper playClerkGiftInfoMapper, + PlayCustomGiftInfoMapper playCustomGiftInfoMapper, PasswordEncoder passwordEncoder, WxTokenService wxTokenService) { this.tenantPackageService = tenantPackageService; @@ -106,7 +120,11 @@ public class ApiTestDataSeeder implements CommandLineRunner { this.commodityAndLevelInfoService = commodityAndLevelInfoService; this.giftInfoService = giftInfoService; this.clerkCommodityService = clerkCommodityService; + this.playClerkGiftInfoService = playClerkGiftInfoService; this.customUserInfoService = customUserInfoService; + this.playCustomGiftInfoService = playCustomGiftInfoService; + this.playClerkGiftInfoMapper = playClerkGiftInfoMapper; + this.playCustomGiftInfoMapper = playCustomGiftInfoMapper; this.passwordEncoder = passwordEncoder; this.wxTokenService = wxTokenService; } @@ -128,6 +146,7 @@ public class ApiTestDataSeeder implements CommandLineRunner { seedClerk(); seedClerkCommodity(); seedGift(); + resetGiftCounters(); seedCustomer(); } finally { if (Objects.nonNull(originalTenant)) { @@ -257,10 +276,53 @@ public class ApiTestDataSeeder implements CommandLineRunner { parent.setSort(1); commodityInfoService.save(parent); log.info("Inserted API test commodity parent {}", DEFAULT_COMMODITY_PARENT_ID); + } else { + boolean parentNeedsUpdate = false; + if (!"00".equals(parent.getPId())) { + parent.setPId("00"); + parentNeedsUpdate = true; + } + if (!"service-category".equals(parent.getItemType())) { + parent.setItemType("service-category"); + parentNeedsUpdate = true; + } + if (!DEFAULT_TENANT_ID.equals(parent.getTenantId())) { + parent.setTenantId(DEFAULT_TENANT_ID); + parentNeedsUpdate = true; + } + if (!"1".equals(parent.getEnableStace())) { + parent.setEnableStace("1"); + parentNeedsUpdate = true; + } + if (parentNeedsUpdate) { + commodityInfoService.updateById(parent); + log.info("Normalized API test commodity parent {}", DEFAULT_COMMODITY_PARENT_ID); + } } PlayCommodityInfoEntity child = commodityInfoService.getById(DEFAULT_COMMODITY_ID); if (child != null) { + boolean childNeedsUpdate = false; + if (!DEFAULT_COMMODITY_PARENT_ID.equals(child.getPId())) { + child.setPId(DEFAULT_COMMODITY_PARENT_ID); + childNeedsUpdate = true; + } + if (!"service".equals(child.getItemType())) { + child.setItemType("service"); + childNeedsUpdate = true; + } + if (!DEFAULT_TENANT_ID.equals(child.getTenantId())) { + child.setTenantId(DEFAULT_TENANT_ID); + childNeedsUpdate = true; + } + if (!"1".equals(child.getEnableStace())) { + child.setEnableStace("1"); + childNeedsUpdate = true; + } + if (childNeedsUpdate) { + commodityInfoService.updateById(child); + log.info("Normalized API test commodity {}", DEFAULT_COMMODITY_ID); + } log.info("API test commodity {} already exists", DEFAULT_COMMODITY_ID); return child; } @@ -386,6 +448,38 @@ public class ApiTestDataSeeder implements CommandLineRunner { log.info("Inserted API test gift {}", DEFAULT_GIFT_ID); } + private void resetGiftCounters() { + int customerReset = playCustomGiftInfoMapper.resetGiftCount(DEFAULT_TENANT_ID, DEFAULT_CUSTOMER_ID, DEFAULT_GIFT_ID); + if (customerReset == 0) { + PlayCustomGiftInfoEntity entity = new PlayCustomGiftInfoEntity(); + entity.setId(IdUtils.getUuid()); + entity.setTenantId(DEFAULT_TENANT_ID); + entity.setCustomId(DEFAULT_CUSTOMER_ID); + entity.setGiffId(DEFAULT_GIFT_ID); + entity.setGiffNumber(0L); + try { + playCustomGiftInfoService.save(entity); + } catch (org.springframework.dao.DuplicateKeyException duplicateKeyException) { + playCustomGiftInfoMapper.resetGiftCount(DEFAULT_TENANT_ID, DEFAULT_CUSTOMER_ID, DEFAULT_GIFT_ID); + } + } + + int clerkReset = playClerkGiftInfoMapper.resetGiftCount(DEFAULT_TENANT_ID, DEFAULT_CLERK_ID, DEFAULT_GIFT_ID); + if (clerkReset == 0) { + PlayClerkGiftInfoEntity entity = new PlayClerkGiftInfoEntity(); + entity.setId(IdUtils.getUuid()); + entity.setTenantId(DEFAULT_TENANT_ID); + entity.setClerkId(DEFAULT_CLERK_ID); + entity.setGiffId(DEFAULT_GIFT_ID); + entity.setGiffNumber(0L); + try { + playClerkGiftInfoService.save(entity); + } catch (org.springframework.dao.DuplicateKeyException duplicateKeyException) { + playClerkGiftInfoMapper.resetGiftCount(DEFAULT_TENANT_ID, DEFAULT_CLERK_ID, DEFAULT_GIFT_ID); + } + } + } + private void seedCustomer() { PlayCustomUserInfoEntity customer = customUserInfoService.getById(DEFAULT_CUSTOMER_ID); String token = wxTokenService.createWxUserToken(DEFAULT_CUSTOMER_ID);