diff --git a/nflg-mobilebroken-common/src/main/java/com/nflg/mobilebroken/common/pojo/vo/PlanSearchItemVO.java b/nflg-mobilebroken-common/src/main/java/com/nflg/mobilebroken/common/pojo/vo/PlanSearchItemVO.java index acf626f7..756d7792 100644 --- a/nflg-mobilebroken-common/src/main/java/com/nflg/mobilebroken/common/pojo/vo/PlanSearchItemVO.java +++ b/nflg-mobilebroken-common/src/main/java/com/nflg/mobilebroken/common/pojo/vo/PlanSearchItemVO.java @@ -47,6 +47,11 @@ public class PlanSearchItemVO { @NotNull(message = "区域不能为空") private Long areaId; + /** + * 区域名称 + */ + private String areaName; + /** * 是否默认 */ diff --git a/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/controller/app/PlanController.java b/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/controller/app/PlanController.java index f3d6ed34..aa135275 100644 --- a/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/controller/app/PlanController.java +++ b/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/controller/app/PlanController.java @@ -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> getDefaultRatio() { - return ApiResult.success( - planDefaultService.lambdaQuery() - .eq(QuotationUserPlanDefault::getCreateByType, AppUserUtil.isAgent() ? 1 : 0) - .eq(QuotationUserPlanDefault::getCreateById, AppUserUtil.getUserId()) - .list() - .stream() - .map(pd -> new DefaultRatioVO() - .setAreaId(pd.getAreaId()) - .setRatio(pd.getRatio()) - ) - .collect(Collectors.toList()) - ); + List datas = planDefaultService.lambdaQuery() + .eq(QuotationUserPlanDefault::getCreateByType, AppUserUtil.isAgent() ? 1 : 0) + .eq(QuotationUserPlanDefault::getCreateById, AppUserUtil.getUserId()) + .list(); + if (isMultiRegionQuotationsUser()) { + List categoryIds = dictionaryItemService.getListByDictionaryCode("DirectSalesCategory") + .stream() + .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 setDefaultRatio(@RequestParam @Min(1) BigDecimal ratio) { - QuotationUserPlanDefault planDefault = planDefaultService.lambdaQuery() + public ApiResult setDefaultRatio(@Valid @RequestBody @NotEmpty List 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) - .setCreateByType(AppUserUtil.isAgent() ? 1 : 0) - .setCreateById(AppUserUtil.getUserId()) - .setCreateBy(AppUserUtil.getUserName()) - .setCreateTime(LocalDateTime.now()) - ); - } else { - planDefaultService.lambdaUpdate() - .set(QuotationUserPlanDefault::getRatio, ratio) - .set(QuotationUserPlanDefault::getUpdateTime, LocalDateTime.now()) - .eq(QuotationUserPlanDefault::getId, planDefault.getId()) - .update(); - } + .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()) + ); return ApiResult.success(); } @@ -135,25 +160,22 @@ public class PlanController extends ControllerBase { pageData.setItems(datas); vo.setDatas(pageData); boolean multiRegionQuotations = isMultiRegionQuotationsUser(); - List categoryIds = new ArrayList<>(); + List 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 prices = priceService.getAllModelPrice(); Map> fgroup = items.stream().collect(Collectors.groupingBy(PlanSearchItemVO::getModelId)); pageData.setTotal(fgroup.size()); for (Map.Entry> 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 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); } } diff --git a/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/pojo/vo/DefaultRatioVO.java b/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/pojo/vo/DefaultRatioVO.java index 091390d3..9c49d555 100644 --- a/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/pojo/vo/DefaultRatioVO.java +++ b/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/pojo/vo/DefaultRatioVO.java @@ -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; }