Browse Source

积分核销 居民端、工作端相关

dev_shibei_match
wangchao 5 years ago
parent
commit
2c22b0913f
  1. 6
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
  2. 6
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java
  3. 37
      epmet-module/epmet-point/epmet-point-client/src/main/java/com/epmet/dto/result/PointExchangeResponseResultDTO.java
  4. 10
      epmet-module/epmet-point/epmet-point-client/src/main/java/dto/form/SendPointFormDTO.java
  5. 3
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/controller/MqPointCallbackController.java
  6. 13
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/controller/ResiPointController.java
  7. 3
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/dao/PointRuleDao.java
  8. 8
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/dao/UserPointActionLogDao.java
  9. 15
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/redis/PointRedis.java
  10. 10
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/PointRuleService.java
  11. 10
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/PointVerificationLogService.java
  12. 9
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/UserPointActionLogService.java
  13. 13
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/impl/PointRuleServiceImpl.java
  14. 37
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/impl/PointVerificationLogServiceImpl.java
  15. 112
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/impl/UserPointActionLogServiceImpl.java
  16. 2
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/utils/ModuleConstant.java
  17. 8
      epmet-module/epmet-point/epmet-point-server/src/main/resources/mapper/PointRuleDao.xml
  18. 18
      epmet-module/epmet-point/epmet-point-server/src/main/resources/mapper/UserPointActionLogDao.xml

6
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java

@ -271,4 +271,10 @@ public class RedisKeys {
return rootPrefix.concat("oper:user:shorId:").concat(shortUserId);
}
/**
* 居民端积分核销结果
* */
public static String getPointVerificationResultKey(String userId){
return rootPrefix.concat("resi:point:exchange:").concat(userId);
}
}

6
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisUtils.java

@ -171,6 +171,10 @@ public class RedisUtils {
}
}
public Object lindex(String key,Long index){
return redisTemplate.opsForList().index(key,index);
}
public Object rightPop(String key) {
return redisTemplate.opsForList().rightPop(key);
}
@ -190,7 +194,7 @@ public class RedisUtils {
}
public String getString(String key) {
return getString(key, DEFAULT_EXPIRE);
return stringRedisTemplate.opsForValue().get(key);
}
/**

37
epmet-module/epmet-point/epmet-point-client/src/main/java/com/epmet/dto/result/PointExchangeResponseResultDTO.java

@ -0,0 +1,37 @@
package com.epmet.dto.result;
import lombok.Data;
import java.io.Serializable;
/**
* @Description
* @ClassName PointExchangeResponseResultDTO
* @Auth wangc
* @Date 2020-07-31 16:07
*/
@Data
public class PointExchangeResponseResultDTO implements Serializable {
private static final long serialVersionUID = -6342757960284704496L;
/**
* 核销成功标识
* */
private boolean resultFlag;
/**
* 失败原因
* */
private String failureReason;
private Integer point;
/**
* 工作人员昵称
* */
private String operatorName;
/**
* 工作人员头像
* */
private String operatorProfile;
}

10
epmet-module/epmet-point/epmet-point-client/src/main/java/dto/form/SendPointFormDTO.java

@ -4,8 +4,11 @@ package dto.form;/**
* @date 2020-07-17 17:16
**/
import com.epmet.commons.tools.validator.group.CustomerClientShowGroup;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* desc发送积分dto
* @author lyn
@ -13,6 +16,9 @@ import lombok.Data;
*/
@Data
public class SendPointFormDTO {
public interface SendPointGroup extends CustomerClientShowGroup{}
private String pointDesc;
/**
@ -33,15 +39,18 @@ public class SendPointFormDTO {
/**
* 客户Id
*/
@NotBlank(message = "客户Id不能为空", groups = SendPointGroup.class)
private String customerId;
/**
* 被操作用户id
*/
@NotBlank(message = "用户Id不能为空", groups = SendPointGroup.class)
private String userId;
/**
* 加减分标识 plus/minus
*/
@NotBlank(message = "加减标识不能为空", groups = SendPointGroup.class)
private String actionFlag;
@ -53,6 +62,7 @@ public class SendPointFormDTO {
/**
* 备注
*/
@NotBlank(message = "积分备注不能为空", groups = SendPointGroup.class)
private String remark;
/**

3
epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/controller/MqPointCallbackController.java

@ -3,6 +3,7 @@ package com.epmet.controller;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.dto.form.mq.ReceiveMqMsg;
import com.epmet.commons.tools.dto.form.mq.eventmsg.BasePointEventMsg;
import com.epmet.commons.tools.enums.EventEnum;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.utils.ConvertUtils;
@ -75,6 +76,7 @@ public class MqPointCallbackController {
BasePointEventMsg formDTO = ConvertUtils.sourceToTarget(mqMsg.getMsg(), BasePointEventMsg.class);
try {
//TODO 调用调整积分方法去给用户加减积分 userPointActionLogService.
userPointActionLogService.grantPointByEvent(EventEnum.REGISTER_VOLUNTEER.getEventTag(),formDTO);
} catch (Exception e) {
logger.error("registerVolunteer consume fail", e);
throw new RenException(EpmetErrorCode.SERVER_ERROR.getMsg());
@ -99,6 +101,7 @@ public class MqPointCallbackController {
BasePointEventMsg formDTO = ConvertUtils.sourceToTarget(mqMsg.getMsg(), BasePointEventMsg.class);
try {
//TODO 调用调整积分方法去给用户加减积分 userPointActionLogService.
userPointActionLogService.grantPointByEvent(EventEnum.ACTIVE_INSERT_LIVE.getEventTag(),formDTO);
} catch (Exception e) {
logger.error("pubActiveLive consume fail", e);
throw new RenException(EpmetErrorCode.SERVER_ERROR.getMsg());

13
epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/controller/ResiPointController.java

@ -7,6 +7,7 @@ import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dto.form.CommonPageUserFormDTO;
import com.epmet.dto.form.ResiCommonUserIdFormDTO;
import com.epmet.dto.form.ResiPointRankFormDTO;
import com.epmet.dto.result.PointExchangeResponseResultDTO;
import com.epmet.dto.result.ResiPointDetailResultDTO;
import com.epmet.dto.result.ResiPointLogListResultDTO;
import com.epmet.dto.result.ResiPointRankListResultDTO;
@ -129,4 +130,16 @@ public class ResiPointController {
ValidatorUtils.validateEntity(pageUserParam,CommonPageUserFormDTO.PageUserGroup.class);
return new Result<List<ResiPointLogListResultDTO>>().ok(pointVerificationLogService.getMyExchangeRecord(pageUserParam));
}
/**
* @Description 居民端积分兑换响应
* @param tokenDto
* @return
* @author wangc
* @date 2020.07.31 16:17
**/
@PostMapping("exchangecallback")
public Result<PointExchangeResponseResultDTO> exchangeCallback(@LoginUser TokenDto tokenDto){
return new Result<PointExchangeResponseResultDTO>().ok(pointVerificationLogService.resiExchangeCallback(tokenDto.getUserId()));
}
}

3
epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/dao/PointRuleDao.java

@ -22,6 +22,7 @@ import com.epmet.dto.form.PointRuleListFormDTO;
import com.epmet.entity.PointRuleEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.PostMapping;
import java.util.List;
@ -51,4 +52,6 @@ public interface PointRuleDao extends BaseDao<PointRuleEntity> {
List<PointRuleEntity> selectListByFunctionId(PointRuleListFormDTO formDTO);
int updateByCustomerId(PointRuleEntity entity);
PointRuleEntity selectByEventCodeAndCustomerId(@Param("customerId") String customerId, @Param("eventCode") String eventCode);
}

8
epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/dao/UserPointActionLogDao.java

@ -43,4 +43,12 @@ public interface UserPointActionLogDao extends BaseDao<UserPointActionLogEntity>
**/
List<ResiPointLogPeriodResultDTO> selectPointActionLogList(@Param("userId") String userId);
/**
* @Description 查询指定用户在某条规则下所得的积分总和
* @param
* @return
* @author wangc
* @date 2020.07.31 15:11
**/
Integer selectSumByEvent(@Param("userId") String userId,@Param("eventId") String eventId, @Param("sourceId") String sourceId,@Param("customerId") String customerId);
}

