删除排行榜
parent
f614593007
commit
da8f356de5
|
@ -4,8 +4,11 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Array;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -131,7 +134,12 @@ public class Utils {
|
|||
return cloneObj;
|
||||
}
|
||||
|
||||
public static int[][] changeList(List<int[]> list){
|
||||
/**
|
||||
* int数组list转二维数组
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
public static int[][] getTwoArrayObject(List<int[]> list){
|
||||
int[][] objects = new int[list.size()][];
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
objects[i] = list.get(i);
|
||||
|
@ -139,4 +147,25 @@ public class Utils {
|
|||
return objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* map转二维数组
|
||||
*/
|
||||
public static Object[][] getTwoArrayObject(Map map) {
|
||||
Object[][] object = null;
|
||||
if (map != null && !map.isEmpty()) {
|
||||
int size = map.size();
|
||||
object = new Object[size][2];
|
||||
|
||||
Iterator iterator = map.entrySet().iterator();
|
||||
for (int i = 0; i < size; i++) {
|
||||
Map.Entry entry = (Map.Entry) iterator.next();
|
||||
Object key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
object[i][0] = key;
|
||||
object[i][1] = value;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,28 +1,26 @@
|
|||
package com.ljsd.jieling.db.redis;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.ljsd.GameApplication;
|
||||
import com.ljsd.common.mogodb.util.GlobalData;
|
||||
import com.ljsd.jieling.db.mongo.AreaManager;
|
||||
import com.ljsd.jieling.util.ConfigurableApplicationContextManager;
|
||||
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||
import org.springframework.data.redis.core.*;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import util.StringUtil;
|
||||
import util.TimeUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.ReturnType;
|
||||
import org.springframework.data.redis.core.*;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import redis.clients.jedis.Protocol;
|
||||
import util.StringUtil;
|
||||
import util.TimeUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
|
|
|
@ -1761,7 +1761,7 @@ public class ActivityLogic implements IEventHandler{
|
|||
}
|
||||
}
|
||||
// 处理奖励
|
||||
int[][] rewards = Utils.changeList(list);
|
||||
int[][] rewards = Utils.getTwoArrayObject(list);
|
||||
CommonProto.Drop.Builder drop = ItemUtil.dropPer(user, rewards, BIReason.QIMENDUNJIA_DRAW);
|
||||
// 事件分发
|
||||
Poster.getPoster().dispatchEvent(new QiMenDunJiaEvent(user.getId(),activityId,num));
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
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.jbean.ActivityProgressInfo;
|
||||
|
@ -15,14 +13,19 @@ import com.ljsd.jieling.logic.rank.rankImpl.AbstractRank;
|
|||
import com.ljsd.jieling.network.server.ProtocolsManager;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.thread.ThreadManager;
|
||||
import com.ljsd.jieling.util.AyncWorkerRunnable;
|
||||
import com.ljsd.jieling.util.AyyncWorker;
|
||||
import com.ljsd.jieling.util.ItemUtil;
|
||||
import util.TimeUtils;
|
||||
import config.*;
|
||||
import config.SActivityRankingReward;
|
||||
import config.SActivityRewardConfig;
|
||||
import config.SErrorCodeEerverConfig;
|
||||
import config.SGlobalActivity;
|
||||
import org.springframework.data.redis.core.ZSetOperations;
|
||||
import util.TimeUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
class ExpectRankActivity extends AbstractActivity {
|
||||
|
||||
|
|
|
@ -5,12 +5,19 @@ import com.ljsd.jieling.globals.Global;
|
|||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.logic.mail.MailLogic;
|
||||
import com.ljsd.jieling.logic.ridingSward.RidingSwardLogic;
|
||||
import com.ljsd.jieling.logic.ridingSward.RidingSwardRecord;
|
||||
import config.SErrorCodeEerverConfig;
|
||||
import rpc.protocols.ActivityProto;
|
||||
import rpc.protocols.CommonProto;
|
||||
import util.StringUtil;
|
||||
import config.SRidingSwardConfig;
|
||||
import manager.STableManager;
|
||||
import util.TimeUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
/**
|
||||
* @author hj
|
||||
*
|
||||
*/
|
||||
public class RidingSwardActivity extends AbstractActivity{
|
||||
|
||||
public RidingSwardActivity(int id) {
|
||||
|
@ -18,28 +25,43 @@ public class RidingSwardActivity extends AbstractActivity{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onActivityEndOnMySelf(User user) throws Exception {
|
||||
// 处理一下数据
|
||||
RidingSwardLogic.getInstance().getRidingSwardRecord(user.getId());
|
||||
// 获取奖励内容
|
||||
ActivityProto.RidingSwardRewardRequest.Builder builder = ActivityProto.RidingSwardRewardRequest.newBuilder().setTime(0);
|
||||
ActivityProto.RidingSwardRewardResponse reward = RidingSwardLogic.getInstance().getRidingSwardReward(user.getId(), builder.build());
|
||||
// 奖励长度
|
||||
int size = reward.getDrop().getItemlistList().size();
|
||||
int[][] drop = new int[size][];
|
||||
for (int i = 0; i < size; i++) {
|
||||
CommonProto.Item item = reward.getDrop().getItemlist(i);
|
||||
drop[i][0] = item.getItemId();
|
||||
drop[i][1] = (int)item.getItemNum();
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
// 更新数据
|
||||
RidingSwardLogic.putRecordList(user.getId(),entry.getKey(),entry.getValue());
|
||||
}
|
||||
// 奖励
|
||||
String rewards = StringUtil.parseArrayToString(drop);
|
||||
// 标题
|
||||
String title = SErrorCodeEerverConfig.getI18NMessage("RidingSwordReward_mail_title");
|
||||
// 内容
|
||||
String content = SErrorCodeEerverConfig.getI18NMessage("RidingSwordReward_mail_txt");
|
||||
// 发送邮件
|
||||
MailLogic.getInstance().sendMail(user.getId(),title,content,rewards,TimeUtils.nowInt(),Global.MAIL_EFFECTIVE_TIME);
|
||||
// 有未领取的奖励,发送邮件
|
||||
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);
|
||||
}
|
||||
// 删除key
|
||||
RedisUtil.getInstence().rename(TimeUtils.ONE_DAY*3/1000,RidingSwardLogic.getRecordKey(user.getId()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,10 @@ import com.ljsd.jieling.jbean.ActivityMission;
|
|||
import com.ljsd.jieling.jbean.ActivityProgressInfo;
|
||||
import com.ljsd.jieling.logic.activity.event.IEvent;
|
||||
import com.ljsd.jieling.logic.activity.event.Poster;
|
||||
import com.ljsd.jieling.logic.activity.event.SevenWorldIntegralEvent;
|
||||
import com.ljsd.jieling.logic.activity.event.SuperBoxEvent;
|
||||
import com.ljsd.jieling.logic.dao.Item;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.logic.item.ItemLogic;
|
||||
import com.ljsd.jieling.logic.store.newRechargeInfo.bean.ReceiveWelfareBag;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.tools.Utils;
|
||||
|
@ -142,7 +140,7 @@ public class SevenWorldActivity extends AbstractActivity {
|
|||
if (rewardList.isEmpty()){
|
||||
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
|
||||
}
|
||||
int[][] rewards = Utils.changeList(rewardList);
|
||||
int[][] rewards = Utils.getTwoArrayObject(rewardList);
|
||||
ItemUtil.drop(user, rewards, drop, BIReason.SEVEN_WORLD_TREASURE);
|
||||
reportTakeActivityReward(user,treasure.getTreasureReward(),missionId);
|
||||
// 更新数据库
|
||||
|
|
|
@ -62,6 +62,7 @@ public class RidingSwardLogic{
|
|||
// 活动过期
|
||||
if (TimeUtils.now() > endTime || TimeUtils.now() < startTime){
|
||||
state = 0;
|
||||
putRankBack();
|
||||
}
|
||||
// 关闭中,不进行处理
|
||||
if (state == 0){
|
||||
|
@ -265,7 +266,7 @@ public class RidingSwardLogic{
|
|||
record.setState(1);
|
||||
}
|
||||
}
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.RIDING_SWARD_RECORD, String.valueOf(uid),String.valueOf(entry.getKey()),entry.getValue());
|
||||
putRecordList(uid,entry.getKey(),entry.getValue());
|
||||
}
|
||||
}else {
|
||||
// 单场领取
|
||||
|
@ -281,10 +282,10 @@ public class RidingSwardLogic{
|
|||
record.setState(1);
|
||||
}
|
||||
}
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.RIDING_SWARD_RECORD, String.valueOf(uid),String.valueOf(time),records);
|
||||
putRecordList(uid,time,records);
|
||||
}
|
||||
// 奖励计算
|
||||
int[][] changeList = Utils.changeList(result);
|
||||
int[][] changeList = Utils.getTwoArrayObject(result);
|
||||
CommonProto.Drop.Builder drop = ItemUtil.drop(user, changeList, BIReason.RIDING_SWARD_REWARD);
|
||||
return ActivityProto.RidingSwardRewardResponse.newBuilder().setDrop(drop).build();
|
||||
}
|
||||
|
@ -341,7 +342,7 @@ public class RidingSwardLogic{
|
|||
throw new ErrorCodeException(ErrorCode.RIDING_SWARD_BET_TWO,"一轮最大押注两次");
|
||||
}
|
||||
if (!records.isEmpty()){
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.RIDING_SWARD_RECORD, String.valueOf(uid),String.valueOf(nextTime),records);
|
||||
putRecordList(uid,nextTime,records);
|
||||
}
|
||||
// 道具消耗
|
||||
ItemUtil.itemCost(user, map, BIReason.RIDING_SWARD_BET,0);
|
||||
|
@ -368,7 +369,7 @@ public class RidingSwardLogic{
|
|||
* @return
|
||||
*/
|
||||
private CommonProto.RidingSwardLastRank getRidingSwardLastRank() throws ErrorCodeException {
|
||||
Map<Long, Integer> map = RedisUtil.getInstence().getMapValues(RedisKey.RIDING_SWARD_RANK, "", Long.class, Integer.class);
|
||||
Map<Long, Integer> map = getRankMap();
|
||||
// 配置
|
||||
SRidingSwardConfig config = STableManager.getConfig(SRidingSwardConfig.class).get(1);
|
||||
long time = 0;
|
||||
|
@ -399,10 +400,6 @@ public class RidingSwardLogic{
|
|||
List<CommonProto.RidingSwardRecord> list = new ArrayList<>();
|
||||
// 投注记录,key:时间戳,value:竞猜记录信息list
|
||||
Map<Long, List<RidingSwardRecord>> recordMap = getRecordList(uid);
|
||||
// 比赛记录,key:场次时间戳,value:剧本id
|
||||
Map<Long, Integer> rankMap = getRankMap();
|
||||
// 配置表
|
||||
Map<Integer, SRidingSwardResult> resultMap = STableManager.getConfig(SRidingSwardResult.class);
|
||||
SRidingSwardConfig config = STableManager.getConfig(SRidingSwardConfig.class).get(1);
|
||||
// 异常可以投注两次,所以最多会有两次记录
|
||||
for (Map.Entry<Long, List<RidingSwardRecord>> entry : recordMap.entrySet()) {
|
||||
|
@ -412,37 +409,7 @@ public class RidingSwardLogic{
|
|||
if (record.getTime() >= (nextTime-config.getTime()[1]*TimeUtils.ONE_SECOND)){
|
||||
break;
|
||||
}
|
||||
// -1是未计算过的参数,需要算值
|
||||
if (record.getState() == -1){
|
||||
// 根据场次获取剧本id
|
||||
Integer scriptId = rankMap.get(record.getTime());
|
||||
if (scriptId == null){
|
||||
break;
|
||||
}
|
||||
// 剧本信息
|
||||
SRidingSwardResult swardResult = resultMap.get(scriptId);
|
||||
int winnerId = 0;
|
||||
for (int i = 0; i < swardResult.getResult().length; i++) {
|
||||
if (swardResult.getResult()[i][0] == 1){
|
||||
winnerId = i+1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 获胜剑id
|
||||
record.setWinnerId(winnerId);
|
||||
// 竞猜结果
|
||||
int result = winnerId == record.getBetSwardId()?1:0;
|
||||
record.setResult(result);
|
||||
// 可领取得奖励数量
|
||||
int getNum = (config.getLoseRate()/10000) * record.getBetNum();
|
||||
if (result == 1){
|
||||
getNum = record.getBetNum() * (config.getRateList()[winnerId-1]/10000);
|
||||
}
|
||||
record.setGetNum(getNum);
|
||||
// 领取状态
|
||||
record.setState(0);
|
||||
judge = true;
|
||||
}
|
||||
judge = recordBuild(record,getRankMap());
|
||||
// 结果
|
||||
CommonProto.RidingSwardRecord.Builder builder = CommonProto.RidingSwardRecord.newBuilder()
|
||||
.setTime(record.getTime())// 赛场时间
|
||||
|
@ -454,15 +421,55 @@ public class RidingSwardLogic{
|
|||
.setResult(record.getResult()); // 输赢结果
|
||||
list.add(builder.build());
|
||||
}
|
||||
|
||||
// 更新缓存对象类型
|
||||
if (judge){
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.RIDING_SWARD_RECORD, String.valueOf(uid),String.valueOf(entry.getKey()),entry.getValue());
|
||||
putRecordList(uid,entry.getKey(),entry.getValue());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录数据处理
|
||||
*/
|
||||
public static boolean recordBuild(RidingSwardRecord record,Map<Long, Integer> rankMap){
|
||||
// 配置表
|
||||
Map<Integer, SRidingSwardResult> resultMap = STableManager.getConfig(SRidingSwardResult.class);
|
||||
SRidingSwardConfig config = STableManager.getConfig(SRidingSwardConfig.class).get(1);
|
||||
// 不需要处理的数据
|
||||
if (record.getState() != -1){
|
||||
return false;
|
||||
}
|
||||
// 根据场次获取剧本id
|
||||
Integer scriptId = rankMap.get(record.getTime());
|
||||
if (scriptId == null){
|
||||
return false;
|
||||
}
|
||||
// 剧本信息
|
||||
SRidingSwardResult swardResult = resultMap.get(scriptId);
|
||||
int winnerId = 0;
|
||||
for (int i = 0; i < swardResult.getResult().length; i++) {
|
||||
if (swardResult.getResult()[i][0] == 1){
|
||||
winnerId = i+1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 获胜剑id
|
||||
record.setWinnerId(winnerId);
|
||||
// 竞猜结果
|
||||
int result = winnerId == record.getBetSwardId()?1:0;
|
||||
record.setResult(result);
|
||||
// 可领取得奖励数量
|
||||
int getNum = (config.getLoseRate()/10000) * record.getBetNum();
|
||||
if (result == 1){
|
||||
getNum = record.getBetNum() * (config.getRateList()[winnerId-1]/10000);
|
||||
}
|
||||
record.setGetNum(getNum);
|
||||
// 领取状态
|
||||
record.setState(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前竞猜信息
|
||||
* @param uid
|
||||
|
@ -484,13 +491,43 @@ public class RidingSwardLogic{
|
|||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取排行榜
|
||||
* @return
|
||||
*/
|
||||
public static Map<Long, Integer> getRankMap(){
|
||||
Map<Long, Integer> map = RedisUtil.getInstence().getMapValues(RedisKey.RIDING_SWARD_RANK, "", Long.class, Integer.class);
|
||||
if (map == null){
|
||||
return new HashMap<>();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static String getRankKey(){
|
||||
return RedisUtil.getInstence().getKey(RedisKey.RIDING_SWARD_RANK, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 排行榜备份
|
||||
*/
|
||||
public void putRankBack(){
|
||||
// 获取当前排行榜数据
|
||||
Map<String, Integer> rankMap = RedisUtil.getInstence().getMapValues(RedisKey.RIDING_SWARD_RANK, "", String.class, Integer.class);
|
||||
// 备份数据
|
||||
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
|
||||
*/
|
||||
private Map<Long, Integer> getRankMap(){
|
||||
Map<Long, Integer> map = RedisUtil.getInstence().getMapValues(RedisKey.RIDING_SWARD_RANK, "", Long.class, Integer.class);
|
||||
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<>();
|
||||
}
|
||||
|
@ -500,7 +537,7 @@ public class RidingSwardLogic{
|
|||
/**
|
||||
* 投注记录,key:场次时间戳,value:竞猜记录信息
|
||||
*/
|
||||
private Map<Long, List<RidingSwardRecord>> getRecordList(int uid){
|
||||
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);
|
||||
if (map == null){
|
||||
|
@ -509,9 +546,10 @@ public class RidingSwardLogic{
|
|||
return map;
|
||||
}
|
||||
|
||||
public static String getRankKey(){
|
||||
return RedisUtil.getInstence().getKey(RedisKey.RIDING_SWARD_RANK, "");
|
||||
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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue