|
|
@@ -3,8 +3,8 @@ package com.cyksj.web.controller.manage.distribute;
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
-import cn.hutool.core.date.BetweenFormater;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.BetweenFormater;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
@@ -16,6 +16,7 @@ import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.BusinessType;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
+import com.cyksj.mapper.DistributeGoodsSkuAlertMapper;
|
|
|
import com.cyksj.mapper.GoodsDonMapper;
|
|
|
import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
import com.cyksj.mapper.UserMapper;
|
|
|
@@ -50,6 +51,7 @@ import javax.validation.constraints.NotNull;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/*
|
|
|
@@ -102,8 +104,12 @@ public class DistributeController {
|
|
|
|
|
|
private final RedisService redisService;
|
|
|
|
|
|
+ private final DistributeGoodsSkuAlertMapper distributeGoodsSkuAlertMapper;
|
|
|
+
|
|
|
private final UserDistributeRuleOrderRecordMapper userDistributeRuleOrderRecordMapper;
|
|
|
|
|
|
+ private final UserDistributeBusinessGeneralRateMapper businessGeneralRateMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 添加固定推广者
|
|
|
*/
|
|
|
@@ -239,7 +245,11 @@ public class DistributeController {
|
|
|
*/
|
|
|
@GetMapping("/get/plat")
|
|
|
public Result<List<GoodsDon>> getGoodsDistributeRate() {
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDonMapper.selectList(Wrappers.lambdaQuery(GoodsDon.class).in(GoodsDon::getType, Constant.dsGoodsIds).eq(GoodsDon::getDeleted, true).eq(GoodsDon::getStatus, true).orderByAsc(GoodsDon::getType).orderByAsc(GoodsDon::getId).select(GoodsDon::getId, GoodsDon::getType, GoodsDon::getTitle, GoodsDon::getRate, GoodsDon::getSecondRate)));
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDonMapper.selectList(Wrappers.lambdaQuery(GoodsDon.class).in(GoodsDon::getType, Constant.dsGoodsIds).eq(GoodsDon::getDeleted, true)
|
|
|
+ .eq(GoodsDon::getStatus, true).orderByAsc(GoodsDon::getType)
|
|
|
+ .eq(GoodsDon::getIsDistribute, true)
|
|
|
+ .orderByAsc(GoodsDon::getId)
|
|
|
+ .select(GoodsDon::getId, GoodsDon::getType, GoodsDon::getTitle, GoodsDon::getRate, GoodsDon::getSecondRate)));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -535,6 +545,7 @@ public class DistributeController {
|
|
|
@PutMapping("/put/business/rate")
|
|
|
@Log(module = "分销管理/修改商务人员比例", businessType = BusinessType.PUT, isSaveRequestData = true)
|
|
|
public Result<String> updateBusinessRate(@RequestBody @Validated List<UserDistributeBusinessRate> rates) {
|
|
|
+ List<Long> newDsSkuIds = new ArrayList<>();
|
|
|
rates.forEach(userDistributeBusinessRate -> {
|
|
|
Long rateId = userDistributeBusinessRate.getId();
|
|
|
UserDistributeBusinessRate businessRate = Optional.ofNullable(userDistributeBusinessRateMapper.selectById(rateId)).orElse(new UserDistributeBusinessRate());
|
|
|
@@ -554,12 +565,20 @@ public class DistributeController {
|
|
|
if (businessRate.getId() == null) {
|
|
|
try {
|
|
|
userDistributeBusinessRateMapper.insert(businessRate);
|
|
|
+
|
|
|
+ newDsSkuIds.add(businessRate.getSkuId());
|
|
|
} catch (DuplicateKeyException e) {
|
|
|
}
|
|
|
} else {
|
|
|
userDistributeBusinessRateMapper.updateById(businessRate);
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(newDsSkuIds)) {
|
|
|
+ //删除存在告警的平台规格
|
|
|
+ distributeGoodsSkuAlertMapper.delete(Wrappers.lambdaQuery(DistributeGoodsSkuAlert.class)
|
|
|
+ .in(DistributeGoodsSkuAlert::getSkuId, newDsSkuIds));
|
|
|
+ }
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult("修改比例成功");
|
|
|
}
|
|
|
|
|
|
@@ -651,7 +670,14 @@ public class DistributeController {
|
|
|
userPlatDistributeRate.setSecondRate(secondRate);
|
|
|
save.add(userPlatDistributeRate);
|
|
|
});
|
|
|
- Lists.partition(save, 100).forEach(part -> userDistributeBusinessRateMapper.batchInsertDistributePlatRate(part));
|
|
|
+ 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);
|
|
|
});
|
|
|
@@ -899,4 +925,92 @@ public class DistributeController {
|
|
|
List<BusinessDistributesMonthlyDataView> collect = businessDistributesDataViews.stream().sorted(Comparator.comparing(BusinessDistributesMonthlyDataView::getBusinessId).thenComparing(BusinessDistributesMonthlyDataView::getType)).collect(Collectors.toList());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(collect);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 针对商务
|
|
|
+ * 获取商务 分销平台通用比例
|
|
|
+ */
|
|
|
+ @GetMapping("/get/business/general/rate")
|
|
|
+ public Result<List<UserDistributeBusinessGeneralRateView>> getBusinessGeneralRate(@RequestParam(defaultValue = "1") Integer type) {
|
|
|
+ List<UserDistributeBusinessGeneralRateView> userDistributeBusinessGeneralRateViews = beanSearcher.searchAll(UserDistributeBusinessGeneralRateView.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
+ .field(UserDistributeBusinessGeneralRateView::getType, type).build());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(userDistributeBusinessGeneralRateViews);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑商务 分销平台通用比例
|
|
|
+ * 商务的平台规格提成 根据这个改变
|
|
|
+ */
|
|
|
+ @PutMapping("/put/business/general/rate")
|
|
|
+ @Transactional(rollbackFor = Throwable.class)
|
|
|
+ public Result<String> updateBusinessGeneralRate(@RequestBody List<UserDistributeBusinessGeneralRate> generalRates) {
|
|
|
+ List<CmsUserVO> userVOS = beanSearcher.searchAll(CmsUserVO.class, MapUtils.builder().field(CmsUserVO::getRoleNames, "商务").op(Operator.Contain).build());
|
|
|
+ List<Long> collect = userVOS.stream().map(CmsUserVO::getId).collect(Collectors.toList());
|
|
|
+ final List<Long> businessIds = collect;
|
|
|
+ List<Long> newDsSkuIds = new ArrayList<>();
|
|
|
+ generalRates.forEach(data -> {
|
|
|
+ if (data.getId() == null) {
|
|
|
+ try {
|
|
|
+ //新增
|
|
|
+ UserDistributeBusinessGeneralRate businessGeneralRate = new UserDistributeBusinessGeneralRate();
|
|
|
+ if (data.getGoodsId() == null || data.getSkuId() == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("缺少必要参数");
|
|
|
+ }
|
|
|
+ businessGeneralRate.setGoodsId(data.getGoodsId());
|
|
|
+ businessGeneralRate.setSkuId(data.getSkuId());
|
|
|
+ Integer firstOrderRate = Optional.ofNullable(data.getFirstOrderRate()).orElse(0);
|
|
|
+ businessGeneralRate.setFirstOrderRate(firstOrderRate);
|
|
|
+ Integer renewOrderRate = Optional.ofNullable(data.getRenewOrderRate()).orElse(0);
|
|
|
+ businessGeneralRate.setRenewOrderRate(renewOrderRate);
|
|
|
+ businessGeneralRateMapper.insert(businessGeneralRate);
|
|
|
+ if (CollUtil.isNotEmpty(businessIds)) {
|
|
|
+ userDistributeBusinessRateMapper.insertOrUpdateBusinessGoodsSkuRate(businessIds, data.getGoodsId(), data.getSkuId(), firstOrderRate, renewOrderRate);
|
|
|
+ }
|
|
|
+ newDsSkuIds.add(data.getSkuId());
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ UserDistributeBusinessGeneralRate dbGeneralRate = businessGeneralRateMapper.selectById(data.getId());
|
|
|
+ if (dbGeneralRate != null) {
|
|
|
+ Integer firstOrderRate_new = null;
|
|
|
+ Integer renewOrderRate_new = null;
|
|
|
+ AtomicBoolean is_change = new AtomicBoolean(false);
|
|
|
+ //需要更新首单比例
|
|
|
+ if (data.getFirstOrderRate() != null && dbGeneralRate.getFirstOrderRate() != data.getFirstOrderRate()) {
|
|
|
+ firstOrderRate_new = data.getFirstOrderRate();
|
|
|
+ is_change.set(true);
|
|
|
+ }
|
|
|
+ //需要更新续费比例
|
|
|
+ if (data.getRenewOrderRate() != null && dbGeneralRate.getRenewOrderRate() != data.getRenewOrderRate()) {
|
|
|
+ renewOrderRate_new = data.getRenewOrderRate();
|
|
|
+ is_change.set(true);
|
|
|
+ }
|
|
|
+ if (is_change.get()) {
|
|
|
+ businessGeneralRateMapper.updateById(data);
|
|
|
+ newDsSkuIds.add(data.getSkuId());
|
|
|
+ if (CollUtil.isNotEmpty(businessIds)) {
|
|
|
+ //获取所有商务
|
|
|
+ userDistributeBusinessRateMapper.insertOrUpdateBusinessGoodsSkuRate(businessIds, data.getGoodsId(), data.getSkuId(), firstOrderRate_new, renewOrderRate_new);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(newDsSkuIds)) {
|
|
|
+ //删除存在告警的平台规格
|
|
|
+ distributeGoodsSkuAlertMapper.delete(Wrappers.lambdaQuery(DistributeGoodsSkuAlert.class)
|
|
|
+ .in(DistributeGoodsSkuAlert::getSkuId, newDsSkuIds));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否有未配置比例的规格
|
|
|
+ */
|
|
|
+ @GetMapping("/get/goodsSku/alert")
|
|
|
+ public Result<Boolean> getGoodsSkuAlert() {
|
|
|
+ Integer count = distributeGoodsSkuAlertMapper.selectCountByCondition();
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(count > 0 ? true : false);
|
|
|
+ }
|
|
|
}
|