Browse Source

积分埋点 积分规则判定修改

feature/syp_points
songyunpeng 6 years ago
parent
commit
c681969f67
  1. 2
      esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/dao/PointsLogsDao.java
  2. 2
      esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/feign/UsersFeignClient.java
  3. 97
      esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/mq/PointsModifyConsumer.java
  4. 3
      esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/service/PointsLogsService.java
  5. 5
      esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/java/com/elink/esua/epdc/service/impl/PointsLogsServiceImpl.java
  6. 33
      esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/resources/mapper/PointsLogsDao.xml
  7. 2
      esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/resources/mapper/PointsRuleDao.xml

2
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<PointsLogsEntity> {
* @Date 2020/4/29
* @Param [pointsLogsFormDTO]
**/
PointsLogsSumResultDTO getPointsSumByBehaviorCodeAndUserId(PointsLogsFormDTO pointsLogsFormDTO);
Integer getPointsSumByBehaviorCodeAndUserId(PointsLogsFormDTO pointsLogsFormDTO);
/**
* @return com.elink.esua.epdc.dto.result.PointsLogsResultDTO

2
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 {
/**

97
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<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);
}

3
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<PointsLogsEntity> {
* @Date 2020/4/29
* @Param [pointsLogsFormDTO]
**/
PointsLogsSumResultDTO getPointsSumByBehaviorCodeAndUserId(PointsLogsFormDTO pointsLogsFormDTO);
Integer getPointsSumByBehaviorCodeAndUserId(PointsLogsFormDTO pointsLogsFormDTO);
/**
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.dto.result.PointsLogsResultDTO>

5
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<PointsLogsDao, Points
}
@Override
public PointsLogsSumResultDTO getPointsSumByBehaviorCodeAndUserId(PointsLogsFormDTO pointsLogsFormDTO) {
PointsLogsSumResultDTO pointsLogsSumResultDTO = baseDao.getPointsSumByBehaviorCodeAndUserId(pointsLogsFormDTO);
return pointsLogsSumResultDTO;
public Integer getPointsSumByBehaviorCodeAndUserId(PointsLogsFormDTO pointsLogsFormDTO) {
return baseDao.getPointsSumByBehaviorCodeAndUserId(pointsLogsFormDTO);
}
@Override

33
esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/resources/mapper/PointsLogsDao.xml

@ -47,44 +47,27 @@
and RULE_CODE = #{ruleCode}
</select>
<select id="getPointsSumByBehaviorCodeAndUserId" resultType="com.elink.esua.epdc.dto.result.PointsLogsSumResultDTO">
select sum(z) - sum(f) as total,OPERATION_TIME from(
<select id="getPointsSumByBehaviorCodeAndUserId" resultType="integer">
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}
<if test="operationFlag == 0">
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()
</if>
<if test="operationFlag == 1">
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()
</if>
<if test="operationFlag == 2">
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()
</if>
<if test="operationFlag == 3">
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()
</if>
<if test="operationFlag == 4">
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()
</if>
group by OPERATION_TYPE)a group by a.BEHAVIOR_CODE;
</select>

2
esua-epdc/epdc-module/epdc-points/epdc-points-server/src/main/resources/mapper/PointsRuleDao.xml

@ -27,7 +27,7 @@
<select id="selecOnePointsRuleByBehaviorCode" resultMap="pointsRuleMap">
select ID,RULE_CODE,BEHAVIOR_CODE,RULE_DESC,OPERATION_TYPE,POINTS,LIMIT_TYPE,UPPER_LIMIT_VAL
,ENABLE_FLAG,ADDED_VAL,REMARK,REVISION,DEL_FLAG,CREATED_BY,CREATED_TIME,UPDATED_BY,UPDATED_TIME,LIMIT_NUM
from epdc_points_rule where BEHAVIOR_CODE = #{behaviorCode} limit 1
from epdc_points_rule where BEHAVIOR_CODE = #{behaviorCode} and ENABLE_FLAG = '1' limit 1
</select>
<select id="selectListPointsRule" resultType="com.elink.esua.epdc.dto.PointsRuleDTO">

Loading…
Cancel
Save