Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/feature/0803-im' into feature/0803-im

zouxuan 2 anni fa
parent
commit
2c7aa05e52

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

@@ -32,6 +32,7 @@ import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
+import org.slf4j.Logger;
 
 /**
  * 即时通讯群组(ImGroup)表控制层
@@ -151,8 +152,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;
     }

+ 2 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/UploadFileService.java

@@ -60,7 +60,8 @@ public class UploadFileService {
             return uploadReturn;
         }
 
-        String root = fileRoot;
+        String root = "d:";
+                //fileRoot;
         if (StringUtils.isBlank(root)) {
             uploadReturn.setMessage("上传临时目录没有配置");
             return uploadReturn;

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

@@ -60,7 +60,10 @@ 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.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.text.MessageFormat;
 import java.text.ParseException;
@@ -736,7 +739,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")){
                     //语音
@@ -758,17 +765,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);
@@ -883,17 +891,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);
@@ -945,7 +954,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();
 
         // 获取图片基本信息
@@ -987,7 +996,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;
         }
@@ -1003,7 +1012,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;
         }
@@ -1020,16 +1029,35 @@ 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, format, imageFile);*/
+
 
-        UploadReturnBean uploadReturnBean = uploadFileService.uploadFile(bais, format);
-        String url = uploadReturnBean.getUrl();
-        //BufferedImage read = ImageIO.read(bais);
 
 
 
+        UploadReturnBean uploadReturnBean = uploadFileService.uploadFile(bais, format);
+        String url = uploadReturnBean.getUrl();
+        URL url2 =  new URL(url);
+        BufferedImage read = ImageIO.read(url2);
+        int width = read.getWidth();
+        int height = read.getHeight();
+
         ImageUtil.ImageInfo imageReq = ImageUtil.ImageInfo.builder()
                 .imgUrl(url)
                 .suffix(format)
@@ -1045,9 +1073,9 @@ 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.setThumbSize((imageReq.getSize().intValue()));
+        timVideoFileElem.setThumbWidth( width);
+        timVideoFileElem.setThumbHeight( height);
+        //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

+ 24 - 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;
 
@@ -55,42 +61,55 @@ public class ImHistoryMessageWrapper {
     @ApiModel("ImHistoryMessage-iM视频")
     public static class TimVideoFileElem {
 
+        @JSONField(name = "VideoUrl")
         @ApiModelProperty("视频下载地址。可通过该 URL 地址直接下载相应视频。")
         private String VideoUrl;
 
+        @JSONField(name = "VideoUUID")
         @ApiModelProperty("文视频的唯一标识,客户端用于索引视频的键值。")
         private String VideoUUID;
 
+        @JSONField(name = "VideoSize")
         @ApiModelProperty("视频数据大小,单位:字节。")
         private Integer VideoSize;
 
+        @JSONField(name = "VideoSecond")
         @ApiModelProperty("视频时长,单位:秒。Web 端不支持获取视频时长,值为0")
         private Integer VideoSecond;
 
+        @JSONField(name = "VideoFormat")
         @ApiModelProperty("视频格式,例如 mp4")
         private String VideoFormat;
 
+        @JSONField(name = "VideoDownloadFlag")
         @ApiModelProperty("视频下载方式标记。目前 VideoDownloadFlag 取值只能为2,表示可通过 VideoUrl 字段值的 URL 地址直接下载视频。")
         private Integer VideoDownloadFlag;
 
+        @JSONField(name = "ThumbUrl")
         @ApiModelProperty("视频缩略图下载地址。可通过该 URL 地址直接下载相应视频缩略图。")
         private String ThumbUrl;
 
+        @JSONField(name = "ThumbUUID")
         @ApiModelProperty("视频缩略图的唯一标识,客户端用于索引视频缩略图的键值")
         private String ThumbUUID;
 
+        @JSONField(name = "ThumbSize")
         @ApiModelProperty("缩略图大小,单位:字节。")
         private Integer ThumbSize;
 
+        @JSONField(name = "ThumbWidth")
         @ApiModelProperty("缩略图宽度,单位为像素。")
         private Integer ThumbWidth;
 
+        @JSONField(name = "ThumbHeight")
         @ApiModelProperty("缩略图高度,单位为像素。")
         private Integer ThumbHeight;
 
+        @JSONField(name = "ThumbFormat")
         @ApiModelProperty("缩略图格式,例如 JPG、BMP 等。")
         private String ThumbFormat;
 
+        @JSONField(name = "ThumbDownloadFlag")
         @ApiModelProperty("视频缩略图下载方式标记。目前 ThumbDownloadFlag 取值只能为2,表示可通过 ThumbUrl 字段值的 URL 地址直接下载视频缩略图。")
         private Integer ThumbDownloadFlag;
     }
@@ -99,15 +118,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

@@ -66,7 +66,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>