From c75c4456e2209d7161899532964ce1dafbc2bd69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Mon, 9 Mar 2026 10:39:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(quotation):=20=E6=96=B0=E5=A2=9E=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=8A=A5=E4=BB=B7=E9=85=8D=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在IQuotationModelRatioDirectService中添加getEffectiveByUser方法 - 为ProductModelController的add方法添加批次号生成 - 优化ProductModelParamsItem查询条件的格式 - 重构QuotationModelRatioDirectServiceImpl实现getEffectiveByUser方法 - 为RatioAgentConfigController中的项目添加IsPrimary字段设置 - 新增TargetUserVO和TargetUserItemVO数据传输对象 - 实现getTargetUsers接口返回报价对象列表 - 优化RatioConfigController中的搜索逻辑和数据绑定 - 更新RatioDirectConfigController使用新的查询方法 - 简化adminUserService的批量查询方式 --- .../controller/ProductModelController.java | 5 +- .../admin/RatioAgentConfigController.java | 3 +- .../admin/RatioConfigController.java | 203 +++++++++++++++--- .../admin/RatioDirectConfigController.java | 11 +- .../quotation/pojo/vo/TargetUserItemVO.java | 24 +++ .../quotation/pojo/vo/TargetUserVO.java | 13 ++ .../IQuotationModelRatioDirectService.java | 2 + .../service/impl/ProductModelServiceImpl.java | 1 - .../QuotationModelRatioDirectServiceImpl.java | 8 + 9 files changed, 234 insertions(+), 36 deletions(-) create mode 100644 nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/pojo/vo/TargetUserItemVO.java create mode 100644 nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/pojo/vo/TargetUserVO.java diff --git a/nflg-mobilebroken-admin/src/main/java/com/nflg/mobilebroken/admin/controller/ProductModelController.java b/nflg-mobilebroken-admin/src/main/java/com/nflg/mobilebroken/admin/controller/ProductModelController.java index 75d66ce4..91fcf58b 100644 --- a/nflg-mobilebroken-admin/src/main/java/com/nflg/mobilebroken/admin/controller/ProductModelController.java +++ b/nflg-mobilebroken-admin/src/main/java/com/nflg/mobilebroken/admin/controller/ProductModelController.java @@ -84,6 +84,7 @@ public class ProductModelController extends ControllerBase { */ @PostMapping("/add") public ApiResult add(@Valid @RequestBody ProductModelAddRequest request) { + request.setBatchNumber(IdUtil.getSnowflakeNextId()); return ApiResult.success(productModelService.add(request)); } @@ -389,7 +390,7 @@ public class ProductModelController extends ControllerBase { VUtils.trueThrowBusinessError(Objects.isNull(info)).throwMessage("无效的数据"); VUtils.trueThrowBusinessError(StrUtil.equals(request.getLanguageCode(), Constant.DEFAULT_LANGUAGE_CODE) && productModelParamsItemService.lambdaQuery() - .ne(ProductModelParamsItem::getId,request.getModelParamsItemId()) + .ne(ProductModelParamsItem::getId, request.getModelParamsItemId()) .eq(ProductModelParamsItem::getModelParamsId, request.getModelParamsId()) .eq(ProductModelParamsItem::getLanguageCode, Constant.DEFAULT_LANGUAGE_CODE) .eq(ProductModelParamsItem::getIndexName, request.getIndexName()) @@ -658,7 +659,7 @@ public class ProductModelController extends ControllerBase { , @Valid @RequestParam(value = "file") @NotNull MultipartFile file) { ProductModel model = productModelService.getById(modelId); VUtils.trueThrowBusinessError(Objects.isNull(model)).throwMessage("无效的" + modelId); - List repeats=new ArrayList<>(); + List repeats = new ArrayList<>(); try (InputStream inputStream = file.getInputStream(); org.apache.poi.ss.usermodel.Workbook workbook = new XSSFWorkbook(inputStream)) { Sheet sheet = workbook.getSheetAt(0); String no = StrUtil.trim(sheet.getRow(1).getCell(1).getStringCellValue()); diff --git a/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/controller/admin/RatioAgentConfigController.java b/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/controller/admin/RatioAgentConfigController.java index d3ffa352..0287bb7f 100644 --- a/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/controller/admin/RatioAgentConfigController.java +++ b/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/controller/admin/RatioAgentConfigController.java @@ -247,7 +247,8 @@ public class RatioAgentConfigController extends ControllerBase { if (Objects.isNull(item)) { item = new QuotationModelRatioAgentItem() .setModelId(modelId) - .setUserId(userId); + .setUserId(userId) + .setIsPrimary(true); items.add(item); } if ("standardRatio".equals(type)) { diff --git a/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/controller/admin/RatioConfigController.java b/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/controller/admin/RatioConfigController.java index 041e1b98..994bedcb 100644 --- a/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/controller/admin/RatioConfigController.java +++ b/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/controller/admin/RatioConfigController.java @@ -16,12 +16,11 @@ import com.nflg.mobilebroken.common.util.NumberUtil; import com.nflg.mobilebroken.common.util.VUtils; import com.nflg.mobilebroken.quotation.controller.ControllerBase; import com.nflg.mobilebroken.quotation.pojo.vo.RatioConfigSearchVO; +import com.nflg.mobilebroken.quotation.pojo.vo.TargetUserItemVO; +import com.nflg.mobilebroken.quotation.pojo.vo.TargetUserVO; import com.nflg.mobilebroken.repository.entity.*; import com.nflg.mobilebroken.repository.service.*; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; @@ -63,6 +62,44 @@ public class RatioConfigController extends ControllerBase { @Resource private IAdminUserService adminUserService; + /** + * 获取报价对象 + */ + @GetMapping("/getTargetUsers") + public ApiResult getTargetUsers() { + boolean isMarketingDirector = AdminUserUtil.getRoles().contains(Constant.ROLE_CODE_MARKETING_DIRECTOR); + TargetUserVO vo = new TargetUserVO(); + if (isMarketingDirector) { + List agentItems = ratioAgentItemService.getEffectives(); + vo.setAppUsers( + appUserService.lambdaQuery() + .in(AppUser::getId, agentItems.stream().map(QuotationModelRatioAgentItemDTO::getUserId).collect(Collectors.toList())) + .list() + .stream() + .map(u -> new TargetUserItemVO() + .setUserType(1) + .setUserId(u.getId()) + .setUserName(u.getName()) + ) + .collect(Collectors.toList()) + ); + List directItems = ratioDirectItemService.getEffectives(); + vo.setAdminUsers( + adminUserService.lambdaQuery() + .in(AdminUser::getId, directItems.stream().map(QuotationModelRatioDirectItemDTO::getUserId).collect(Collectors.toList())) + .list() + .stream() + .map(u -> new TargetUserItemVO() + .setUserType(0) + .setUserId(u.getId()) + .setUserName(u.getUserName()) + ) + .collect(Collectors.toList()) + ); + } + return ApiResult.success(vo); + } + /** * 搜索 */ @@ -258,8 +295,15 @@ public class RatioConfigController extends ControllerBase { .orElse("") ); vos.add(vo); - RatioConfigSearchVO voc = new RatioConfigSearchVO().setName("直销"); - vo.getChildren().add(voc); + RatioConfigSearchVO vop; + if (isMarketingDirector) { + RatioConfigSearchVO voc = new RatioConfigSearchVO().setName("直销"); + vo.getChildren().add(voc); + vop = voc; + } else { + vop = vo; + } + //TODO 添加方案 QuotationModelRatioDirectItemDTO dto = entry.getValue().stream() .filter(item -> item.getUserId().equals(request.getUserId())) .findFirst() @@ -268,17 +312,17 @@ public class RatioConfigController extends ControllerBase { .filter(u -> u.getId().equals(dto.getUserId())) .findFirst() .get(); - QuotationModelRatioDirectItemDTO pdto=directItems.stream() + QuotationModelRatioDirectItemDTO pdto = directItems.stream() .filter(item -> item.getUserId().equals(dto.getParentId()) - && Objects.equals(item.getModelId(),dto.getModelId())) + && Objects.equals(item.getModelId(), dto.getModelId())) .findFirst() .orElse(null); - if (Objects.nonNull(pdto)){ + if (Objects.nonNull(pdto)) { AdminUser puser = adminUsers.stream() .filter(u -> u.getId().equals(pdto.getUserId())) .findFirst() .orElse(null); - if (Objects.nonNull(puser)){ + if (Objects.nonNull(puser)) { ModelPriceVO modelPrice = prices.stream() .filter(it -> it.getModelId().equals(pdto.getModelId()) && it.getAreaId().equals(puser.getCategoryId())) @@ -289,30 +333,137 @@ public class RatioConfigController extends ControllerBase { .setStandardPrice(modelPrice.getAmount()) .setStandardRatio(NumberUtil.format(pdto.getStandardRatio())) .setOptionalRatio(NumberUtil.format(pdto.getOptionalRatio())); - voc.getChildren().add(vocp); + vop.getChildren().add(vocp); RatioConfigSearchVO vocc = new RatioConfigSearchVO() .setName(cuser.getUserName()) .setStandardPrice(vocp.getSalePrice()) .setStandardRatio(NumberUtil.format(dto.getStandardRatio())) .setOptionalRatio(NumberUtil.format(dto.getOptionalRatio())); vocp.getChildren().add(vocc); - }else { - ModelPriceVO modelPrice = prices.stream() - .filter(it -> it.getModelId().equals(dto.getModelId()) - && it.getAreaId().equals(cuser.getCategoryId())) - .findFirst() - .orElse(null); - RatioConfigSearchVO vocc = new RatioConfigSearchVO() - .setName(cuser.getUserName()) - .setStandardPrice(modelPrice.getAmount()) - .setStandardRatio(NumberUtil.format(dto.getStandardRatio())) - .setOptionalRatio(NumberUtil.format(dto.getOptionalRatio())); - voc.getChildren().add(vocc); } + } else { + ModelPriceVO modelPrice = prices.stream() + .filter(it -> it.getModelId().equals(dto.getModelId()) + && it.getAreaId().equals(cuser.getCategoryId())) + .findFirst() + .orElse(null); + RatioConfigSearchVO vocc = new RatioConfigSearchVO() + .setName(cuser.getUserName()) + .setStandardPrice(modelPrice.getAmount()) + .setStandardRatio(NumberUtil.format(dto.getStandardRatio())) + .setOptionalRatio(NumberUtil.format(dto.getOptionalRatio())); + vop.getChildren().add(vocc); } } index++; } + } else if (request.getUserType() == 1) { + List agentItems = ratioAgentItemService.getEffectives(); + List afilterItems = agentItems.stream() + .filter(item -> item.getUserId().equals(request.getUserId())) + .collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(filterItems)) { + List prices = priceService.getAllModelPrice(); + List models = productModelService.getEffectives(); + Map> fgroup = afilterItems.stream() + .collect(Collectors.groupingBy(QuotationModelRatioAgentItemDTO::getModelId)); + pageData.setTotal(fgroup.keySet().size()); + List appUsers = appUserService.lambdaQuery() + .in(AppUser::getId, agentItems.stream().map(QuotationModelRatioAgentItemDTO::getUserId).collect(Collectors.toList())) + .list(); + List customers = customerService.lambdaQuery() + .select(TBaseCustomer::getId, TBaseCustomer::getCategoryId) + .eq(TBaseCustomer::getDelIs, 0) + .eq(TBaseCustomer::getEnableState, 1) + .list(); + int index = 0, startIndex = (request.getPage() - 1) * request.getPageSize(), endIndex = request.getPage() * request.getPageSize(); + for (Map.Entry> entry : fgroup.entrySet()) { + if (index >= startIndex && index < endIndex) { + RatioConfigSearchVO vo = new RatioConfigSearchVO() + .setModelNo(models.stream() + .filter(m -> m.getBatchNumber().equals(entry.getKey())) + .findFirst() + .map(ProductModel::getNo) + .orElse("") + ); + vos.add(vo); + RatioConfigSearchVO vop; + if (isMarketingDirector) { + RatioConfigSearchVO voc = new RatioConfigSearchVO().setName("代理商"); + vo.getChildren().add(voc); + vop = voc; + } else { + vop = vo; + } + //TODO 添加方案 + QuotationModelRatioAgentItemDTO dto = entry.getValue().stream() + .filter(item -> item.getUserId().equals(request.getUserId())) + .findFirst() + .get(); + AppUser cuser = appUsers.stream() + .filter(u -> u.getId().equals(dto.getUserId())) + .findFirst() + .get(); + if (!cuser.getIsPrimary()) { + QuotationModelRatioAgentItemDTO pdto = agentItems.stream() + .filter(item -> item.getUserId().equals(dto.getParentId()) + && Objects.equals(item.getModelId(), dto.getModelId())) + .findFirst() + .orElse(null); + if (Objects.nonNull(pdto)) { + AppUser puser = appUsers.stream() + .filter(u -> u.getId().equals(pdto.getUserId())) + .findFirst() + .orElse(null); + if (Objects.nonNull(puser)) { + TBaseCustomer customer = customers.stream() + .filter(cit -> StrUtil.split(puser.getCompanyId(), ',').contains(cit.getId().toString())) + .findFirst() + .orElse(null); + if (Objects.nonNull(customer)) { + ModelPriceVO modelPrice = prices.stream() + .filter(it -> it.getModelId().equals(pdto.getModelId()) + && it.getAreaId().equals(customer.getCategoryId())) + .findFirst() + .orElse(null); + RatioConfigSearchVO vocp = new RatioConfigSearchVO() + .setName(puser.getName()) + .setStandardPrice(modelPrice.getAmount()) + .setStandardRatio(NumberUtil.format(pdto.getStandardRatio())) + .setOptionalRatio(NumberUtil.format(pdto.getOptionalRatio())); + vop.getChildren().add(vocp); + RatioConfigSearchVO vocc = new RatioConfigSearchVO() + .setName(cuser.getName()) + .setStandardPrice(vocp.getSalePrice()) + .setStandardRatio(NumberUtil.format(dto.getStandardRatio())) + .setOptionalRatio(NumberUtil.format(dto.getOptionalRatio())); + vocp.getChildren().add(vocc); + } + } + } + } else { + TBaseCustomer customer = customers.stream() + .filter(cit -> StrUtil.split(cuser.getCompanyId(), ',').contains(cit.getId().toString())) + .findFirst() + .orElse(null); + if (Objects.nonNull(customer)) { + ModelPriceVO modelPrice = prices.stream() + .filter(it -> it.getModelId().equals(dto.getModelId()) + && it.getAreaId().equals(customer.getCategoryId())) + .findFirst() + .orElse(null); + RatioConfigSearchVO vocc = new RatioConfigSearchVO() + .setName(cuser.getName()) + .setStandardPrice(modelPrice.getAmount()) + .setStandardRatio(NumberUtil.format(dto.getStandardRatio())) + .setOptionalRatio(NumberUtil.format(dto.getOptionalRatio())); + vop.getChildren().add(vocc); + } + } + } + index++; + } + } } } return ApiResult.success(pageData); @@ -344,7 +495,8 @@ public class RatioConfigController extends ControllerBase { return BigDecimal.ZERO; } - private void bindAgentChild(List children, RatioConfigSearchVO vo, List users) { + private void bindAgentChild(List children, RatioConfigSearchVO + vo, List users) { children.forEach(child -> { AppUser user = users.stream() .filter(u -> u.getId().equals(child.getUserId())) @@ -363,7 +515,8 @@ public class RatioConfigController extends ControllerBase { }); } - private void bindDirectChild(List children, RatioConfigSearchVO vo, List users) { + private void bindDirectChild(List children, RatioConfigSearchVO + vo, List users) { children.forEach(child -> { AdminUser user = users.stream() .filter(u -> u.getId().equals(child.getUserId())) diff --git a/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/controller/admin/RatioDirectConfigController.java b/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/controller/admin/RatioDirectConfigController.java index 698901c2..9c6e94f0 100644 --- a/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/controller/admin/RatioDirectConfigController.java +++ b/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/controller/admin/RatioDirectConfigController.java @@ -153,9 +153,7 @@ public class RatioDirectConfigController extends ControllerBase { public ApiResult search(@Valid @RequestBody ModelRatioDirectUserSearchRequest request) { Long departmentId = AdminUserUtil.getDepartmentId(); VUtils.trueThrowBusinessError(Objects.isNull(departmentId)).throwMessage("未设置部门,请联系管理员"); - QuotationModelRatioDirect ratioAgent = ratioDirectService.lambdaQuery() - .eq(QuotationModelRatioDirect::getStatus, 1) - .one(); + QuotationModelRatioDirect ratioAgent = ratioDirectService.getEffectiveByUser(AdminUserUtil.getUserId()); RatioAgentSearchVO vo = new RatioAgentSearchVO(); if (Objects.nonNull(ratioAgent)) { vo.setInfo(Convert.convert(QuotationModelRatioVO.class, ratioAgent)); @@ -170,10 +168,9 @@ public class RatioDirectConfigController extends ControllerBase { List departments = departmentService.getChildByParentId(departmentId); users = adminUserService.getByDepartmentIds(departments.stream().map(TBaseDepartment::getId).collect(Collectors.toList())); } else { - users = adminUserService.lambdaQuery() - .in(AdminUser::getId, CollectionUtil.union(request.getUserIds() - , items.stream().map(QuotationModelRatioDirectItem::getUserId).collect(Collectors.toSet()))) - .list(); + users = adminUserService.listByIds(CollectionUtil.union(request.getUserIds() + , items.stream().map(QuotationModelRatioDirectItem::getUserId).collect(Collectors.toSet())) + ); } boolean isMarketingDirector = AdminUserUtil.getRoles().contains(Constant.ROLE_CODE_MARKETING_DIRECTOR); List categories = dictionaryItemService.getListByDictionaryCode(Constant.DICTIONARY_DIRECT_SALES_CATEGORY); diff --git a/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/pojo/vo/TargetUserItemVO.java b/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/pojo/vo/TargetUserItemVO.java new file mode 100644 index 00000000..42698765 --- /dev/null +++ b/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/pojo/vo/TargetUserItemVO.java @@ -0,0 +1,24 @@ +package com.nflg.mobilebroken.quotation.pojo.vo; + +import lombok.Data; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +public class TargetUserItemVO { + + /** + * 用户类型:0-系统用户;1-代理商 + */ + private Integer userType; + + /** + * 用户ID + */ + private Integer userId; + + /** + * 用户名称 + */ + private String userName; +} \ No newline at end of file diff --git a/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/pojo/vo/TargetUserVO.java b/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/pojo/vo/TargetUserVO.java new file mode 100644 index 00000000..da46ca7a --- /dev/null +++ b/nflg-mobilebroken-quotation/src/main/java/com/nflg/mobilebroken/quotation/pojo/vo/TargetUserVO.java @@ -0,0 +1,13 @@ +package com.nflg.mobilebroken.quotation.pojo.vo; + +import lombok.Data; + +import java.util.List; + +@Data +public class TargetUserVO { + + private List appUsers; + + private List adminUsers; +} diff --git a/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/IQuotationModelRatioDirectService.java b/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/IQuotationModelRatioDirectService.java index 5b6aa918..591ad607 100644 --- a/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/IQuotationModelRatioDirectService.java +++ b/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/IQuotationModelRatioDirectService.java @@ -17,4 +17,6 @@ import java.util.List; public interface IQuotationModelRatioDirectService extends IService { List getEffectives(); + + QuotationModelRatioDirect getEffectiveByUser(Integer userId); } diff --git a/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/impl/ProductModelServiceImpl.java b/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/impl/ProductModelServiceImpl.java index 9b89992e..70d9af1a 100644 --- a/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/impl/ProductModelServiceImpl.java +++ b/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/impl/ProductModelServiceImpl.java @@ -1,7 +1,6 @@ package com.nflg.mobilebroken.repository.service.impl; import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; diff --git a/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/impl/QuotationModelRatioDirectServiceImpl.java b/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/impl/QuotationModelRatioDirectServiceImpl.java index ac0595f0..198822e5 100644 --- a/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/impl/QuotationModelRatioDirectServiceImpl.java +++ b/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/impl/QuotationModelRatioDirectServiceImpl.java @@ -24,4 +24,12 @@ public class QuotationModelRatioDirectServiceImpl extends ServiceImpl getEffectives() { return baseMapper.getEffectives(); } + + @Override + public QuotationModelRatioDirect getEffectiveByUser(Integer userId) { + return lambdaQuery() + .eq(QuotationModelRatioDirect::getStatus, 1) + .eq(QuotationModelRatioDirect::getCreateById, userId) + .one(); + } }