Commit 11227f2b 11227f2b39a95167c8936030165f7643256d28e4 by xianghan@topdraw.cn

优化部分接口,积分消耗添加分布式锁

1 parent 509a2011
...@@ -59,6 +59,7 @@ public class PointsOperationController { ...@@ -59,6 +59,7 @@ public class PointsOperationController {
59 @PostMapping(value = "/grantPointsByManual") 59 @PostMapping(value = "/grantPointsByManual")
60 @ApiOperation("新增PointsDetail") 60 @ApiOperation("新增PointsDetail")
61 public ResultInfo grantPointsByManual(@Validated @RequestBody TempPoints tempPoints) { 61 public ResultInfo grantPointsByManual(@Validated @RequestBody TempPoints tempPoints) {
62 LOG.info("======>>>>> grantPointsByManual start");
62 Long memberId = tempPoints.getMemberId(); 63 Long memberId = tempPoints.getMemberId();
63 this.pointsOperationService.grantPointsByManual(memberId,tempPoints); 64 this.pointsOperationService.grantPointsByManual(memberId,tempPoints);
64 return ResultInfo.success(); 65 return ResultInfo.success();
......
...@@ -57,12 +57,15 @@ public class CouponOperationServiceImpl implements CouponOperationService { ...@@ -57,12 +57,15 @@ public class CouponOperationServiceImpl implements CouponOperationService {
57 /** 57 /**
58 * 手动发放优惠券 58 * 手动发放优惠券
59 * @param memberId 会员id 59 * @param memberId 会员id
60 * @param userId 账户id
60 * @param tempCouponList 61 * @param tempCouponList
61 */ 62 */
62 @Override 63 @Override
63 public void grantCouponByManual(Long memberId,Long userId ,List<TempCoupon> tempCouponList) { 64 public void grantCouponByManual(Long memberId,Long userId ,List<TempCoupon> tempCouponList) {
64 // 优惠券领取、使用历史记录表 65 // 优惠券领取、使用历史记录表
65 for (TempCoupon tempCoupon : tempCouponList) { 66 for (TempCoupon tempCoupon : tempCouponList) {
67 tempCoupon.setMemberId(memberId);
68 tempCoupon.setUserId(userId);
66 this.refresh(tempCoupon); 69 this.refresh(tempCoupon);
67 } 70 }
68 } 71 }
......
...@@ -88,7 +88,7 @@ public class ExpOperationServiceImpl implements ExpOperationService { ...@@ -88,7 +88,7 @@ public class ExpOperationServiceImpl implements ExpOperationService {
88 88
89 Long memberId = tempExp.getMemberId(); 89 Long memberId = tempExp.getMemberId();
90 90
91 RLock rLock = this.redissonClient.getLock("refresh" + memberId.toString()); 91 RLock rLock = this.redissonClient.getLock("refreshMemberExpAndLevel" + memberId.toString());
92 try { 92 try {
93 RedissonUtil.lock(rLock); 93 RedissonUtil.lock(rLock);
94 // 1.获取当前成长值 94 // 1.获取当前成长值
......
...@@ -82,26 +82,39 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -82,26 +82,39 @@ public class PointsOperationServiceImpl implements PointsOperationService {
82 @Transactional(rollbackFor = Exception.class) 82 @Transactional(rollbackFor = Exception.class)
83 public boolean customPoints(TempPoints tempPoints) { 83 public boolean customPoints(TempPoints tempPoints) {
84 Long memberId = tempPoints.getMemberId(); 84 Long memberId = tempPoints.getMemberId();
85
86 RLock rLock = this.redissonClient.getLock("refresh" + memberId.toString());
87 try {
88 RedissonUtil.lock(rLock);
85 // 1.判断可用积分是否够用 89 // 1.判断可用积分是否够用
86 boolean b = this.checkAvailablePoints(tempPoints); 90 boolean b = this.checkAvailablePoints(tempPoints);
87 if (b) { 91 if (b) {
88 // 当前可用总积分
89 long currentPoints = this.findAvailablePointsByMemberId(memberId);
90 // 1.可用积分表,按照过期时间进行升序排列 92 // 1.可用积分表,按照过期时间进行升序排列
93 // TODO 删除过期的积分
91 List<PointsAvailableDTO> pointsAvailableDTOS = this.findByMemberIdOrderByExpireTime(tempPoints); 94 List<PointsAvailableDTO> pointsAvailableDTOS = this.findByMemberIdOrderByExpireTime(tempPoints);
95
96 // 当前可用总积分
97 long currentPoints = this.findAvailablePointsByMemberId(memberId);
92 // 2.优先使用即将过期的积分,累加到超过需兑换积分时,需要进行拆分 98 // 2.优先使用即将过期的积分,累加到超过需兑换积分时,需要进行拆分
93 Map<String, List<PointsAvailableDTO>> customAvailablePointsMap = this.customAvailablePoints(tempPoints, pointsAvailableDTOS); 99 Map<String, List<PointsAvailableDTO>> customAvailablePointsMap = this.customAvailablePoints(tempPoints, pointsAvailableDTOS);
94 // 3.添加积分明细 100 // 3.添加积分明细
95 this.doInsertTrPointsDetailByAvailablePointsMap(tempPoints,customAvailablePointsMap,currentPoints); 101 this.doInsertTrPointsDetailByAvailablePointsMap(tempPoints, customAvailablePointsMap, currentPoints);
96 // 4.更新可用积分表,超过的删除,剩余的新增 102 // 4.更新可用积分表,超过的删除,剩余的新增
97 long totalPoints = this.doFreshTrPointsAvailableByAvailablePointsMap(customAvailablePointsMap,currentPoints); 103 long totalPoints = this.doFreshTrPointsAvailableByAvailablePointsMap(customAvailablePointsMap, currentPoints);
98 // 4.获取即将过期的积分 104 // 4.获取即将过期的积分
99 long soonExpireTime = this.getSoonExpirePoints(memberId,tempPoints); 105 // TODO 不用在这里查询
106 long soonExpireTime = this.getSoonExpirePoints(memberId, tempPoints);
100 // 6.更新会员积分信息 107 // 6.更新会员积分信息
101 this.freshMemberCurrentPoints(memberId,totalPoints,soonExpireTime); 108 this.freshMemberCurrentPoints(memberId, totalPoints, soonExpireTime);
102 109
103 return true; 110 return true;
104 } 111 }
112 }catch (Exception e) {
113 e.printStackTrace();
114 throw e;
115 } finally {
116 RedissonUtil.unlock(rLock);
117 }
105 118
106 return false; 119 return false;
107 } 120 }
...@@ -140,7 +153,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -140,7 +153,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
140 } 153 }
141 154
142 /** 155 /**
143 * 优先使用即将过期的积分,累加到超过需兑换积分时,需要进行拆分 156 * 优先使用即将过期的积分,注意拆分
144 * @param customAvailablePointsMap 157 * @param customAvailablePointsMap
145 */ 158 */
146 private void doInsertTrPointsDetailByAvailablePointsMap(TempPoints tempPoints, 159 private void doInsertTrPointsDetailByAvailablePointsMap(TempPoints tempPoints,
...@@ -159,7 +172,8 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -159,7 +172,8 @@ public class PointsOperationServiceImpl implements PointsOperationService {
159 BeanUtils.copyProperties(pointsAvailableDTO,tempPoints1); 172 BeanUtils.copyProperties(pointsAvailableDTO,tempPoints1);
160 BeanUtils.copyProperties(tempPoints,tempPoints1); 173 BeanUtils.copyProperties(tempPoints,tempPoints1);
161 tempPoints1.setPoints(-(Math.abs(points))); 174 tempPoints1.setPoints(-(Math.abs(points)));
162 this.doInsertTrPointsDetail(memberId,tempPoints1,currentPoints); 175 long totalPoints = this.calculateTotalPoints(tempPoints1, currentPoints);
176 this.doInsertTrPointsDetail(memberId,tempPoints1,currentPoints,totalPoints);
163 } 177 }
164 } 178 }
165 179
...@@ -330,9 +344,13 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -330,9 +344,13 @@ public class PointsOperationServiceImpl implements PointsOperationService {
330 RedissonUtil.lock(rLock); 344 RedissonUtil.lock(rLock);
331 // 1.可用总积分 345 // 1.可用总积分
332 long currentPoints = this.findAvailablePointsByMemberId(memberId); 346 long currentPoints = this.findAvailablePointsByMemberId(memberId);
347 // 2.计算总积分
348 long totalPoints = this.calculateTotalPoints(tempPoints, currentPoints);
333 // 2.添加积分明细,并计算总积分 349 // 2.添加积分明细,并计算总积分
334 long totalPoints = this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints); 350 // TODO 把计算总积分的过程单独提取出来,保存积分流水的时候可以异步
351 this.doInsertTrPointsDetail(memberId, tempPoints, currentPoints,totalPoints);
335 // 3.获取即将过期的积分 352 // 3.获取即将过期的积分
353 // TODO 不需要在这里查询过期积分,用的时候再去查看
336 long soonExpireTime = this.getSoonExpirePoints(memberId, tempPoints); 354 long soonExpireTime = this.getSoonExpirePoints(memberId, tempPoints);
337 // 4.更新会员的总积分 355 // 4.更新会员的总积分
338 this.freshMemberCurrentPoints(memberId, totalPoints, soonExpireTime); 356 this.freshMemberCurrentPoints(memberId, totalPoints, soonExpireTime);
...@@ -347,6 +365,20 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -347,6 +365,20 @@ public class PointsOperationServiceImpl implements PointsOperationService {
347 } 365 }
348 366
349 /** 367 /**
368 * 获取总积分
369 * @param tempPoints
370 * @param currentPoints
371 * @return
372 */
373 private long calculateTotalPoints(TempPoints tempPoints, long currentPoints) {
374 // 获取的积分
375 long rewardPoints = tempPoints.getPoints();
376 // 总积分
377 long totalPoints = currentPoints + rewardPoints;
378 return totalPoints;
379 }
380
381 /**
350 * 获取即将过期的积分 382 * 获取即将过期的积分
351 * @param memberId 383 * @param memberId
352 * @return 384 * @return
...@@ -436,22 +468,22 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -436,22 +468,22 @@ public class PointsOperationServiceImpl implements PointsOperationService {
436 * @param tempPoints 积分 468 * @param tempPoints 积分
437 * @return Integer 总积分 469 * @return Integer 总积分
438 */ 470 */
439 private long doInsertTrPointsDetail(Long memberId, TempPoints tempPoints,long currentPoints){ 471 private void doInsertTrPointsDetail(Long memberId, TempPoints tempPoints,long totalPoints,long currentPoints){
440 472
441 PointsDetail pointsDetail = new PointsDetail(); 473 PointsDetail pointsDetail = new PointsDetail();
442 BeanUtils.copyProperties(tempPoints,pointsDetail); 474 BeanUtils.copyProperties(tempPoints,pointsDetail);
443 475
444 // 获取的积分 476 /* // 获取的积分
445 long rewardPoints = tempPoints.getPoints(); 477 long rewardPoints = tempPoints.getPoints();
446 // 原始积分 478 // 原始积分
447 long originalPoints = currentPoints; 479 long originalPoints = currentPoints;
448 // 总积分 480 // 总积分
449 long totalPoints = originalPoints + rewardPoints; 481 long totalPoints = originalPoints + rewardPoints;*/
450 482
451 pointsDetail.setMemberId(memberId); 483 pointsDetail.setMemberId(memberId);
452 pointsDetail.setCode(String.valueOf(IdWorker.generator())); 484 pointsDetail.setCode(String.valueOf(IdWorker.generator()));
453 485
454 pointsDetail.setOriginalPoints(originalPoints); 486 pointsDetail.setOriginalPoints(currentPoints);
455 pointsDetail.setResultPoints(totalPoints); 487 pointsDetail.setResultPoints(totalPoints);
456 String description = pointsDetail.getDescription(); 488 String description = pointsDetail.getDescription();
457 if (StringUtils.isEmpty(description)) { 489 if (StringUtils.isEmpty(description)) {
...@@ -461,8 +493,6 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -461,8 +493,6 @@ public class PointsOperationServiceImpl implements PointsOperationService {
461 // 保存积分流水 493 // 保存积分流水
462 this.doInsertPointsDetail(pointsDetail); 494 this.doInsertPointsDetail(pointsDetail);
463 495
464 return totalPoints;
465
466 } 496 }
467 497
468 /** 498 /**
......
...@@ -19,6 +19,7 @@ import org.springframework.stereotype.Service; ...@@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
19 import org.springframework.util.CollectionUtils; 19 import org.springframework.util.CollectionUtils;
20 20
21 import javax.annotation.Resource; 21 import javax.annotation.Resource;
22 import java.sql.Timestamp;
22 import java.util.*; 23 import java.util.*;
23 24
24 /** 25 /**
...@@ -76,7 +77,6 @@ public class RightsOperationServiceImpl implements RightsOperationService { ...@@ -76,7 +77,6 @@ public class RightsOperationServiceImpl implements RightsOperationService {
76 this.doInsertTrRightHistory(rightsList); 77 this.doInsertTrRightHistory(rightsList);
77 } 78 }
78 79
79
80 /** 80 /**
81 * 81 *
82 * @param tempRightsMap 82 * @param tempRightsMap
...@@ -169,29 +169,68 @@ public class RightsOperationServiceImpl implements RightsOperationService { ...@@ -169,29 +169,68 @@ public class RightsOperationServiceImpl implements RightsOperationService {
169 169
170 // 优惠券 170 // 优惠券
171 List<TempCoupon> tempCouponList = new ArrayList<>(); 171 List<TempCoupon> tempCouponList = new ArrayList<>();
172 List<TempExp> tempExpList = new ArrayList<>();
173 List<TempPoints> tempPointsList = new ArrayList<>();
174
172 for (RightsHistory right : rightsList) { 175 for (RightsHistory right : rightsList) {
173 Long rightId = right.getRightsId(); 176 Long rightId = right.getRightsId();
174 Long memberId = right.getMemberId(); 177 Long memberId = right.getMemberId();
175 Long userId = right.getUserId(); 178 Long userId = right.getUserId();
176 // 权益类型 179 // 权益类型
177 RightsDTO rightsDTO = this.getRights(rightId); 180 RightsDTO rightsDTO = this.getRights(rightId);
178 Integer type = rightsDTO.getType(); 181 // 权益的实体类型 1:积分;2成长值;3优惠券
182 String type = rightsDTO.getEntityType();
183 String code = rightsDTO.getCode();
184 Long expireTime = rightsDTO.getExpireTime();
185 Timestamp validTime = rightsDTO.getValidTime();
186
187
188 switch (type) {
179 // 优惠券 189 // 优惠券
180 if (type == 1) { 190 case "3":
181 TempCoupon tempCoupon = new TempCoupon(); 191 TempCoupon tempCoupon = new TempCoupon();
182 tempCoupon.setId(rightId); 192 tempCoupon.setId(rightId);
183 tempCoupon.setMemberId(memberId); 193 tempCoupon.setMemberId(memberId);
184 tempCoupon.setUserId(userId); 194 tempCoupon.setUserId(userId);
185 tempCoupon.setRightsAmount(1); 195 tempCoupon.setRightsAmount(1);
186 tempCoupon.setRightsSendStrategy(0); 196 tempCoupon.setRightsSendStrategy(0);
197 tempCoupon.setExpireTime(TimestampUtil.long2Timestamp(expireTime));
187 tempCouponList.add(tempCoupon); 198 tempCouponList.add(tempCoupon);
199 break;
200 // 成长值
201 case "2":
202 TempExp tempExp = new TempExp();
203 tempExp.setId(rightId);
204 tempExp.setMemberId(memberId);
205 tempExp.setUserId(userId);
206 tempExp.setRightsAmount(1);
207 tempExp.setRightsSendStrategy(0);
208 tempExpList.add(tempExp);
209 break;
210 // 积分
211 case "1":
212 TempPoints tempPoints = new TempPoints();
213 tempPoints.setId(rightId);
214 tempPoints.setMemberId(memberId);
215 tempPoints.setUserId(userId);
216 tempPoints.setRightsAmount(1);
217 tempPoints.setRightsSendStrategy(0);
218 tempPointsList.add(tempPoints);
219 break;
188 } 220 }
189 } 221 }
190 222
191 // TODO 其他 223 // TODO 其他
192 224
193 // 优惠券 225 // 优惠券
226 if (!CollectionUtils.isEmpty(tempCouponList))
194 map.put(RightType.COUPON,tempCouponList); 227 map.put(RightType.COUPON,tempCouponList);
228 // 成长值
229 if (!CollectionUtils.isEmpty(tempExpList))
230 map.put(RightType.EXP,tempExpList);
231 // 积分
232 if (!CollectionUtils.isEmpty(tempPointsList))
233 map.put(RightType.POINTS,tempPointsList);
195 234
196 return map; 235 return map;
197 } 236 }
......
...@@ -23,6 +23,7 @@ import com.topdraw.util.*; ...@@ -23,6 +23,7 @@ import com.topdraw.util.*;
23 import org.slf4j.Logger; 23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory; 24 import org.slf4j.LoggerFactory;
25 import org.springframework.beans.factory.annotation.Autowired; 25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.cache.annotation.EnableCaching;
26 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 27 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
27 import org.springframework.stereotype.Service; 28 import org.springframework.stereotype.Service;
28 import org.springframework.util.CollectionUtils; 29 import org.springframework.util.CollectionUtils;
...@@ -81,7 +82,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -81,7 +82,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
81 DataSyncMsg.MsgData msgData = dataSyncMsg.getMsg(); 82 DataSyncMsg.MsgData msgData = dataSyncMsg.getMsg();
82 Long memberId = msgData.getMemberId(); 83 Long memberId = msgData.getMemberId();
83 84
84 // 1.通过任务标识获取任务模板 85 // 1.通过任务标识获取任务模板,通过模板参数获取具体的模板
85 TaskTemplate taskTemplate = this.getTaskTemplate(eventType); 86 TaskTemplate taskTemplate = this.getTaskTemplate(eventType);
86 // 2.解析模板参数 87 // 2.解析模板参数
87 Map<String,Object> paramMap = this.parseTaskTemplateParam(taskTemplate); 88 Map<String,Object> paramMap = this.parseTaskTemplateParam(taskTemplate);
...@@ -92,12 +93,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -92,12 +93,8 @@ public class TaskOperationServiceImpl implements TaskOperationService {
92 if (checkResult) { 93 if (checkResult) {
93 // 5.权益区分(积分、权益、成长值) 94 // 5.权益区分(积分、权益、成长值)
94 Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId,taskList,msgData); 95 Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId,taskList,msgData);
95 // 6.永久权益 96 // 6.权益发放
96 PermanentRightsDTO permanentRights = this.getPermanentRights(memberId); 97 this.grantRight(tempRightsMap);
97 // 7.永久权益计算之后的权益
98 Map<RightType, Object> rightTypeObjectMap = this.calculateRight(permanentRights, tempRightsMap, memberId);
99 // 8..权益发放
100 this.grantRight(rightTypeObjectMap);
101 } 98 }
102 99
103 long r = System.currentTimeMillis(); 100 long r = System.currentTimeMillis();
...@@ -201,6 +198,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -201,6 +198,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
201 * @param permanentRights 198 * @param permanentRights
202 * @param map 199 * @param map
203 */ 200 */
201 @Deprecated
204 private Map<RightType, Object> calculateRight(PermanentRightsDTO permanentRights, Map<RightType, Object> map,Long memberId) { 202 private Map<RightType, Object> calculateRight(PermanentRightsDTO permanentRights, Map<RightType, Object> map,Long memberId) {
205 203
206 // 验证永久权益 204 // 验证永久权益
...@@ -229,6 +227,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -229,6 +227,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
229 * @param tempPointsList 积分 227 * @param tempPointsList 积分
230 * @return BigDecimal 总积分 228 * @return BigDecimal 总积分
231 */ 229 */
230 @Deprecated
232 private BigDecimal calculateTotalPoints(PermanentRightsDTO permanentRights, List<TempPoints> tempPointsList) { 231 private BigDecimal calculateTotalPoints(PermanentRightsDTO permanentRights, List<TempPoints> tempPointsList) {
233 232
234 // 总积分 233 // 总积分
...@@ -337,7 +336,8 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -337,7 +336,8 @@ public class TaskOperationServiceImpl implements TaskOperationService {
337 * @param task 336 * @param task
338 * @return 337 * @return
339 */ 338 */
340 private Map<RightType,Object> getTempRight(Long memberId , Task task,Map<RightType,Object> map) { 339 private Map<RightType,Object> getTempRight(Long memberId , Task task , Map<RightType,Object> map) {
340
341 // 优惠券 341 // 优惠券
342 List<TempCoupon> tempCouponList = new ArrayList<>(); 342 List<TempCoupon> tempCouponList = new ArrayList<>();
343 // 权益列表,用以保存权益记录 343 // 权益列表,用以保存权益记录
...@@ -346,88 +346,67 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -346,88 +346,67 @@ public class TaskOperationServiceImpl implements TaskOperationService {
346 // 权益1 346 // 权益1
347 Long rights1Id = task.getRightsId(); 347 Long rights1Id = task.getRightsId();
348 if (Objects.nonNull(rights1Id)) { 348 if (Objects.nonNull(rights1Id)) {
349 // 权益详情
350 RightsDTO rightsDTO = this.getRight(rights1Id);
351 // 领取的权益数量 349 // 领取的权益数量
352 Integer rights1Amount = task.getRightsAmount(); 350 Integer rights1Amount = task.getRightsAmount();
353 // TODO 权益1发放的策略 351 // TODO 权益1发放的策略
354 Integer rightsSendStrategy = task.getRightsSendStrategy(); 352 Integer rightsSendStrategy = task.getRightsSendStrategy();
355 353 // 权益分类
356 if (Objects.nonNull(rightsDTO)){ 354 this.getTempRightType(memberId,rights1Id,rights1Amount,rightsSendStrategy,tempCouponList,rightsList);
357 // 用以保存权益历史
358 Long expireTime = rightsDTO.getExpireTime();
359 TempRights tempRights = this.tmpRightsBuild(memberId,rights1Id,rights1Amount,expireTime);
360 rightsList.add(tempRights);
361
362 // 权益类型
363 Integer type = rightsDTO.getType();
364 switch (type) {
365 case 1:
366 // 优惠券
367 TempCoupon tempCoupon = this.tempCouponBuild(memberId,rights1Id,rights1Amount,rightsSendStrategy);
368 tempCouponList.add(tempCoupon);
369 break;
370 default:
371 break;
372 }
373 }
374 } 355 }
375 356
376 // 权益2 357 // 权益2
377 Long rights2Id = task.getRights2Id(); 358 Long rights2Id = task.getRights2Id();
378 if (Objects.nonNull(rights2Id)) { 359 if (Objects.nonNull(rights2Id)) {
379
380 // 权益详情
381 RightsDTO rightsDTO = this.getRight(rights2Id);
382
383 Integer rights2Amount = task.getRights2Amount(); 360 Integer rights2Amount = task.getRights2Amount();
384 // TODO 权益2发放的策略 361 // TODO 权益2发放的策略
385 Integer rightsSendStrategy = task.getRightsSendStrategy(); 362 Integer rightsSendStrategy = task.getRightsSendStrategy();
386 363 // 权权益分类
387 if (Objects.nonNull(rightsDTO)) { 364 this.getTempRightType(memberId,rights2Id,rights2Amount,rightsSendStrategy,tempCouponList,rightsList);
388 // 用以保存权益历史
389 Long expireTime = rightsDTO.getExpireTime();
390 TempRights tempRights = this.tmpRightsBuild(memberId,rights2Id,rights2Amount,expireTime);
391 rightsList.add(tempRights);
392
393 // 权益类型
394 Integer type = rightsDTO.getType();
395 switch (type) {
396 case 1:
397 // 优惠券
398 TempCoupon tempCoupon = this.tempCouponBuild(memberId,rights2Id,rights2Amount,rightsSendStrategy);
399 tempCouponList.add(tempCoupon);
400 break;
401 default:
402 break;
403 }
404
405 }
406 } 365 }
407 366
408 // 权益3 367 // 权益3
409 Long rights3Id = task.getRights3Id(); 368 Long rights3Id = task.getRights3Id();
410 if (Objects.nonNull(rights3Id)) { 369 if (Objects.nonNull(rights3Id)) {
411
412 // 权益详情
413 RightsDTO rightsDTO = this.getRight(rights3Id);
414
415 Integer rights3Amount = task.getRights3Amount(); 370 Integer rights3Amount = task.getRights3Amount();
416 // TODO 权益3发放的策略 371 // TODO 权益3发放的策略
417 Integer rightsSendStrategy = task.getRightsSendStrategy(); 372 Integer rightsSendStrategy = task.getRightsSendStrategy();
373 // 权益分类
374 this.getTempRightType(memberId,rights3Id,rights3Amount,rightsSendStrategy,tempCouponList,rightsList);
375 }
376 // 优惠券
377 map.put(RightType.COUPON,tempCouponList);
378 map.put(RightType.RIGHTS,rightsList);
379 return map;
380 }
381
382 /**
383 * 权益分类
384 * @param memberId
385 * @param rightsId
386 * @param rightsAmount
387 * @param rightsSendStrategy
388 * @param tempCouponList
389 * @param rightsList
390 */
391 private void getTempRightType(Long memberId , Long rightsId, Integer rightsAmount,Integer rightsSendStrategy,List<TempCoupon> tempCouponList,
392 List<TempRights> rightsList) {
393
394
395 // 权益详情
396 RightsDTO rightsDTO = this.getRight(rightsId);
418 397
419 if (Objects.nonNull(rightsDTO)){ 398 if (Objects.nonNull(rightsDTO)){
420 // 用以保存权益历史 399 // 用以保存权益历史
421 Long expireTime = rightsDTO.getExpireTime(); 400 Long expireTime = rightsDTO.getExpireTime();
422 TempRights tempRights = this.tmpRightsBuild(memberId,rights3Id,rights3Amount,expireTime); 401 TempRights tempRights = this.tmpRightsBuild(memberId,rightsId,rightsAmount,expireTime);
423 rightsList.add(tempRights); 402 rightsList.add(tempRights);
424 403
425 // 权益类型 404 // 权益类型
426 Integer type = rightsDTO.getType(); 405 String type = rightsDTO.getEntityType();
427 switch (type) { 406 switch (type) {
428 case 1: 407 case "1":
429 // 优惠券 408 // 优惠券
430 TempCoupon tempCoupon = this.tempCouponBuild(memberId,rights3Id,rights3Amount,rightsSendStrategy); 409 TempCoupon tempCoupon = this.tempCouponBuild(memberId,rightsId,rightsAmount,rightsSendStrategy);
431 tempCouponList.add(tempCoupon); 410 tempCouponList.add(tempCoupon);
432 break; 411 break;
433 default: 412 default:
...@@ -435,11 +414,6 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -435,11 +414,6 @@ public class TaskOperationServiceImpl implements TaskOperationService {
435 } 414 }
436 } 415 }
437 } 416 }
438 // 优惠券
439 map.put(RightType.COUPON,tempCouponList);
440 map.put(RightType.RIGHTS,rightsList);
441 return map;
442 }
443 417
444 /** 418 /**
445 * 419 *
...@@ -522,9 +496,9 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -522,9 +496,9 @@ public class TaskOperationServiceImpl implements TaskOperationService {
522 * 判断任务是否完成 496 * 判断任务是否完成
523 * 完成的条件如下:-> 497 * 完成的条件如下:->
524 * 1. status 当前任务的状态 0:失效;1:生效 498 * 1. status 当前任务的状态 0:失效;1:生效
525 * 1. task_repeat_type 任务重复类型,-1:不限次;1:单次;>1:多次
526 * 2. valid_time 任务生效时间 499 * 2. valid_time 任务生效时间
527 * 3. expire_time 任务失效时间 500 * 3. expire_time 任务失效时间
501 * 1. task_repeat_type 任务重复类型,-1:不限次;1:单次;>1:多次
528 * 5. member_level 会员等级门槛(0表示无门槛) 502 * 5. member_level 会员等级门槛(0表示无门槛)
529 * 6. member_vip 会员vip门槛(0表示没有门槛) 503 * 6. member_vip 会员vip门槛(0表示没有门槛)
530 * 7. groups 能够获取该任务的用户分组,为空则都能获取 504 * 7. groups 能够获取该任务的用户分组,为空则都能获取
...@@ -533,6 +507,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -533,6 +507,7 @@ public class TaskOperationServiceImpl implements TaskOperationService {
533 * @param taskList 任务列表 507 * @param taskList 任务列表
534 * @return boolean true:success false:fail 508 * @return boolean true:success false:fail
535 */ 509 */
510 //<taskId,boolean>
536 private boolean checkTaskCompletion(Long memberId , List<Task> taskList) { 511 private boolean checkTaskCompletion(Long memberId , List<Task> taskList) {
537 if (!CollectionUtils.isEmpty(taskList)) { 512 if (!CollectionUtils.isEmpty(taskList)) {
538 // 会员信息 513 // 会员信息
...@@ -542,11 +517,11 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -542,11 +517,11 @@ public class TaskOperationServiceImpl implements TaskOperationService {
542 517
543 List<Task> taskStream = taskList1.stream().filter(task1 -> 518 List<Task> taskStream = taskList1.stream().filter(task1 ->
544 task1.getStatus() == 1 && 519 task1.getStatus() == 1 &&
545 (Objects.isNull(task1.getExpireTime()) || task1.getExpireTime().compareTo(TimestampUtil.now()) <= 0) && 520 (Objects.isNull(task1.getExpireTime()) || task1.getExpireTime().compareTo(TimestampUtil.now()) >= 0) &&
546 (Objects.isNull(task1.getGroups()) || task1.getGroups().equalsIgnoreCase(memberDTO1.getGroups())) && 521 (Objects.isNull(task1.getGroups()) || task1.getGroups().equalsIgnoreCase(memberDTO1.getGroups())) &&
547 (Objects.isNull(task1.getValidTime()) || task1.getValidTime().compareTo(TimestampUtil.now()) <= 0) && 522 (Objects.isNull(task1.getValidTime()) || task1.getValidTime().compareTo(TimestampUtil.now()) <= 0) &&
548 (Objects.isNull(task1.getMemberLevel()) || task1.getMemberLevel() == 0 || task1.getMemberLevel() <= memberDTO1.getLevel()) && 523 (Objects.isNull(task1.getMemberLevel()) || task1.getMemberLevel() == 0 || task1.getMemberLevel() <= memberDTO1.getLevel()) &&
549 (Objects.isNull(task1.getMemberVip()) || task1.getMemberVip() == 0 || task1.getMemberVip() == memberDTO1.getVip()) 524 (Objects.isNull(task1.getMemberVip()) || task1.getMemberVip() == 0 || task1.getMemberVip() <= memberDTO1.getVip())
550 ).collect(Collectors.toList()); 525 ).collect(Collectors.toList());
551 526
552 if (CollectionUtils.isEmpty(taskStream)) { 527 if (CollectionUtils.isEmpty(taskStream)) {
...@@ -564,6 +539,9 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -564,6 +539,9 @@ public class TaskOperationServiceImpl implements TaskOperationService {
564 539
565 /** 540 /**
566 * 检查并更新当前任务的完成情况 541 * 检查并更新当前任务的完成情况
542 *
543 * 1.每天都能做,但要求总次数达到行为量
544 *
567 * @param memberId 545 * @param memberId
568 * @param taskStream 546 * @param taskStream
569 * @return boolean false:失败 true:成功 547 * @return boolean false:失败 true:成功
......
...@@ -22,9 +22,9 @@ import java.util.List; ...@@ -22,9 +22,9 @@ import java.util.List;
22 /** 22 /**
23 * 积分台账 23 * 积分台账
24 */ 24 */
25 @Component 25 //@Component
26 @Slf4j 26 //@Slf4j
27 @EnableScheduling 27 //@EnableScheduling
28 public class ScheduledTask { 28 public class ScheduledTask {
29 29
30 @Autowired 30 @Autowired
...@@ -35,9 +35,9 @@ public class ScheduledTask { ...@@ -35,9 +35,9 @@ public class ScheduledTask {
35 /** 35 /**
36 * 清理已过期的积分 36 * 清理已过期的积分
37 */ 37 */
38 @Scheduled(cron = "0 0/1 * * * ? ") 38 // @Scheduled(cron = "0 0/1 * * * ? ")
39 public void cleanValidAvailablePoints(){ 39 public void cleanValidAvailablePoints(){
40 this.pointsOperationService.cleanInvalidAvailablePoints(); 40 // this.pointsOperationService.cleanInvalidAvailablePoints();
41 } 41 }
42 42
43 } 43 }
......