refactor(quotation): 优化方案及方案项保存逻辑

- 合并方案项保存操作,避免重复查询和判断
- 统一设置方案项的创建和更新时间
- 精简对旧方案版本号处理逻辑
- 避免空指针,确保方案存在才更新状态

feat(price-config): 增加价格配置可用标志

- 在价格配置数据中添加“enable”字段,默认设置为true

fix(ratio-agent-config): 修复空字符串过滤问题

- 过滤条件中排除空字符串,避免无效数据处理
This commit is contained in:
曹鹏飞 2026-05-26 08:41:02 +08:00
parent 492f57ebbe
commit 4690d8b2b3
3 changed files with 21 additions and 39 deletions

View File

@ -110,6 +110,8 @@ public class PriceConfigController extends ControllerBase {
map.put(area.getCode(), NumberUtil.format(area.getAmount()));
});
}
//是否可以配置价格
map.put("enable", true);
map.put("children", new ArrayList<>());
data.getChildren().forEach(item -> convert(map, item));
return map;

View File

@ -235,7 +235,7 @@ public class RatioAgentConfigController extends ControllerBase {
data.remove("modelId");
data.remove("modelNo");
data.forEach((key, value) -> {
if (Objects.nonNull(value)) {
if (Objects.nonNull(value) && StrUtil.isNotBlank(value.toString())) {
Integer userId = Integer.parseInt(key.split("-")[0]);
String type = key.split("-")[1];
if ("standardRatio".equals(type) || "optionalRatio".equals(type)) {

View File

@ -338,13 +338,12 @@ public class PlanController extends ControllerBase {
.eq(QuotationUserPlanModel::getCreateByType, AppUserUtil.isAgent() ? 1 : 0)
.eq(QuotationUserPlanModel::getCreateById, AppUserUtil.getUserId())
.one();
List<QuotationUserPlanModelItem> items = Objects.isNull(plan)
? new ArrayList<>()
: planModelItemService.lambdaQuery()
.eq(QuotationUserPlanModelItem::getPlanId, plan.getId())
.list();
List<QuotationUserPlanModelItem> items = new ArrayList<>();
if (Objects.nonNull(plan)) {
QuotationUserPlanModel oldPlan = planModelService.getById(plan.getId());
String version = plan.getVersion().substring(2);
String day = version.split("-")[0];
int index = Integer.parseInt(version.split("-")[1]);
String today = DateTimeUtil.format(LocalDate.now(), "yyMMdd");
planModelService.lambdaUpdate()
.set(QuotationUserPlanModel::getStatus, 2)
.eq(QuotationUserPlanModel::getId, plan.getId())
@ -356,10 +355,6 @@ public class PlanController extends ControllerBase {
.setCreateById(AppUserUtil.getUserId())
.setCreateBy(AppUserUtil.getUserName())
.setCreateTime(LocalDateTime.now());
String version = oldPlan.getVersion().substring(2);
String day = version.split("-")[0];
int index = Integer.parseInt(version.split("-")[1]);
String today = DateTimeUtil.format(LocalDate.now(), "yyMMdd");
if (today.equals(day)) {
plan.setVersion("BP" + day + "-" + StrUtil.padPre(String.valueOf(index + 1), 2, '0'));
} else {
@ -377,34 +372,19 @@ public class PlanController extends ControllerBase {
.setCreateTime(LocalDateTime.now());
planModelService.save(plan);
}
QuotationUserPlanModel finalPlan = plan;
datas.forEach(data -> {
if (Objects.isNull(data.getId())) {
items.add(new QuotationUserPlanModelItem()
.setPlanId(finalPlan.getId())
.setModelId(data.getModelId())
.setName(data.getName())
.setRatio(data.getRatio())
.setAreaId(data.getAreaId())
.setIsDefault(data.getIsDefault())
.setCreateTime(LocalDateTime.now())
);
} else {
QuotationUserPlanModelItem item = items.stream()
.filter(item1 -> item1.getId().equals(data.getId()))
.findFirst()
.orElse(null);
VUtils.trueThrowBusinessError(Objects.isNull(item)).throwMessage("数据不存在:" + data.getId());
item.setPlanId(finalPlan.getId());
item.setName(data.getName());
item.setRatio(data.getRatio());
item.setAreaId(data.getAreaId());
item.setIsDefault(data.getIsDefault());
item.setCreateTime(LocalDateTime.now());
}
});
items.forEach(item -> item.setId(IdUtil.getId()));
planModelItemService.saveBatch(items);
Long planId = plan.getId();
planModelItemService.saveBatch(
datas.stream()
.map(data -> new QuotationUserPlanModelItem()
.setPlanId(planId)
.setName(data.getName())
.setRatio(data.getRatio())
.setModelId(data.getModelId())
.setIsDefault(data.getIsDefault())
.setCreateTime(LocalDateTime.now())
.setUpdateTime(LocalDateTime.now()))
.collect(Collectors.toList())
);
return ApiResult.success();
}