|
@@ -7,40 +7,54 @@
|
|
|
|
|
|
package cn.com.qmth.examcloud.core.examwork.api.controller;
|
|
|
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import org.jsoup.Jsoup;
|
|
|
+import org.jsoup.safety.Whitelist;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import com.mysql.cj.util.StringUtils;
|
|
|
+
|
|
|
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.User;
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.api.controller.bean.*;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.api.controller.bean.AddNoticeDomain;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.api.controller.bean.NoticeDomain;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.api.controller.bean.NoticeDomainQuery;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.api.controller.bean.UpdateNoticeDomain;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.api.controller.bean.UserNoticeDomain;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.api.controller.bean.UserNoticeDomainQuery;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.NoticeRepo;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.entity.NoticeEntity;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.entity.NoticeRulePublishProgressEntity;
|
|
|
import cn.com.qmth.examcloud.core.examwork.service.NoticeService;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.service.bean.*;
|
|
|
-import cn.com.qmth.examcloud.examwork.api.bean.NoticeRulePublishProgressBean;
|
|
|
-import cn.com.qmth.examcloud.examwork.api.request.DisposePublishingUserNoticeReq;
|
|
|
-import cn.com.qmth.examcloud.examwork.api.response.DisposePublishingUserNoticeResp;
|
|
|
-import cn.com.qmth.examcloud.examwork.api.response.GetNoticeRulePublishProgressListResp;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.service.bean.AddNoticeInfo;
|
|
|
+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.UpdateNoticeInfo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.service.bean.UserNoticeInfo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.service.bean.UserNoticeInfoQuery;
|
|
|
import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
import cn.com.qmth.examcloud.web.support.Naked;
|
|
|
-import com.mysql.cj.util.StringUtils;
|
|
|
-import io.micrometer.core.instrument.util.DoubleFormat;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
-import org.jsoup.Jsoup;
|
|
|
-import org.jsoup.safety.Whitelist;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-
|
|
|
-import java.text.DecimalFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 公告类
|
|
@@ -49,302 +63,305 @@ import java.util.stream.Collectors;
|
|
|
@Api(tags = "公告类")
|
|
|
@RequestMapping("${$rmp.ctr.examwork}/notice")
|
|
|
public class NoticeController extends ControllerSupport {
|
|
|
- @Autowired
|
|
|
- private NoticeService noticeService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private NoticeRepo noticeRepo;
|
|
|
+ @Autowired
|
|
|
+ private NoticeService noticeService;
|
|
|
|
|
|
- @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);
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private NoticeRepo noticeRepo;
|
|
|
|
|
|
- @ApiOperation(value = "添加新通知")
|
|
|
- @PostMapping("addNotice")
|
|
|
- public void addNotice(@Validated @RequestBody AddNoticeDomain addNoticeDomain) {
|
|
|
- validateAddNotice(addNoticeDomain);
|
|
|
+ @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);
|
|
|
+ }
|
|
|
|
|
|
- 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;
|
|
|
+ }
|
|
|
|
|
|
- @ApiOperation(value = "获取消息")
|
|
|
- @GetMapping("{noticeId}")
|
|
|
- public NoticeDomain getNotice(@PathVariable Long noticeId) {
|
|
|
- NoticeEntity ni = GlobalHelper.getEntity(noticeRepo, noticeId,
|
|
|
- NoticeEntity.class);
|
|
|
- if (ni == null) {
|
|
|
- throw new StatusException("600001", "该通知已不存在,请刷新后重试");
|
|
|
- }
|
|
|
- NoticeDomain domain = new NoticeDomain();
|
|
|
- domain.setId(ni.getId());
|
|
|
- domain.setPublisher(ni.getPublisher());
|
|
|
- domain.setPublishStatus(ni.getNoticeStatus());
|
|
|
- domain.setPublishTime(ni.getPublishTime());
|
|
|
- domain.setTitle(ni.getTitle());
|
|
|
- domain.setContent(ni.getContent());
|
|
|
- return domain;
|
|
|
- }
|
|
|
+ @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());
|
|
|
+ }
|
|
|
|
|
|
+ @ApiOperation(value = "获取消息")
|
|
|
+ @GetMapping("{noticeId}")
|
|
|
+ public NoticeDomain getNotice(@PathVariable Long noticeId) {
|
|
|
+ NoticeEntity ni = GlobalHelper.getEntity(noticeRepo, noticeId, NoticeEntity.class);
|
|
|
+ if (ni == null) {
|
|
|
+ throw new StatusException("600001", "该通知已不存在,请刷新后重试");
|
|
|
+ }
|
|
|
+ NoticeDomain domain = new NoticeDomain();
|
|
|
+ domain.setId(ni.getId());
|
|
|
+ domain.setPublisher(ni.getPublisher());
|
|
|
+ domain.setPublishStatus(ni.getNoticeStatus());
|
|
|
+ domain.setPublishTime(ni.getPublishTime());
|
|
|
+ domain.setTitle(ni.getTitle());
|
|
|
+ domain.setContent(ni.getContent());
|
|
|
+ return domain;
|
|
|
+ }
|
|
|
|
|
|
- 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 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 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 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 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 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 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个字符");
|
|
|
- }
|
|
|
- // 总大小不得超过5M
|
|
|
- if (content.getBytes().length > 5 * 1024) {
|
|
|
- DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
|
|
- String currentLength = decimalFormat.format((double) content.getBytes().length / (double) 1024);
|
|
|
- throw new StatusException("500010", "通知内容总大小不得超过5MB,当前大小为:"+currentLength+"MB");
|
|
|
- }
|
|
|
- }
|
|
|
- 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个字符");
|
|
|
- }
|
|
|
- // 总大小不得超过5M
|
|
|
- if (content.getBytes().length > 5 * 1024) {
|
|
|
- DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
|
|
- String currentLength = decimalFormat.format((double) content.getBytes().length / (double) 1024);
|
|
|
- throw new StatusException("500010", "通知内容总大小不得超过5MB,当前大小为:"+currentLength+"MB");
|
|
|
- }
|
|
|
+ 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个字符");
|
|
|
+ }
|
|
|
+ // 总大小不得超过5M
|
|
|
+ if (content.getBytes().length > 5 * 1024) {
|
|
|
+ DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
|
|
+ String currentLength = decimalFormat
|
|
|
+ .format((double) content.getBytes().length / (double) 1024);
|
|
|
+ throw new StatusException("500010", "通知内容总大小不得超过5MB,当前大小为:" + currentLength + "MB");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- 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 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个字符");
|
|
|
+ }
|
|
|
+ // 总大小不得超过5M
|
|
|
+ if (content.getBytes().length > 5 * 1024) {
|
|
|
+ DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
|
|
+ String currentLength = decimalFormat
|
|
|
+ .format((double) content.getBytes().length / (double) 1024);
|
|
|
+ throw new StatusException("500010", "通知内容总大小不得超过5MB,当前大小为:" + currentLength + "MB");
|
|
|
+ }
|
|
|
|
|
|
- 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;
|
|
|
- }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
|
|
|
- @Naked
|
|
|
- @GetMapping("disposetest")
|
|
|
- @ApiOperation(value = "获取用户公告列表")
|
|
|
- public void disposetest(){
|
|
|
- //获取待处理的通知进度数据
|
|
|
- List<NoticeRulePublishProgressEntity> progressList = noticeService.getToBeDisposedNoticeRulePublishProgressList();
|
|
|
- if (progressList == null || progressList.isEmpty()) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ @Naked
|
|
|
+ @GetMapping("disposetest")
|
|
|
+ @ApiOperation(value = "获取用户公告列表")
|
|
|
+ public void disposetest() {
|
|
|
+ // 获取待处理的通知进度数据
|
|
|
+ List<NoticeRulePublishProgressEntity> progressList = noticeService
|
|
|
+ .getToBeDisposedNoticeRulePublishProgressList();
|
|
|
+ if (progressList == null || progressList.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- for (NoticeRulePublishProgressEntity progress : progressList) {
|
|
|
- Long startUserId = 0L;
|
|
|
- int loopTimes = 0;
|
|
|
- Long lastMaxUserId = getLastMaxUserId(progress.getNoticeReceiverRuleType(), progress);
|
|
|
- if (lastMaxUserId != null) {
|
|
|
- startUserId = lastMaxUserId + 1;
|
|
|
- }
|
|
|
- while (true) {
|
|
|
- Long nextUserId = noticeService.disposePublishingUserNotice(startUserId, progress);
|
|
|
+ for (NoticeRulePublishProgressEntity progress : progressList) {
|
|
|
+ Long startUserId = 0L;
|
|
|
+ int loopTimes = 0;
|
|
|
+ Long lastMaxUserId = getLastMaxUserId(progress.getNoticeReceiverRuleType(), progress);
|
|
|
+ if (lastMaxUserId != null) {
|
|
|
+ startUserId = lastMaxUserId + 1;
|
|
|
+ }
|
|
|
+ while (true) {
|
|
|
+ Long nextUserId = noticeService.disposePublishingUserNotice(startUserId, progress);
|
|
|
|
|
|
- if (nextUserId.equals(startUserId)) {
|
|
|
- noticeService.updateNoticeStatus(progress.getNoticeId(), NoticeStatus.PUBLISHED);
|
|
|
- break;
|
|
|
- } else {
|
|
|
- startUserId = nextUserId;
|
|
|
- //处理中的状态只需更新一次
|
|
|
- if (loopTimes == 1) {
|
|
|
- noticeService.updateNoticeStatus(progress.getNoticeId(), NoticeStatus.PUBLISHING);
|
|
|
- }
|
|
|
- }
|
|
|
- loopTimes++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ if (nextUserId.equals(startUserId)) {
|
|
|
+ noticeService.updateNoticeStatus(progress.getNoticeId(),
|
|
|
+ NoticeStatus.PUBLISHED);
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ startUserId = nextUserId;
|
|
|
+ // 处理中的状态只需更新一次
|
|
|
+ if (loopTimes == 1) {
|
|
|
+ noticeService.updateNoticeStatus(progress.getNoticeId(),
|
|
|
+ NoticeStatus.PUBLISHING);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ loopTimes++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 获取上次更新的最大用户id
|
|
|
- *
|
|
|
- * @param ruleType
|
|
|
- * @param process
|
|
|
- * @return
|
|
|
- */
|
|
|
- private Long getLastMaxUserId(NoticeReceiverRuleType ruleType,
|
|
|
- NoticeRulePublishProgressEntity process) {
|
|
|
- if (ruleType == NoticeReceiverRuleType.ALL_STUDENTS_OF_ROOT_ORG
|
|
|
- || ruleType == NoticeReceiverRuleType.STUDENTS_OF_EXAM) {
|
|
|
- return process.getMaxStudentId();
|
|
|
- } else {
|
|
|
- return process.getMaxCommonUserId();
|
|
|
- }
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 获取上次更新的最大用户id
|
|
|
+ *
|
|
|
+ * @param ruleType
|
|
|
+ * @param process
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Long getLastMaxUserId(NoticeReceiverRuleType ruleType,
|
|
|
+ NoticeRulePublishProgressEntity process) {
|
|
|
+ if (ruleType == NoticeReceiverRuleType.ALL_STUDENTS_OF_ROOT_ORG
|
|
|
+ || ruleType == NoticeReceiverRuleType.STUDENTS_OF_EXAM) {
|
|
|
+ return process.getMaxStudentId();
|
|
|
+ } else {
|
|
|
+ return process.getMaxCommonUserId();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|