|
@ -17,19 +17,25 @@ |
|
|
|
|
|
|
|
|
package com.epmet.service.impl; |
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
|
|
import com.epmet.commons.tools.dto.form.mq.eventmsg.BasePointEventMsg; |
|
|
import com.epmet.commons.tools.enums.EventEnum; |
|
|
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.page.PageData; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
import com.epmet.dao.UserPointActionLogDao; |
|
|
import com.epmet.dao.UserPointActionLogDao; |
|
|
import com.epmet.dto.UserPointActionLogDTO; |
|
|
import com.epmet.dto.UserPointActionLogDTO; |
|
|
import com.epmet.dto.form.CommonPageUserFormDTO; |
|
|
import com.epmet.dto.form.CommonPageUserFormDTO; |
|
|
|
|
|
import com.epmet.dto.form.PointRuleListFormDTO; |
|
|
import com.epmet.dto.result.ResiPointLogListResultDTO; |
|
|
import com.epmet.dto.result.ResiPointLogListResultDTO; |
|
|
import com.epmet.dto.result.ResiPointLogPeriodResultDTO; |
|
|
import com.epmet.dto.result.ResiPointLogPeriodResultDTO; |
|
|
|
|
|
import com.epmet.entity.PointRuleEntity; |
|
|
import com.epmet.entity.UserPointActionLogEntity; |
|
|
import com.epmet.entity.UserPointActionLogEntity; |
|
|
import com.epmet.entity.UserPointStatisticalDailyEntity; |
|
|
import com.epmet.entity.UserPointStatisticalDailyEntity; |
|
|
import com.epmet.entity.UserPointTotalEntity; |
|
|
import com.epmet.entity.UserPointTotalEntity; |
|
@ -43,6 +49,10 @@ import com.google.common.collect.Maps; |
|
|
import dto.form.SendPointFormDTO; |
|
|
import dto.form.SendPointFormDTO; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
import org.apache.commons.lang3.Validate; |
|
|
|
|
|
import org.bouncycastle.math.raw.Mod; |
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
@ -60,12 +70,13 @@ import java.util.stream.Collectors; |
|
|
@Slf4j |
|
|
@Slf4j |
|
|
@Service |
|
|
@Service |
|
|
public class UserPointActionLogServiceImpl extends BaseServiceImpl<UserPointActionLogDao, UserPointActionLogEntity> implements UserPointActionLogService { |
|
|
public class UserPointActionLogServiceImpl extends BaseServiceImpl<UserPointActionLogDao, UserPointActionLogEntity> implements UserPointActionLogService { |
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(UserPointActionLogServiceImpl.class); |
|
|
@Autowired |
|
|
@Autowired |
|
|
private UserPointTotalService userPointTotalService; |
|
|
private UserPointTotalService userPointTotalService; |
|
|
@Autowired |
|
|
@Autowired |
|
|
private UserPointStatisticalDailyService userPointStatisticalDailyService; |
|
|
private UserPointStatisticalDailyService userPointStatisticalDailyService; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private PointRuleServiceImpl pointRuleService; |
|
|
@Override |
|
|
@Override |
|
|
public PageData<UserPointActionLogDTO> page(Map<String, Object> params) { |
|
|
public PageData<UserPointActionLogDTO> page(Map<String, Object> params) { |
|
|
IPage<UserPointActionLogEntity> page = baseDao.selectPage( |
|
|
IPage<UserPointActionLogEntity> page = baseDao.selectPage( |
|
@ -168,7 +179,100 @@ public class UserPointActionLogServiceImpl extends BaseServiceImpl<UserPointActi |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @Description 通过事件推送进行积分加减 |
|
|
|
|
|
* @param event |
|
|
|
|
|
* @return |
|
|
|
|
|
* @author wangc |
|
|
|
|
|
* @date 2020.07.31 13:45 |
|
|
|
|
|
**/ |
|
|
|
|
|
@Override |
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
public void grantPointByEvent(String eventCode,BasePointEventMsg event) { |
|
|
|
|
|
if(!StringUtils.equals(EventEnum.REGISTER_VOLUNTEER.getEventTag(),eventCode) && !StringUtils.equals(EventEnum.ACTIVE_INSERT_LIVE.getEventTag(),eventCode)){ |
|
|
|
|
|
logger.error(String.format("无法识别事件类型与积分规则,消息体->【%s】", JSON.toJSON(event))); |
|
|
|
|
|
throw new RenException("无法识别事件类型与积分规则"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PointRuleEntity ruleInfo = pointRuleService.getByEventCodeAndCustomerId(event.getCustomerId(),eventCode); |
|
|
|
|
|
if(null != ruleInfo && StringUtils.equals(NumConstant.ONE_STR,ruleInfo.getEnabledFlag())){ |
|
|
|
|
|
//校验是否达到上限
|
|
|
|
|
|
if(ruleInfo.getUpLimit() > NumConstant.ZERO){ |
|
|
|
|
|
Integer sum = baseDao.selectSumByEvent(event.getUserId(),eventCode,event.getSourceId(),event.getCustomerId()); |
|
|
|
|
|
if(null == sum) sum = NumConstant.ZERO; |
|
|
|
|
|
if(StringUtils.equals(ModuleConstant.OPERATION_TYPE_PLUS,ruleInfo.getOperateType())){ |
|
|
|
|
|
sum += ruleInfo.getPoint(); |
|
|
|
|
|
if(ruleInfo.getPoint() < NumConstant.ZERO){ |
|
|
|
|
|
//保证要加的积分是正数
|
|
|
|
|
|
ruleInfo.setPoint(ruleInfo.getPoint() * NumConstant.ONE_NEG); |
|
|
|
|
|
} |
|
|
|
|
|
}else{ |
|
|
|
|
|
//actionLog中存的是正负数,如果是减操作,则算出来的是负数相加
|
|
|
|
|
|
sum -= ruleInfo.getPoint() * NumConstant.ONE_NEG; |
|
|
|
|
|
sum *= NumConstant.ONE_NEG; |
|
|
|
|
|
if(ruleInfo.getPoint() > NumConstant.ZERO){ |
|
|
|
|
|
//保证要扣减的积分是负数
|
|
|
|
|
|
ruleInfo.setPoint(ruleInfo.getPoint() * NumConstant.ONE_NEG); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//这里sum一定是正数
|
|
|
|
|
|
if(ruleInfo.getUpLimit() < (sum + ruleInfo.getPoint())){ |
|
|
|
|
|
log.info(String.format("该用户获取此类事件的积分已达上限,详细数据->【%s】", JSON.toJSON(event))); |
|
|
|
|
|
return ; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//完成校验,可以进行积分操作
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//1.新增用户积分行为记录
|
|
|
|
|
|
UserPointActionLogEntity action = new UserPointActionLogEntity(); |
|
|
|
|
|
action.setCustomerId(event.getCustomerId()); |
|
|
|
|
|
action.setPoint(ruleInfo.getPoint()); |
|
|
|
|
|
action.setEventStatement(event.getRemark()); |
|
|
|
|
|
action.setEventName(EventEnum.getEnum(eventCode).getEventDesc()); |
|
|
|
|
|
action.setEventId(eventCode); |
|
|
|
|
|
action.setActionFlag(event.getActionFlag()); |
|
|
|
|
|
action.setUserId(event.getUserId()); |
|
|
|
|
|
action.setCreatedBy(StringUtils.isBlank(event.getOperatorId()) ? ModuleConstant.CREATED_BY_SYSTEM : event.getOperatorId()); |
|
|
|
|
|
action.setUpdatedBy(StringUtils.isBlank(event.getOperatorId()) ? ModuleConstant.CREATED_BY_SYSTEM : event.getOperatorId()); |
|
|
|
|
|
action.setSourceId(event.getSourceId()); |
|
|
|
|
|
action.setOperatorAgencyId(event.getOpAgencyId()); |
|
|
|
|
|
baseDao.insert(action); |
|
|
|
|
|
//2.新增/修改用户积分日统计
|
|
|
|
|
|
DimIdGenerator.DimIdBean dimVal = DimIdGenerator.getDimIdBean(new Date()); |
|
|
|
|
|
UserPointStatisticalDailyEntity statistical = ConvertUtils.sourceToTarget(dimVal,UserPointStatisticalDailyEntity.class); |
|
|
|
|
|
statistical.setPointChange(ruleInfo.getPoint()); |
|
|
|
|
|
statistical.setActionFlag(event.getActionFlag()); |
|
|
|
|
|
statistical.setCustomerId(event.getCustomerId()); |
|
|
|
|
|
statistical.setUserId(event.getUserId()); |
|
|
|
|
|
statistical.setCreatedBy(StringUtils.isBlank(event.getOperatorId()) ? ModuleConstant.CREATED_BY_SYSTEM : event.getOperatorId()); |
|
|
|
|
|
statistical.setUpdatedBy(StringUtils.isBlank(event.getOperatorId()) ? ModuleConstant.CREATED_BY_SYSTEM : event.getOperatorId()); |
|
|
|
|
|
userPointStatisticalDailyService.insertOrUpdate(statistical); |
|
|
|
|
|
//3.新增/修改用户积分日统计
|
|
|
|
|
|
UserPointTotalEntity point = new UserPointTotalEntity(); |
|
|
|
|
|
point.setCustomerId(event.getCustomerId()); |
|
|
|
|
|
point.setUserId(event.getUserId()); |
|
|
|
|
|
point.setTotalPoint(ruleInfo.getPoint()); |
|
|
|
|
|
point.setUsablePoint(ruleInfo.getPoint()); |
|
|
|
|
|
point.setUsedPoint(NumConstant.ZERO); |
|
|
|
|
|
point.setCreatedBy(StringUtils.isBlank(event.getOperatorId()) ? ModuleConstant.CREATED_BY_SYSTEM : event.getOperatorId()); |
|
|
|
|
|
point.setUpdatedBy(StringUtils.isBlank(event.getOperatorId()) ? ModuleConstant.CREATED_BY_SYSTEM : event.getOperatorId()); |
|
|
|
|
|
userPointTotalService.insertOrUpdate(point); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
log.error(String.format("未检测到该用户下有效的积分规则,消息体->【%s】", JSON.toJSON(event))); |
|
|
|
|
|
throw new RenException("未检测到该用户下有效的积分规则"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private void plusPoint(SendPointFormDTO grantPoint) { |
|
|
private void plusPoint(SendPointFormDTO grantPoint) { |
|
|
|
|
|
ValidatorUtils.validateEntity(grantPoint, SendPointFormDTO.SendPointGroup.class); |
|
|
|
|
|
|
|
|
if(StringUtils.equals(ModuleConstant.OPERATION_TYPE_MINUS,grantPoint.getActionFlag())){ |
|
|
if(StringUtils.equals(ModuleConstant.OPERATION_TYPE_MINUS,grantPoint.getActionFlag())){ |
|
|
//减
|
|
|
//减
|
|
|
if(grantPoint.getPoint() > NumConstant.ZERO){ |
|
|
if(grantPoint.getPoint() > NumConstant.ZERO){ |
|
@ -186,7 +290,7 @@ public class UserPointActionLogServiceImpl extends BaseServiceImpl<UserPointActi |
|
|
UserPointActionLogEntity action = new UserPointActionLogEntity(); |
|
|
UserPointActionLogEntity action = new UserPointActionLogEntity(); |
|
|
action.setCustomerId(grantPoint.getCustomerId()); |
|
|
action.setCustomerId(grantPoint.getCustomerId()); |
|
|
action.setPoint(grantPoint.getPoint()); |
|
|
action.setPoint(grantPoint.getPoint()); |
|
|
action.setEventStatement(grantPoint.getPointDesc()); |
|
|
action.setEventStatement(grantPoint.getRemark()); |
|
|
action.setEventName(EventEnum.ACTIVE_SEND_POINT.getEventDesc()); |
|
|
action.setEventName(EventEnum.ACTIVE_SEND_POINT.getEventDesc()); |
|
|
action.setEventId(EventEnum.ACTIVE_INSERT_LIVE.getEventTag()); |
|
|
action.setEventId(EventEnum.ACTIVE_INSERT_LIVE.getEventTag()); |
|
|
action.setActionFlag(grantPoint.getActionFlag()); |
|
|
action.setActionFlag(grantPoint.getActionFlag()); |
|
@ -206,7 +310,7 @@ public class UserPointActionLogServiceImpl extends BaseServiceImpl<UserPointActi |
|
|
statistical.setCreatedBy(grantPoint.getOperatorId()); |
|
|
statistical.setCreatedBy(grantPoint.getOperatorId()); |
|
|
statistical.setUpdatedBy(grantPoint.getOperatorId()); |
|
|
statistical.setUpdatedBy(grantPoint.getOperatorId()); |
|
|
userPointStatisticalDailyService.insertOrUpdate(statistical); |
|
|
userPointStatisticalDailyService.insertOrUpdate(statistical); |
|
|
//3.新增/修改用户总积分
|
|
|
//3.新增/修改用户积分日统计
|
|
|
UserPointTotalEntity point = new UserPointTotalEntity(); |
|
|
UserPointTotalEntity point = new UserPointTotalEntity(); |
|
|
point.setCustomerId(grantPoint.getCustomerId()); |
|
|
point.setCustomerId(grantPoint.getCustomerId()); |
|
|
point.setUserId(grantPoint.getUserId()); |
|
|
point.setUserId(grantPoint.getUserId()); |
|
|