Merge branch 'master_otnew' into cycle_activity
# Conflicts: # conf/c_database_version.json # conf/hotfix.jsonmaster_otnew
commit
bbb9d414f8
|
@ -38,9 +38,6 @@ public class LjsdMongoTemplate implements MongoUpdateImp {
|
|||
|
||||
//注释
|
||||
public <T> void save(int uid,T obj) throws Exception {
|
||||
// MongoRoot root = (MongoRoot)obj;
|
||||
// mongoTemplate.save(obj,root.getCollection());
|
||||
// root.setBsave(true);
|
||||
int serverIdByUid = AreaManager.getInstance().getServerIdByUid(uid);
|
||||
MongoTemplate otherMonogTemplate = getMongoTemplate(serverIdByUid);
|
||||
if (otherMonogTemplate == null) {
|
||||
|
@ -75,14 +72,8 @@ public class LjsdMongoTemplate implements MongoUpdateImp {
|
|||
if (mongoTemplate != null) {
|
||||
return mongoTemplate.findAll(clazz);
|
||||
}
|
||||
|
||||
// for (MongoTemplate mongoTemplate : MongoUtil.mongoTemplateMap.values()) {
|
||||
// List<T> all = mongoTemplate.findAll(clazz);
|
||||
// list.addAll(all);
|
||||
// }
|
||||
}
|
||||
return list;
|
||||
//return mongoTemplate.findAll(clazz,collectionName);
|
||||
}
|
||||
|
||||
public <T> List<T> findAllByCondition(Query query, Class<T> entityClass) {
|
||||
|
@ -149,7 +140,6 @@ public class LjsdMongoTemplate implements MongoUpdateImp {
|
|||
return otherMonogTemplate.findById(id,clazz,collectionName);
|
||||
}
|
||||
|
||||
|
||||
public <T> T findById(int id, Class<T> clazz) throws Exception {
|
||||
int serverIdByUid ;
|
||||
if(clazz.equals(GlobalSystemControl.class)||clazz.equals(ServerConfig.class)){
|
||||
|
|
|
@ -12,7 +12,9 @@ import com.ljsd.jieling.logic.dao.root.User;
|
|||
import com.ljsd.jieling.util.ConfigurableApplicationContextManager;
|
||||
import com.ljsd.jieling.util.InnerMessageUtil;
|
||||
import com.ljsd.jieling.util.SysUtil;
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.MongoClient;
|
||||
import org.bson.Document;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
|
@ -86,22 +88,37 @@ public class MongoUtil {
|
|||
}
|
||||
|
||||
//todo 慢查 需要修改
|
||||
public List<User> getRandomUsers(int size, int uid, int level) throws Exception {
|
||||
public List<User> getRandomUsers(int size, int uid, int level) {
|
||||
// 验证size参数的有效性
|
||||
if (size <= 0) {
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
int randomLevel = MathUtils.random(5, 20);
|
||||
Criteria criatira = new Criteria();
|
||||
int minLevel = level - randomLevel;
|
||||
minLevel = Math.max(minLevel, 5);
|
||||
int maxLevel = level + randomLevel;
|
||||
long befor3Day = System.currentTimeMillis() - BEFOR_3_DAY;
|
||||
|
||||
criatira.andOperator(Criteria.where("id").nin(uid),//不包含自己
|
||||
Criteria.where("playerManager.level").gte(minLevel), Criteria.where("playerManager.level").lte(maxLevel),
|
||||
Criteria.where("playerManager.loginTime").gte(befor3Day));
|
||||
Query query = new Query(criatira).limit(size * 2 + 1);
|
||||
// 随机等级差异的计算
|
||||
int randomLevel = MathUtils.random(5, 20);
|
||||
int minLevel = Math.max(level - randomLevel, 5);
|
||||
int maxLevel = level + randomLevel;
|
||||
|
||||
// 计算三天前的时间点
|
||||
long threeDaysAgo = System.currentTimeMillis() - BEFOR_3_DAY;
|
||||
|
||||
// 构建查询条件
|
||||
Criteria criteria = Criteria.where("id").nin(uid)
|
||||
.and("playerManager.level").gte(minLevel).lte(maxLevel)
|
||||
.and("playerManager.loginTime").gte(threeDaysAgo);
|
||||
|
||||
// 创建查询对象,并设置限制条件
|
||||
int length = size * 2 + 1;
|
||||
Query query = Query.query(criteria).limit(length);
|
||||
|
||||
// 限定返回的字段,只返回需要的字段可以提高效率
|
||||
query.fields().include("playerManager");
|
||||
|
||||
// MongoTemplate mongoTemplate = mongoTemplateMap.get(GameApplication.serverId);
|
||||
// DBObject explainResult = mongoTemplate.getCollection("user").find(query.getQueryObject()).explain();
|
||||
// LOGGER.info("随机玩家mongo检查:{}",explainResult.toString());
|
||||
|
||||
// 执行查询
|
||||
return this.myMongoTemplate.findAllByCondition(query, User.class);
|
||||
}
|
||||
|
||||
|
@ -266,7 +283,7 @@ public class MongoUtil {
|
|||
mongoTemplate = new MongoTemplate(mongoDbFactory, mappingMongoConverter);
|
||||
mongoTemplateMap.put(serverId,mongoTemplate);
|
||||
}
|
||||
return mongoTemplate;
|
||||
return mongoTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -91,7 +91,7 @@ public class GetPlayerInfoHandler extends BaseHandler{
|
|||
int unlockType = entry.getValue().getUnlockType();
|
||||
if(unlockType < 4 || unlockType == 6 || unlockType == 11){
|
||||
if (!vipInfo.containsKey(entry.getKey())){
|
||||
playerInfoManager.addVipInfo(entry.getKey());
|
||||
PlayerLogic.getInstance().addVipInfo(user, entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.ljsd.jieling.logic.activity;
|
|||
import com.ljsd.jieling.logic.activity.event.LuckWheelEvent;
|
||||
import com.ljsd.jieling.logic.activity.event.Poster;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.logic.player.PlayerLogic;
|
||||
import config.SGlobalActivity;
|
||||
|
||||
/**
|
||||
|
@ -23,7 +24,7 @@ public class GmDialActivity extends LuckWheelNormalActivity{
|
|||
super.initActivity(user);
|
||||
SGlobalActivity activity = SGlobalActivity.getsGlobalActivityMap().get(id);
|
||||
if (activity.getPrivilege() != 0){
|
||||
user.getPlayerInfoManager().addVipInfo(activity.getPrivilege());
|
||||
PlayerLogic.getInstance().addVipInfo(user, activity.getPrivilege());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -514,6 +514,11 @@ public class PlayerManager extends MongoBase {
|
|||
return vipInfo;
|
||||
}
|
||||
|
||||
public void setVipInfo(Map<Integer, VipInfo> vipInfo) {
|
||||
this.vipInfo = vipInfo;
|
||||
updateString("vipInfo", vipInfo);
|
||||
}
|
||||
|
||||
public Set<Integer> getHadTakeLevelBoxVip() {
|
||||
return vipGoodInfo;
|
||||
}
|
||||
|
@ -562,68 +567,12 @@ public class PlayerManager extends MongoBase {
|
|||
updateString("vipInfo", vipInfo);
|
||||
}
|
||||
|
||||
public void vipFlush(Set<Integer> removePrivileges) {
|
||||
if (vipInfo.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (Map.Entry<Integer, VipInfo> entry : vipInfo.entrySet()) {
|
||||
Integer id = entry.getKey();
|
||||
SPrivilegeTypeConfig sPrivilegeTypeConfig = SPrivilegeTypeConfig.getsPrivilegeTypeConfigMap().get(id);
|
||||
if (null == sPrivilegeTypeConfig) {
|
||||
continue;
|
||||
}
|
||||
int refreshType = sPrivilegeTypeConfig.getRefreshType()[0];
|
||||
if (refreshType == 1 && entry.getValue().getCount() > 0) {
|
||||
VipInfo refreshVipInfo = new VipInfo();
|
||||
refreshVipInfo.setEffectTime(entry.getValue().getEffectTime());
|
||||
vipInfo.put(id,refreshVipInfo);
|
||||
}
|
||||
}
|
||||
for (Integer remove : removePrivileges) {
|
||||
vipInfo.remove(remove);
|
||||
}
|
||||
updateString("vipInfo", vipInfo);
|
||||
setHadTakeDailyBoxVip(-1);
|
||||
}
|
||||
|
||||
public void clearVipCount(int priviliageId){
|
||||
vipInfo.put(priviliageId,new VipInfo());
|
||||
updateString("vipInfo", vipInfo);
|
||||
|
||||
}
|
||||
|
||||
public void addVipInfo(int privilegeId){
|
||||
SPrivilegeTypeConfig config = SPrivilegeTypeConfig.getsPrivilegeTypeConfigMap().get(privilegeId);
|
||||
if (config==null){
|
||||
return;
|
||||
}
|
||||
int maxTime;
|
||||
int nowInt = TimeUtils.nowInt();
|
||||
VipInfo newVipInfo = new VipInfo();
|
||||
if(config.getContinueTime()!=null && config.getContinueTime().length>0){
|
||||
if(vipInfo.containsKey(privilegeId)){
|
||||
VipInfo info = vipInfo.get(privilegeId);
|
||||
if(config.getContinueTime()[1]==1 && nowInt < info.getEffectTime()){
|
||||
boolean aBool = config.getCondition().length == 1 && config.getCondition()[0][0] == 0;
|
||||
if(!aBool){
|
||||
newVipInfo.setCount(info.getCount()-config.getCondition()[0][1]);
|
||||
newVipInfo.setEffectTime(info.getEffectTime());
|
||||
vipInfo.put(privilegeId,newVipInfo);
|
||||
updateString("vipInfo", this.vipInfo);
|
||||
}
|
||||
return;
|
||||
}
|
||||
maxTime = Math.max(nowInt, info.getEffectTime()) + config.getContinueTime()[0];
|
||||
}else {
|
||||
maxTime = nowInt + config.getContinueTime()[0];
|
||||
}
|
||||
maxTime = (int)(TimeUtils.getLastOrUnderHour(maxTime*1000L,0,0,true)/1000);
|
||||
newVipInfo.setEffectTime(maxTime);
|
||||
}
|
||||
this.vipInfo.put(privilegeId,newVipInfo);
|
||||
updateString("vipInfo", this.vipInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据时间添加权限
|
||||
* @param privilageId 权限id
|
||||
|
|
|
@ -6,7 +6,11 @@ import com.ljsd.jieling.handler.map.MapManager;
|
|||
import com.ljsd.jieling.jbean.ActivityManager;
|
||||
import com.ljsd.jieling.jbean.gm.GmActivityManager;
|
||||
import com.ljsd.jieling.logic.dao.*;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndex;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
@CompoundIndex(def = "{'playerManager.level' : 1, 'playerManager.loginTime': 1}", name = "level_loginTime_idx")
|
||||
public class User {
|
||||
|
||||
public static final String _COLLECTION_NAME = "user";
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.ljsd.jieling.core.GlobalsDef;
|
|||
import com.ljsd.jieling.core.VipPrivilegeType;
|
||||
import com.ljsd.jieling.dataReport.reportBeans_37.ChatContentType;
|
||||
import com.ljsd.jieling.db.mongo.AreaManager;
|
||||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||
import com.ljsd.jieling.db.redis.RedisKey;
|
||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
import com.ljsd.jieling.exception.ErrorCode;
|
||||
|
@ -57,6 +58,7 @@ import util.MathUtils;
|
|||
import util.TimeUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class PlayerLogic {
|
||||
|
@ -350,29 +352,32 @@ public class PlayerLogic {
|
|||
int nowInt = TimeUtils.nowInt();
|
||||
Map<Integer, VipInfo> vipInfo = playerInfoManager.getVipInfo();
|
||||
for(Map.Entry<Integer,VipInfo> vipInfoItem : vipInfo.entrySet()){
|
||||
Integer id = vipInfoItem.getKey();
|
||||
VipInfo info = vipInfoItem.getValue();
|
||||
//如果这个权限是活动 且永久了 那么需要修复
|
||||
SPrivilegeTypeConfig config = SPrivilegeTypeConfig.getsPrivilegeTypeConfigMap().get(vipInfoItem.getKey());
|
||||
SPrivilegeTypeConfig config = SPrivilegeTypeConfig.getsPrivilegeTypeConfigMap().get(id);
|
||||
if (config == null){
|
||||
LOGGER.info("特权刷新删除日志1:{}-{}",vipInfoItem.getKey(),vipInfoItem.getValue().getEffectTime());
|
||||
removePrivileges.add(vipInfoItem.getKey());
|
||||
LOGGER.info("特权刷新删除日志1:{};{};{}",user.getId(), id, info.getEffectTime());
|
||||
removePrivileges.add(id);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(vipInfoItem.getValue().getEffectTime() == 0){
|
||||
if(info.getEffectTime() == 0){
|
||||
int unlockType = config.getUnlockType();
|
||||
if(unlockType==5 || (unlockType==4 && config.getContinueTime().length>0)){
|
||||
playerInfoManager.addVipByTime(vipInfoItem.getKey(), nowInt);
|
||||
playerInfoManager.addVipByTime(id, nowInt);
|
||||
}
|
||||
}
|
||||
else if(vipInfoItem.getValue().getEffectTime() <= nowInt){
|
||||
else if(info.getEffectTime() <= nowInt){
|
||||
if(config.getPrivilegeType() == VipPrivilegeType.ADVENTURE_BASE_REWARD){
|
||||
CombatLogic.getInstance().getNewAdventureReward(user,true,vipInfoItem.getValue().getEffectTime());
|
||||
CombatLogic.getInstance().getNewAdventureReward(user,true, info.getEffectTime());
|
||||
}
|
||||
removePrivileges.add(vipInfoItem.getKey());
|
||||
LOGGER.info("特权刷新删除日志2:{}-{}",vipInfoItem.getKey(),vipInfoItem.getValue().getEffectTime());
|
||||
removePrivileges.add(id);
|
||||
LOGGER.info("特权刷新删除日志2:{};{};{}",user.getId(), id, info.getEffectTime());
|
||||
}
|
||||
}
|
||||
playerInfoManager.vipFlush(removePrivileges);
|
||||
LOGGER.info("特权刷新删除日志3:{};{}",user.getId(),removePrivileges);
|
||||
vipFlush(user, removePrivileges);
|
||||
|
||||
// vip刷新后才能发给前端
|
||||
if(fBuilder != null){
|
||||
|
@ -388,6 +393,96 @@ public class PlayerLogic {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* vip刷新逻辑测试
|
||||
* @param uid
|
||||
* @param remove
|
||||
* @throws Exception
|
||||
*/
|
||||
public void vipFlushTest(int uid, int[] remove) throws Exception {
|
||||
LOGGER.info("刷新特权测试,uid:{},remove:{}",uid,remove);
|
||||
User user = UserManager.getUser(uid);
|
||||
Set<Integer> collect = Arrays.stream(remove).boxed().collect(Collectors.toSet());
|
||||
vipFlush(user, collect);
|
||||
}
|
||||
|
||||
/**
|
||||
* vip刷新逻辑
|
||||
* @param user
|
||||
* @param removePrivileges
|
||||
*/
|
||||
public void vipFlush(User user, Set<Integer> removePrivileges) throws Exception {
|
||||
PlayerManager playerInfoManager = user.getPlayerInfoManager();
|
||||
Map<Integer, VipInfo> vipInfo = playerInfoManager.getVipInfo();
|
||||
LOGGER.info("开始刷新特权,uid:{},list:{}",user.getId(),removePrivileges);
|
||||
if (vipInfo.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
LOGGER.info("开始刷新特权,删除前特权数量,uid:{},size:{}",user.getId(),vipInfo.size());
|
||||
for (Integer remove : removePrivileges) {
|
||||
vipInfo.remove(remove);
|
||||
}
|
||||
LOGGER.info("开始刷新特权,删除后特权数量,uid:{},size:{}",user.getId(),vipInfo.size());
|
||||
for (Map.Entry<Integer, VipInfo> entry : vipInfo.entrySet()) {
|
||||
Integer id = entry.getKey();
|
||||
VipInfo info = entry.getValue();
|
||||
SPrivilegeTypeConfig sPrivilegeTypeConfig = SPrivilegeTypeConfig.getsPrivilegeTypeConfigMap().get(id);
|
||||
if (null == sPrivilegeTypeConfig) {
|
||||
continue;
|
||||
}
|
||||
int refreshType = sPrivilegeTypeConfig.getRefreshType()[0];
|
||||
if (refreshType == 1 && info.getCount() > 0) {
|
||||
VipInfo refreshVipInfo = new VipInfo();
|
||||
refreshVipInfo.setCount(0);
|
||||
refreshVipInfo.setEffectTime(info.getEffectTime());
|
||||
vipInfo.put(id,refreshVipInfo);
|
||||
}
|
||||
}
|
||||
LOGGER.info("刷新特权完成,特权数量,uid:{},size:{}",user.getId(),vipInfo.size());
|
||||
playerInfoManager.setVipInfo(vipInfo);
|
||||
playerInfoManager.setHadTakeDailyBoxVip(-1);
|
||||
MongoUtil.getInstence().lastUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增或刷新vip信息
|
||||
* @param user
|
||||
* @param privilegeId
|
||||
*/
|
||||
public void addVipInfo(User user, int privilegeId){
|
||||
SPrivilegeTypeConfig config = SPrivilegeTypeConfig.getsPrivilegeTypeConfigMap().get(privilegeId);
|
||||
if (config==null){
|
||||
return;
|
||||
}
|
||||
PlayerManager playerManager = user.getPlayerInfoManager();
|
||||
Map<Integer, VipInfo> vipInfo = playerManager.getVipInfo();
|
||||
int maxTime;
|
||||
int nowInt = TimeUtils.nowInt();
|
||||
VipInfo newVipInfo = new VipInfo();
|
||||
if(config.getContinueTime()!=null && config.getContinueTime().length>0){
|
||||
if(vipInfo.containsKey(privilegeId)){
|
||||
VipInfo info = vipInfo.get(privilegeId);
|
||||
if(config.getContinueTime()[1]==1 && nowInt < info.getEffectTime()){
|
||||
boolean aBool = config.getCondition().length == 1 && config.getCondition()[0][0] == 0;
|
||||
if(!aBool){
|
||||
newVipInfo.setCount(info.getCount()-config.getCondition()[0][1]);
|
||||
newVipInfo.setEffectTime(info.getEffectTime());
|
||||
vipInfo.put(privilegeId,newVipInfo);
|
||||
playerManager.setVipInfo(vipInfo);
|
||||
}
|
||||
return;
|
||||
}
|
||||
maxTime = Math.max(nowInt, info.getEffectTime()) + config.getContinueTime()[0];
|
||||
}else {
|
||||
maxTime = nowInt + config.getContinueTime()[0];
|
||||
}
|
||||
maxTime = (int)(TimeUtils.getLastOrUnderHour(maxTime*1000L,0,0,true)/1000);
|
||||
newVipInfo.setEffectTime(maxTime);
|
||||
}
|
||||
vipInfo.put(privilegeId,newVipInfo);
|
||||
playerManager.setVipInfo(vipInfo);
|
||||
}
|
||||
|
||||
public Set<CommonProto.Privilege> getPrivilege(User user, Collection<Integer> collection) {
|
||||
Map<Integer, VipInfo> vipInfo = user.getPlayerInfoManager().getVipInfo();
|
||||
HashSet<CommonProto.Privilege> set = new HashSet<>();
|
||||
|
|
|
@ -606,7 +606,7 @@ public class BuyGoodsNewLogic {
|
|||
if(privilegeType == VipPrivilegeType.ADVENTURE_BASE_REWARD){
|
||||
CombatLogic.getInstance().getNewAdventureReward(user,true,TimeUtils.nowInt());
|
||||
}
|
||||
user.getPlayerInfoManager().addVipInfo(privilege);
|
||||
PlayerLogic.getInstance().addVipInfo(user, privilege);
|
||||
VipInfo vipInfo = user.getPlayerInfoManager().getVipInfo().get(privilege);
|
||||
indication.addInfos(CommonProto.Privilege.newBuilder().setId(privilege).setUsedTimes(vipInfo.getCount()).setEffectTime(vipInfo.getEffectTime()).build());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue