Przeglądaj źródła

微信会话内容存储获取优化

anderx 6 miesięcy temu
rodzic
commit
7bbe070766

+ 2 - 1
src/main/java/com/kede/common/dao/ChatMsgMapper.java

@@ -5,6 +5,7 @@ import com.kede.wechat.bo.InputgetUserMsg;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Pageable;
 
 
+import java.util.Date;
 import java.util.List;
 import java.util.List;
 
 
 /**
 /**
@@ -82,7 +83,7 @@ public interface ChatMsgMapper {
      */
      */
     int deleteById(Integer id);
     int deleteById(Integer id);
 
 
-    ChatMsg selectByMsgId(String msgid);
+    ChatMsg selectByMsgId(@Param("msgid") String msgid, @Param("date") Date date);
 
 
 
 
     List<ChatMsg> selectMsgById(@Param("userId") String userId, @Param("type") Integer type);
     List<ChatMsg> selectMsgById(@Param("userId") String userId, @Param("type") Integer type);

+ 3 - 0
src/main/java/com/kede/common/mapper/ChatMsgMapper.xml

@@ -250,6 +250,9 @@
         <include refid="ChatMsgAllSql"/>
         <include refid="ChatMsgAllSql"/>
         from chat_msg
         from chat_msg
         where msgid = #{id}
         where msgid = #{id}
+        <if test="date !=null">
+        and msgtime >= #{date}
+        </if>
     </select>
     </select>
     <select id="selectMsgById" resultMap="ChatMsgMap">
     <select id="selectMsgById" resultMap="ChatMsgMap">
         select
         select

+ 12 - 1
src/main/java/com/kede/common/utils/DateUtils.java

@@ -466,7 +466,18 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
 	{
 	{
 	return new SimpleDateFormat(ymd).parse(date);
 	return new SimpleDateFormat(ymd).parse(date);
 	}
 	}
-	
 
 
 
 
+	/**
+	 * 根据date获取i天前的日期
+	 * @param date
+	 * @param i
+	 * @return
+	 */
+    public static Date getDateBefore(Date date, int i) {
+		Calendar c = Calendar.getInstance();
+		c.setTime(date);
+		c.add(Calendar.DATE, -i);
+		return c.getTime();
+    }
 }
 }

+ 4 - 1
src/main/java/com/kede/wechat/service/impl/ConversationContentServiceImpl.java

@@ -152,7 +152,10 @@ public class ConversationContentServiceImpl extends BaseMybatisDao<ChatMsgUserMa
                     com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(str);
                     com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(str);
                     String msgtype = jsonObject.getString("msgtype");
                     String msgtype = jsonObject.getString("msgtype");
                     InputChatMsg chatMsg = new InputChatMsg(jsonObject);
                     InputChatMsg chatMsg = new InputChatMsg(jsonObject);
-                    ChatMsg chatMsg1 = chatMsgMapper.selectByMsgId(chatMsg.getMsgid());
+                    //获取五天前的时间
+                    Date date = DateUtils.getDateBefore(new Date(), 5);
+                    System.out.println(DateUtils.formatDate(date, "yyyy-MM-dd HH:mm:ss"));
+                    ChatMsg chatMsg1 = chatMsgMapper.selectByMsgId(chatMsg.getMsgid(),date);
                     if (chatMsg1 == null){
                     if (chatMsg1 == null){
                         //处理数据
                         //处理数据
                         pushSmgType(msgtype, jsonObject, sdk, chatMsg);
                         pushSmgType(msgtype, jsonObject, sdk, chatMsg);