15
epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/redis/PointRedis.java

@ -1,6 +1,8 @@
package com.epmet.redis;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.dto.result.PointExchangeResponseResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -15,4 +17,17 @@ public class PointRedis {
@Autowired
private RedisUtils redisUtils;
public void lpush(String userId , PointExchangeResponseResultDTO verificationResult){
redisUtils.leftPush(RedisKeys.getPointVerificationResultKey(userId),verificationResult);
}
public Object lindex(String userId,Long index){
return redisUtils.lindex(RedisKeys.getPointVerificationResultKey(userId),index);
}
public String checkIfQrCodeExpire(String shortId){
String userId = (String)redisUtils.getString(RedisKeys.getShortUserIdKey(shortId));
return userId;
}
}

10
epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/PointRuleService.java

@ -56,4 +56,14 @@ public interface PointRuleService extends BaseService<PointRuleEntity> {
void update(TokenDto tokenDTO, PointRuleFormDTO formDTO);
void add(TokenDto tokenDTO, PointRuleFormDTO formDTO);
/**
* @Description 根据evetCode和客户Id查找积分规则详情
* @param customerId
* @param eventCode
* @return
* @author wangc
* @date 2020.07.31 14:54
**/
PointRuleEntity getByEventCodeAndCustomerId(String customerId,String eventCode);
}

10
epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/PointVerificationLogService.java

@ -23,6 +23,7 @@ import com.epmet.dto.PointVerificationLogDTO;
import com.epmet.dto.form.CommonPageUserFormDTO;
import com.epmet.dto.form.PointVerificationFormDTO;
import com.epmet.dto.form.WorkPointVerificationFormDTO;
import com.epmet.dto.result.PointExchangeResponseResultDTO;
import com.epmet.dto.result.PointVerificationResultDTO;
import com.epmet.dto.result.ResiPointLogListResultDTO;
import com.epmet.dto.result.WorkPointVerficationListResultDTO;
@ -125,4 +126,13 @@ public interface PointVerificationLogService extends BaseService<PointVerificati
* @date 2020.07.27 14:03
**/
PointVerificationResultDTO verifyPoint(PointVerificationFormDTO verificationParam);
/**
* @Description 居民端积分核销响应
* @param userId
* @return
* @author wangc
* @date 2020.07.31 16:09
**/
PointExchangeResponseResultDTO resiExchangeCallback(String userId);
}

9
epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/UserPointActionLogService.java

@ -18,6 +18,7 @@
package com.epmet.service;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.dto.form.mq.eventmsg.BasePointEventMsg;
import com.epmet.commons.tools.page.PageData;
import com.epmet.dto.UserPointActionLogDTO;
import com.epmet.dto.form.CommonPageUserFormDTO;
@ -114,4 +115,12 @@ public interface UserPointActionLogService extends BaseService<UserPointActionLo
**/
void grantPoint(List<SendPointFormDTO> grantPointParam);
/**
* @Description 通过事件推送进行积分加减
* @param event
* @return
* @author wangc
* @date 2020.07.31 13:45
**/
void grantPointByEvent(String eventCode,BasePointEventMsg event);
}

13
epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/impl/PointRuleServiceImpl.java

@ -169,6 +169,19 @@ public class PointRuleServiceImpl extends BaseServiceImpl<PointRuleDao, PointRul
insertOperateRecord(tokenDTO, entity, null, CommonOperateTypeEnum.ADD.getCode());
}
/**
* @Description 根据evetCode和客户Id查找积分规则详情
* @param customerId
* @param eventCode
* @return
* @author wangc
* @date 2020.07.31 14:54
**/
@Override
public PointRuleEntity getByEventCodeAndCustomerId(String customerId, String eventCode) {
return baseDao.selectByEventCodeAndCustomerId(customerId,eventCode);
}
private void insertOperateRecord(TokenDto tokenDTO, PointRuleEntity entityNew, PointRuleEntity entityDB, String opType) {
RuleOperateLogEntity record = new RuleOperateLogEntity();
if (tokenDTO != null) {

37
epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/impl/PointVerificationLogServiceImpl.java

@ -17,11 +17,13 @@
package com.epmet.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.EpmetErrorCode;
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.constant.FieldConstant;
@ -77,7 +79,7 @@ public class PointVerificationLogServiceImpl extends BaseServiceImpl<PointVerifi
@Autowired
private PointVerificationStatisticalDailyService pointVerificationStatisticalDailyService;
@Autowired
PointRedis pointRedis;
private PointRedis pointRedis;
@Autowired
private UserPointActionLogDao userPointActionLogDao;
@Autowired
@ -237,6 +239,14 @@ public class PointVerificationLogServiceImpl extends BaseServiceImpl<PointVerifi
@Transactional(rollbackFor = Exception.class)
public PointVerificationResultDTO verifyPoint(PointVerificationFormDTO verificationParam) {
String decodedUserId = pointRedis.checkIfQrCodeExpire(verificationParam.getUserId());
if(StringUtils.isNotBlank(decodedUserId)){
verificationParam.setUserId(decodedUserId);
}else{
logger.error(String.format("用户二维码失效,参数详情 -> 【】", JSON.toJSON(verificationParam)));
throw new RenException("用户二维码失效");
}
DimIdGenerator.DimIdBean dim = DimIdGenerator.getDimIdBean(new Date());
PointVerificationResultDTO result = new PointVerificationResultDTO();
ResiCommonUserIdFormDTO userId = new ResiCommonUserIdFormDTO();
@ -245,6 +255,12 @@ public class PointVerificationLogServiceImpl extends BaseServiceImpl<PointVerifi
if(null == currentPoint || null == currentPoint.getUsablePoint() || currentPoint.getUsablePoint() < verificationParam.getPoint()){
result.setSuccessFlag(false);
result.setFailureReason(ModuleConstant.POINT_NOT_ENOUGH);
PointExchangeResponseResultDTO resultCache = new PointExchangeResponseResultDTO();
resultCache.setResultFlag(false);
resultCache.setFailureReason(ModuleConstant.POINT_NOT_ENOUGH);
pointRedis.lpush(verificationParam.getUserId(),resultCache);
return result;
}
IssueInitiatorFormDTO staffId = new IssueInitiatorFormDTO();
@ -321,6 +337,13 @@ public class PointVerificationLogServiceImpl extends BaseServiceImpl<PointVerifi
userPointTotalService.insertOrUpdate(userPoint);
//6.将核销结果记录redis(List) key -> [epmet:point:verification:userId] lpush #新元素插入表头 lindex key 0 #表头
PointExchangeResponseResultDTO resultCache = new PointExchangeResponseResultDTO();
resultCache.setResultFlag(true);
resultCache.setOperatorName(operatorName);
resultCache.setPoint(point * NumConstant.ONE_NEG);
//工作人员没有头像
pointRedis.lpush(verificationParam.getUserId(),resultCache);
result.setSuccessFlag(true);
List<String> userParam = new LinkedList<>();
userParam.add(verificationParam.getUserId());
@ -337,6 +360,18 @@ public class PointVerificationLogServiceImpl extends BaseServiceImpl<PointVerifi
return result;
}
/**
* @Description 居民端积分核销响应
* @param userId
* @return
* @author wangc
* @date 2020.07.31 16:09
**/
@Override
public PointExchangeResponseResultDTO resiExchangeCallback(String userId) {
return (PointExchangeResponseResultDTO)pointRedis.lindex(userId,NumConstant.ZERO_L);
}
/**
* @Description 得到指定日所在月第一天
* @param date

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

@ -17,19 +17,25 @@
package com.epmet.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.FieldConstant;
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.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dao.UserPointActionLogDao;
import com.epmet.dto.UserPointActionLogDTO;
import com.epmet.dto.form.CommonPageUserFormDTO;
import com.epmet.dto.form.PointRuleListFormDTO;
import com.epmet.dto.result.ResiPointLogListResultDTO;
import com.epmet.dto.result.ResiPointLogPeriodResultDTO;
import com.epmet.entity.PointRuleEntity;
import com.epmet.entity.UserPointActionLogEntity;
import com.epmet.entity.UserPointStatisticalDailyEntity;
import com.epmet.entity.UserPointTotalEntity;
@ -43,6 +49,10 @@ import com.google.common.collect.Maps;
import dto.form.SendPointFormDTO;
import lombok.extern.slf4j.Slf4j;
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -60,12 +70,13 @@ import java.util.stream.Collectors;
@Slf4j
@Service
public class UserPointActionLogServiceImpl extends BaseServiceImpl<UserPointActionLogDao, UserPointActionLogEntity> implements UserPointActionLogService {
private static Logger logger = LoggerFactory.getLogger(UserPointActionLogServiceImpl.class);
@Autowired
private UserPointTotalService userPointTotalService;
@Autowired
private UserPointStatisticalDailyService userPointStatisticalDailyService;
@Autowired
private PointRuleServiceImpl pointRuleService;
@Override
public PageData<UserPointActionLogDTO> page(Map<String, Object> params) {
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) {
ValidatorUtils.validateEntity(grantPoint, SendPointFormDTO.SendPointGroup.class);
if(StringUtils.equals(ModuleConstant.OPERATION_TYPE_MINUS,grantPoint.getActionFlag())){
//减
if(grantPoint.getPoint() > NumConstant.ZERO){
@ -186,7 +290,7 @@ public class UserPointActionLogServiceImpl extends BaseServiceImpl<UserPointActi
UserPointActionLogEntity action = new UserPointActionLogEntity();
action.setCustomerId(grantPoint.getCustomerId());
action.setPoint(grantPoint.getPoint());
action.setEventStatement(grantPoint.getPointDesc());
action.setEventStatement(grantPoint.getRemark());
action.setEventName(EventEnum.ACTIVE_SEND_POINT.getEventDesc());
action.setEventId(EventEnum.ACTIVE_INSERT_LIVE.getEventTag());
action.setActionFlag(grantPoint.getActionFlag());
@ -206,7 +310,7 @@ public class UserPointActionLogServiceImpl extends BaseServiceImpl<UserPointActi
statistical.setCreatedBy(grantPoint.getOperatorId());
statistical.setUpdatedBy(grantPoint.getOperatorId());
userPointStatisticalDailyService.insertOrUpdate(statistical);
//3.新增/修改用户积分
//3.新增/修改用户积分日统计
UserPointTotalEntity point = new UserPointTotalEntity();
point.setCustomerId(grantPoint.getCustomerId());
point.setUserId(grantPoint.getUserId());

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

@ -90,4 +90,6 @@ public interface ModuleConstant extends Constant {
String EVENT_NAME_EXCHANGE = "积分兑换";
String POINT_NOT_ENOUGH = "积分余额不足";
String CREATED_BY_SYSTEM = "SYSTEM";
}

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

@ -36,4 +36,12 @@
UP_LIMIT = #{upLimit,jdbcType=INTEGER}
WHERE id = #{id,jdbcType=VARCHAR} and CUSTOMER_ID = #{customerId,jdbcType=VARCHAR}
</update>
<select id="selectByEventCodeAndCustomerId" resultType="com.epmet.entity.PointRuleEntity">
SELECT ID,RULE_NAME,RULE_DESC,POINT,POINT_UNIT,ENABLED_FLAG,UP_LIMIT,OPERATE_TYPE
FROM point_rule
WHERE
DEL_FLAG = '0'
CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} AND EVENT_CODE = #{evertCode,jdbcType=VARCHAR}
</select>
</mapper>

18
epmet-module/epmet-point/epmet-point-server/src/main/resources/mapper/UserPointActionLogDao.xml

@ -40,4 +40,22 @@
CREATED_TIME DESC
</select>
<!-- 查询指定用户在某条规则下所得的积分总和 -->
<select id="selectSumByEvent" resultType="integer">
SELECT
SUM( POINT )
FROM
USER_POINT_ACTTION
WHERE
DEL_FLAG = '0'
AND USER_ID = #{userId}
AND EVENT_ID = #{eventCode}
<if test='null != customerId and "" != customerId'>
AND CUSTOMER_ID = #{customerId}
</if>
<if test='null != sourceId and "" != sourceId'>
AND SOURCE_ID = #{sourceId}
</if>
</select>
</mapper>
Loading…
Cancel
Save