Browse Source

积分上限周期

master
wangchao 5 years ago
parent
commit
4474ac5046
  1. 64
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/impl/UserPointActionLogServiceImpl.java
  2. 5
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/utils/ModuleConstant.java
  3. 2
      epmet-module/epmet-point/epmet-point-server/src/main/resources/mapper/PointRuleDao.xml

64
epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/impl/UserPointActionLogServiceImpl.java

@ -28,6 +28,7 @@ import com.epmet.commons.tools.enums.EventEnum;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dao.UserPointActionLogDao;
import com.epmet.dto.UserPointActionLogDTO;
@ -43,6 +44,7 @@ import com.epmet.service.UserPointStatisticalDailyService;
import com.epmet.service.UserPointTotalService;
import com.epmet.utils.DimIdGenerator;
import com.epmet.utils.ModuleConstant;
import com.epmet.utils.RuleCycleEnum;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Maps;
import dto.form.SendPointFormDTO;
@ -55,6 +57,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@ -193,23 +196,57 @@ public class UserPointActionLogServiceImpl extends BaseServiceImpl<UserPointActi
PointRuleEntity ruleInfo = pointRuleService.getByEventCodeAndCustomerId(event.getCustomerId(),eventCode);
if(null != ruleInfo && StringUtils.equals(NumConstant.ONE_STR,ruleInfo.getEnabledFlag())){
Date dateCheck = null;
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.set(Calendar.HOUR_OF_DAY, NumConstant.ZERO);
calendar.set(Calendar.MINUTE, NumConstant.ZERO);
calendar.set(Calendar.SECOND, NumConstant.ZERO);
//先判断周期,是否超过限值
RuleCycleEnum cycle = RuleCycleEnum.getEnum(ruleInfo.getRulePeriod());
switch(cycle){
//当周期为首次或无限制时,不需要传时间参数
// case UNLIMITED:
// break;
// case FIRST:
// break;
case DAILY:
//今天零点
dateCheck = calendar.getTime();
break;
case WEEKLY:
//本周第一天零点
calendar.add(Calendar.WEEK_OF_MONTH, 0);
calendar.set(Calendar.DAY_OF_WEEK, 2);
dateCheck = calendar.getTime();
break;
case MONTHLY:
//本月第一天零点
calendar.add(Calendar.MONTH, 0);
calendar.set(Calendar.DAY_OF_MONTH, 1);
dateCheck = calendar.getTime();
break;
case YEARLY:
//本年第一天零点
int dayOfYear = Calendar.getInstance().get(Calendar.DAY_OF_YEAR);
calendar.add(Calendar.DAY_OF_YEAR, -dayOfYear + 1);
dateCheck = calendar.getTime();
break;
default:
}
//判断积分规则的积分单位 次、天、分钟、小时
if(StringUtils.equals(ModuleConstant.POINT_UNIT_TIME,ruleInfo.getPointUnit())){
//次
}else if(StringUtils.equals(ModuleConstant.POINT_UNIT_DAY,ruleInfo.getPointUnit())){
//天
//在selectSumByEvent时要校验时间区间
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.set(Calendar.HOUR_OF_DAY, NumConstant.ZERO);
calendar.set(Calendar.MINUTE, NumConstant.ZERO);
calendar.set(Calendar.SECOND, NumConstant.ZERO);
dateCheck = calendar.getTime();
}else{
if(!StringUtils.equals(ModuleConstant.POINT_UNIT_TIME,ruleInfo.getPointUnit()) && !StringUtils.equals(ModuleConstant.POINT_UNIT_DAY,ruleInfo.getPointUnit())){
//其余积分单位
//TODO..
logger.warn(String.format("当前规则属于按%s计分,系统尚不支持响应此类积分规则的事件"),ruleInfo.getPointUnit());
return ;
}
//校验是否达到上限
if(ruleInfo.getUpLimit() > NumConstant.ZERO){
//不按照sourceId查询,查询指定日期内的相关积分规则的总和
@ -325,7 +362,7 @@ public class UserPointActionLogServiceImpl extends BaseServiceImpl<UserPointActi
action.setPoint(grantPoint.getPoint());
action.setEventStatement(grantPoint.getRemark());
action.setEventName(EventEnum.ACTIVE_SEND_POINT.getEventDesc());
action.setEventId("COMMON");
action.setEventId(ModuleConstant.COMMON_EVENT_ID);
action.setActionFlag(grantPoint.getActionFlag());
action.setUserId(grantPoint.getUserId());
action.setCreatedBy(grantPoint.getOperatorId());
@ -355,4 +392,5 @@ public class UserPointActionLogServiceImpl extends BaseServiceImpl<UserPointActi
userPointTotalService.insertOrUpdate(point);
}
}

5
epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/utils/ModuleConstant.java

@ -120,4 +120,9 @@ public interface ModuleConstant extends Constant {
String EVENT_NAME_PARTICIPATED_ACT = "参与活动";
String EVENT_NAME_ADD_LIVE = "添加活动实况";
/**
* 通用事件不走规则但也是事件所以在用户积分行为记录表中的eventId中要有值与积分调整积分兑换分开
* */
String COMMON_EVENT_ID = "COMMON";
}

2
epmet-module/epmet-point/epmet-point-server/src/main/resources/mapper/PointRuleDao.xml

@ -40,7 +40,7 @@
</update>
<select id="selectByEventCodeAndCustomerId" resultType="com.epmet.entity.PointRuleEntity">
SELECT ID,RULE_NAME,RULE_DESC,POINT,POINT_UNIT,ENABLED_FLAG,UP_LIMIT,OPERATE_TYPE
SELECT ID,RULE_NAME,RULE_DESC,POINT,POINT_UNIT,ENABLED_FLAG,UP_LIMIT,OPERATE_TYPE,RULE_PERIOD
FROM point_rule
WHERE
DEL_FLAG = '0'

Loading…
Cancel
Save