Browse Source

Merge branch 'feature/0803-im'

liujc 2 years ago
parent
commit
ea2b0c7926

+ 3 - 0
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/ImGroupController.java

@@ -35,6 +35,7 @@ import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
+import org.slf4j.Logger;
 
 /**
  * 即时通讯群组(ImGroup)表控制层
@@ -136,8 +137,10 @@ public class ImGroupController extends BaseController {
             info = imGroupService.getRongYunInfo(page,size);
             //IM导入
             imGroupService.importInfo(info);
+
             //为已导入数据更改标识
             imGroupService.updateStatus(info);
+
         }
     }
 

+ 10 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/entity/ImRoomMessage.java

@@ -49,6 +49,16 @@ public class ImRoomMessage extends BaseMessage {
     private String toChatroomId;
 
 
+    private String clientType;
+
+    public String getClientType() {
+        return clientType;
+    }
+
+    public void setClientType(String clientType) {
+        this.clientType = clientType;
+    }
+
     public String getServiceProvider() {
         return serviceProvider;
     }

+ 45 - 18
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/ImGroupServiceImpl.java

@@ -87,6 +87,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
 import java.io.*;
 import java.nio.charset.StandardCharsets;
 import java.io.*;
@@ -805,7 +807,11 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
                     list.add(body1);
                 } else if (i.getClassname().equals("RC:GIFMsg")) {
                     //GIf
-                    TencentRequest.MessageBody body1 = CustomerServiceBatchSendingServiceImpl.getTimImageElem(jsonObject.getString("remoteUrl"));
+                    String remoteUrl = jsonObject.getString("remoteUrl");
+                    int gifDataSize = jsonObject.getInteger("gifDataSize");
+                    int width = jsonObject.getInteger("width");
+                    int height = jsonObject.getInteger("height");
+                    TencentRequest.MessageBody body1 = getTimGifElem(remoteUrl,gifDataSize,width,height);
                     list.add(body1);
                 } else if (i.getClassname().equals("RC:HQVCMsg")){
                     //语音
@@ -827,17 +833,18 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
                     String size = jsonObject.getString("size");
                     int duration = jsonObject.getInteger("duration");
                     String content = jsonObject.getString("content");
+                    String name = jsonObject.getString("name");
                     TencentRequest.MessageBody body1 = null;
                     try {
-                        body1 = getTimVideoFileElem(sightUrl,size,duration,content);
+                        body1 = getTimVideoFileElem(sightUrl,size,duration,content,name);
                     } catch (IOException e) {
                         e.printStackTrace();
                     }
                     list.add(body1);
                 } else if(i.getClassname().equals("RC:LBSMsg")) {
                     //位置
-                    int latitude = jsonObject.getInteger("latitude");
-                    int longitude = jsonObject.getInteger("longitude");
+                    double latitude = jsonObject.getDouble("latitude");
+                    double longitude = jsonObject.getDouble("longitude");
                     String poi = jsonObject.getString("poi");
                     TencentRequest.MessageBody body1 = getTimLocationElem(latitude, longitude, poi);
                     list.add(body1);
@@ -952,17 +959,18 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
                     String size = jsonObject.getString("size");
                     int duration = jsonObject.getInteger("duration");
                     String content = jsonObject.getString("content");
+                    String name = jsonObject.getString("name");
                     TencentRequest.MessageBody body1 = null;
                     try {
-                        body1 = getTimVideoFileElem(sightUrl,size,duration,content);
+                        body1 = getTimVideoFileElem(sightUrl,size,duration,content,name);
                     } catch (IOException e) {
                         e.printStackTrace();
                     }
                     bodyList.add(body1);
                 } else if(i.getClassname().equals("RC:LBSMsg")) {
                     //位置
-                    int latitude = jsonObject.getInteger("latitude");
-                    int longitude = jsonObject.getInteger("longitude");
+                    double latitude = jsonObject.getDouble("latitude");
+                    double longitude = jsonObject.getDouble("longitude");
                     String poi = jsonObject.getString("poi");
                     TencentRequest.MessageBody body1 = getTimLocationElem(latitude, longitude, poi);
                     bodyList.add(body1);
@@ -1014,7 +1022,7 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
         // 腾讯云消息
         ImageUtil.ImageInfo imageReq = ImageUtil.ImageInfo.builder()
                 .imgUrl(remoteUr)
-                .suffix(remoteUr.substring(remoteUr.lastIndexOf(".") + 1))
+                .suffix("GIF")
                 .build();
 
         // 获取图片基本信息
@@ -1056,7 +1064,7 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
     }
 
     //构建位置请求体
-    private TencentRequest.MessageBody getTimLocationElem(int latitude, int longitude, String poi) {
+    private TencentRequest.MessageBody getTimLocationElem(double latitude, double longitude, String poi) {
         if (latitude == 0 && longitude == 0 &&  StringUtils.isEmpty(poi)) {
             return null;
         }
@@ -1072,7 +1080,7 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
     }
 
     //构建视频请求体
-    public  TencentRequest.MessageBody getTimVideoFileElem(String sightUrl, String size, int duration, String content) throws IOException {
+    public  TencentRequest.MessageBody getTimVideoFileElem(String sightUrl, String size, int duration, String content,String name) throws IOException {
         if (StringUtils.isEmpty(sightUrl) && StringUtils.isEmpty(sightUrl) && duration == 0) {
             return null;
         }
@@ -1089,19 +1097,38 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
         }
 
         //获取JDK8里的解码器Base64.Decoder,将base64字符串转为字节数组
-        byte[] bytes = Base64.getDecoder().decode(content);
+        //byte[] bytes = Base64.getDecoder().decode(content);
         //构建字节数组输入流
-        bais = new ByteArrayInputStream(bytes);
+        //bais = new ByteArrayInputStream(bytes);
+
+            //获取图片类型
+            String suffix = name.substring(name.lastIndexOf(".") + 1);
+            //获取JDK8里的解码器Base64.Decoder,将base64字符串转为字节数组
+            byte[] bytes = Base64.getDecoder().decode(content);
+            //构建字节数组输入流
+            bais = new ByteArrayInputStream(bytes);
+            //通过ImageIO把字节数组输入流转为BufferedImage
+            BufferedImage bufferedImage = ImageIO.read(bais);
+
+            //构建文件
+            File imageFile = new File(name);
+            //写入生成文件
+            ImageIO.write(bufferedImage, suffix, imageFile);
+
 
-        UploadReturnBean uploadReturnBean = uploadFileService.uploadFile(bais, format);
-        String url = uploadReturnBean.getUrl();
-        //BufferedImage read = ImageIO.read(bais);
 
 
 
+        UploadReturnBean uploadReturnBean = uploadFileService.uploadFile(bais, suffix);
+        String url = uploadReturnBean.getUrl();
+        /*BufferedImage read = ImageIO.read(bais);
+        int width = read.getWidth();
+        int height = read.getHeight();*/
+
+
         ImageUtil.ImageInfo imageReq = ImageUtil.ImageInfo.builder()
                 .imgUrl(url)
