|
@@ -0,0 +1,109 @@
|
|
|
+package cn.com.qmth.examcloud.core.examwork.service.impl;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.api.commons.exchange.PageInfo;
|
|
|
+import cn.com.qmth.examcloud.api.commons.security.bean.UserType;
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.commons.util.DBUtil;
|
|
|
+import cn.com.qmth.examcloud.commons.util.StringUtil;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.NoticePublishScheduleRepo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.NoticeRepo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.UserNoticeRepo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.NoticeEntity;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.NoticePublishScheduleEntity;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.UserNoticeEntity;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.service.NoticeService;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.service.bean.NoticeInfo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.service.bean.NoticeInfoQuery;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.service.bean.UserNoticeInfo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.service.bean.UserNoticeInfoQuery;
|
|
|
+import com.mysql.cj.util.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
+
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description 通知实现类
|
|
|
+ * @Author lideyin
|
|
|
+ * @Date 2019/7/2 17:41
|
|
|
+ * @Version 1.0
|
|
|
+ */
|
|
|
+public class NoticeServiceImpl implements NoticeService {
|
|
|
+ @Autowired
|
|
|
+ private NoticeRepo noticeRepo;
|
|
|
+ @Autowired
|
|
|
+ private UserNoticeRepo userNoticeRepo;
|
|
|
+ @Autowired
|
|
|
+ private NoticePublishScheduleRepo noticePublishScheduleRepo;
|
|
|
+ @Override
|
|
|
+ public List<UserNoticeInfo> getNoticeList(UserNoticeInfoQuery query) {
|
|
|
+ List<UserNoticeInfo> resultList = new ArrayList<>();
|
|
|
+ List<UserNoticeEntity> userNoticeList;
|
|
|
+ if (query.getRead()!=null){
|
|
|
+ userNoticeList = userNoticeRepo.findByRootOrgIdAndUserTypeAndUserIdAndRead(query.getRootOrgId(),query.getUserType(), query.getUserId(),query.getRead());
|
|
|
+ }else {
|
|
|
+ userNoticeList = userNoticeRepo.findByRootOrgIdAndUserTypeAndUserId(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("500001","找不到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.setRead(un.getRead());
|
|
|
+ resultList.add(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int updateNoticeReadStatus(String noticeId, UserType userType, Long userId) {
|
|
|
+ return userNoticeRepo.updateNoticeReadStatus(noticeId,userType,userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageInfo<NoticeInfo> getPagedNoticeList(Integer curPage, Integer pageSize, NoticeInfoQuery infoQuery) {
|
|
|
+ Specification<NoticeEntity> specification = (root,query,cb)->{
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"),infoQuery.getPublishStatus()));
|
|
|
+ if (!StringUtils.isNullOrEmpty(infoQuery.getTitle())){
|
|
|
+ predicates.add(cb.like(root.get("title"), DBUtil.toSqlSearchPattern(infoQuery.getTitle())));
|
|
|
+ }
|
|
|
+ if(null!=infoQuery.getPublishStatus()){
|
|
|
+ List<NoticePublishScheduleEntity> byPublishStatusNoticeScheduleList = noticePublishScheduleRepo.findByRootOrgIdAndPublishStatus(infoQuery.getRootOrgId(), infoQuery.getPublishStatus());
|
|
|
+ if (null == byPublishStatusNoticeScheduleList || byPublishStatusNoticeScheduleList.isEmpty()){
|
|
|
+ throw new StatusException("500001","通知发布状态数据异常");
|
|
|
+ }
|
|
|
+ //获取相应发布状态的通知id集合
|
|
|
+ List<Long> noticeIdList = byPublishStatusNoticeScheduleList.stream().map(NoticePublishScheduleEntity::getNoticeId).collect(Collectors.toList());
|
|
|
+ // predicates.add(cb.in());
|
|
|
+ }
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+ //TODO
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|