lideyin 5 سال پیش
والد
کامیت
d7a4246e6f

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

@@ -15,11 +15,17 @@ 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.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.web.helpers.GlobalHelper;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 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;
@@ -29,6 +35,7 @@ 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;
@@ -41,239 +48,301 @@ 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("addNotice")
-	public void addNotice(@Validated @RequestBody AddNoticeDomain addNoticeDomain) {
-		validateAddNotice(addNoticeDomain);
+    @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", "添加新通知失败");
-		}
-	}
+        AddNoticeInfo info = getAddNoticeInfoFrom(addNoticeDomain);
+        int result = noticeService.addNotice(info);
+        if (result == 0) {
+            throw new StatusException("500008", "添加新通知失败");
+        }
+    }
 
-	@ApiOperation(value = "修改通知信息")
-	@PostMapping("updateNotice")
-	public void updateNotice(@Validated @RequestBody UpdateNoticeDomain updateNoticeDomain) {
-		validateUpdateNotice(updateNoticeDomain);
+    @ApiOperation(value = "修改通知信息")
+    @PostMapping("updateNotice")
+    public void updateNotice(@Validated @RequestBody UpdateNoticeDomain updateNoticeDomain) {
+        validateUpdateNotice(updateNoticeDomain);
 
-		UpdateNoticeInfo info = getUpdateNoticeInfoFrom(updateNoticeDomain);
-		noticeService.updateNotice(info);
-	}
+        UpdateNoticeInfo info = getUpdateNoticeInfoFrom(updateNoticeDomain);
+        noticeService.updateNotice(info);
+    }
 
-	@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);
-	}
+    @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);
+    }
 
-	@GetMapping("getUserNoticeList")
-	@ApiOperation(value = "获取用户公告列表")
-	public List<UserNoticeDomain> getUserNoticeList(UserNoticeDomainQuery query) {
-		List<UserNoticeDomain> resultList = new ArrayList<>();
-		UserNoticeInfoQuery noticeQuery = getNoticeInfoQueryFrom(query);
+    @GetMapping("getUserNoticeList")
+    @ApiOperation(value = "获取用户公告列表")
+    public List<UserNoticeDomain> getUserNoticeList(UserNoticeDomainQuery query) {
+        List<UserNoticeDomain> resultList = new ArrayList<>();
+        UserNoticeInfoQuery noticeQuery = getNoticeInfoQueryFrom(query);
 
-		List<UserNoticeInfo> noticeInfoList = noticeService.getNoticeList(noticeQuery);
+        List<UserNoticeInfo> noticeInfoList = noticeService.getNoticeList(noticeQuery);
 
-		if (null != noticeInfoList && !noticeInfoList.isEmpty()) {
-			resultList = getNoticeDomainListFrom(noticeInfoList);
-		}
-		return resultList;
-	}
+        if (null != noticeInfoList && !noticeInfoList.isEmpty()) {
+            resultList = getNoticeDomainListFrom(noticeInfoList);
+        }
+        return resultList;
+    }
 
-	@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());
-	}
+    @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;
-	}
+    @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个字符");
-		}
-		// 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个字符");
+        }
+        // 总大小不得超过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 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", "该通知状态已变更,请刷新后重试");
-		}
-	}
+        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 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;
+    }
+
+
+    @GetMapping("dipose")
+    @ApiOperation(value = "获取用户公告列表")
+    public void dipose(){
+        //获取待处理的通知进度数据
+        List<NoticeRulePublishProgressEntity> progressList = noticeService.getToBeDisposedNoticeRulePublishProgressList();
+        if (progressList == null || progressList.isEmpty()) {
+            return;
+        }
+        Long startUserId = 0L;
+
+        for (NoticeRulePublishProgressEntity progress : progressList) {
+            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+1;
+                    //处理中的状态只需更新一次
+                    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();
+        }
+    }
 }

+ 8 - 2
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/NoticeRulePublishProgressRepo.java

