浏览代码

Merge branch 'test' of http://git.dayaedu.com/yonge/mec into test

zouxuan 2 年之前
父节点
当前提交
360387d677

+ 31 - 1
mec-application/src/main/java/com/ym/mec/student/controller/ImGroupController.java

@@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dto.ImUserFriendDto;
 import com.ym.mec.biz.dal.entity.ImGroup;
+import com.ym.mec.biz.dal.entity.ImGroupMemberPlus;
 import com.ym.mec.biz.dal.enums.im.ClientEnum;
 import com.ym.mec.biz.dal.page.ImGroupNoticeQueryInfo;
 import com.ym.mec.biz.service.*;
@@ -18,6 +19,7 @@ import io.swagger.annotations.ApiOperation;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -51,6 +53,9 @@ public class ImGroupController extends BaseController {
     @Autowired
     private ImGroupCoreService imGroupCoreService;
 
+    @Autowired
+    private ImGroupMemberPlusService imGroupMemberPlusService;
+
 	@ApiOperation("查询群列表")
 	@GetMapping(value = "/queryGroupList")
 	public Object queryGroupList(String search,String groupType) {
@@ -63,7 +68,19 @@ public class ImGroupController extends BaseController {
 		if (imGroupId.contains("S") || imGroupId.contains("I")){
 			imGroupId = imGroupId.substring(1);
 		}
-		ImGroup imGroup = imGroupService.get(imGroupId);
+        ImGroup imGroup = imGroupService.get(imGroupId);
+
+        if (imGroup == null) {
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
+        ImGroupMemberPlus admin = imGroupMemberPlusService.lambdaQuery()
+            .eq(ImGroupMemberPlus::getImGroupId, imGroup.getId())
+            .eq(ImGroupMemberPlus::getUserId, sysUserService.getUser().getId())
+            .last("limit 1").one();
+        if (admin == null) {
+            // 该用户不在该群,无权限查看,处理用户退出群后,查看历史消息校验
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
 		// 设置默认头像
 		if (Objects.nonNull(imGroup.getGroupType()) && StringUtils.isBlank(imGroup.getImg())) {
 			imGroup.setImg(imGroup.getGroupType().getAvatar());
@@ -80,6 +97,19 @@ public class ImGroupController extends BaseController {
 		if (imGroupId.contains("S") || imGroupId.contains("I")){
 			imGroupId = imGroupId.substring(1);
 		}
+        ImGroup imGroup = imGroupService.get(imGroupId);
+
+        if (imGroup == null) {
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
+        ImGroupMemberPlus admin = imGroupMemberPlusService.lambdaQuery()
+            .eq(ImGroupMemberPlus::getImGroupId, imGroup.getId())
+            .eq(ImGroupMemberPlus::getUserId, sysUserService.getUser().getId())
+            .last("limit 1").one();
+        if (admin == null) {
+            // 该用户不在该群,无权限查看,处理用户退出群后,查看历史消息校验
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
 		return succeed(imGroupService.get(imGroupId));
 	}
 

+ 32 - 5
mec-application/src/main/java/com/ym/mec/teacher/controller/ImGroupController.java

@@ -4,12 +4,10 @@ import com.google.common.collect.Lists;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dto.ImUserFriendDto;
 import com.ym.mec.biz.dal.entity.ImGroup;
+import com.ym.mec.biz.dal.entity.ImGroupMemberPlus;
 import com.ym.mec.biz.dal.enums.im.ClientEnum;
 import com.ym.mec.biz.dal.page.ImGroupNoticeQueryInfo;
-import com.ym.mec.biz.service.ImGroupNoticeService;
-import com.ym.mec.biz.service.ImGroupService;
-import com.ym.mec.biz.service.ImUserFriendService;
-import com.ym.mec.biz.service.SysUserService;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.vo.ImUserWrapper;
@@ -20,6 +18,7 @@ import io.swagger.annotations.ApiOperation;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -47,6 +46,9 @@ public class ImGroupController extends BaseController {
 	@Autowired
 	private SysUserService userLoginService;
 
+    @Autowired
+    private ImGroupMemberPlusService imGroupMemberPlusService;
+
 	@ApiOperation("查询群列表")
 	@GetMapping(value = "/queryGroupList")
 	public Object queryGroupList(String search,String groupType) {
@@ -69,7 +71,19 @@ public class ImGroupController extends BaseController {
 		if (imGroupId.contains("S") || imGroupId.contains("I")){
 			imGroupId = imGroupId.substring(1);
 		}
-		ImGroup imGroup = imGroupService.get(imGroupId);
+        ImGroup imGroup = imGroupService.get(imGroupId);
+
+        if (imGroup == null) {
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
+        ImGroupMemberPlus admin = imGroupMemberPlusService.lambdaQuery()
+            .eq(ImGroupMemberPlus::getImGroupId, imGroup.getId())
+            .eq(ImGroupMemberPlus::getUserId, userLoginService.getUser().getId())
+            .last("limit 1").one();
+        if (admin == null) {
+            // 该用户不在该群,无权限查看,处理用户退出群后,查看历史消息校验
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
 		// 设置默认头像
 		if (Objects.nonNull(imGroup.getGroupType()) && StringUtils.isBlank(imGroup.getImg())) {
 			imGroup.setImg(imGroup.getGroupType().getAvatar());
@@ -86,6 +100,19 @@ public class ImGroupController extends BaseController {
 		if (imGroupId.contains("S") || imGroupId.contains("I")){
 			imGroupId = imGroupId.substring(1);
 		}
+        ImGroup imGroup = imGroupService.get(imGroupId);
+
+        if (imGroup == null) {
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
+        ImGroupMemberPlus admin = imGroupMemberPlusService.lambdaQuery()
+            .eq(ImGroupMemberPlus::getImGroupId, imGroup.getId())
+            .eq(ImGroupMemberPlus::getUserId, userLoginService.getUser().getId())
+            .last("limit 1").one();
+        if (admin == null) {
+            // 该用户不在该群,无权限查看,处理用户退出群后,查看历史消息校验
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
 		return succeed(imGroupService.get(imGroupId));
 	}
 

+ 32 - 1
mec-application/src/main/java/com/ym/mec/web/controller/ImGroupController.java

@@ -7,6 +7,8 @@ import com.ym.mec.biz.dal.dto.ImGroupMemberDto;
 import com.ym.mec.biz.dal.dto.ImUserFriendDto;
 import com.ym.mec.biz.dal.dto.NameDto;
 import com.ym.mec.biz.dal.entity.ImGroup;
+import com.ym.mec.biz.dal.entity.ImGroupMember;
+import com.ym.mec.biz.dal.entity.ImGroupMemberPlus;
 import com.ym.mec.biz.dal.enums.im.ClientEnum;
 import com.ym.mec.biz.dal.page.ImGroupNoticeQueryInfo;
 import com.ym.mec.biz.dal.vo.ImGroupVo;
@@ -24,6 +26,7 @@ import io.swagger.annotations.ApiOperation;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.Arrays;
@@ -49,6 +52,9 @@ public class ImGroupController extends BaseController {
 	@Autowired
 	private ImGroupMemberService imGroupMemberService;
 
+    @Autowired
+    private ImGroupMemberPlusService imGroupMemberPlusService;
+
 	@Autowired
 	private ImGroupNoticeService imGroupNoticeService;
 
@@ -74,6 +80,18 @@ public class ImGroupController extends BaseController {
 			imGroupId = imGroupId.substring(1);
 		}
 		ImGroup imGroup = imGroupService.get(imGroupId);
+
+        if (imGroup == null) {
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
+        ImGroupMemberPlus admin = imGroupMemberPlusService.lambdaQuery()
+            .eq(ImGroupMemberPlus::getImGroupId, imGroup.getId())
+            .eq(ImGroupMemberPlus::getUserId, sysUserService.getUser().getId())
+            .last("limit 1").one();
+        if (admin == null) {
+            // 该用户不在该群,无权限查看,处理用户退出群后,查看历史消息校验
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
 		// 设置默认头像
 		if (Objects.nonNull(imGroup.getGroupType()) && StringUtils.isBlank(imGroup.getImg())) {
 			imGroup.setImg(imGroup.getGroupType().getAvatar());
@@ -90,7 +108,20 @@ public class ImGroupController extends BaseController {
 		if (imGroupId.contains("S") || imGroupId.contains("I")){
 			imGroupId = imGroupId.substring(1);
 		}
-		return succeed(imGroupService.get(imGroupId));
+        ImGroup imGroup = imGroupService.get(imGroupId);
+
+        if (imGroup == null) {
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
+        ImGroupMemberPlus admin = imGroupMemberPlusService.lambdaQuery()
+            .eq(ImGroupMemberPlus::getImGroupId, imGroup.getId())
+            .eq(ImGroupMemberPlus::getUserId, sysUserService.getUser().getId())
+            .last("limit 1").one();
+        if (admin == null) {
+            // 该用户不在该群,无权限查看,处理用户退出群后,查看历史消息校验
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
+		return succeed(imGroup);
 	}
 
 	@ApiOperation("修改群信息")

+ 54 - 48
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ImGroupServiceImpl.java

@@ -1547,61 +1547,67 @@ public class ImGroupServiceImpl extends BaseServiceImpl<String, ImGroup> impleme
     public void imToTencent(List<HistoryMessage> list) {
 
         for (HistoryMessage historyMessage : list) {
-            HistoryMessageTencent tencent = new HistoryMessageTencent();
-            tencent.setId(historyMessage.getMsgUID());
-            // 时间
-            String dateTime = historyMessage.getDateTime();
-            LocalDateTime ldt = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"));
-            // yyyyMMddHH
-            String date = ldt.format(DateTimeFormatter.ofPattern("yyyyMMddHH"));
-            tencent.setMsgTime(Long.parseLong(date));
-
-            List<TencentRequest.MessageBody> bodyList = new ArrayList<>();
-            JSONObject jsonObject = JSONObject.parseObject(historyMessage.getContent());
-            // 类型
-            if (historyMessage.getTargetType() == 1) {
-                tencent.setChatType("C2C");
-                tencent.setToAccount(historyMessage.getTargetId());
-                bodyList = getPrivateMessge(historyMessage,jsonObject);
-            } else if (historyMessage.getTargetType() == 3) {
-                tencent.setChatType("GROUP");
-                tencent.setGroupId(historyMessage.getGroupId());
-                bodyList = getGroupMessage(historyMessage,jsonObject);
-            } else {
+            try {
+                HistoryMessageTencent tencent = new HistoryMessageTencent();
+                tencent.setId(historyMessage.getMsgUID());
+                // 时间
+                String dateTime = historyMessage.getDateTime();
+                LocalDateTime ldt = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"));
+                // yyyyMMddHH
+                String date = ldt.format(DateTimeFormatter.ofPattern("yyyyMMddHH"));
+                tencent.setMsgTime(Long.parseLong(date));
+
+                List<TencentRequest.MessageBody> bodyList = new ArrayList<>();
+                JSONObject jsonObject = JSONObject.parseObject(historyMessage.getContent());
+                // 类型
+                if (historyMessage.getTargetType() == 1) {
+                    tencent.setChatType("C2C");
+                    tencent.setToAccount(historyMessage.getTargetId());
+                    bodyList = getPrivateMessge(historyMessage,jsonObject);
+                } else if (historyMessage.getTargetType() == 3) {
+                    tencent.setChatType("GROUP");
+                    tencent.setGroupId(historyMessage.getGroupId());
+                    bodyList = getGroupMessage(historyMessage,jsonObject);
+                } else {
+
+                    historyMessage.setSyncFlag(1);
+                    historyMessageService.updateSyncFlag(historyMessage.getMsgUID(),1);
+                    continue;
+                }
 
-                historyMessage.setSyncFlag(1);
-                historyMessageService.updateSyncFlag(historyMessage.getMsgUID(),1);
-                continue;
-            }
+                if (CollectionUtils.isEmpty(bodyList)) {
+
+                    historyMessage.setSyncFlag(1);
+                    historyMessageService.updateSyncFlag(historyMessage.getMsgUID(),1);
+                    continue;
+                }
+                bodyList = bodyList.stream().filter(Objects::nonNull).collect(Collectors.toList());
+                if (CollectionUtils.isEmpty(bodyList)) {
+                    historyMessage.setSyncFlag(1);
+                    historyMessageService.updateSyncFlag(historyMessage.getMsgUID(),1);
+                    continue;
+                }
+                // 发送人
+                tencent.setFromAccount(historyMessage.getFromUserId());
+                //类型
+                tencent.setAppService("MEC");
+                tencent.setMsgFromPlatform(historyMessage.getSource());
+                tencent.setMsgTimestamp(ldt.toInstant(ZoneId.systemDefault().getRules().getOffset(ldt)).toEpochMilli()/1000);
 
-            if (CollectionUtils.isEmpty(bodyList)) {
+                // 消息转换
+                tencent.setCloudCustomData(jsonObject.getString("extra"));
+                tencent.setMsgBody(JSON.toJSONString(bodyList));
+                tencent.setMsgBodyJson(JSON.parseObject(tencent.getMsgBody(), JSONArray.class));
+
+                historyMessageTencentService.insert(tencent);
 
                 historyMessage.setSyncFlag(1);
                 historyMessageService.updateSyncFlag(historyMessage.getMsgUID(),1);
-                continue;
-            }
-            bodyList = bodyList.stream().filter(Objects::nonNull).collect(Collectors.toList());
-            if (CollectionUtils.isEmpty(bodyList)) {
-                historyMessage.setSyncFlag(1);
+            } catch (Exception e) {
+                historyMessage.setSyncFlag(2);
                 historyMessageService.updateSyncFlag(historyMessage.getMsgUID(),1);
-                continue;
             }
-            // 发送人
-            tencent.setFromAccount(historyMessage.getFromUserId());
-            //类型
-            tencent.setAppService("MEC");
-            tencent.setMsgFromPlatform(historyMessage.getSource());
-            tencent.setMsgTimestamp(ldt.toInstant(ZoneId.systemDefault().getRules().getOffset(ldt)).toEpochMilli()/1000);
-
-            // 消息转换
-            tencent.setCloudCustomData(jsonObject.getString("extra"));
-            tencent.setMsgBody(JSON.toJSONString(bodyList));
-            tencent.setMsgBodyJson(JSON.parseObject(tencent.getMsgBody(), JSONArray.class));
-
-            historyMessageTencentService.insert(tencent);
-
-            historyMessage.setSyncFlag(1);
-            historyMessageService.updateSyncFlag(historyMessage.getMsgUID(),1);
+
         }
 
     }