Ver código fonte

查询印刷项目列表(分页)

deason 6 anos atrás
pai
commit
86b4f7eaab

+ 12 - 0
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/PrintingProjectService.java

@@ -7,6 +7,10 @@
 
 package cn.com.qmth.examcloud.core.print.service;
 
+import cn.com.qmth.examcloud.core.print.service.bean.PrintingProjectInfo;
+import cn.com.qmth.examcloud.core.print.service.bean.PrintingProjectQuery;
+import org.springframework.data.domain.Page;
+
 /**
  * 印刷项目相关接口
  *
@@ -15,4 +19,12 @@ package cn.com.qmth.examcloud.core.print.service;
  */
 public interface PrintingProjectService {
 
+    /**
+     * 查询印刷项目列表(分页)
+     *
+     * @param query
+     * @return
+     */
+    Page<PrintingProjectInfo> getPrintingProjectList(PrintingProjectQuery query);
+
 }

+ 43 - 0
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/bean/PrintingProjectConvert.java

@@ -0,0 +1,43 @@
+/*
+ * *************************************************
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
+ * Created by Deason on 2018-10-24 14:38:26.
+ * *************************************************
+ */
+
+package cn.com.qmth.examcloud.core.print.service.bean;
+
+import cn.com.qmth.examcloud.core.print.entity.PrintingProject;
+import com.google.common.collect.Lists;
+import org.springframework.beans.BeanUtils;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author: fengdesheng
+ * @since: 2018/10/24
+ */
+public class PrintingProjectConvert {
+
+    public static PrintingProjectInfo of(PrintingProject entity) {
+        PrintingProjectInfo info = new PrintingProjectInfo();
+        BeanUtils.copyProperties(entity, info);
+        return info;
+    }
+
+    public static Page<PrintingProjectInfo> ofPage(Page<PrintingProject> page) {
+        Pageable pageable = new PageRequest(page.getNumber(), page.getSize());
+        List<PrintingProject> entities = page.getContent();
+        if (entities == null || entities.isEmpty()) {
+            return new PageImpl<>(Lists.newArrayList(), pageable, page.getTotalElements());
+        }
+        List<PrintingProjectInfo> list = entities.stream().map(entity -> of(entity)).collect(Collectors.toList());
+        return new PageImpl<>(list, pageable, page.getTotalElements());
+    }
+
+}

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

