Selaa lähdekoodia

优化群组不存在导致的业务逻辑的阻塞

zouxuan 4 vuotta sitten
vanhempi
commit
c05725e7c9

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/ImGroupService.java

@@ -20,7 +20,7 @@ public interface ImGroupService extends BaseService<Long, ImGroup> {
 	 * @param type 群类型
 	 * @return
 	 */
-	boolean create(Long id, Integer userId, String name, String introduce, String memo, String tags, String img, String type);
+	ImGroup create(Long id, Integer userId, String name, String introduce, String memo, String tags, String img, String type);
 
 	/**
 	 * 解散群组

+ 28 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ImGroupMemberServiceImpl.java

@@ -4,6 +4,11 @@ import java.util.*;
 import java.util.Map.Entry;
 import java.util.stream.Collectors;
 
+import com.ym.mec.biz.dal.dao.*;
+import com.ym.mec.biz.dal.entity.ClassGroup;
+import com.ym.mec.biz.dal.entity.MusicGroup;
+import com.ym.mec.biz.dal.enums.GroupType;
+import com.ym.mec.biz.service.ImGroupService;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -11,9 +16,6 @@ import org.springframework.transaction.annotation.Transactional;
 
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
-import com.ym.mec.biz.dal.dao.ImGroupDao;
-import com.ym.mec.biz.dal.dao.ImGroupMemberDao;
-import com.ym.mec.biz.dal.dao.TeacherDao;
 import com.ym.mec.biz.dal.entity.ImGroup;
 import com.ym.mec.biz.dal.entity.ImGroupMember;
 import com.ym.mec.biz.service.ImGroupMemberService;
@@ -35,9 +37,18 @@ public class ImGroupMemberServiceImpl extends BaseServiceImpl<Long, ImGroupMembe
 	private ImGroupDao imGroupDao;
 
 	@Autowired
+	private ImGroupService imGroupService;
+
+	@Autowired
 	private TeacherDao teacherDao;
 
 	@Autowired
+	private ClassGroupDao classGroupDao;
+
+	@Autowired
+	private MusicGroupDao musicGroupDao;
+
+	@Autowired
 	private ImFeignService imFeignService;
 	
 	@Autowired
@@ -53,7 +64,13 @@ public class ImGroupMemberServiceImpl extends BaseServiceImpl<Long, ImGroupMembe
 	public boolean join(Long imGroupId, Integer userId, String roleType, boolean isAdmin) {
 		ImGroup imGroup = imGroupDao.getLocked(imGroupId);
 		if (imGroup == null) {
-			throw new BizException("加入群组失败:群组[{}]不存在", imGroupId);
+			ClassGroup classGroup = classGroupDao.get(imGroupId.intValue());
+			String tags = classGroup.getName();
+			if(classGroup.getGroupType() == GroupType.MUSIC){
+				MusicGroup musicGroup = musicGroupDao.get(classGroup.getMusicGroupId());
+				tags = musicGroup.getName();
+			}
+			imGroup = imGroupService.create(imGroupId, null, classGroup.getName(), null, null, tags, null, classGroup.getGroupType().getCode());
 		}
 		//检查用户是否已存在
 		List<ImGroupMember> imGroupMemberList = imGroupMemberDao.queryByImGroupIdAndUserId(imGroupId.toString(), userId.toString());
@@ -97,7 +114,13 @@ public class ImGroupMemberServiceImpl extends BaseServiceImpl<Long, ImGroupMembe
 	public boolean join(Long imGroupId, Map<Integer, String> userRoleMap) {
 		ImGroup imGroup = imGroupDao.getLocked(imGroupId);
 		if (imGroup == null) {
-			throw new BizException("加入群组失败:群组[{}]不存在", imGroupId);
+			ClassGroup classGroup = classGroupDao.get(imGroupId.intValue());
+			String tags = classGroup.getName();
+			if(classGroup.getGroupType() == GroupType.MUSIC){
+				MusicGroup musicGroup = musicGroupDao.get(classGroup.getMusicGroupId());
+				tags = musicGroup.getName();
+			}
+			imGroup = imGroupService.create(imGroupId, null, classGroup.getName(), null, null, tags, null, classGroup.getGroupType().getCode());
 		}
 		//检查用户是否已存在
 		List<Integer> existUserIdList = imGroupMemberDao.queryByImGroupIdAndUserId(imGroupId.toString(), userRoleMap.keySet().stream().filter(Objects::nonNull).map(Objects::toString)

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

@@ -52,10 +52,10 @@ public class ImGroupServiceImpl extends BaseServiceImpl<Long, ImGroup> implement
 
 	@Override
 	@Transactional(rollbackFor = Exception.class)
-	public boolean create(Long id, Integer userId, String name, String introduce, String memo, String tags, String img, String type) {
+	public ImGroup create(Long id, Integer userId, String name, String introduce, String memo, String tags, String img, String type) {
 		ImGroup imGroup = imGroupDao.get(id);
 		if (imGroup != null) {
-			return true;
+			return imGroup;
 		}
 
 		imGroup = new ImGroup();
@@ -91,7 +91,7 @@ public class ImGroupServiceImpl extends BaseServiceImpl<Long, ImGroup> implement
 			imFeignService.groupCreate(new GroupModel(groupId, null, name));
 		}
 
-		return true;
+		return imGroup;
 	}
 
 	@Override