Ver código fonte

考生端代码重构及性能优化

lideyin 5 anos atrás
pai
commit
fff2812db4

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

@@ -51,15 +51,13 @@ public class NoticeController extends ControllerSupport {
     @GetMapping("getPagedNoticeList/{curPage}/{pageSize}")
     public PageInfo<NoticeDomain> getPagedNoticeList(@PathVariable Integer curPage,
                                                      @PathVariable Integer pageSize, NoticeDomainQuery query) {
-        PageInfo<NoticeDomain> resultPageInfo = new PageInfo<>();
         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);
-        resultPageInfo = getPageInfoFrom(pagedNoticeInfo);
-        return resultPageInfo;
+        return getPageInfoFrom(pagedNoticeInfo);
     }
 
     @ApiOperation(value = "修改通知信息")
@@ -94,10 +92,7 @@ public class NoticeController extends ControllerSupport {
     @DeleteMapping("/{noticeId}")
     public void deleteNotice(@Validated @ApiParam(value = "通知id,多个以逗号分隔") @PathVariable(required = true) String noticeId) {
         List<Long> noticeIdList= validateDeleteNotice(noticeId);
-        int result = noticeService.deleteNotice(getRootOrgId(),noticeIdList);
-        if (result==0){
-            throw new StatusException("500006","删除失败");
-        }
+        noticeService.deleteNotice(getRootOrgId(),noticeIdList);
     }
 
     @GetMapping("getUserNoticeList")
@@ -213,10 +208,11 @@ public class NoticeController extends ControllerSupport {
         }
         String content = addNoticeDomain.getContent();
         String simpleText =  Jsoup.clean(content, Whitelist.simpleText());
-        //普通文本内容不允许超过500个字 TODO 该方法待校验,因为不确定富文本框中图片的保存格式
+        //普通文本内容不允许超过500个字
         if (simpleText.length()>500){
             throw new StatusException("500010","通知内容不得超过500个字符");
         }
+        //TODO 加上总长度校验(5M,找张莹确定)
     }
     private void validateUpdateNotice(UpdateNoticeDomain updateNoticeDomain) {
         if (updateNoticeDomain.getRuleType()== NoticeReceiverRuleType.STUDENTS_OF_EXAM
@@ -231,6 +227,7 @@ public class NoticeController extends ControllerSupport {
         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","该通知已不存在,请刷新后重试");

+ 20 - 17
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/provider/NoticeCloudServiceProvider.java

@@ -44,29 +44,31 @@ public class NoticeCloudServiceProvider extends ControllerSupport implements Not
     public GetNoticeRulePublishProgressListResp getToBeDisposedNoticeRulePublishProgressList() {
         GetNoticeRulePublishProgressListResp resp = new GetNoticeRulePublishProgressListResp();
         List<NoticeRulePublishProgressEntity> progressEntityList = noticeService.getToBeDisposedNoticeRulePublishProgressList();
-        if (progressEntityList != null && !progressEntityList.isEmpty()) {
-            List<NoticeRulePublishProgressBean> beanList = new ArrayList<>();
-            for (NoticeRulePublishProgressEntity entity : progressEntityList) {
-                NoticeRulePublishProgressBean bean = new NoticeRulePublishProgressBean();
-                bean.setId(entity.getId());
-                bean.setMaxCommonUserId(entity.getMaxCommonUserId());
-                bean.setMaxStudentId(entity.getMaxStudentId());
-                bean.setNoticeId(entity.getNoticeId());
-                bean.setNoticeReceiverRuleType(entity.getNoticeReceiverRuleType());
-                bean.setRootOrgId(entity.getRootOrgId());
-                beanList.add(bean);
-            }
-            resp.setList(beanList);
+        if (progressEntityList == null || progressEntityList.isEmpty()) {
+            return resp;
         }
+        List<NoticeRulePublishProgressBean> beanList = new ArrayList<>();
+        for (NoticeRulePublishProgressEntity entity : progressEntityList) {
+            NoticeRulePublishProgressBean bean = new NoticeRulePublishProgressBean();
+            bean.setId(entity.getId());
+            bean.setMaxCommonUserId(entity.getMaxCommonUserId());
+            bean.setMaxStudentId(entity.getMaxStudentId());
+            bean.setNoticeId(entity.getNoticeId());
+            bean.setNoticeReceiverRuleType(entity.getNoticeReceiverRuleType());
+            bean.setRootOrgId(entity.getRootOrgId());
+            beanList.add(bean);
+        }
+        resp.setList(beanList);
         return resp;
     }
 
     @ApiOperation(value = "处理待发布和发布中的数据")
     @PostMapping("disposePublishingUserNotice")
     @Override
-    public DisposePublishingUserNoticeResp disposePublishingUserNotice(@RequestBody DisposePublishingUserNoticeReq req) {
-        DisposePublishingUserNoticeResp resp = new DisposePublishingUserNoticeResp();
+    public DisposePublishingUserNoticeResp disposePublishingUserNotice(@RequestBody DisposePublishingUserNoticeReq
+                                                                               req) {
         NoticeRulePublishProgressBean processBean = req.getNoticeRulePublishProgress();
+
         NoticeRulePublishProgressEntity processEntity = new NoticeRulePublishProgressEntity();
         processEntity.setId(processBean.getId());
         processEntity.setMaxCommonUserId(processBean.getMaxCommonUserId());
@@ -74,9 +76,10 @@ public class NoticeCloudServiceProvider extends ControllerSupport implements Not
         processEntity.setNoticeId(processBean.getNoticeId());
         processEntity.setNoticeReceiverRuleType(processBean.getNoticeReceiverRuleType());
         processEntity.setRootOrgId(processBean.getRootOrgId());
-        Long nextUserId = noticeService.disposePublishingUserNotice(req.getStartUserId(),processEntity);
 
+        Long nextUserId = noticeService.disposePublishingUserNotice(req.getStartUserId(), processEntity);
 
+        DisposePublishingUserNoticeResp resp = new DisposePublishingUserNoticeResp();
         resp.setNextUserId(nextUserId);
         return resp;
     }
@@ -92,7 +95,7 @@ public class NoticeCloudServiceProvider extends ControllerSupport implements Not
     @PostMapping("updateNoticeStatus")
     @Override
     public void updateNoticeStatus(@RequestBody UpdateNoticeStatusReq updateNoticeStatusReq) {
-        noticeService.updateNoticeStatus(updateNoticeStatusReq.getNoticeId(),updateNoticeStatusReq.getNoticeStatus());
+        noticeService.updateNoticeStatus(updateNoticeStatusReq.getNoticeId(), updateNoticeStatusReq.getNoticeStatus());
     }
 
 }

+ 1 - 1
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/ExamServiceImpl.java

@@ -286,7 +286,7 @@ public class ExamServiceImpl implements ExamService {
 		for (Entry<String, String> entry : properties.entrySet()) {
 			String key = entry.getKey();
 			String value = entry.getValue();
-			DynamicEnum de = null;
+			DynamicEnum de;
 			try {
 				de = manager.getByName(key);
 			} catch (Exception e) {

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

@@ -257,23 +257,23 @@ public class NoticeServiceImpl implements NoticeService {
     @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;
+                limitStudentIdList, getLimitUserIdResp.getMaxId());
+        return getLimitUserIdResp.getNextId();
 
     }
 
@@ -357,10 +357,11 @@ public class NoticeServiceImpl implements NoticeService {
                 return getLimitUserIdByExamStudent(rootOrgId, startUserId, rowNumber, ruleList);
             case ALL_STUDENTS_OF_ROOT_ORG:
                 return getLimitUserIdByAllStudent(rootOrgId, rowNumber, startUserId);
+                default:
+                    resultResp.setNextId(0L);
+                    resultResp.setIdList(null);
+                    return resultResp;
         }
-        resultResp.setNextId(nextUserId);
-        resultResp.setIdList(limitUserIdList);
-        return resultResp;
     }
 
     private GetLimitUserIdResp getGetLimitUserIdByMarkWork(Long rootOrgId, int rowNumber,