fix: ignore null level prices when updating commodity

This commit is contained in:
irving
2025-11-08 20:06:15 -05:00
parent eaee5f5aa6
commit 438aef7af7
2 changed files with 38 additions and 1 deletions

View File

@@ -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("请求参数错误,价格格式为空");
} }

View File

@@ -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 {