@@ -15,10 +15,16 @@ public interface NoticeRulePublishProgressRepo extends JpaRepository<NoticeRuleP
 
     List<NoticeRulePublishProgressEntity> findByNoticeIdIn(List<Long> noticeIdList);
 
+    @Query("select t1.id,t1.creation_time,t1.update_time from ec_e_notice_rule_publish_progress t1 " +
+            " inner join ec_e_notice t2 on t1.notice_id=t2.id" +
+            " where t2.notice_status in ('PUBLISHING','TO_BE_PUBLISHED')" +
+            " order by t2.notice_status,t2.creation_time")
+    List<NoticeRulePublishProgressEntity> findUnpublishedNoticeProcessList();
+
     @Transactional
     @Modifying
-    @Query(value="delete from EC_E_NOTICE_RULE_PUBLISH_PROGRESS where root_org_id=?1 and notice_id in ?2",nativeQuery = true)
-    int deleteByRootOrgIdAndNoticeIdIn(Long rootOrgId,List<Long> noticeId);
+    @Query(value = "delete from EC_E_NOTICE_RULE_PUBLISH_PROGRESS where root_org_id=?1 and notice_id in ?2", nativeQuery = true)
+    int deleteByRootOrgIdAndNoticeIdIn(Long rootOrgId, List<Long> noticeId);
 
     @Transactional
     @Modifying

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

@@ -145,7 +145,7 @@ public class NoticeServiceImpl implements NoticeService {
             ni.setPublishTime(ne.getPublishTime());
             ni.setTitle(ne.getTitle());
             ni.setContent(ne.getContent());
-            ni.setPublishObject(getPublishObject(rootOrgId, ruleType, ruleList));
+            ni.setPublishObject(getPublishObject(rootOrgId, ruleType,ne.getId(), ruleList));
             ni.setPublishStatus(ne.getNoticeStatus());
             ni.setRuleType(ruleType);
             resultList.add(ni);
@@ -237,23 +237,7 @@ public class NoticeServiceImpl implements NoticeService {
 
     @Override
     public List<NoticeRulePublishProgressEntity> getToBeDisposedNoticeRulePublishProgressList() {
-        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()) {
-            return null;
-        }
-        return noticeRulePublishProgressRepo.findByNoticeIdIn(noticeIdList);
+        return noticeRulePublishProgressRepo.findUnpublishedNoticeProcessList();
     }
 
     @Override
@@ -483,17 +467,19 @@ public class NoticeServiceImpl implements NoticeService {
      * 获取发布对象
      *
      * @param rootOrgId
+     * @param ruleType
      * @param noticeId
      * @return
      */
     private List<Map<String, Object>> getPublishObject(Long rootOrgId,
-                                                       NoticeReceiverRuleType ruleType, List<NoticeReceiverRuleEntity> ruleList) {
+                                                       NoticeReceiverRuleType ruleType,Long noticeId, 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)
+                currentRuleList = ruleList.stream().filter(p -> rootOrgId.equals(p.getRootOrgId()) &&
+                        noticeId.equals(p.getNoticeId()) && p.getRuleType() == ruleType)
                         .collect(Collectors.toList());
                 return getExamStudentObject(currentRuleList);
             case ALL_STUDENTS_OF_ROOT_ORG:
@@ -511,7 +497,8 @@ public class NoticeServiceImpl implements NoticeService {
                 resultList.add(objectMap);
                 return resultList;
             case TEACHER_OF_MARK_WORK:
-                currentRuleList = ruleList.stream().filter(p -> p.getRuleType() == ruleType)
+                currentRuleList = ruleList.stream().filter(p -> rootOrgId.equals(p.getRootOrgId()) &&
+                        noticeId.equals(p.getNoticeId()) && p.getRuleType() == ruleType)
                         .collect(Collectors.toList());
                 return getMarkTeacherObject(rootOrgId, currentRuleList);
         }