Showing
11 changed files
with
128 additions
and
58 deletions
@@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
7 | <result column="uid" property="uid" jdbcType="INTEGER"/> | 7 | <result column="uid" property="uid" jdbcType="INTEGER"/> |
8 | <result column="begin_time" property="beginTime" jdbcType="INTEGER"/> | 8 | <result column="begin_time" property="beginTime" jdbcType="INTEGER"/> |
9 | <result column="end_time" property="endTime" jdbcType="INTEGER"/> | 9 | <result column="end_time" property="endTime" jdbcType="INTEGER"/> |
10 | - <result column="quantity" property="statsPeriod" jdbcType="INTEGER"/> | 10 | + <result column="quantity" property="quantity" jdbcType="INTEGER"/> |
11 | </resultMap> | 11 | </resultMap> |
12 | <sql id="Base_Column_List"> | 12 | <sql id="Base_Column_List"> |
13 | id, stats_code, uid, begin_time, end_time, quantity | 13 | id, stats_code, uid, begin_time, end_time, quantity |
@@ -3,12 +3,9 @@ package com.yohoufo.order.model.bo; | @@ -3,12 +3,9 @@ package com.yohoufo.order.model.bo; | ||
3 | import com.yohoufo.order.utils.BeanTool; | 3 | import com.yohoufo.order.utils.BeanTool; |
4 | import lombok.Data; | 4 | import lombok.Data; |
5 | import lombok.ToString; | 5 | import lombok.ToString; |
6 | -import org.apache.commons.collections.CollectionUtils; | ||
7 | import org.apache.commons.lang3.StringUtils; | 6 | import org.apache.commons.lang3.StringUtils; |
8 | - | ||
9 | import java.math.BigDecimal; | 7 | import java.math.BigDecimal; |
10 | -import java.util.Comparator; | ||
11 | -import java.util.List; | 8 | +import java.util.*; |
12 | 9 | ||
13 | /** | 10 | /** |
14 | * Created by jiexiang.wu on 2019/7/23. | 11 | * Created by jiexiang.wu on 2019/7/23. |
@@ -18,8 +15,20 @@ import java.util.List; | @@ -18,8 +15,20 @@ import java.util.List; | ||
18 | @ToString | 15 | @ToString |
19 | public class PlatformServiceFeeDefinition { | 16 | public class PlatformServiceFeeDefinition { |
20 | 17 | ||
21 | - //费用规则 | ||
22 | - private List<FeeRule> rules; | 18 | + //费用规则 按照threshold从小到大排序 |
19 | + private List<FeeRule> rules = new ArrayList<>(); | ||
20 | + | ||
21 | + /** | ||
22 | + * 排序 | ||
23 | + * | ||
24 | + * @param comparator | ||
25 | + */ | ||
26 | + private void sortRules(Comparator comparator) { | ||
27 | + if (Objects.isNull(rules)) { | ||
28 | + rules = new ArrayList<>(); | ||
29 | + } | ||
30 | + rules.sort(comparator); | ||
31 | + } | ||
23 | 32 | ||
24 | /** | 33 | /** |
25 | * 根据阀值获取对应的折扣 | 34 | * 根据阀值获取对应的折扣 |
@@ -28,13 +37,6 @@ public class PlatformServiceFeeDefinition { | @@ -28,13 +37,6 @@ public class PlatformServiceFeeDefinition { | ||
28 | * @return | 37 | * @return |
29 | */ | 38 | */ |
30 | public BigDecimal getFeeRate(int threshold) { | 39 | public BigDecimal getFeeRate(int threshold) { |
31 | - if (CollectionUtils.isEmpty(rules)) { | ||
32 | - return null; | ||
33 | - } | ||
34 | - | ||
35 | - //nodes排序 按照threshold从大到小排序 | ||
36 | - rules.sort(Comparator.comparing(FeeRule::getThreshold).reversed()); | ||
37 | - | ||
38 | for (FeeRule rule : rules) { | 40 | for (FeeRule rule : rules) { |
39 | if (threshold >= rule.getThreshold()) { | 41 | if (threshold >= rule.getThreshold()) { |
40 | return rule.getRate(); | 42 | return rule.getRate(); |
@@ -44,12 +46,37 @@ public class PlatformServiceFeeDefinition { | @@ -44,12 +46,37 @@ public class PlatformServiceFeeDefinition { | ||
44 | return null; | 46 | return null; |
45 | } | 47 | } |
46 | 48 | ||
49 | + public Collection<FeeRule> getRules() { | ||
50 | + return Collections.unmodifiableCollection(rules); | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * 获取下一个未满足的扣点规则 | ||
55 | + * | ||
56 | + * @param threshold | ||
57 | + * @return | ||
58 | + */ | ||
59 | + public FeeRule getUnsatisfiedFeeRule(int threshold) { | ||
60 | + //必须确保 rules 从大到小排序的 | ||
61 | + for (int i = 0; i < rules.size(); i++) { | ||
62 | + FeeRule rule = rules.get(i); | ||
63 | + if (threshold >= rule.getThreshold()) { | ||
64 | + //满足当前规则,上一个规则一定不满足 | ||
65 | + return rules.get(Math.max(0, i - 1)); | ||
66 | + } | ||
67 | + } | ||
68 | + return null; | ||
69 | + } | ||
70 | + | ||
47 | 71 | ||
48 | public static PlatformServiceFeeDefinition convert(String json) { | 72 | public static PlatformServiceFeeDefinition convert(String json) { |
49 | if (StringUtils.isEmpty(json)) { | 73 | if (StringUtils.isEmpty(json)) { |
50 | return new PlatformServiceFeeDefinition(); | 74 | return new PlatformServiceFeeDefinition(); |
51 | } else { | 75 | } else { |
52 | - return BeanTool.string2Value(json, PlatformServiceFeeDefinition.class); | 76 | + PlatformServiceFeeDefinition definition = BeanTool.string2Value(json, PlatformServiceFeeDefinition.class); |
77 | + //从大到小排序 | ||
78 | + definition.sortRules(Comparator.comparing(FeeRule::getThreshold).reversed()); | ||
79 | + return definition; | ||
53 | } | 80 | } |
54 | } | 81 | } |
55 | 82 |
@@ -2,6 +2,7 @@ package com.yohoufo.order.model.bo; | @@ -2,6 +2,7 @@ package com.yohoufo.order.model.bo; | ||
2 | 2 | ||
3 | import lombok.Data; | 3 | import lombok.Data; |
4 | import lombok.ToString; | 4 | import lombok.ToString; |
5 | +import org.apache.commons.collections.CollectionUtils; | ||
5 | 6 | ||
6 | import java.math.BigDecimal; | 7 | import java.math.BigDecimal; |
7 | 8 | ||
@@ -23,6 +24,14 @@ public class SellerPlatformServiceFee { | @@ -23,6 +24,14 @@ public class SellerPlatformServiceFee { | ||
23 | } | 24 | } |
24 | 25 | ||
25 | /** | 26 | /** |
27 | + * 规则是否配置了 | ||
28 | + * @return | ||
29 | + */ | ||
30 | + public boolean isRuleConfigured() { | ||
31 | + return CollectionUtils.isNotEmpty(definition.getRules()); | ||
32 | + } | ||
33 | + | ||
34 | + /** | ||
26 | * 费用比例 | 35 | * 费用比例 |
27 | * | 36 | * |
28 | * @return | 37 | * @return |
@@ -73,12 +73,12 @@ public class SellerOrderStatsConfigCacheService { | @@ -73,12 +73,12 @@ public class SellerOrderStatsConfigCacheService { | ||
73 | }); | 73 | }); |
74 | } | 74 | } |
75 | 75 | ||
76 | - public SellerOrderStatsConfiguration findBy(OrderAttributes orderAttributes) { | 76 | + public Optional<SellerOrderStatsConfiguration> findBy(OrderAttributes orderAttributes) { |
77 | List<SellerOrderStatsConfiguration> configurations = (List) localCache.get(SELLER_ORDER_STATS_CONFIG_KEY); | 77 | List<SellerOrderStatsConfiguration> configurations = (List) localCache.get(SELLER_ORDER_STATS_CONFIG_KEY); |
78 | if (CollectionUtils.isEmpty(configurations)) { | 78 | if (CollectionUtils.isEmpty(configurations)) { |
79 | - return null; | 79 | + return Optional.ofNullable(null); |
80 | } | 80 | } |
81 | Optional<SellerOrderStatsConfiguration> optional = configurations.stream().filter(config -> config.getOrderAttributes().contains(orderAttributes)).findFirst(); | 81 | Optional<SellerOrderStatsConfiguration> optional = configurations.stream().filter(config -> config.getOrderAttributes().contains(orderAttributes)).findFirst(); |
82 | - return optional.isPresent() ? optional.get() : null; | 82 | + return optional; |
83 | } | 83 | } |
84 | } | 84 | } |
@@ -9,6 +9,7 @@ import com.yohobuy.ufo.model.order.common.SuperEnterStageLevel; | @@ -9,6 +9,7 @@ import com.yohobuy.ufo.model.order.common.SuperEnterStageLevel; | ||
9 | import com.yohobuy.ufo.model.order.resp.EntryThreshold; | 9 | import com.yohobuy.ufo.model.order.resp.EntryThreshold; |
10 | import com.yohobuy.ufo.model.order.resp.SellerPlatformServiceFeeResp; | 10 | import com.yohobuy.ufo.model.order.resp.SellerPlatformServiceFeeResp; |
11 | import com.yohoufo.common.cache.CacheKeyEnum; | 11 | import com.yohoufo.common.cache.CacheKeyEnum; |
12 | +import com.yohoufo.common.utils.DateUtil; | ||
12 | import com.yohoufo.dal.order.SellerEnterApplyMapper; | 13 | import com.yohoufo.dal.order.SellerEnterApplyMapper; |
13 | import com.yohoufo.dal.order.StoredSellerMapper; | 14 | import com.yohoufo.dal.order.StoredSellerMapper; |
14 | import com.yohoufo.dal.order.SuperEntrySellerMapper; | 15 | import com.yohoufo.dal.order.SuperEntrySellerMapper; |
@@ -27,6 +28,7 @@ import com.yohoufo.order.utils.LoggerUtils; | @@ -27,6 +28,7 @@ import com.yohoufo.order.utils.LoggerUtils; | ||
27 | import com.yohoufo.order.utils.MathUtils; | 28 | import com.yohoufo.order.utils.MathUtils; |
28 | import com.yohoufo.order.utils.SellerHelper; | 29 | import com.yohoufo.order.utils.SellerHelper; |
29 | import org.apache.commons.collections.CollectionUtils; | 30 | import org.apache.commons.collections.CollectionUtils; |
31 | +import org.apache.commons.lang3.tuple.Pair; | ||
30 | import org.slf4j.Logger; | 32 | import org.slf4j.Logger; |
31 | import org.springframework.beans.factory.annotation.Autowired; | 33 | import org.springframework.beans.factory.annotation.Autowired; |
32 | import org.springframework.stereotype.Service; | 34 | import org.springframework.stereotype.Service; |
@@ -167,30 +169,25 @@ public class SellerService { | @@ -167,30 +169,25 @@ public class SellerService { | ||
167 | * @return | 169 | * @return |
168 | */ | 170 | */ |
169 | public SellerPlatformServiceFeeResp platformServiceFeeDetail(int uid) { | 171 | public SellerPlatformServiceFeeResp platformServiceFeeDetail(int uid) { |
170 | - | ||
171 | logger.info("platformServiceFee uid {}", uid); | 172 | logger.info("platformServiceFee uid {}", uid); |
173 | + SellerPlatformServiceFee currentServiceFee = getCurrentTimeSellerPlatformServiceFee(uid); | ||
172 | 174 | ||
173 | - SellerOrderStatsEntry statsEntry = SellerOrderStatsEntry.builder().sellerUid(uid).orderAttribute(OrderAttributes.COMMON_IN_STOCK).build(); | ||
174 | - | ||
175 | - SellerOrderStatsConfiguration statsConfig = statsConfigurationManager.getStatsConfig(statsEntry); | ||
176 | - | ||
177 | - SellerPlatformServiceFee serviceFee = (SellerPlatformServiceFee) statsConfigurationManager.getStatsProcessor(statsConfig.getStatsProcessorName()).apply(statsEntry, statsConfig); | 175 | + SellerPlatformServiceFee nextPeriodServiceFee = getNextPeriodSellerPlatformServiceFee(uid); |
178 | 176 | ||
179 | - if (Objects.isNull(serviceFee)) { | ||
180 | - logger.info("platformServiceFee is null for uid {}", uid); | 177 | + if (!currentServiceFee.isRuleConfigured() || !nextPeriodServiceFee.isRuleConfigured()) { |
178 | + logger.info("platformServiceFee rule is not configured,uid {}", uid); | ||
181 | return SellerPlatformServiceFeeResp.builder() | 179 | return SellerPlatformServiceFeeResp.builder() |
182 | - .currentMonthRate(null) | ||
183 | .nodes(Lists.newArrayList()) | 180 | .nodes(Lists.newArrayList()) |
184 | - .orderQuantity(0) | ||
185 | .build(); | 181 | .build(); |
186 | } | 182 | } |
187 | - | 183 | + //当前完成的数量,在下个周期使用 |
184 | + int nextPeriodOrderQuantity = nextPeriodServiceFee.getOrderQuantity(); | ||
185 | + //未到达的规则 | ||
186 | + PlatformServiceFeeDefinition.FeeRule unsatisfiedFeeRule = nextPeriodServiceFee.getDefinition().getUnsatisfiedFeeRule(nextPeriodOrderQuantity); | ||
188 | //扣点比例 | 187 | //扣点比例 |
189 | - List<PlatformServiceFeeDefinition.FeeRule> rules = serviceFee.getDefinition().getRules(); | ||
190 | - | 188 | + List<PlatformServiceFeeDefinition.FeeRule> rules = new ArrayList<>(nextPeriodServiceFee.getDefinition().getRules()); |
191 | //从小到大排序 | 189 | //从小到大排序 |
192 | rules.sort(Comparator.comparing(PlatformServiceFeeDefinition.FeeRule::getThreshold)); | 190 | rules.sort(Comparator.comparing(PlatformServiceFeeDefinition.FeeRule::getThreshold)); |
193 | - | ||
194 | List<SellerPlatformServiceFeeResp.Node> nodes = rules.stream().map(rule -> { | 191 | List<SellerPlatformServiceFeeResp.Node> nodes = rules.stream().map(rule -> { |
195 | SellerPlatformServiceFeeResp.Node node = new SellerPlatformServiceFeeResp.Node(); | 192 | SellerPlatformServiceFeeResp.Node node = new SellerPlatformServiceFeeResp.Node(); |
196 | node.setKey(rule.getThreshold()); | 193 | node.setKey(rule.getThreshold()); |
@@ -198,17 +195,46 @@ public class SellerService { | @@ -198,17 +195,46 @@ public class SellerService { | ||
198 | return node; | 195 | return node; |
199 | }).collect(Collectors.toList()); | 196 | }).collect(Collectors.toList()); |
200 | 197 | ||
201 | - | ||
202 | SellerPlatformServiceFeeResp resp = SellerPlatformServiceFeeResp.builder() | 198 | SellerPlatformServiceFeeResp resp = SellerPlatformServiceFeeResp.builder() |
203 | - .currentMonthRate(MathUtils.convert2Percent(serviceFee.getFeeRate())) | 199 | + .currentRate(MathUtils.convert2Percent(currentServiceFee.getFeeRate())) |
204 | .nodes(nodes) | 200 | .nodes(nodes) |
205 | - .orderQuantity(serviceFee.getOrderQuantity()) | 201 | + .finishedOrderQuantity(nextPeriodOrderQuantity) |
202 | + .nextRateToReach(MathUtils.convert2Percent(unsatisfiedFeeRule.getRate())) | ||
203 | + .nextRateRequiredIncOrderQuantity(Math.max(0, unsatisfiedFeeRule.getThreshold() - nextPeriodOrderQuantity)) | ||
206 | .build(); | 204 | .build(); |
207 | 205 | ||
208 | logger.info("platformServiceFee uid {},resp {}", uid, resp); | 206 | logger.info("platformServiceFee uid {},resp {}", uid, resp); |
209 | return resp; | 207 | return resp; |
210 | } | 208 | } |
211 | 209 | ||
210 | + /** | ||
211 | + * 当前 | ||
212 | + * @param uid | ||
213 | + * @return | ||
214 | + */ | ||
215 | + private SellerPlatformServiceFee getCurrentTimeSellerPlatformServiceFee(int uid) { | ||
216 | + //当前的扣点服务 | ||
217 | + SellerOrderStatsEntry currentStatsEntry = SellerOrderStatsEntry.builder().sellerUid(uid).orderAttribute(OrderAttributes.COMMON_IN_STOCK).time(DateUtil.getCurrentTimeSecond()).build(); | ||
218 | + SellerOrderStatsConfiguration currentStatsConfig = statsConfigurationManager.getStatsConfig(currentStatsEntry); | ||
219 | + return (SellerPlatformServiceFee)statsConfigurationManager.getStatsProcessor(currentStatsConfig.getStatsProcessorName()).apply(currentStatsEntry, currentStatsConfig); | ||
220 | + } | ||
221 | + | ||
222 | + /** | ||
223 | + * 下个周期的 | ||
224 | + * | ||
225 | + * @param uid | ||
226 | + * @return | ||
227 | + */ | ||
228 | + private SellerPlatformServiceFee getNextPeriodSellerPlatformServiceFee(int uid) { | ||
229 | + //下个周期 | ||
230 | + SellerOrderStatsEntry nextStatsEntry = SellerOrderStatsEntry.builder().sellerUid(uid).orderAttribute(OrderAttributes.COMMON_IN_STOCK).build(); | ||
231 | + SellerOrderStatsConfiguration nextStatsConfig = statsConfigurationManager.getStatsConfig(nextStatsEntry); | ||
232 | + Pair<Integer, Integer> nextValidityTimeTuple = nextStatsConfig.getStatsUnit().getValidityTimeTuple(nextStatsConfig.getStatsPeriod(), nextStatsConfig.getStatsPeriod()); | ||
233 | + //设置查询时间为下个周期的开始时间 | ||
234 | + nextStatsEntry.setTime(nextValidityTimeTuple.getKey()); | ||
235 | + return (SellerPlatformServiceFee) statsConfigurationManager.getStatsProcessor(nextStatsConfig.getStatsProcessorName()).apply(nextStatsEntry, nextStatsConfig); | ||
236 | + } | ||
237 | + | ||
212 | 238 | ||
213 | 239 | ||
214 | /** | 240 | /** |
@@ -18,11 +18,21 @@ public interface StatsProcessor<T extends StatsEntry, U extends StatsConfigurati | @@ -18,11 +18,21 @@ public interface StatsProcessor<T extends StatsEntry, U extends StatsConfigurati | ||
18 | String getName(); | 18 | String getName(); |
19 | 19 | ||
20 | /** | 20 | /** |
21 | - * 执行的动作 | 21 | + * 执行动作 |
22 | * | 22 | * |
23 | * @param t | 23 | * @param t |
24 | * @param u | 24 | * @param u |
25 | */ | 25 | */ |
26 | @Override | 26 | @Override |
27 | void accept(T t, U u); | 27 | void accept(T t, U u); |
28 | + | ||
29 | + /** | ||
30 | + * 获取结果 | ||
31 | + * | ||
32 | + * @param t | ||
33 | + * @param u | ||
34 | + * @return | ||
35 | + */ | ||
36 | + @Override | ||
37 | + R apply(T t, U u); | ||
28 | } | 38 | } |
1 | package com.yohoufo.order.service.stats.impl; | 1 | package com.yohoufo.order.service.stats.impl; |
2 | 2 | ||
3 | +import com.yohoufo.order.model.bo.PlatformServiceFeeDefinition; | ||
4 | +import com.yohoufo.order.model.bo.SellerPlatformServiceFee; | ||
3 | import com.yohoufo.order.service.stats.StatsProcessor; | 5 | import com.yohoufo.order.service.stats.StatsProcessor; |
4 | import com.yohoufo.order.utils.LoggerUtils; | 6 | import com.yohoufo.order.utils.LoggerUtils; |
5 | import org.slf4j.Logger; | 7 | import org.slf4j.Logger; |
@@ -10,7 +12,7 @@ import org.springframework.stereotype.Service; | @@ -10,7 +12,7 @@ import org.springframework.stereotype.Service; | ||
10 | * nothing to do | 12 | * nothing to do |
11 | */ | 13 | */ |
12 | @Service | 14 | @Service |
13 | -public class EmptyStatsProcessor implements StatsProcessor<SellerOrderStatsEntry, SellerOrderStatsConfiguration, Void> { | 15 | +public class EmptyStatsProcessor implements StatsProcessor<SellerOrderStatsEntry, SellerOrderStatsConfiguration, SellerPlatformServiceFee> { |
14 | 16 | ||
15 | private Logger logger = LoggerUtils.getSellerOrderLogger(); | 17 | private Logger logger = LoggerUtils.getSellerOrderLogger(); |
16 | 18 | ||
@@ -21,12 +23,12 @@ public class EmptyStatsProcessor implements StatsProcessor<SellerOrderStatsEntry | @@ -21,12 +23,12 @@ public class EmptyStatsProcessor implements StatsProcessor<SellerOrderStatsEntry | ||
21 | 23 | ||
22 | @Override | 24 | @Override |
23 | public void accept(SellerOrderStatsEntry entry, SellerOrderStatsConfiguration configuration) { | 25 | public void accept(SellerOrderStatsEntry entry, SellerOrderStatsConfiguration configuration) { |
24 | - logger.info("accept entry:{},configuration:{},nothing to do", entry, configuration); | 26 | + logger.info("emptyStatsProcessor accept entry:{},configuration:{},nothing to do", entry, configuration); |
25 | } | 27 | } |
26 | 28 | ||
27 | @Override | 29 | @Override |
28 | - public Void apply(SellerOrderStatsEntry entry, SellerOrderStatsConfiguration configuration) { | ||
29 | - logger.info("apply entry:{},configuration:{},nothing to do", entry, configuration); | ||
30 | - return null; | 30 | + public SellerPlatformServiceFee apply(SellerOrderStatsEntry entry, SellerOrderStatsConfiguration configuration) { |
31 | + logger.info("emptyStatsProcessor apply entry:{},configuration:{},nothing to do", entry, configuration); | ||
32 | + return new SellerPlatformServiceFee(0, new PlatformServiceFeeDefinition()); | ||
31 | } | 33 | } |
32 | } | 34 | } |
1 | package com.yohoufo.order.service.stats.impl; | 1 | package com.yohoufo.order.service.stats.impl; |
2 | 2 | ||
3 | -import com.yohoufo.common.utils.DateUtil; | ||
4 | import com.yohoufo.dal.order.SellerOrderStatsResultMapper; | 3 | import com.yohoufo.dal.order.SellerOrderStatsResultMapper; |
5 | import com.yohoufo.dal.order.model.SellerOrderStatsResult; | 4 | import com.yohoufo.dal.order.model.SellerOrderStatsResult; |
6 | import com.yohoufo.order.model.bo.PlatformServiceFeeDefinition; | 5 | import com.yohoufo.order.model.bo.PlatformServiceFeeDefinition; |
@@ -31,7 +30,7 @@ public class SellerOrderQuantityStatsProcessor implements StatsProcessor<SellerO | @@ -31,7 +30,7 @@ public class SellerOrderQuantityStatsProcessor implements StatsProcessor<SellerO | ||
31 | 30 | ||
32 | @Override | 31 | @Override |
33 | public void accept(SellerOrderStatsEntry entry, SellerOrderStatsConfiguration configuration) { | 32 | public void accept(SellerOrderStatsEntry entry, SellerOrderStatsConfiguration configuration) { |
34 | - logger.info("accept entry:{},configuration:{}", entry, configuration); | 33 | + logger.info("sellerOrderQuantityStatsProcessor accept entry:{},configuration:{}", entry, configuration); |
35 | 34 | ||
36 | Pair<Integer, Integer> timeTuple = configuration.getStatsUnit().getValidityTimeTuple(configuration.getStatsPeriod(), configuration.getStatsPeriod()); | 35 | Pair<Integer, Integer> timeTuple = configuration.getStatsUnit().getValidityTimeTuple(configuration.getStatsPeriod(), configuration.getStatsPeriod()); |
37 | 36 | ||
@@ -53,12 +52,12 @@ public class SellerOrderQuantityStatsProcessor implements StatsProcessor<SellerO | @@ -53,12 +52,12 @@ public class SellerOrderQuantityStatsProcessor implements StatsProcessor<SellerO | ||
53 | 52 | ||
54 | @Override | 53 | @Override |
55 | public SellerPlatformServiceFee apply(SellerOrderStatsEntry entry, SellerOrderStatsConfiguration configuration) { | 54 | public SellerPlatformServiceFee apply(SellerOrderStatsEntry entry, SellerOrderStatsConfiguration configuration) { |
56 | - logger.info("apply entry:{},configuration:{}", entry, configuration); | ||
57 | - SellerOrderStatsResult result = sellerOrderStatsResultMapper.selectStatsResult(entry.getSellerUid(), configuration.getStatsCode(), DateUtil.getCurrentTimeSecond()); | 55 | + logger.info("sellerOrderQuantityStatsProcessor apply entry:{},configuration:{}", entry, configuration); |
56 | + SellerOrderStatsResult result = sellerOrderStatsResultMapper.selectStatsResult(entry.getSellerUid(), configuration.getStatsCode(), entry.getTime()); | ||
58 | int quantity = (result != null) ? result.getQuantity() : 0; | 57 | int quantity = (result != null) ? result.getQuantity() : 0; |
59 | PlatformServiceFeeDefinition psfd = PlatformServiceFeeDefinition.convert(configuration.getActionParam()); | 58 | PlatformServiceFeeDefinition psfd = PlatformServiceFeeDefinition.convert(configuration.getActionParam()); |
60 | SellerPlatformServiceFee serviceFee = new SellerPlatformServiceFee(quantity, psfd); | 59 | SellerPlatformServiceFee serviceFee = new SellerPlatformServiceFee(quantity, psfd); |
61 | - logger.info("seller platform service fee is:{},statsResult:{},entry:{}", serviceFee, result, entry); | 60 | + logger.info("[{}] seller platform service statsResult:{}", entry.getSellerUid(),result); |
62 | return serviceFee; | 61 | return serviceFee; |
63 | } | 62 | } |
64 | } | 63 | } |
@@ -8,7 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -8,7 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
8 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
9 | 9 | ||
10 | import javax.annotation.PostConstruct; | 10 | import javax.annotation.PostConstruct; |
11 | -import java.util.Objects; | 11 | +import java.util.Optional; |
12 | 12 | ||
13 | /** | 13 | /** |
14 | * Created by jiexiang.wu on 2019/7/19. | 14 | * Created by jiexiang.wu on 2019/7/19. |
@@ -36,12 +36,12 @@ public class SellerOrderStatsConfigurationManager implements StatsConfigManager< | @@ -36,12 +36,12 @@ public class SellerOrderStatsConfigurationManager implements StatsConfigManager< | ||
36 | 36 | ||
37 | @Override | 37 | @Override |
38 | public SellerOrderStatsConfiguration getStatsConfig(SellerOrderStatsEntry statsEntry) { | 38 | public SellerOrderStatsConfiguration getStatsConfig(SellerOrderStatsEntry statsEntry) { |
39 | - SellerOrderStatsConfiguration configuration = sellerOrderStatsConfigCacheService.findBy(statsEntry.getOrderAttribute()); | ||
40 | - if (Objects.isNull(configuration) || configuration.getExcludeUids().stream().anyMatch(uid -> uid == statsEntry.getSellerUid())) { | 39 | + Optional<SellerOrderStatsConfiguration> configurationOp = sellerOrderStatsConfigCacheService.findBy(statsEntry.getOrderAttribute()); |
40 | + if (!configurationOp.isPresent() || configurationOp.get().getExcludeUids().stream().anyMatch(uid -> uid == statsEntry.getSellerUid())) { | ||
41 | // 没有找到配置项或卖家被排除 | 41 | // 没有找到配置项或卖家被排除 |
42 | return SellerOrderStatsConfiguration.emptyConfiguration; | 42 | return SellerOrderStatsConfiguration.emptyConfiguration; |
43 | } | 43 | } |
44 | - return configuration; | 44 | + return configurationOp.get(); |
45 | } | 45 | } |
46 | 46 | ||
47 | @Override | 47 | @Override |
@@ -18,4 +18,6 @@ public class SellerOrderStatsEntry implements StatsEntry { | @@ -18,4 +18,6 @@ public class SellerOrderStatsEntry implements StatsEntry { | ||
18 | private int buyerUid; | 18 | private int buyerUid; |
19 | private long buyerOrderCode; | 19 | private long buyerOrderCode; |
20 | private OrderAttributes orderAttribute; | 20 | private OrderAttributes orderAttribute; |
21 | + //查询时间 | ||
22 | + private int time; | ||
21 | } | 23 | } |
1 | package com.yohoufo.order.service.support; | 1 | package com.yohoufo.order.service.support; |
2 | 2 | ||
3 | -import com.google.common.collect.Lists; | 3 | +import com.yoho.core.common.utils.DateUtil; |
4 | import com.yohobuy.ufo.model.order.common.OrderAttributes; | 4 | import com.yohobuy.ufo.model.order.common.OrderAttributes; |
5 | -import com.yohobuy.ufo.model.order.resp.SellerPlatformServiceFeeResp; | ||
6 | import com.yohoufo.order.model.bo.SellerPlatformServiceFee; | 5 | import com.yohoufo.order.model.bo.SellerPlatformServiceFee; |
7 | import com.yohoufo.order.service.stats.StatsConfigManager; | 6 | import com.yohoufo.order.service.stats.StatsConfigManager; |
8 | import com.yohoufo.order.service.stats.impl.SellerOrderStatsConfiguration; | 7 | import com.yohoufo.order.service.stats.impl.SellerOrderStatsConfiguration; |
@@ -13,7 +12,6 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -13,7 +12,6 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
13 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
14 | 13 | ||
15 | import java.math.BigDecimal; | 14 | import java.math.BigDecimal; |
16 | -import java.util.Objects; | ||
17 | 15 | ||
18 | /** | 16 | /** |
19 | * Created by jiexiang.wu on 2019/7/23. | 17 | * Created by jiexiang.wu on 2019/7/23. |
@@ -35,16 +33,13 @@ public class SellerPlatformServiceFeeSupport { | @@ -35,16 +33,13 @@ public class SellerPlatformServiceFeeSupport { | ||
35 | */ | 33 | */ |
36 | public BigDecimal getPlatformServiceFeeRate(int uid, OrderAttributes orderAttributes) { | 34 | public BigDecimal getPlatformServiceFeeRate(int uid, OrderAttributes orderAttributes) { |
37 | logger.info("platformServiceFeeRate,uid {}, attribute:{}", uid, orderAttributes); | 35 | logger.info("platformServiceFeeRate,uid {}, attribute:{}", uid, orderAttributes); |
38 | - SellerOrderStatsEntry statsEntry = SellerOrderStatsEntry.builder().sellerUid(uid).orderAttribute(orderAttributes).build(); | 36 | + |
37 | + SellerOrderStatsEntry statsEntry = SellerOrderStatsEntry.builder().sellerUid(uid).orderAttribute(orderAttributes).time(DateUtil.getCurrentTimeSecond()).build(); | ||
39 | 38 | ||
40 | SellerOrderStatsConfiguration statsConfig = statsConfigurationManager.getStatsConfig(statsEntry); | 39 | SellerOrderStatsConfiguration statsConfig = statsConfigurationManager.getStatsConfig(statsEntry); |
41 | 40 | ||
42 | SellerPlatformServiceFee serviceFee = (SellerPlatformServiceFee) statsConfigurationManager.getStatsProcessor(statsConfig.getStatsProcessorName()).apply(statsEntry, statsConfig); | 41 | SellerPlatformServiceFee serviceFee = (SellerPlatformServiceFee) statsConfigurationManager.getStatsProcessor(statsConfig.getStatsProcessorName()).apply(statsEntry, statsConfig); |
43 | 42 | ||
44 | - if (Objects.isNull(serviceFee)) { | ||
45 | - logger.info("platformServiceFeeRate is null for uid {}", uid); | ||
46 | - return null; | ||
47 | - } | ||
48 | return serviceFee.getFeeRate(); | 43 | return serviceFee.getFeeRate(); |
49 | } | 44 | } |
50 | } | 45 | } |
-
Please register or login to post a comment