Parcourir la source

同步更新印刷项目信息

deason il y a 6 ans
Parent
commit
aa5557bf15

+ 8 - 2
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/PrintingProjectService.java

@@ -28,10 +28,16 @@ public interface PrintingProjectService {
     Page<PrintingProjectInfo> getPrintingProjectList(PrintingProjectQuery query);
 
     /**
-     * 保存或更新印刷项目信息
+     * 更新印刷项目信息
      *
      * @param info
      */
-    void savePrintingProject(PrintingProjectInfo info);
+    void updatePrintingProject(PrintingProjectInfo info);
+
+    /**
+     * 同步更新印刷项目信息
+     * 仅同步学校、考试的基本信息
+     */
+    void syncPrintingProject(PrintingProjectInfo info);
 
 }

+ 3 - 3
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/bean/PrintingProjectInfo.java

@@ -35,7 +35,7 @@ public class PrintingProjectInfo implements JsonSerializable {
      */
     private String orgName;
     /**
-     * 供应商ID(表ecs_core_org的ID)
+     * 供应商ID
      */
     private Long supplierId;
     /**
@@ -43,7 +43,7 @@ public class PrintingProjectInfo implements JsonSerializable {
      */
     private String supplierName;
     /**
-     * 项目经理ID(表ecs_core_user的ID)
+     * 项目经理ID
      */
     private Long pmId;
     /**
@@ -200,7 +200,7 @@ public class PrintingProjectInfo implements JsonSerializable {
     }
 
     public Boolean getCompleted() {
-        return completed;
+        return completed != null ? completed : false;
     }
 
     public void setCompleted(Boolean completed) {

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

@@ -7,6 +7,7 @@
 
 package cn.com.qmth.examcloud.core.print.service.impl;
 
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.core.print.common.jpa.OrderBuilder;
 import cn.com.qmth.examcloud.core.print.common.jpa.SearchBuilder;
 import cn.com.qmth.examcloud.core.print.common.jpa.SpecUtils;
@@ -23,6 +24,10 @@ import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
+import static cn.com.qmth.examcloud.core.print.common.Constants.PRT_CODE_500;
+
 /**
  * 印刷项目相关接口
  *
@@ -61,11 +66,63 @@ public class PrintingProjectServiceImpl implements PrintingProjectService {
     }
 
     @Override
-    public void savePrintingProject(PrintingProjectInfo info) {
-        PrintingProject entity = PrintingProjectConvert.of(info);
-        Check.isNull(entity.getOrgId(), "学校机构ID不能为空!");
-        Check.isNull(entity.getExamId(), "考试ID不能为空!");
+    public void updatePrintingProject(PrintingProjectInfo info) {
+        Check.isNull(info.getId(), "ID不能为空!");
+        Check.isNull(info.getSupplierId(), "供应商ID不能为空!");
+        Check.isBlank(info.getSupplierName(), "供应商名称不能为空!");
+        Check.isNull(info.getPmId(), "项目经理ID不能为空!");
+        Check.isBlank(info.getPmName(), "项目经理名称不能为空!");
+        Check.isNull(info.getPrepareStartTime(), "准备开始时间不能为空!");
+        Check.isNull(info.getPrepareEndTime(), "准备结束时间不能为空!");
+        Check.isNull(info.getPrintStartTime(), "印刷开始时间不能为空!");
+        Check.isNull(info.getPrintEndTime(), "印刷结束时间不能为空!");
+        Check.isNull(info.getMailStartTime(), "邮寄开始时间不能为空!");
+        Check.isNull(info.getMailEndTime(), "邮寄结束时间不能为空!");
+
+        PrintingProject entity = printingProjectRepository.findOne(info.getId());
+        if (entity == null) {
+            throw new StatusException(PRT_CODE_500, "印刷项目信息不存在!");
+        }
+
+        entity.setSupplierId(info.getSupplierId());
+        entity.setSupplierName(info.getSupplierName());
+        entity.setPmId(info.getPmId());
+        entity.setPmName(info.getPmName());
+        entity.setPrepareStartTime(info.getPrepareStartTime());
+        entity.setPrepareEndTime(info.getPrepareEndTime());
+        entity.setPrintStartTime(info.getPrintStartTime());
+        entity.setPrintEndTime(info.getPrintEndTime());
+        entity.setMailStartTime(info.getMailStartTime());
+        entity.setMailEndTime(info.getMailEndTime());
         printingProjectRepository.save(entity);
     }
 
+    @Override
+    public void syncPrintingProject(PrintingProjectInfo info) {
+        Check.isNull(info.getOrgId(), "学校ID不能为空!");
+        Check.isBlank(info.getOrgName(), "学校名称不能为空!");
+        Check.isNull(info.getExamId(), "考试ID不能为空!");
+        Check.isBlank(info.getExamName(), "考试名称不能为空!");
+
+        SearchBuilder searches = new SearchBuilder()
+                .eq("orgId", info.getOrgId())
+                .eq("examId", info.getExamId());
+        Specification<PrintingProject> spec = SpecUtils.buildSearchers(PrintingProject.class, searches.build());
+
+        List<PrintingProject> projects = printingProjectRepository.findAll(spec);
+        if (projects == null || projects.isEmpty()) {
+            //新增信息
+            PrintingProject project = PrintingProjectConvert.of(info);
+            printingProjectRepository.save(project);
+            return;
+        }
+
+        //更新信息
+        for (PrintingProject project : projects) {
+            project.setOrgName(info.getOrgName());
+            project.setExamName(info.getExamName());
+        }
+        printingProjectRepository.save(projects);
+    }
+
 }

+ 12 - 7
examcloud-core-print-starter/src/test/java/cn/com/qmth/examcloud/core/print/test/PrintingProjectServiceTest.java

@@ -46,13 +46,9 @@ public class PrintingProjectServiceTest {
     private JdbcTemplate jdbcTemplate;
 
     @Test
-    public void savePrintingProjectTest() throws Exception {
+    public void updatePrintingProjectTest() throws Exception {
         PrintingProjectInfo info = new PrintingProjectInfo();
         info.setId(1L);
-        info.setOrgId(1L);
-        info.setExamId(1L);
-        info.setOrgName("武汉大学");
-        info.setExamName("计算机考试");
         info.setPmId(1L);
         info.setPmName("雷布斯");
         info.setSupplierId(1L);
@@ -63,8 +59,17 @@ public class PrintingProjectServiceTest {
         info.setPrintEndTime(new Date());
         info.setMailStartTime(new Date());
         info.setMailEndTime(new Date());
-        info.setCompleted(false);
-        printingProjectService.savePrintingProject(info);
+        printingProjectService.updatePrintingProject(info);
+    }
+
+    //@Test
+    public void syncPrintingProjectTest() throws Exception {
+        PrintingProjectInfo info = new PrintingProjectInfo();
+        info.setOrgId(1L);
+        info.setExamId(1L);
+        info.setOrgName("武汉大学");
+        info.setExamName("计算机考试");
+        printingProjectService.syncPrintingProject(info);
     }
 
     //@Test