test(apitest): 完善接口测试数据播种逻辑
This commit is contained in:
@@ -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.IPlayClerkCommodityService;
|
||||||
import com.starry.admin.modules.clerk.service.IPlayClerkLevelInfoService;
|
import com.starry.admin.modules.clerk.service.IPlayClerkLevelInfoService;
|
||||||
import com.starry.admin.modules.clerk.service.IPlayClerkUserInfoService;
|
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.module.entity.PlayCustomUserInfoEntity;
|
||||||
|
import com.starry.admin.modules.custom.service.IPlayCustomGiftInfoService;
|
||||||
import com.starry.admin.modules.custom.service.IPlayCustomUserInfoService;
|
import com.starry.admin.modules.custom.service.IPlayCustomUserInfoService;
|
||||||
import com.starry.admin.modules.personnel.module.entity.PlayPersonnelGroupInfoEntity;
|
import com.starry.admin.modules.personnel.module.entity.PlayPersonnelGroupInfoEntity;
|
||||||
import com.starry.admin.modules.personnel.service.IPlayPersonnelGroupInfoService;
|
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.PlayCommodityAndLevelInfoEntity;
|
||||||
import com.starry.admin.modules.shop.module.entity.PlayCommodityInfoEntity;
|
import com.starry.admin.modules.shop.module.entity.PlayCommodityInfoEntity;
|
||||||
import com.starry.admin.modules.shop.module.entity.PlayGiftInfoEntity;
|
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.IPlayCommodityAndLevelInfoService;
|
||||||
import com.starry.admin.modules.shop.service.IPlayCommodityInfoService;
|
import com.starry.admin.modules.shop.service.IPlayCommodityInfoService;
|
||||||
import com.starry.admin.modules.shop.service.IPlayGiftInfoService;
|
import com.starry.admin.modules.shop.service.IPlayGiftInfoService;
|
||||||
@@ -78,7 +84,11 @@ public class ApiTestDataSeeder implements CommandLineRunner {
|
|||||||
private final IPlayCommodityAndLevelInfoService commodityAndLevelInfoService;
|
private final IPlayCommodityAndLevelInfoService commodityAndLevelInfoService;
|
||||||
private final IPlayGiftInfoService giftInfoService;
|
private final IPlayGiftInfoService giftInfoService;
|
||||||
private final IPlayClerkCommodityService clerkCommodityService;
|
private final IPlayClerkCommodityService clerkCommodityService;
|
||||||
|
private final IPlayClerkGiftInfoService playClerkGiftInfoService;
|
||||||
private final IPlayCustomUserInfoService customUserInfoService;
|
private final IPlayCustomUserInfoService customUserInfoService;
|
||||||
|
private final IPlayCustomGiftInfoService playCustomGiftInfoService;
|
||||||
|
private final PlayClerkGiftInfoMapper playClerkGiftInfoMapper;
|
||||||
|
private final PlayCustomGiftInfoMapper playCustomGiftInfoMapper;
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
private final WxTokenService wxTokenService;
|
private final WxTokenService wxTokenService;
|
||||||
|
|
||||||
@@ -93,7 +103,11 @@ public class ApiTestDataSeeder implements CommandLineRunner {
|
|||||||
IPlayCommodityAndLevelInfoService commodityAndLevelInfoService,
|
IPlayCommodityAndLevelInfoService commodityAndLevelInfoService,
|
||||||
IPlayGiftInfoService giftInfoService,
|
IPlayGiftInfoService giftInfoService,
|
||||||
IPlayClerkCommodityService clerkCommodityService,
|
IPlayClerkCommodityService clerkCommodityService,
|
||||||
|
IPlayClerkGiftInfoService playClerkGiftInfoService,
|
||||||
IPlayCustomUserInfoService customUserInfoService,
|
IPlayCustomUserInfoService customUserInfoService,
|
||||||
|
IPlayCustomGiftInfoService playCustomGiftInfoService,
|
||||||
|
PlayClerkGiftInfoMapper playClerkGiftInfoMapper,
|
||||||
|
PlayCustomGiftInfoMapper playCustomGiftInfoMapper,
|
||||||
PasswordEncoder passwordEncoder,
|
PasswordEncoder passwordEncoder,
|
||||||
WxTokenService wxTokenService) {
|
WxTokenService wxTokenService) {
|
||||||
this.tenantPackageService = tenantPackageService;
|
this.tenantPackageService = tenantPackageService;
|
||||||
@@ -106,7 +120,11 @@ public class ApiTestDataSeeder implements CommandLineRunner {
|
|||||||
this.commodityAndLevelInfoService = commodityAndLevelInfoService;
|
this.commodityAndLevelInfoService = commodityAndLevelInfoService;
|
||||||
this.giftInfoService = giftInfoService;
|
this.giftInfoService = giftInfoService;
|
||||||
this.clerkCommodityService = clerkCommodityService;
|
this.clerkCommodityService = clerkCommodityService;
|
||||||
|
this.playClerkGiftInfoService = playClerkGiftInfoService;
|
||||||
this.customUserInfoService = customUserInfoService;
|
this.customUserInfoService = customUserInfoService;
|
||||||
|
this.playCustomGiftInfoService = playCustomGiftInfoService;
|
||||||
|
this.playClerkGiftInfoMapper = playClerkGiftInfoMapper;
|
||||||
|
this.playCustomGiftInfoMapper = playCustomGiftInfoMapper;
|
||||||
this.passwordEncoder = passwordEncoder;
|
this.passwordEncoder = passwordEncoder;
|
||||||
this.wxTokenService = wxTokenService;
|
this.wxTokenService = wxTokenService;
|
||||||
}
|
}
|
||||||
@@ -128,6 +146,7 @@ public class ApiTestDataSeeder implements CommandLineRunner {
|
|||||||
seedClerk();
|
seedClerk();
|
||||||
seedClerkCommodity();
|
seedClerkCommodity();
|
||||||
seedGift();
|
seedGift();
|
||||||
|
resetGiftCounters();
|
||||||
seedCustomer();
|
seedCustomer();
|
||||||
} finally {
|
} finally {
|
||||||
if (Objects.nonNull(originalTenant)) {
|
if (Objects.nonNull(originalTenant)) {
|
||||||
@@ -257,10 +276,53 @@ public class ApiTestDataSeeder implements CommandLineRunner {
|
|||||||
parent.setSort(1);
|
parent.setSort(1);
|
||||||
commodityInfoService.save(parent);
|
commodityInfoService.save(parent);
|
||||||
log.info("Inserted API test commodity parent {}", DEFAULT_COMMODITY_PARENT_ID);
|
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);
|
PlayCommodityInfoEntity child = commodityInfoService.getById(DEFAULT_COMMODITY_ID);
|
||||||
if (child != null) {
|
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);
|
log.info("API test commodity {} already exists", DEFAULT_COMMODITY_ID);
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
@@ -386,6 +448,38 @@ public class ApiTestDataSeeder implements CommandLineRunner {
|
|||||||
log.info("Inserted API test gift {}", DEFAULT_GIFT_ID);
|
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() {
|
private void seedCustomer() {
|
||||||
PlayCustomUserInfoEntity customer = customUserInfoService.getById(DEFAULT_CUSTOMER_ID);
|
PlayCustomUserInfoEntity customer = customUserInfoService.getById(DEFAULT_CUSTOMER_ID);
|
||||||
String token = wxTokenService.createWxUserToken(DEFAULT_CUSTOMER_ID);
|
String token = wxTokenService.createWxUserToken(DEFAULT_CUSTOMER_ID);
|
||||||
|
|||||||
Reference in New Issue
Block a user