Răsfoiți Sursa

1.修复通知唯一约束冲突的bug
2.去掉examRecordData表中的主外键约束
3.修改所有相关的引用

lideyin 5 ani în urmă
părinte
comite
5bec5b7fd4

+ 24 - 12
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/NoticeServiceImpl.java

@@ -25,6 +25,7 @@ import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import com.mysql.cj.util.StringUtils;
 import org.apache.commons.lang.time.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Example;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Sort;
@@ -236,7 +237,6 @@ public class NoticeServiceImpl implements NoticeService {
 
     @Override
     public List<NoticeRulePublishProgressEntity> getToBeDisposedNoticeRulePublishProgressList() {
-        List<NoticeRulePublishProgressEntity> resultList = null;
         List<NoticeEntity> publishingNoticeList = noticeRepo
                 .findByNoticeStatus(NoticeStatus.PUBLISHING);
         List<NoticeEntity> toBePublishedNoticeList = noticeRepo
@@ -250,10 +250,10 @@ public class NoticeServiceImpl implements NoticeService {
             noticeIdList.addAll(toBePublishedNoticeList.stream().map(p -> p.getId())
                     .collect(Collectors.toList()));
         }
-        if (!noticeIdList.isEmpty()) {
-            resultList = noticeRulePublishProgressRepo.findByNoticeIdIn(noticeIdList);
+        if (noticeIdList.isEmpty()) {
+            return null;
         }
-        return resultList;
+        return noticeRulePublishProgressRepo.findByNoticeIdIn(noticeIdList);
     }
 
     @Override
@@ -329,11 +329,27 @@ public class NoticeServiceImpl implements NoticeService {
         // 保存并更新发布状态为发布完成
         List<UserNoticeEntity> userNoticeList = new ArrayList<>();
         for (Long userId : limitStudentIdList) {
-            UserNoticeEntity userNotice = initUserNoticeEntity(rootOrgId, userId, noticeId,
-                    ruleType);
-            userNoticeList.add(userNotice);
+            //构建查询条件,判断当前用户是否已发过当前通知
+            UserNoticeEntity query = new UserNoticeEntity();
+            query.setUserId(userId);
+            query.setNoticeId(noticeId);
+            UserType userType = (ruleType == NoticeReceiverRuleType.STUDENTS_OF_EXAM
+                    || ruleType == NoticeReceiverRuleType.ALL_STUDENTS_OF_ROOT_ORG)
+                    ? UserType.STUDENT
+                    : UserType.COMMON;
+            query.setUserType(userType);
+            Example<UserNoticeEntity> queryExample = Example.of(query);
+
+            //如果用户未发过当前通知,则添加相当通知数据,否则跳过
+            if (!userNoticeRepo.exists(queryExample)){
+                UserNoticeEntity userNotice = initUserNoticeEntity(rootOrgId, userId, noticeId,
+                        userType);
+                userNoticeList.add(userNotice);
+            }
         }
         userNoticeRepo.saveAll(userNoticeList);
+
+        //更新通知通知进度的最大用户id
         rulePublishProgress.setMaxStudentId(maxUserId);
         noticeRulePublishProgressRepo.save(rulePublishProgress);
     }
@@ -453,11 +469,7 @@ public class NoticeServiceImpl implements NoticeService {
     }
 
     private UserNoticeEntity initUserNoticeEntity(Long rootOrgId, Long userId, Long noticeId,
-                                                  NoticeReceiverRuleType ruleType) {
-        UserType userType = (ruleType == NoticeReceiverRuleType.STUDENTS_OF_EXAM
-                || ruleType == NoticeReceiverRuleType.ALL_STUDENTS_OF_ROOT_ORG)
-                ? UserType.STUDENT
-                : UserType.COMMON;
+                                                  UserType userType) {
         UserNoticeEntity userNotice = new UserNoticeEntity();
         userNotice.setRootOrgId(rootOrgId);
         userNotice.setHasRead(false);