合服功能

master
duhui 2023-05-19 14:31:57 +08:00
parent c0a4864ca1
commit bebb3b648f
12 changed files with 512 additions and 62 deletions

View File

@ -5,6 +5,7 @@ import com.jmfy.dao.BanFuctionDao;
import com.jmfy.dao.ItemDao;
import com.jmfy.dao.ServerInfoDao;
import com.jmfy.dao.UserInfoDao;
import com.jmfy.handler.HeFuManager;
import com.jmfy.model.*;
import com.jmfy.model.vo.HeroHotRankVo;
import com.jmfy.model.vo.ItemLogVo;
@ -48,6 +49,8 @@ public class GmController {
private BanFuctionDao banFuctionDao;
@Resource
private ItemDao itemDao;
@Resource
private HeFuManager heFuManager;
private int htmlLikeId = 0;
@ -64,6 +67,11 @@ public class GmController {
return 0;
}
if (cmd.contains("hefu")) {
TaskKit.scheduleWithFixedOne(()->heFuManager.hefu(cmd),0);
return 0;
}
//根据excel删除道具
if (cmd.equals("deleteItem0210")){
deleteItem0210();

View File

@ -229,7 +229,7 @@ public class MailController {
// 个人邮件
else {
// 同一区服审核时间加限制
long now = DateUtil.now()/1000;
long now = DateUtil.nowInt();
Long oldTime = record.getOrDefault(Integer.parseInt(mail.getServerId()), 0L);
if(oldTime != 0 && (oldTime+limitTime)>now){
return 4;
@ -285,18 +285,6 @@ public class MailController {
*/
@RequestMapping(value = "/getMailListToCheck", method = {RequestMethod.POST, RequestMethod.GET})
public String getMailListToCheck (ModelMap map,int type) throws Exception {
if (type == PERSONAL_MAIL){
// 个人邮件,改版后,需要清理旧库中的数据,并添加到新库中
clearOldPersonalMail();
}else {
// 全服邮件处理,改版后,添加type类型
List<ServerMail> list = mailDao.getAllMailList();
list.removeIf(v->v.getType() == PERSONAL_MAIL || v.getType() == SERVER_MAIL);
for (ServerMail mail : list) {
mail.setType(SERVER_MAIL);
mailDao.updateMail(mail);
}
}
List<ServerMail> mails = mailDao.getMailList(type);
List<ServerMailVo> mailVos = new ArrayList<>();
for (ServerMail mail :mails){
@ -352,40 +340,40 @@ public class MailController {
*
* @throws Exception
*/
private void clearOldPersonalMail() throws Exception {
List<PersonalMail> personalMail = mailDao.getPMailList();
for (PersonalMail mail : personalMail) {
ServerMail serverMail = pTos(mail);
mailDao.removePMail(mail.getId());
mailDao.insertMail(serverMail);
}
}
// private void clearOldPersonalMail() throws Exception {
// List<PersonalMail> personalMail = mailDao.getPMailList();
// for (PersonalMail mail : personalMail) {
// ServerMail serverMail = pTos(mail);
//
// mailDao.removePMail(mail.getId());
// mailDao.insertMail(serverMail);
// }
// }
/**
*
* @param personalMail
* @return
*/
private ServerMail pTos(PersonalMail personalMail){
ServerMail serverMail = new ServerMail();
serverMail.setId(personalMail.getId());
serverMail.setServerId(String.valueOf(personalMail.getServerId()));
serverMail.setMailTitle(personalMail.getMailTitle());
serverMail.setMailContent(personalMail.getMailContent());
serverMail.setIsAttach(personalMail.getIsAttach());
serverMail.setItemIds(personalMail.getItemIds());
serverMail.setItemNums(personalMail.getItemNums());
serverMail.setSendTime(personalMail.getSendTime());
serverMail.setVersion(personalMail.getVersion());
serverMail.setUserId(personalMail.getUserId());
serverMail.setCreateTime(personalMail.getCreateTime());
serverMail.setState(personalMail.getState());
serverMail.setCreateUser(personalMail.getCreateUser());
serverMail.setEffectTime(personalMail.getEffectTime());
serverMail.setType(PERSONAL_MAIL);
return serverMail;
}
// private ServerMail pTos(PersonalMail personalMail){
// ServerMail serverMail = new ServerMail();
// serverMail.setId(personalMail.getId());
// serverMail.setServerId(String.valueOf(personalMail.getServerId()));
// serverMail.setMailTitle(personalMail.getMailTitle());
// serverMail.setMailContent(personalMail.getMailContent());
// serverMail.setIsAttach(personalMail.getIsAttach());
// serverMail.setItemIds(personalMail.getItemIds());
// serverMail.setItemNums(personalMail.getItemNums());
// serverMail.setSendTime(personalMail.getSendTime());
// serverMail.setVersion(personalMail.getVersion());
// serverMail.setUserId(personalMail.getUserId());
// serverMail.setCreateTime(personalMail.getCreateTime());
// serverMail.setState(personalMail.getState());
// serverMail.setCreateUser(personalMail.getCreateUser());
// serverMail.setEffectTime(personalMail.getEffectTime());
// serverMail.setType(PERSONAL_MAIL);
//
// return serverMail;
// }
}

View File

@ -0,0 +1,24 @@
package com.jmfy.dao;
import com.jmfy.model.CHefuInfo;
import java.util.List;
/**
* @Author hj
* @Date 2023/5/18 11:02:05
* @Description:
* @Version 1.0
*/
public interface CHefuDao {
CHefuInfo findHefuById(int id) throws Exception;
CHefuInfo findHefuByServerID(int serverId) throws Exception;
void upsertHefuInfo(CHefuInfo hefuInfo) throws Exception;
void removeHefuInfo(CHefuInfo hefuInfo) throws Exception;
List<CHefuInfo> findHefuList() throws Exception;
}

View File

@ -0,0 +1,59 @@
package com.jmfy.dao.impl;
import com.jmfy.dao.CHefuDao;
import com.jmfy.model.CHefuInfo;
import com.jmfy.model.Constant;
import com.jmfy.utils.Connect;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
/**
* @Author hj
* @Date 2023/5/18 11:19:36
* @Description:
* @Version 1.0
*/
@Component
public class CHefuDaoImpl implements CHefuDao {
@Resource
private Connect connect;
public static final String dbName = Constant.dbName;
@Override
public CHefuInfo findHefuById(int id) throws Exception {
MongoTemplate mongoTemplate = connect.getMongoTemplete(dbName);
Query query = new Query(Criteria.where("_id").is(id));
return mongoTemplate.findOne(query, CHefuInfo.class);
}
@Override
public CHefuInfo findHefuByServerID(int serverId) throws Exception {
MongoTemplate mongoTemplate = connect.getMongoTemplete(dbName);
Query query = new Query(Criteria.where("serverId").is(serverId));
return mongoTemplate.findOne(query, CHefuInfo.class);
}
@Override
public void upsertHefuInfo(CHefuInfo hefuInfo) throws Exception {
MongoTemplate mongoTemplate = connect.getMongoTemplete(dbName);
mongoTemplate.insert(hefuInfo);
}
@Override
public void removeHefuInfo(CHefuInfo hefuInfo) throws Exception {
MongoTemplate mongoTemplate = connect.getMongoTemplete(dbName);
mongoTemplate.remove(hefuInfo);
}
@Override
public List<CHefuInfo> findHefuList() throws Exception {
MongoTemplate mongoTemplate = connect.getMongoTemplete(dbName);
return mongoTemplate.findAll(CHefuInfo.class);
}
}

View File

@ -15,7 +15,6 @@ import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
/**

View File

@ -114,7 +114,9 @@ public class MailDaoImpl implements MailDao {
@Override
public List<ServerMail> getMailList(int type) throws Exception {
MongoTemplate mongoTemplate = connect.getMongoTemplete(Constant.dbName);
Query query = new Query(Criteria.where("type").is(type));
Query query = new Query();
query.addCriteria(Criteria.where("type").is(type));
query.addCriteria(Criteria.where("isDel").ne(1));
return mongoTemplate.find(query,ServerMail.class);
}
@ -158,9 +160,10 @@ public class MailDaoImpl implements MailDao {
@Override
public void removePMail(int id) throws Exception {
MongoTemplate mongoTemplate = connect.getMongoTemplete(Constant.dbName);
Query query = new Query();
query.addCriteria(Criteria.where("_id").is(id));
mongoTemplate.remove(query, PersonalMail.class);
Query query = new Query(Criteria.where("_id").is(id));
Update update = new Update();
update.set("isDel",1);
mongoTemplate.updateMulti(query, update, ServerMail.class);
}
@Override

View File

@ -0,0 +1,279 @@
package com.jmfy.handler;
import com.jmfy.dao.CHefuDao;
import com.jmfy.dao.ServerInfoDao;
import com.jmfy.model.CHefuInfo;
import com.jmfy.model.ServerInfo;
import com.jmfy.utils.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Set;
/**
* @Author hj
* @Date 2023/5/11 10:28:41
* @Description:
* @Version 1.0
*/
@Component
public class HeFuManager {
private static final Logger LOGGER = LoggerFactory.getLogger(HeFuManager.class);
@Resource
private CHefuDao hefuDao;
@Resource
private ServerInfoDao serverInfoDao;
/**
* mongo
*/
@Value("${spring.data.gameMongodb.uri}")
private static String mongoClient;
private static String path = "/data/jieling/hefu/";
/**
* mongo
*/
private static String MONGO_BACKUPS_COMMAND = "mongodump --forceTableScan --host 10.0.0.176 --port 27017 -u rwuser -p Ysj666_777 --authenticationDatabase admin -d ysj_40001 -o ./";
/**
* mongo
*/
private static String MONGO_RESTORE_COMMAND = "mongorestore --host 10.0.0.176 --port 27017 -u rwuser -p Ysj666_777 --authenticationDatabase admin -d ysj_40001 ./";
public void hefu(String cmd) {
try {
String[] split = cmd.split("\\|");
int masterId = Integer.parseInt(split[1]);
String slave = split[2];
String[] strings = slave.split("#");
LOGGER.info("合服信息:{}",cmd);
// mongo连接信息
// String[] data = mongoData();
// String nowTime = getNowTime();
// LOGGER.info("mongo信息{},date:{}",data.toString(),nowTime);
//
// // 主服
// boolean script = merageScript(MONGO_BACKUPS_COMMAND, String.valueOf(masterId), data[0], data[1], data[2], data[3], path, nowTime);
// if (!script){
// LOGGER.error("备份主服中断:{}",masterId);
// throw new Exception("备份主服中断");
// }
// // 合服
// for (String s : strings) {
// boolean back = merageScript(MONGO_BACKUPS_COMMAND, s, data[0], data[1], data[2], data[3], path, nowTime);
// if (!back){
// LOGGER.error("备份从服中断:{}",s);
// throw new Exception("备份从服中断");
// }
// }
// for (String s : strings) {
// boolean restore = merageScript(MONGO_RESTORE_COMMAND, s, data[0], data[1], data[2], data[3], path, nowTime);
// if (!restore){
// LOGGER.error("导入中断:{}",s);
// throw new Exception("导入中断");
// }
// }
// 处理从服redis
for (String s : strings) {
int slaveId = Integer.parseInt(s);
dealRedis(masterId,slaveId);
}
ArrayList<Integer> list = new ArrayList<>();
for (String s : strings) {
int slaveId = Integer.parseInt(s);
list.add(slaveId);
upsertServerIpAndPort(masterId,slaveId);
}
// 合服信息入库
CHefuInfo hefuInfo = new CHefuInfo();
hefuInfo.setMasterServerId(masterId);
hefuInfo.setSlaveServerIds(list);
hefuDao.upsertHefuInfo(hefuInfo);
LOGGER.info("合服完成");
}catch (Exception e){
e.printStackTrace();
}
}
/**
*
*
* @return
*/
private static String getNowTime() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHH");
return sdf.format(new Date(System.currentTimeMillis()));
}
/**
*
* @param serverId
* @param mongodbHost
* @param mongoProt
* @param mongoUser
* @param mongoPaw
* @param mongoPath
* @param date
*/
public boolean merageScript(String script, String serverId, String mongodbHost, String mongoProt, String mongoUser, String mongoPaw, String mongoPath, String date){
String command = script.replace("10.0.0.176", mongodbHost)
.replace("27017", mongoProt)
.replace("rwuser", mongoUser)
.replace("Ysj666_777", mongoPaw)
.replace("ysj_40001", "jieling_" + serverId)
.replace("./", mongoPath + date + "/");
boolean isSuccess = exeShell(command);
if (isSuccess) {
LOGGER.info("mongoBackups==>exeShell:{}", command);
} else {
LOGGER.error("mongoBackups==>exeShell:{}", command);
}
return isSuccess;
}
/**
* shell
*
* @param command
*/
public static boolean exeShell(String command) {
Process process = null;
try {
process = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(
new InputStreamReader(
process.getInputStream()));
String data;
while ((data = reader.readLine()) != null) {
LOGGER.info("exeShell==>data={}", data);
}
int exitValue = process.waitFor();
if (exitValue != 0) {
return false;
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
public static String[] mongoData() {
//"mongodb://zhj:zhj666@60.1.1.22:27017/?authSource\u003dadmin"
String[] mongdData = mongoClient.split(":");
String user = mongdData[1].substring(2);
String[] hosts = mongdData[2].split("@");
String password = hosts[0];
String host = hosts[1];
String port = mongdData[3].split("/")[0];
String[] datas = new String[4];
datas[0] = host;
datas[1] = port;
datas[2] = user;
datas[3] = password;
return datas;
}
public void upsertServerIpAndPort(int masterSID, int slowSID) throws Exception {
LOGGER.info("开始处理IP和端口===========a{}b:{}",masterSID,slowSID);
ServerInfo masterServer = serverInfoDao.getServerInfo(String.valueOf(masterSID));
String ip = masterServer.getIp();
String port = masterServer.getPort();
ServerInfo slaveServer = serverInfoDao.getServerInfo(String.valueOf(slowSID));
slaveServer.setIp(ip);
slaveServer.setPort(port);
serverInfoDao.updateServerInfo(slaveServer);
}
public static final String colon = ":";
public static final String FORCE_CURR_RANK = "FORCE_CURR_RANK";//战力排行榜
public static final String MONSTER_ATTACK_RANK = "MONSTER_ATTACK_RANK";//心魔试炼排行榜
public static final String GUILD_FORCE_RANK = "GUILD_FORCE_RANK";//公会战力排行榜
public static final String SHAN_HE_SHE_JI_STAR_RANK = "SHAN_HE_SHE_JI_STAR_RANK";//山河社稷图星级排行榜
public static final String SHAN_HE_SHE_JI_CHAPTER_RANK = "SHAN_HE_SHE_JI_CHAPTER_RANK";//山河社稷图关卡进度排行榜
public static final String AREDEF_TEAM_FORCE_RANK = "AREDEF_TEAM_FORCE_RANK";//竞技场防御编队
public static final String FOUR_CHALLENGE_TIER_RANK = "FOUR_CHALLENGE_TIER_RANK";//四灵试炼排行榜
public static final String GUILD_CHALLENGE_RANK = "GUILD_CHALLENGE_RANK";//公会副本排行榜
public static final String ARENA_RANK = "ARENA_RANK";//竞技场排行榜
public boolean dealRedis(int masterSID, int slowSID){
LOGGER.info("开始处理排行榜===========a{}b:{}",masterSID,slowSID);
// 战力排行榜处理
defaultRankOfRedis(FORCE_CURR_RANK,masterSID,slowSID);
// 心魔试炼排行榜处理
defaultRankOfRedis(MONSTER_ATTACK_RANK,masterSID,slowSID);
// 公会战力排行榜处理
defaultRankOfRedis(GUILD_FORCE_RANK,masterSID,slowSID);
// 山河社稷图星级排行榜处理
defaultRankOfRedis(SHAN_HE_SHE_JI_STAR_RANK,masterSID,slowSID);
// 山河社稷图关卡等级排行榜处理
defaultRankOfRedis(SHAN_HE_SHE_JI_CHAPTER_RANK,masterSID,slowSID);
// 竞技场防御编队处理
defaultRankOfRedis(AREDEF_TEAM_FORCE_RANK,masterSID,slowSID);
// 四灵试炼排行榜处理
fourRankOfRedis(FOUR_CHALLENGE_TIER_RANK,masterSID,slowSID);
// 公会副本排行榜处理
deleteRankOfRedis(GUILD_CHALLENGE_RANK,masterSID);
// 竞技场排行榜处理
deleteRankOfRedis(ARENA_RANK,masterSID);
return true;
}
public void defaultRankOfRedis(String key, int masterSID, int slowSID){
try {
RedisUtil instence = RedisUtil.getInstence();
String masterChapterKey = masterSID + colon + key + colon;
String slowChapterKey = slowSID + colon + key + colon;
Set<ZSetOperations.TypedTuple<String>> chapterSet = instence.rangeWithScores(slowChapterKey, 0, -1);
instence.zsetAddAall(masterChapterKey,chapterSet);
}catch (Exception e){
LOGGER.error("排行榜合并报错key{}master{}slave{}",key,masterSID,slowSID);
e.printStackTrace();
}
}
public void fourRankOfRedis(String key, int masterSID, int slowSID){
RedisUtil instence = RedisUtil.getInstence();
for (int i = 1; i < 5; i++) {
try {
String masterChapterKey = masterSID + colon + key + colon + i;
String slowChapterKey = slowSID + colon + key + colon + i;
Set<ZSetOperations.TypedTuple<String>> chapterSet = instence.rangeWithScores(slowChapterKey, 0, -1);
instence.zsetAddAall(masterChapterKey,chapterSet);
}catch (Exception e){
LOGGER.error("四灵排行榜合并报错key{}master{}slave{}type{}",key,masterSID,slowSID,i);
e.printStackTrace();
}
}
}
public void deleteRankOfRedis(String key, int masterSID){
try {
RedisUtil instence = RedisUtil.getInstence();
String masterChapterKey = masterSID + colon + key + colon;
Set<String> dimKey = instence.getDimKey(masterChapterKey, -1);
for (String s : dimKey) {
instence.del(s);
}
}catch (Exception e){
LOGGER.error("排行榜删除报错key{}master{}",key,masterSID);
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,50 @@
package com.jmfy.model;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import java.util.List;
/**
* @Author hj
* @Date 2023/5/17 17:22:10
* @Description:
* @Version 1.0
*/
@Document(collection = "c_hefu_info")
public class CHefuInfo {
@Id
private int id;
@Field(value = "masterServerId")
private int masterServerId;
@Field(value = "slaveServerIds")
private List<Integer> slaveServerIds;
public int getMasterServerId() {
return masterServerId;
}
public void setMasterServerId(int masterServerId) {
this.masterServerId = masterServerId;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public List<Integer> getSlaveServerIds() {
return slaveServerIds;
}
public void setSlaveServerIds(List<Integer> slaveServerIds) {
this.slaveServerIds = slaveServerIds;
}
}

View File

@ -102,6 +102,12 @@ public class ServerMail {
@Field(value = "auditTime")
private String auditTime;
/**
*
*/
@Field(value = "isDel")
private int isDel;
/**************************************** setter and getter ******************************************/
public String getServerId() {
@ -255,4 +261,12 @@ public class ServerMail {
public void setAuditTime(String auditTime) {
this.auditTime = auditTime;
}
public int getIsDel() {
return isDel;
}
public void setIsDel(int isDel) {
this.isDel = isDel;
}
}

View File

@ -1,14 +1,10 @@
package com.jmfy.model.vo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
public class HeroManager {
private static final Logger LOGGER = LoggerFactory.getLogger(HeroManager.class);
/**
*
*/

View File

@ -49,7 +49,7 @@ public enum PowersEnum {
ADD_WHITELIST_ACCOUNT_HERO(409,"添加白名单账号英雄",400,0,"addHeroPage"),
GUILD_LIST_MANAGER(410,"公会列表管理",400,1,"initGuildList"),
GUILD_OPERATE_PERMISSIONS(411,"权限: 操作公会",400,1,""),
USER_INFO_QUERY1(412,"角色神将查询",400,0,"toGetHeroInfoPage"),
USER_INFO_QUERY1(412,"角色神将查询",400,1,"toGetHeroInfoPage"),
SEND_MAILS(413,"发送txt里的邮件",400,0,"toSendMailInfoPage"),
HERO_HOT_RANK(414, "英雄热度排行榜管理", 400,1,"findHeroHotRankInfo?subRank=0"),
/**
@ -136,7 +136,7 @@ public enum PowersEnum {
/**
*
*/
HEFU(1500,"合服",1500,1,""),
HEFU(1500,"合服",1500,0,""),
HEFU_MANAGER(1501,"合服",1500,1,"/html/hefu.html"),
;

View File

@ -6,14 +6,12 @@ import com.jmfy.redisProperties.RedisUserKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
@ -342,7 +340,39 @@ public class RedisUtil {
sleep(FAILED_SLEEP);
}
}
throw new RedisRunTimeException("redisGetKeys excepiton" + rkey);
LOGGER.error("redis命令zsetAddAall异常报错");
}
private Cursor<String> scan(String match, int count){
ScanOptions.ScanOptionsBuilder match1 = ScanOptions.scanOptions().match(match);
if(count!=-1) {
match1.count(count);
}
RedisSerializer<String> redisSerializer = (RedisSerializer<String>) redisObjectTemplate.getKeySerializer();
return (Cursor) redisObjectTemplate.executeWithStickyConnection((RedisCallback) redisConnection -> new ConvertingCursor<>(redisConnection.scan(match1.build()), redisSerializer::deserialize));
}
/**
* key
* @param key
* @param count
* @return
*/
public Set<String> getDimKey(String key, int count){
Set<String> keys = new HashSet<>();
long start = System.currentTimeMillis();
try {
Cursor<String> cursor = scan(key, count);
while (cursor.hasNext()){
//添加key
keys.add(cursor.next());
}
cursor.close();
} catch (IOException e) {
e.printStackTrace();
}
LOGGER.info("scan扫描共耗时{} ms ,key数量{},模糊key{}",System.currentTimeMillis()-start,keys.size(),key);
return keys;
}