Procházet zdrojové kódy

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

anderx před 6 měsíci
rodič
revize
aa1914ae1b

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

@@ -1,6 +1,7 @@
 package com.kede.common.dao;
 
 import com.kede.common.model.ChatMsg;
+import com.kede.wechat.bo.InputgetUserMsg;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.data.domain.Pageable;
 
@@ -86,8 +87,8 @@ public interface ChatMsgMapper {
 
     List<ChatMsg> selectMsgById(@Param("userId") String userId, @Param("type") Integer type);
 
-    List<ChatMsg> selectByRoomId(String roomId);
+    List<ChatMsg> selectByRoomId(InputgetUserMsg in );
 
-    List<ChatMsg> selectByUserIdAndFoId(@Param("userId") String userId, @Param("foId") String foId);
+    List<ChatMsg> selectByUserIdAndFoId(InputgetUserMsg in );
 }
 

+ 51 - 0
src/main/java/com/kede/common/enums/WechatSmgTypeEnum.java

@@ -0,0 +1,51 @@
+package com.kede.common.enums;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public enum WechatSmgTypeEnum {
+    text("text","文字"),
+    link("link","链接"),
+    mixed("mixed","混合消息"),
+    sphfeed("sphfeed","视频号消息"),
+    file("file","文件"),
+    image("image","图片"),
+    video("video","视频"),
+    revoke("revoke","撤回消息"),
+    voice("voice","语音");
+    private String code;
+    private String desc;
+    private static Map<String,WechatSmgTypeEnum> status=new HashMap<String,WechatSmgTypeEnum>();
+    static{
+    	for(WechatSmgTypeEnum e:WechatSmgTypeEnum.values()){
+    		status.put(e.getCode(), e);
+    	}
+    }
+
+    private WechatSmgTypeEnum(String code, String desc) {
+        this.code = code;
+        this.desc = desc;
+    }
+
+    public static WechatSmgTypeEnum getField(String code){
+    	return status.get(code);
+    }
+
+
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getDesc() {
+        return desc;
+    }
+
+    public void setDesc(String desc) {
+        this.desc = desc;
+    }
+}

+ 1 - 1
src/main/java/com/kede/common/mapper/ChatMsgUserMapper.xml

@@ -156,7 +156,7 @@
                  left join chat_msg_user b on x.user_id=b.user_id
     </select>
     <select id="selectMyIdByRoom" resultType="com.kede.common.model.ChatMsgUser">
-        select x.roomid user_id,b.name
+        select x.roomid userId,b.name
         from (select roomid
               from chat_msg
               where from_id = #{userId} and type=1

+ 9 - 0
src/main/java/com/kede/common/model/ChatMsg.java

@@ -73,6 +73,15 @@ public class ChatMsg implements Serializable {
      */
     private Date createTime;
 
+    private String msgType;
+
+    public String getMsgType() {
+        return msgType;
+    }
+
+    public void setMsgType(String msgType) {
+        this.msgType = msgType;
+    }
 
     public Integer getId() {
         return id;

+ 2 - 1
src/main/java/com/kede/common/task/ConversationContentTask.java

@@ -30,7 +30,8 @@ public class ConversationContentTask {
     /**
      * 获取企业微信聊天记录
      */
-//    @Scheduled(cron = "0 0/5 * * * ?")
+    //每天下午五点执行
+    @Scheduled(cron = "0 0 17 * * ?")
     @RequestMapping(value ="/open/pushMsg", method = RequestMethod.GET)
     public void pushMsg() {
         long startTime = System.currentTimeMillis();

+ 18 - 0
src/main/java/com/kede/wechat/bo/InputgetUserMsg.java

@@ -6,6 +6,24 @@ public class InputgetUserMsg {
     private Integer msgType;
     private String foId;
     private String roomId;
+    private String startTime;
+    private String endTime;
+
+    public String getStartTime() {
+        return startTime;
+    }
+
+    public void setStartTime(String startTime) {
+        this.startTime = startTime;
+    }
+
+    public String getEndTime() {
+        return endTime;
+    }
+
+    public void setEndTime(String endTime) {
+        this.endTime = endTime;
+    }
 
     public Integer getMsgType() {
         return msgType;

+ 0 - 4
src/main/java/com/kede/wechat/controller/ConversationContentController.java

@@ -102,10 +102,6 @@ public class ConversationContentController extends BaseController {
             res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"用户ID"));
             return res;
         }
-        if (StringUtils.isNotEmpty(in.getUserId())&&StringUtils.isNotEmpty(in.getRoomId())){
-            res.getError().add(buildError("用户ID和群ID不能同时为空"));
-            return res;
-        }
         return res.data(conversationContentService.getMsgList(in));
     }
 }

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

@@ -1,6 +1,7 @@
 package com.kede.wechat.service.impl;
 
 import com.kede.common.dao.ChatMsgMapper;
+import com.kede.common.enums.WechatSmgTypeEnum;
 import com.kede.common.model.ChatMsg;
 import com.kede.common.model.ChatMsgUser;
 import com.kede.common.utils.DateUtils;
@@ -179,6 +180,7 @@ public class ConversationContentServiceImpl extends BaseMybatisDao<ChatMsgUserMa
             if (text!=null){
                 String content1 = text.getString("content");
                 chatMsg.setContent(pushCharset(content1));
+//                chatMsg.setContent(content1);
             }
         }else if (msgtype.equals("link"))
         {
@@ -595,15 +597,25 @@ public class ConversationContentServiceImpl extends BaseMybatisDao<ChatMsgUserMa
 
     @Override
     public Object getMsgList(InputgetUserMsg in) {
+        List<ChatMsg> chatMsgs=new ArrayList<>();
         if (StringUtils.isNotEmpty(in.getRoomId())){
-           return chatMsgMapper.selectByRoomId(in.getRoomId());
+            chatMsgs = chatMsgMapper.selectByRoomId(in);
         }else if (StringUtils.isNotEmpty(in.getUserId())&&StringUtils.isNotEmpty(in.getFoId())){
-            List<ChatMsg> chatMsgs = chatMsgMapper.selectByUserIdAndFoId(in.getUserId(), in.getFoId());
+             chatMsgs = chatMsgMapper.selectByUserIdAndFoId(in);
             //将list按时间先后排序
             chatMsgs.sort(Comparator.comparing(ChatMsg::getMsgtime));
-            return chatMsgs;
+
         }
-        return null;
+        for (ChatMsg e : chatMsgs) {
+            WechatSmgTypeEnum field = WechatSmgTypeEnum.getField(e.getMsgtype());
+            if (field==null){
+                e.setMsgType(e.getMsgtype());
+            }else {
+                String desc = field.getDesc();
+                e.setMsgType(desc);
+            }
+        }
+        return chatMsgs;
     }