御剑行功能优化
parent
e2cf755930
commit
70b19c8beb
|
|
@ -1,7 +1,9 @@
|
|||
package com.ljsd.jieling.logic.activity;
|
||||
|
||||
import com.ljsd.jieling.db.redis.RedisKey;
|
||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
import com.ljsd.jieling.globals.Global;
|
||||
import com.ljsd.jieling.jbean.ActivityMission;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.logic.mail.MailLogic;
|
||||
import com.ljsd.jieling.logic.ridingSward.RidingSwardLogic;
|
||||
|
|
@ -11,6 +13,7 @@ import config.SRidingSwardConfig;
|
|||
import manager.STableManager;
|
||||
import util.TimeUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -25,43 +28,52 @@ public class RidingSwardActivity extends AbstractActivity{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onActivityEndOnMySelf(User user){
|
||||
// 关闭活动
|
||||
RidingSwardLogic.getInstance().checkState();
|
||||
// 记录数据
|
||||
Map<Long, List<RidingSwardRecord>> list = RidingSwardLogic.getRecordList(user.getId());
|
||||
// 配置
|
||||
SRidingSwardConfig config = STableManager.getConfig(SRidingSwardConfig.class).get(1);
|
||||
public void initActivity(User user) {
|
||||
ActivityMission mission = new ActivityMission();
|
||||
// 初始化阶段奖励
|
||||
ActivityLogic.getInstance().initOtherMission(mission, new ArrayList<>());
|
||||
user.getActivityManager().getActivityMissionMap().put(id, mission);
|
||||
LOGGER.info("御剑行初始化...{}",id);
|
||||
}
|
||||
|
||||
HashMap<Integer, Integer> map = new HashMap<>();
|
||||
for (Map.Entry<Long, List<RidingSwardRecord>> entry : list.entrySet()) {
|
||||
for (RidingSwardRecord record : entry.getValue()) {
|
||||
// 处理记录
|
||||
RidingSwardLogic.recordBuild(record,RidingSwardLogic.getRankBack());
|
||||
// 未领取的记录
|
||||
if (record.getState() == 0){
|
||||
Integer num = map.getOrDefault(config.getMaxRaiseNum()[0], 0);
|
||||
map.put(config.getMaxRaiseNum()[0],num+record.getGetNum());
|
||||
record.setState(1);
|
||||
@Override
|
||||
public void onActivityEndOnMySelf(User user){
|
||||
if (RidingSwardLogic.getInstance().getState() == 0){
|
||||
// 记录数据
|
||||
Map<Integer, List<RidingSwardRecord>> list = RidingSwardLogic.getRecordList(user.getId());
|
||||
// 配置
|
||||
SRidingSwardConfig config = STableManager.getConfig(SRidingSwardConfig.class).get(1);
|
||||
|
||||
HashMap<Integer, Integer> map = new HashMap<>();
|
||||
for (Map.Entry<Integer, List<RidingSwardRecord>> entry : list.entrySet()) {
|
||||
for (RidingSwardRecord record : entry.getValue()) {
|
||||
// 处理记录
|
||||
RidingSwardLogic.recordBuild(record,RidingSwardLogic.getRankMap("back"));
|
||||
// 未领取的记录
|
||||
if (record.getState() == 0){
|
||||
Integer num = map.getOrDefault(config.getMaxRaiseNum()[0], 0);
|
||||
map.put(config.getMaxRaiseNum()[0],num+record.getGetNum());
|
||||
record.setState(1);
|
||||
}
|
||||
}
|
||||
// 更新数据
|
||||
RidingSwardLogic.putRecordList(user.getId(),String.valueOf(entry.getKey()),entry.getValue());
|
||||
}
|
||||
// 更新数据
|
||||
RidingSwardLogic.putRecordList(user.getId(),entry.getKey(),entry.getValue());
|
||||
}
|
||||
// 有未领取的奖励,发送邮件
|
||||
if (!map.isEmpty()){
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
|
||||
builder.append(entry.getKey()).append("#").append(entry.getValue()).append("|");
|
||||
// 有未领取的奖励,发送邮件
|
||||
if (!map.isEmpty()){
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
|
||||
builder.append(entry.getKey()).append("#").append(entry.getValue()).append("|");
|
||||
}
|
||||
String reward = builder.substring(0, builder.length() - 1);
|
||||
// 标题和内容
|
||||
String title = SErrorCodeEerverConfig.getI18NMessage("RidingSwordReward_mail_title");
|
||||
String content = SErrorCodeEerverConfig.getI18NMessage("RidingSwordReward_mail_txt");
|
||||
// 发送邮件
|
||||
MailLogic.getInstance().sendMail(user.getId(),title,content,reward,TimeUtils.nowInt(),Global.MAIL_EFFECTIVE_TIME);
|
||||
}
|
||||
String reward = builder.substring(0, builder.length() - 1);
|
||||
// 标题和内容
|
||||
String title = SErrorCodeEerverConfig.getI18NMessage("RidingSwordReward_mail_title");
|
||||
String content = SErrorCodeEerverConfig.getI18NMessage("RidingSwordReward_mail_txt");
|
||||
// 发送邮件
|
||||
MailLogic.getInstance().sendMail(user.getId(),title,content,reward,TimeUtils.nowInt(),Global.MAIL_EFFECTIVE_TIME);
|
||||
// 删除key
|
||||
RedisUtil.getInstence().rename(TimeUtils.ONE_DAY*3/1000,RedisUtil.getInstence().getKey(RedisKey.RIDING_SWARD_RECORD, String.valueOf(user.getId())));
|
||||
}
|
||||
// 删除key
|
||||
RedisUtil.getInstence().rename(TimeUtils.ONE_DAY*3/1000,RidingSwardLogic.getRecordKey(user.getId()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,45 +51,89 @@ public class RidingSwardLogic{
|
|||
return instance;
|
||||
}
|
||||
|
||||
//当前状态,0:关闭,1:投注,2:比赛中
|
||||
public static int state = 0;
|
||||
private static long startTime = 0L;
|
||||
private static long endTime = 0L;
|
||||
private static long nextTime = 0L;
|
||||
// 功能开始时间和结束时间,秒
|
||||
private static int startTime = 0;
|
||||
private static int endTime = 0;
|
||||
|
||||
public void checkState(){
|
||||
//当前状态,0:关闭,1:投注,2:比赛中,3:结算中
|
||||
public int getState() {
|
||||
try {
|
||||
if (endTime == 0 && startTime == 0){
|
||||
return 0;
|
||||
}
|
||||
int now = TimeUtils.nowInt();
|
||||
// 活动过期
|
||||
if (TimeUtils.now() > endTime || TimeUtils.now() < startTime){
|
||||
state = 0;
|
||||
putRankBack();
|
||||
if (now > endTime || now < startTime){
|
||||
// 活动结束,备服排行数据
|
||||
if (now > endTime){
|
||||
rankBack();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// 关闭中,不进行处理
|
||||
if (state == 0){
|
||||
return;
|
||||
}
|
||||
long now = TimeUtils.now();
|
||||
// 配置表
|
||||
SRidingSwardConfig config = STableManager.getConfig(SRidingSwardConfig.class).get(1);
|
||||
// 投注时间
|
||||
long bet = config.getTime()[0] * TimeUtils.ONE_SECOND;
|
||||
// 比赛时间
|
||||
long competition = config.getTime()[1] * TimeUtils.ONE_SECOND;
|
||||
// 活动开始到现在经过了多少时间,计算第几轮, 取模,小于60000是比赛中,大于60000是投注
|
||||
long time = (now - startTime) % (bet + competition);
|
||||
long num = (now - startTime) / (bet + competition);
|
||||
if (time > bet){
|
||||
// 比赛阶段
|
||||
state = 2;
|
||||
nextTime = (num + 1) * (bet + competition) + startTime;
|
||||
}else{
|
||||
// 投注阶段
|
||||
state = 1;
|
||||
nextTime = num * (bet + competition) + bet + startTime;
|
||||
// 一场比赛得时间,投注时间+比赛时间
|
||||
int oneGameTime = config.getTime()[0] + config.getTime()[1];
|
||||
if (now + oneGameTime >= endTime){
|
||||
return 3;
|
||||
}
|
||||
// (当前时间-开始时间)%场次时间,取模,可以获得限制位于哪个阶段
|
||||
return (now - startTime) % (oneGameTime) > config.getTime()[0] ? 2 : 1;
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前第几轮
|
||||
* @return
|
||||
*/
|
||||
public int getRound(){
|
||||
// 配置表
|
||||
SRidingSwardConfig config = STableManager.getConfig(SRidingSwardConfig.class).get(1);
|
||||
// 一场比赛得时间,投注时间+比赛时间
|
||||
int oneGameTime = config.getTime()[0] + config.getTime()[1];
|
||||
// 第几轮
|
||||
int time = TimeUtils.nowInt() - startTime;
|
||||
int round = 0;
|
||||
if (time % oneGameTime == 0){
|
||||
round = time / oneGameTime;
|
||||
}else {
|
||||
round = time / oneGameTime +1;
|
||||
}
|
||||
if (getState() == 3){
|
||||
round -= 1;
|
||||
}
|
||||
return round;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前第几轮
|
||||
* @return
|
||||
*/
|
||||
public int getTime(){
|
||||
SRidingSwardConfig config = STableManager.getConfig(SRidingSwardConfig.class).get(1);
|
||||
// 根据状态返回时间
|
||||
int state = getState();
|
||||
switch (state){
|
||||
case 1:
|
||||
// 投注阶段
|
||||
return Optional.ofNullable(getRankMap("").get(getRound()))
|
||||
.map(RidingSwardRank::getTime)
|
||||
.orElse(0);
|
||||
case 2:
|
||||
// 比赛阶段
|
||||
return Optional.ofNullable(getRankMap("").get(getRound()+1))
|
||||
.map(v->v.getTime() - config.getTime()[0])
|
||||
.orElse(0);
|
||||
case 3:
|
||||
// 结算阶段
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -97,15 +141,14 @@ public class RidingSwardLogic{
|
|||
*/
|
||||
public void createExecuteScript(){
|
||||
// 处理状态
|
||||
checkState();
|
||||
if (state == 0){
|
||||
if (getState() == 0){
|
||||
return;
|
||||
}
|
||||
RedisUtil redisUtil = RedisUtil.getInstence();
|
||||
// 时间锁,同一天只会执行一次
|
||||
String key = redisUtil.getKey(RedisKey.RIDING_SWARD_TIME_LOCK, "");
|
||||
String timeLock = Optional.ofNullable(redisUtil.get(key)).map(Object::toString).orElse("0");
|
||||
if (TimeUtils.now() < Long.parseLong(timeLock)){
|
||||
if (TimeUtils.nowInt() < Integer.parseInt(timeLock)){
|
||||
return;
|
||||
}
|
||||
// 配置表
|
||||
|
|
@ -114,39 +157,39 @@ public class RidingSwardLogic{
|
|||
|
||||
// 开始时间计算
|
||||
// boolean sameDay = TimeUtils.isSameDay(TimeUtils.now(), startTime);
|
||||
// long start = sameDay ? startTime : TimeUtils.getTodayZero();
|
||||
// int start = sameDay ? startTime : TimeUtils.getTodayZero();
|
||||
// 结束时间计算
|
||||
// boolean sameDay2 = TimeUtils.isSameDay(TimeUtils.now(), endTime);
|
||||
// long end = sameDay2 ? endTime : TimeUtils.getTomorrowZero();
|
||||
// int end = sameDay2 ? endTime : TimeUtils.getTomorrowZero();
|
||||
// 投注时间获取
|
||||
long bet = config.getTime()[0] * TimeUtils.ONE_SECOND;
|
||||
int bet = config.getTime()[0];
|
||||
// 比赛时间获取
|
||||
long competition = config.getTime()[1] * TimeUtils.ONE_SECOND;
|
||||
|
||||
int competition = config.getTime()[1];
|
||||
// 今日比赛次数
|
||||
long num = (endTime - startTime) / (bet + competition);
|
||||
int num = (endTime - startTime) / (bet + competition);
|
||||
// 总权重
|
||||
int sum = treeMap.values().stream().mapToInt(SRidingSwardResult::getRate).sum();
|
||||
|
||||
// map存储结果
|
||||
HashMap<String, Integer> result = new HashMap<>();
|
||||
long time = startTime;
|
||||
HashMap<String, RidingSwardRank> result = new HashMap<>();
|
||||
int competitionIng = startTime;
|
||||
for (int i = 0; i < num; i++) {
|
||||
// 比赛开始时间
|
||||
long competitionIng = time += bet;
|
||||
competitionIng += bet;
|
||||
// 计算随机权重
|
||||
int randomInt = MathUtils.randomInt(sum);
|
||||
// 计算比赛脚本
|
||||
for (SRidingSwardResult value : treeMap.values()) {
|
||||
if (randomInt <= value.getRate()) {
|
||||
// 存储
|
||||
result.put(String.valueOf(competitionIng),value.getId());
|
||||
RidingSwardRank swardRank = new RidingSwardRank(value.getId(), competitionIng);
|
||||
result.put(String.valueOf(i+1),swardRank);
|
||||
break;
|
||||
}
|
||||
randomInt-=value.getRate();
|
||||
}
|
||||
// 加上比赛用时,获得下一场投注开始时间
|
||||
time = competitionIng + competition;
|
||||
competitionIng += competition;
|
||||
}
|
||||
redisUtil.putMapEntrys(RedisKey.RIDING_SWARD_RANK, "", result);
|
||||
LOGGER.info("御剑行日志:结果:{}", result.toString());
|
||||
|
|
@ -186,19 +229,16 @@ public class RidingSwardLogic{
|
|||
}
|
||||
else {
|
||||
// 初始化状态信息
|
||||
if (state == 0) {
|
||||
if (startTime == 0 || endTime == 0) {
|
||||
// 初始化活动数据
|
||||
SGlobalActivity activity = SGlobalActivity.getsGlobalActivityMap().get(proto.getActivityId());
|
||||
state = 1;
|
||||
startTime = TimeUtils.stringToTimeLong(activity.getStartTime(), "yyyyMMdd HHmmss");
|
||||
endTime = TimeUtils.stringToTimeLong(activity.getEndtime(), "yyyyMMdd HHmmss");
|
||||
startTime = (int) (TimeUtils.stringToTimeLong(activity.getStartTime(), "yyyyMMdd HHmmss")/1000);
|
||||
endTime = (int) (TimeUtils.stringToTimeLong(activity.getEndtime(), "yyyyMMdd HHmmss")/1000);
|
||||
// 定时器启动
|
||||
getInstance().createExecuteScript();
|
||||
}
|
||||
// 处理缓存
|
||||
checkState();
|
||||
// 活动未到开启时间
|
||||
if (state == 0){
|
||||
if (getState() == 0){
|
||||
build.setState(0);
|
||||
}
|
||||
else {
|
||||
|
|
@ -217,29 +257,16 @@ public class RidingSwardLogic{
|
|||
infos.add(builder.build());
|
||||
}
|
||||
build.addAllModelInfo(infos);
|
||||
build.setState(state);
|
||||
build.setTime(nextTime);
|
||||
build.setRankId(getMatchRankId());
|
||||
build.setState(getState());
|
||||
build.setTime(getTime());
|
||||
int rankId = Optional.ofNullable(getRankMap("").get(getRound())).map(RidingSwardRank::getRankId).orElse(1);
|
||||
build.setRankId(rankId);
|
||||
build.setBetCount(user.getPlayerInfoManager().getRidingSwardNum());
|
||||
}
|
||||
}
|
||||
MessageUtil.sendMessage(uid,1, MessageTypeProto.MessageType.RidingSwardActivityResponse_VALUE,build.build(),true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前比赛剧本id
|
||||
* @return
|
||||
*/
|
||||
private int getMatchRankId(){
|
||||
if (state == 2){
|
||||
// 配置
|
||||
SRidingSwardConfig config = STableManager.getConfig(SRidingSwardConfig.class).get(1);
|
||||
long time = nextTime - config.getTime()[1] * TimeUtils.ONE_SECOND;
|
||||
return getRankMap().getOrDefault(time,0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取奖励
|
||||
* @param uid
|
||||
|
|
@ -249,15 +276,15 @@ public class RidingSwardLogic{
|
|||
public ActivityProto.RidingSwardRewardResponse getRidingSwardReward(int uid,ActivityProto.RidingSwardRewardRequest proto) throws Exception {
|
||||
// 玩家信息
|
||||
User user = verifyUser(uid);
|
||||
// 场次时间
|
||||
long time = proto.getTime();
|
||||
// 场次
|
||||
int round = proto.getRound();
|
||||
// 投注记录,key:时间戳,value:竞猜记录信息
|
||||
Map<Long, List<RidingSwardRecord>> recordMap = getRecordList(uid);
|
||||
Map<Integer, List<RidingSwardRecord>> recordMap = getRecordList(uid);
|
||||
// 配置
|
||||
SRidingSwardConfig config = STableManager.getConfig(SRidingSwardConfig.class).get(1);
|
||||
List<int[]> result = new ArrayList<>();
|
||||
if (time == 0){
|
||||
for (Map.Entry<Long, List<RidingSwardRecord>> entry : recordMap.entrySet()) {
|
||||
if (round == -1){
|
||||
for (Map.Entry<Integer, List<RidingSwardRecord>> entry : recordMap.entrySet()) {
|
||||
for (RidingSwardRecord record : entry.getValue()) {
|
||||
// 未领取奖励
|
||||
if (record.getState() == 0){
|
||||
|
|
@ -266,12 +293,12 @@ public class RidingSwardLogic{
|
|||
record.setState(1);
|
||||
}
|
||||
}
|
||||
putRecordList(uid,entry.getKey(),entry.getValue());
|
||||
putRecordList(uid,String.valueOf(entry.getKey()),entry.getValue());
|
||||
}
|
||||
}else {
|
||||
// 单场领取
|
||||
int swardId = proto.getSwardId();
|
||||
List<RidingSwardRecord> records = recordMap.get(time);
|
||||
List<RidingSwardRecord> records = recordMap.get(round);
|
||||
if (records == null || records.isEmpty() || swardId == 0){
|
||||
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE,"比赛场次不存在,领取失败");
|
||||
}
|
||||
|
|
@ -282,7 +309,7 @@ public class RidingSwardLogic{
|
|||
record.setState(1);
|
||||
}
|
||||
}
|
||||
putRecordList(uid,time,records);
|
||||
putRecordList(uid,String.valueOf(round),records);
|
||||
}
|
||||
// 奖励计算
|
||||
int[][] changeList = Utils.getTwoArrayObject(result);
|
||||
|
|
@ -296,7 +323,7 @@ public class RidingSwardLogic{
|
|||
* @param proto
|
||||
*/
|
||||
public void ridingSwardBet(int uid,ActivityProto.RidingSwardBetRequest proto) throws Exception {
|
||||
if (state != 1){
|
||||
if (getState() != 1){
|
||||
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE,"活动关闭或正在比赛中,无法投标");
|
||||
}
|
||||
User user = verifyUser(uid);
|
||||
|
|
@ -314,9 +341,9 @@ public class RidingSwardLogic{
|
|||
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
|
||||
}
|
||||
// 投注记录,key:时间戳,value:竞猜记录信息
|
||||
Map<Long, List<RidingSwardRecord>> recordMap = getRecordList(uid);
|
||||
Map<Integer, List<RidingSwardRecord>> recordMap = getRecordList(uid);
|
||||
// 获取下一场
|
||||
List<RidingSwardRecord> records = recordMap.getOrDefault(nextTime,new ArrayList<>());
|
||||
List<RidingSwardRecord> records = recordMap.getOrDefault(getRound(),new ArrayList<>());
|
||||
// 首次押注,验证次数消耗
|
||||
if (records.isEmpty()){
|
||||
// 验证押注次数
|
||||
|
|
@ -324,7 +351,7 @@ public class RidingSwardLogic{
|
|||
if (betNum >= config.getJoinCount()){
|
||||
throw new ErrorCodeException(ErrorCode.REFRESH_WHEL_TIME_NOT);
|
||||
}
|
||||
RidingSwardRecord record = new RidingSwardRecord(nextTime,proto.getSwardId(),proto.getCostNum());
|
||||
RidingSwardRecord record = new RidingSwardRecord(getTime(),getRound(),proto.getSwardId(),proto.getCostNum());
|
||||
records.add(record);
|
||||
// 记录押注次数
|
||||
user.getPlayerInfoManager().setRidingSwardNum(betNum + 1);
|
||||
|
|
@ -336,13 +363,13 @@ public class RidingSwardLogic{
|
|||
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE,"不能重复押注");
|
||||
}
|
||||
}
|
||||
RidingSwardRecord record = new RidingSwardRecord(nextTime,proto.getSwardId(),proto.getCostNum());
|
||||
RidingSwardRecord record = new RidingSwardRecord(getTime(),getRound(),proto.getSwardId(),proto.getCostNum());
|
||||
records.add(record);
|
||||
}else {
|
||||
throw new ErrorCodeException(ErrorCode.RIDING_SWARD_BET_TWO,"一轮最大押注两次");
|
||||
}
|
||||
if (!records.isEmpty()){
|
||||
putRecordList(uid,nextTime,records);
|
||||
putRecordList(uid,String.valueOf(getRound()),records);
|
||||
}
|
||||
// 道具消耗
|
||||
ItemUtil.itemCost(user, map, BIReason.RIDING_SWARD_BET,0);
|
||||
|
|
@ -369,24 +396,11 @@ public class RidingSwardLogic{
|
|||
* @return
|
||||
*/
|
||||
private CommonProto.RidingSwardLastRank getRidingSwardLastRank() throws ErrorCodeException {
|
||||
Map<Long, Integer> map = getRankMap();
|
||||
// 配置
|
||||
SRidingSwardConfig config = STableManager.getConfig(SRidingSwardConfig.class).get(1);
|
||||
long time = 0;
|
||||
// 押注阶段,返回上一层比赛结果
|
||||
if (state == 1){
|
||||
time = nextTime - (config.getTime()[0] + config.getTime()[1]) * TimeUtils.ONE_SECOND;
|
||||
}
|
||||
// 比赛阶段,返回当前比赛结果
|
||||
else if (state == 2){
|
||||
time = nextTime - (config.getTime()[0] + config.getTime()[1]*2) * TimeUtils.ONE_SECOND;
|
||||
}else {
|
||||
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
|
||||
}
|
||||
Integer integer = map.getOrDefault(time,0);
|
||||
RidingSwardRank swardRank = getRankMap("").getOrDefault(getRound(), new RidingSwardRank());
|
||||
return CommonProto.RidingSwardLastRank.newBuilder()
|
||||
.setRankTime(time)
|
||||
.setRankId(integer)
|
||||
.setRankTime(swardRank.getTime())
|
||||
.setRankId(swardRank.getRankId())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
@ -399,17 +413,17 @@ public class RidingSwardLogic{
|
|||
// 返回值
|
||||
List<CommonProto.RidingSwardRecord> list = new ArrayList<>();
|
||||
// 投注记录,key:时间戳,value:竞猜记录信息list
|
||||
Map<Long, List<RidingSwardRecord>> recordMap = getRecordList(uid);
|
||||
Map<Integer, List<RidingSwardRecord>> recordMap = getRecordList(uid);
|
||||
SRidingSwardConfig config = STableManager.getConfig(SRidingSwardConfig.class).get(1);
|
||||
// 异常可以投注两次,所以最多会有两次记录
|
||||
for (Map.Entry<Long, List<RidingSwardRecord>> entry : recordMap.entrySet()) {
|
||||
// 一场可以投注两次,所以最多会有两次记录
|
||||
for (Map.Entry<Integer, List<RidingSwardRecord>> entry : recordMap.entrySet()) {
|
||||
boolean judge = false;
|
||||
for (RidingSwardRecord record : entry.getValue()) {
|
||||
// 当前比赛结果不能显示
|
||||
if (record.getTime() >= (nextTime-config.getTime()[1]*TimeUtils.ONE_SECOND)){
|
||||
if (record.getTime() > (getTime()-config.getTime()[1])){
|
||||
break;
|
||||
}
|
||||
judge = recordBuild(record,getRankMap());
|
||||
judge = recordBuild(record,getRankMap(""));
|
||||
// 结果
|
||||
CommonProto.RidingSwardRecord.Builder builder = CommonProto.RidingSwardRecord.newBuilder()
|
||||
.setTime(record.getTime())// 赛场时间
|
||||
|
|
@ -418,12 +432,13 @@ public class RidingSwardLogic{
|
|||
.setState(record.getState())// 领取状态
|
||||
.setWinnerId(record.getWinnerId())// 获胜的剑
|
||||
.setGetNum(record.getGetNum())// 可领取数量
|
||||
.setResult(record.getResult()); // 输赢结果
|
||||
.setResult(record.getResult()) // 输赢结果
|
||||
.setRound(record.getRound());//轮次
|
||||
list.add(builder.build());
|
||||
}
|
||||
// 更新缓存对象类型
|
||||
if (judge){
|
||||
putRecordList(uid,entry.getKey(),entry.getValue());
|
||||
putRecordList(uid,String.valueOf(entry.getKey()),entry.getValue());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
|
|
@ -432,7 +447,7 @@ public class RidingSwardLogic{
|
|||
/**
|
||||
* 记录数据处理
|
||||
*/
|
||||
public static boolean recordBuild(RidingSwardRecord record,Map<Long, Integer> rankMap){
|
||||
public static boolean recordBuild(RidingSwardRecord record,Map<Integer, RidingSwardRank> rankMap){
|
||||
// 配置表
|
||||
Map<Integer, SRidingSwardResult> resultMap = STableManager.getConfig(SRidingSwardResult.class);
|
||||
SRidingSwardConfig config = STableManager.getConfig(SRidingSwardConfig.class).get(1);
|
||||
|
|
@ -441,12 +456,12 @@ public class RidingSwardLogic{
|
|||
return false;
|
||||
}
|
||||
// 根据场次获取剧本id
|
||||
Integer scriptId = rankMap.get(record.getTime());
|
||||
if (scriptId == null){
|
||||
RidingSwardRank rank = rankMap.get(record.getRound());
|
||||
if (rank == null){
|
||||
return false;
|
||||
}
|
||||
// 剧本信息
|
||||
SRidingSwardResult swardResult = resultMap.get(scriptId);
|
||||
SRidingSwardResult swardResult = resultMap.get(rank.getRankId());
|
||||
int winnerId = 0;
|
||||
for (int i = 0; i < swardResult.getResult().length; i++) {
|
||||
if (swardResult.getResult()[i][0] == 1){
|
||||
|
|
@ -478,7 +493,7 @@ public class RidingSwardLogic{
|
|||
private List<CommonProto.RidingSwardBet> getRidingSwardBet(int uid){
|
||||
List<CommonProto.RidingSwardBet> list = new ArrayList<>();
|
||||
// 比赛记录,key:场次时间戳,value:剧本id
|
||||
List<RidingSwardRecord> records = getRecordList(uid).get(nextTime);
|
||||
List<RidingSwardRecord> records = getRecordList(uid).get(getRound());
|
||||
if (records != null){
|
||||
for (RidingSwardRecord record : records) {
|
||||
// 竞猜信息
|
||||
|
|
@ -493,65 +508,52 @@ public class RidingSwardLogic{
|
|||
|
||||
/**
|
||||
* 获取排行榜
|
||||
* @param subKey
|
||||
* ”“ 使用中
|
||||
* BACK 备份
|
||||
* @return
|
||||
*/
|
||||
public static Map<Long, Integer> getRankMap(){
|
||||
Map<Long, Integer> map = RedisUtil.getInstence().getMapValues(RedisKey.RIDING_SWARD_RANK, "", Long.class, Integer.class);
|
||||
public static Map<Integer, RidingSwardRank> getRankMap(String subKey){
|
||||
Map<Integer, RidingSwardRank> map =
|
||||
RedisUtil.getInstence().getMapValues(RedisKey.RIDING_SWARD_RANK, subKey, Integer.class, RidingSwardRank.class);
|
||||
if (map == null){
|
||||
return new HashMap<>();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static String getRankKey(){
|
||||
return RedisUtil.getInstence().getKey(RedisKey.RIDING_SWARD_RANK, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 排行榜备份
|
||||
*/
|
||||
public void putRankBack(){
|
||||
public void rankBack(){
|
||||
// 获取当前排行榜数据
|
||||
Map<String, Integer> rankMap = RedisUtil.getInstence().getMapValues(RedisKey.RIDING_SWARD_RANK, "", String.class, Integer.class);
|
||||
Map<String, RidingSwardRank> rankMap = RedisUtil.getInstence().getMapValues(RedisKey.RIDING_SWARD_RANK, "", String.class, RidingSwardRank.class);
|
||||
if (rankMap == null || rankMap.isEmpty()){
|
||||
return;
|
||||
}
|
||||
// 备份数据
|
||||
RedisUtil.getInstence().putMapEntrys(RedisKey.RIDING_SWARD_RANK, "BACK", rankMap);
|
||||
// 设置过期时间
|
||||
String key = RedisUtil.getInstence().getKey(RedisKey.RIDING_SWARD_RANK, "BACK");
|
||||
RedisUtil.getInstence().expire(key, TimeUtils.ONE_DAY*15/1000);
|
||||
// 删除旧榜
|
||||
RedisUtil.getInstence().del(getRankKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取排行榜
|
||||
* @return
|
||||
*/
|
||||
public static Map<Long, Integer> getRankBack(){
|
||||
Map<Long, Integer> map = RedisUtil.getInstence().getMapValues(RedisKey.RIDING_SWARD_RANK, "BACK", Long.class, Integer.class);
|
||||
if (map == null){
|
||||
return new HashMap<>();
|
||||
}
|
||||
return map;
|
||||
RedisUtil.getInstence().del(RedisUtil.getInstence().getKey(RedisKey.RIDING_SWARD_RANK, ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* 投注记录,key:场次时间戳,value:竞猜记录信息
|
||||
*/
|
||||
public static Map<Long, List<RidingSwardRecord>> getRecordList(int uid){
|
||||
Type valueType = new TypeToken<List<RidingSwardRecord>>() {}.getType();
|
||||
Map<Long, List<RidingSwardRecord>> map = RedisUtil.getInstence().getMapValues(RedisKey.RIDING_SWARD_RECORD, String.valueOf(uid), Long.class, valueType);
|
||||
public static Map<Integer, List<RidingSwardRecord>> getRecordList(int uid){
|
||||
Type valueType = new TypeToken<List<RidingSwardRecord>>(){}.getType();
|
||||
Map<Integer, List<RidingSwardRecord>> map = RedisUtil.getInstence().getMapValues(RedisKey.RIDING_SWARD_RECORD, String.valueOf(uid), int.class, valueType);
|
||||
if (map == null){
|
||||
map = new HashMap<>();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void putRecordList(int uid,long time,List<RidingSwardRecord> records){
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.RIDING_SWARD_RECORD, String.valueOf(uid),String.valueOf(time),records);
|
||||
}
|
||||
|
||||
public static String getRecordKey(int uid){
|
||||
return RedisUtil.getInstence().getKey(RedisKey.RIDING_SWARD_RECORD, String.valueOf(uid));
|
||||
public static void putRecordList(int uid,String round,List<RidingSwardRecord> records){
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.RIDING_SWARD_RECORD, String.valueOf(uid),round,records);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
package com.ljsd.jieling.logic.ridingSward;
|
||||
|
||||
/**
|
||||
* @Author hj
|
||||
* @Date 2021/10/20 14:38:00
|
||||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class RidingSwardRank {
|
||||
private int rankId;
|
||||
private int time;
|
||||
|
||||
public RidingSwardRank(int rankId, int time) {
|
||||
this.rankId = rankId;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public RidingSwardRank() {
|
||||
}
|
||||
|
||||
public int getRankId() {
|
||||
return rankId;
|
||||
}
|
||||
|
||||
public void setRankId(int rankId) {
|
||||
this.rankId = rankId;
|
||||
}
|
||||
|
||||
public int getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(int time) {
|
||||
this.time = time;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,8 @@ package com.ljsd.jieling.logic.ridingSward;
|
|||
* @Version 1.0
|
||||
*/
|
||||
public class RidingSwardRecord {
|
||||
private long time;
|
||||
private int time;
|
||||
private int round;
|
||||
private int betSwardId;
|
||||
private int betNum;
|
||||
// 领取状态,0:未领取,1:已领取
|
||||
|
|
@ -16,21 +17,27 @@ public class RidingSwardRecord {
|
|||
private int winnerId;
|
||||
private int getNum;
|
||||
|
||||
public RidingSwardRecord(long time, int betSwardId, int betNum) {
|
||||
public RidingSwardRecord(int time, int round, int betSwardId, int betNum) {
|
||||
this.time = time;
|
||||
this.round = round;
|
||||
this.betSwardId = betSwardId;
|
||||
this.betNum = betNum;
|
||||
this.state = -1;
|
||||
}
|
||||
|
||||
public RidingSwardRecord() {
|
||||
public int getRound() {
|
||||
return round;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
public void setRound(int round) {
|
||||
this.round = round;
|
||||
}
|
||||
|
||||
public int getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
public void setTime(int time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ public class SRidingSwardConfig implements BaseConfig {
|
|||
|
||||
private int[] time;
|
||||
|
||||
private int[][] openTime;
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
|
|
@ -63,5 +64,7 @@ public class SRidingSwardConfig implements BaseConfig {
|
|||
return time;
|
||||
}
|
||||
|
||||
|
||||
public int[][] getOpenTime() {
|
||||
return openTime;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue