back_recharge
parent
c7e522bae8
commit
afa595c7e0
|
@ -2,6 +2,22 @@ package com.ljsd.jieling.globals;
|
||||||
|
|
||||||
public interface Global {
|
public interface Global {
|
||||||
int SEND_CARD_COUNT = 50; // 每页发送卡牌个数
|
int SEND_CARD_COUNT = 50; // 每页发送卡牌个数
|
||||||
int SEND_ITEM_COUNT = 3; // 每页发送道具个数
|
int SEND_ITEM_COUNT = 200; // 每页发送道具个数
|
||||||
int SEND_EQUIP_COUNT = 50; // 每页发送装备个数
|
int SEND_EQUIP_COUNT = 50; // 每页发送装备个数
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//mail state
|
||||||
|
int MAIL_BOX_CAPACITY = 30; // 邮箱最大容量
|
||||||
|
int MAIL_STATE_NEW = 0; // 新增邮件 未读
|
||||||
|
int MAIL_STATE_READ = 1; // 已读取
|
||||||
|
int MAIL_DRAW_ST_UNGET = 2; // 附件未领取
|
||||||
|
int MAIL_DRAW_ST_GOT = 3; //附件已领取
|
||||||
|
//mail type
|
||||||
|
int MAIL_TYPE_SYS = 1; //系统邮件
|
||||||
|
int MAIL_TYPE_IDIP = 2; //idip 邮件
|
||||||
|
|
||||||
|
//sysMail state
|
||||||
|
int SYS_MAIL_STATE_NEW = 1; //未发布
|
||||||
|
int SYS_MAIL_STATE_LAUCHED = 2; // 已完成
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.ljsd.jieling.handler;
|
||||||
|
|
||||||
|
import com.ljsd.jieling.util.MailUtil;
|
||||||
|
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||||
|
import com.ljsd.jieling.network.session.ISession;
|
||||||
|
import com.ljsd.jieling.protocols.CommonProto;
|
||||||
|
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||||
|
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
||||||
|
import com.ljsd.jieling.util.MessageUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class GetAllMailHandler extends BaseHandler {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(GetAllMailHandler.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageTypeProto.MessageType getMessageCode() {
|
||||||
|
return MessageTypeProto.MessageType.GET_ALL_MAIL_INFO_REQUEST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(ISession iSession, PacketNetData netData) throws Exception {
|
||||||
|
int userId = netData.getUserId();
|
||||||
|
int token = netData.getToken();
|
||||||
|
int msgId = netData.getMsgId();
|
||||||
|
int msgIndex = netData.getIndex();
|
||||||
|
LOGGER.info("processMessage->uid={},token={},msgId={},msgIndex={}",
|
||||||
|
userId, token,msgId,msgIndex);
|
||||||
|
List<CommonProto.Mail> allUserMail = MailUtil.getInstance().getAllUserMail(userId);
|
||||||
|
PlayerInfoProto.GetAllMailInfoResponse getPlayerInfoResponse = PlayerInfoProto.GetAllMailInfoResponse.newBuilder()
|
||||||
|
.addAllMialList(allUserMail)
|
||||||
|
.build();
|
||||||
|
try {
|
||||||
|
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.GET_ALL_MAIL_INFO_RESPONSE_VALUE,getPlayerInfoResponse , true);
|
||||||
|
LOGGER.info("back to client!");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.ljsd.jieling.logic.dao;
|
||||||
|
|
||||||
|
import com.ljsd.common.mogodb.MongoBase;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
public class AutoIncrement extends MongoBase {
|
||||||
|
|
||||||
|
private String name ;
|
||||||
|
|
||||||
|
private int cnt;
|
||||||
|
|
||||||
|
public void setCnt(int cnt) throws Exception {
|
||||||
|
updateString("cnt", cnt);
|
||||||
|
this.cnt = cnt;
|
||||||
|
}
|
||||||
|
public AutoIncrement(String name){
|
||||||
|
this.name = name;
|
||||||
|
this.cnt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCnt() {
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.ljsd.jieling.logic.dao;
|
||||||
|
|
||||||
|
import com.ljsd.common.mogodb.MongoBase;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class AutoIncrementManager extends MongoBase {
|
||||||
|
private Map<String,AutoIncrement> autoIncrementMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public Map<String,AutoIncrement> getAutoIncrementMap() {
|
||||||
|
return autoIncrementMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAutoIncrement(AutoIncrement autoIncrement) throws Exception {
|
||||||
|
autoIncrement.init(getRoot(), getMongoKey() + ".autoIncrementMap." + autoIncrement.getName());
|
||||||
|
updateString("autoIncrementMap." + autoIncrement.getName(), autoIncrement);
|
||||||
|
autoIncrementMap.put(autoIncrement.getName(),autoIncrement);
|
||||||
|
}
|
||||||
|
public AutoIncrement getAutoIncrement(String key){
|
||||||
|
return autoIncrementMap.get(key);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ import com.ljsd.common.mogodb.MongoBase;
|
||||||
|
|
||||||
public class Mail extends MongoBase {
|
public class Mail extends MongoBase {
|
||||||
|
|
||||||
private int id ;
|
private String id ;
|
||||||
private int roleUid; //所属玩家的UID
|
private int roleUid; //所属玩家的UID
|
||||||
|
|
||||||
private int state;//0:未读 1:已读取 2: 未领取 3 已领取
|
private int state;//0:未读 1:已读取 2: 未领取 3 已领取
|
||||||
|
@ -17,7 +17,7 @@ public class Mail extends MongoBase {
|
||||||
|
|
||||||
private int sendTime; //发送时间
|
private int sendTime; //发送时间
|
||||||
|
|
||||||
private int effectiveTime;//有效时间()
|
private int effectiveTime;//有效时间(s) 0 永久有效
|
||||||
|
|
||||||
private String sendName;//发送者名字
|
private String sendName;//发送者名字
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ public class Mail extends MongoBase {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,18 +8,22 @@ import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class MailManager extends MongoBase {
|
public class MailManager extends MongoBase {
|
||||||
private Map<Integer, Mail> mailMap = new ConcurrentHashMap<>();
|
private Map<String, Mail> mailMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public Map<Integer, Mail> getMailMap() {
|
public Map<String, Mail> getMailMap() {
|
||||||
return mailMap;
|
return mailMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMailMap(Map<Integer, Mail> mailMap) {
|
|
||||||
this.mailMap = mailMap;
|
|
||||||
}
|
|
||||||
public void addMail(Mail mail) throws Exception {
|
public void addMail(Mail mail) throws Exception {
|
||||||
// mail.init(getRoot(), getMongoKey() + ".mailMap." + mail.getId());
|
mail.init(getRoot(), getMongoKey() + ".mailMap." + mail.getId());
|
||||||
// updateString("mailMap." + mail.getId(), mail);
|
updateString("mailMap." + mail.getId(), mail);
|
||||||
// mailMap.put(item.getItemId(), item);
|
mailMap.put(mail.getId(), mail);
|
||||||
|
}
|
||||||
|
public Mail getMail(String key) {
|
||||||
|
return mailMap.get(key);
|
||||||
|
}
|
||||||
|
public void removeMail(String key) {
|
||||||
|
mailMap.remove(key);
|
||||||
|
removeString(getMongoKey() + ".mailMap." + key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.ljsd.jieling.logic.dao;
|
||||||
|
|
||||||
|
import com.ljsd.common.mogodb.LjsdMongoTemplate;
|
||||||
|
import com.ljsd.common.mogodb.MongoRoot;
|
||||||
|
|
||||||
|
public class MailingSystem extends MongoRoot {
|
||||||
|
public static final String _COLLECTION_NAME = "mailingSystem";
|
||||||
|
private static LjsdMongoTemplate _myMongoDBPool;
|
||||||
|
private static SystemMailManager systemMailManager;
|
||||||
|
private static SysMailManager sysMailManager;
|
||||||
|
private static AutoIncrementManager cAutoIncrementManager;
|
||||||
|
@Override
|
||||||
|
public String getCollection() {
|
||||||
|
return _COLLECTION_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(LjsdMongoTemplate ljsdMongoTemplate){
|
||||||
|
_myMongoDBPool = ljsdMongoTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MailingSystem(){
|
||||||
|
systemMailManager = new SystemMailManager();
|
||||||
|
sysMailManager = new SysMailManager();
|
||||||
|
cAutoIncrementManager = new AutoIncrementManager();
|
||||||
|
|
||||||
|
//綁定关系
|
||||||
|
systemMailManager.init(this, "systemMailManager", false);
|
||||||
|
systemMailManager.init(this, "sysMailManager", false);
|
||||||
|
systemMailManager.init(this, "autoIncrementManager", false);
|
||||||
|
}
|
||||||
|
public static SystemMailManager getSystemMailManager() {
|
||||||
|
return systemMailManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SysMailManager getSysMailManager() {
|
||||||
|
return sysMailManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AutoIncrementManager getcAutoIncrementManager() {
|
||||||
|
return cAutoIncrementManager;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,111 @@
|
||||||
|
package com.ljsd.jieling.logic.dao;
|
||||||
|
|
||||||
|
|
||||||
|
import com.ljsd.common.mogodb.LjsdMongoTemplate;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class MailingSystemManager {
|
||||||
|
|
||||||
|
private static Map<Integer, User> userMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public static LjsdMongoTemplate ljsdMongoTemplate;
|
||||||
|
|
||||||
|
public static void init(ConfigurableApplicationContext configurableApplicationContext) {
|
||||||
|
ljsdMongoTemplate =configurableApplicationContext.getBean(LjsdMongoTemplate.class);
|
||||||
|
User.init(ljsdMongoTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addUser(User user) {
|
||||||
|
userMap.put(user._getIntId(), user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isUserExist(int uid) {
|
||||||
|
return userMap.containsKey(uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static User getUserForLogin(int uid) throws Exception {
|
||||||
|
User user = userMap.get(uid);
|
||||||
|
if (user == null) {
|
||||||
|
user = ljsdMongoTemplate.findById(User.getCollectionName(), Integer.toString(uid), User.class);
|
||||||
|
}
|
||||||
|
if (user == null) {
|
||||||
|
user = registerUser(uid);
|
||||||
|
}else{
|
||||||
|
refreshUserLoginInfo(user);
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void refreshUserLoginInfo(User user) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
public static User userLogin(int uid) throws Exception {
|
||||||
|
User user = ljsdMongoTemplate.findById(User.getCollectionName(), Integer.toString(uid), User.class);
|
||||||
|
if (user == null) {
|
||||||
|
user = registerUser(uid);
|
||||||
|
}else {
|
||||||
|
if (!MailingSystemManager.isUserExist(uid)){
|
||||||
|
MailingSystemManager.addUser(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static User registerUser(int uid) throws Exception {
|
||||||
|
User user = new User(uid,new PlayerManager(),new ItemManager(),new HeroManager(),new MapManager());
|
||||||
|
initPlayer(user);
|
||||||
|
MailingSystemManager.addUser(user);
|
||||||
|
ljsdMongoTemplate.save(user);
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initPlayer(User user) throws Exception {
|
||||||
|
PlayerManager playerManager = user.getPlayerInfoManager();
|
||||||
|
playerManager.setNickName("戒灵666");
|
||||||
|
playerManager.setLevel(1);
|
||||||
|
playerManager.setExp(0);
|
||||||
|
playerManager.setVipLevel(0);
|
||||||
|
playerManager.setFamilyId("12345");
|
||||||
|
playerManager.setHead("image_head_1");
|
||||||
|
playerManager.setGold(100000l);
|
||||||
|
playerManager.setGem(9999);
|
||||||
|
playerManager.setChargeGem(666);
|
||||||
|
|
||||||
|
ItemManager itemManager = user.getItemManager();
|
||||||
|
//TODO
|
||||||
|
HeroManager heroManager = user.getHeroManager();
|
||||||
|
//TODO
|
||||||
|
MapManager mapManager = user.getMapManager();
|
||||||
|
//TODO
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static User getUser(int uid) throws Exception {
|
||||||
|
User user = userMap.get(uid);
|
||||||
|
if (user != null) {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
user =ljsdMongoTemplate.findById(User.getCollectionName(), Integer.toString(uid), User.class);
|
||||||
|
if (user == null) {
|
||||||
|
throw new Exception("UserManager::getUser null exception");
|
||||||
|
}
|
||||||
|
MailingSystemManager.addUser(user);
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeUser(int uid) {
|
||||||
|
userMap.remove(uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getNewToken(int userId) {
|
||||||
|
|
||||||
|
return "33521";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.ljsd.jieling.logic.dao;
|
||||||
|
|
||||||
|
import com.ljsd.common.mogodb.MongoBase;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
public class SysMail extends MongoBase {
|
||||||
|
|
||||||
|
private String id ;
|
||||||
|
|
||||||
|
private int roleUid; //所属玩家的UID
|
||||||
|
|
||||||
|
private List<Integer> sysMailIds ; //领取过的系统邮件id
|
||||||
|
|
||||||
|
public void setSysMailIds(List<Integer> sysMailIds) throws Exception {
|
||||||
|
updateString("sysMailIds", sysMailIds);
|
||||||
|
this.sysMailIds = sysMailIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRoleUid() {
|
||||||
|
return roleUid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getSysMailIds() {
|
||||||
|
return sysMailIds;
|
||||||
|
}
|
||||||
|
public SysMail(int uid){
|
||||||
|
this.roleUid = uid;
|
||||||
|
this.sysMailIds = new CopyOnWriteArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.ljsd.jieling.logic.dao;
|
||||||
|
|
||||||
|
import com.ljsd.common.mogodb.MongoBase;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class SysMailManager extends MongoBase {
|
||||||
|
private Map<Integer,SysMail> sysMailMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public Map<Integer,SysMail> getSystemMailMap() {
|
||||||
|
return sysMailMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSystemMail(SysMail sysMail) throws Exception {
|
||||||
|
sysMail.init(getRoot(), getMongoKey() + ".sysMailMap." + sysMail.getRoleUid());
|
||||||
|
updateString("sysMailMap." + sysMail.getRoleUid(), sysMail);
|
||||||
|
sysMailMap.put(sysMail.getRoleUid(),sysMail);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeSystemMail(int key) {
|
||||||
|
sysMailMap.remove(key);
|
||||||
|
removeString(getMongoKey() + ".sysMailMap." + key);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
package com.ljsd.jieling.logic.dao;
|
||||||
|
|
||||||
|
import com.ljsd.common.mogodb.MongoBase;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SystemMail extends MongoBase {
|
||||||
|
|
||||||
|
private int id ;
|
||||||
|
private String title; //邮件标题
|
||||||
|
|
||||||
|
private String subTitle; //邮件副标题
|
||||||
|
|
||||||
|
private List<Integer> userList; //邮件发送列表 若为空,则全服发送
|
||||||
|
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
private long sendTime;
|
||||||
|
|
||||||
|
private String reward; //奖励
|
||||||
|
|
||||||
|
private int effectiveTime;
|
||||||
|
|
||||||
|
private String name; // 发送者
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户注册截止时间 0 : 所有用户时间
|
||||||
|
*/
|
||||||
|
private int registerEndTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 版本号以,分割,用于对指定版本前端发送邮件,为0则是全部版本
|
||||||
|
*/
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubTitle() {
|
||||||
|
return subTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getUserList() {
|
||||||
|
return userList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getSendTime() {
|
||||||
|
return sendTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReward() {
|
||||||
|
return reward;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEffectiveTime() {
|
||||||
|
return effectiveTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRegisterEndTime() {
|
||||||
|
return registerEndTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.ljsd.jieling.logic.dao;
|
||||||
|
|
||||||
|
import com.ljsd.common.mogodb.MongoBase;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class SystemMailManager extends MongoBase {
|
||||||
|
private Map<Integer,SystemMail> systemMailMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public Map<Integer,SystemMail> getSystemMailMap() {
|
||||||
|
return systemMailMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSystemMail(SystemMail systemMail) throws Exception {
|
||||||
|
systemMail.init(getRoot(), getMongoKey() + ".systemMailMap." + systemMail.getId());
|
||||||
|
updateString("systemMailMap." + systemMail.getId(), systemMail);
|
||||||
|
systemMailMap.put(systemMail.getId(),systemMail);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeSystemMail(int key) {
|
||||||
|
systemMailMap.remove(key);
|
||||||
|
removeString(getMongoKey() + ".systemMailMap." + key);
|
||||||
|
}
|
||||||
|
public String getName (){
|
||||||
|
return "systemMail";
|
||||||
|
}
|
||||||
|
}
|
|
@ -45,6 +45,21 @@ public class CBean2Proto {
|
||||||
.build();
|
.build();
|
||||||
return heroProto;
|
return heroProto;
|
||||||
}
|
}
|
||||||
|
public static CommonProto.Mail getMail(Mail mail){
|
||||||
|
CommonProto.Mail mailProto = CommonProto.Mail
|
||||||
|
.newBuilder()
|
||||||
|
.setMailId(mail.getId())
|
||||||
|
.setHead(mail.getHead())
|
||||||
|
.setContent(mail.getContent())
|
||||||
|
.setState(mail.getState())
|
||||||
|
.setMailItem(mail.getMailItem())
|
||||||
|
.setEffectiveTime(mail.getEffectiveTime())
|
||||||
|
.setSendTime(mail.getSendTime())
|
||||||
|
.setSendName(mail.getSendName())
|
||||||
|
.setMailType(mail.getMailType())
|
||||||
|
.build();
|
||||||
|
return mailProto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static List<String> getHeroEquip(List<Equip> equipList) {
|
private static List<String> getHeroEquip(List<Equip> equipList) {
|
||||||
|
@ -52,4 +67,6 @@ public class CBean2Proto {
|
||||||
return equips;
|
return equips;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
package com.ljsd.jieling.util;
|
||||||
|
|
||||||
|
import com.ljsd.jieling.globals.Global;
|
||||||
|
import com.ljsd.jieling.logic.dao.Mail;
|
||||||
|
import com.ljsd.jieling.logic.dao.MailManager;
|
||||||
|
import com.ljsd.jieling.logic.dao.User;
|
||||||
|
import com.ljsd.jieling.logic.dao.UserManager;
|
||||||
|
import com.ljsd.jieling.protocols.CommonProto;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
public class MailUtil {
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(MailUtil.class);
|
||||||
|
|
||||||
|
private MailUtil(){}
|
||||||
|
|
||||||
|
public static class Instance {
|
||||||
|
public final static MailUtil instance = new MailUtil();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MailUtil getInstance() {
|
||||||
|
return MailUtil.Instance.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户的所有邮件
|
||||||
|
* @param userId
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public List<CommonProto.Mail> getAllUserMail(int userId) throws Exception {
|
||||||
|
List<CommonProto.Mail> mailList = new CopyOnWriteArrayList<>();
|
||||||
|
User user = UserManager.getUser(userId);
|
||||||
|
MailManager mailManager = user.getMailManager();
|
||||||
|
Map<String, Mail> mailMap = mailManager.getMailMap();
|
||||||
|
getSystemMail(mailMap);
|
||||||
|
if (mailMap.size() ==0){
|
||||||
|
return mailList;
|
||||||
|
}
|
||||||
|
List<Mail> cMailList = new CopyOnWriteArrayList<>();
|
||||||
|
for (Map.Entry<String,Mail> entry :mailMap.entrySet()){
|
||||||
|
Mail cMail = entry.getValue();
|
||||||
|
int nowTime = (int)(TimeUtils.now()/1000);
|
||||||
|
if (cMail.getEffectiveTime() != 0 && (nowTime - cMail.getSendTime()) > cMail.getEffectiveTime()){
|
||||||
|
mailManager.removeMail(cMail.getId());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
cMailList.add(cMail);
|
||||||
|
}
|
||||||
|
//超过邮件上限, 删除时间最早的一封
|
||||||
|
if (cMailList.size() > Global.MAIL_BOX_CAPACITY){
|
||||||
|
Collections.sort(cMailList, Comparator.comparingInt(Mail::getSendTime));
|
||||||
|
for(int i = 0; i < (cMailList.size()-Global.MAIL_BOX_CAPACITY); i++){
|
||||||
|
cMailList.remove(0);
|
||||||
|
mailManager.removeMail(cMailList.get(0).getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getAllMailProtoList(cMailList,mailList);
|
||||||
|
return mailList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有系统邮件
|
||||||
|
* @param mailMap
|
||||||
|
*/
|
||||||
|
private void getSystemMail(Map<String, Mail> mailMap) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getAllMailProtoList(List<Mail> cMailList, List<CommonProto.Mail> mailList) {
|
||||||
|
for (Mail mail :cMailList){
|
||||||
|
mailList.add(CBean2Proto.getMail(mail));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -212,7 +212,7 @@ public class TimeUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static long now() {
|
public static long now() {
|
||||||
return System.currentTimeMillis();
|
return System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue