diff --git a/src/main/java/com/jmfy/controller/ItemSendController.java b/src/main/java/com/jmfy/controller/ItemSendController.java index e0131ce..59c68ed 100644 --- a/src/main/java/com/jmfy/controller/ItemSendController.java +++ b/src/main/java/com/jmfy/controller/ItemSendController.java @@ -4,13 +4,14 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.jmfy.dto.CPayOrder; import com.jmfy.dto.CUserDao; +import com.jmfy.paramBean.CMail; import com.jmfy.paramBean.MailCache; import com.jmfy.paramBean.PaySdkEnum; import com.jmfy.redisProperties.RedisUserKey; import com.jmfy.util.JsonUtil; import com.jmfy.util.RedisUtil; import com.jmfy.util.ToolUtils; -import com.mongodb.util.JSON; +import com.jmfy.util.UUIDEnum; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,17 +20,15 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; -import java.io.IOException; import java.io.UnsupportedEncodingException; import java.lang.reflect.Type; import java.net.URLEncoder; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.util.HashMap; import java.util.Map; import java.util.TreeMap; +import java.util.concurrent.TimeUnit; @RestController public class ItemSendController { @@ -116,23 +115,22 @@ public class ItemSendController { public void sendMail(HashMap params) { String title = params.get("title"); String content = params.get("content"); - String serverId = params.get("sid"); String uid = params.get("roleid"); - - Gson gson = new Gson(); - Type type = new TypeToken>() {}.getType(); + int time = (int) (System.currentTimeMillis() / 1000); String props = params.get("props"); - Map item = gson.fromJson(props, type); + Gson gson = new Gson(); + Map item = gson.fromJson(props, Map.class); String reward = ToolUtils.getMailReward(item); + sendMailToRedis(Integer.parseInt(uid), title, content, reward, time, 2592000); + } - MailCache cache = new MailCache(); - cache.setTitle(title); - cache.setContent(content); - cache.setReward(reward); - cache.setTime((int)System.currentTimeMillis()/1000); - cache.setValidTime((int)(ToolUtils.ONE_DAY * 30 / 1000)); - LOGGER.info("返利邮件,标题:{},内容:{}, 奖励:{}, 服务器ID: {}, UID: {}", title, content, reward, serverId, uid); - RedisUtil.getInstence().putMapEntry(serverId, RedisUserKey.READY_TO_USER_MAIL, String.valueOf(uid), cache, 0); + public static void sendMailToRedis(int uid, String title, String content, String reward, int sendTime, int mailEffectiveTime){ + CMail mail = new CMail(uid,title,content,reward,sendTime, mailEffectiveTime,"rebate", 4); + String key = RedisUserKey.MAIL_REWARD_MARK + ":" + uid; + String timeKey = String.valueOf(System.currentTimeMillis() + UUIDEnum.MAIL.getValue()); + // 有新邮件就增加30天的有效时间 + RedisUtil.getInstence().putMapEntry(RedisUserKey.MAIL_REWARD_MARK, String.valueOf(uid), timeKey, mail, mailEffectiveTime); + LOGGER.info("redis返利邮件标记:key:{}, time:{}, mail:{}",key,timeKey,mail); } public boolean checkSignature(Map map) { diff --git a/src/main/java/com/jmfy/paramBean/CMail.java b/src/main/java/com/jmfy/paramBean/CMail.java new file mode 100644 index 0000000..dff0ba4 --- /dev/null +++ b/src/main/java/com/jmfy/paramBean/CMail.java @@ -0,0 +1,138 @@ +package com.jmfy.paramBean; + +import com.jmfy.util.ToolUtils; +import com.jmfy.util.UUIDEnum; + +public class CMail { + + private String id ; + + private int roleUid; //所属玩家的UID + + private int state;//0:未读 1:已读取 2: 未领取 3 已领取 + + private String head; //标题 + + private String content;//邮件内容 + + private String mailItem;//获取所有的附件 + + private int sendTime; //发送时间 + + private int effectiveTime;//有效时间(s) 0 永久有效 + + private String sendName;//发送者名字 + + private long noUseDeleteTime;//已读或已领取邮件删除时间 + + private int mailType; //邮件类型 1:系统邮件 2:idip 业务邮件 + + private int isTop;//0不置顶 1置顶 + + private int markType;//0无类型 1:站内信 + + + public CMail(){ + + } + + // 详细注释去游戏服mail类查询 + public CMail(int uid, String head, String content, String mailItem, int sendTime, int effectiveTime, String sendName, int mailType){ + this.id = ToolUtils.produceIdByModuleNew(UUIDEnum.MAIL, uid); + this.roleUid = uid; + this.state = 0; + this.head = head; + this.content = content; + this.mailItem = mailItem; + this.sendTime = sendTime; + this.effectiveTime = effectiveTime ; + this.sendName = sendName ; + this.mailType = mailType; + } + + public String getId() { + return id; + } + + public int getRoleUid() { + return roleUid; + } + + public int getState() { + return state; + } + + public String getHead() { + return head; + } + + public String getContent() { + return content; + } + + public String getMailItem() { + return mailItem; + } + + public int getSendTime() { + return sendTime; + } + + public int getEffectiveTime() { + return effectiveTime; + } + + public String getSendName() { + return sendName; + } + + public int getMailType() { + return mailType; + } + + public void setMailItem(String mailItem) { + this.mailItem = mailItem; + } + + public long getNoUseDeleteTime() { + return noUseDeleteTime; + } + public void setNoUseDeleteTime(long noUseDeleteTime) { + this.noUseDeleteTime = noUseDeleteTime; + } + + public int getIsTop() { + return isTop; + } + + public void setIsTop(int isTop) { + this.isTop = isTop; + } + + public int getMarkType() { + return markType; + } + + public void setMarkType(int markType) { + this.markType = markType; + } + + @Override + public String toString() { + return "Mail{" + + "id='" + id + '\'' + + ", roleUid=" + roleUid + + ", state=" + state + + ", head='" + head + '\'' + + ", content='" + content + '\'' + + ", mailItem='" + mailItem + '\'' + + ", sendTime=" + sendTime + + ", effectiveTime=" + effectiveTime + + ", sendName='" + sendName + '\'' + + ", noUseDeleteTime=" + noUseDeleteTime + + ", mailType=" + mailType + + ", isTop=" + isTop + + ", markType=" + markType + + '}'; + } +} diff --git a/src/main/java/com/jmfy/redisProperties/RedisUserKey.java b/src/main/java/com/jmfy/redisProperties/RedisUserKey.java index 5f135f8..bc4cf22 100644 --- a/src/main/java/com/jmfy/redisProperties/RedisUserKey.java +++ b/src/main/java/com/jmfy/redisProperties/RedisUserKey.java @@ -9,4 +9,7 @@ public class RedisUserKey { public final static String C_PAYORDER_MAP = "C_PAYORDER_MAP"; public static final String READY_TO_USER_MAIL = "READY_TO_USER_MAIL"; public static final String REBATES_ORDER = "rebates_order"; + public static final String UUID_KEY = "UUID_KEY";//唯一key + public static final String MAIL_REWARD_MARK = "MAIL_REWARD_MARK";// 邮件奖励 + } diff --git a/src/main/java/com/jmfy/util/RedisUtil.java b/src/main/java/com/jmfy/util/RedisUtil.java index 27225fa..add118f 100644 --- a/src/main/java/com/jmfy/util/RedisUtil.java +++ b/src/main/java/com/jmfy/util/RedisUtil.java @@ -232,7 +232,20 @@ public class RedisUtil { return null; } - + public long increment(String key) { + for (int i = 0; i < 3; i++) { + try { + return oldRedisObjectTemplate.opsForValue().increment(key, 1); + } catch (Exception e) { + try { + Thread.sleep(2); + } catch (InterruptedException ex) { + LOGGER.error("sleep->msg=null",e); + } + } + } + return -1; + } public void delHash(String type, int key, String mapId) { diff --git a/src/main/java/com/jmfy/util/ToolUtils.java b/src/main/java/com/jmfy/util/ToolUtils.java index 13351d1..eeea046 100644 --- a/src/main/java/com/jmfy/util/ToolUtils.java +++ b/src/main/java/com/jmfy/util/ToolUtils.java @@ -1,5 +1,8 @@ package com.jmfy.util; +import com.jmfy.paramBean.PaySdkEnum; +import com.jmfy.redisProperties.RedisUserKey; + import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; @@ -28,6 +31,15 @@ public class ToolUtils { return reward.toString(); } + public synchronized static String produceIdByModuleNew(UUIDEnum uuidEnum, int userId){ + StringBuilder stringBuffer = new StringBuilder(); + stringBuffer.append(userId); + stringBuffer.append(uuidEnum.getValue()); + stringBuffer.append(System.currentTimeMillis()); + stringBuffer.append(RedisUtil.getInstence().increment(RedisUserKey.UUID_KEY)); + return stringBuffer.toString(); + } + /** * 获取时间戳 */ diff --git a/src/main/java/com/jmfy/util/UUIDEnum.java b/src/main/java/com/jmfy/util/UUIDEnum.java new file mode 100644 index 0000000..4cc5804 --- /dev/null +++ b/src/main/java/com/jmfy/util/UUIDEnum.java @@ -0,0 +1,15 @@ +package com.jmfy.util; + +public enum UUIDEnum { + MAIL(101), + ; + + private final int value; + UUIDEnum(int value ){ + this.value = value; + } + + public int getValue() { + return value; + } +}