Browse Source

实习动态, 发送消息控制

大数据与最优化研究所 7 months ago
parent
commit
c41097d7d6

+ 36 - 38
src/main/java/com/xjrsoft/module/teacher/service/impl/ClassInternshipDynamicServiceImpl.java

@@ -296,49 +296,47 @@ public class ClassInternshipDynamicServiceImpl extends MPJBaseServiceImpl<ClassI
         }
 
         // 发送通知
-        List<User> combinedList = new ArrayList<>();
-        if (ObjectUtils.isNotEmpty(dto.getRoleType()) && dto.getRoleType() == 1) {
-            // 找到班上所有的学生
-            MPJLambdaWrapper<User> stuMPJLambdaWrapper = new MPJLambdaWrapper<>();
-            stuMPJLambdaWrapper
-                    .distinct()
-                    .select(User::getId)
-                    .select(User.class, x -> VoToColumnUtil.fieldsToColumns(User.class).contains(x.getProperty()))
-                    .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, User::getId)
-                    .in(BaseStudentSchoolRoll::getClassId, dto.getClassIds());
-            List<User> stuList = userMapper.selectJoinList(User.class, stuMPJLambdaWrapper);
-
-            combinedList.addAll(stuList);
-        }
-
-        if (ObjectUtils.isNotEmpty(dto.getRoleType()) && dto.getRoleType() == 2) {
-            // 找到班上所有的学生的家长
-            MPJLambdaWrapper<User> parentMPJLambdaWrapper = new MPJLambdaWrapper<>();
-            parentMPJLambdaWrapper
-                    .distinct()
-                    .disableSubLogicDel()
-                    .select(User::getId).select(User.class, x -> VoToColumnUtil.fieldsToColumns(User.class).contains(x.getProperty()))
-                    .leftJoin(UserStudent.class, UserStudent::getUserId, User::getId)
-                    .leftJoin(WorkflowFormRelation.class, WorkflowFormRelation::getFormKeyValue, UserStudent::getId)
-                    .leftJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, User::getId)
-                    .eq(WorkflowFormRelation::getCurrentState, HistoricProcessInstance.STATE_COMPLETED)
-                    .in(BaseStudentSchoolRoll::getClassId, dto.getClassIds());
-            List<User> parentList = userMapper.selectJoinList(User.class, parentMPJLambdaWrapper);
-
-            // 合并两个列表,并根据 User 的 id 去重
-            combinedList = new ArrayList<>(Stream.concat(combinedList.stream(), parentList.stream())
-                    .collect(Collectors.toMap(
-                            User::getId, // 键:User 的 id
-                            user -> user, // 值:User 对象本身
-                            (existing, replacement) -> existing // 如果有重复的键,保留旧值(existing)
-                    ))
-                    .values());
+        Set<User> combinedUserSet = new LinkedHashSet<>();
+
+        // 找到班上所有的学生
+        MPJLambdaWrapper<User> stuMPJLambdaWrapper = new MPJLambdaWrapper<>();
+        stuMPJLambdaWrapper
+                .distinct()
+                .select(User::getId)
+                .select(User.class, x -> VoToColumnUtil.fieldsToColumns(User.class).contains(x.getProperty()))
+                .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, User::getId)
+                .in(BaseStudentSchoolRoll::getClassId, dto.getClassIds());
+        List<User> stuList = userMapper.selectJoinList(User.class, stuMPJLambdaWrapper);
+
+        // 找到班上所有的学生的家长
+        MPJLambdaWrapper<User> parentMPJLambdaWrapper = new MPJLambdaWrapper<>();
+        parentMPJLambdaWrapper
+                .distinct()
+                .disableSubLogicDel()
+                .select(User::getId).select(User.class, x -> VoToColumnUtil.fieldsToColumns(User.class).contains(x.getProperty()))
+                .leftJoin(UserStudent.class, UserStudent::getUserId, User::getId)
+                .leftJoin(WorkflowFormRelation.class, WorkflowFormRelation::getFormKeyValue, UserStudent::getId)
+                .leftJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, User::getId)
+                .eq(WorkflowFormRelation::getCurrentState, HistoricProcessInstance.STATE_COMPLETED)
+                .in(BaseStudentSchoolRoll::getClassId, dto.getClassIds());
+        List<User> parentList = userMapper.selectJoinList(User.class, parentMPJLambdaWrapper);
+
+        // 根据 roleType 添加对应的角色对象到集合中
+        if (ObjectUtils.isNotEmpty(dto.getRoleType())) {
+            int roleType = dto.getRoleType();
+
+            if (roleType == 1 || roleType == 3) {
+                combinedUserSet.addAll(stuList);
+            }
+            if (roleType == 2 || roleType == 3) {
+                combinedUserSet.addAll(parentList);
+            }
         }
 
         // 发布作业的教师
         User releaseUser = userMapper.selectById(loginId);
         try {
-            for (User user : combinedList) {
+            for (User user : combinedUserSet) {
                 WeChatSendMessageDto weChatSendMessageDto = new WeChatSendMessageDto();
                 weChatSendMessageDto.setUserId(user.getOpenId());
                 weChatSendMessageDto.setTemplateId("qmpXORPM1Cocqn503Qa4On6BJhR92UZ00eod2-6IcGo");