xiatian 10 месяцев назад
Родитель
Сommit
acd8c43c54

+ 7 - 2
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/NoticeController.java

@@ -68,6 +68,9 @@ public class NoticeController extends ControllerSupport {
         infoQuery.setTitle(query.getTitle());
         infoQuery.setRootOrgId(accessUser.getRootOrgId());
         infoQuery.setUserId(accessUser.getUserId());
+        if(UserType.STUDENT.equals(accessUser.getUserType())) {
+        	noticeService.checkStudentNotice(accessUser.getRootOrgId(), accessUser.getUserId());
+        }
         PageInfo<NoticeInfo> pagedNoticeInfo = noticeService.getPagedNoticeList(curPage, pageSize,
                 infoQuery);
         return getPageInfoFrom(pagedNoticeInfo);
@@ -118,15 +121,17 @@ public class NoticeController extends ControllerSupport {
     @ApiOperation(value = "获取用户公告列表")
     public List<UserNoticeDomain> getUserNoticeList(UserNoticeDomainQuery query) {
         List<UserNoticeDomain> resultList = new ArrayList<>();
+        User user = this.getAccessUser();
         UserNoticeInfoQuery noticeQuery = getNoticeInfoQueryFrom(query);
-
+        if(UserType.STUDENT.equals(user.getUserType())) {
+        	noticeService.checkStudentNotice(user.getRootOrgId(), user.getUserId());
+        }
         List<UserNoticeInfo> noticeInfoList = noticeService.getNoticeList(noticeQuery);
 
         if (null != noticeInfoList && !noticeInfoList.isEmpty()) {
             resultList = getNoticeDomainListFrom(noticeInfoList);
         }
 
-        User user = this.getAccessUser();
         //在线数据打点 start
         if (UserType.STUDENT.equals(user.getUserType())) {
             //在线学生登录打点

+ 1 - 1
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/ExamStudentRepo.java

@@ -18,7 +18,7 @@ public interface ExamStudentRepo
 			QueryByExampleExecutor<ExamStudentEntity>,
 			JpaSpecificationExecutor<ExamStudentEntity> {
 
-	List<ExamStudentEntity> findByStudentId(Long examId);
+	List<ExamStudentEntity> findByStudentId(Long studentId);
 
 	List<ExamStudentEntity> findByIdIn(List<Long> ids);
 

+ 4 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/NoticeReceiverRuleRepo.java

@@ -12,6 +12,10 @@ import java.util.List;
 
 public interface NoticeReceiverRuleRepo extends JpaRepository<NoticeReceiverRuleEntity, Long>,
         QueryByExampleExecutor<NoticeReceiverRuleEntity>, JpaSpecificationExecutor<NoticeReceiverRuleEntity> {
+	
+    @Query(value=" select t.* from EC_E_NOTICE_RECEIVER_RULE t inner join EC_E_NOTICE f on t.notice_id=f.id "
+    +" where t.root_org_id=?1 and t.rule_type in('STUDENTS_OF_EXAM','ALL_STUDENTS_OF_ROOT_ORG') and f.notice_status='PUBLISHED' ",nativeQuery = true)
+    List<NoticeReceiverRuleEntity> findStudentNotice(Long rootOrgId);
 
     List<NoticeReceiverRuleEntity> findByRootOrgIdAndNoticeIdIn(Long rootOrgId,List<Long> noticeIdList);
 

+ 3 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/UserNoticeRepo.java

@@ -30,4 +30,7 @@ public interface UserNoticeRepo extends JpaRepository<UserNoticeEntity, Long>,
     @Modifying
     @Query(value = "update EC_E_USER_NOTICE set has_recalled = 1 where notice_id = ?1",nativeQuery = true)
     int updateNoticeRecalledStatus(Long noticeId);
+    
+    @Query(value = "select t.id from EC_E_USER_NOTICE t where t.notice_id = ?1 and t.user_type=?2 and t.user_id=?3 limit 1",nativeQuery = true)
+    Long getNotice(Long noticeId,String userType,Long userId);
 }

+ 2 - 1
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/NoticeService.java

@@ -7,7 +7,6 @@
 
 package cn.com.qmth.examcloud.core.examwork.service;
 
-import cn.com.qmth.examcloud.api.commons.enums.NoticeReceiverRuleType;
 import cn.com.qmth.examcloud.api.commons.enums.NoticeStatus;
 import cn.com.qmth.examcloud.api.commons.exchange.PageInfo;
 import cn.com.qmth.examcloud.api.commons.security.bean.UserType;
@@ -106,4 +105,6 @@ public interface NoticeService {
     void sendMsg(Long id);
 
     void recallMsg(Long id);
+
+	void checkStudentNotice(Long rootOrgId, Long studentId);
 }

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

@@ -24,6 +24,8 @@ import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import cn.com.qmth.examcloud.web.jpa.PageUtils;
 import com.mysql.cj.util.StringUtils;
+
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang.time.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Example;
@@ -71,6 +73,40 @@ public class NoticeServiceImpl implements NoticeService {
     @Autowired
     private ExamRepo examRepo;
 
+    
+    @Transactional
+    @Override
+    public void checkStudentNotice(Long rootOrgId,Long studentId) {
+    	List <NoticeReceiverRuleEntity> rs=noticeReceiverRuleRepo.findStudentNotice(rootOrgId);
+    	if(CollectionUtils.isEmpty(rs)) {
+    		return;
+    	}
+    	List <ExamStudentEntity> es=examStudentRepo.findByStudentId(studentId);
+    	Set<Long> examIds=new HashSet<>();
+    	for(ExamStudentEntity e:es) {
+    		examIds.add(e.getExamId());
+    	}
+    	List<UserNoticeEntity> adds=new ArrayList<>();
+    	for(NoticeReceiverRuleEntity r:rs) {
+    		if(NoticeReceiverRuleType.ALL_STUDENTS_OF_ROOT_ORG.equals(r.getRuleType())) {
+    			if (userNoticeRepo.getNotice(rootOrgId, UserType.STUDENT.name(), studentId)==null) {
+                    UserNoticeEntity userNotice = initUserNoticeEntity(rootOrgId, studentId, r.getNoticeId(),
+                    		UserType.STUDENT);
+                    adds.add(userNotice);
+                }
+    		}else if(NoticeReceiverRuleType.STUDENTS_OF_EXAM.equals(r.getRuleType())) {
+    			if(examIds.contains(Long.valueOf(r.getRuleValue()))) {
+    				UserNoticeEntity userNotice = initUserNoticeEntity(rootOrgId, studentId, r.getNoticeId(),
+                    		UserType.STUDENT);
+                    adds.add(userNotice);
+    			}
+    		}
+    	}
+    	if(adds.size()>0) {
+    		userNoticeRepo.saveAll(adds);
+    	}
+    }
+    
     @Override
     public List<UserNoticeInfo> getNoticeList(UserNoticeInfoQuery query) {
         List<UserNoticeInfo> resultList = new ArrayList<>();
@@ -314,7 +350,20 @@ public class NoticeServiceImpl implements NoticeService {
 
             Date date = new Date();
             entity.setPublishTime(date);
-            entity.setNoticeStatus(NoticeStatus.TO_BE_PUBLISHED);
+            List <NoticeReceiverRuleEntity> rs=getReceiverRuleList(entity.getRootOrgId(), entity.getId());
+            boolean spec=false;
+            for(NoticeReceiverRuleEntity r:rs) {
+            	if(NoticeReceiverRuleType.ALL_STUDENTS_OF_ROOT_ORG.equals(r.getRuleType())
+            			||NoticeReceiverRuleType.STUDENTS_OF_EXAM.equals(r.getRuleType())) {
+            		spec=true;
+            		break;
+            	}
+            }
+            if(spec) {
+            	entity.setNoticeStatus(NoticeStatus.PUBLISHED);
+            }else {
+            	entity.setNoticeStatus(NoticeStatus.TO_BE_PUBLISHED);
+            }
             entity.setUpdateTime(date);
             noticeRepo.save(entity);
         } else {