...
|
...
|
@@ -9,6 +9,7 @@ import com.yohobuy.ufo.model.order.common.SuperEnterStageLevel; |
|
|
import com.yohobuy.ufo.model.order.resp.EntryThreshold;
|
|
|
import com.yohobuy.ufo.model.order.resp.SellerPlatformServiceFeeResp;
|
|
|
import com.yohoufo.common.cache.CacheKeyEnum;
|
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.dal.order.SellerEnterApplyMapper;
|
|
|
import com.yohoufo.dal.order.StoredSellerMapper;
|
|
|
import com.yohoufo.dal.order.SuperEntrySellerMapper;
|
...
|
...
|
@@ -27,6 +28,7 @@ import com.yohoufo.order.utils.LoggerUtils; |
|
|
import com.yohoufo.order.utils.MathUtils;
|
|
|
import com.yohoufo.order.utils.SellerHelper;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
...
|
...
|
@@ -167,30 +169,25 @@ public class SellerService { |
|
|
* @return
|
|
|
*/
|
|
|
public SellerPlatformServiceFeeResp platformServiceFeeDetail(int uid) {
|
|
|
|
|
|
logger.info("platformServiceFee uid {}", uid);
|
|
|
SellerPlatformServiceFee currentServiceFee = getCurrentTimeSellerPlatformServiceFee(uid);
|
|
|
|
|
|
SellerOrderStatsEntry statsEntry = SellerOrderStatsEntry.builder().sellerUid(uid).orderAttribute(OrderAttributes.COMMON_IN_STOCK).build();
|
|
|
|
|
|
SellerOrderStatsConfiguration statsConfig = statsConfigurationManager.getStatsConfig(statsEntry);
|
|
|
|
|
|
SellerPlatformServiceFee serviceFee = (SellerPlatformServiceFee) statsConfigurationManager.getStatsProcessor(statsConfig.getStatsProcessorName()).apply(statsEntry, statsConfig);
|
|
|
SellerPlatformServiceFee nextPeriodServiceFee = getNextPeriodSellerPlatformServiceFee(uid);
|
|
|
|
|
|
if (Objects.isNull(serviceFee)) {
|
|
|
logger.info("platformServiceFee is null for uid {}", uid);
|
|
|
if (!currentServiceFee.isRuleConfigured() || !nextPeriodServiceFee.isRuleConfigured()) {
|
|
|
logger.info("platformServiceFee rule is not configured,uid {}", uid);
|
|
|
return SellerPlatformServiceFeeResp.builder()
|
|
|
.currentMonthRate(null)
|
|
|
.nodes(Lists.newArrayList())
|
|
|
.orderQuantity(0)
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
//当前完成的数量,在下个周期使用
|
|
|
int nextPeriodOrderQuantity = nextPeriodServiceFee.getOrderQuantity();
|
|
|
//未到达的规则
|
|
|
PlatformServiceFeeDefinition.FeeRule unsatisfiedFeeRule = nextPeriodServiceFee.getDefinition().getUnsatisfiedFeeRule(nextPeriodOrderQuantity);
|
|
|
//扣点比例
|
|
|
List<PlatformServiceFeeDefinition.FeeRule> rules = serviceFee.getDefinition().getRules();
|
|
|
|
|
|
List<PlatformServiceFeeDefinition.FeeRule> rules = new ArrayList<>(nextPeriodServiceFee.getDefinition().getRules());
|
|
|
//从小到大排序
|
|
|
rules.sort(Comparator.comparing(PlatformServiceFeeDefinition.FeeRule::getThreshold));
|
|
|
|
|
|
List<SellerPlatformServiceFeeResp.Node> nodes = rules.stream().map(rule -> {
|
|
|
SellerPlatformServiceFeeResp.Node node = new SellerPlatformServiceFeeResp.Node();
|
|
|
node.setKey(rule.getThreshold());
|
...
|
...
|
@@ -198,17 +195,46 @@ public class SellerService { |
|
|
return node;
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
SellerPlatformServiceFeeResp resp = SellerPlatformServiceFeeResp.builder()
|
|
|
.currentMonthRate(MathUtils.convert2Percent(serviceFee.getFeeRate()))
|
|
|
.currentRate(MathUtils.convert2Percent(currentServiceFee.getFeeRate()))
|
|
|
.nodes(nodes)
|
|
|
.orderQuantity(serviceFee.getOrderQuantity())
|
|
|
.finishedOrderQuantity(nextPeriodOrderQuantity)
|
|
|
.nextRateToReach(MathUtils.convert2Percent(unsatisfiedFeeRule.getRate()))
|
|
|
.nextRateRequiredIncOrderQuantity(Math.max(0, unsatisfiedFeeRule.getThreshold() - nextPeriodOrderQuantity))
|
|
|
.build();
|
|
|
|
|
|
logger.info("platformServiceFee uid {},resp {}", uid, resp);
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 当前
|
|
|
* @param uid
|
|
|
* @return
|
|
|
*/
|
|
|
private SellerPlatformServiceFee getCurrentTimeSellerPlatformServiceFee(int uid) {
|
|
|
//当前的扣点服务
|
|
|
SellerOrderStatsEntry currentStatsEntry = SellerOrderStatsEntry.builder().sellerUid(uid).orderAttribute(OrderAttributes.COMMON_IN_STOCK).time(DateUtil.getCurrentTimeSecond()).build();
|
|
|
SellerOrderStatsConfiguration currentStatsConfig = statsConfigurationManager.getStatsConfig(currentStatsEntry);
|
|
|
return (SellerPlatformServiceFee)statsConfigurationManager.getStatsProcessor(currentStatsConfig.getStatsProcessorName()).apply(currentStatsEntry, currentStatsConfig);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 下个周期的
|
|
|
*
|
|
|
* @param uid
|
|
|
* @return
|
|
|
*/
|
|
|
private SellerPlatformServiceFee getNextPeriodSellerPlatformServiceFee(int uid) {
|
|
|
//下个周期
|
|
|
SellerOrderStatsEntry nextStatsEntry = SellerOrderStatsEntry.builder().sellerUid(uid).orderAttribute(OrderAttributes.COMMON_IN_STOCK).build();
|
|
|
SellerOrderStatsConfiguration nextStatsConfig = statsConfigurationManager.getStatsConfig(nextStatsEntry);
|
|
|
Pair<Integer, Integer> nextValidityTimeTuple = nextStatsConfig.getStatsUnit().getValidityTimeTuple(nextStatsConfig.getStatsPeriod(), nextStatsConfig.getStatsPeriod());
|
|
|
//设置查询时间为下个周期的开始时间
|
|
|
nextStatsEntry.setTime(nextValidityTimeTuple.getKey());
|
|
|
return (SellerPlatformServiceFee) statsConfigurationManager.getStatsProcessor(nextStatsConfig.getStatsProcessorName()).apply(nextStatsEntry, nextStatsConfig);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
|