Browse Source

。。。。

WANG 5 years ago
parent
commit
ac31b66217

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

@@ -41,218 +41,220 @@ import java.util.stream.Collectors;
 @Api(tags = "公告类")
 @RequestMapping("${$rmp.ctr.examwork}/notice")
 public class NoticeController extends ControllerSupport {
-    @Autowired
-    private NoticeService noticeService;
+	@Autowired
+	private NoticeService noticeService;
 
-    @Autowired
-    private NoticeRepo noticeRepo;
+	@Autowired
+	private NoticeRepo noticeRepo;
 
-    @ApiOperation(value = "分页查询消息列表", notes = "带条件带分页")
-    @GetMapping("getPagedNoticeList/{curPage}/{pageSize}")
-    public PageInfo<NoticeDomain> getPagedNoticeList(@PathVariable Integer curPage,
-                                                     @PathVariable Integer pageSize, NoticeDomainQuery query) {
-        User accessUser = this.getAccessUser();
-        NoticeInfoQuery infoQuery = new NoticeInfoQuery();
-        infoQuery.setTitle(query.getTitle());
-        infoQuery.setRootOrgId(accessUser.getRootOrgId());
-        infoQuery.setUserId(accessUser.getUserId());
-        PageInfo<NoticeInfo> pagedNoticeInfo = noticeService.getPagedNoticeList(curPage, pageSize, infoQuery);
-        return getPageInfoFrom(pagedNoticeInfo);
-    }
+	@ApiOperation(value = "分页查询消息列表", notes = "带条件带分页")
+	@GetMapping("getPagedNoticeList/{curPage}/{pageSize}")
+	public PageInfo<NoticeDomain> getPagedNoticeList(@PathVariable Integer curPage,
+			@PathVariable Integer pageSize, NoticeDomainQuery query) {
+		User accessUser = this.getAccessUser();
+		NoticeInfoQuery infoQuery = new NoticeInfoQuery();
+		infoQuery.setTitle(query.getTitle());
+		infoQuery.setRootOrgId(accessUser.getRootOrgId());
+		infoQuery.setUserId(accessUser.getUserId());
+		PageInfo<NoticeInfo> pagedNoticeInfo = noticeService.getPagedNoticeList(curPage, pageSize,
+				infoQuery);
+		return getPageInfoFrom(pagedNoticeInfo);
+	}
 
-    @ApiOperation(value = "修改通知信息")
-    @PostMapping("disposeNotice")
-    public void disposeNotice() {
-//        noticeService.disposePublishingUserNotice();
-    }
+	@ApiOperation(value = "添加新通知")
+	@PostMapping("addNotice")
+	public void addNotice(@Validated @RequestBody AddNoticeDomain addNoticeDomain) {
+		validateAddNotice(addNoticeDomain);
 
+		AddNoticeInfo info = getAddNoticeInfoFrom(addNoticeDomain);
+		int result = noticeService.addNotice(info);
+		if (result == 0) {
+			throw new StatusException("500008", "添加新通知失败");
+		}
+	}
 
-    @ApiOperation(value = "添加新通知")
-    @PostMapping("addNotice")
-    public void addNotice(@Validated @RequestBody AddNoticeDomain addNoticeDomain) {
-        validateAddNotice(addNoticeDomain);
+	@ApiOperation(value = "修改通知信息")
+	@PostMapping("updateNotice")
+	public void updateNotice(@Validated @RequestBody UpdateNoticeDomain updateNoticeDomain) {
+		validateUpdateNotice(updateNoticeDomain);
 
-        AddNoticeInfo info = getAddNoticeInfoFrom(addNoticeDomain);
-        int result =noticeService.addNotice(info);
-        if (result==0){
-            throw new StatusException("500008","添加新通知失败");
-        }
-    }
+		UpdateNoticeInfo info = getUpdateNoticeInfoFrom(updateNoticeDomain);
+		noticeService.updateNotice(info);
+	}
 
-    @ApiOperation(value = "修改通知信息")
-    @PostMapping("updateNotice")
-    public void updateNotice(@Validated @RequestBody UpdateNoticeDomain updateNoticeDomain) {
-        validateUpdateNotice(updateNoticeDomain);
+	@ApiOperation(value = "删除通知信息")
+	@DeleteMapping("/{noticeId}")
+	public void deleteNotice(
+			@Validated @ApiParam(value = "通知id,多个以逗号分隔") @PathVariable(required = true) String noticeId) {
+		List<Long> noticeIdList = validateDeleteNotice(noticeId);
+		noticeService.deleteNotice(getRootOrgId(), noticeIdList);
+	}
 
-        UpdateNoticeInfo info = getUpdateNoticeInfoFrom(updateNoticeDomain);
-        noticeService.updateNotice(info);
-    }
+	@GetMapping("getUserNoticeList")
+	@ApiOperation(value = "获取用户公告列表")
+	public List<UserNoticeDomain> getUserNoticeList(UserNoticeDomainQuery query) {
+		List<UserNoticeDomain> resultList = new ArrayList<>();
+		UserNoticeInfoQuery noticeQuery = getNoticeInfoQueryFrom(query);
 
-    @ApiOperation(value = "删除通知信息")
-    @DeleteMapping("/{noticeId}")
-    public void deleteNotice(@Validated @ApiParam(value = "通知id,多个以逗号分隔") @PathVariable(required = true) String noticeId) {
-        List<Long> noticeIdList= validateDeleteNotice(noticeId);
-        noticeService.deleteNotice(getRootOrgId(),noticeIdList);
-    }
+		List<UserNoticeInfo> noticeInfoList = noticeService.getNoticeList(noticeQuery);
 
-    @GetMapping("getUserNoticeList")
-    @ApiOperation(value = "获取用户公告列表")
-    public List<UserNoticeDomain> getUserNoticeList(UserNoticeDomainQuery query) {
-        List<UserNoticeDomain> resultList = new ArrayList<>();
-        UserNoticeInfoQuery noticeQuery = getNoticeInfoQueryFrom(query);
+		if (null != noticeInfoList && !noticeInfoList.isEmpty()) {
+			resultList = getNoticeDomainListFrom(noticeInfoList);
+		}
+		return resultList;
+	}
 
-        List<UserNoticeInfo> noticeInfoList = noticeService.getNoticeList(noticeQuery);
+	@PostMapping("updateNoticeReadStatus")
+	@ApiOperation(value = "更新通知状态为已读")
+	public void updateNoticeReadStatus(
+			@ApiParam(value = "通知id,多个以逗号分隔") @RequestParam(required = true) String noticeId) {
+		if (StringUtils.isNullOrEmpty(noticeId)) {
+			throw new StatusException("500001", "通知id不允许为空");
+		}
+		User user = this.getAccessUser();
+		noticeService.updateNoticeReadStatus(noticeId, user.getUserType(), user.getUserId());
+	}
 
-        if (null != noticeInfoList && !noticeInfoList.isEmpty()) {
-            resultList = getNoticeDomainListFrom(noticeInfoList);
-        }
-        return resultList;
-    }
+	private UserNoticeInfoQuery getNoticeInfoQueryFrom(UserNoticeDomainQuery query) {
+		User user = this.getAccessUser();
+		UserNoticeInfoQuery noticeQuery = new UserNoticeInfoQuery();
+		noticeQuery.setHasRead(query.getHasRead());
+		noticeQuery.setRootOrgId(user.getRootOrgId());
+		noticeQuery.setUserId(user.getUserId());
+		noticeQuery.setUserType(user.getUserType());
+		return noticeQuery;
+	}
 
-    @PostMapping("updateNoticeReadStatus")
-    @ApiOperation(value = "更新通知状态为已读")
-    public void updateNoticeReadStatus(@ApiParam(value = "通知id,多个以逗号分隔") @RequestParam(required = true) String noticeId) {
-        if (StringUtils.isNullOrEmpty(noticeId)) {
-            throw new StatusException("500001", "通知id不允许为空");
-        }
-        User user = this.getAccessUser();
-        noticeService.updateNoticeReadStatus(noticeId, user.getUserType(), user.getUserId());
-    }
+	private AddNoticeInfo getAddNoticeInfoFrom(AddNoticeDomain addNoticeDomain) {
+		AddNoticeInfo info = new AddNoticeInfo();
+		User accessUser = this.getAccessUser();
+		info.setContent(addNoticeDomain.getContent());
+		info.setPublisher(addNoticeDomain.getPublisher());
+		info.setPublishObjectId(addNoticeDomain.getPublishObjectId());
+		info.setRootOrgId(accessUser.getRootOrgId());
+		info.setRuleType(addNoticeDomain.getRuleType());
+		info.setUserId(accessUser.getUserId());
+		info.setNoticeStatus(addNoticeDomain.getNoticeStatus());
+		info.setTitle(addNoticeDomain.getTitle());
+		return info;
+	}
 
-    private UserNoticeInfoQuery getNoticeInfoQueryFrom(UserNoticeDomainQuery query) {
-        User user = this.getAccessUser();
-        UserNoticeInfoQuery noticeQuery = new UserNoticeInfoQuery();
-        noticeQuery.setHasRead(query.getHasRead());
-        noticeQuery.setRootOrgId(user.getRootOrgId());
-        noticeQuery.setUserId(user.getUserId());
-        noticeQuery.setUserType(user.getUserType());
-        return noticeQuery;
-    }
+	private UpdateNoticeInfo getUpdateNoticeInfoFrom(UpdateNoticeDomain updateNoticeDomain) {
+		UpdateNoticeInfo info = new UpdateNoticeInfo();
+		User accessUser = this.getAccessUser();
+		info.setId(updateNoticeDomain.getId());
+		info.setTitle(updateNoticeDomain.getTitle());
+		info.setContent(updateNoticeDomain.getContent());
+		info.setPublisher(updateNoticeDomain.getPublisher());
+		info.setPublishObjectId(updateNoticeDomain.getPublishObjectId());
+		info.setRootOrgId(accessUser.getRootOrgId());
+		info.setRuleType(updateNoticeDomain.getRuleType());
+		info.setUserId(accessUser.getUserId());
+		info.setNoticeStatus(updateNoticeDomain.getNoticeStatus());
+		return info;
+	}
 
-    private AddNoticeInfo getAddNoticeInfoFrom(AddNoticeDomain addNoticeDomain) {
-        AddNoticeInfo info = new AddNoticeInfo();
-        User accessUser = this.getAccessUser();
-        info.setContent(addNoticeDomain.getContent());
-        info.setPublisher(addNoticeDomain.getPublisher());
-        info.setPublishObjectId(addNoticeDomain.getPublishObjectId());
-        info.setRootOrgId(accessUser.getRootOrgId());
-        info.setRuleType(addNoticeDomain.getRuleType());
-        info.setUserId(accessUser.getUserId());
-        info.setNoticeStatus(addNoticeDomain.getNoticeStatus());
-        info.setTitle(addNoticeDomain.getTitle());
-        return info;
-    }
+	private List<UserNoticeDomain> getNoticeDomainListFrom(List<UserNoticeInfo> noticeInfoList) {
+		List<UserNoticeDomain> resultList = new ArrayList<>();
+		for (UserNoticeInfo info : noticeInfoList) {
+			UserNoticeDomain domain = new UserNoticeDomain();
+			domain.setContent(info.getContent());
+			domain.setId(info.getId());
+			domain.setPublisher(info.getPublisher());
+			domain.setPublishTime(info.getPublishTime());
+			domain.setHasRead(info.getHasRead());
+			domain.setTitle(info.getTitle());
+			resultList.add(domain);
+		}
+		return resultList;
+	}
 
-    private UpdateNoticeInfo getUpdateNoticeInfoFrom(UpdateNoticeDomain updateNoticeDomain) {
-        UpdateNoticeInfo info = new UpdateNoticeInfo();
-        User accessUser = this.getAccessUser();
-        info.setId(updateNoticeDomain.getId());
-        info.setTitle(updateNoticeDomain.getTitle());
-        info.setContent(updateNoticeDomain.getContent());
-        info.setPublisher(updateNoticeDomain.getPublisher());
-        info.setPublishObjectId(updateNoticeDomain.getPublishObjectId());
-        info.setRootOrgId(accessUser.getRootOrgId());
-        info.setRuleType(updateNoticeDomain.getRuleType());
-        info.setUserId(accessUser.getUserId());
-        info.setNoticeStatus(updateNoticeDomain.getNoticeStatus());
-        return info;
-    }
-    private List<UserNoticeDomain> getNoticeDomainListFrom(List<UserNoticeInfo> noticeInfoList) {
-        List<UserNoticeDomain> resultList = new ArrayList<>();
-        for (UserNoticeInfo info : noticeInfoList) {
-            UserNoticeDomain domain = new UserNoticeDomain();
-            domain.setContent(info.getContent());
-            domain.setId(info.getId());
-            domain.setPublisher(info.getPublisher());
-            domain.setPublishTime(info.getPublishTime());
-            domain.setHasRead(info.getHasRead());
-            domain.setTitle(info.getTitle());
-            resultList.add(domain);
-        }
-        return resultList;
-    }
+	private PageInfo<NoticeDomain> getPageInfoFrom(PageInfo<NoticeInfo> pagedNoticeInfo) {
+		PageInfo<NoticeDomain> resultPageInfo = new PageInfo<>();
+		resultPageInfo.setTotal(pagedNoticeInfo.getTotal());
+		resultPageInfo.setIndex(pagedNoticeInfo.getIndex());
+		resultPageInfo.setLimit(pagedNoticeInfo.getLimit());
+		resultPageInfo.setPages(pagedNoticeInfo.getPages());
+		resultPageInfo.setSize(pagedNoticeInfo.getSize());
+		List<NoticeInfo> infoList = pagedNoticeInfo.getList();
+		List<NoticeDomain> domainList = new ArrayList<>();
+		if (infoList != null && !infoList.isEmpty()) {
+			for (NoticeInfo ni : infoList) {
+				NoticeDomain domain = new NoticeDomain();
+				domain.setId(ni.getId());
+				domain.setPublisher(ni.getPublisher());
+				domain.setPublishStatus(ni.getPublishStatus());
+				domain.setPublishTime(ni.getPublishTime());
+				domain.setTitle(ni.getTitle());
+				domain.setPublishObject(ni.getPublishObject());
+				domain.setRuleType(ni.getRuleType());
+				domain.setContent(ni.getContent());
+				domainList.add(domain);
+			}
+		}
+		resultPageInfo.setList(domainList);
+		return resultPageInfo;
+	}
 
-    private PageInfo<NoticeDomain> getPageInfoFrom(PageInfo<NoticeInfo> pagedNoticeInfo) {
-        PageInfo<NoticeDomain> resultPageInfo = new PageInfo<>();
-        resultPageInfo.setTotal(pagedNoticeInfo.getTotal());
-        resultPageInfo.setIndex(pagedNoticeInfo.getIndex());
-        resultPageInfo.setLimit(pagedNoticeInfo.getLimit());
-        resultPageInfo.setPages(pagedNoticeInfo.getPages());
-        resultPageInfo.setSize(pagedNoticeInfo.getSize());
-        List<NoticeInfo> infoList = pagedNoticeInfo.getList();
-        List<NoticeDomain> domainList = new ArrayList<>();
-        if (infoList != null && !infoList.isEmpty()) {
-            for (NoticeInfo ni : infoList) {
-                NoticeDomain domain = new NoticeDomain();
-                domain.setId(ni.getId());
-                domain.setPublisher(ni.getPublisher());
-                domain.setPublishStatus(ni.getPublishStatus());
-                domain.setPublishTime(ni.getPublishTime());
-                domain.setTitle(ni.getTitle());
-                domain.setPublishObject(ni.getPublishObject());
-                domain.setRuleType(ni.getRuleType());
-                domain.setContent(ni.getContent());
-                domainList.add(domain);
-            }
-        }
-        resultPageInfo.setList(domainList);
-        return resultPageInfo;
-    }
+	private void validateAddNotice(AddNoticeDomain addNoticeDomain) {
+		if (addNoticeDomain.getRuleType() == NoticeReceiverRuleType.STUDENTS_OF_EXAM
+				|| addNoticeDomain.getRuleType() == NoticeReceiverRuleType.TEACHER_OF_MARK_WORK) {
+			if (StringUtils.isNullOrEmpty(addNoticeDomain.getPublishObjectId())) {
+				throw new StatusException("500009", "发送对象不允许为空");
+			}
+		}
+		String content = addNoticeDomain.getContent();
+		String simpleText = Jsoup.clean(content, Whitelist.simpleText());
+		// 普通文本内容不允许超过500个字
+		if (simpleText.length() > 500) {
+			throw new StatusException("500010", "通知内容不得超过500个字符");
+		}
+		// TODO 加上总长度校验(5M,找张莹确定)
+	}
 
-    private void validateAddNotice(AddNoticeDomain addNoticeDomain) {
-        if (addNoticeDomain.getRuleType()== NoticeReceiverRuleType.STUDENTS_OF_EXAM
-                || addNoticeDomain.getRuleType()==NoticeReceiverRuleType.TEACHER_OF_MARK_WORK){
-            if (StringUtils.isNullOrEmpty(addNoticeDomain.getPublishObjectId()) ){
-                throw new StatusException("500009","发送对象不允许为空");
-            }
-        }
-        String content = addNoticeDomain.getContent();
-        String simpleText =  Jsoup.clean(content, Whitelist.simpleText());
-        //普通文本内容不允许超过500个字
-        if (simpleText.length()>500){
-            throw new StatusException("500010","通知内容不得超过500个字符");
-        }
-        //TODO 加上总长度校验(5M,找张莹确定)
-    }
-    private void validateUpdateNotice(UpdateNoticeDomain updateNoticeDomain) {
-        if (updateNoticeDomain.getRuleType()== NoticeReceiverRuleType.STUDENTS_OF_EXAM
-                || updateNoticeDomain.getRuleType()==NoticeReceiverRuleType.TEACHER_OF_MARK_WORK){
-            if (StringUtils.isNullOrEmpty(updateNoticeDomain.getPublishObjectId()) ){
-                throw new StatusException("500011","发送对象不允许为空");
-            }
-        }
-        String content = updateNoticeDomain.getContent();
-        String simpleText =  Jsoup.clean(content, Whitelist.simpleText());
-        //普通文本内容不允许超过500个字 TODO 该方法待校验,因为不确定富文本框中图片的保存格式
-        if (simpleText.length()>500){
-            throw new StatusException("500012","通知内容不得超过500个字符");
-        }
-        //TODO 校验总大小
-        NoticeEntity notice = GlobalHelper.getEntity(noticeRepo, updateNoticeDomain.getId(), NoticeEntity.class);
-        if (notice==null){
-            throw new StatusException("500013","该通知已不存在,请刷新后重试");
-        }
-        if (notice.getNoticeStatus()!= NoticeStatus.DRAFT){
-            throw new StatusException("500014","该通知状态已变更,请刷新后重试");
-        }
-    }
-    private List<Long> validateDeleteNotice(String noticeId){
-        if (noticeId.indexOf(",")>-1 && noticeId.lastIndexOf(",")==noticeId.length()-1){
-            noticeId=noticeId.substring(0, noticeId.length()-1);
-        }
-        String[] noticeIdArr = noticeId.split(",");
-        List<Long> noticeIdList = null;
-        try {
-            noticeIdList = Arrays.asList(noticeIdArr).stream()
-                    .map(p -> Long.parseLong(p)).collect(Collectors.toList());
-        } catch (Exception e) {
-            throw new StatusException("500015","通知id格式不正确",e);
-        }
-        List<NoticeEntity> noticeList = noticeRepo.findByIdIn(noticeIdList);
-        boolean existPublishingData = noticeList.stream().anyMatch(p->p.getNoticeStatus()!=NoticeStatus.DRAFT);
-        if (existPublishingData){
-            throw new StatusException("500016","通知状态已改变,请刷新后重试");
-        }
-        return noticeIdList;
-    }
+	private void validateUpdateNotice(UpdateNoticeDomain updateNoticeDomain) {
+		if (updateNoticeDomain.getRuleType() == NoticeReceiverRuleType.STUDENTS_OF_EXAM
+				|| updateNoticeDomain
+						.getRuleType() == NoticeReceiverRuleType.TEACHER_OF_MARK_WORK) {
+			if (StringUtils.isNullOrEmpty(updateNoticeDomain.getPublishObjectId())) {
+				throw new StatusException("500011", "发送对象不允许为空");
+			}
+		}
+		String content = updateNoticeDomain.getContent();
+		String simpleText = Jsoup.clean(content, Whitelist.simpleText());
+		// 普通文本内容不允许超过500个字 TODO 该方法待校验,因为不确定富文本框中图片的保存格式
+		if (simpleText.length() > 500) {
+			throw new StatusException("500012", "通知内容不得超过500个字符");
+		}
+		// TODO 校验总大小
+		NoticeEntity notice = GlobalHelper.getEntity(noticeRepo, updateNoticeDomain.getId(),
+				NoticeEntity.class);
+		if (notice == null) {
+			throw new StatusException("500013", "该通知已不存在,请刷新后重试");
+		}
+		if (notice.getNoticeStatus() != NoticeStatus.DRAFT) {
+			throw new StatusException("500014", "该通知状态已变更,请刷新后重试");
+		}
+	}
+
+	private List<Long> validateDeleteNotice(String noticeId) {
+		if (noticeId.indexOf(",") > -1 && noticeId.lastIndexOf(",") == noticeId.length() - 1) {
+			noticeId = noticeId.substring(0, noticeId.length() - 1);
+		}
+		String[] noticeIdArr = noticeId.split(",");
+		List<Long> noticeIdList = null;
+		try {
+			noticeIdList = Arrays.asList(noticeIdArr).stream().map(p -> Long.parseLong(p))
+					.collect(Collectors.toList());
+		} catch (Exception e) {
+			throw new StatusException("500015", "通知id格式不正确", e);
+		}
+		List<NoticeEntity> noticeList = noticeRepo.findByIdIn(noticeIdList);
+		boolean existPublishingData = noticeList.stream()
+				.anyMatch(p -> p.getNoticeStatus() != NoticeStatus.DRAFT);
+		if (existPublishingData) {
+			throw new StatusException("500016", "通知状态已改变,请刷新后重试");
+		}
+		return noticeIdList;
+	}
 }