瀏覽代碼

jpa upgrade by springboot v2.1+

deason 6 年之前
父節點
當前提交
8020579aad

+ 9 - 6
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/CoursePaperServiceImpl.java

@@ -241,7 +241,7 @@ public class CoursePaperServiceImpl implements CoursePaperService {
 
         //批量更新
         if (updateStatistics.size() > 0) {
-            courseStatisticRepository.save(updateStatistics);
+            courseStatisticRepository.saveAll(updateStatistics);
         }
     }
 
@@ -250,11 +250,14 @@ public class CoursePaperServiceImpl implements CoursePaperService {
         Check.isEmpty(courseStatisticId, "课程统计ID不能为空!");
         Check.isEmpty(coursePaperId, "课程试卷ID不能为空!");
 
-        CourseStatistic statistic = courseStatisticRepository.findOne(courseStatisticId);
-        Check.isNull(statistic, "当前课程统计不存在!");
+        Optional<CourseStatistic> statisticOptional = courseStatisticRepository.findById(courseStatisticId);
+        Check.isFalse(statisticOptional.isPresent(), "当前课程统计不存在!");
 
-        CoursePaper coursePaper = coursePaperRepository.findOne(coursePaperId);
-        Check.isNull(coursePaper, "当前课程试卷不存在!");
+        Optional<CoursePaper> coursePaperOptional = coursePaperRepository.findById(coursePaperId);
+        Check.isFalse(coursePaperOptional.isPresent(), "当前课程试卷不存在!");
+
+        CourseStatistic statistic = statisticOptional.get();
+        CoursePaper coursePaper = coursePaperOptional.get();
 
         statistic.setCoursePaper(coursePaper);
         statistic.setPaperStatus(PaperStatus.已有.getIndex());
@@ -341,7 +344,7 @@ public class CoursePaperServiceImpl implements CoursePaperService {
 
         //批量更新
         if (!needUpdateStatistics.isEmpty()) {
-            courseStatisticRepository.save(needUpdateStatistics);
+            courseStatisticRepository.saveAll(needUpdateStatistics);
         }
 
         //试卷不足时,反馈给前端

+ 1 - 1
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/CourseStatisticServiceImpl.java

@@ -219,7 +219,7 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
 
         //清除已不存在的考试课程
         if (needClear && oldCourseStatisticMaps.size() > 0) {
-            courseStatisticRepository.delete(oldCourseStatisticMaps.values());
+            courseStatisticRepository.deleteAll(oldCourseStatisticMaps.values());
         }
     }
 

+ 1 - 1
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/ExamStructureServiceImpl.java

@@ -148,7 +148,7 @@ public class ExamStructureServiceImpl implements ExamStructureService {
         }
         for (Long id : ids) {
             try {
-                examStructureRepository.delete(id);
+                examStructureRepository.deleteById(id);
             } catch (Exception e) {
                 // ignore: record not exist
                 log.warn(e.getMessage());

+ 16 - 10
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/PrintingProjectServiceImpl.java

@@ -35,6 +35,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
+import java.util.Optional;
 
 import static cn.com.qmth.examcloud.core.print.common.Constants.SYS_CODE_500;
 
@@ -83,11 +84,11 @@ public class PrintingProjectServiceImpl implements PrintingProjectService {
     @Override
     public PrintingProjectInfo getPrintingProjectById(Long id) {
         Check.isNull(id, "印刷项目ID不能为空!");
-        PrintingProject project = printingProjectRepository.findOne(id);
-        if (project == null) {
+        Optional<PrintingProject> optional = printingProjectRepository.findById(id);
+        if (!optional.isPresent()) {
             throw new StatusException(SYS_CODE_500, "印刷项目信息不存在!");
         }
-        return PrintingProjectConvert.of(project);
+        return PrintingProjectConvert.of(optional.get());
     }
 
     @Override
@@ -96,7 +97,11 @@ public class PrintingProjectServiceImpl implements PrintingProjectService {
                 .eq("orgId", orgId)
                 .eq("examId", examId);
         Specification<PrintingProject> spec = SpecUtils.buildSearchers(PrintingProject.class, searches.build());
-        return printingProjectRepository.findOne(spec);
+        Optional<PrintingProject> optional = printingProjectRepository.findOne(spec);
+        if (optional.isPresent()) {
+            return optional.get();
+        }
+        return null;
     }
 
     @Override
@@ -113,11 +118,11 @@ public class PrintingProjectServiceImpl implements PrintingProjectService {
         Check.isNull(info.getMailStartTime(), "邮寄开始时间不能为空!");
         Check.isNull(info.getMailEndTime(), "邮寄结束时间不能为空!");
 
-        PrintingProject entity = printingProjectRepository.findOne(info.getId());
-        if (entity == null) {
+        Optional<PrintingProject> optional = printingProjectRepository.findById(info.getId());
+        if (!optional.isPresent()) {
             throw new StatusException(SYS_CODE_500, "印刷项目信息不存在!");
         }
-
+        PrintingProject entity = optional.get();
         entity.setSupplierId(info.getSupplierId());
         entity.setSupplierName(info.getSupplierName());
         entity.setPmId(info.getPmId());
@@ -144,9 +149,10 @@ public class PrintingProjectServiceImpl implements PrintingProjectService {
         Specification<PrintingProject> spec = SpecUtils.buildSearchers(PrintingProject.class, searches.build());
 
         //某学校某考试仅当作一个项目
-        PrintingProject project = printingProjectRepository.findOne(spec);
-        if (project != null) {
+        Optional<PrintingProject> optional = printingProjectRepository.findOne(spec);
+        if (optional.isPresent()) {
             //更新学校名称、考试名称等信息
+            PrintingProject project = optional.get();
             project.setOrgName(examInfo.getOrgName());
             project.setExamName(examInfo.getExamName());
             printingProjectRepository.save(project);
@@ -154,7 +160,7 @@ public class PrintingProjectServiceImpl implements PrintingProjectService {
         }
 
         //新增印刷项目信息
-        project = new PrintingProject();
+        PrintingProject project = new PrintingProject();
         project.setOrgId(examInfo.getOrgId());
         project.setOrgName(examInfo.getOrgName());
         project.setExamId(examInfo.getExamId());

+ 1 - 1
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/PrintingProjectStatisticServiceImpl.java

@@ -181,7 +181,7 @@ public class PrintingProjectStatisticServiceImpl implements PrintingProjectStati
         }
 
         //批量保存
-        projectStatisticRepository.save(statistics);
+        projectStatisticRepository.saveAll(statistics);
     }
 
     private int parseNormalA3(List<CourseStatisticLessInfo> courseStatistics, int totalStudent) {

+ 7 - 5
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/PrintingTemplateServiceImpl.java

@@ -25,6 +25,7 @@ import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
+import java.util.Optional;
 
 import static cn.com.qmth.examcloud.core.print.common.Constants.SYS_CODE_500;
 
@@ -52,11 +53,11 @@ public class PrintingTemplateServiceImpl implements PrintingTemplateService {
 
     @Override
     public PrintingTemplateInfo getPrintingTemplateById(Long id) {
-        PrintingTemplate template = printingTemplateRepository.findOne(id);
-        if (template == null) {
+        Optional<PrintingTemplate> optional = printingTemplateRepository.findById(id);
+        if (!optional.isPresent()) {
             throw new StatusException(SYS_CODE_500, "当前模板信息不存在!");
         }
-        return PrintingTemplateConvert.of(template);
+        return PrintingTemplateConvert.of(optional.get());
     }
 
     @Override
@@ -78,9 +79,10 @@ public class PrintingTemplateServiceImpl implements PrintingTemplateService {
         info.setFileName(info.getFileUrl().replace(upYunClient.getUrlPrefix(), ""));
 
         //某学校考试下一种模板类型只有一条记录
-        PrintingTemplate template = printingTemplateRepository.findOne(spec);
-        if (template != null) {
+        Optional<PrintingTemplate> optional = printingTemplateRepository.findOne(spec);
+        if (optional.isPresent()) {
             //存在记录时,则修改
+            PrintingTemplate template = optional.get();
             template.setFileName(info.getFileName());
             template.setFileUrl(info.getFileUrl());
             printingTemplateRepository.save(template);

+ 4 - 2
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/ProjectBackupSettingServiceImpl.java

@@ -20,6 +20,7 @@ import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 
 import java.util.Date;
+import java.util.Optional;
 
 import static cn.com.qmth.examcloud.core.print.common.Constants.SYS_CODE_500;
 
@@ -62,9 +63,10 @@ public class ProjectBackupSettingServiceImpl implements ProjectBackupSettingServ
         }
 
         Specification<ProjectBackupSetting> spec = SearchBuilder.EQ("projectId", info.getProjectId());
-        ProjectBackupSetting setting = projectBackupSettingRepository.findOne(spec);
-        if (setting != null) {
+        Optional<ProjectBackupSetting> optional = projectBackupSettingRepository.findOne(spec);
+        if (optional.isPresent()) {
             //存在记录时,则修改
+            ProjectBackupSetting setting = optional.get();
             info.setId(setting.getId());
             info.setCreationTime(setting.getCreationTime());
             info.setUpdateTime(new Date());

+ 5 - 4
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/ProjectOtherSettingServiceImpl.java

@@ -21,6 +21,7 @@ import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
+import java.util.Optional;
 
 import static cn.com.qmth.examcloud.core.print.common.Constants.SYS_CODE_500;
 
@@ -43,11 +44,11 @@ public class ProjectOtherSettingServiceImpl implements ProjectOtherSettingServic
 
     @Override
     public ProjectOtherSetting getProjectOtherSettingById(Long id) {
-        ProjectOtherSetting setting = projectOtherSettingRepository.findOne(id);
-        if (setting == null) {
+        Optional<ProjectOtherSetting> optional = projectOtherSettingRepository.findById(id);
+        if (!optional.isPresent()) {
             throw new StatusException(SYS_CODE_500, "当前事项设置的信息不存在!");
         }
-        return setting;
+        return optional.get();
     }
 
     @Override
@@ -61,7 +62,7 @@ public class ProjectOtherSettingServiceImpl implements ProjectOtherSettingServic
     @Override
     public void deleteProjectOtherSettingById(Long id) {
         try {
-            projectOtherSettingRepository.delete(id);
+            projectOtherSettingRepository.deleteById(id);
         } catch (EmptyResultDataAccessException e) {
             //ignore: record not exist
             log.warn(e.getMessage());

+ 2 - 2
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/QuestionStructureServiceImpl.java

@@ -75,7 +75,7 @@ public class QuestionStructureServiceImpl implements ExamQuestionStructureServic
                 structure.setExamId(examId);
                 structure.setPaperId(paperId);
             }
-            objectiveQuestionStructureRepository.save(info.getObjectives());
+            objectiveQuestionStructureRepository.saveAll(info.getObjectives());
         }
 
         //保存主观题数据
@@ -85,7 +85,7 @@ public class QuestionStructureServiceImpl implements ExamQuestionStructureServic
                 structure.setExamId(examId);
                 structure.setPaperId(paperId);
             }
-            subjectiveQuestionStructureRepository.save(info.getSubjectives());
+            subjectiveQuestionStructureRepository.saveAll(info.getSubjectives());
         }
     }