@@ -0,0 +1,210 @@
+/*
+ * *************************************************
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
+ * Created by Deason on 2018-10-24 14:36:00.
+ * *************************************************
+ */
+
+package cn.com.qmth.examcloud.core.print.service.bean;
+
+import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
+
+import java.util.Date;
+
+/**
+ * @author: fengdesheng
+ * @since: 2018/10/24
+ */
+public class PrintingProjectInfo implements JsonSerializable {
+    private static final long serialVersionUID = 1L;
+    private Long id;
+    /**
+     * 学校机构ID
+     */
+    private Long orgId;
+    /**
+     * 考试ID
+     */
+    private Long examId;
+    /**
+     * 考试名称
+     */
+    private String examName;
+    /**
+     * 机构名称
+     */
+    private String orgName;
+    /**
+     * 供应商ID(表ecs_core_org的ID)
+     */
+    private Long supplierId;
+    /**
+     * 供应商名称
+     */
+    private String supplierName;
+    /**
+     * 项目经理ID(表ecs_core_user的ID)
+     */
+    private Long pmId;
+    /**
+     * 项目经理名称
+     */
+    private String pmName;
+    /**
+     * 印刷数据准备开始时间
+     */
+    private Date prepareStartTime;
+    /**
+     * 印刷数据准备结束时间
+     */
+    private Date prepareEndTime;
+    /**
+     * 具体印刷开始时间
+     */
+    private Date printStartTime;
+    /**
+     * 具体印刷结束时间
+     */
+    private Date printEndTime;
+    /**
+     * 邮寄开始时间
+     */
+    private Date mailStartTime;
+    /**
+     * 邮寄结束时间
+     */
+    private Date mailEndTime;
+    /**
+     * 项目是否已完成
+     */
+    private Boolean completed;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getOrgId() {
+        return orgId;
+    }
+
+    public void setOrgId(Long orgId) {
+        this.orgId = orgId;
+    }
+
+    public Long getExamId() {
+        return examId;
+    }
+
+    public void setExamId(Long examId) {
+        this.examId = examId;
+    }
+
+    public String getExamName() {
+        return examName;
+    }
+
+    public void setExamName(String examName) {
+        this.examName = examName;
+    }
+
+    public String getOrgName() {
+        return orgName;
+    }
+
+    public void setOrgName(String orgName) {
+        this.orgName = orgName;
+    }
+
+    public Long getSupplierId() {
+        return supplierId;
+    }
+
+    public void setSupplierId(Long supplierId) {
+        this.supplierId = supplierId;
+    }
+
+    public String getSupplierName() {
+        return supplierName;
+    }
+
+    public void setSupplierName(String supplierName) {
+        this.supplierName = supplierName;
+    }
+
+    public Long getPmId() {
+        return pmId;
+    }
+
+    public void setPmId(Long pmId) {
+        this.pmId = pmId;
+    }
+
+    public String getPmName() {
+        return pmName;
+    }
+
+    public void setPmName(String pmName) {
+        this.pmName = pmName;
+    }
+
+    public Date getPrepareStartTime() {
+        return prepareStartTime;
+    }
+
+    public void setPrepareStartTime(Date prepareStartTime) {
+        this.prepareStartTime = prepareStartTime;
+    }
+
+    public Date getPrepareEndTime() {
+        return prepareEndTime;
+    }
+
+    public void setPrepareEndTime(Date prepareEndTime) {
+        this.prepareEndTime = prepareEndTime;
+    }
+
+    public Date getPrintStartTime() {
+        return printStartTime;
+    }
+
+    public void setPrintStartTime(Date printStartTime) {
+        this.printStartTime = printStartTime;
+    }
+
+    public Date getPrintEndTime() {
+        return printEndTime;
+    }
+
+    public void setPrintEndTime(Date printEndTime) {
+        this.printEndTime = printEndTime;
+    }
+
+    public Date getMailStartTime() {
+        return mailStartTime;
+    }
+
+    public void setMailStartTime(Date mailStartTime) {
+        this.mailStartTime = mailStartTime;
+    }
+
+    public Date getMailEndTime() {
+        return mailEndTime;
+    }
+
+    public void setMailEndTime(Date mailEndTime) {
+        this.mailEndTime = mailEndTime;
+    }
+
+    public Boolean getCompleted() {
+        return completed;
+    }
+
+    public void setCompleted(Boolean completed) {
+        this.completed = completed;
+    }
+
+}

+ 68 - 0
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/bean/PrintingProjectQuery.java

@@ -0,0 +1,68 @@
+/*
+ * *************************************************
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
+ * Created by Deason on 2018-10-24 14:21:34.
+ * *************************************************
+ */
+
+package cn.com.qmth.examcloud.core.print.service.bean;
+
+import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
+import cn.com.qmth.examcloud.core.print.common.PageQuery;
+
+/**
+ * @author: fengdesheng
+ * @since: 2018/10/17
+ */
+public class PrintingProjectQuery extends PageQuery implements JsonSerializable {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 学校机构ID
+     */
+    private Long orgId;
+    /**
+     * 考试ID
+     */
+    private Long examId;
+    /**
+     * 项目经理ID
+     */
+    private Long pmId;
+    /**
+     * 供应商ID
+     */
+    private Long supplierId;
+
+    public Long getOrgId() {
+        return orgId;
+    }
+
+    public void setOrgId(Long orgId) {
+        this.orgId = orgId;
+    }
+
+    public Long getExamId() {
+        return examId;
+    }
+
+    public void setExamId(Long examId) {
+        this.examId = examId;
+    }
+
+    public Long getPmId() {
+        return pmId;
+    }
+
+    public void setPmId(Long pmId) {
+        this.pmId = pmId;
+    }
+
+    public Long getSupplierId() {
+        return supplierId;
+    }
+
+    public void setSupplierId(Long supplierId) {
+        this.supplierId = supplierId;
+    }
+
+}

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