-                .suffix(format)
+                .suffix(suffix)
                 .build();
 
 
@@ -1114,8 +1141,8 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
         timVideoFileElem.setVideoDownloadFlag(2);
         timVideoFileElem.setThumbUrl(url);
         timVideoFileElem.setThumbUUID(imageReq.getMd5());
-        timVideoFileElem.setThumbWidth(imageReq.getWidth());
-        timVideoFileElem.setThumbHeight(imageReq.getHeight());
+        timVideoFileElem.setThumbWidth( bufferedImage.getWidth());
+        timVideoFileElem.setThumbHeight( bufferedImage.getHeight());
         timVideoFileElem.setThumbSize((imageReq.getSize().intValue()));
         timVideoFileElem.setThumbDownloadFlag(2);
         timVideoFileElem.setThumbFormat(format);

+ 20 - 18
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/LiveRoomServiceImpl.java

@@ -713,6 +713,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
         ImRoomMessage message = new ImRoomMessage();
         message.setFromUserId(speakerIdStr);
         message.setToChatroomId(roomUid);
+        message.setClientType(ClientEnum.TEACHER.getCode());
         message.setObjectName(ImRoomMessage.FORCED_OFFLINE);
         message.setContent(speakerIdStr);
         try {
@@ -873,21 +874,22 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
                     .update(roomMember);
 
             //向直播间发送当前在线人数消息
-            this.sendOnlineUserCount(roomUid, userId, onlineUserInfo.size());
+//            this.sendOnlineUserCount(roomUid, roomInfo.getSpeakerId(), onlineUserInfo.size());
             log.info("opsRoom>>>> looker userInfo: {}", userJsonStr);
-            //用户离开直播间发送退出房间消息给主讲人
-            ImRoomMessage message = new ImRoomMessage();
-            message.setFromUserId(userId.toString());
-            message.setToChatroomId(roomUid);
-            message.setObjectName(ImRoomMessage.LOOKER_LOGIN_OUT);
-            message.setContent(userId);
-            try {
-                this.publishRoomMessage(message);
-                log.info("opsRoom>>>> looker RC_CHATROOM_LEAVE : {}", userJsonStr);
-            } catch (Exception e) {
-                log.error("opsRoom>>>>  looker error RC_CHATROOM_LEAVE {}", e.getMessage());
-                log.error("opsRoom>>>>  looker error sendMessage {} : RC_CHATROOM_LEAVE : {}", message, userJsonStr);
-            }
+//            //用户离开直播间发送退出房间消息给主讲人
+//            ImRoomMessage message = new ImRoomMessage();
+//            message.setFromUserId(userId.toString());
+//            message.setToChatroomId(roomUid);
+//            message.setClientType(ClientEnum.STUDENT.getCode());
+//            message.setObjectName(ImRoomMessage.LOOKER_LOGIN_OUT);
+//            message.setContent(userId);
+//            try {
+//                this.publishRoomMessage(message);
+//                log.info("opsRoom>>>> looker RC_CHATROOM_LEAVE : {}", userJsonStr);
+//            } catch (Exception e) {
+//                log.error("opsRoom>>>>  looker error RC_CHATROOM_LEAVE {}", e.getMessage());
+//                log.error("opsRoom>>>>  looker error sendMessage {} : RC_CHATROOM_LEAVE : {}", message, userJsonStr);
+//            }
         });
 
     }
