generated from root/miduo_server
批量补发邮件
parent
325caa8e94
commit
72b3f84ba5
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"version":0,
|
||||
"tables":"",
|
||||
"mailTitle":"系统邮件",
|
||||
"mailContent":"系统邮件"
|
||||
}
|
|
@ -5,10 +5,7 @@ import com.jmfy.controller.GlobalSysController;
|
|||
import com.jmfy.handler.BaseHandler;
|
||||
import com.jmfy.handler.ManagerManager;
|
||||
import com.jmfy.thrift.pool.ThriftPoolUtils;
|
||||
import com.jmfy.utils.FileCacheUtils;
|
||||
import com.jmfy.utils.MinuteTask;
|
||||
import com.jmfy.utils.MyStringRedisTemplate;
|
||||
import com.jmfy.utils.RedisUtil;
|
||||
import com.jmfy.utils.*;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
|
@ -45,7 +42,9 @@ public class Application extends SpringBootServletInitializer {
|
|||
handlerManager.addHandler(handler);
|
||||
}
|
||||
ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
|
||||
SHotFixManager sHotFixManager = configurableApplicationContext.getBean(SHotFixManager.class);
|
||||
MinuteTask minuteTask = configurableApplicationContext.getBean(MinuteTask.class);
|
||||
minuteTask.setsHotFixManager(sHotFixManager);
|
||||
scheduledExecutorService.scheduleWithFixedDelay(minuteTask,30,10, TimeUnit.SECONDS);
|
||||
FileCacheUtils.initData();
|
||||
// FileCacheUtils.initData();
|
||||
|
|
|
@ -34,5 +34,5 @@ public interface UserInfoDao {
|
|||
WhiteList findWhiteListInfo(String openId) throws Exception;
|
||||
|
||||
void delWhiteList(String openId) throws Exception;
|
||||
|
||||
CUserInfo findUserInfoById(String roleId) throws Exception ;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,10 @@ import java.util.List;
|
|||
public class UserInfoDaoImpl implements UserInfoDao {
|
||||
@Resource
|
||||
private Connect connect ;
|
||||
public static final String colon = ":";
|
||||
public static final String colon = "标题:每日礼包差额补偿\n" +
|
||||
"尊敬的道友:\n" +
|
||||
" 为了给各位道友带来更好的游戏体验,我们对游戏进行了一次更新,本次更新提升了每日礼包中的奖励内容,对于17号至今已购买过礼包的玩家,我们会对其中的差额进行补偿,具体补偿内容详见附件,烦请查收。祝各位道友修行愉快~\n" +
|
||||
" 如果您在修行中还遇到问题,可追踪我们官方Facebook:太初行,并进行留言,自有小妖为您解答。";
|
||||
String dbName =Constant.dbName;
|
||||
|
||||
@Override
|
||||
|
@ -33,6 +36,16 @@ public class UserInfoDaoImpl implements UserInfoDao {
|
|||
return mongoTemplate.find(query, CUserInfo.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CUserInfo findUserInfoById(String roleId) throws Exception {
|
||||
MongoTemplate mongoTemplate = connect.getMongoTemplete(dbName);
|
||||
Query query = new Query();
|
||||
Criteria cr = new Criteria();
|
||||
cr.andOperator(Criteria.where("_id").is(Integer.valueOf(roleId)));
|
||||
query.addCriteria(cr);
|
||||
return mongoTemplate.findOne(query, CUserInfo.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CUser findCuserInfo(int serverId ,int userId) throws Exception {
|
||||
CUser cUser = RedisUtil.getInstence().getObject(serverId + colon + RedisUserKey.CUser_Key,
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package com.jmfy.utils;
|
||||
|
||||
public class CFixMailVersion {
|
||||
|
||||
|
||||
private int version;
|
||||
private String tables;
|
||||
private String mailTitle;
|
||||
private String mailContent;
|
||||
|
||||
public CFixMailVersion(int version) {
|
||||
this.version = version;
|
||||
this.tables = "";
|
||||
this.mailTitle = "系统邮件";
|
||||
this.mailContent = "系统邮件";
|
||||
}
|
||||
|
||||
public CFixMailVersion(int version, String tables, String mailTitle, String mailContent) {
|
||||
this.version = version;
|
||||
this.tables = tables;
|
||||
this.mailTitle = mailTitle;
|
||||
this.mailContent = mailContent;
|
||||
}
|
||||
|
||||
public CFixMailVersion() {
|
||||
this.tables = "";
|
||||
this.mailTitle = "系统邮件";
|
||||
this.mailContent = "系统邮件";
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public String getTables() {
|
||||
return tables;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public void setTables(String tables) {
|
||||
this.tables = tables;
|
||||
}
|
||||
|
||||
public String getMailTitle() {
|
||||
return mailTitle;
|
||||
}
|
||||
|
||||
public void setMailTitle(String mailTitle) {
|
||||
this.mailTitle = mailTitle;
|
||||
}
|
||||
|
||||
public String getMailContent() {
|
||||
return mailContent;
|
||||
}
|
||||
|
||||
public void setMailContent(String mailContent) {
|
||||
this.mailContent = mailContent;
|
||||
}
|
||||
}
|
|
@ -21,9 +21,27 @@ public class MinuteTask implements Runnable {
|
|||
@Resource
|
||||
private ServerInfoDaoImpl serverInfoDao;
|
||||
|
||||
SHotFixManager sHotFixManager;
|
||||
|
||||
public SHotFixManager getsHotFixManager() {
|
||||
return sHotFixManager;
|
||||
}
|
||||
|
||||
public void setsHotFixManager(SHotFixManager sHotFixManager) {
|
||||
this.sHotFixManager = sHotFixManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
try {
|
||||
sHotFixManager.updateTablesWithTableNames();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
List<ServerInfo> serverInfos = serverInfoDao.getAllServerInfo();
|
||||
|
||||
SortedSet<ServerInfo> toStartMap = new TreeSet<>((o1, o2) ->
|
||||
|
|
|
@ -0,0 +1,176 @@
|
|||
package com.jmfy.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jmfy.dao.UserInfoDao;
|
||||
import com.jmfy.model.CUserInfo;
|
||||
import com.jmfy.model.MailPersonalCache;
|
||||
import com.jmfy.redisProperties.RedisUserKey;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Description: des
|
||||
* Author: zsx
|
||||
* CreateDate: 2020/9/23 19:41
|
||||
*/
|
||||
@Controller
|
||||
public class SHotFixManager {
|
||||
|
||||
private static String jsonPath;
|
||||
private static int currentDbVersion;
|
||||
@Resource
|
||||
private UserInfoDao userInfoDao;
|
||||
/**
|
||||
* 补发邮件规则
|
||||
* 补发名_补发原因_补发内容
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
|
||||
public void updateTablesWithTableNames() throws Exception {
|
||||
|
||||
if(null ==jsonPath){
|
||||
initJsonPath();
|
||||
}
|
||||
|
||||
String[] tableList = new String[0];
|
||||
|
||||
CFixMailVersion version = getJsonFilePathInJsonConf("fix_version.json", CFixMailVersion.class);
|
||||
if (version == null || version.getTables().isEmpty() || currentDbVersion >= version.getVersion()) { // 启动而不是热更
|
||||
return;
|
||||
}
|
||||
currentDbVersion = version.getVersion();
|
||||
//更新指定表
|
||||
tableList = version.getTables().split("\\|");
|
||||
|
||||
HashMap<Integer ,StringBuilder> roleId2reward= new HashMap<>();
|
||||
|
||||
//多个文件补充
|
||||
for (int i = 0; i <tableList.length ; i++) {
|
||||
String[] s = tableList[i].split("_");
|
||||
boolean b = s.length >=3;
|
||||
if(!b){
|
||||
continue;
|
||||
}
|
||||
//单个文件奖励循环补充
|
||||
StringBuilder reward = new StringBuilder();
|
||||
for (int j = 2; j < s.length; j++) {
|
||||
if(reward.length()!=0)
|
||||
reward.append("|");
|
||||
reward.append(s[j]);
|
||||
}
|
||||
|
||||
String path = getPath("conf", tableList[i] + ".txt");
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
System.out.println("file not find {}, do not find sheet with {} you need rebuild all sheet by gen sheet tool!"+path+tableList[i]);
|
||||
continue;
|
||||
}
|
||||
String line;
|
||||
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
String[] prarms = line.split("\\t");
|
||||
StringBuilder orDefault = roleId2reward.getOrDefault(Integer.valueOf(prarms[0]), new StringBuilder());
|
||||
|
||||
//单个文件奖励次数循环
|
||||
for (int j = 0; j <Integer.valueOf(prarms[1]) ; j++) {
|
||||
if(orDefault.length()!=0)
|
||||
orDefault.append("|");
|
||||
orDefault.append(reward);
|
||||
}
|
||||
roleId2reward.putIfAbsent(Integer.valueOf(prarms[0]),orDefault);
|
||||
}
|
||||
}
|
||||
file.renameTo(new File(path+"_hadfix"));
|
||||
}
|
||||
|
||||
try {
|
||||
long l = System.currentTimeMillis();
|
||||
roleId2reward.forEach((integer, stringBuilder) -> {
|
||||
System.out.println("integer = " + integer+stringBuilder);
|
||||
try {
|
||||
CUserInfo userInfoById = userInfoDao.findUserInfoById(integer.toString());
|
||||
if(null == userInfoById){
|
||||
return;
|
||||
}
|
||||
MailPersonalCache mailPersonalCache = new MailPersonalCache();
|
||||
mailPersonalCache.setTitle(version.getMailTitle());
|
||||
mailPersonalCache.setContent(version.getMailContent());
|
||||
mailPersonalCache.setReward(stringBuilder.toString());
|
||||
mailPersonalCache.setTime((int)(l/1000));
|
||||
RedisUtil.getInstence().putMapEntry(String.valueOf(userInfoById.getServerid()), RedisUserKey.READY_TO_USER_MAIL+RedisUserKey.Delimiter_colon,integer.toString(),mailPersonalCache,240);
|
||||
|
||||
}catch (Exception e){
|
||||
System.out.println("do fix send mail integer e = " + e+integer);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
}catch (Exception e){
|
||||
System.out.println("do fix send mail e = " + e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static <T> T getJsonFilePathInJsonConf(String fileName, Class<T> fileClass) {
|
||||
File file = new File(jsonPath + fileName);
|
||||
if (!file.exists()) {
|
||||
System.out.println("the {} is not exist"+fileName);
|
||||
return null;
|
||||
}
|
||||
try (InputStream in = new FileInputStream(file);) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
return mapper.readValue(in, fileClass);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void initJsonPath() {
|
||||
String osName = System.getProperty("os.name");
|
||||
jsonPath = "conf/";
|
||||
if (osName.matches("^(?i)Windows.*$")) {// Window 系统
|
||||
jsonPath = "conf/";
|
||||
}
|
||||
}
|
||||
|
||||
private static String getPath(String prefixDir, String... filePath) throws IOException {
|
||||
StringBuilder path = new StringBuilder();
|
||||
path.append(getRootPath()).append(prefixDir);
|
||||
for (String p : filePath) {
|
||||
path.append(File.separator).append(p);
|
||||
}
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
|
||||
public static String getRootPath() throws IOException {
|
||||
StringBuilder path = new StringBuilder();
|
||||
if (isWindows()) {// Window 系统
|
||||
path.append(new File(".").getCanonicalPath()).append(File.separator);
|
||||
}else {
|
||||
path.append("../");
|
||||
}
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
public static boolean isWindows() {
|
||||
String osName = System.getProperty("os.name");
|
||||
return osName.matches("^(?i)Windows.*$");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue