fix: ignore null level prices when updating commodity
This commit is contained in:
@@ -109,9 +109,13 @@ public class PlayCommodityInfoController {
|
|||||||
if (!jsonObject.containsKey(playClerkLevelInfoEntity.getId())) {
|
if (!jsonObject.containsKey(playClerkLevelInfoEntity.getId())) {
|
||||||
throw new CustomException("请求参数错误");
|
throw new CustomException("请求参数错误");
|
||||||
}
|
}
|
||||||
|
String rawPrice = jsonObject.getString(playClerkLevelInfoEntity.getId());
|
||||||
|
if (rawPrice == null || rawPrice.trim().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
double price = 0.0;
|
double price = 0.0;
|
||||||
try {
|
try {
|
||||||
price = Double.parseDouble(jsonObject.getString(playClerkLevelInfoEntity.getId()));
|
price = Double.parseDouble(rawPrice);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
throw new CustomException("请求参数错误,价格格式为空");
|
throw new CustomException("请求参数错误,价格格式为空");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,6 +221,39 @@ class PlayCommodityInfoApiTest extends WxCustomOrderApiTestSupport {
|
|||||||
assertThat(pricing.getPrice()).isEqualByComparingTo(new BigDecimal("188.50"));
|
assertThat(pricing.getPrice()).isEqualByComparingTo(new BigDecimal("188.50"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// 测试用例:调用价格更新接口时若某个等级价格传入null,接口应忽略该列并保持原价,确保支持分步维护价格。
|
||||||
|
void updateInfoSkipsNullLevelPrices() throws Exception {
|
||||||
|
ensureTenantContext();
|
||||||
|
PlayCommodityAndLevelInfoEntity before = commodityAndLevelInfoService.lambdaQuery()
|
||||||
|
.eq(PlayCommodityAndLevelInfoEntity::getCommodityId, ApiTestDataSeeder.DEFAULT_COMMODITY_ID)
|
||||||
|
.eq(PlayCommodityAndLevelInfoEntity::getLevelId, ApiTestDataSeeder.DEFAULT_CLERK_LEVEL_ID)
|
||||||
|
.one();
|
||||||
|
|
||||||
|
assertThat(before).as("种子数据应具备默认等级价格").isNotNull();
|
||||||
|
|
||||||
|
ObjectNode payload = objectMapper.createObjectNode();
|
||||||
|
payload.put("id", ApiTestDataSeeder.DEFAULT_COMMODITY_ID);
|
||||||
|
payload.putNull(ApiTestDataSeeder.DEFAULT_CLERK_LEVEL_ID);
|
||||||
|
|
||||||
|
mockMvc.perform(post("/shop/commodity/updateInfo")
|
||||||
|
.header(USER_HEADER, DEFAULT_USER)
|
||||||
|
.header(TENANT_HEADER, DEFAULT_TENANT)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content(payload.toString()))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.code").value(200));
|
||||||
|
|
||||||
|
ensureTenantContext();
|
||||||
|
PlayCommodityAndLevelInfoEntity after = commodityAndLevelInfoService.lambdaQuery()
|
||||||
|
.eq(PlayCommodityAndLevelInfoEntity::getCommodityId, ApiTestDataSeeder.DEFAULT_COMMODITY_ID)
|
||||||
|
.eq(PlayCommodityAndLevelInfoEntity::getLevelId, ApiTestDataSeeder.DEFAULT_CLERK_LEVEL_ID)
|
||||||
|
.one();
|
||||||
|
|
||||||
|
assertThat(after).isNotNull();
|
||||||
|
assertThat(after.getPrice()).as("空价格不应覆盖原值").isEqualByComparingTo(before.getPrice());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
// 测试用例:使用商品修改接口把自动结算等待时长从不限时(-1)调整为10分钟,验证更新后查询返回新的配置。
|
// 测试用例:使用商品修改接口把自动结算等待时长从不限时(-1)调整为10分钟,验证更新后查询返回新的配置。
|
||||||
void updateEndpointSwitchesAutomaticSettlement() throws Exception {
|
void updateEndpointSwitchesAutomaticSettlement() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user