From c681969f67980843908d1003df6ccddaf3721c36 Mon Sep 17 00:00:00 2001 From: songyunpeng Date: Fri, 8 May 2020 18:20:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=AF=E5=88=86=E5=9F=8B=E7=82=B9=20?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E8=A7=84=E5=88=99=E5=88=A4=E5=AE=9A=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../elink/esua/epdc/dao/PointsLogsDao.java | 2 +- .../esua/epdc/feign/UsersFeignClient.java | 2 +- .../esua/epdc/mq/PointsModifyConsumer.java | 97 ++----------------- .../esua/epdc/service/PointsLogsService.java | 3 +- .../service/impl/PointsLogsServiceImpl.java | 5 +- .../main/resources/mapper/PointsLogsDao.xml | 33 ++----- .../main/resources/mapper/PointsRuleDao.xml | 2 +- 7 files changed, 25 insertions(+), 119 deletions(-) diff --git a/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/dao/PointsLogsDao.java b/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/dao/PointsLogsDao.java index 69e62f26..e49db8ea 100755 --- a/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/dao/PointsLogsDao.java +++ b/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/dao/PointsLogsDao.java @@ -54,7 +54,7 @@ public interface PointsLogsDao extends BaseDao { * @Date 2020/4/29 * @Param [pointsLogsFormDTO] **/ - PointsLogsSumResultDTO getPointsSumByBehaviorCodeAndUserId(PointsLogsFormDTO pointsLogsFormDTO); + Integer getPointsSumByBehaviorCodeAndUserId(PointsLogsFormDTO pointsLogsFormDTO); /** * @return com.elink.esua.epdc.dto.result.PointsLogsResultDTO diff --git a/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/feign/UsersFeignClient.java b/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/feign/UsersFeignClient.java index 725f0380..2d79b0f8 100644 --- a/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/feign/UsersFeignClient.java +++ b/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/feign/UsersFeignClient.java @@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.*; * @author songyunpeng * @date 2020/04/28 */ -@FeignClient(name = ServiceConstant.EPDC_USER_SERVER, fallback = UsersFeignClientFallback.class, url = "http://127.0.0.1:9068") +@FeignClient(name = ServiceConstant.EPDC_USER_SERVER, fallback = UsersFeignClientFallback.class) public interface UsersFeignClient { /** diff --git a/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/mq/PointsModifyConsumer.java b/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/mq/PointsModifyConsumer.java index b9e15ce4..48b68c7c 100644 --- a/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/mq/PointsModifyConsumer.java +++ b/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/mq/PointsModifyConsumer.java @@ -115,7 +115,7 @@ public class PointsModifyConsumer implements RocketMQListener { 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 { } //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 { cpUserDetailRedis.set(tokenDto, expire); //更新用户的积分 -- 结束 //添加操作日志 -- 开始 - addRuleLog(pointsRuleResultDTO, dto, pointsLogsSumResultDTO, pointsLogsFormDTO, userDTO); + addRuleLog(pointsRuleResultDTO, dto, userDTO); //添加操作日志 -- 结束 } @@ -209,7 +179,7 @@ public class PointsModifyConsumer implements RocketMQListener { * 若是没有超过积分总数界限且返回的时间+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 { 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); } diff --git a/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/service/PointsLogsService.java b/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/service/PointsLogsService.java index bfaa7f82..78955f30 100755 --- a/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/service/PointsLogsService.java +++ b/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/service/PointsLogsService.java @@ -30,6 +30,7 @@ import com.elink.esua.epdc.dto.form.EpdcAppPointsRecordFormDTO; import com.elink.esua.epdc.dto.result.EpdcAppPointsRankingResultDTO; import com.elink.esua.epdc.dto.result.EpdcAppPointsRecordResultDTO; import com.elink.esua.epdc.entity.PointsLogsEntity; +import io.swagger.models.auth.In; import java.util.List; import java.util.Map; @@ -144,7 +145,7 @@ public interface PointsLogsService extends BaseService { * @Date 2020/4/29 * @Param [pointsLogsFormDTO] **/ - PointsLogsSumResultDTO getPointsSumByBehaviorCodeAndUserId(PointsLogsFormDTO pointsLogsFormDTO); + Integer getPointsSumByBehaviorCodeAndUserId(PointsLogsFormDTO pointsLogsFormDTO); /** * @return com.elink.esua.epdc.commons.tools.utils.Result diff --git a/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/service/impl/PointsLogsServiceImpl.java b/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/service/impl/PointsLogsServiceImpl.java index 0db1080f..f65753fc 100755 --- a/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/service/impl/PointsLogsServiceImpl.java +++ b/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/service/impl/PointsLogsServiceImpl.java @@ -136,9 +136,8 @@ public class PointsLogsServiceImpl extends BaseServiceImpl - + select sum(z) - sum(f) as total from( select case when OPERATION_TYPE =0 then sum(POINTS) else 0 end as f, case when OPERATION_TYPE =1 then sum(POINTS) else 0 end as z, - BEHAVIOR_CODE, - (select OPERATION_TIME from epdc_points_logs where LAVE_POINTS = #{upperLimitVal} order by OPERATION_TIME desc - limit 1) as OPERATION_TIME + BEHAVIOR_CODE from epdc_points_logs where USER_ID = #{userId} and BEHAVIOR_CODE = #{behaviorCode} - and OPERATION_TIME between (select OPERATION_TIME from epdc_points_logs where LAVE_POINTS = #{upperLimitVal} - order by OPERATION_TIME desc limit 1) and - (select date_add(OPERATION_TIME,interval +1 minute )from epdc_points_logs where LAVE_POINTS = - #{upperLimitVal} order by OPERATION_TIME desc limit 1) + and OPERATION_TIME between date_add(now() , interval -1 minute ) and now() - and OPERATION_TIME between (select OPERATION_TIME from epdc_points_logs where LAVE_POINTS = #{upperLimitVal} - order by OPERATION_TIME desc limit 1) and - (select date_add(OPERATION_TIME,interval +1 hour )from epdc_points_logs where LAVE_POINTS = #{upperLimitVal} - order by OPERATION_TIME desc limit 1) + and OPERATION_TIME between date_add(now() , interval -1 hour ) and now() - and OPERATION_TIME between (select OPERATION_TIME from epdc_points_logs where LAVE_POINTS = #{upperLimitVal} - order by OPERATION_TIME desc limit 1) and - (select date_add(OPERATION_TIME,interval +1 day )from epdc_points_logs where LAVE_POINTS = #{upperLimitVal} - order by OPERATION_TIME desc limit 1) + and OPERATION_TIME between date_add(now() , interval -1 minute ) and now() - and OPERATION_TIME between (select OPERATION_TIME from epdc_points_logs where LAVE_POINTS = #{upperLimitVal} - order by OPERATION_TIME desc limit 1) and - (select date_add(OPERATION_TIME,interval +1 month )from epdc_points_logs where LAVE_POINTS = - #{upperLimitVal} order by OPERATION_TIME desc limit 1) + and OPERATION_TIME between date_add(now() , interval -1 minute ) and now() - and OPERATION_TIME between (select OPERATION_TIME from epdc_points_logs where LAVE_POINTS = #{upperLimitVal} - order by OPERATION_TIME desc limit 1) and - (select date_add(OPERATION_TIME,interval +1 year )from epdc_points_logs where LAVE_POINTS = #{upperLimitVal} - order by OPERATION_TIME desc limit 1) + and OPERATION_TIME between date_add(now() , interval -1 minute ) and now() group by OPERATION_TYPE)a group by a.BEHAVIOR_CODE; diff --git a/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/resources/mapper/PointsRuleDao.xml b/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/resources/mapper/PointsRuleDao.xml index e365da47..9c2ee6cd 100644 --- a/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/resources/mapper/PointsRuleDao.xml +++ b/esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/resources/mapper/PointsRuleDao.xml @@ -27,7 +27,7 @@