@@ -1133,6 +1135,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
         }
         ImRoomMessage message = new ImRoomMessage();
         message.setObjectName(ImRoomMessage.MEMBER_COUNT);
+        message.setClientType(ClientEnum.TEACHER.getCode());
         message.setToChatroomId(roomUid);
         HashMap<String, Integer> sendMap = new HashMap<>();
         sendMap.put("count", count);
@@ -1164,7 +1167,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
             // 发送用户信息
             messageUser = LiveRoomMessage.MessageUser
                     .builder()
-                    .sendUserId(sysUser.getId().toString())
+                    .sendUserId(imGroupService.getImUserId(message.getFromUserId(), message.getClientType()))
                     .sendUserName(sysUser.getUsername())
                     .avatarUrl(sysUser.getAvatar())
                     .build();
@@ -1172,14 +1175,13 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
 
         LiveRoomMessage.MessageContent messageContent = LiveRoomMessage.MessageContent
                 .builder()
-                .targetId(sysUser.getId().toString())
                 .sendUserInfo(messageUser)
                 .build();
 
         LiveRoomMessage build = LiveRoomMessage.builder()
                 .isIncludeSender(1)
                 .objectName(message.getObjectName())
-                .fromUserId(message.getFromUserId())
+                .fromUserId(imGroupService.getImUserId(message.getFromUserId(), message.getClientType()))
                 .toChatRoomId(message.getToChatroomId())
                 .content(messageContent)
                 .build();
@@ -2128,7 +2130,7 @@ public class LiveRoomServiceImpl extends ServiceImpl<LiveRoomDao, LiveRoom> impl
         onlineUserCache.fastPut(userId, userJsonStr);
         log.info("joinRoom>>>> userInfo: {}", userJsonStr);
         //向直播间发送当前在线人数消息
-        this.sendOnlineUserCount(roomUid, userId, onlineUserCache.size());
+//        this.sendOnlineUserCount(roomUid, userId, onlineUserCache.size());
         log.info("join sendOnlineUserCount>>>> param is null   roomUid: {}  fromUserId:{}  count:{}", roomUid, userId, onlineUserCache.size());
         log.info("joinRoom>>>> userInfo: {}", userJsonStr);
         //记录当前用户对应的房间uid

+ 11 - 3
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/ImHistoryMessageWrapper.java

@@ -1,5 +1,6 @@
 package com.yonge.cooleshow.biz.dal.wrapper;
 
+import com.alibaba.fastjson.annotation.JSONField;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -34,18 +35,23 @@ public class ImHistoryMessageWrapper {
     @ApiModel("ImHistoryMessage-iM文件")
     public static class TimFileElem {
 
+        @JSONField(name = "Url")
         @ApiModelProperty("文件下载地址,可通过该 URL 地址直接下载相应文件。")
         private String Url;
 
+        @JSONField(name = "UUID")
         @ApiModelProperty("文件的唯一标识,客户端用于索引文件的键值。")
         private String UUID;
 
+        @JSONField(name = "FileSize")
         @ApiModelProperty("文件数据大小,单位:字节。")
         private Integer FileSize;
 
+        @JSONField(name = "FileName")
         @ApiModelProperty("文件名称。")
         private String FileName;
 
+        @JSONField(name = "Download_Flag")
         @ApiModelProperty("文件下载方式标记。目前 Download_Flag 取值只能为2,表示可通过Url字段值的 URL 地址直接下载文件。")
         private Integer Download_Flag;
 
@@ -99,15 +105,17 @@ public class ImHistoryMessageWrapper {
     @Data
     @ApiModel("ImHistoryMessage-iM位置")
     public static class TimLocationElem {
-
+        @JSONField(name = "Desc")
         @ApiModelProperty("地理位置描述信息。")
         private String Desc;
 
+        @JSONField(name = "Latitude")
         @ApiModelProperty("纬度。")
-        private Integer Latitude;
+        private double Latitude;
 
+        @JSONField(name = "Longitude")
         @ApiModelProperty("经度。")
-        private Integer Longitude;
+        private double Longitude;
     }
 
     @Data

+ 1 - 1
cooleshow-user/user-biz/src/main/resources/config/mybatis/ImGroupMapper.xml

@@ -50,7 +50,7 @@
     </update>
     <update id="updateStatus">
         update im_history_message set status_ = 1
-        where msgUID in <foreach collection="info" open="(" close=")" separator="," item="info">
+        where msgUID_ in <foreach collection="info" open="(" close=")" separator="," item="info">
         #{info.msgUID}
     </foreach>
     </update>