新增红包雨功能
This commit is contained in:
@@ -2313,6 +2313,9 @@ public enum RedisKey {
|
||||
//活动消息状态
|
||||
act_user_task_message_status,
|
||||
|
||||
//红包雨列表
|
||||
red_envelope_rain_list,
|
||||
|
||||
;
|
||||
|
||||
public String getKey() {
|
||||
|
@@ -64,7 +64,7 @@ open class BaseRequestVO {
|
||||
val imei: String? = httpServletRequest?.getHeader(PublicHeaderParamEnum.IMEI.value).orEmpty()
|
||||
|
||||
@get: ApiModelProperty("公共参数-当前用户 userId", hidden = true)
|
||||
val myUserId: Long? = httpServletRequest?.getHeader(PublicHeaderParamEnum.PUB_UID.value)?.toLongOrNull()
|
||||
var myUserId: Long? = httpServletRequest?.getHeader(PublicHeaderParamEnum.PUB_UID.value)?.toLongOrNull()
|
||||
|
||||
@get: ApiModelProperty("公共参数-当前用户 ticket", hidden = true)
|
||||
val myTicket: String? = httpServletRequest?.getHeader(PublicHeaderParamEnum.PUB_TICKET.value)
|
||||
|
@@ -2,18 +2,24 @@ package com.accompany.business.fools.handler;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.accompany.business.activity.dto.ActTaskContext;
|
||||
import com.accompany.business.activity.enums.ActConditionKindEnum;
|
||||
import com.accompany.business.activity.enums.ActTaskStatusEnum;
|
||||
import com.accompany.business.activity.handle.IActTaskHandler;
|
||||
import com.accompany.business.activity.model.ActTask;
|
||||
import com.accompany.business.activity.model.ActTaskCondition;
|
||||
import com.accompany.business.activity.model.ActUserTask;
|
||||
import com.accompany.business.constant.redenvelope.OuterRedEnvelopeTypeEnum;
|
||||
import com.accompany.business.enums.message.ContentTypeEnum;
|
||||
import com.accompany.business.enums.message.ResourceTypeEnum;
|
||||
import com.accompany.business.model.redenvelope.RedEnvelopeRain;
|
||||
import com.accompany.business.service.SendSysMsgService;
|
||||
import com.accompany.business.service.redenvelope.RedEnvelopeRainService;
|
||||
import com.accompany.business.service.redenvelope.RedEnvelopeService;
|
||||
import com.accompany.business.service.room.RoomService;
|
||||
import com.accompany.business.vo.message.FloatingMessageTemplate;
|
||||
import com.accompany.business.vo.message.MessageTemplate;
|
||||
import com.accompany.business.vo.message.TextSpan;
|
||||
import com.accompany.common.config.SystemConfig;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
@@ -52,6 +58,12 @@ public class AprilFoolsDayRoomHandler extends IActTaskHandler {
|
||||
@Autowired
|
||||
private SendSysMsgService sendSysMsgService;
|
||||
|
||||
@Autowired
|
||||
private RedEnvelopeRainService redEnvelopeRainService;
|
||||
|
||||
@Autowired
|
||||
private RedEnvelopeService redEnvelopeService;
|
||||
|
||||
@Override
|
||||
public boolean ge(ActTaskCondition actTaskCondition, ActTaskContext context) {
|
||||
Long giftValue = context.getGiftValue();
|
||||
@@ -68,6 +80,12 @@ public class AprilFoolsDayRoomHandler extends IActTaskHandler {
|
||||
if (taskValue != null && !isPermitRoom.equals(taskValue.byteValue())) {
|
||||
return false;
|
||||
}
|
||||
//红包雨进行中
|
||||
boolean isUnderway = redEnvelopeRainService.isUnderway(roomUid);
|
||||
if (isUnderway) {
|
||||
log.info("红包雨进行中...");
|
||||
return false;
|
||||
}
|
||||
String activityCode = actTask.getActivityCode();
|
||||
String componentCode = actTask.getComponentCode();
|
||||
String taskCode = actTask.getTaskCode();
|
||||
@@ -133,7 +151,54 @@ public class AprilFoolsDayRoomHandler extends IActTaskHandler {
|
||||
|
||||
@Override
|
||||
public void doHandle(ActTaskContext context) {
|
||||
|
||||
ActTask actTask = context.getActTask();
|
||||
Long roomUid = context.getRoomUid();
|
||||
Date startTime = context.getActivityStartTime();
|
||||
Date endTime = context.getActivityEndTime();
|
||||
Room room = roomService.getRoomByUid(roomUid);
|
||||
if (room == null) {
|
||||
return;
|
||||
}
|
||||
String activityCode = actTask.getActivityCode();
|
||||
String componentCode = actTask.getComponentCode();
|
||||
String taskCode = actTask.getTaskCode();
|
||||
Integer taskValue = actTask.getTaskValue();
|
||||
List<ActTaskCondition> actTaskConditions = actTaskConditionService.list(Wrappers.<ActTaskCondition>lambdaQuery()
|
||||
.eq(ActTaskCondition::getActivityCode, activityCode)
|
||||
.eq(ActTaskCondition::getComponentCode, componentCode)
|
||||
.eq(ActTaskCondition::getTaskCode, taskCode)
|
||||
.eq(ActTaskCondition::getConditionKind, ActConditionKindEnum.GE.name()));
|
||||
if (CollectionUtil.isEmpty(actTaskConditions)) {
|
||||
return;
|
||||
}
|
||||
ActTaskCondition actTaskCondition = actTaskConditions.get(0);
|
||||
String conditionCode = actTaskCondition.getConditionCode();
|
||||
List<ActUserTask> actUserTasks = actUserTaskService.list(Wrappers.<ActUserTask>lambdaQuery()
|
||||
.eq(ActUserTask::getActivityCode, activityCode)
|
||||
.eq(ActUserTask::getComponentCode, componentCode)
|
||||
.eq(ActUserTask::getTaskCode, taskCode)
|
||||
.eq(ActUserTask::getConditionCode, conditionCode)
|
||||
.eq(ActUserTask::getUid, roomUid)
|
||||
.eq(ActUserTask::getTaskStatus, ActTaskStatusEnum.COMPLETE.ordinal())
|
||||
.between(ActUserTask::getCreateTime, startTime, endTime)
|
||||
.orderByAsc(ActUserTask::getCreateTime));
|
||||
if (CollectionUtil.isEmpty(actUserTasks)) {
|
||||
return;
|
||||
}
|
||||
//红包雨
|
||||
List<RedEnvelopeRain> redEnvelopeRains = redEnvelopeRainService.getRedEnvelopeRainByPermitType(taskValue);
|
||||
if (CollectionUtil.isEmpty(redEnvelopeRains)) {
|
||||
return;
|
||||
}
|
||||
for (ActUserTask actUserTask : actUserTasks) {
|
||||
for (RedEnvelopeRain redEnvelopeRain : redEnvelopeRains) {
|
||||
redEnvelopeRainService.addRedEnvelope(redEnvelopeRainService.buildRedEnvelope(Long.valueOf(SystemConfig.systemMessageUid), actUserTask.getUid(), OuterRedEnvelopeTypeEnum.DIAMOND_IN_ROOM, redEnvelopeRain));
|
||||
}
|
||||
actUserTask.setTaskStatus(ActTaskStatusEnum.GRANT.ordinal());
|
||||
actUserTaskService.updateById(actUserTask);
|
||||
}
|
||||
//发红包
|
||||
redEnvelopeRainService.sendRedEnvelope(roomUid);
|
||||
}
|
||||
|
||||
private void sendMessage(String activityCode, Date startTime, Date endTime, Long actUserTaskId, Long activityValue, Long conditionValue, Room room) {
|
||||
|
@@ -24,7 +24,13 @@ public class RedEnvelopeRain {
|
||||
*/
|
||||
@ApiModelProperty("主键")
|
||||
@TableId(type = IdType.AUTO)
|
||||
public Long id;
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 牌照类型
|
||||
*/
|
||||
@ApiModelProperty("牌照类型")
|
||||
private Integer permitType;
|
||||
|
||||
/**
|
||||
* 标题内容
|
||||
@@ -63,10 +69,28 @@ public class RedEnvelopeRain {
|
||||
private Integer kind;
|
||||
|
||||
/**
|
||||
* 生效类型 0 立即生效 1 限时生效
|
||||
* 开始倒计时
|
||||
*/
|
||||
@ApiModelProperty("生效类型 0 立即生效 1 限时生效")
|
||||
private Integer validityType;
|
||||
@ApiModelProperty("开始倒计时")
|
||||
private Integer countDownSecond;
|
||||
|
||||
/**
|
||||
* 红包有效时长
|
||||
*/
|
||||
@ApiModelProperty("红包有效时长")
|
||||
private Integer timeDuration;
|
||||
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
@ApiModelProperty("开始时间")
|
||||
private Date startTime;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
@ApiModelProperty("结束时间")
|
||||
private Date endTime;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
|
@@ -0,0 +1,56 @@
|
||||
package com.accompany.business.model.redenvelope;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author: liaozetao
|
||||
* @date: 2024/3/21 17:20
|
||||
* @description:
|
||||
*/
|
||||
@Data
|
||||
@TableName("red_envelope_rain_record")
|
||||
public class RedEnvelopeRainRecord {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@ApiModelProperty("主键")
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 房间UID
|
||||
*/
|
||||
@ApiModelProperty("房间UID")
|
||||
private Long roomUid;
|
||||
|
||||
/**
|
||||
* 红包雨ID
|
||||
*/
|
||||
@ApiModelProperty("红包雨ID")
|
||||
private Long redEnvelopeRainId;
|
||||
|
||||
/**
|
||||
* 红包ID
|
||||
*/
|
||||
@ApiModelProperty("红包ID")
|
||||
private Long redEnvelopeId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@ApiModelProperty("创建时间")
|
||||
public Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@ApiModelProperty("更新时间")
|
||||
public Date updateTime;
|
||||
}
|
@@ -61,5 +61,16 @@ class SendRedEnvelopeRequest : BaseRequestVO() {
|
||||
@ApiModelProperty("生效类型 0 立即生效 1 限时生效")
|
||||
var validityType: Int = 0
|
||||
|
||||
/**
|
||||
* 红包时长
|
||||
*/
|
||||
@ApiModelProperty("红包时长")
|
||||
var timeDuration: Int = 0
|
||||
|
||||
/**
|
||||
* 红包雨ID
|
||||
*/
|
||||
@ApiModelProperty("红包雨ID")
|
||||
var redEnvelopeRainId: Long = 0
|
||||
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package com.accompany.business.event.listener.redenvelope;
|
||||
import com.accompany.business.constant.redenvelope.RedEnvelopStateEnum;
|
||||
import com.accompany.business.event.redenvelope.RedEnvelopeEvent;
|
||||
import com.accompany.business.model.redenvelope.RedEnvelope;
|
||||
import com.accompany.business.service.redenvelope.RedEnvelopeRainService;
|
||||
import com.accompany.business.service.redenvelope.RedEnvelopeService;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -22,6 +23,9 @@ public class RedEnvelopeListener implements ApplicationListener<RedEnvelopeEvent
|
||||
@Autowired
|
||||
private RedEnvelopeService redEnvelopeService;
|
||||
|
||||
@Autowired
|
||||
private RedEnvelopeRainService redEnvelopeRainService;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(RedEnvelopeEvent event) {
|
||||
Object source = event.getSource();
|
||||
@@ -29,6 +33,11 @@ public class RedEnvelopeListener implements ApplicationListener<RedEnvelopeEvent
|
||||
return;
|
||||
}
|
||||
Long redEnvelopeId = (Long) source;
|
||||
RedEnvelope redEnvelope = redEnvelopeService.getById(redEnvelopeId);
|
||||
if (redEnvelope == null) {
|
||||
return;
|
||||
}
|
||||
Long roomUid = redEnvelope.getRoomUid();
|
||||
log.info("RedEnvelopeListener redEnvelopeId : {}", redEnvelopeId);
|
||||
RedEnvelopStateEnum redEnvelopState = redEnvelopeService.stateById(redEnvelopeId);
|
||||
if (redEnvelopState == null) {
|
||||
@@ -40,5 +49,14 @@ public class RedEnvelopeListener implements ApplicationListener<RedEnvelopeEvent
|
||||
.set(RedEnvelope::getState, state)
|
||||
.eq(RedEnvelope::getId, redEnvelopeId));
|
||||
log.info("更新红包状态 redEnvelopeId : {}, state : {}", redEnvelopeId, state);
|
||||
//超时
|
||||
if (state == RedEnvelopStateEnum.TIME_OUT.getCode()) {
|
||||
log.info("红包超时...");
|
||||
redEnvelopeRainService.sendRedEnvelope(roomUid);
|
||||
//抢光了
|
||||
} else if (state == RedEnvelopStateEnum.REMAIN_ZERO.getCode()) {
|
||||
log.info("红包抢光...");
|
||||
redEnvelopeRainService.sendRedEnvelope(roomUid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,12 @@
|
||||
package com.accompany.business.mybatismapper.redenvelope;
|
||||
|
||||
import com.accompany.business.model.redenvelope.RedEnvelopeRainRecord;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author: liaozetao
|
||||
* @date: 2024/3/21 17:24
|
||||
* @description:
|
||||
*/
|
||||
public interface RedEnvelopeRainRecordMapper extends BaseMapper<RedEnvelopeRainRecord> {
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package com.accompany.business.service.redenvelope;
|
||||
|
||||
import com.accompany.business.model.redenvelope.RedEnvelopeRainRecord;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author: liaozetao
|
||||
* @date: 2024/3/21 17:28
|
||||
* @description:
|
||||
*/
|
||||
public interface RedEnvelopeRainRecordService extends IService<RedEnvelopeRainRecord> {
|
||||
}
|
@@ -1,12 +1,58 @@
|
||||
package com.accompany.business.service.redenvelope;
|
||||
|
||||
import com.accompany.business.constant.redenvelope.OuterRedEnvelopeTypeEnum;
|
||||
import com.accompany.business.model.redenvelope.RedEnvelopeRain;
|
||||
import com.accompany.business.vo.redenvelope.OpenRedEnvelopeRequest;
|
||||
import com.accompany.business.vo.redenvelope.SendRedEnvelopeRequest;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: liaozetao
|
||||
* @date: 2024/3/20 11:55
|
||||
* @description:
|
||||
*/
|
||||
public interface RedEnvelopeRainService extends IService<RedEnvelopeRain> {
|
||||
|
||||
/**
|
||||
* 添加红包
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
void addRedEnvelope(SendRedEnvelopeRequest request);
|
||||
|
||||
/**
|
||||
* 发红包
|
||||
*
|
||||
* @param roomUid
|
||||
*/
|
||||
void sendRedEnvelope(Long roomUid);
|
||||
|
||||
/**
|
||||
* 获取红包雨
|
||||
*
|
||||
* @param permitType
|
||||
* @return
|
||||
*/
|
||||
List<RedEnvelopeRain> getRedEnvelopeRainByPermitType(Integer permitType);
|
||||
|
||||
/**
|
||||
* 构建红包请求
|
||||
*
|
||||
* @param userId
|
||||
* @param roomUid
|
||||
* @param type
|
||||
* @param redEnvelopeRain
|
||||
* @return
|
||||
*/
|
||||
SendRedEnvelopeRequest buildRedEnvelope(Long userId, Long roomUid, OuterRedEnvelopeTypeEnum type, RedEnvelopeRain redEnvelopeRain);
|
||||
|
||||
/**
|
||||
* 是否进行中
|
||||
*
|
||||
* @param roomUid
|
||||
* @return
|
||||
*/
|
||||
boolean isUnderway(Long roomUid);
|
||||
}
|
||||
|
@@ -254,12 +254,33 @@ public class RedEnvelopeService extends ServiceImpl<RedEnvelopeMapper, RedEnvelo
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void sendRedEnvelope(SendRedEnvelopeRequest request) {
|
||||
public void sendRedEnvelopeForCheck(SendRedEnvelopeRequest request) {
|
||||
Long roomUid = request.getRoomUId();
|
||||
List<RedEnvelope> validRedEnvelopes = getValidRedEnvelopes(roomUid);
|
||||
if (CollectionUtil.isNotEmpty(validRedEnvelopes)) {
|
||||
throw new ApiException("當前房間內還有未搶完/未到期的紅包,暫時不能發出新紅包");
|
||||
}
|
||||
//生效类型
|
||||
int validityType = request.getValidityType();
|
||||
int beginSecond = request.getCountDownSecond();
|
||||
int endSecond = request.getTimeDuration();
|
||||
RedEnvelopeConfig config = redEnvelopeConfig();
|
||||
if (config != null) {
|
||||
if (validityType != 0) {
|
||||
//获取红包配置
|
||||
beginSecond = config.getBeginSecond();
|
||||
}
|
||||
endSecond = config.getEndSecond();
|
||||
}
|
||||
request.setCountDownSecond(beginSecond);
|
||||
request.setTimeDuration(endSecond);
|
||||
//发红包
|
||||
sendRedEnvelope(request, true);
|
||||
}
|
||||
|
||||
public Long sendRedEnvelope(SendRedEnvelopeRequest request, boolean isCheck) {
|
||||
int beginSecond = request.getCountDownSecond();
|
||||
int endSecond = request.getTimeDuration();
|
||||
RedEnvelopeContext context = new RedEnvelopeContext();
|
||||
context.setRoomUid(request.getRoomUId());
|
||||
context.setUid(request.getMyUserId());
|
||||
@@ -269,20 +290,13 @@ public class RedEnvelopeService extends ServiceImpl<RedEnvelopeMapper, RedEnvelo
|
||||
context.setAmount(request.getGoldNum());
|
||||
context.setNum(request.getNum());
|
||||
context.setPassword(request.getPassword());
|
||||
//生效类型
|
||||
int validityType = request.getValidityType();
|
||||
int beginSecond = request.getCountDownSecond();
|
||||
RedEnvelopeConfig config = redEnvelopeConfig();
|
||||
if (validityType != 0) {
|
||||
//获取红包配置
|
||||
beginSecond = config.getBeginSecond();
|
||||
}
|
||||
int endSecond = config.getEndSecond();
|
||||
context.setCheck(isCheck);
|
||||
long now = System.currentTimeMillis();
|
||||
context.setBeginTime(new Date(now + beginSecond * 1000L));
|
||||
context.setEndTime(new Date(now + endSecond * 1000L));
|
||||
context.setValidityType(request.getValidityType());
|
||||
Objects.requireNonNull(RedEnvelopeFactory.INSTANCE.getInstance(request.getKind())).send(context);
|
||||
return context.getRedEnvelopeId();
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
|
@@ -0,0 +1,18 @@
|
||||
package com.accompany.business.service.redenvelope.impl;
|
||||
|
||||
import com.accompany.business.model.redenvelope.RedEnvelopeRainRecord;
|
||||
import com.accompany.business.mybatismapper.redenvelope.RedEnvelopeRainRecordMapper;
|
||||
import com.accompany.business.service.redenvelope.RedEnvelopeRainRecordService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author: liaozetao
|
||||
* @date: 2024/3/21 17:29
|
||||
* @description:
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class RedEnvelopeRainRecordServiceImpl extends ServiceImpl<RedEnvelopeRainRecordMapper, RedEnvelopeRainRecord> implements RedEnvelopeRainRecordService {
|
||||
}
|
@@ -1,12 +1,36 @@
|
||||
package com.accompany.business.service.redenvelope.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.accompany.business.activity.model.ActActivity;
|
||||
import com.accompany.business.constant.redenvelope.OuterRedEnvelopeTypeEnum;
|
||||
import com.accompany.business.constant.redenvelope.RedEnvelopStateEnum;
|
||||
import com.accompany.business.model.redenvelope.RedEnvelope;
|
||||
import com.accompany.business.model.redenvelope.RedEnvelopeRain;
|
||||
import com.accompany.business.model.redenvelope.RedEnvelopeRainRecord;
|
||||
import com.accompany.business.mybatismapper.redenvelope.RedEnvelopeRainMapper;
|
||||
import com.accompany.business.service.redenvelope.RedEnvelopeRainRecordService;
|
||||
import com.accompany.business.service.redenvelope.RedEnvelopeRainService;
|
||||
import com.accompany.business.service.redenvelope.RedEnvelopeService;
|
||||
import com.accompany.business.service.redenvelope.strategy.RedEnvelopeContext;
|
||||
import com.accompany.business.vo.redenvelope.OpenRedEnvelopeRequest;
|
||||
import com.accompany.business.vo.redenvelope.SendRedEnvelopeRequest;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.core.model.Room;
|
||||
import com.accompany.core.mybatismapper.RoomMapper;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author: liaozetao
|
||||
* @date: 2024/3/20 11:55
|
||||
@@ -15,4 +39,107 @@ import org.springframework.stereotype.Service;
|
||||
@Slf4j
|
||||
@Service
|
||||
public class RedEnvelopeRainServiceImpl extends ServiceImpl<RedEnvelopeRainMapper, RedEnvelopeRain> implements RedEnvelopeRainService {
|
||||
|
||||
@Autowired
|
||||
private RoomMapper roomMapper;
|
||||
|
||||
@Autowired
|
||||
private RedEnvelopeService redEnvelopeService;
|
||||
|
||||
@Autowired
|
||||
private RedEnvelopeRainRecordService redEnvelopeRainRecordService;
|
||||
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
|
||||
@Override
|
||||
public void addRedEnvelope(SendRedEnvelopeRequest request) {
|
||||
//保留一周
|
||||
int ONE_WEEK = 7 * 24 * 60 * 60;
|
||||
String redisKey = RedisKey.red_envelope_rain_list.getKey(String.valueOf(request.getRoomUId()));
|
||||
jedisService.lpush(redisKey, JSONObject.toJSONString(request));
|
||||
jedisService.expire(redisKey, ONE_WEEK);
|
||||
}
|
||||
|
||||
public void sendRedEnvelope(Long roomUid) {
|
||||
Date now = new Date();
|
||||
int count = count(Wrappers.<RedEnvelopeRain>lambdaQuery()
|
||||
.le(RedEnvelopeRain::getStartTime, now)
|
||||
.ge(RedEnvelopeRain::getEndTime, now));
|
||||
if (count == 0) {
|
||||
return;
|
||||
}
|
||||
String redEnvelopeJson = jedisService.lpop(RedisKey.red_envelope_rain_list.getKey(String.valueOf(roomUid)));
|
||||
if (StrUtil.isEmpty(redEnvelopeJson)) {
|
||||
return;
|
||||
}
|
||||
log.info("RedEnvelopeRain json : {}", redEnvelopeJson);
|
||||
SendRedEnvelopeRequest request = JSONObject.parseObject(redEnvelopeJson, SendRedEnvelopeRequest.class);
|
||||
//发红包
|
||||
Long redEnvelopeId = redEnvelopeService.sendRedEnvelope(request, false);
|
||||
//红包雨关联红包记录
|
||||
RedEnvelopeRainRecord record = new RedEnvelopeRainRecord();
|
||||
record.setRoomUid(roomUid);
|
||||
record.setRedEnvelopeId(redEnvelopeId);
|
||||
record.setRedEnvelopeRainId(request.getRedEnvelopeRainId());
|
||||
record.setCreateTime(now);
|
||||
record.setUpdateTime(now);
|
||||
redEnvelopeRainRecordService.save(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RedEnvelopeRain> getRedEnvelopeRainByPermitType(Integer permitType) {
|
||||
Date now = new Date();
|
||||
return list(Wrappers.<RedEnvelopeRain>lambdaQuery()
|
||||
.eq(RedEnvelopeRain::getPermitType, permitType)
|
||||
.le(RedEnvelopeRain::getStartTime, now)
|
||||
.ge(RedEnvelopeRain::getEndTime, now));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SendRedEnvelopeRequest buildRedEnvelope(Long userId, Long roomUid, OuterRedEnvelopeTypeEnum type, RedEnvelopeRain redEnvelopeRain) {
|
||||
SendRedEnvelopeRequest request = new SendRedEnvelopeRequest();
|
||||
request.setMyUserId(userId);
|
||||
request.setRoomUId(roomUid);
|
||||
request.setType(type.getCode());
|
||||
if (redEnvelopeRain != null) {
|
||||
request.setRedEnvelopeRainId(redEnvelopeRain.getId());
|
||||
request.setGoldNum(redEnvelopeRain.getOriginalAmount().longValue());
|
||||
request.setNum(redEnvelopeRain.getNum());
|
||||
request.setKind(redEnvelopeRain.getKind());
|
||||
request.setMessage(redEnvelopeRain.getMessage());
|
||||
request.setCountDownSecond(redEnvelopeRain.getCountDownSecond());
|
||||
request.setTimeDuration(redEnvelopeRain.getTimeDuration());
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
public boolean isUnderway(Long roomUid) {
|
||||
Room room = roomMapper.selectByPrimaryKey(roomUid);
|
||||
if (room == null) {
|
||||
return false;
|
||||
}
|
||||
Byte permitType = room.getIsPermitRoom();
|
||||
List<RedEnvelopeRain> redEnvelopeRains = getRedEnvelopeRainByPermitType(Integer.valueOf(permitType));
|
||||
if (CollectionUtil.isEmpty(redEnvelopeRains)) {
|
||||
return false;
|
||||
}
|
||||
List<Long> redEnvelopeRainIds = redEnvelopeRains.stream().map(RedEnvelopeRain::getId).collect(Collectors.toList());
|
||||
List<RedEnvelopeRainRecord> redEnvelopeRainRecords = redEnvelopeRainRecordService.list(Wrappers.<RedEnvelopeRainRecord>lambdaQuery()
|
||||
.select(RedEnvelopeRainRecord::getRedEnvelopeId)
|
||||
.eq(RedEnvelopeRainRecord::getRoomUid, roomUid)
|
||||
.in(RedEnvelopeRainRecord::getRedEnvelopeRainId, redEnvelopeRainIds));
|
||||
if (CollectionUtil.isEmpty(redEnvelopeRainRecords)) {
|
||||
return false;
|
||||
}
|
||||
List<Long> redEnvelopeIds = redEnvelopeRainRecords.stream().map(RedEnvelopeRainRecord::getRedEnvelopeId).collect(Collectors.toList());
|
||||
for (Long redEnvelopeId : redEnvelopeIds) {
|
||||
RedEnvelopStateEnum state = redEnvelopeService.stateById(redEnvelopeId);
|
||||
if (RedEnvelopStateEnum.ING.compareTo(state) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -86,43 +86,46 @@ abstract class IRedEnvelopeStrategy {
|
||||
val amount = context.amount
|
||||
var message = context.message
|
||||
val password = context.password
|
||||
if (message == null || StrUtil.isEmpty(message)) {
|
||||
throw ApiException("紅包標題不能為空")
|
||||
}
|
||||
//去空格
|
||||
message = message.replace(StrUtil.SPACE, StrUtil.EMPTY);
|
||||
if (message.length > 10) {
|
||||
throw ApiException("紅包標題長度不能超過10")
|
||||
}
|
||||
if (YidunCheckUtil.checkHasSensitiveWord(message)) {
|
||||
throw ApiException("當前內容不符合規範,請修改后重試哦~")
|
||||
}
|
||||
val users = usersService!!.getUsersByUid(uid)
|
||||
val payPassWord = users.paymentPwd ?: throw ApiException("請設置支付密碼")
|
||||
if (!usersService!!.checkPaymentPwd(password, payPassWord)) {
|
||||
throw ApiException(BusiStatus.USER_INCORRECT_PAYMENT_PASS.reasonPhrase)
|
||||
}
|
||||
val minAmount = when (type) {
|
||||
RedEnvelopeTypeConstant.IN_ROOM -> 10
|
||||
RedEnvelopeTypeConstant.SERVER -> 100
|
||||
else -> 100
|
||||
}
|
||||
if (amount % minAmount > 0) {
|
||||
throw ApiException("紅包鉆石數量必須為${minAmount}的倍數")
|
||||
}
|
||||
if (!roomRedEnvelopeService!!.hasRedEnvelope(roomUid, uid, type)) {
|
||||
throw ApiException("對應權限不足,請更新版本")
|
||||
}
|
||||
//红包金额检测
|
||||
val redEnvelopeAmount = redEnvelopeAmount(amount)
|
||||
if (UserPurseUtil.subTwoDouble(num * 1.0, redEnvelopeAmount) > 0) {
|
||||
throw ApiException("單個紅包金額過小")
|
||||
}
|
||||
//余额校验
|
||||
val userPurse = userPurseService!!.queryUserPurse(uid)
|
||||
val currentDiamonds = userPurse.diamonds
|
||||
if (currentDiamonds < amount) {
|
||||
throw ApiException(BusiStatus.NOT_ENOUGH_DIAMOND)
|
||||
val isCheck = context.isCheck
|
||||
if (isCheck) {
|
||||
if (message == null || StrUtil.isEmpty(message)) {
|
||||
throw ApiException("紅包標題不能為空")
|
||||
}
|
||||
//去空格
|
||||
message = message.replace(StrUtil.SPACE, StrUtil.EMPTY);
|
||||
if (message.length > 10) {
|
||||
throw ApiException("紅包標題長度不能超過10")
|
||||
}
|
||||
if (YidunCheckUtil.checkHasSensitiveWord(message)) {
|
||||
throw ApiException("當前內容不符合規範,請修改后重試哦~")
|
||||
}
|
||||
val users = usersService!!.getUsersByUid(uid)
|
||||
val payPassWord = users.paymentPwd ?: throw ApiException("請設置支付密碼")
|
||||
if (!usersService!!.checkPaymentPwd(password, payPassWord)) {
|
||||
throw ApiException(BusiStatus.USER_INCORRECT_PAYMENT_PASS.reasonPhrase)
|
||||
}
|
||||
val minAmount = when (type) {
|
||||
RedEnvelopeTypeConstant.IN_ROOM -> 10
|
||||
RedEnvelopeTypeConstant.SERVER -> 100
|
||||
else -> 100
|
||||
}
|
||||
if (amount % minAmount > 0) {
|
||||
throw ApiException("紅包鉆石數量必須為${minAmount}的倍數")
|
||||
}
|
||||
if (!roomRedEnvelopeService!!.hasRedEnvelope(roomUid, uid, type)) {
|
||||
throw ApiException("對應權限不足,請更新版本")
|
||||
}
|
||||
//红包金额检测
|
||||
val redEnvelopeAmount = redEnvelopeAmount(amount)
|
||||
if (UserPurseUtil.subTwoDouble(num * 1.0, redEnvelopeAmount) > 0) {
|
||||
throw ApiException("單個紅包金額過小")
|
||||
}
|
||||
//余额校验
|
||||
val userPurse = userPurseService!!.queryUserPurse(uid)
|
||||
val currentDiamonds = userPurse.diamonds
|
||||
if (currentDiamonds < amount) {
|
||||
throw ApiException(BusiStatus.NOT_ENOUGH_DIAMOND)
|
||||
}
|
||||
}
|
||||
//处理发红包业务
|
||||
doSend(context)
|
||||
|
@@ -69,4 +69,9 @@ class RedEnvelopeContext {
|
||||
* 生效类型 0 立即生效 1 限时生效
|
||||
*/
|
||||
var validityType: Int = 0
|
||||
|
||||
/**
|
||||
* 是否校验
|
||||
*/
|
||||
var isCheck: Boolean = true
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.accompany.business.mybatismapper.redenvelope.RedEnvelopeRainRecordMapper">
|
||||
|
||||
</mapper>
|
@@ -54,7 +54,7 @@ open class RedEnvelopeController {
|
||||
@Authorization
|
||||
@PostMapping
|
||||
open fun sendRedEnvelope(request: SendRedEnvelopeRequest): BusiResult<Void> {
|
||||
redEnvelopeService.sendRedEnvelope(request)
|
||||
redEnvelopeService.sendRedEnvelopeForCheck(request)
|
||||
return BusiResult.success()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user