feat(quotation): 新增用户报价配置功能
- 在IQuotationModelRatioDirectService中添加getEffectiveByUser方法 - 为ProductModelController的add方法添加批次号生成 - 优化ProductModelParamsItem查询条件的格式 - 重构QuotationModelRatioDirectServiceImpl实现getEffectiveByUser方法 - 为RatioAgentConfigController中的项目添加IsPrimary字段设置 - 新增TargetUserVO和TargetUserItemVO数据传输对象 - 实现getTargetUsers接口返回报价对象列表 - 优化RatioConfigController中的搜索逻辑和数据绑定 - 更新RatioDirectConfigController使用新的查询方法 - 简化adminUserService的批量查询方式
This commit is contained in:
parent
d17bb88a4b
commit
c75c4456e2
|
|
@ -84,6 +84,7 @@ public class ProductModelController extends ControllerBase {
|
|||
*/
|
||||
@PostMapping("/add")
|
||||
public ApiResult<Integer> add(@Valid @RequestBody ProductModelAddRequest request) {
|
||||
request.setBatchNumber(IdUtil.getSnowflakeNextId());
|
||||
return ApiResult.success(productModelService.add(request));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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<TargetUserVO> getTargetUsers() {
|
||||
boolean isMarketingDirector = AdminUserUtil.getRoles().contains(Constant.ROLE_CODE_MARKETING_DIRECTOR);
|
||||
TargetUserVO vo = new TargetUserVO();
|
||||
if (isMarketingDirector) {
|
||||
List<QuotationModelRatioAgentItemDTO> 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<QuotationModelRatioDirectItemDTO> 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 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()
|
||||
|
|
@ -289,13 +333,14 @@ 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())
|
||||
|
|
@ -307,7 +352,112 @@ public class RatioConfigController extends ControllerBase {
|
|||
.setStandardPrice(modelPrice.getAmount())
|
||||
.setStandardRatio(NumberUtil.format(dto.getStandardRatio()))
|
||||
.setOptionalRatio(NumberUtil.format(dto.getOptionalRatio()));
|
||||
voc.getChildren().add(vocc);
|
||||
vop.getChildren().add(vocc);
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
} else if (request.getUserType() == 1) {
|
||||
List<QuotationModelRatioAgentItemDTO> agentItems = ratioAgentItemService.getEffectives();
|
||||
List<QuotationModelRatioAgentItemDTO> afilterItems = agentItems.stream()
|
||||
.filter(item -> item.getUserId().equals(request.getUserId()))
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(filterItems)) {
|
||||
List<ModelPriceVO> prices = priceService.getAllModelPrice();
|
||||
List<ProductModel> models = productModelService.getEffectives();
|
||||
Map<Long, List<QuotationModelRatioAgentItemDTO>> fgroup = afilterItems.stream()
|
||||
.collect(Collectors.groupingBy(QuotationModelRatioAgentItemDTO::getModelId));
|
||||
pageData.setTotal(fgroup.keySet().size());
|
||||
List<AppUser> appUsers = appUserService.lambdaQuery()
|
||||
.in(AppUser::getId, agentItems.stream().map(QuotationModelRatioAgentItemDTO::getUserId).collect(Collectors.toList()))
|
||||
.list();
|
||||
List<TBaseCustomer> 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<Long, List<QuotationModelRatioAgentItemDTO>> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -315,6 +465,7 @@ public class RatioConfigController extends ControllerBase {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ApiResult.success(pageData);
|
||||
}
|
||||
}
|
||||
|
|
@ -344,7 +495,8 @@ public class RatioConfigController extends ControllerBase {
|
|||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
private void bindAgentChild(List<QuotationModelRatioAgentItemDTO> children, RatioConfigSearchVO vo, List<AppUser> users) {
|
||||
private void bindAgentChild(List<QuotationModelRatioAgentItemDTO> children, RatioConfigSearchVO
|
||||
vo, List<AppUser> 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<QuotationModelRatioDirectItemDTO> children, RatioConfigSearchVO vo, List<AdminUser> users) {
|
||||
private void bindDirectChild(List<QuotationModelRatioDirectItemDTO> children, RatioConfigSearchVO
|
||||
vo, List<AdminUser> users) {
|
||||
children.forEach(child -> {
|
||||
AdminUser user = users.stream()
|
||||
.filter(u -> u.getId().equals(child.getUserId()))
|
||||
|
|
|
|||
|
|
@ -153,9 +153,7 @@ public class RatioDirectConfigController extends ControllerBase {
|
|||
public ApiResult<RatioAgentSearchVO> 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<TBaseDepartment> 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<DictionaryItem> categories = dictionaryItemService.getListByDictionaryCode(Constant.DICTIONARY_DIRECT_SALES_CATEGORY);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.nflg.mobilebroken.quotation.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class TargetUserVO {
|
||||
|
||||
private List<TargetUserItemVO> appUsers;
|
||||
|
||||
private List<TargetUserItemVO> adminUsers;
|
||||
}
|
||||
|
|
@ -17,4 +17,6 @@ import java.util.List;
|
|||
public interface IQuotationModelRatioDirectService extends IService<QuotationModelRatioDirect> {
|
||||
|
||||
List<RatioDirectEffectiveDTO> getEffectives();
|
||||
|
||||
QuotationModelRatioDirect getEffectiveByUser(Integer userId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -24,4 +24,12 @@ public class QuotationModelRatioDirectServiceImpl extends ServiceImpl<QuotationM
|
|||
public List<RatioDirectEffectiveDTO> getEffectives() {
|
||||
return baseMapper.getEffectives();
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuotationModelRatioDirect getEffectiveByUser(Integer userId) {
|
||||
return lambdaQuery()
|
||||
.eq(QuotationModelRatioDirect::getStatus, 1)
|
||||
.eq(QuotationModelRatioDirect::getCreateById, userId)
|
||||
.one();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue