Commit 2cf78f54 2cf78f54f653d5ac16380083dac5500b94da5866 by xianghan@topdraw.cn

修复清理积分接口

1 parent a1507fc5
...@@ -91,4 +91,6 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable ...@@ -91,4 +91,6 @@ public interface PointsAvailableRepository extends JpaRepository<PointsAvailable
91 @Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where upa.member_id = ?1" 91 @Query(value = "SELECT sum(upa.points) AS pointsExpire from uc_points_available upa where upa.member_id = ?1"
92 ,nativeQuery = true) 92 ,nativeQuery = true)
93 long findTotalCountByMemberId(Long memberId); 93 long findTotalCountByMemberId(Long memberId);
94
95 List<PointsAvailable> findByMemberIdAndExpireTimeAfter(Long memberId, Date timestamp);
94 } 96 }
......
...@@ -80,6 +80,8 @@ public interface PointsAvailableService { ...@@ -80,6 +80,8 @@ public interface PointsAvailableService {
80 */ 80 */
81 List<PointsAvailableDTO> findByMemberIdAndExpireTimeBefore(Long memberId, Date timestamp); 81 List<PointsAvailableDTO> findByMemberIdAndExpireTimeBefore(Long memberId, Date timestamp);
82 82
83 List<PointsAvailableDTO> findByMemberIdAndExpireTimeAfter(Long memberId, Date timestamp);
84
83 /** 85 /**
84 * 即将过期的积分 86 * 即将过期的积分
85 * @param memberId 会员id 87 * @param memberId 会员id
......
...@@ -127,6 +127,13 @@ public class PointsAvailableServiceImpl implements PointsAvailableService { ...@@ -127,6 +127,13 @@ public class PointsAvailableServiceImpl implements PointsAvailableService {
127 } 127 }
128 128
129 @Override 129 @Override
130 public List<PointsAvailableDTO> findByMemberIdAndExpireTimeAfter(Long memberId, Date timestamp) {
131 return Objects.nonNull(memberId)?
132 PointsAvailableMapper.toDto(PointsAvailableRepository.findByMemberIdAndExpireTimeAfter(memberId, timestamp))
133 :null;
134 }
135
136 @Override
130 public Long findSoonExpireTime(Long memberId, Integer factor) { 137 public Long findSoonExpireTime(Long memberId, Integer factor) {
131 return PointsAvailableRepository.findSoonExpireTime(memberId, factor); 138 return PointsAvailableRepository.findSoonExpireTime(memberId, factor);
132 } 139 }
......
...@@ -102,8 +102,10 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -102,8 +102,10 @@ public class PointsOperationServiceImpl implements PointsOperationService {
102 this.doInsertTrPointsDetailByAvailablePointsMap(tempPoints, customAvailablePointsMap, currentPoints); 102 this.doInsertTrPointsDetailByAvailablePointsMap(tempPoints, customAvailablePointsMap, currentPoints);
103 // 4.更新可用积分表,超过的删除,剩余的新增 103 // 4.更新可用积分表,超过的删除,剩余的新增
104 long totalPoints = this.doFreshTrPointsAvailableByAvailablePointsMap(customAvailablePointsMap, currentPoints); 104 long totalPoints = this.doFreshTrPointsAvailableByAvailablePointsMap(customAvailablePointsMap, currentPoints);
105 // 5.即将过期的积分
106 long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints);
105 // 6.更新会员积分信息 107 // 6.更新会员积分信息
106 this.freshMemberCurrentPoints(memberId, totalPoints); 108 this.freshMemberCurrentPoints(memberId, totalPoints,soonExpirePoints);
107 109
108 return true; 110 return true;
109 } 111 }
...@@ -281,7 +283,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -281,7 +283,7 @@ public class PointsOperationServiceImpl implements PointsOperationService {
281 */ 283 */
282 private void cleanInvalidAvailablePointsByMemberId(Long memberId) { 284 private void cleanInvalidAvailablePointsByMemberId(Long memberId) {
283 List<PointsAvailableDTO> pointsAvailableDTOS = 285 List<PointsAvailableDTO> pointsAvailableDTOS =
284 pointsAvailableService.findByMemberIdAndExpireTimeBefore(memberId,TimestampUtil.now()); 286 pointsAvailableService.findByMemberIdAndExpireTimeAfter(memberId,TimestampUtil.now());
285 if (!CollectionUtils.isEmpty(pointsAvailableDTOS)) { 287 if (!CollectionUtils.isEmpty(pointsAvailableDTOS)) {
286 //1.获取原始积分 288 //1.获取原始积分
287 for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS) { 289 for (PointsAvailableDTO pointsAvailableDTO : pointsAvailableDTOS) {
...@@ -301,8 +303,10 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -301,8 +303,10 @@ public class PointsOperationServiceImpl implements PointsOperationService {
301 this.cleanInvalidAvailablePointsByMemberId(memberId); 303 this.cleanInvalidAvailablePointsByMemberId(memberId);
302 // 获取当前用户的可用总积分 304 // 获取当前用户的可用总积分
303 long currentPoints = this.findAvailablePointsByMemberId(memberId); 305 long currentPoints = this.findAvailablePointsByMemberId(memberId);
306 // 即将过期的积分
307 long soonExpirePoints = this.getSoonExpirePoints(memberId, null);
304 // 更新会员信息 308 // 更新会员信息
305 this.doUpdateMemberPoints(memberId,currentPoints); 309 this.doUpdateMemberPoints(memberId,currentPoints,soonExpirePoints);
306 310
307 return currentPoints; 311 return currentPoints;
308 } 312 }
...@@ -321,10 +325,11 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -321,10 +325,11 @@ public class PointsOperationServiceImpl implements PointsOperationService {
321 * @param memberId 325 * @param memberId
322 * @param currentPoints 326 * @param currentPoints
323 */ 327 */
324 private void doUpdateMemberPoints(Long memberId, long currentPoints) { 328 private void doUpdateMemberPoints(Long memberId, long currentPoints,long soonExpirePoints) {
325 Member member = new Member(); 329 Member member = new Member();
326 member.setId(memberId); 330 member.setId(memberId);
327 member.setPoints(currentPoints); 331 member.setPoints(currentPoints);
332 member.setDuePoints(soonExpirePoints);
328 this.memberOperationService.doUpdateMemberPoints(member); 333 this.memberOperationService.doUpdateMemberPoints(member);
329 } 334 }
330 335
...@@ -403,9 +408,12 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -403,9 +408,12 @@ public class PointsOperationServiceImpl implements PointsOperationService {
403 this.doInsertTrPointsAvailable(tempPoints); 408 this.doInsertTrPointsAvailable(tempPoints);
404 log.info("----------->> refresh doInsertTrPointsAvailable end "); 409 log.info("----------->> refresh doInsertTrPointsAvailable end ");
405 410
411 // 即将过期的积分
412 long soonExpirePoints = this.getSoonExpirePoints(memberId, tempPoints);
413
406 // 6.更新会员的总积分 414 // 6.更新会员的总积分
407 log.info("----------->> refresh freshMemberCurrentPoints start "); 415 log.info("----------->> refresh freshMemberCurrentPoints start ");
408 this.freshMemberCurrentPoints(memberId, totalPoints); 416 this.freshMemberCurrentPoints(memberId, totalPoints,soonExpirePoints);
409 log.info("----------->> refresh freshMemberCurrentPoints end "); 417 log.info("----------->> refresh freshMemberCurrentPoints end ");
410 418
411 } catch (Exception e) { 419 } catch (Exception e) {
...@@ -461,11 +469,11 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -461,11 +469,11 @@ public class PointsOperationServiceImpl implements PointsOperationService {
461 * @param memberId 会员Id 469 * @param memberId 会员Id
462 * @param currentPoints 当前总积分 470 * @param currentPoints 当前总积分
463 */ 471 */
464 private void freshMemberCurrentPoints(Long memberId, Long currentPoints) { 472 private void freshMemberCurrentPoints(Long memberId, Long currentPoints,long duePoints) {
465 Member member = new Member(); 473 Member member = new Member();
466 member.setId(memberId); 474 member.setId(memberId);
467 member.setPoints(Objects.nonNull(currentPoints)?currentPoints:0); 475 member.setPoints(Objects.nonNull(currentPoints)?currentPoints:0);
468 // member.setDuePoints(duePoints); 476 member.setDuePoints(duePoints);
469 member.setUpdateTime(Timestamp.valueOf(LocalDateTime.now())); 477 member.setUpdateTime(Timestamp.valueOf(LocalDateTime.now()));
470 try { 478 try {
471 this.memberOperationService.doUpdateMemberPoints(member); 479 this.memberOperationService.doUpdateMemberPoints(member);
......
...@@ -554,13 +554,16 @@ public class TaskOperationServiceImpl implements TaskOperationService { ...@@ -554,13 +554,16 @@ public class TaskOperationServiceImpl implements TaskOperationService {
554 if (!CollectionUtils.isEmpty(taskList)) { 554 if (!CollectionUtils.isEmpty(taskList)) {
555 // 会员信息 555 // 会员信息
556 MemberDTO memberDTO = this.memberService.findById(memberId); 556 MemberDTO memberDTO = this.memberService.findById(memberId);
557
558
559
557 // 判断是否完成任务 560 // 判断是否完成任务
558 CompareTaskCondition compareTaskCondition =(MemberDTO memberDTO1,List<Task> taskList1) -> { 561 CompareTaskCondition compareTaskCondition =(MemberDTO memberDTO1,List<Task> taskList1) -> {
559 562
560 List<Task> taskStream = taskList1.stream().filter(task1 -> 563 List<Task> taskStream = taskList1.stream().filter(task1 ->
561 task1.getStatus() == 1 && 564 task1.getStatus() == 1 &&
562 (Objects.isNull(task1.getExpireTime()) || task1.getExpireTime().compareTo(TimestampUtil.now()) >= 0) && 565 (Objects.isNull(task1.getExpireTime()) || task1.getExpireTime().compareTo(TimestampUtil.now()) >= 0) &&
563 (Objects.isNull(task1.getGroups()) || task1.getGroups().equalsIgnoreCase(memberDTO1.getGroups())) && 566 (Objects.isNull(task1.getGroups()) || task1.getGroups().equals("0") || task1.getGroups().equalsIgnoreCase(memberDTO1.getGroups())) &&
564 (Objects.isNull(task1.getValidTime()) || task1.getValidTime().compareTo(TimestampUtil.now()) <= 0) && 567 (Objects.isNull(task1.getValidTime()) || task1.getValidTime().compareTo(TimestampUtil.now()) <= 0) &&
565 (Objects.isNull(task1.getMemberLevel()) || task1.getMemberLevel() <= memberDTO1.getLevel()) && 568 (Objects.isNull(task1.getMemberLevel()) || task1.getMemberLevel() <= memberDTO1.getLevel()) &&
566 (Objects.isNull(task1.getMemberVip()) || task1.getMemberVip() <= memberDTO1.getVip()) 569 (Objects.isNull(task1.getMemberVip()) || task1.getMemberVip() <= memberDTO1.getVip())
......
...@@ -53,9 +53,9 @@ public class PointsOperationControllerTest extends BaseTest { ...@@ -53,9 +53,9 @@ public class PointsOperationControllerTest extends BaseTest {
53 @Test 53 @Test
54 public void grantPointsByManual(){ 54 public void grantPointsByManual(){
55 TempPoints tempPoints = new TempPoints(); 55 TempPoints tempPoints = new TempPoints();
56 tempPoints.setMemberId(5L);
56 tempPoints.setPoints(10L); 57 tempPoints.setPoints(10L);
57 tempPoints.setPointsType(0); 58 tempPoints.setPointsType(0);
58 tempPoints.setMemberId(3L);
59 tempPoints.setRightsSendStrategy(0); 59 tempPoints.setRightsSendStrategy(0);
60 tempPoints.setAccountId(2L); 60 tempPoints.setAccountId(2L);
61 tempPoints.setExpireTime(Timestamp.valueOf("2021-11-27 09:00:00")); 61 tempPoints.setExpireTime(Timestamp.valueOf("2021-11-27 09:00:00"));
...@@ -72,6 +72,28 @@ public class PointsOperationControllerTest extends BaseTest { ...@@ -72,6 +72,28 @@ public class PointsOperationControllerTest extends BaseTest {
72 LOG.info("===>>>"+byId); 72 LOG.info("===>>>"+byId);
73 } 73 }
74 74
75 @Test
76 public void cleanInvalidPointsAndCalculateCurrentPoints(){
77 /*TempPoints tempPoints = new TempPoints();
78 tempPoints.setMemberId(5L);
79 tempPoints.setPoints(10L);
80 tempPoints.setPointsType(0);
81 tempPoints.setRightsSendStrategy(0);
82 tempPoints.setAccountId(2L);
83 tempPoints.setExpireTime(Timestamp.valueOf("2021-11-27 09:00:00"));
84 tempPoints.setDeviceType(2);
85 tempPoints.setAppCode("WEI_XIN_GOLD_PANDA");
86 tempPoints.setOrderId(null);
87 tempPoints.setMediaId(null);
88 tempPoints.setActivityId(null);
89 tempPoints.setItemId(null);
90 tempPoints.setDescription("系统发放");
91 tempPoints.setEvtType(1);
92 String s = JSON.toJSONString(tempPoints);*/
93 ResultInfo byId = this.pointsOperationController.cleanInvalidPointsAndCalculateCurrentPoints(5L);
94 LOG.info("===>>>"+byId);
95 }
96
75 /*@Test 97 /*@Test
76 public void update(){ 98 public void update(){
77 MemberAddress memberAddress = new MemberAddress(); 99 MemberAddress memberAddress = new MemberAddress();
......
...@@ -29,9 +29,9 @@ public class TaskOperationControllerTest extends BaseTest { ...@@ -29,9 +29,9 @@ public class TaskOperationControllerTest extends BaseTest {
29 DataSyncMsg dataSyncMsg = new DataSyncMsg(); 29 DataSyncMsg dataSyncMsg = new DataSyncMsg();
30 dataSyncMsg.setEventType(EventType.VIEWING.name()); 30 dataSyncMsg.setEventType(EventType.VIEWING.name());
31 DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData(); 31 DataSyncMsg.MsgData msgData = new DataSyncMsg.MsgData();
32 msgData.setEvent(6); 32 msgData.setEvent(3); // 类型 1-登录 2-观影 3-参加活动 4-订购 5-优享会员 6-签到
33 msgData.setRemarks("remark"); 33 msgData.setRemarks("remark");
34 msgData.setMemberId(3L); 34 msgData.setMemberId(5L);
35 msgData.setDeviceType(2); 35 msgData.setDeviceType(2);
36 msgData.setAppCode("WEI_XIN_GOLD_PANDA"); 36 msgData.setAppCode("WEI_XIN_GOLD_PANDA");
37 dataSyncMsg.setMsg(msgData); 37 dataSyncMsg.setMsg(msgData);
......