|
|
@@ -24,6 +24,7 @@ import com.cyksj.mapper.manage.cms.CmsUserMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponDistributePopularizeMapper;
|
|
|
import com.cyksj.mapper.manage.distribute.*;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
+import com.cyksj.model.request.BusinessDistributeDefaultRateDetailReq;
|
|
|
import com.cyksj.model.request.DistributeApplyMoneyReq;
|
|
|
import com.cyksj.model.request.UserDistributeReq;
|
|
|
import com.cyksj.model.views.*;
|
|
|
@@ -38,7 +39,6 @@ import com.ejlchina.searcher.SearchResult;
|
|
|
import com.ejlchina.searcher.param.Operator;
|
|
|
import com.ejlchina.searcher.util.MapBuilder;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
-import com.google.common.collect.Lists;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
|
@@ -96,6 +96,8 @@ public class DistributeController {
|
|
|
|
|
|
private final BusinessDistributeDefaultRateConfigMapper businessDefaultRateConfigMapper;
|
|
|
|
|
|
+ private final BusinessDistributeDefaultSkuRateConfigMapper businessDistributeDefaultSkuRateConfigMapper;
|
|
|
+
|
|
|
private final UserBenefitsService userBenefitsService;
|
|
|
|
|
|
private final CouponDistributePopularizeMapper couponDistributePopularizeMapper;
|
|
|
@@ -158,11 +160,19 @@ public class DistributeController {
|
|
|
* 固定推广者详情
|
|
|
*/
|
|
|
@GetMapping("/get/detail/{id}")
|
|
|
- public Result<List<UserDistributeView>> getDetailById(@PathVariable Long id) {
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(beanSearcher.searchAll(UserDistributeView.class, MapUtils.builder()
|
|
|
- .field(UserDistributeView::getDistribute_id, id).op(Operator.Equal)
|
|
|
+ public Result<UserDistributeRateDetailView> getDetailById(@PathVariable Long id) {
|
|
|
+ UserDistributeRateDetailView rateDetailView = new UserDistributeRateDetailView();
|
|
|
+ List<UserDistributeView> rates = beanSearcher.searchAll(UserDistributeView.class, MapUtils.builder()
|
|
|
+ .put("dis_id", String.format(" and up.distribute_id = %s", id))
|
|
|
.orderBy(UserDistributeView::getGoodsId).asc()
|
|
|
- .build()));
|
|
|
+ .build());
|
|
|
+ rateDetailView.setRates(rates);
|
|
|
+ List<UserSkuDistributeView> skuRates = beanSearcher.searchAll(UserSkuDistributeView.class, MapUtils.builder()
|
|
|
+ .put("dis_id", String.format(" and up.distribute_id = %s", id))
|
|
|
+ .orderBy(UserSkuDistributeView::getGoodsId).asc()
|
|
|
+ .build());
|
|
|
+ rateDetailView.setSkuRates(skuRates);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(rateDetailView);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -303,6 +313,12 @@ public class DistributeController {
|
|
|
@Log(module = "分销管理/修改平台分销比例", businessType = BusinessType.PUT, isSaveRequestData = true)
|
|
|
public Result<String> editGoodsDistributeRate(@RequestBody UserDistributeReq userDistributeReq) {
|
|
|
for (UserPlatDistributeRate rate : userDistributeReq.getRates()) {
|
|
|
+ if (rate.getRate() == null) {
|
|
|
+ rate.setRate(0);
|
|
|
+ }
|
|
|
+ if (rate.getSecondRate() == null) {
|
|
|
+ rate.setSecondRate(0);
|
|
|
+ }
|
|
|
if (rate.getRate() < 0 || rate.getRate() > 100) {
|
|
|
throw new BusinessRuntimeException("比例错误");
|
|
|
}
|
|
|
@@ -626,11 +642,17 @@ public class DistributeController {
|
|
|
* 商务人员推广平台分销比例默认配置列表
|
|
|
*/
|
|
|
@GetMapping("/get/business/distribute/rate")
|
|
|
- public Result<List<BusinessDistributeRateView>> getBusinessDistributeRateConfigList() {
|
|
|
- List<BusinessDistributeRateView> businessDistributeRateViews = beanSearcher.searchAll(BusinessDistributeRateView.class,
|
|
|
+ public Result<BusinessDistributeRateDetailView> getBusinessDistributeRateConfigList() {
|
|
|
+ BusinessDistributeRateDetailView rateDetailView = new BusinessDistributeRateDetailView();
|
|
|
+ List<BusinessDistributeRateView> rates = beanSearcher.searchAll(BusinessDistributeRateView.class,
|
|
|
+ MapUtils.flatBuilder(request.getParameterMap())
|
|
|
+ .build());
|
|
|
+ rateDetailView.setRates(rates);
|
|
|
+ List<BusinessDistributeSkuRateView> skuRates = beanSearcher.searchAll(BusinessDistributeSkuRateView.class,
|
|
|
MapUtils.flatBuilder(request.getParameterMap())
|
|
|
.build());
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(businessDistributeRateViews);
|
|
|
+ rateDetailView.setSkuRates(skuRates);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(rateDetailView);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -638,49 +660,63 @@ public class DistributeController {
|
|
|
*/
|
|
|
@PutMapping("/put/business/distribute/rate")
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
- public Result<String> updateBusinessDistributeRate(@RequestBody List<BusinessDistributeDefaultRateConfig> configs) {
|
|
|
- configs.forEach(config -> {
|
|
|
- Long id = config.getId();
|
|
|
- Long goodsId = config.getGoodsId();
|
|
|
- Integer rate = config.getRate();
|
|
|
- if (goodsId == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("平台id为空");
|
|
|
- }
|
|
|
- if (rate == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("分销比列为空");
|
|
|
- }
|
|
|
- if (id == null) {
|
|
|
- try {
|
|
|
- businessDefaultRateConfigMapper.insert(config);
|
|
|
- } catch (DuplicateKeyException e) {
|
|
|
+ public Result<String> updateBusinessDistributeRate(@RequestBody BusinessDistributeDefaultRateDetailReq req) {
|
|
|
+ List<BusinessDistributeDefaultRateConfig> rates = req.getRates();
|
|
|
+ List<BusinessDistributeDefaultSkuRateConfig> skuRates = req.getSkuRates();
|
|
|
+ List<Long> alertGoodsId = new ArrayList<>();
|
|
|
+ if (CollUtil.isNotEmpty(rates)) {
|
|
|
+ rates.forEach(config -> {
|
|
|
+ Long id = config.getId();
|
|
|
+ Long goodsId = config.getGoodsId();
|
|
|
+ if (config.getRate() == null) {
|
|
|
+ config.setRate(0);
|
|
|
}
|
|
|
- return;
|
|
|
- }
|
|
|
- //新品编辑成功 给渠道自动添加对应值
|
|
|
- List<Long> distributeIds = userDistributeBusinessRateMapper.selectNoThisGoodsDistribute(config.getGoodsId());
|
|
|
- if (!distributeIds.isEmpty()) {
|
|
|
- List<UserPlatDistributeRate> save = new ArrayList<>(distributeIds.size());
|
|
|
- distributeIds.forEach(distributeId -> {
|
|
|
- Integer secondRate = config.getSecondRate();
|
|
|
- if (secondRate == null) secondRate = 0;
|
|
|
- UserPlatDistributeRate userPlatDistributeRate = new UserPlatDistributeRate();
|
|
|
- userPlatDistributeRate.setDistributeId(distributeId);
|
|
|
- userPlatDistributeRate.setRate(rate);
|
|
|
- userPlatDistributeRate.setGoodsId(config.getGoodsId());
|
|
|
- userPlatDistributeRate.setSecondRate(secondRate);
|
|
|
- save.add(userPlatDistributeRate);
|
|
|
- });
|
|
|
- Lists.partition(save, 100).forEach(part -> {
|
|
|
- List<Long> goodsIds = part.stream().map(UserPlatDistributeRate::getGoodsId).collect(Collectors.toList());
|
|
|
- //删除存在告警的平台
|
|
|
- distributeGoodsSkuAlertMapper.delete(Wrappers.lambdaQuery(DistributeGoodsSkuAlert.class)
|
|
|
- .in(DistributeGoodsSkuAlert::getGoodsId, goodsIds));
|
|
|
-
|
|
|
- userDistributeBusinessRateMapper.batchInsertDistributePlatRate(part);
|
|
|
- });
|
|
|
- }
|
|
|
- businessDefaultRateConfigMapper.updateById(config);
|
|
|
- });
|
|
|
+ Integer rate = config.getRate();
|
|
|
+ if (goodsId == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("平台id为空");
|
|
|
+ }
|
|
|
+ if (rate < 0 && rate > 100) {
|
|
|
+ throw BusinessRuntimeException.getInstance("请输入正确的比例");
|
|
|
+ }
|
|
|
+ if (id == null) {
|
|
|
+ try {
|
|
|
+ businessDefaultRateConfigMapper.insert(config);
|
|
|
+ alertGoodsId.add(config.getGoodsId());
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ businessDefaultRateConfigMapper.updateById(config);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //sku规格比例设置
|
|
|
+ if (CollUtil.isNotEmpty(skuRates)) {
|
|
|
+ skuRates.forEach(config -> {
|
|
|
+ if (config.getRate() == null) {
|
|
|
+ config.setRate(0);
|
|
|
+ }
|
|
|
+ Integer rate = config.getRate();
|
|
|
+ if (rate < 0 && rate > 100) {
|
|
|
+ throw BusinessRuntimeException.getInstance("请输入正确的比例");
|
|
|
+ }
|
|
|
+ if (config.getId() == null) {
|
|
|
+ try {
|
|
|
+ businessDistributeDefaultSkuRateConfigMapper.insert(config);
|
|
|
+ alertGoodsId.add(config.getGoodsId());
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ businessDistributeDefaultSkuRateConfigMapper.updateById(config);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(alertGoodsId)) {
|
|
|
+ //删除存在告警的平台
|
|
|
+ distributeGoodsSkuAlertMapper.delete(Wrappers.lambdaQuery(DistributeGoodsSkuAlert.class)
|
|
|
+ .in(DistributeGoodsSkuAlert::getGoodsId, alertGoodsId));
|
|
|
+ }
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
|