API-test-in-progress

This commit is contained in:
irving
2025-11-01 15:16:45 -04:00
parent f3480b6ba0
commit 04b9960e35
12 changed files with 2253 additions and 19 deletions

View File

@@ -11,16 +11,22 @@ import com.starry.admin.modules.custom.module.entity.PlayCustomUserInfoEntity;
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.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.IPlayCommodityAndLevelInfoService;
import com.starry.admin.modules.shop.service.IPlayCommodityInfoService;
import com.starry.admin.modules.shop.service.IPlayGiftInfoService;
import com.starry.admin.modules.system.module.entity.SysTenantEntity;
import com.starry.admin.modules.system.module.entity.SysTenantPackageEntity;
import com.starry.admin.modules.system.module.entity.SysUserEntity;
import com.starry.admin.modules.system.service.ISysTenantPackageService;
import com.starry.admin.modules.system.service.ISysTenantService;
import com.starry.admin.modules.system.service.SysUserService;
import com.starry.admin.modules.weichat.service.WxTokenService;
import com.starry.admin.utils.SecurityUtils;
import com.starry.common.context.CustomSecurityContextHolder;
import com.starry.common.utils.IdUtils;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
@@ -49,9 +55,18 @@ public class ApiTestDataSeeder implements CommandLineRunner {
public static final String DEFAULT_CLERK_LEVEL_ID = "lvl-basic";
public static final String DEFAULT_CLERK_ID = "clerk-apitest";
public static final String DEFAULT_CLERK_OPEN_ID = "openid-clerk-apitest";
public static final String DEFAULT_COMMODITY_PARENT_ID = "svc-parent";
public static final String DEFAULT_COMMODITY_PARENT_NAME = "语音陪聊服务";
public static final String DEFAULT_COMMODITY_ID = "svc-basic";
public static final String DEFAULT_CLERK_COMMODITY_ID = "clerk-svc-basic";
public static final String DEFAULT_CUSTOMER_ID = "customer-apitest";
public static final String DEFAULT_GIFT_ID = "gift-basic";
public static final String DEFAULT_GIFT_NAME = "API测试礼物";
public static final BigDecimal DEFAULT_COMMODITY_PRICE = new BigDecimal("120.00");
private static final String GIFT_TYPE_REGULAR = "1";
private static final String GIFT_STATE_ACTIVE = "0";
private static final BigDecimal DEFAULT_CUSTOMER_BALANCE = new BigDecimal("200.00");
private static final BigDecimal DEFAULT_CUSTOMER_RECHARGE = DEFAULT_CUSTOMER_BALANCE;
private final ISysTenantPackageService tenantPackageService;
private final ISysTenantService tenantService;
@@ -60,9 +75,12 @@ public class ApiTestDataSeeder implements CommandLineRunner {
private final IPlayClerkLevelInfoService clerkLevelInfoService;
private final IPlayClerkUserInfoService clerkUserInfoService;
private final IPlayCommodityInfoService commodityInfoService;
private final IPlayCommodityAndLevelInfoService commodityAndLevelInfoService;
private final IPlayGiftInfoService giftInfoService;
private final IPlayClerkCommodityService clerkCommodityService;
private final IPlayCustomUserInfoService customUserInfoService;
private final PasswordEncoder passwordEncoder;
private final WxTokenService wxTokenService;
public ApiTestDataSeeder(
ISysTenantPackageService tenantPackageService,
@@ -72,9 +90,12 @@ public class ApiTestDataSeeder implements CommandLineRunner {
IPlayClerkLevelInfoService clerkLevelInfoService,
IPlayClerkUserInfoService clerkUserInfoService,
IPlayCommodityInfoService commodityInfoService,
IPlayCommodityAndLevelInfoService commodityAndLevelInfoService,
IPlayGiftInfoService giftInfoService,
IPlayClerkCommodityService clerkCommodityService,
IPlayCustomUserInfoService customUserInfoService,
PasswordEncoder passwordEncoder) {
PasswordEncoder passwordEncoder,
WxTokenService wxTokenService) {
this.tenantPackageService = tenantPackageService;
this.tenantService = tenantService;
this.sysUserService = sysUserService;
@@ -82,9 +103,12 @@ public class ApiTestDataSeeder implements CommandLineRunner {
this.clerkLevelInfoService = clerkLevelInfoService;
this.clerkUserInfoService = clerkUserInfoService;
this.commodityInfoService = commodityInfoService;
this.commodityAndLevelInfoService = commodityAndLevelInfoService;
this.giftInfoService = giftInfoService;
this.clerkCommodityService = clerkCommodityService;
this.customUserInfoService = customUserInfoService;
this.passwordEncoder = passwordEncoder;
this.wxTokenService = wxTokenService;
}
@Override
@@ -99,9 +123,11 @@ public class ApiTestDataSeeder implements CommandLineRunner {
seedAdminUser();
seedPersonnelGroup();
seedClerkLevel();
seedCommodity();
PlayCommodityInfoEntity commodity = seedCommodityHierarchy();
seedCommodityPricing(commodity);
seedClerk();
seedClerkCommodity();
seedGift();
seedCustomer();
} finally {
if (Objects.nonNull(originalTenant)) {
@@ -218,28 +244,70 @@ public class ApiTestDataSeeder implements CommandLineRunner {
log.info("Inserted API test clerk level {}", DEFAULT_CLERK_LEVEL_ID);
}
private void seedCommodity() {
PlayCommodityInfoEntity commodity = commodityInfoService.getById(DEFAULT_COMMODITY_ID);
if (commodity != null) {
private PlayCommodityInfoEntity seedCommodityHierarchy() {
PlayCommodityInfoEntity parent = commodityInfoService.getById(DEFAULT_COMMODITY_PARENT_ID);
if (parent == null) {
parent = new PlayCommodityInfoEntity();
parent.setId(DEFAULT_COMMODITY_PARENT_ID);
parent.setTenantId(DEFAULT_TENANT_ID);
parent.setPId("00");
parent.setItemType("service-category");
parent.setItemName(DEFAULT_COMMODITY_PARENT_NAME);
parent.setEnableStace("1");
parent.setSort(1);
commodityInfoService.save(parent);
log.info("Inserted API test commodity parent {}", DEFAULT_COMMODITY_PARENT_ID);
}
PlayCommodityInfoEntity child = commodityInfoService.getById(DEFAULT_COMMODITY_ID);
if (child != null) {
log.info("API test commodity {} already exists", DEFAULT_COMMODITY_ID);
return child;
}
child = new PlayCommodityInfoEntity();
child.setId(DEFAULT_COMMODITY_ID);
child.setTenantId(DEFAULT_TENANT_ID);
child.setPId(DEFAULT_COMMODITY_PARENT_ID);
child.setItemType("service");
child.setItemName("60分钟语音陪聊");
child.setServiceDuration("60min");
child.setEnableStace("1");
child.setSort(1);
commodityInfoService.save(child);
log.info("Inserted API test commodity {}", DEFAULT_COMMODITY_ID);
return child;
}
private void seedCommodityPricing(PlayCommodityInfoEntity commodity) {
if (commodity == null) {
return;
}
PlayCommodityAndLevelInfoEntity existing = commodityAndLevelInfoService.lambdaQuery()
.eq(PlayCommodityAndLevelInfoEntity::getCommodityId, commodity.getId())
.eq(PlayCommodityAndLevelInfoEntity::getLevelId, DEFAULT_CLERK_LEVEL_ID)
.one();
if (existing != null) {
log.info("API test commodity pricing for {} already exists", commodity.getId());
return;
}
PlayCommodityInfoEntity entity = new PlayCommodityInfoEntity();
entity.setId(DEFAULT_COMMODITY_ID);
entity.setTenantId(DEFAULT_TENANT_ID);
entity.setItemType("service");
entity.setItemName("60分钟语音陪聊");
entity.setServiceDuration("60min");
entity.setEnableStace("1");
entity.setSort(1);
commodityInfoService.save(entity);
log.info("Inserted API test commodity {}", DEFAULT_COMMODITY_ID);
PlayCommodityAndLevelInfoEntity price = new PlayCommodityAndLevelInfoEntity();
price.setId(IdUtils.getUuid());
price.setTenantId(DEFAULT_TENANT_ID);
price.setCommodityId(commodity.getId());
price.setLevelId(DEFAULT_CLERK_LEVEL_ID);
price.setPrice(DEFAULT_COMMODITY_PRICE);
price.setSort(1L);
commodityAndLevelInfoService.save(price);
log.info("Inserted API test commodity pricing for {}", commodity.getId());
}
private void seedClerk() {
PlayClerkUserInfoEntity clerk = clerkUserInfoService.getById(DEFAULT_CLERK_ID);
String clerkToken = wxTokenService.createWxUserToken(DEFAULT_CLERK_ID);
if (clerk != null) {
clerkUserInfoService.updateTokenById(DEFAULT_CLERK_ID, clerkToken);
log.info("API test clerk {} already exists", DEFAULT_CLERK_ID);
return;
}
@@ -261,9 +329,11 @@ public class ApiTestDataSeeder implements CommandLineRunner {
entity.setOnboardingState("1");
entity.setListingState("1");
entity.setDisplayState("1");
entity.setOnlineState("1");
entity.setRandomOrderState("1");
entity.setClerkState("1");
entity.setEntryTime(LocalDateTime.now());
entity.setToken(clerkToken);
clerkUserInfoService.save(entity);
log.info("Inserted API test clerk {}", DEFAULT_CLERK_ID);
}
@@ -275,22 +345,64 @@ public class ApiTestDataSeeder implements CommandLineRunner {
return;
}
String commodityName = DEFAULT_COMMODITY_PARENT_NAME;
PlayCommodityInfoEntity parent = commodityInfoService.getById(DEFAULT_COMMODITY_PARENT_ID);
if (parent != null && parent.getItemName() != null) {
commodityName = parent.getItemName();
}
PlayClerkCommodityEntity entity = new PlayClerkCommodityEntity();
entity.setId(DEFAULT_CLERK_COMMODITY_ID);
entity.setTenantId(DEFAULT_TENANT_ID);
entity.setClerkId(DEFAULT_CLERK_ID);
entity.setCommodityId(DEFAULT_COMMODITY_ID);
entity.setCommodityName("60分钟语音陪聊");
entity.setCommodityName(commodityName);
entity.setEnablingState("1");
entity.setSort(1);
clerkCommodityService.save(entity);
log.info("Inserted API test clerk commodity link {}", DEFAULT_CLERK_COMMODITY_ID);
}
private void seedGift() {
PlayGiftInfoEntity gift = giftInfoService.getById(DEFAULT_GIFT_ID);
if (gift != null) {
log.info("API test gift {} already exists", DEFAULT_GIFT_ID);
return;
}
PlayGiftInfoEntity entity = new PlayGiftInfoEntity();
entity.setId(DEFAULT_GIFT_ID);
entity.setTenantId(DEFAULT_TENANT_ID);
entity.setHistory("0");
entity.setName(DEFAULT_GIFT_NAME);
entity.setType(GIFT_TYPE_REGULAR);
entity.setUrl("https://example.com/apitest/gift.png");
entity.setPrice(new BigDecimal("15.00"));
entity.setUnit("CNY");
entity.setState(GIFT_STATE_ACTIVE);
entity.setListingTime(LocalDateTime.now());
entity.setRemark("Seeded gift for API tests");
giftInfoService.save(entity);
log.info("Inserted API test gift {}", DEFAULT_GIFT_ID);
}
private void seedCustomer() {
PlayCustomUserInfoEntity customer = customUserInfoService.getById(DEFAULT_CUSTOMER_ID);
String token = wxTokenService.createWxUserToken(DEFAULT_CUSTOMER_ID);
if (customer != null) {
log.info("API test customer {} already exists", DEFAULT_CUSTOMER_ID);
customUserInfoService.updateTokenById(DEFAULT_CUSTOMER_ID, token);
customUserInfoService.lambdaUpdate()
.set(PlayCustomUserInfoEntity::getAccountBalance, DEFAULT_CUSTOMER_BALANCE)
.set(PlayCustomUserInfoEntity::getAccumulatedRechargeAmount, DEFAULT_CUSTOMER_RECHARGE)
.set(PlayCustomUserInfoEntity::getAccumulatedConsumptionAmount, BigDecimal.ZERO)
.set(PlayCustomUserInfoEntity::getAccountState, "1")
.set(PlayCustomUserInfoEntity::getSubscribeState, "1")
.set(PlayCustomUserInfoEntity::getPurchaseState, "1")
.set(PlayCustomUserInfoEntity::getMobilePhoneState, "1")
.set(PlayCustomUserInfoEntity::getLastLoginTime, new Date())
.eq(PlayCustomUserInfoEntity::getId, DEFAULT_CUSTOMER_ID)
.update();
log.info("API test customer {} already exists, state refreshed", DEFAULT_CUSTOMER_ID);
return;
}
@@ -303,8 +415,8 @@ public class ApiTestDataSeeder implements CommandLineRunner {
entity.setSex(1);
entity.setPhone("13700000002");
entity.setWeiChatCode("apitest-customer");
entity.setAccountBalance(new BigDecimal("200.00"));
entity.setAccumulatedRechargeAmount(new BigDecimal("200.00"));
entity.setAccountBalance(DEFAULT_CUSTOMER_BALANCE);
entity.setAccumulatedRechargeAmount(DEFAULT_CUSTOMER_RECHARGE);
entity.setAccumulatedConsumptionAmount(BigDecimal.ZERO);
entity.setAccountState("1");
entity.setSubscribeState("1");
@@ -312,6 +424,7 @@ public class ApiTestDataSeeder implements CommandLineRunner {
entity.setMobilePhoneState("1");
entity.setRegistrationTime(new Date());
entity.setLastLoginTime(new Date());
entity.setToken(token);
customUserInfoService.save(entity);
log.info("Inserted API test customer {}", DEFAULT_CUSTOMER_ID);
}

View File

@@ -0,0 +1,14 @@
package com.starry.admin.modules.blindbox.config;
import java.time.Clock;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class BlindBoxConfiguration {
@Bean
public Clock systemClock() {
return Clock.systemDefaultZone();
}
}

View File

@@ -46,6 +46,11 @@ public class PlayCommodityInfoEntity extends BaseEntity<PlayCommodityInfoEntity>
*/
private String serviceDuration;
/**
* 接单后自动结算等待时长(单位:秒,-1 表示不自动结算)
*/
private Integer automaticSettlementDuration;
/**
* 启用状态(0:停用,1:启用)
*/