@@ -7,9 +7,20 @@
 
 package cn.com.qmth.examcloud.core.print.service.impl;
 
+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;
+import cn.com.qmth.examcloud.core.print.common.utils.Check;
+import cn.com.qmth.examcloud.core.print.entity.PrintingProject;
 import cn.com.qmth.examcloud.core.print.repository.PrintingProjectRepository;
 import cn.com.qmth.examcloud.core.print.service.PrintingProjectService;
+import cn.com.qmth.examcloud.core.print.service.bean.PrintingProjectConvert;
+import cn.com.qmth.examcloud.core.print.service.bean.PrintingProjectInfo;
+import cn.com.qmth.examcloud.core.print.service.bean.PrintingProjectQuery;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 
 /**
@@ -23,4 +34,30 @@ public class PrintingProjectServiceImpl implements PrintingProjectService {
     @Autowired
     private PrintingProjectRepository printingProjectRepository;
 
+    @Override
+    public Page<PrintingProjectInfo> getPrintingProjectList(PrintingProjectQuery query) {
+        Check.isNull(query, "查询参数不能为空!");
+        //查询条件
+        SearchBuilder searches = new SearchBuilder();
+        if (query.getOrgId() != null) {
+            searches.eq("orgId", query.getOrgId());
+        }
+        if (query.getExamId() != null) {
+            searches.eq("examId", query.getExamId());
+        }
+        if (query.getPmId() != null) {
+            searches.eq("pmId", query.getPmId());
+        }
+        if (query.getSupplierId() != null) {
+            searches.eq("supplierId", query.getSupplierId());
+        }
+        Specification<PrintingProject> spec = SpecUtils.buildSearchers(PrintingProject.class, searches.build());
+        //排序条件
+        OrderBuilder orders = new OrderBuilder().desc("id");
+        //分页条件
+        Pageable pageable = SpecUtils.buildPageable(query.getPageNo(), query.getPageSize(), orders.build());
+        Page<PrintingProject> page = printingProjectRepository.findAll(spec, pageable);
+        return PrintingProjectConvert.ofPage(page);
+    }
+
 }

+ 15 - 1
examcloud-core-print-starter/src/test/java/cn/com/qmth/examcloud/core/print/test/PrintingProjectServiceTest.java

@@ -16,10 +16,13 @@ import cn.com.qmth.examcloud.core.print.common.utils.JsonMapper;
 import cn.com.qmth.examcloud.core.print.entity.PrintingProject;
 import cn.com.qmth.examcloud.core.print.repository.PrintingProjectRepository;
 import cn.com.qmth.examcloud.core.print.service.PrintingProjectService;
+import cn.com.qmth.examcloud.core.print.service.bean.PrintingProjectInfo;
+import cn.com.qmth.examcloud.core.print.service.bean.PrintingProjectQuery;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -41,6 +44,17 @@ public class PrintingProjectServiceTest {
     @Autowired
     private JdbcTemplate jdbcTemplate;
 
+    @Test
+    public void pageTest() throws Exception {
+        PrintingProjectQuery query = new PrintingProjectQuery();
+        query.setOrgId(1L);
+        query.setExamId(1L);
+        query.setPmId(1L);
+        query.setSupplierId(1L);
+        Page<PrintingProjectInfo> page = printingProjectService.getPrintingProjectList(query);
+        System.out.println(new JsonMapper().toJson(page));
+    }
+
     //@Test
     public void specTest() throws Exception {
         //查询条件1
@@ -65,7 +79,7 @@ public class PrintingProjectServiceTest {
         System.out.println(new JsonMapper().toJson(list));
     }
 
-    @Test
+    //@Test
     public void sqlTest() throws Exception {
         SqlWrapper wrapper = new SqlWrapper();
         wrapper.select().from("ec_prt_project").where().like("exam_id", 1L);