|
@@ -44,670 +44,652 @@ import java.util.stream.Collectors;
|
|
*/
|
|
*/
|
|
@Service("noticeService")
|
|
@Service("noticeService")
|
|
public class NoticeServiceImpl implements NoticeService {
|
|
public class NoticeServiceImpl implements NoticeService {
|
|
- @Autowired
|
|
|
|
- private NoticeRepo noticeRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private UserNoticeRepo userNoticeRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private NoticeRulePublishProgressRepo noticeRulePublishProgressRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private NoticeReceiverRuleRepo noticeReceiverRuleRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private ExamRepo examRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- MarkWorkCloudService markWorkCloudService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- ExamStudentRepo examStudentRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- UserCloudService userCloudService;
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public List<UserNoticeInfo> getNoticeList(UserNoticeInfoQuery query) {
|
|
|
|
- List<UserNoticeInfo> resultList = new ArrayList<>();
|
|
|
|
- List<UserNoticeEntity> userNoticeList;
|
|
|
|
- if (query.getHasRead() != null) {
|
|
|
|
- userNoticeList = userNoticeRepo
|
|
|
|
- .findByRootOrgIdAndUserTypeAndUserIdAndHasReadOrderByCreationTimeDesc(
|
|
|
|
- query.getRootOrgId(), query.getUserType(), query.getUserId(),
|
|
|
|
- query.getHasRead());
|
|
|
|
- } else {
|
|
|
|
- userNoticeList = userNoticeRepo
|
|
|
|
- .findByRootOrgIdAndUserTypeAndUserIdOrderByCreationTimeDesc(
|
|
|
|
- query.getRootOrgId(), query.getUserType(), query.getUserId());
|
|
|
|
- }
|
|
|
|
- if (null != userNoticeList && !userNoticeList.isEmpty()) {
|
|
|
|
- List<Long> noticeIdList = userNoticeList.stream().map(UserNoticeEntity::getNoticeId)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- List<NoticeEntity> noticeList = noticeRepo.findByIdIn(noticeIdList);
|
|
|
|
- for (UserNoticeEntity un : userNoticeList) {
|
|
|
|
- NoticeEntity noticeEntity = getNoticeById(noticeList, un.getNoticeId());
|
|
|
|
- if (noticeEntity == null) {
|
|
|
|
- throw new StatusException("501005", "找不到id为:" + un.getNoticeId() + "的通知");
|
|
|
|
- }
|
|
|
|
- UserNoticeInfo info = new UserNoticeInfo();
|
|
|
|
- info.setId(noticeEntity.getId());
|
|
|
|
- info.setTitle(noticeEntity.getTitle());
|
|
|
|
- info.setContent(noticeEntity.getContent());
|
|
|
|
- info.setPublisher(noticeEntity.getPublisher());
|
|
|
|
- info.setPublishTime(noticeEntity.getPublishTime());
|
|
|
|
- info.setHasRead(un.getHasRead());
|
|
|
|
- resultList.add(info);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return resultList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public int updateNoticeReadStatus(String noticeId, UserType userType, Long userId) {
|
|
|
|
- List<Long> noticeIdList;
|
|
|
|
- if (noticeId.contains(",")) {
|
|
|
|
- noticeIdList = Arrays.asList(noticeId.split(",")).stream().map(p -> Long.parseLong(p))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- } else {
|
|
|
|
- noticeIdList = Arrays.asList(noticeId).stream().map(p -> Long.parseLong(p))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- }
|
|
|
|
- return userNoticeRepo.updateNoticeReadStatus(noticeIdList, userType.toString(), userId);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public PageInfo<NoticeInfo> getPagedNoticeList(Integer curPage, Integer pageSize,
|
|
|
|
- NoticeInfoQuery infoQuery) {
|
|
|
|
- List<NoticeInfo> resultList = new ArrayList<>();
|
|
|
|
- Long rootOrgId = infoQuery.getRootOrgId();
|
|
|
|
- Specification<NoticeEntity> specification = (root, query, cb) -> {
|
|
|
|
- List<Predicate> predicates = new ArrayList<>();
|
|
|
|
- predicates.add(cb.equal(root.get("rootOrgId"), rootOrgId));
|
|
|
|
- if (!StringUtils.isNullOrEmpty(infoQuery.getTitle())) {
|
|
|
|
- predicates.add(cb.like(root.get("title"),
|
|
|
|
- DBUtil.toSqlSearchPattern(infoQuery.getTitle())));
|
|
|
|
- }
|
|
|
|
- if (null != infoQuery.getPublishStatus()) {
|
|
|
|
- predicates.add(cb.equal(root.get("noticeStatus"), infoQuery.getPublishStatus()));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
|
- };
|
|
|
|
- PageRequest pageRequest = PageRequest.of(curPage, pageSize,
|
|
|
|
- new Sort(Sort.Direction.DESC, "creationTime"));
|
|
|
|
- Page<NoticeEntity> pagedNoticeEntityList = noticeRepo.findAll(specification, pageRequest);
|
|
|
|
- List<Long> noticeIdList = pagedNoticeEntityList.stream().map(p -> p.getId())
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- List<NoticeReceiverRuleEntity> ruleList = getReceiverRuleList(rootOrgId,
|
|
|
|
- noticeIdList.toArray(new Long[noticeIdList.size()]));
|
|
|
|
-
|
|
|
|
- for (NoticeEntity ne : pagedNoticeEntityList) {
|
|
|
|
- NoticeReceiverRuleType ruleType = getNoticeReceiverRuleType(ne.getId(), ruleList);
|
|
|
|
- NoticeInfo ni = new NoticeInfo();
|
|
|
|
- ni.setId(ne.getId());
|
|
|
|
- ni.setPublisher(ne.getPublisher());
|
|
|
|
- ni.setPublishTime(ne.getPublishTime());
|
|
|
|
- ni.setTitle(ne.getTitle());
|
|
|
|
- ni.setContent(ne.getContent());
|
|
|
|
- ni.setPublishObject(getPublishObject(rootOrgId, ruleType, ruleList));
|
|
|
|
- ni.setPublishStatus(ne.getNoticeStatus());
|
|
|
|
- ni.setRuleType(ruleType);
|
|
|
|
- resultList.add(ni);
|
|
|
|
- }
|
|
|
|
- return new PageInfo<>(pagedNoticeEntityList, resultList);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Transactional
|
|
|
|
- @Override
|
|
|
|
- public int deleteNotice(Long rootOrgId, List<Long> noticeIdList) {
|
|
|
|
- int result = 0;
|
|
|
|
- // 删除通知进度相关信息
|
|
|
|
- result += noticeRulePublishProgressRepo.deleteByRootOrgIdAndNoticeIdIn(rootOrgId,
|
|
|
|
- noticeIdList);
|
|
|
|
- // 删除通知规则相关信息
|
|
|
|
- result += noticeReceiverRuleRepo.deleteByRootOrgIdAndNoticeIdIn(rootOrgId, noticeIdList);
|
|
|
|
- // 删除通知相关信息
|
|
|
|
- result += noticeRepo.deleteByIdIn(noticeIdList);
|
|
|
|
- return result;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Transactional
|
|
|
|
- @Override
|
|
|
|
- public int addNotice(AddNoticeInfo addNoticeInfo) {
|
|
|
|
- // 保存公告基本信息
|
|
|
|
- NoticeEntity noticeEntity = getNoticeEntityFrom(addNoticeInfo);
|
|
|
|
- NoticeEntity savedNotice = noticeRepo.save(noticeEntity);
|
|
|
|
-
|
|
|
|
- Long noticeId = savedNotice.getId();
|
|
|
|
-
|
|
|
|
- // 保存公告接收规则
|
|
|
|
- List<NoticeReceiverRuleEntity> ruleList = getNoticeReceiverRuleEntityListFrom(addNoticeInfo,
|
|
|
|
- noticeId);
|
|
|
|
- noticeReceiverRuleRepo.saveAll(ruleList);
|
|
|
|
-
|
|
|
|
- // 保存公告发布进度
|
|
|
|
- NoticeRulePublishProgressEntity publishScheduleEntity = getNoticeRulePublishProgressEntityFrom(
|
|
|
|
- addNoticeInfo, noticeId);
|
|
|
|
- noticeRulePublishProgressRepo.save(publishScheduleEntity);
|
|
|
|
-
|
|
|
|
- return noticeId > 0 ? 1 : 0;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Transactional
|
|
|
|
- @Override
|
|
|
|
- public NoticeRulePublishProgressEntity updateNotice(UpdateNoticeInfo info) {
|
|
|
|
- Long rootOrgId = info.getRootOrgId();
|
|
|
|
- List<Long> noticeIdList = Collections.singletonList(info.getId());
|
|
|
|
- // 校验通知状态,正在发送的通知不允许修改
|
|
|
|
- NoticeEntity originalNotice = GlobalHelper.getEntity(noticeRepo, info.getId(),
|
|
|
|
- NoticeEntity.class);
|
|
|
|
- if (originalNotice == null) {
|
|
|
|
- throw new StatusException("501006", "找不到通知id为:" + info.getId() + "的数据");
|
|
|
|
- }
|
|
|
|
- if (originalNotice.getNoticeStatus() != NoticeStatus.DRAFT) {
|
|
|
|
- throw new StatusException("501008", "发布中或已发布的通知不允许修改");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 更新通知表
|
|
|
|
-
|
|
|
|
- originalNotice.setTitle(info.getTitle());
|
|
|
|
- originalNotice.setPublisher(info.getPublisher());
|
|
|
|
- originalNotice.setNoticeStatus(info.getNoticeStatus());
|
|
|
|
- if (info.getNoticeStatus() == NoticeStatus.TO_BE_PUBLISHED) {
|
|
|
|
- originalNotice.setPublishTime(new Date());
|
|
|
|
- }
|
|
|
|
- originalNotice.setContent(info.getContent());
|
|
|
|
- originalNotice.setUpdateTime(new Date());
|
|
|
|
- noticeRepo.save(originalNotice);
|
|
|
|
-
|
|
|
|
- // 更新公告接收规则实体
|
|
|
|
- noticeReceiverRuleRepo.deleteByRootOrgIdAndNoticeIdIn(rootOrgId, noticeIdList);
|
|
|
|
- List<NoticeReceiverRuleEntity> ruleList = getNoticeReceiverRuleEntityListFrom(info);
|
|
|
|
- noticeReceiverRuleRepo.saveAll(ruleList);
|
|
|
|
-
|
|
|
|
- // 更新公告发布进度实体
|
|
|
|
- noticeRulePublishProgressRepo.deleteByRootOrgIdAndNoticeIdIn(rootOrgId, noticeIdList);
|
|
|
|
- NoticeRulePublishProgressEntity publishScheduleEntity = getNoticeRulePublishProgressEntityFrom(
|
|
|
|
- info);
|
|
|
|
- NoticeRulePublishProgressEntity saved = noticeRulePublishProgressRepo
|
|
|
|
- .save(publishScheduleEntity);
|
|
|
|
-
|
|
|
|
- return saved;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public List<NoticeRulePublishProgressEntity> getToBeDisposedNoticeRulePublishProgressList() {
|
|
|
|
- List<NoticeRulePublishProgressEntity> resultList = null;
|
|
|
|
- List<NoticeEntity> publishingNoticeList = noticeRepo
|
|
|
|
- .findByNoticeStatus(NoticeStatus.PUBLISHING);
|
|
|
|
- List<NoticeEntity> toBePublishedNoticeList = noticeRepo
|
|
|
|
- .findByNoticeStatus(NoticeStatus.TO_BE_PUBLISHED);
|
|
|
|
- List<Long> noticeIdList = new ArrayList<>();
|
|
|
|
- if (publishingNoticeList != null && !publishingNoticeList.isEmpty()) {
|
|
|
|
- noticeIdList = publishingNoticeList.stream().map(p -> p.getId())
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- }
|
|
|
|
- if (toBePublishedNoticeList != null && !toBePublishedNoticeList.isEmpty()) {
|
|
|
|
- noticeIdList.addAll(toBePublishedNoticeList.stream().map(p -> p.getId())
|
|
|
|
- .collect(Collectors.toList()));
|
|
|
|
- }
|
|
|
|
- if (!noticeIdList.isEmpty()) {
|
|
|
|
- resultList = noticeRulePublishProgressRepo.findByNoticeIdIn(noticeIdList);
|
|
|
|
- }
|
|
|
|
- return resultList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public Long disposePublishingUserNotice(Long startUserId,
|
|
|
|
- NoticeRulePublishProgressEntity ruleProgress) {
|
|
|
|
- Long nextUserId;
|
|
|
|
- // 发布通知每次处理的用户id数量 // TODO: 2019/7/10 需要将参数放到配置文件
|
|
|
|
- int rowNumber = PropertyHolder.getInt("notice.dispose.userId.size", 100);
|
|
|
|
- Long rootOrgId = ruleProgress.getRootOrgId();
|
|
|
|
- Long noticeId = ruleProgress.getNoticeId();
|
|
|
|
- NoticeReceiverRuleType ruleType = ruleProgress.getNoticeReceiverRuleType();
|
|
|
|
- List<NoticeReceiverRuleEntity> currentRuleList = getReceiverRuleList(rootOrgId, noticeId);
|
|
|
|
-
|
|
|
|
- GetLimitUserIdResp getLimitUserIdResp = getSpecifiedUserIdList(rootOrgId, rowNumber,
|
|
|
|
- startUserId, ruleType, currentRuleList);
|
|
|
|
- nextUserId = getLimitUserIdResp.getNextId();
|
|
|
|
- Long maxUserId = getLimitUserIdResp.getMaxId();
|
|
|
|
- // 满足条件的用户id集合(可能为空)
|
|
|
|
- List<Long> limitStudentIdList = getLimitUserIdResp.getIdList();
|
|
|
|
- saveUserNoticeAndUpdateRulePublishProgress(rootOrgId, noticeId, ruleType, ruleProgress,
|
|
|
|
- limitStudentIdList, maxUserId);
|
|
|
|
- return nextUserId;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void disposeOverdueNotice() {
|
|
|
|
- // 通知过期年限阈值// TODO: 2019/7/10
|
|
|
|
- int overdueYearThreshold = PropertyHolder.getInt("notice.dispose.overdue.year", 1);
|
|
|
|
- Date now = new Date();
|
|
|
|
- Date lastYear = DateUtils.addYears(now, -overdueYearThreshold);
|
|
|
|
- List<NoticeEntity> overdueNoticeList = noticeRepo.findByCreationTimeBefore(lastYear);
|
|
|
|
- if (overdueNoticeList != null && !overdueNoticeList.isEmpty()) {
|
|
|
|
- for (NoticeEntity notice : overdueNoticeList) {
|
|
|
|
- deleteAllRelatedNotice(notice.getId());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void updateNoticeStatus(Long noticeId, NoticeStatus noticeStatus) {
|
|
|
|
- noticeRepo.updateNoticeStatus(noticeId, noticeStatus.toString());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 删除所有相关的通知数据
|
|
|
|
- *
|
|
|
|
- * @param noticeId
|
|
|
|
- */
|
|
|
|
- @Transactional
|
|
|
|
- public void deleteAllRelatedNotice(Long noticeId) {
|
|
|
|
- userNoticeRepo.deleteByNoticeId(noticeId);
|
|
|
|
- noticeReceiverRuleRepo.deleteByNoticeId(noticeId);
|
|
|
|
- noticeRulePublishProgressRepo.deleteByNoticeId(noticeId);
|
|
|
|
- noticeRepo.deleteById(noticeId);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 更新发布进度
|
|
|
|
- *
|
|
|
|
- * @param publishSchedule
|
|
|
|
- * @param maxUserId
|
|
|
|
- */
|
|
|
|
- @Transactional
|
|
|
|
- public void saveUserNoticeAndUpdateRulePublishProgress(Long rootOrgId, Long noticeId,
|
|
|
|
- NoticeReceiverRuleType ruleType, NoticeRulePublishProgressEntity rulePublishProgress,
|
|
|
|
- List<Long> limitStudentIdList, Long maxUserId) {
|
|
|
|
- // 保存并更新发布状态为发布完成
|
|
|
|
- List<UserNoticeEntity> userNoticeList = new ArrayList<>();
|
|
|
|
- for (Long userId : limitStudentIdList) {
|
|
|
|
- UserNoticeEntity userNotice = initUserNoticeEntity(rootOrgId, userId, noticeId,
|
|
|
|
- ruleType);
|
|
|
|
- userNoticeList.add(userNotice);
|
|
|
|
- }
|
|
|
|
- userNoticeRepo.saveAll(userNoticeList);
|
|
|
|
- rulePublishProgress.setMaxStudentId(maxUserId);
|
|
|
|
- noticeRulePublishProgressRepo.save(rulePublishProgress);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 获取指定数量的考试记录id
|
|
|
|
- *
|
|
|
|
- * @param rootOrgId
|
|
|
|
- * 组织机构id
|
|
|
|
- * @param rowNumber
|
|
|
|
- * 获取的行数
|
|
|
|
- * @param startUserId
|
|
|
|
- * 起始用户id
|
|
|
|
- * @param ruleType
|
|
|
|
- * 通知对象规则类型
|
|
|
|
- * @param ruleList
|
|
|
|
- * 当前规则类型下对应的规则明细
|
|
|
|
- * @return 返回用户id集合, 和下一次请求id
|
|
|
|
- */
|
|
|
|
- private GetLimitUserIdResp getSpecifiedUserIdList(Long rootOrgId, int rowNumber,
|
|
|
|
- Long startUserId, NoticeReceiverRuleType ruleType,
|
|
|
|
- List<NoticeReceiverRuleEntity> ruleList) {
|
|
|
|
- GetLimitUserIdResp resultResp = new GetLimitUserIdResp();
|
|
|
|
- List<Long> limitUserIdList = null;
|
|
|
|
- long nextUserId = 0;
|
|
|
|
- switch (ruleType) {
|
|
|
|
- case TEACHER_OF_MARK_WORK :
|
|
|
|
- return getGetLimitUserIdByMarkWork(rootOrgId, rowNumber, startUserId, ruleList);
|
|
|
|
- case COMMON_USERS_OF_ROLE :
|
|
|
|
- return getGetLimitUserIdByRole(rootOrgId, startUserId);
|
|
|
|
- case STUDENTS_OF_EXAM :
|
|
|
|
- return getLimitUserIdByExamStudent(rootOrgId, startUserId, rowNumber, ruleList);
|
|
|
|
- case ALL_STUDENTS_OF_ROOT_ORG :
|
|
|
|
- return getLimitUserIdByAllStudent(rootOrgId, rowNumber, startUserId);
|
|
|
|
- }
|
|
|
|
- resultResp.setNextId(nextUserId);
|
|
|
|
- resultResp.setIdList(limitUserIdList);
|
|
|
|
- return resultResp;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private GetLimitUserIdResp getGetLimitUserIdByMarkWork(Long rootOrgId, int rowNumber,
|
|
|
|
- Long startUserId, List<NoticeReceiverRuleEntity> ruleList) {
|
|
|
|
- GetLimitUserIdResp resultResp = new GetLimitUserIdResp();
|
|
|
|
- // 获取当前规则下所有问卷工作id
|
|
|
|
- List<Long> markWorkIdList = ruleList.stream().map(p -> Long.parseLong(p.getRuleValue()))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- GetMarkersByWorkIdsReq markWorkerReq = new GetMarkersByWorkIdsReq();
|
|
|
|
- markWorkerReq.setRootOrgId(rootOrgId);
|
|
|
|
- markWorkerReq.setWorkIds(markWorkIdList);
|
|
|
|
- markWorkerReq.setStarId(startUserId);
|
|
|
|
- markWorkerReq.setSize(rowNumber);
|
|
|
|
- // FIXME: 2019/7/11
|
|
|
|
- GetMarkersByWorkIdsResp markWorkerResp = markWorkCloudService
|
|
|
|
- .getMarkersByWorkIds(markWorkerReq);
|
|
|
|
- List<Long> limitUserIdList = markWorkerResp.getMarkers();
|
|
|
|
- if (markWorkerResp.getMarkers() != null && !markWorkerResp.getMarkers().isEmpty()) {
|
|
|
|
- resultResp.setMaxId(Collections.max(limitUserIdList));
|
|
|
|
- }
|
|
|
|
- resultResp.setNextId(markWorkerResp.getNextId());
|
|
|
|
- resultResp.setIdList(markWorkerResp.getMarkers());
|
|
|
|
- return resultResp;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private GetLimitUserIdResp getGetLimitUserIdByRole(Long rootOrgId, Long startUserId) {
|
|
|
|
- GetLimitUserIdResp resultResp = new GetLimitUserIdResp();
|
|
|
|
- List<Long> limitUserIdList = new ArrayList<>();
|
|
|
|
- long nextUserId;// 当前需求只有考试中心
|
|
|
|
- GetAllUsersByRoleReq getLcUserReq = new GetAllUsersByRoleReq();
|
|
|
|
- getLcUserReq.setRootOrgId(rootOrgId);
|
|
|
|
- getLcUserReq.setRoleCode(RoleMeta.LC_USER.toString());
|
|
|
|
- getLcUserReq.setStart(startUserId);
|
|
|
|
- GetAllUsersByRoleResp getLcUserResp = userCloudService.getAllUsersByRole(getLcUserReq);
|
|
|
|
- nextUserId = getLcUserResp.getNext();
|
|
|
|
- if (getLcUserResp.getUserBeanList() != null && !getLcUserResp.getUserBeanList().isEmpty()) {
|
|
|
|
- limitUserIdList = getLcUserResp.getUserBeanList().stream().map(p -> p.getUserId())
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- resultResp.setMaxId(Collections.max(limitUserIdList));
|
|
|
|
- }
|
|
|
|
- resultResp.setNextId(nextUserId);
|
|
|
|
- resultResp.setIdList(limitUserIdList);
|
|
|
|
- return resultResp;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private GetLimitUserIdResp getLimitUserIdByAllStudent(Long rootOrgId, int rowNumber,
|
|
|
|
- Long startUserId) {
|
|
|
|
- GetLimitUserIdResp resultResp = new GetLimitUserIdResp();
|
|
|
|
- long nextId = startUserId;
|
|
|
|
- Long maxUserId = null;
|
|
|
|
- List<Long> limitUserIdList = examStudentRepo.findLimitStudentIdList(rootOrgId, startUserId,
|
|
|
|
- rowNumber);
|
|
|
|
- if (limitUserIdList != null && !limitUserIdList.isEmpty()) {
|
|
|
|
- maxUserId = Collections.max(limitUserIdList);
|
|
|
|
- nextId = maxUserId;
|
|
|
|
- }
|
|
|
|
- if (nextId != startUserId) {
|
|
|
|
- nextId++;
|
|
|
|
- }
|
|
|
|
- resultResp.setNextId(nextId);
|
|
|
|
- resultResp.setMaxId(maxUserId);
|
|
|
|
- resultResp.setIdList(limitUserIdList);
|
|
|
|
- return resultResp;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private GetLimitUserIdResp getLimitUserIdByExamStudent(Long rootOrgId, Long startUserId,
|
|
|
|
- int rowNumber, List<NoticeReceiverRuleEntity> ruleList) {
|
|
|
|
- GetLimitUserIdResp resultResp = new GetLimitUserIdResp();
|
|
|
|
- // 获取当前规则下所有的考试批次id
|
|
|
|
- List<Long> examIdList = ruleList.stream().map(p -> Long.parseLong(p.getRuleValue()))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- long nextId = startUserId;
|
|
|
|
- Long maxUserId = null;
|
|
|
|
- List<Long> limitUserIdList = examStudentRepo.findByExamIdLimitStudentIdList(rootOrgId,
|
|
|
|
- examIdList, startUserId, rowNumber);
|
|
|
|
- if (limitUserIdList != null && !limitUserIdList.isEmpty()) {
|
|
|
|
- maxUserId = Collections.max(limitUserIdList);
|
|
|
|
- nextId = maxUserId;
|
|
|
|
- }
|
|
|
|
- if (nextId != startUserId) {
|
|
|
|
- nextId++;
|
|
|
|
- }
|
|
|
|
- resultResp.setMaxId(maxUserId);
|
|
|
|
- resultResp.setNextId(nextId);
|
|
|
|
- resultResp.setIdList(limitUserIdList);
|
|
|
|
- return resultResp;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- 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;
|
|
|
|
- UserNoticeEntity userNotice = new UserNoticeEntity();
|
|
|
|
- userNotice.setRootOrgId(rootOrgId);
|
|
|
|
- userNotice.setHasRead(false);
|
|
|
|
- userNotice.setNoticeId(noticeId);
|
|
|
|
- userNotice.setUserType(userType);
|
|
|
|
- userNotice.setUserId(userId);
|
|
|
|
- return userNotice;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 获取发布对象
|
|
|
|
- *
|
|
|
|
- * @param rootOrgId
|
|
|
|
- * @param noticeId
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private List<Map<String, Object>> getPublishObject(Long rootOrgId,
|
|
|
|
- NoticeReceiverRuleType ruleType, List<NoticeReceiverRuleEntity> ruleList) {
|
|
|
|
- List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
- Map<String, Object> objectMap;
|
|
|
|
- List<NoticeReceiverRuleEntity> currentRuleList;
|
|
|
|
- switch (ruleType) {
|
|
|
|
- case STUDENTS_OF_EXAM :
|
|
|
|
- currentRuleList = ruleList.stream().filter(p -> p.getRuleType() == ruleType)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- return getExamStudentObject(currentRuleList);
|
|
|
|
- case ALL_STUDENTS_OF_ROOT_ORG :
|
|
|
|
- objectMap = new HashMap<>();
|
|
|
|
- objectMap.put("id", 0);
|
|
|
|
- objectMap.put("name", "所有学生");
|
|
|
|
- objectMap.put("ruleType", "ALL_STUDENTS_OF_ROOT_ORG");
|
|
|
|
- resultList.add(objectMap);
|
|
|
|
- return resultList;
|
|
|
|
- case COMMON_USERS_OF_ROLE :
|
|
|
|
- objectMap = new HashMap<>();
|
|
|
|
- objectMap.put("id", 0);
|
|
|
|
- objectMap.put("name", "所有学习中心用户");
|
|
|
|
- objectMap.put("ruleType", "COMMON_USERS_OF_ROLE");
|
|
|
|
- resultList.add(objectMap);
|
|
|
|
- return resultList;
|
|
|
|
- case TEACHER_OF_MARK_WORK :
|
|
|
|
- currentRuleList = ruleList.stream().filter(p -> p.getRuleType() == ruleType)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- return getMarkTeacherObject(rootOrgId, currentRuleList);
|
|
|
|
- }
|
|
|
|
- return resultList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 组装学生发布对象
|
|
|
|
- *
|
|
|
|
- * @param ruleList
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private List<Map<String, Object>> getExamStudentObject(
|
|
|
|
- List<NoticeReceiverRuleEntity> ruleList) {
|
|
|
|
- List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
- // 考试批次id
|
|
|
|
- List<Long> examIdList = ruleList.stream().map(p -> Long.parseLong(p.getRuleValue()))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- List<ExamEntity> examList = examRepo.findByIdIn(examIdList);
|
|
|
|
- for (ExamEntity e : examList) {
|
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
|
- map.put("id", e.getId());
|
|
|
|
- map.put("name", "学生-" + e.getName());
|
|
|
|
- map.put("ruleType", "STUDENTS_OF_EXAM");
|
|
|
|
- resultList.add(map);
|
|
|
|
- }
|
|
|
|
- return resultList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 组装阅卷老师发布对象
|
|
|
|
- *
|
|
|
|
- * @param rootOrgId
|
|
|
|
- * @param ruleList
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private List<Map<String, Object>> getMarkTeacherObject(Long rootOrgId,
|
|
|
|
- List<NoticeReceiverRuleEntity> ruleList) {
|
|
|
|
- List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
- List<Long> markWorkIdList = ruleList.stream().map(p -> Long.parseLong(p.getRuleValue()))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- GetMarkWorkMainByIdsReq req = new GetMarkWorkMainByIdsReq();
|
|
|
|
- req.setRootOrgId(rootOrgId);
|
|
|
|
- req.setWorkIds(markWorkIdList);
|
|
|
|
-
|
|
|
|
- GetMarkWorkMainByIdsResp markWorkResp = markWorkCloudService.getMarkWorkMainByIds(req);
|
|
|
|
- List<MarkWorkMainBean> markWorkList = markWorkResp.getList();
|
|
|
|
- for (MarkWorkMainBean mw : markWorkList) {
|
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
|
- map.put("id", mw.getId());
|
|
|
|
- map.put("name", "老师-" + mw.getName());
|
|
|
|
- map.put("ruleType", "TEACHER_OF_MARK_WORK");
|
|
|
|
- resultList.add(map);
|
|
|
|
- }
|
|
|
|
- return resultList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 根据通知id获取通知
|
|
|
|
- *
|
|
|
|
- * @param noticeList
|
|
|
|
- * @param noticeId
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private NoticeEntity getNoticeById(List<NoticeEntity> noticeList, Long noticeId) {
|
|
|
|
- Optional<NoticeEntity> optional = noticeList.stream()
|
|
|
|
- .filter(p -> p.getId().equals(noticeId)).findFirst();
|
|
|
|
- if (optional.isPresent()) {
|
|
|
|
- return optional.get();
|
|
|
|
- } else {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private NoticeRulePublishProgressEntity getNoticeRulePublishProgressEntityFrom(
|
|
|
|
- AddNoticeInfo addNoticeInfo, Long noticeId) {
|
|
|
|
- NoticeRulePublishProgressEntity progressEntity = new NoticeRulePublishProgressEntity();
|
|
|
|
- progressEntity.setRootOrgId(addNoticeInfo.getRootOrgId());
|
|
|
|
- progressEntity.setNoticeId(noticeId);
|
|
|
|
- progressEntity.setNoticeReceiverRuleType(addNoticeInfo.getRuleType());
|
|
|
|
- return progressEntity;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private NoticeEntity getNoticeEntityFrom(AddNoticeInfo addNoticeInfo) {
|
|
|
|
- NoticeEntity noticeEntity = new NoticeEntity();
|
|
|
|
- noticeEntity.setRootOrgId(addNoticeInfo.getRootOrgId());
|
|
|
|
- noticeEntity.setTitle(addNoticeInfo.getTitle());
|
|
|
|
- noticeEntity.setContent(addNoticeInfo.getContent());
|
|
|
|
- noticeEntity.setNoticeStatus(addNoticeInfo.getNoticeStatus());
|
|
|
|
- noticeEntity.setPublisher(addNoticeInfo.getPublisher());
|
|
|
|
- // 只有为立即发布的才有发布时间
|
|
|
|
- if (addNoticeInfo.getNoticeStatus() == NoticeStatus.TO_BE_PUBLISHED) {
|
|
|
|
- noticeEntity.setPublishTime(new Date());
|
|
|
|
- }
|
|
|
|
- return noticeEntity;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private List<NoticeReceiverRuleEntity> getNoticeReceiverRuleEntityListFrom(
|
|
|
|
- AddNoticeInfo addNoticeInfo, Long noticeId) {
|
|
|
|
- List<NoticeReceiverRuleEntity> ruleList = new ArrayList<>();
|
|
|
|
- // 如果发送对象规则类型为所有学生或学习中心不需要赋值
|
|
|
|
- if (addNoticeInfo.getRuleType() == NoticeReceiverRuleType.ALL_STUDENTS_OF_ROOT_ORG
|
|
|
|
- || addNoticeInfo.getRuleType() == NoticeReceiverRuleType.COMMON_USERS_OF_ROLE) {
|
|
|
|
- NoticeReceiverRuleEntity ruleEntity = new NoticeReceiverRuleEntity();
|
|
|
|
- ruleEntity.setRootOrgId(addNoticeInfo.getRootOrgId());
|
|
|
|
- ruleEntity.setNoticeId(noticeId);
|
|
|
|
- ruleEntity.setRuleType(addNoticeInfo.getRuleType());
|
|
|
|
- ruleEntity.setRuleValue(null);
|
|
|
|
- ruleList.add(ruleEntity);
|
|
|
|
- } else {
|
|
|
|
- String publishObjectIds = getStandardIds(addNoticeInfo.getPublishObjectId(), ",");
|
|
|
|
- String[] publishObjectIdArr = publishObjectIds.split(",");
|
|
|
|
- for (String publishObjectId : publishObjectIdArr) {
|
|
|
|
- NoticeReceiverRuleEntity ruleEntity = new NoticeReceiverRuleEntity();
|
|
|
|
- ruleEntity.setRootOrgId(addNoticeInfo.getRootOrgId());
|
|
|
|
- ruleEntity.setNoticeId(noticeId);
|
|
|
|
- ruleEntity.setRuleType(addNoticeInfo.getRuleType());
|
|
|
|
- ruleEntity.setRuleValue(publishObjectId);
|
|
|
|
- ruleList.add(ruleEntity);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return ruleList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 获取标准的id字符串,去掉最后一个字符
|
|
|
|
- *
|
|
|
|
- * @param strIds
|
|
|
|
- * id字符串
|
|
|
|
- * @param separator
|
|
|
|
- * 分隔符
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private String getStandardIds(String strIds, String separator) {
|
|
|
|
- if (!StringUtils.isNullOrEmpty(strIds)) {
|
|
|
|
- if (strIds.lastIndexOf(separator) == strIds.length() - 1) {
|
|
|
|
- return strIds.substring(0, strIds.lastIndexOf(separator));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return strIds;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private NoticeRulePublishProgressEntity getNoticeRulePublishProgressEntityFrom(
|
|
|
|
- UpdateNoticeInfo info) {
|
|
|
|
- NoticeRulePublishProgressEntity publishScheduleEntity = new NoticeRulePublishProgressEntity();
|
|
|
|
- publishScheduleEntity.setRootOrgId(info.getRootOrgId());
|
|
|
|
- publishScheduleEntity.setNoticeId(info.getId());
|
|
|
|
- publishScheduleEntity.setNoticeReceiverRuleType(info.getRuleType());
|
|
|
|
- return publishScheduleEntity;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private List<NoticeReceiverRuleEntity> getNoticeReceiverRuleEntityListFrom(
|
|
|
|
- UpdateNoticeInfo info) {
|
|
|
|
- List<NoticeReceiverRuleEntity> ruleList = new ArrayList<>();
|
|
|
|
- // 如果发送对象规则类型为所有学生或学习中心不需要赋值
|
|
|
|
- if (info.getRuleType() == NoticeReceiverRuleType.ALL_STUDENTS_OF_ROOT_ORG
|
|
|
|
- || info.getRuleType() == NoticeReceiverRuleType.COMMON_USERS_OF_ROLE) {
|
|
|
|
- NoticeReceiverRuleEntity ruleEntity = new NoticeReceiverRuleEntity();
|
|
|
|
- ruleEntity.setRootOrgId(info.getRootOrgId());
|
|
|
|
- ruleEntity.setNoticeId(info.getId());
|
|
|
|
- ruleEntity.setRuleType(info.getRuleType());
|
|
|
|
- ruleEntity.setRuleValue(null);
|
|
|
|
- ruleList.add(ruleEntity);
|
|
|
|
- } else {
|
|
|
|
- String publishObjectIds = getStandardIds(info.getPublishObjectId(), ",");
|
|
|
|
- String[] publishObjectIdArr = publishObjectIds.split(",");
|
|
|
|
- for (String publishObjectId : publishObjectIdArr) {
|
|
|
|
- NoticeReceiverRuleEntity ruleEntity = new NoticeReceiverRuleEntity();
|
|
|
|
- ruleEntity.setRootOrgId(info.getRootOrgId());
|
|
|
|
- ruleEntity.setNoticeId(info.getId());
|
|
|
|
- ruleEntity.setRuleType(info.getRuleType());
|
|
|
|
- ruleEntity.setRuleValue(publishObjectId);
|
|
|
|
- ruleList.add(ruleEntity);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return ruleList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private List<NoticeReceiverRuleEntity> getReceiverRuleList(Long rootOrgId, Long... noticeId) {
|
|
|
|
- List<NoticeReceiverRuleEntity> ruleList = noticeReceiverRuleRepo
|
|
|
|
- .findByRootOrgIdAndNoticeIdIn(rootOrgId, Arrays.asList(noticeId));
|
|
|
|
- if (ruleList == null) {
|
|
|
|
- throw new StatusException("501009", "找不到通知id为:" + noticeId + "的通知对象信息");
|
|
|
|
- }
|
|
|
|
- return ruleList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private NoticeReceiverRuleType getNoticeReceiverRuleType(Long noticeId,
|
|
|
|
- List<NoticeReceiverRuleEntity> ruleList) {
|
|
|
|
- Optional<NoticeReceiverRuleType> first = ruleList.stream()
|
|
|
|
- .filter(p -> p.getNoticeId().equals(noticeId)).map(p -> p.getRuleType())
|
|
|
|
- .findFirst();
|
|
|
|
- if (first.isPresent()) {
|
|
|
|
- return first.get();
|
|
|
|
- } else {
|
|
|
|
- throw new StatusException("501012", "找不到通知id为:" + noticeId + "的通知规则类型");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ MarkWorkCloudService markWorkCloudService;
|
|
|
|
+ @Autowired
|
|
|
|
+ ExamStudentRepo examStudentRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ UserCloudService userCloudService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private NoticeRepo noticeRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserNoticeRepo userNoticeRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private NoticeRulePublishProgressRepo noticeRulePublishProgressRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private NoticeReceiverRuleRepo noticeReceiverRuleRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExamRepo examRepo;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<UserNoticeInfo> getNoticeList(UserNoticeInfoQuery query) {
|
|
|
|
+ List<UserNoticeInfo> resultList = new ArrayList<>();
|
|
|
|
+ List<UserNoticeEntity> userNoticeList;
|
|
|
|
+ if (query.getHasRead() != null) {
|
|
|
|
+ userNoticeList = userNoticeRepo
|
|
|
|
+ .findByRootOrgIdAndUserTypeAndUserIdAndHasReadOrderByCreationTimeDesc(
|
|
|
|
+ query.getRootOrgId(), query.getUserType(), query.getUserId(),
|
|
|
|
+ query.getHasRead());
|
|
|
|
+ } else {
|
|
|
|
+ userNoticeList = userNoticeRepo
|
|
|
|
+ .findByRootOrgIdAndUserTypeAndUserIdOrderByCreationTimeDesc(
|
|
|
|
+ query.getRootOrgId(), query.getUserType(), query.getUserId());
|
|
|
|
+ }
|
|
|
|
+ if (null != userNoticeList && !userNoticeList.isEmpty()) {
|
|
|
|
+ List<Long> noticeIdList = userNoticeList.stream().map(UserNoticeEntity::getNoticeId)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ List<NoticeEntity> noticeList = noticeRepo.findByIdIn(noticeIdList);
|
|
|
|
+ for (UserNoticeEntity un : userNoticeList) {
|
|
|
|
+ NoticeEntity noticeEntity = getNoticeById(noticeList, un.getNoticeId());
|
|
|
|
+ if (noticeEntity == null) {
|
|
|
|
+ throw new StatusException("501005", "找不到id为:" + un.getNoticeId() + "的通知");
|
|
|
|
+ }
|
|
|
|
+ UserNoticeInfo info = new UserNoticeInfo();
|
|
|
|
+ info.setId(noticeEntity.getId());
|
|
|
|
+ info.setTitle(noticeEntity.getTitle());
|
|
|
|
+ info.setContent(noticeEntity.getContent());
|
|
|
|
+ info.setPublisher(noticeEntity.getPublisher());
|
|
|
|
+ info.setPublishTime(noticeEntity.getPublishTime());
|
|
|
|
+ info.setHasRead(un.getHasRead());
|
|
|
|
+ resultList.add(info);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return resultList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public int updateNoticeReadStatus(String noticeId, UserType userType, Long userId) {
|
|
|
|
+ List<Long> noticeIdList;
|
|
|
|
+ if (noticeId.contains(",")) {
|
|
|
|
+ noticeIdList = Arrays.asList(noticeId.split(",")).stream().map(p -> Long.parseLong(p))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ } else {
|
|
|
|
+ noticeIdList = Arrays.asList(noticeId).stream().map(p -> Long.parseLong(p))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+ return userNoticeRepo.updateNoticeReadStatus(noticeIdList, userType.toString(), userId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public PageInfo<NoticeInfo> getPagedNoticeList(Integer curPage, Integer pageSize,
|
|
|
|
+ NoticeInfoQuery infoQuery) {
|
|
|
|
+ List<NoticeInfo> resultList = new ArrayList<>();
|
|
|
|
+ Long rootOrgId = infoQuery.getRootOrgId();
|
|
|
|
+ Specification<NoticeEntity> specification = (root, query, cb) -> {
|
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), rootOrgId));
|
|
|
|
+ if (!StringUtils.isNullOrEmpty(infoQuery.getTitle())) {
|
|
|
|
+ predicates.add(cb.like(root.get("title"),
|
|
|
|
+ DBUtil.toSqlSearchPattern(infoQuery.getTitle())));
|
|
|
|
+ }
|
|
|
|
+ if (null != infoQuery.getPublishStatus()) {
|
|
|
|
+ predicates.add(cb.equal(root.get("noticeStatus"), infoQuery.getPublishStatus()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
|
+ };
|
|
|
|
+ PageRequest pageRequest = PageRequest.of(curPage, pageSize,
|
|
|
|
+ new Sort(Sort.Direction.DESC, "creationTime"));
|
|
|
|
+ Page<NoticeEntity> pagedNoticeEntityList = noticeRepo.findAll(specification, pageRequest);
|
|
|
|
+ List<Long> noticeIdList = pagedNoticeEntityList.stream().map(p -> p.getId())
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ List<NoticeReceiverRuleEntity> ruleList = getReceiverRuleList(rootOrgId,
|
|
|
|
+ noticeIdList.toArray(new Long[noticeIdList.size()]));
|
|
|
|
+
|
|
|
|
+ for (NoticeEntity ne : pagedNoticeEntityList) {
|
|
|
|
+ NoticeReceiverRuleType ruleType = getNoticeReceiverRuleType(ne.getId(), ruleList);
|
|
|
|
+ NoticeInfo ni = new NoticeInfo();
|
|
|
|
+ ni.setId(ne.getId());
|
|
|
|
+ ni.setPublisher(ne.getPublisher());
|
|
|
|
+ ni.setPublishTime(ne.getPublishTime());
|
|
|
|
+ ni.setTitle(ne.getTitle());
|
|
|
|
+ ni.setContent(ne.getContent());
|
|
|
|
+ ni.setPublishObject(getPublishObject(rootOrgId, ruleType, ruleList));
|
|
|
|
+ ni.setPublishStatus(ne.getNoticeStatus());
|
|
|
|
+ ni.setRuleType(ruleType);
|
|
|
|
+ resultList.add(ni);
|
|
|
|
+ }
|
|
|
|
+ return new PageInfo<>(pagedNoticeEntityList, resultList);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public int deleteNotice(Long rootOrgId, List<Long> noticeIdList) {
|
|
|
|
+ int result = 0;
|
|
|
|
+ // 删除通知进度相关信息
|
|
|
|
+ result += noticeRulePublishProgressRepo.deleteByRootOrgIdAndNoticeIdIn(rootOrgId,
|
|
|
|
+ noticeIdList);
|
|
|
|
+ // 删除通知规则相关信息
|
|
|
|
+ result += noticeReceiverRuleRepo.deleteByRootOrgIdAndNoticeIdIn(rootOrgId, noticeIdList);
|
|
|
|
+ // 删除通知相关信息
|
|
|
|
+ result += noticeRepo.deleteByIdIn(noticeIdList);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public int addNotice(AddNoticeInfo addNoticeInfo) {
|
|
|
|
+ // 保存公告基本信息
|
|
|
|
+ NoticeEntity noticeEntity = getNoticeEntityFrom(addNoticeInfo);
|
|
|
|
+ NoticeEntity savedNotice = noticeRepo.save(noticeEntity);
|
|
|
|
+
|
|
|
|
+ Long noticeId = savedNotice.getId();
|
|
|
|
+
|
|
|
|
+ // 保存公告接收规则
|
|
|
|
+ List<NoticeReceiverRuleEntity> ruleList = getNoticeReceiverRuleEntityListFrom(addNoticeInfo,
|
|
|
|
+ noticeId);
|
|
|
|
+ noticeReceiverRuleRepo.saveAll(ruleList);
|
|
|
|
+
|
|
|
|
+ // 保存公告发布进度
|
|
|
|
+ NoticeRulePublishProgressEntity publishScheduleEntity = getNoticeRulePublishProgressEntityFrom(
|
|
|
|
+ addNoticeInfo, noticeId);
|
|
|
|
+ noticeRulePublishProgressRepo.save(publishScheduleEntity);
|
|
|
|
+
|
|
|
|
+ return noticeId > 0 ? 1 : 0;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public NoticeRulePublishProgressEntity updateNotice(UpdateNoticeInfo info) {
|
|
|
|
+ Long rootOrgId = info.getRootOrgId();
|
|
|
|
+ List<Long> noticeIdList = Collections.singletonList(info.getId());
|
|
|
|
+ // 校验通知状态,正在发送的通知不允许修改
|
|
|
|
+ NoticeEntity originalNotice = GlobalHelper.getEntity(noticeRepo, info.getId(),
|
|
|
|
+ NoticeEntity.class);
|
|
|
|
+ if (originalNotice == null) {
|
|
|
|
+ throw new StatusException("501006", "找不到通知id为:" + info.getId() + "的数据");
|
|
|
|
+ }
|
|
|
|
+ if (originalNotice.getNoticeStatus() != NoticeStatus.DRAFT) {
|
|
|
|
+ throw new StatusException("501008", "发布中或已发布的通知不允许修改");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新通知表
|
|
|
|
+
|
|
|
|
+ originalNotice.setTitle(info.getTitle());
|
|
|
|
+ originalNotice.setPublisher(info.getPublisher());
|
|
|
|
+ originalNotice.setNoticeStatus(info.getNoticeStatus());
|
|
|
|
+ if (info.getNoticeStatus() == NoticeStatus.TO_BE_PUBLISHED) {
|
|
|
|
+ originalNotice.setPublishTime(new Date());
|
|
|
|
+ }
|
|
|
|
+ originalNotice.setContent(info.getContent());
|
|
|
|
+ originalNotice.setUpdateTime(new Date());
|
|
|
|
+ noticeRepo.save(originalNotice);
|
|
|
|
+
|
|
|
|
+ // 更新公告接收规则实体
|
|
|
|
+ noticeReceiverRuleRepo.deleteByRootOrgIdAndNoticeIdIn(rootOrgId, noticeIdList);
|
|
|
|
+ List<NoticeReceiverRuleEntity> ruleList = getNoticeReceiverRuleEntityListFrom(info);
|
|
|
|
+ noticeReceiverRuleRepo.saveAll(ruleList);
|
|
|
|
+
|
|
|
|
+ // 更新公告发布进度实体
|
|
|
|
+ noticeRulePublishProgressRepo.deleteByRootOrgIdAndNoticeIdIn(rootOrgId, noticeIdList);
|
|
|
|
+ NoticeRulePublishProgressEntity publishScheduleEntity = getNoticeRulePublishProgressEntityFrom(
|
|
|
|
+ info);
|
|
|
|
+ NoticeRulePublishProgressEntity saved = noticeRulePublishProgressRepo
|
|
|
|
+ .save(publishScheduleEntity);
|
|
|
|
+
|
|
|
|
+ return saved;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<NoticeRulePublishProgressEntity> getToBeDisposedNoticeRulePublishProgressList() {
|
|
|
|
+ List<NoticeRulePublishProgressEntity> resultList = null;
|
|
|
|
+ List<NoticeEntity> publishingNoticeList = noticeRepo
|
|
|
|
+ .findByNoticeStatus(NoticeStatus.PUBLISHING);
|
|
|
|
+ List<NoticeEntity> toBePublishedNoticeList = noticeRepo
|
|
|
|
+ .findByNoticeStatus(NoticeStatus.TO_BE_PUBLISHED);
|
|
|
|
+ List<Long> noticeIdList = new ArrayList<>();
|
|
|
|
+ if (publishingNoticeList != null && !publishingNoticeList.isEmpty()) {
|
|
|
|
+ noticeIdList = publishingNoticeList.stream().map(p -> p.getId())
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+ if (toBePublishedNoticeList != null && !toBePublishedNoticeList.isEmpty()) {
|
|
|
|
+ noticeIdList.addAll(toBePublishedNoticeList.stream().map(p -> p.getId())
|
|
|
|
+ .collect(Collectors.toList()));
|
|
|
|
+ }
|
|
|
|
+ if (!noticeIdList.isEmpty()) {
|
|
|
|
+ resultList = noticeRulePublishProgressRepo.findByNoticeIdIn(noticeIdList);
|
|
|
|
+ }
|
|
|
|
+ return resultList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Long disposePublishingUserNotice(Long startUserId,
|
|
|
|
+ NoticeRulePublishProgressEntity ruleProgress) {
|
|
|
|
+ Long nextUserId;
|
|
|
|
+ // 发布通知每次处理的用户id数量 // TODO: 2019/7/10 需要将参数放到配置文件
|
|
|
|
+ int rowNumber = PropertyHolder.getInt("notice.dispose.userId.size", 100);
|
|
|
|
+ Long rootOrgId = ruleProgress.getRootOrgId();
|
|
|
|
+ Long noticeId = ruleProgress.getNoticeId();
|
|
|
|
+ NoticeReceiverRuleType ruleType = ruleProgress.getNoticeReceiverRuleType();
|
|
|
|
+ List<NoticeReceiverRuleEntity> currentRuleList = getReceiverRuleList(rootOrgId, noticeId);
|
|
|
|
+
|
|
|
|
+ GetLimitUserIdResp getLimitUserIdResp = getSpecifiedUserIdList(rootOrgId, rowNumber,
|
|
|
|
+ startUserId, ruleType, currentRuleList);
|
|
|
|
+ nextUserId = getLimitUserIdResp.getNextId();
|
|
|
|
+ Long maxUserId = getLimitUserIdResp.getMaxId();
|
|
|
|
+ // 满足条件的用户id集合(可能为空)
|
|
|
|
+ List<Long> limitStudentIdList = getLimitUserIdResp.getIdList();
|
|
|
|
+ saveUserNoticeAndUpdateRulePublishProgress(rootOrgId, noticeId, ruleType, ruleProgress,
|
|
|
|
+ limitStudentIdList, maxUserId);
|
|
|
|
+ return nextUserId;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void disposeOverdueNotice() {
|
|
|
|
+ // 通知过期年限阈值// TODO: 2019/7/10
|
|
|
|
+ int overdueYearThreshold = PropertyHolder.getInt("notice.dispose.overdue.year", 1);
|
|
|
|
+ Date now = new Date();
|
|
|
|
+ Date lastYear = DateUtils.addYears(now, -overdueYearThreshold);
|
|
|
|
+ List<NoticeEntity> overdueNoticeList = noticeRepo.findByCreationTimeBefore(lastYear);
|
|
|
|
+ if (overdueNoticeList != null && !overdueNoticeList.isEmpty()) {
|
|
|
|
+ for (NoticeEntity notice : overdueNoticeList) {
|
|
|
|
+ deleteAllRelatedNotice(notice.getId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void updateNoticeStatus(Long noticeId, NoticeStatus noticeStatus) {
|
|
|
|
+ noticeRepo.updateNoticeStatus(noticeId, noticeStatus.toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除所有相关的通知数据
|
|
|
|
+ *
|
|
|
|
+ * @param noticeId
|
|
|
|
+ */
|
|
|
|
+ @Transactional
|
|
|
|
+ public void deleteAllRelatedNotice(Long noticeId) {
|
|
|
|
+ userNoticeRepo.deleteByNoticeId(noticeId);
|
|
|
|
+ noticeReceiverRuleRepo.deleteByNoticeId(noticeId);
|
|
|
|
+ noticeRulePublishProgressRepo.deleteByNoticeId(noticeId);
|
|
|
|
+ noticeRepo.deleteById(noticeId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新发布进度
|
|
|
|
+ *
|
|
|
|
+ * @param publishSchedule
|
|
|
|
+ * @param maxUserId
|
|
|
|
+ */
|
|
|
|
+ @Transactional
|
|
|
|
+ public void saveUserNoticeAndUpdateRulePublishProgress(Long rootOrgId, Long noticeId,
|
|
|
|
+ NoticeReceiverRuleType ruleType, NoticeRulePublishProgressEntity rulePublishProgress,
|
|
|
|
+ List<Long> limitStudentIdList, Long maxUserId) {
|
|
|
|
+ // 保存并更新发布状态为发布完成
|
|
|
|
+ List<UserNoticeEntity> userNoticeList = new ArrayList<>();
|
|
|
|
+ for (Long userId : limitStudentIdList) {
|
|
|
|
+ UserNoticeEntity userNotice = initUserNoticeEntity(rootOrgId, userId, noticeId,
|
|
|
|
+ ruleType);
|
|
|
|
+ userNoticeList.add(userNotice);
|
|
|
|
+ }
|
|
|
|
+ userNoticeRepo.saveAll(userNoticeList);
|
|
|
|
+ rulePublishProgress.setMaxStudentId(maxUserId);
|
|
|
|
+ noticeRulePublishProgressRepo.save(rulePublishProgress);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取指定数量的考试记录id
|
|
|
|
+ *
|
|
|
|
+ * @param rootOrgId 组织机构id
|
|
|
|
+ * @param rowNumber 获取的行数
|
|
|
|
+ * @param startUserId 起始用户id
|
|
|
|
+ * @param ruleType 通知对象规则类型
|
|
|
|
+ * @param ruleList 当前规则类型下对应的规则明细
|
|
|
|
+ * @return 返回用户id集合, 和下一次请求id
|
|
|
|
+ */
|
|
|
|
+ private GetLimitUserIdResp getSpecifiedUserIdList(Long rootOrgId, int rowNumber,
|
|
|
|
+ Long startUserId, NoticeReceiverRuleType ruleType,
|
|
|
|
+ List<NoticeReceiverRuleEntity> ruleList) {
|
|
|
|
+ GetLimitUserIdResp resultResp = new GetLimitUserIdResp();
|
|
|
|
+ List<Long> limitUserIdList = null;
|
|
|
|
+ long nextUserId = 0;
|
|
|
|
+ switch (ruleType) {
|
|
|
|
+ case TEACHER_OF_MARK_WORK:
|
|
|
|
+ return getGetLimitUserIdByMarkWork(rootOrgId, rowNumber, startUserId, ruleList);
|
|
|
|
+ case COMMON_USERS_OF_ROLE:
|
|
|
|
+ return getGetLimitUserIdByRole(rootOrgId, startUserId);
|
|
|
|
+ case STUDENTS_OF_EXAM:
|
|
|
|
+ return getLimitUserIdByExamStudent(rootOrgId, startUserId, rowNumber, ruleList);
|
|
|
|
+ case ALL_STUDENTS_OF_ROOT_ORG:
|
|
|
|
+ return getLimitUserIdByAllStudent(rootOrgId, rowNumber, startUserId);
|
|
|
|
+ }
|
|
|
|
+ resultResp.setNextId(nextUserId);
|
|
|
|
+ resultResp.setIdList(limitUserIdList);
|
|
|
|
+ return resultResp;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private GetLimitUserIdResp getGetLimitUserIdByMarkWork(Long rootOrgId, int rowNumber,
|
|
|
|
+ Long startUserId, List<NoticeReceiverRuleEntity> ruleList) {
|
|
|
|
+ GetLimitUserIdResp resultResp = new GetLimitUserIdResp();
|
|
|
|
+ // 获取当前规则下所有问卷工作id
|
|
|
|
+ List<Long> markWorkIdList = ruleList.stream().map(p -> Long.parseLong(p.getRuleValue()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ GetMarkersByWorkIdsReq markWorkerReq = new GetMarkersByWorkIdsReq();
|
|
|
|
+ markWorkerReq.setRootOrgId(rootOrgId);
|
|
|
|
+ markWorkerReq.setWorkIds(markWorkIdList);
|
|
|
|
+ markWorkerReq.setStarId(startUserId);
|
|
|
|
+ markWorkerReq.setSize(rowNumber);
|
|
|
|
+ // FIXME: 2019/7/11
|
|
|
|
+ GetMarkersByWorkIdsResp markWorkerResp = markWorkCloudService
|
|
|
|
+ .getMarkersByWorkIds(markWorkerReq);
|
|
|
|
+ List<Long> limitUserIdList = markWorkerResp.getMarkers();
|
|
|
|
+ if (markWorkerResp.getMarkers() != null && !markWorkerResp.getMarkers().isEmpty()) {
|
|
|
|
+ resultResp.setMaxId(Collections.max(limitUserIdList));
|
|
|
|
+ }
|
|
|
|
+ resultResp.setNextId(markWorkerResp.getNextId());
|
|
|
|
+ resultResp.setIdList(markWorkerResp.getMarkers());
|
|
|
|
+ return resultResp;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private GetLimitUserIdResp getGetLimitUserIdByRole(Long rootOrgId, Long startUserId) {
|
|
|
|
+ GetLimitUserIdResp resultResp = new GetLimitUserIdResp();
|
|
|
|
+ List<Long> limitUserIdList = new ArrayList<>();
|
|
|
|
+ long nextUserId;// 当前需求只有考试中心
|
|
|
|
+ GetAllUsersByRoleReq getLcUserReq = new GetAllUsersByRoleReq();
|
|
|
|
+ getLcUserReq.setRootOrgId(rootOrgId);
|
|
|
|
+ getLcUserReq.setRoleCode(RoleMeta.LC_USER.toString());
|
|
|
|
+ getLcUserReq.setStart(startUserId);
|
|
|
|
+ GetAllUsersByRoleResp getLcUserResp = userCloudService.getAllUsersByRole(getLcUserReq);
|
|
|
|
+ nextUserId = getLcUserResp.getNext();
|
|
|
|
+ if (getLcUserResp.getUserBeanList() != null && !getLcUserResp.getUserBeanList().isEmpty()) {
|
|
|
|
+ limitUserIdList = getLcUserResp.getUserBeanList().stream().map(p -> p.getUserId())
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ resultResp.setMaxId(Collections.max(limitUserIdList));
|
|
|
|
+ }
|
|
|
|
+ resultResp.setNextId(nextUserId);
|
|
|
|
+ resultResp.setIdList(limitUserIdList);
|
|
|
|
+ return resultResp;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private GetLimitUserIdResp getLimitUserIdByAllStudent(Long rootOrgId, int rowNumber,
|
|
|
|
+ Long startUserId) {
|
|
|
|
+ GetLimitUserIdResp resultResp = new GetLimitUserIdResp();
|
|
|
|
+ long nextId = startUserId;
|
|
|
|
+ Long maxUserId = null;
|
|
|
|
+ List<Long> limitUserIdList = examStudentRepo.findLimitStudentIdList(rootOrgId, startUserId,
|
|
|
|
+ rowNumber);
|
|
|
|
+ if (limitUserIdList != null && !limitUserIdList.isEmpty()) {
|
|
|
|
+ maxUserId = Collections.max(limitUserIdList);
|
|
|
|
+ nextId = maxUserId;
|
|
|
|
+ }
|
|
|
|
+ nextId++;
|
|
|
|
+ resultResp.setNextId(nextId);
|
|
|
|
+ resultResp.setMaxId(maxUserId);
|
|
|
|
+ resultResp.setIdList(limitUserIdList);
|
|
|
|
+ return resultResp;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private GetLimitUserIdResp getLimitUserIdByExamStudent(Long rootOrgId, Long startUserId,
|
|
|
|
+ int rowNumber, List<NoticeReceiverRuleEntity> ruleList) {
|
|
|
|
+ GetLimitUserIdResp resultResp = new GetLimitUserIdResp();
|
|
|
|
+ // 获取当前规则下所有的考试批次id
|
|
|
|
+ List<Long> examIdList = ruleList.stream().map(p -> Long.parseLong(p.getRuleValue()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ long nextId = startUserId;
|
|
|
|
+ Long maxUserId = null;
|
|
|
|
+ List<Long> limitUserIdList = examStudentRepo.findByExamIdLimitStudentIdList(rootOrgId,
|
|
|
|
+ examIdList, startUserId, rowNumber);
|
|
|
|
+ if (limitUserIdList != null && !limitUserIdList.isEmpty()) {
|
|
|
|
+ maxUserId = Collections.max(limitUserIdList);
|
|
|
|
+ nextId = maxUserId;
|
|
|
|
+ }
|
|
|
|
+ nextId++;
|
|
|
|
+ resultResp.setMaxId(maxUserId);
|
|
|
|
+ resultResp.setNextId(nextId);
|
|
|
|
+ resultResp.setIdList(limitUserIdList);
|
|
|
|
+ return resultResp;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+ UserNoticeEntity userNotice = new UserNoticeEntity();
|
|
|
|
+ userNotice.setRootOrgId(rootOrgId);
|
|
|
|
+ userNotice.setHasRead(false);
|
|
|
|
+ userNotice.setNoticeId(noticeId);
|
|
|
|
+ userNotice.setUserType(userType);
|
|
|
|
+ userNotice.setUserId(userId);
|
|
|
|
+ return userNotice;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取发布对象
|
|
|
|
+ *
|
|
|
|
+ * @param rootOrgId
|
|
|
|
+ * @param noticeId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<Map<String, Object>> getPublishObject(Long rootOrgId,
|
|
|
|
+ NoticeReceiverRuleType ruleType, List<NoticeReceiverRuleEntity> ruleList) {
|
|
|
|
+ List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
+ Map<String, Object> objectMap;
|
|
|
|
+ List<NoticeReceiverRuleEntity> currentRuleList;
|
|
|
|
+ switch (ruleType) {
|
|
|
|
+ case STUDENTS_OF_EXAM:
|
|
|
|
+ currentRuleList = ruleList.stream().filter(p -> p.getRuleType() == ruleType)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ return getExamStudentObject(currentRuleList);
|
|
|
|
+ case ALL_STUDENTS_OF_ROOT_ORG:
|
|
|
|
+ objectMap = new HashMap<>();
|
|
|
|
+ objectMap.put("id", 0);
|
|
|
|
+ objectMap.put("name", "所有学生");
|
|
|
|
+ objectMap.put("ruleType", "ALL_STUDENTS_OF_ROOT_ORG");
|
|
|
|
+ resultList.add(objectMap);
|
|
|
|
+ return resultList;
|
|
|
|
+ case COMMON_USERS_OF_ROLE:
|
|
|
|
+ objectMap = new HashMap<>();
|
|
|
|
+ objectMap.put("id", 0);
|
|
|
|
+ objectMap.put("name", "所有学习中心用户");
|
|
|
|
+ objectMap.put("ruleType", "COMMON_USERS_OF_ROLE");
|
|
|
|
+ resultList.add(objectMap);
|
|
|
|
+ return resultList;
|
|
|
|
+ case TEACHER_OF_MARK_WORK:
|
|
|
|
+ currentRuleList = ruleList.stream().filter(p -> p.getRuleType() == ruleType)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ return getMarkTeacherObject(rootOrgId, currentRuleList);
|
|
|
|
+ }
|
|
|
|
+ return resultList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 组装学生发布对象
|
|
|
|
+ *
|
|
|
|
+ * @param ruleList
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<Map<String, Object>> getExamStudentObject(
|
|
|
|
+ List<NoticeReceiverRuleEntity> ruleList) {
|
|
|
|
+ List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
+ // 考试批次id
|
|
|
|
+ List<Long> examIdList = ruleList.stream().map(p -> Long.parseLong(p.getRuleValue()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ List<ExamEntity> examList = examRepo.findByIdIn(examIdList);
|
|
|
|
+ for (ExamEntity e : examList) {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("id", e.getId());
|
|
|
|
+ map.put("name", "学生-" + e.getName());
|
|
|
|
+ map.put("ruleType", "STUDENTS_OF_EXAM");
|
|
|
|
+ resultList.add(map);
|
|
|
|
+ }
|
|
|
|
+ return resultList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 组装阅卷老师发布对象
|
|
|
|
+ *
|
|
|
|
+ * @param rootOrgId
|
|
|
|
+ * @param ruleList
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<Map<String, Object>> getMarkTeacherObject(Long rootOrgId,
|
|
|
|
+ List<NoticeReceiverRuleEntity> ruleList) {
|
|
|
|
+ List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
+ List<Long> markWorkIdList = ruleList.stream().map(p -> Long.parseLong(p.getRuleValue()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ GetMarkWorkMainByIdsReq req = new GetMarkWorkMainByIdsReq();
|
|
|
|
+ req.setRootOrgId(rootOrgId);
|
|
|
|
+ req.setWorkIds(markWorkIdList);
|
|
|
|
+
|
|
|
|
+ GetMarkWorkMainByIdsResp markWorkResp = markWorkCloudService.getMarkWorkMainByIds(req);
|
|
|
|
+ List<MarkWorkMainBean> markWorkList = markWorkResp.getList();
|
|
|
|
+ for (MarkWorkMainBean mw : markWorkList) {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("id", mw.getId());
|
|
|
|
+ map.put("name", "老师-" + mw.getName());
|
|
|
|
+ map.put("ruleType", "TEACHER_OF_MARK_WORK");
|
|
|
|
+ resultList.add(map);
|
|
|
|
+ }
|
|
|
|
+ return resultList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据通知id获取通知
|
|
|
|
+ *
|
|
|
|
+ * @param noticeList
|
|
|
|
+ * @param noticeId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private NoticeEntity getNoticeById(List<NoticeEntity> noticeList, Long noticeId) {
|
|
|
|
+ Optional<NoticeEntity> optional = noticeList.stream()
|
|
|
|
+ .filter(p -> p.getId().equals(noticeId)).findFirst();
|
|
|
|
+ if (optional.isPresent()) {
|
|
|
|
+ return optional.get();
|
|
|
|
+ } else {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private NoticeRulePublishProgressEntity getNoticeRulePublishProgressEntityFrom(
|
|
|
|
+ AddNoticeInfo addNoticeInfo, Long noticeId) {
|
|
|
|
+ NoticeRulePublishProgressEntity progressEntity = new NoticeRulePublishProgressEntity();
|
|
|
|
+ progressEntity.setRootOrgId(addNoticeInfo.getRootOrgId());
|
|
|
|
+ progressEntity.setNoticeId(noticeId);
|
|
|
|
+ progressEntity.setNoticeReceiverRuleType(addNoticeInfo.getRuleType());
|
|
|
|
+ return progressEntity;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private NoticeEntity getNoticeEntityFrom(AddNoticeInfo addNoticeInfo) {
|
|
|
|
+ NoticeEntity noticeEntity = new NoticeEntity();
|
|
|
|
+ noticeEntity.setRootOrgId(addNoticeInfo.getRootOrgId());
|
|
|
|
+ noticeEntity.setTitle(addNoticeInfo.getTitle());
|
|
|
|
+ noticeEntity.setContent(addNoticeInfo.getContent());
|
|
|
|
+ noticeEntity.setNoticeStatus(addNoticeInfo.getNoticeStatus());
|
|
|
|
+ noticeEntity.setPublisher(addNoticeInfo.getPublisher());
|
|
|
|
+ // 只有为立即发布的才有发布时间
|
|
|
|
+ if (addNoticeInfo.getNoticeStatus() == NoticeStatus.TO_BE_PUBLISHED) {
|
|
|
|
+ noticeEntity.setPublishTime(new Date());
|
|
|
|
+ }
|
|
|
|
+ return noticeEntity;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<NoticeReceiverRuleEntity> getNoticeReceiverRuleEntityListFrom(
|
|
|
|
+ AddNoticeInfo addNoticeInfo, Long noticeId) {
|
|
|
|
+ List<NoticeReceiverRuleEntity> ruleList = new ArrayList<>();
|
|
|
|
+ // 如果发送对象规则类型为所有学生或学习中心不需要赋值
|
|
|
|
+ if (addNoticeInfo.getRuleType() == NoticeReceiverRuleType.ALL_STUDENTS_OF_ROOT_ORG
|
|
|
|
+ || addNoticeInfo.getRuleType() == NoticeReceiverRuleType.COMMON_USERS_OF_ROLE) {
|
|
|
|
+ NoticeReceiverRuleEntity ruleEntity = new NoticeReceiverRuleEntity();
|
|
|
|
+ ruleEntity.setRootOrgId(addNoticeInfo.getRootOrgId());
|
|
|
|
+ ruleEntity.setNoticeId(noticeId);
|
|
|
|
+ ruleEntity.setRuleType(addNoticeInfo.getRuleType());
|
|
|
|
+ ruleEntity.setRuleValue(null);
|
|
|
|
+ ruleList.add(ruleEntity);
|
|
|
|
+ } else {
|
|
|
|
+ String publishObjectIds = getStandardIds(addNoticeInfo.getPublishObjectId(), ",");
|
|
|
|
+ String[] publishObjectIdArr = publishObjectIds.split(",");
|
|
|
|
+ for (String publishObjectId : publishObjectIdArr) {
|
|
|
|
+ NoticeReceiverRuleEntity ruleEntity = new NoticeReceiverRuleEntity();
|
|
|
|
+ ruleEntity.setRootOrgId(addNoticeInfo.getRootOrgId());
|
|
|
|
+ ruleEntity.setNoticeId(noticeId);
|
|
|
|
+ ruleEntity.setRuleType(addNoticeInfo.getRuleType());
|
|
|
|
+ ruleEntity.setRuleValue(publishObjectId);
|
|
|
|
+ ruleList.add(ruleEntity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return ruleList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取标准的id字符串,去掉最后一个字符
|
|
|
|
+ *
|
|
|
|
+ * @param strIds id字符串
|
|
|
|
+ * @param separator 分隔符
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private String getStandardIds(String strIds, String separator) {
|
|
|
|
+ if (!StringUtils.isNullOrEmpty(strIds)) {
|
|
|
|
+ if (strIds.lastIndexOf(separator) == strIds.length() - 1) {
|
|
|
|
+ return strIds.substring(0, strIds.lastIndexOf(separator));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return strIds;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private NoticeRulePublishProgressEntity getNoticeRulePublishProgressEntityFrom(
|
|
|
|
+ UpdateNoticeInfo info) {
|
|
|
|
+ NoticeRulePublishProgressEntity publishScheduleEntity = new NoticeRulePublishProgressEntity();
|
|
|
|
+ publishScheduleEntity.setRootOrgId(info.getRootOrgId());
|
|
|
|
+ publishScheduleEntity.setNoticeId(info.getId());
|
|
|
|
+ publishScheduleEntity.setNoticeReceiverRuleType(info.getRuleType());
|
|
|
|
+ return publishScheduleEntity;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<NoticeReceiverRuleEntity> getNoticeReceiverRuleEntityListFrom(
|
|
|
|
+ UpdateNoticeInfo info) {
|
|
|
|
+ List<NoticeReceiverRuleEntity> ruleList = new ArrayList<>();
|
|
|
|
+ // 如果发送对象规则类型为所有学生或学习中心不需要赋值
|
|
|
|
+ if (info.getRuleType() == NoticeReceiverRuleType.ALL_STUDENTS_OF_ROOT_ORG
|
|
|
|
+ || info.getRuleType() == NoticeReceiverRuleType.COMMON_USERS_OF_ROLE) {
|
|
|
|
+ NoticeReceiverRuleEntity ruleEntity = new NoticeReceiverRuleEntity();
|
|
|
|
+ ruleEntity.setRootOrgId(info.getRootOrgId());
|
|
|
|
+ ruleEntity.setNoticeId(info.getId());
|
|
|
|
+ ruleEntity.setRuleType(info.getRuleType());
|
|
|
|
+ ruleEntity.setRuleValue(null);
|
|
|
|
+ ruleList.add(ruleEntity);
|
|
|
|
+ } else {
|
|
|
|
+ String publishObjectIds = getStandardIds(info.getPublishObjectId(), ",");
|
|
|
|
+ String[] publishObjectIdArr = publishObjectIds.split(",");
|
|
|
|
+ for (String publishObjectId : publishObjectIdArr) {
|
|
|
|
+ NoticeReceiverRuleEntity ruleEntity = new NoticeReceiverRuleEntity();
|
|
|
|
+ ruleEntity.setRootOrgId(info.getRootOrgId());
|
|
|
|
+ ruleEntity.setNoticeId(info.getId());
|
|
|
|
+ ruleEntity.setRuleType(info.getRuleType());
|
|
|
|
+ ruleEntity.setRuleValue(publishObjectId);
|
|
|
|
+ ruleList.add(ruleEntity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return ruleList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<NoticeReceiverRuleEntity> getReceiverRuleList(Long rootOrgId, Long... noticeId) {
|
|
|
|
+ List<NoticeReceiverRuleEntity> ruleList = noticeReceiverRuleRepo
|
|
|
|
+ .findByRootOrgIdAndNoticeIdIn(rootOrgId, Arrays.asList(noticeId));
|
|
|
|
+ if (ruleList == null) {
|
|
|
|
+ throw new StatusException("501009", "找不到通知id为:" + noticeId + "的通知对象信息");
|
|
|
|
+ }
|
|
|
|
+ return ruleList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private NoticeReceiverRuleType getNoticeReceiverRuleType(Long noticeId,
|
|
|
|
+ List<NoticeReceiverRuleEntity> ruleList) {
|
|
|
|
+ Optional<NoticeReceiverRuleType> first = ruleList.stream()
|
|
|
|
+ .filter(p -> p.getNoticeId().equals(noticeId)).map(p -> p.getRuleType())
|
|
|
|
+ .findFirst();
|
|
|
|
+ if (first.isPresent()) {
|
|
|
|
+ return first.get();
|
|
|
|
+ } else {
|
|
|
|
+ throw new StatusException("501012", "找不到通知id为:" + noticeId + "的通知规则类型");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|