|
|
@ -115,7 +115,7 @@ public class PointsModifyConsumer implements RocketMQListener<MessageExt> { |
|
|
|
pointsLogsFormDTO.setUserId(dto.getUserId()); |
|
|
|
pointsLogsFormDTO.setReferenceId(dto.getReferenceId()); |
|
|
|
PointsRuleResultDTO pointsRuleResultDTO = pointsRuleService.getPointsRuleByBehaviorCode(dto.getBehavior()); |
|
|
|
if (pointsRuleResultDTO == null) { |
|
|
|
if (pointsRuleResultDTO == null || pointsRuleResultDTO.getUpperLimitVal() == 0) { |
|
|
|
return; |
|
|
|
} |
|
|
|
pointsLogsFormDTO.setRuleCode(pointsRuleResultDTO.getRuleCode()); |
|
|
@ -130,42 +130,12 @@ public class PointsModifyConsumer implements RocketMQListener<MessageExt> { |
|
|
|
} |
|
|
|
//2.赋值积分规则的上限期限(小时,年。。。。)
|
|
|
|
pointsLogsFormDTO.setOperationFlag(pointsRuleResultDTO.getLimitType()); |
|
|
|
pointsLogsFormDTO.setUpperLimitVal(pointsRuleResultDTO.getUpperLimitVal() - pointsRuleResultDTO.getPoints()); |
|
|
|
//3.根据积分上限期限,行为编码获取该用户最近的一次行为记录和时间
|
|
|
|
PointsLogsSumResultDTO pointsLogsSumResultDTO = pointsLogsService.getPointsSumByBehaviorCodeAndUserId(pointsLogsFormDTO); |
|
|
|
//4.先判断积分总值是否超出上限 若超过上限且返回的时间+1min大与当前时间则返回(此时代表已经到达界限且在该时限内不能再加分)
|
|
|
|
//此处返回的时间为离当前时间最近的一条剩余积分最多的时间
|
|
|
|
if (pointsLogsSumResultDTO != null) { |
|
|
|
if (Math.abs(pointsLogsSumResultDTO.getTotal()) >= Math.abs(pointsRuleResultDTO.getUpperLimitVal())) { |
|
|
|
switch (pointsRuleResultDTO.getLimitType()) { |
|
|
|
case "0": |
|
|
|
if (DateUtils.addDateMinutes(pointsLogsSumResultDTO.getOperationTime(), 1).after(new Date())) { |
|
|
|
return; |
|
|
|
} |
|
|
|
break; |
|
|
|
case "1": |
|
|
|
if (DateUtils.addDateHours(pointsLogsSumResultDTO.getOperationTime(), 1).after(new Date())) { |
|
|
|
return; |
|
|
|
} |
|
|
|
break; |
|
|
|
case "2": |
|
|
|
if (DateUtils.addDateDays(pointsLogsSumResultDTO.getOperationTime(), 1).after(new Date())) { |
|
|
|
return; |
|
|
|
} |
|
|
|
break; |
|
|
|
case "3": |
|
|
|
if (DateUtils.addDateMonths(pointsLogsSumResultDTO.getOperationTime(), 1).after(new Date())) { |
|
|
|
return; |
|
|
|
} |
|
|
|
break; |
|
|
|
case "4": |
|
|
|
if (DateUtils.addDateYears(pointsLogsSumResultDTO.getOperationTime(), 1).after(new Date())) { |
|
|
|
return; |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
//3.获取前一分钟的总分
|
|
|
|
Integer total = pointsLogsService.getPointsSumByBehaviorCodeAndUserId(pointsLogsFormDTO); |
|
|
|
//判断总分是否超过上限
|
|
|
|
if (total != null) { |
|
|
|
if (Math.abs(total+ pointsRuleResultDTO.getPoints()) >= Math.abs(pointsRuleResultDTO.getUpperLimitVal())) { |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
//计算是否超过该动作的积分上限 -- 结束
|
|
|
@ -195,7 +165,7 @@ public class PointsModifyConsumer implements RocketMQListener<MessageExt> { |
|
|
|
cpUserDetailRedis.set(tokenDto, expire); |
|
|
|
//更新用户的积分 -- 结束
|
|
|
|
//添加操作日志 -- 开始
|
|
|
|
addRuleLog(pointsRuleResultDTO, dto, pointsLogsSumResultDTO, pointsLogsFormDTO, userDTO); |
|
|
|
addRuleLog(pointsRuleResultDTO, dto, userDTO); |
|
|
|
//添加操作日志 -- 结束
|
|
|
|
} |
|
|
|
|
|
|
@ -209,7 +179,7 @@ public class PointsModifyConsumer implements RocketMQListener<MessageExt> { |
|
|
|
* 若是没有超过积分总数界限且返回的时间+1min小于当前时间(代表不在时间界限内,用户在操作,取界限值为剩余分) |
|
|
|
* 若是没有超过积分总数界限且返回的时间+1min大于当前时间(代表在时间界限内,用户在操作,剩余积分正常加减) |
|
|
|
*/ |
|
|
|
private void addRuleLog(PointsRuleResultDTO pointsRuleResultDTO, BehaviorDto dto, PointsLogsSumResultDTO pointsLogsSumResultDTO, PointsLogsFormDTO pointsLogsFormDTO, UserDTO userDTO) { |
|
|
|
private void addRuleLog(PointsRuleResultDTO pointsRuleResultDTO, BehaviorDto dto, UserDTO userDTO) { |
|
|
|
PointsLogsAddFormDTO pointsLogsAddFormDTO = new PointsLogsAddFormDTO(); |
|
|
|
pointsLogsAddFormDTO.setUserId(dto.getUserId()); |
|
|
|
pointsLogsAddFormDTO.setNickname(userDTO.getNickname()); |
|
|
@ -222,54 +192,7 @@ public class PointsModifyConsumer implements RocketMQListener<MessageExt> { |
|
|
|
pointsLogsAddFormDTO.setOperationDesc(pointsRuleResultDTO.getRuleDesc()); |
|
|
|
pointsLogsAddFormDTO.setOperationTime(new Date()); |
|
|
|
pointsLogsAddFormDTO.setOperationMode("user"); |
|
|
|
//若是返回时间+1min/hour/day/month/year 大于当前时间则正常加减 其他取界限值
|
|
|
|
if (pointsLogsSumResultDTO != null) { |
|
|
|
switch (pointsRuleResultDTO.getLimitType()) { |
|
|
|
case "0": |
|
|
|
if (DateUtils.addDateMinutes(pointsLogsSumResultDTO.getOperationTime(), 1).after(new Date())) { |
|
|
|
PointsLogsResultDTO pointsLogsResultDTO = pointsLogsService.getLastPointLogs(pointsLogsFormDTO); |
|
|
|
pointsLogsAddFormDTO.setLavePoints(pointsLogsResultDTO.getLavePoints() - pointsRuleResultDTO.getPoints()); |
|
|
|
} else { |
|
|
|
pointsLogsAddFormDTO.setLavePoints(pointsRuleResultDTO.getUpperLimitVal() - pointsRuleResultDTO.getPoints()); |
|
|
|
} |
|
|
|
break; |
|
|
|
case "1": |
|
|
|
if (DateUtils.addDateHours(pointsLogsSumResultDTO.getOperationTime(), 1).after(new Date())) { |
|
|
|
PointsLogsResultDTO pointsLogsResultDTO = pointsLogsService.getLastPointLogs(pointsLogsFormDTO); |
|
|
|
pointsLogsAddFormDTO.setLavePoints(pointsLogsResultDTO.getLavePoints() - pointsRuleResultDTO.getPoints()); |
|
|
|
} else { |
|
|
|
pointsLogsAddFormDTO.setLavePoints(pointsRuleResultDTO.getUpperLimitVal() - pointsRuleResultDTO.getPoints()); |
|
|
|
} |
|
|
|
break; |
|
|
|
case "2": |
|
|
|
if (DateUtils.addDateDays(pointsLogsSumResultDTO.getOperationTime(), 1).after(new Date())) { |
|
|
|
PointsLogsResultDTO pointsLogsResultDTO = pointsLogsService.getLastPointLogs(pointsLogsFormDTO); |
|
|
|
pointsLogsAddFormDTO.setLavePoints(pointsLogsResultDTO.getLavePoints() - pointsRuleResultDTO.getPoints()); |
|
|
|
} else { |
|
|
|
pointsLogsAddFormDTO.setLavePoints(pointsRuleResultDTO.getUpperLimitVal() - pointsRuleResultDTO.getPoints()); |
|
|
|
} |
|
|
|
break; |
|
|
|
case "3": |
|
|
|
if (DateUtils.addDateMonths(pointsLogsSumResultDTO.getOperationTime(), 1).after(new Date())) { |
|
|
|
PointsLogsResultDTO pointsLogsResultDTO = pointsLogsService.getLastPointLogs(pointsLogsFormDTO); |
|
|
|
pointsLogsAddFormDTO.setLavePoints(pointsLogsResultDTO.getLavePoints() - pointsRuleResultDTO.getPoints()); |
|
|
|
} else { |
|
|
|
pointsLogsAddFormDTO.setLavePoints(pointsRuleResultDTO.getUpperLimitVal() - pointsRuleResultDTO.getPoints()); |
|
|
|
} |
|
|
|
break; |
|
|
|
case "4": |
|
|
|
if (DateUtils.addDateYears(pointsLogsSumResultDTO.getOperationTime(), 1).after(new Date())) { |
|
|
|
PointsLogsResultDTO pointsLogsResultDTO = pointsLogsService.getLastPointLogs(pointsLogsFormDTO); |
|
|
|
pointsLogsAddFormDTO.setLavePoints(pointsLogsResultDTO.getLavePoints() - pointsRuleResultDTO.getPoints()); |
|
|
|
} else { |
|
|
|
pointsLogsAddFormDTO.setLavePoints(pointsRuleResultDTO.getUpperLimitVal() - pointsRuleResultDTO.getPoints()); |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
} |
|
|
|
} else { |
|
|
|
pointsLogsAddFormDTO.setLavePoints(pointsRuleResultDTO.getUpperLimitVal() - pointsRuleResultDTO.getPoints()); |
|
|
|
} |
|
|
|
pointsLogsAddFormDTO.setLavePoints(userDTO.getPoints()); |
|
|
|
PointsLogsEntity pointsLogsEntity = ConvertUtils.sourceToTarget(pointsLogsAddFormDTO, PointsLogsEntity.class); |
|
|
|
pointsLogsService.insert(pointsLogsEntity); |
|
|
|
} |
|
|
|