feat(plan): 优化默认系数设置与区域类别处理

- DefaultRatioVO 中添加@NotNull校验,确保比例和区域不能为空
- getDefaultRatio接口支持多区域报价用户,返回对应所有分类的默认比例
- setDefaultRatio接口改为接收多个默认系数列表,批量保存并删除旧数据
- 优化分页查询逻辑,支持多区域时按分类获取销售价格和区域名称
- 将单个类别ID接口改为返回完整DictionaryItem对象,包含ID和名称
- PlanSearchItemVO增加areaName字段,用于展示区域名称信息
This commit is contained in:
曹鹏飞 2026-05-15 17:19:15 +08:00
parent b9db108346
commit dc4e3f04f1
3 changed files with 78 additions and 46 deletions

View File

@ -47,6 +47,11 @@ public class PlanSearchItemVO {
@NotNull(message = "区域不能为空")
private Long areaId;
/**
* 区域名称
*/
private String areaName;
/**
* 是否默认
*/

View File

@ -21,7 +21,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import java.math.BigDecimal;
import java.time.LocalDate;
@ -72,45 +71,71 @@ public class PlanController extends ControllerBase {
*/
@GetMapping("/getDefaultRatio")
public ApiResult<List<DefaultRatioVO>> getDefaultRatio() {
return ApiResult.success(
planDefaultService.lambdaQuery()
List<QuotationUserPlanDefault> datas = planDefaultService.lambdaQuery()
.eq(QuotationUserPlanDefault::getCreateByType, AppUserUtil.isAgent() ? 1 : 0)
.eq(QuotationUserPlanDefault::getCreateById, AppUserUtil.getUserId())
.list()
.list();
if (isMultiRegionQuotationsUser()) {
List<Long> categoryIds = dictionaryItemService.getListByDictionaryCode("DirectSalesCategory")
.stream()
.map(pd -> new DefaultRatioVO()
.setAreaId(pd.getAreaId())
.setRatio(pd.getRatio())
)
.map(DictionaryItem::getId)
.collect(Collectors.toList());
return ApiResult.success(
categoryIds.stream()
.map(categoryId -> {
QuotationUserPlanDefault d = datas.stream()
.filter(pd -> Objects.equals(pd.getAreaId(), categoryId))
.findFirst()
.orElse(null);
if (Objects.isNull(d)) {
return new DefaultRatioVO()
.setAreaId(categoryId);
} else {
return new DefaultRatioVO()
.setRatio(d.getRatio());
}
})
.collect(Collectors.toList())
);
} else {
DictionaryItem category = getCategory();
QuotationUserPlanDefault d = datas.stream()
.filter(pd -> Objects.equals(pd.getAreaId(), category.getId()))
.findFirst()
.orElse(null);
if (Objects.isNull(d)) {
return ApiResult.success(
List.of(new DefaultRatioVO().setAreaId(category.getId()))
);
} else {
return ApiResult.success(
List.of(new DefaultRatioVO().setRatio(d.getRatio()))
);
}
}
}
/**
* 设置方案默认系数
*/
@Transactional
@PostMapping("/setDefaultRatio")
public ApiResult<Void> setDefaultRatio(@RequestParam @Min(1) BigDecimal ratio) {
QuotationUserPlanDefault planDefault = planDefaultService.lambdaQuery()
public ApiResult<Void> setDefaultRatio(@Valid @RequestBody @NotEmpty List<DefaultRatioVO> request) {
planDefaultService.lambdaUpdate()
.eq(QuotationUserPlanDefault::getCreateByType, AppUserUtil.isAgent() ? 1 : 0)
.eq(QuotationUserPlanDefault::getCreateById, AppUserUtil.getUserId())
.one();
if (Objects.isNull(planDefault)) {
planDefaultService.save(
new QuotationUserPlanDefault()
.setRatio(ratio)
.remove();
planDefaultService.saveBatch(
request.stream()
.map(r -> new QuotationUserPlanDefault()
.setRatio(r.getRatio())
.setAreaId(r.getAreaId())
.setCreateByType(AppUserUtil.isAgent() ? 1 : 0)
.setCreateById(AppUserUtil.getUserId())
.setCreateBy(AppUserUtil.getUserName())
.setCreateTime(LocalDateTime.now())
).collect(Collectors.toList())
);
} else {
planDefaultService.lambdaUpdate()
.set(QuotationUserPlanDefault::getRatio, ratio)
.set(QuotationUserPlanDefault::getUpdateTime, LocalDateTime.now())
.eq(QuotationUserPlanDefault::getId, planDefault.getId())
.update();
}
return ApiResult.success();
}
@ -135,25 +160,22 @@ public class PlanController extends ControllerBase {
pageData.setItems(datas);
vo.setDatas(pageData);
boolean multiRegionQuotations = isMultiRegionQuotationsUser();
List<Long> categoryIds = new ArrayList<>();
List<DictionaryItem> categories = new ArrayList<>();
if (multiRegionQuotations) {
categoryIds = dictionaryItemService.getListByDictionaryCode("DirectSalesCategory")
.stream()
.map(DictionaryItem::getId)
.collect(Collectors.toList());
categories = dictionaryItemService.getListByDictionaryCode("DirectSalesCategory");
} else {
categoryIds.add(getCategoryId());
categories.add(getCategory());
}
List<ModelPriceVO> prices = priceService.getAllModelPrice();
Map<Long, List<PlanSearchItemVO>> fgroup = items.stream().collect(Collectors.groupingBy(PlanSearchItemVO::getModelId));
pageData.setTotal(fgroup.size());
for (Map.Entry<Long, List<PlanSearchItemVO>> entry : fgroup.entrySet()) {
if (index >= startIndex && index < endIndex) {
categoryIds.forEach(categoryId -> {
BigDecimal salePrice = getSalePrice(entry.getKey(), categoryId, prices);
categories.forEach(category -> {
BigDecimal salePrice = getSalePrice(entry.getKey(), category.getId(), prices);
List<PlanSearchItemVO> vos = entry.getValue()
.stream()
.filter(pv -> Objects.equals(pv.getAreaId(), categoryId))
.filter(pv -> Objects.equals(pv.getAreaId(), category.getId()))
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(vos)) {
entry.getValue().forEach(item -> {
@ -164,7 +186,8 @@ public class PlanController extends ControllerBase {
.setModelNo(item.getModelNo())
.setName(item.getName())
.setRatio(item.getRatio())
.setAreaId(categoryId)
.setAreaId(category.getId())
.setAreaName(category.getName())
.setStandardPrice(salePrice)
);
});
@ -178,7 +201,8 @@ public class PlanController extends ControllerBase {
.setModelNo(item.getModelNo())
.setName(item.getName())
.setRatio(item.getRatio())
.setAreaId(categoryId)
.setAreaId(category.getId())
.setAreaName(category.getName())
.setStandardPrice(salePrice)
);
});
@ -189,15 +213,15 @@ public class PlanController extends ControllerBase {
return ApiResult.success(vo);
}
private Long getCategoryId() {
private DictionaryItem getCategory() {
if (AppUserUtil.isAgent()) {
DictionaryItem di = appUserService.getCategory(appUserService.getById(AppUserUtil.getUserId()));
VUtils.trueThrowBusinessError(Objects.isNull(di)).throwMessage("请联系管理员设置区域类别");
return di.getId();
return di;
} else {
Long categoryId = adminUserService.getById(AppUserUtil.getUserId()).getCategoryId();
VUtils.trueThrowBusinessError(Objects.isNull(categoryId)).throwMessage("请联系管理员设置区域类别");
return categoryId;
return dictionaryItemService.getById(categoryId);
}
}

View File

@ -3,6 +3,7 @@ package com.nflg.mobilebroken.quotation.pojo.vo;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
@Data
@ -12,10 +13,12 @@ public class DefaultRatioVO {
/**
* 比例
*/
@NotNull(message = "比例不能为空")
private BigDecimal ratio;
/**
* 区域国内/国外字典id
*/
@NotNull(message = "区域不能为空")
private Long areaId;
}