gm充值返利活动
parent
ffc965a6fe
commit
8f602dfebe
|
@ -299,16 +299,39 @@ public class TimeUtils {
|
|||
return new SimpleDateFormat(ymdhms_Format_new).format(new Date(time));
|
||||
}
|
||||
|
||||
/**
|
||||
* yyyy-MM-dd HH:mm:ss
|
||||
* @param time
|
||||
* @return
|
||||
* @throws ParseException
|
||||
*/
|
||||
public static Date dateFormat(String time) throws ParseException {
|
||||
DateFormat format1 = new SimpleDateFormat(ymdhms_Format_new);
|
||||
return format1.parse(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* yyyy-MM-dd HH:mm:ss
|
||||
* @param time
|
||||
* @return
|
||||
* @throws ParseException
|
||||
*/
|
||||
public static long dateFormat2(String time) throws ParseException {
|
||||
DateFormat format1 = new SimpleDateFormat(ymdhms_Format_new);
|
||||
return format1.parse(time).getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* yyyyMMddHHmmss
|
||||
* @param time
|
||||
* @return
|
||||
* @throws ParseException
|
||||
*/
|
||||
public static long dateFormat3(String time) throws ParseException {
|
||||
DateFormat format1 = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
return format1.parse(time).getTime();
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * 是否是同一天
|
||||
|
|
|
@ -44,4 +44,6 @@ public class MongoKey {
|
|||
public final static String mainLevelManager = "mainLevelManager";
|
||||
public final static String expeditionManager = "expeditionManager";
|
||||
public final static String hardStageManager = "hardStageManager";
|
||||
|
||||
public final static String gmActivityManager = "gmActivityManager";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
package com.ljsd.jieling.db.mongo.gmActivity;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Author hj
|
||||
* @Date 2022/9/26 16:51:23
|
||||
* @Description: 自动充值返利活动
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Document(collection = "c_arb_activity")
|
||||
public class ARBActivity {
|
||||
@Id
|
||||
private String id;
|
||||
/**
|
||||
* 活动名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 活动描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 活动类型
|
||||
*/
|
||||
private int type;
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private String startTime;
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private String endTime;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
/**
|
||||
* 生效的服务器列表
|
||||
*/
|
||||
private Set<String> serverIds = new HashSet<>();
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(String startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public String getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(String endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public Set<String> getServerIds() {
|
||||
return serverIds;
|
||||
}
|
||||
|
||||
public void setServerIds(Set<String> serverIds) {
|
||||
this.serverIds = serverIds;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
package com.ljsd.jieling.db.mongo.gmActivity;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
/**
|
||||
* @Author hj
|
||||
* @Date 2022/9/26 16:56:07
|
||||
* @Description:自动充值返利活动档位
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Document(collection = "c_arb_mission")
|
||||
public class ARBMission {
|
||||
@Id
|
||||
private String id;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private int sort;
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 通用充值额度
|
||||
* @return
|
||||
*/
|
||||
private int rechargeNum;
|
||||
/**
|
||||
* 道具数组
|
||||
*/
|
||||
private int[][] reward;
|
||||
/**
|
||||
* 关联查询,活动信息
|
||||
*/
|
||||
@DBRef
|
||||
private ARBActivity activity;
|
||||
|
||||
/**
|
||||
* 返利活动数据
|
||||
* @return
|
||||
*/
|
||||
private int beforeNum;
|
||||
|
||||
private int afterNum;
|
||||
|
||||
private int backRatio;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getSort() {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public void setSort(int sort) {
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public int[][] getReward() {
|
||||
return reward;
|
||||
}
|
||||
|
||||
public void setReward(int[][] reward) {
|
||||
this.reward = reward;
|
||||
}
|
||||
|
||||
public ARBActivity getActivity() {
|
||||
return activity;
|
||||
}
|
||||
|
||||
public void setActivity(ARBActivity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
public int getBeforeNum() {
|
||||
return beforeNum;
|
||||
}
|
||||
|
||||
public void setBeforeNum(int beforeNum) {
|
||||
this.beforeNum = beforeNum;
|
||||
}
|
||||
|
||||
public int getAfterNum() {
|
||||
return afterNum;
|
||||
}
|
||||
|
||||
public void setAfterNum(int afterNum) {
|
||||
this.afterNum = afterNum;
|
||||
}
|
||||
|
||||
public int getBackRatio() {
|
||||
return backRatio;
|
||||
}
|
||||
|
||||
public void setBackRatio(int backRatio) {
|
||||
this.backRatio = backRatio;
|
||||
}
|
||||
|
||||
public int getRechargeNum() {
|
||||
return rechargeNum;
|
||||
}
|
||||
|
||||
public void setRechargeNum(int rechargeNum) {
|
||||
this.rechargeNum = rechargeNum;
|
||||
}
|
||||
}
|
|
@ -454,9 +454,10 @@ public class RedisKey {
|
|||
public static final String RIDING_SWARD_RECORD = "RIDING_SWARD_RECORD";
|
||||
// 御剑飞行时间锁
|
||||
public static final String RIDING_SWARD_TIME_LOCK = "RIDING_SWARD_TIME_LOCK";
|
||||
|
||||
//全民福利购买礼包次数
|
||||
public static final String ALL_PEOPLE_WELFARE_BUY_COUNT = "ALL_PEOPLE_WELFARE_BUY_COUNT";
|
||||
// GM活动更新
|
||||
public static final String GM_ACTIVITY_UPDATE = "GM_ACTIVITY_UPDATE";
|
||||
|
||||
public static Set<String> newAreaCacChe = new HashSet<>();//进程排行 合区统一
|
||||
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
package com.ljsd.jieling.jbean;
|
||||
|
||||
import com.ljsd.common.mogodb.MongoBase;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* 说明:gm活动
|
||||
*
|
||||
* @author ascend
|
||||
* 2022/10/26 11:42:48
|
||||
*/
|
||||
public class GmActivityManager extends MongoBase {
|
||||
private HashMap<String, ActivityProgressInfo> map = new HashMap<>();
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package com.ljsd.jieling.jbean.gm;
|
||||
|
||||
import com.ljsd.common.mogodb.MongoBase;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* 说明:gm活动
|
||||
*
|
||||
* @author ascend
|
||||
* 2022/10/27 16:09:45
|
||||
*/
|
||||
public class GmActivity {
|
||||
private HashMap<String, GmMission> missionMap = new HashMap<>();
|
||||
private String id;
|
||||
private int type;
|
||||
private int value;
|
||||
private String startTime;
|
||||
private String endTime;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public HashMap<String, GmMission> getMissionMap() {
|
||||
return missionMap;
|
||||
}
|
||||
|
||||
public void setMissionMap(HashMap<String, GmMission> missionMap) {
|
||||
this.missionMap = missionMap;
|
||||
}
|
||||
|
||||
public void putMissionMap(String id, GmMission mission) {
|
||||
this.missionMap.put(id,mission);
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(String startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public String getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(String endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.ljsd.jieling.jbean.gm;
|
||||
|
||||
import com.ljsd.common.mogodb.MongoBase;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* 说明:gm活动
|
||||
*
|
||||
* @author ascendz
|
||||
* 2022/10/26 11:42:48
|
||||
*/
|
||||
public class GmActivityManager extends MongoBase {
|
||||
private HashMap<String, GmActivity> activityMap = new HashMap<>();
|
||||
|
||||
private int updateVersion;
|
||||
|
||||
public HashMap<String, GmActivity> getActivityMap() {
|
||||
return activityMap;
|
||||
}
|
||||
|
||||
public void setActivityMap(HashMap<String, GmActivity> activityMap) {
|
||||
this.activityMap = activityMap;
|
||||
updateString("activityMap",activityMap);
|
||||
}
|
||||
|
||||
public void putActivityMap(String activityId, GmActivity activity) {
|
||||
this.activityMap.put(activityId,activity);
|
||||
updateString("activityMap",activityMap);
|
||||
}
|
||||
|
||||
public void removeActivity(String activityId) {
|
||||
this.activityMap.remove(activityId);
|
||||
updateString("activityMap",activityMap);
|
||||
}
|
||||
|
||||
public int getUpdateVersion() {
|
||||
return updateVersion;
|
||||
}
|
||||
|
||||
public void setUpdateVersion(int updateVersion) {
|
||||
this.updateVersion = updateVersion;
|
||||
updateString("updateVersion",updateVersion);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.ljsd.jieling.jbean.gm;
|
||||
|
||||
/**
|
||||
* 说明:gm活动档位
|
||||
*
|
||||
* @author ascend
|
||||
* 2022/10/27 16:09:54
|
||||
*/
|
||||
public class GmMission {
|
||||
private String id;
|
||||
private int value;
|
||||
private int state;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(int state) {
|
||||
this.state = state;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,325 @@
|
|||
package com.ljsd.jieling.logic.activity.activityLogic;
|
||||
|
||||
import com.ljsd.GameApplication;
|
||||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||
import com.ljsd.jieling.db.mongo.gmActivity.ARBActivity;
|
||||
import com.ljsd.jieling.db.mongo.gmActivity.ARBMission;
|
||||
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.gm.GmActivity;
|
||||
import com.ljsd.jieling.jbean.gm.GmActivityManager;
|
||||
import com.ljsd.jieling.jbean.gm.GmMission;
|
||||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||
import com.ljsd.jieling.logic.activity.IEventHandler;
|
||||
import com.ljsd.jieling.logic.activity.event.IEvent;
|
||||
import com.ljsd.jieling.logic.activity.event.Poster;
|
||||
import com.ljsd.jieling.logic.activity.event.SuperBoxEvent;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.logic.mail.MailLogic;
|
||||
import com.ljsd.jieling.network.server.ProtocolsManager;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.util.AyyncWorker;
|
||||
import com.ljsd.jieling.util.ItemUtil;
|
||||
import config.SErrorCodeEerverConfig;
|
||||
import config.SRechargeCommodityNewConfig;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import util.StringUtil;
|
||||
import util.TimeUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 说明:gm活动处理类
|
||||
*
|
||||
* @author ascend
|
||||
* 2022/10/27 16:20:08
|
||||
*/
|
||||
public class GmActivityLogic implements IEventHandler {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GmActivityLogic.class);
|
||||
|
||||
public GmActivityLogic() {
|
||||
Poster.getPoster().listenEvent(this, SuperBoxEvent.class);
|
||||
}
|
||||
|
||||
public static GmActivityLogic getInstance() {
|
||||
return GmActivityLogic.Instance.instance;
|
||||
}
|
||||
|
||||
public static class Instance {
|
||||
public final static GmActivityLogic instance = new GmActivityLogic();
|
||||
}
|
||||
|
||||
private static int gameUpdateVersion = 0;
|
||||
|
||||
@Override
|
||||
public void onEvent(IEvent event) throws Exception {
|
||||
if (!(event instanceof SuperBoxEvent)){
|
||||
return;
|
||||
}
|
||||
SuperBoxEvent boxEvent = (SuperBoxEvent) event;
|
||||
if (boxEvent.getGiftId() <= 0){
|
||||
return;
|
||||
}
|
||||
SRechargeCommodityNewConfig config = SRechargeCommodityNewConfig.getConfigById(boxEvent.getGiftId());
|
||||
if (config == null){
|
||||
return;
|
||||
}
|
||||
User user = UserManager.getUser(boxEvent.getUserId());
|
||||
GmActivityManager manager = user.getGmActivityManager();
|
||||
HashMap<String, GmActivity> activityMap = manager.getActivityMap();
|
||||
for (Map.Entry<String, GmActivity> entry : activityMap.entrySet()) {
|
||||
GmActivity gmActivity = entry.getValue();
|
||||
// 时间校验
|
||||
long start = TimeUtils.dateFormat2(gmActivity.getStartTime());
|
||||
long end = TimeUtils.dateFormat2(gmActivity.getEndTime());
|
||||
long now = TimeUtils.now();
|
||||
if (start > now || end <= now){
|
||||
continue;
|
||||
}
|
||||
// 邮件信息
|
||||
String title = SErrorCodeEerverConfig.getI18NMessage("zidongfanli_mail_title");
|
||||
String content = SErrorCodeEerverConfig.getI18NMessage("zidongfanli_mail_text");
|
||||
List<int[][]> rewards = new ArrayList<>();
|
||||
switch (gmActivity.getType()){
|
||||
case 1:
|
||||
case 3:
|
||||
case 5://单笔累充,多日累充,永久大充
|
||||
getDefaultReward(gmActivity,config.getPrice(),rewards);
|
||||
break;
|
||||
case 2://妖晶返利
|
||||
getRewardToMonsterCurrencyBack(gmActivity,config.getPrice(),rewards);
|
||||
break;
|
||||
case 4://单笔充值
|
||||
getRewardToSingleRecharge(gmActivity,config.getPrice(),rewards);
|
||||
break;
|
||||
default:
|
||||
LOGGER.error("充值返利,未找到得活动类型,uid:{}, activityId:{}", user.getId(), gmActivity.getId());
|
||||
continue;
|
||||
}
|
||||
// 入库
|
||||
manager.putActivityMap(gmActivity.getId(),gmActivity);
|
||||
// 验证奖励非空
|
||||
String mailReward = ItemUtil.getMailReward(rewards);
|
||||
if (StringUtil.isEmpty(mailReward)){
|
||||
continue;
|
||||
}
|
||||
MailLogic.getInstance().sendMail(user.getId(),title,content,mailReward,TimeUtils.nowInt(),Global.MAIL_EFFECTIVE_TIME);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认奖励
|
||||
* @param gmActivity
|
||||
* @param price
|
||||
* @param rewards
|
||||
*/
|
||||
private void getDefaultReward(GmActivity gmActivity, double price, List<int[][]> rewards){
|
||||
List<ARBMission> gmMissionList = findAllGmMission(gmActivity.getId());
|
||||
int num = gmActivity.getValue() + (int) price;
|
||||
for (ARBMission arbMission : gmMissionList) {
|
||||
GmMission gmMission = gmActivity.getMissionMap().getOrDefault(arbMission.getId(), new GmMission());
|
||||
// 已领取
|
||||
if (gmMission.getState() == 1){
|
||||
continue;
|
||||
}
|
||||
// 不能领
|
||||
if (num < arbMission.getRechargeNum()){
|
||||
continue;
|
||||
}
|
||||
// 奖励
|
||||
rewards.add(arbMission.getReward());
|
||||
// 记录到库
|
||||
gmMission.setId(arbMission.getId());
|
||||
gmMission.setState(1);
|
||||
gmActivity.putMissionMap(arbMission.getId(), gmMission);
|
||||
}
|
||||
gmActivity.setValue(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单笔充值奖励
|
||||
* @param gmActivity
|
||||
* @param price
|
||||
* @param rewards
|
||||
*/
|
||||
private void getRewardToSingleRecharge(GmActivity gmActivity, double price, List<int[][]> rewards){
|
||||
List<ARBMission> gmMissionList = findAllGmMission(gmActivity.getId());
|
||||
for (ARBMission arbMission : gmMissionList) {
|
||||
GmMission gmMission = gmActivity.getMissionMap().getOrDefault(arbMission.getId(), new GmMission());
|
||||
// 已领取
|
||||
if (gmMission.getState() == 1){
|
||||
continue;
|
||||
}
|
||||
// 不能领
|
||||
if (price != arbMission.getRechargeNum()){
|
||||
continue;
|
||||
}
|
||||
// 奖励
|
||||
rewards.add(arbMission.getReward());
|
||||
// 记录到库
|
||||
gmMission.setId(arbMission.getId());
|
||||
gmMission.setState(1);
|
||||
gmActivity.putMissionMap(arbMission.getId(), gmMission);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 妖晶返利奖励
|
||||
* @param gmActivity
|
||||
* @param price
|
||||
* @param rewards
|
||||
*/
|
||||
private void getRewardToMonsterCurrencyBack(GmActivity gmActivity, double price, List<int[][]> rewards){
|
||||
List<ARBMission> gmMissionList = findAllGmMission(gmActivity.getId());
|
||||
List<ARBMission> arbMissions = gmMissionList.stream().sorted(Comparator.comparing(ARBMission::getSort)).collect(Collectors.toList());
|
||||
int num = gmActivity.getValue() + (int) price;
|
||||
for (ARBMission arbMission : arbMissions) {
|
||||
if (num <= 0){
|
||||
break;
|
||||
}
|
||||
// 已领取
|
||||
GmMission gmMission = gmActivity.getMissionMap().getOrDefault(arbMission.getId(), new GmMission());
|
||||
if (gmMission.getState() == 1){
|
||||
num -= arbMission.getAfterNum();
|
||||
continue;
|
||||
}
|
||||
// 未到领取条件
|
||||
if (num < arbMission.getBeforeNum()){
|
||||
continue;
|
||||
}
|
||||
// 当前档位还可以返利得金额
|
||||
int count = arbMission.getAfterNum() - gmMission.getValue();
|
||||
// 总返利和当前档位返利获取最小
|
||||
int min = Math.min(num, count);
|
||||
// 奖励
|
||||
int[][] reward = {{16,min*arbMission.getBackRatio()}};
|
||||
rewards.add(reward);
|
||||
// 档位信息更新
|
||||
gmMission.setId(arbMission.getId());
|
||||
if (num - min > 0){
|
||||
gmMission.setState(1);
|
||||
num -= min;
|
||||
}else {
|
||||
gmMission.setValue(gmMission.getValue() + num);
|
||||
}
|
||||
gmActivity.putMissionMap(arbMission.getId(),gmMission);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验活动开关
|
||||
* @param user
|
||||
*/
|
||||
public void updateGmActivity(User user){
|
||||
GmActivityManager gmActivityManager = user.getGmActivityManager();
|
||||
int version = getRedisUpdateVersion();
|
||||
if (gmActivityManager.getUpdateVersion() == version){
|
||||
return;
|
||||
}
|
||||
List<ARBActivity> list = findServerActivityList(String.valueOf(GameApplication.serverId));
|
||||
HashMap<String, GmActivity> activityMap = gmActivityManager.getActivityMap();
|
||||
// 删除不存在得活动
|
||||
Set<String> set = list.stream().map(ARBActivity::getId).collect(Collectors.toSet());
|
||||
for (String key : activityMap.keySet()) {
|
||||
if (!set.contains(key)){
|
||||
gmActivityManager.removeActivity(key);
|
||||
}
|
||||
}
|
||||
// 更新活动信息
|
||||
for (ARBActivity arbActivity : list) {
|
||||
GmActivity gmActivity = activityMap.getOrDefault(arbActivity.getId(),new GmActivity());
|
||||
gmActivity.setId(arbActivity.getId());
|
||||
gmActivity.setType(arbActivity.getType());
|
||||
gmActivity.setStartTime(arbActivity.getStartTime());
|
||||
gmActivity.setEndTime(arbActivity.getEndTime());
|
||||
gmActivityManager.putActivityMap(gmActivity.getId(),gmActivity);
|
||||
}
|
||||
gmActivityManager.setUpdateVersion(version);
|
||||
}
|
||||
|
||||
/**
|
||||
* 零点更新活动信息
|
||||
* @param user
|
||||
*/
|
||||
public void zeroUpdateGmActivity(User user){
|
||||
updateGmActivity(user);
|
||||
GmActivityManager manager = user.getGmActivityManager();
|
||||
HashMap<String, GmActivity> activityMap = manager.getActivityMap();
|
||||
for (GmActivity gmActivity : activityMap.values()) {
|
||||
// 单笔累充和妖晶返利每日清零
|
||||
if (gmActivity.getType() == 1 || gmActivity.getType() == 2){
|
||||
gmActivity.setValue(0);
|
||||
gmActivity.setMissionMap(new HashMap<>());
|
||||
// 入库
|
||||
manager.putActivityMap(gmActivity.getId(),gmActivity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 每分钟处理
|
||||
*/
|
||||
public static void minuteTask(){
|
||||
int version = getRedisUpdateVersion();
|
||||
if (gameUpdateVersion == version){
|
||||
return;
|
||||
}
|
||||
gameUpdateVersion = version;
|
||||
try {
|
||||
for (ISession session : OnlineUserManager.sessionMap.values()) {
|
||||
User user = UserManager.getUser(session.getUid());
|
||||
AyyncWorker ayyncWorker = new AyyncWorker(user, true, user1 -> {
|
||||
GmActivityLogic.getInstance().updateGmActivity(user);
|
||||
});
|
||||
ProtocolsManager.getInstance().updateAyncWorker(ayyncWorker);
|
||||
}
|
||||
MongoUtil.getInstence().lastUpdate();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ARBActivity> findAllGmActivity() {
|
||||
MongoTemplate coreMonoTemplate = MongoUtil.getCoreMongoTemplate();
|
||||
return coreMonoTemplate.findAll(ARBActivity.class);
|
||||
}
|
||||
|
||||
|
||||
public List<ARBActivity> findServerActivityList(String serverId) {
|
||||
List<ARBActivity> resultList = new ArrayList<>();
|
||||
for (ARBActivity activity : findAllGmActivity()) {
|
||||
if (activity.getServerIds().contains(serverId)){
|
||||
resultList.add(activity);
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
public List<ARBMission> findAllGmMission(String activityId) {
|
||||
MongoTemplate coreMonoTemplate = MongoUtil.getCoreMongoTemplate();
|
||||
Query query = new Query(Criteria.where("activity.$id").is(new ObjectId(activityId)));
|
||||
return coreMonoTemplate.find(query, ARBMission.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从redis获取更新号码(秒级时间戳格式)
|
||||
* @return
|
||||
*/
|
||||
public static int getRedisUpdateVersion(){
|
||||
String updateVersion = (String) RedisUtil.getInstence().get(RedisKey.GM_ACTIVITY_UPDATE);
|
||||
if (updateVersion == null){
|
||||
return 0;
|
||||
}
|
||||
return Integer.parseInt(updateVersion);
|
||||
}
|
||||
|
||||
}
|
|
@ -4,6 +4,7 @@ import com.ljsd.jieling.db.mongo.MongoKey;
|
|||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||
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.*;
|
||||
|
||||
public class User {
|
||||
|
@ -50,6 +51,8 @@ public class User {
|
|||
private MainLevelManager mainLevelManager;
|
||||
private ExpeditionManager expeditionManager;
|
||||
private HardStageManager hardStageManager;
|
||||
|
||||
private GmActivityManager gmActivityManager;
|
||||
//TODO 新增manager 需要兼容旧的数据 提前判null
|
||||
|
||||
//构造函数必须要声明,否则从mongodb读出来反编译成类不通过
|
||||
|
@ -79,7 +82,7 @@ public class User {
|
|||
this.mainLevelManager = new MainLevelManager();
|
||||
this.expeditionManager = new ExpeditionManager();
|
||||
this.hardStageManager = new HardStageManager();
|
||||
|
||||
this.gmActivityManager = new GmActivityManager();
|
||||
//綁定关系
|
||||
|
||||
this.playerManager.init(id, MongoKey.playerManager);
|
||||
|
@ -104,6 +107,7 @@ public class User {
|
|||
this.mainLevelManager.init(id,MongoKey.mainLevelManager);
|
||||
this.expeditionManager.init(id,MongoKey.expeditionManager);
|
||||
this.hardStageManager.init(id,MongoKey.hardStageManager);
|
||||
this.gmActivityManager.init(id,MongoKey.gmActivityManager);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
@ -231,6 +235,23 @@ public class User {
|
|||
return hardStageManager;
|
||||
}
|
||||
|
||||
public GmActivityManager getGmActivityManager() {
|
||||
if(null ==gmActivityManager){
|
||||
this.gmActivityManager = new GmActivityManager();
|
||||
this.gmActivityManager.init(id,MongoKey.gmActivityManager);
|
||||
}else{
|
||||
if(this.gmActivityManager.getMongoKey()== null || this.gmActivityManager.getMongoKey().isEmpty()){
|
||||
this.gmActivityManager.init(id,MongoKey.gmActivityManager);
|
||||
try {
|
||||
MongoUtil.getInstence().getMyMongoTemplate().save(id,this);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return gmActivityManager;
|
||||
}
|
||||
|
||||
public RoomInfo getRoomInfo() {
|
||||
if(roomInfo == null){
|
||||
roomInfo = new RoomInfo();
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.ljsd.jieling.logic.GlobleSystemLogic;
|
|||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||
import com.ljsd.jieling.logic.SituationLogic;
|
||||
import com.ljsd.jieling.logic.activity.ActivityLogic;
|
||||
import com.ljsd.jieling.logic.activity.activityLogic.GmActivityLogic;
|
||||
import com.ljsd.jieling.logic.activity.event.MinuteTaskEvent;
|
||||
import com.ljsd.jieling.logic.activity.event.Poster;
|
||||
import com.ljsd.jieling.logic.activity.fourChallenge.FourChallengeLogic;
|
||||
|
@ -174,6 +175,13 @@ public class MinuteTask extends Thread {
|
|||
LOGGER.error("跨服排行榜初始化异常,Exception::=>{}",e.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
GmActivityLogic.minuteTask();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
LOGGER.error("自动返利初始化异常,Exception::=>{}",e.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
ArenaLogic.getInstance().worldSendReward();
|
||||
}catch (Exception e){
|
||||
|
|
Loading…
Reference in New Issue