|
|
|
@ -1,16 +1,25 @@ |
|
|
|
package com.bnyer.img.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.bnyer.common.core.constant.RedisKeyConstant; |
|
|
|
import com.bnyer.common.core.domain.GoldLog; |
|
|
|
import com.bnyer.common.core.dto.GoldLogPageDto; |
|
|
|
import com.bnyer.common.core.dto.GetGoldDto; |
|
|
|
import com.bnyer.common.core.enums.GoldEnum; |
|
|
|
import com.bnyer.common.core.exception.ServiceException; |
|
|
|
import com.bnyer.common.core.utils.StringUtils; |
|
|
|
import com.bnyer.common.redis.service.RedisService; |
|
|
|
import com.bnyer.common.rocketmq.constant.RocketMqTopic; |
|
|
|
import com.bnyer.common.rocketmq.domain.img.GoldRewardMessage; |
|
|
|
import com.bnyer.img.mapper.GoldLogMapper; |
|
|
|
import com.bnyer.img.service.GoldLogService; |
|
|
|
import com.bnyer.img.service.ImgMqMessageRecordService; |
|
|
|
import com.bnyer.img.vo.GoldLogVo; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
@ -21,6 +30,12 @@ public class GoldLogServiceImpl implements GoldLogService { |
|
|
|
@Autowired |
|
|
|
private GoldLogMapper goldLogMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RedisService redisService; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ImgMqMessageRecordService mqMessageRecordService; |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public int insert(GoldLog goldLog) { |
|
|
|
@ -34,4 +49,109 @@ public class GoldLogServiceImpl implements GoldLogService { |
|
|
|
public List<GoldLogVo> queryPage(Long userId, String source) { |
|
|
|
return goldLogMapper.queryPage(userId,source); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void signGetGold(GetGoldDto param) { |
|
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
String date = df.format(new Date()); |
|
|
|
String redisKey = RedisKeyConstant.PLATFORM_USER_SIGN_REWARD_KEY + date; |
|
|
|
String hashKey = param.getAppType()+":"+param.getSource()+":"+param.getUserId(); |
|
|
|
//判断redis中是否存在签到数据,有则提示当日已签到,否则则进行签到,发送mq消息写入缓存,给予奖励,写入奖励记录
|
|
|
|
if(redisService.hasHashKey(redisKey,hashKey)){ |
|
|
|
throw new ServiceException("今日已签到,请明日再来!",400); |
|
|
|
}else{ |
|
|
|
//签到
|
|
|
|
redisService.hashIncr(redisKey,hashKey,1); |
|
|
|
//发送签到画意值奖励并写入记录消息(此处0->抖音;1->快手;2->微信)
|
|
|
|
GoldRewardMessage msg = null; |
|
|
|
switch (param.getSource()){ |
|
|
|
case "1": |
|
|
|
//抖音
|
|
|
|
msg = buildGoldRewardMsg(param.getUserId(),GoldEnum.SIGN.getGoldNum(),GoldEnum.SIGN.getCode(),"0",null); |
|
|
|
break; |
|
|
|
case "2": |
|
|
|
//快手
|
|
|
|
msg = buildGoldRewardMsg(param.getUserId(),GoldEnum.SIGN.getGoldNum(),GoldEnum.SIGN.getCode(),"1",null); |
|
|
|
break; |
|
|
|
case "3": |
|
|
|
//微信
|
|
|
|
msg = buildGoldRewardMsg(param.getUserId(),GoldEnum.SIGN.getGoldNum(),GoldEnum.SIGN.getCode(),"2",null); |
|
|
|
break; |
|
|
|
} |
|
|
|
mqMessageRecordService.sendAsyncMsg(RocketMqTopic.GOLD_REWARD_TOPIC,null,msg); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void watchAdGetGold(GetGoldDto param) { |
|
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
String date = df.format(new Date()); |
|
|
|
String redisKey = RedisKeyConstant.PLATFORM_USER_PAINT_REWARD_KEY + date; |
|
|
|
String hashKey = param.getAppType()+":"+param.getSource()+":"+param.getUserId(); |
|
|
|
//判断redis中是否观看广告次数大于等于5,有则提示当日已完成观看任务,否则发送mq消息写入缓存,给予奖励,写入奖励记录
|
|
|
|
if(redisService.hasHashKey(redisKey,hashKey)){ |
|
|
|
Integer watchAdNum = redisService.getCacheMapValue(redisKey, hashKey); |
|
|
|
if(watchAdNum >= 5){ |
|
|
|
throw new ServiceException("今日观看任务已完成,请明日再来!",400); |
|
|
|
}else{ |
|
|
|
//写入观看记录
|
|
|
|
redisService.hashIncr(redisKey,hashKey,1); |
|
|
|
//发送观看广告获取画意值奖励并写入记录消息(此处0->抖音;1->快手;2->微信)
|
|
|
|
GoldRewardMessage msg = null; |
|
|
|
switch (param.getSource()){ |
|
|
|
case "1": |
|
|
|
//抖音
|
|
|
|
msg = buildGoldRewardMsg(param.getUserId(),GoldEnum.WATCH_AD.getGoldNum(),GoldEnum.WATCH_AD.getCode(),"0",null); |
|
|
|
break; |
|
|
|
case "2": |
|
|
|
//快手
|
|
|
|
msg = buildGoldRewardMsg(param.getUserId(),GoldEnum.WATCH_AD.getGoldNum(),GoldEnum.WATCH_AD.getCode(),"1",null); |
|
|
|
break; |
|
|
|
case "3": |
|
|
|
//微信
|
|
|
|
msg = buildGoldRewardMsg(param.getUserId(),GoldEnum.WATCH_AD.getGoldNum(),GoldEnum.WATCH_AD.getCode(),"2",null); |
|
|
|
break; |
|
|
|
} |
|
|
|
mqMessageRecordService.sendAsyncMsg(RocketMqTopic.GOLD_REWARD_TOPIC,null,msg); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
//不存在,则是第一次观看
|
|
|
|
//写入观看记录
|
|
|
|
redisService.hashIncr(redisKey,hashKey,1); |
|
|
|
//发送观看广告获取画意值奖励并写入记录消息(此处0->抖音;1->快手;2->微信)
|
|
|
|
GoldRewardMessage msg = null; |
|
|
|
switch (param.getSource()){ |
|
|
|
case "1": |
|
|
|
//抖音
|
|
|
|
msg = buildGoldRewardMsg(param.getUserId(),GoldEnum.WATCH_AD.getGoldNum(),GoldEnum.WATCH_AD.getCode(),"0",null); |
|
|
|
break; |
|
|
|
case "2": |
|
|
|
//快手
|
|
|
|
msg = buildGoldRewardMsg(param.getUserId(),GoldEnum.WATCH_AD.getGoldNum(),GoldEnum.WATCH_AD.getCode(),"1",null); |
|
|
|
break; |
|
|
|
case "3": |
|
|
|
//微信
|
|
|
|
msg = buildGoldRewardMsg(param.getUserId(),GoldEnum.WATCH_AD.getGoldNum(),GoldEnum.WATCH_AD.getCode(),"2",null); |
|
|
|
break; |
|
|
|
} |
|
|
|
mqMessageRecordService.sendAsyncMsg(RocketMqTopic.GOLD_REWARD_TOPIC,null,msg); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public GoldRewardMessage buildGoldRewardMsg(Long userId, int goldNum, String goldCode, String platform, Integer userClientType) { |
|
|
|
GoldRewardMessage message = new GoldRewardMessage(); |
|
|
|
message.setUserId(userId); |
|
|
|
message.setGoldNum(goldNum); |
|
|
|
message.setGoldCode(goldCode); |
|
|
|
if(StringUtils.isNotNull(platform)){ |
|
|
|
message.setPlatform(platform); |
|
|
|
} |
|
|
|
if(StringUtils.isNotNull(userClientType)){ |
|
|
|
message.setUserClientType(userClientType); |
|
|
|
} |
|
|
|
return message; |
|
|
|
} |
|
|
|
} |
|
|
|
|