소스 검색

Merge branch 'feature/0803-im' of http://git.dayaedu.com/yonge/cooleshow into feature/0803-im

liujc 2 년 전
부모
커밋
4aecf1a427

+ 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);
+
         }
     }
 

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

@@ -60,6 +60,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.text.MessageFormat;
@@ -736,7 +738,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 +764,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 +890,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 +953,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 +995,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 +1011,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,19 +1028,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();
 
 
@@ -1045,8 +1072,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);

+ 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

@@ -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>