feat(plan): 优化默认系数设置与区域类别处理
- DefaultRatioVO 中添加@NotNull校验,确保比例和区域不能为空 - getDefaultRatio接口支持多区域报价用户,返回对应所有分类的默认比例 - setDefaultRatio接口改为接收多个默认系数列表,批量保存并删除旧数据 - 优化分页查询逻辑,支持多区域时按分类获取销售价格和区域名称 - 将单个类别ID接口改为返回完整DictionaryItem对象,包含ID和名称 - PlanSearchItemVO增加areaName字段,用于展示区域名称信息
This commit is contained in:
parent
b9db108346
commit
dc4e3f04f1
|
|
@ -47,6 +47,11 @@ public class PlanSearchItemVO {
|
||||||
@NotNull(message = "区域不能为空")
|
@NotNull(message = "区域不能为空")
|
||||||
private Long areaId;
|
private Long areaId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 区域名称
|
||||||
|
*/
|
||||||
|
private String areaName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否默认
|
* 是否默认
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.constraints.Min;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
@ -72,45 +71,71 @@ public class PlanController extends ControllerBase {
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getDefaultRatio")
|
@GetMapping("/getDefaultRatio")
|
||||||
public ApiResult<List<DefaultRatioVO>> getDefaultRatio() {
|
public ApiResult<List<DefaultRatioVO>> getDefaultRatio() {
|
||||||
return ApiResult.success(
|
List<QuotationUserPlanDefault> datas = planDefaultService.lambdaQuery()
|
||||||
planDefaultService.lambdaQuery()
|
.eq(QuotationUserPlanDefault::getCreateByType, AppUserUtil.isAgent() ? 1 : 0)
|
||||||
.eq(QuotationUserPlanDefault::getCreateByType, AppUserUtil.isAgent() ? 1 : 0)
|
.eq(QuotationUserPlanDefault::getCreateById, AppUserUtil.getUserId())
|
||||||
.eq(QuotationUserPlanDefault::getCreateById, AppUserUtil.getUserId())
|
.list();
|
||||||
.list()
|
if (isMultiRegionQuotationsUser()) {
|
||||||
.stream()
|
List<Long> categoryIds = dictionaryItemService.getListByDictionaryCode("DirectSalesCategory")
|
||||||
.map(pd -> new DefaultRatioVO()
|
.stream()
|
||||||
.setAreaId(pd.getAreaId())
|
.map(DictionaryItem::getId)
|
||||||
.setRatio(pd.getRatio())
|
.collect(Collectors.toList());
|
||||||
)
|
return ApiResult.success(
|
||||||
.collect(Collectors.toList())
|
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")
|
@PostMapping("/setDefaultRatio")
|
||||||
public ApiResult<Void> setDefaultRatio(@RequestParam @Min(1) BigDecimal ratio) {
|
public ApiResult<Void> setDefaultRatio(@Valid @RequestBody @NotEmpty List<DefaultRatioVO> request) {
|
||||||
QuotationUserPlanDefault planDefault = planDefaultService.lambdaQuery()
|
planDefaultService.lambdaUpdate()
|
||||||
.eq(QuotationUserPlanDefault::getCreateByType, AppUserUtil.isAgent() ? 1 : 0)
|
.eq(QuotationUserPlanDefault::getCreateByType, AppUserUtil.isAgent() ? 1 : 0)
|
||||||
.eq(QuotationUserPlanDefault::getCreateById, AppUserUtil.getUserId())
|
.eq(QuotationUserPlanDefault::getCreateById, AppUserUtil.getUserId())
|
||||||
.one();
|
.remove();
|
||||||
if (Objects.isNull(planDefault)) {
|
planDefaultService.saveBatch(
|
||||||
planDefaultService.save(
|
request.stream()
|
||||||
new QuotationUserPlanDefault()
|
.map(r -> new QuotationUserPlanDefault()
|
||||||
.setRatio(ratio)
|
.setRatio(r.getRatio())
|
||||||
.setCreateByType(AppUserUtil.isAgent() ? 1 : 0)
|
.setAreaId(r.getAreaId())
|
||||||
.setCreateById(AppUserUtil.getUserId())
|
.setCreateByType(AppUserUtil.isAgent() ? 1 : 0)
|
||||||
.setCreateBy(AppUserUtil.getUserName())
|
.setCreateById(AppUserUtil.getUserId())
|
||||||
.setCreateTime(LocalDateTime.now())
|
.setCreateBy(AppUserUtil.getUserName())
|
||||||
);
|
.setCreateTime(LocalDateTime.now())
|
||||||
} else {
|
).collect(Collectors.toList())
|
||||||
planDefaultService.lambdaUpdate()
|
);
|
||||||
.set(QuotationUserPlanDefault::getRatio, ratio)
|
|
||||||
.set(QuotationUserPlanDefault::getUpdateTime, LocalDateTime.now())
|
|
||||||
.eq(QuotationUserPlanDefault::getId, planDefault.getId())
|
|
||||||
.update();
|
|
||||||
}
|
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,25 +160,22 @@ public class PlanController extends ControllerBase {
|
||||||
pageData.setItems(datas);
|
pageData.setItems(datas);
|
||||||
vo.setDatas(pageData);
|
vo.setDatas(pageData);
|
||||||
boolean multiRegionQuotations = isMultiRegionQuotationsUser();
|
boolean multiRegionQuotations = isMultiRegionQuotationsUser();
|
||||||
List<Long> categoryIds = new ArrayList<>();
|
List<DictionaryItem> categories = new ArrayList<>();
|
||||||
if (multiRegionQuotations) {
|
if (multiRegionQuotations) {
|
||||||
categoryIds = dictionaryItemService.getListByDictionaryCode("DirectSalesCategory")
|
categories = dictionaryItemService.getListByDictionaryCode("DirectSalesCategory");
|
||||||
.stream()
|
|
||||||
.map(DictionaryItem::getId)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
} else {
|
} else {
|
||||||
categoryIds.add(getCategoryId());
|
categories.add(getCategory());
|
||||||
}
|
}
|
||||||
List<ModelPriceVO> prices = priceService.getAllModelPrice();
|
List<ModelPriceVO> prices = priceService.getAllModelPrice();
|
||||||
Map<Long, List<PlanSearchItemVO>> fgroup = items.stream().collect(Collectors.groupingBy(PlanSearchItemVO::getModelId));
|
Map<Long, List<PlanSearchItemVO>> fgroup = items.stream().collect(Collectors.groupingBy(PlanSearchItemVO::getModelId));
|
||||||
pageData.setTotal(fgroup.size());
|
pageData.setTotal(fgroup.size());
|
||||||
for (Map.Entry<Long, List<PlanSearchItemVO>> entry : fgroup.entrySet()) {
|
for (Map.Entry<Long, List<PlanSearchItemVO>> entry : fgroup.entrySet()) {
|
||||||
if (index >= startIndex && index < endIndex) {
|
if (index >= startIndex && index < endIndex) {
|
||||||
categoryIds.forEach(categoryId -> {
|
categories.forEach(category -> {
|
||||||
BigDecimal salePrice = getSalePrice(entry.getKey(), categoryId, prices);
|
BigDecimal salePrice = getSalePrice(entry.getKey(), category.getId(), prices);
|
||||||
List<PlanSearchItemVO> vos = entry.getValue()
|
List<PlanSearchItemVO> vos = entry.getValue()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(pv -> Objects.equals(pv.getAreaId(), categoryId))
|
.filter(pv -> Objects.equals(pv.getAreaId(), category.getId()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (CollectionUtil.isEmpty(vos)) {
|
if (CollectionUtil.isEmpty(vos)) {
|
||||||
entry.getValue().forEach(item -> {
|
entry.getValue().forEach(item -> {
|
||||||
|
|
@ -164,7 +186,8 @@ public class PlanController extends ControllerBase {
|
||||||
.setModelNo(item.getModelNo())
|
.setModelNo(item.getModelNo())
|
||||||
.setName(item.getName())
|
.setName(item.getName())
|
||||||
.setRatio(item.getRatio())
|
.setRatio(item.getRatio())
|
||||||
.setAreaId(categoryId)
|
.setAreaId(category.getId())
|
||||||
|
.setAreaName(category.getName())
|
||||||
.setStandardPrice(salePrice)
|
.setStandardPrice(salePrice)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -178,7 +201,8 @@ public class PlanController extends ControllerBase {
|
||||||
.setModelNo(item.getModelNo())
|
.setModelNo(item.getModelNo())
|
||||||
.setName(item.getName())
|
.setName(item.getName())
|
||||||
.setRatio(item.getRatio())
|
.setRatio(item.getRatio())
|
||||||
.setAreaId(categoryId)
|
.setAreaId(category.getId())
|
||||||
|
.setAreaName(category.getName())
|
||||||
.setStandardPrice(salePrice)
|
.setStandardPrice(salePrice)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -189,15 +213,15 @@ public class PlanController extends ControllerBase {
|
||||||
return ApiResult.success(vo);
|
return ApiResult.success(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Long getCategoryId() {
|
private DictionaryItem getCategory() {
|
||||||
if (AppUserUtil.isAgent()) {
|
if (AppUserUtil.isAgent()) {
|
||||||
DictionaryItem di = appUserService.getCategory(appUserService.getById(AppUserUtil.getUserId()));
|
DictionaryItem di = appUserService.getCategory(appUserService.getById(AppUserUtil.getUserId()));
|
||||||
VUtils.trueThrowBusinessError(Objects.isNull(di)).throwMessage("请联系管理员设置区域类别");
|
VUtils.trueThrowBusinessError(Objects.isNull(di)).throwMessage("请联系管理员设置区域类别");
|
||||||
return di.getId();
|
return di;
|
||||||
} else {
|
} else {
|
||||||
Long categoryId = adminUserService.getById(AppUserUtil.getUserId()).getCategoryId();
|
Long categoryId = adminUserService.getById(AppUserUtil.getUserId()).getCategoryId();
|
||||||
VUtils.trueThrowBusinessError(Objects.isNull(categoryId)).throwMessage("请联系管理员设置区域类别");
|
VUtils.trueThrowBusinessError(Objects.isNull(categoryId)).throwMessage("请联系管理员设置区域类别");
|
||||||
return categoryId;
|
return dictionaryItemService.getById(categoryId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.nflg.mobilebroken.quotation.pojo.vo;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
|
@ -12,10 +13,12 @@ public class DefaultRatioVO {
|
||||||
/**
|
/**
|
||||||
* 比例
|
* 比例
|
||||||
*/
|
*/
|
||||||
|
@NotNull(message = "比例不能为空")
|
||||||
private BigDecimal ratio;
|
private BigDecimal ratio;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 区域(国内/国外),字典id
|
* 区域(国内/国外),字典id
|
||||||
*/
|
*/
|
||||||
|
@NotNull(message = "区域不能为空")
|
||||||
private Long areaId;
|
private Long areaId;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue