haogh 1 rok pred
rodič
commit
66e8324a20

+ 11 - 0
pom.xml

@@ -150,6 +150,17 @@
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.itextpdf</groupId>
+            <artifactId>layout</artifactId>
+            <version>7.0.1</version>
+        </dependency>
+        <dependency>
+            <groupId>com.itextpdf</groupId>
+            <artifactId>kernel</artifactId>
+            <version>7.0.1</version>
+        </dependency>
+        
 
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 73 - 0
src/main/java/com/qmth/exam/reserve/bean/stdapply/ItextDocumentInfo.java

@@ -0,0 +1,73 @@
+package com.qmth.exam.reserve.bean.stdapply;
+
+import java.io.File;
+
+import com.itextpdf.kernel.font.PdfFont;
+import com.itextpdf.layout.Document;
+import com.qmth.exam.reserve.bean.IModel;
+import com.qmth.exam.reserve.util.ItextPdfUtil;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class ItextDocumentInfo implements IModel {
+
+    private static final long serialVersionUID = 7598562571622959860L;
+
+    @ApiModelProperty("页面宽度,单位mm")
+    private int page_width = 210;
+
+    @ApiModelProperty("页面高度,单位mm")
+    private int page_height = 297;
+
+    @ApiModelProperty("页面边距")
+    private String page_margin = "20 30 20 30";
+
+    protected int margin_top = 10;
+    protected int margin_right = 10;
+    protected int margin_bottom = 10;
+    protected int margin_left = 10;
+
+    protected PdfFont font = null;
+
+    protected PdfFont getFont() {
+        return font;
+    }
+
+    public Document prepareDocument(File tempFile) {
+        return prepareDocument(tempFile, ItextPdfUtil.getPdfFontSTSong());
+    }
+
+    public Document prepareDocument(File tempFile, PdfFont font) {
+        try {
+            String[] array = this.page_margin.split("\\s+");
+            margin_top = Integer.parseInt(array[0]);
+            margin_right = Integer.parseInt(array[1]);
+            margin_bottom = Integer.parseInt(array[2]);
+            margin_left = Integer.parseInt(array[3]);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        Document doc = ItextPdfUtil.createPdf(tempFile,
+                ItextPdfUtil.getPageSizeByMillimeter(this.page_width, this.page_height));
+
+        doc.setMargins(margin_top, margin_right, margin_bottom, margin_left);
+        if (font == null)
+            font = ItextPdfUtil.getPdfFontSTSong();
+        this.font = font;
+        doc.setFont(font);
+
+        return doc;
+    }
+
+    public void rotate() {
+        int w = this.page_width;
+        this.page_width = this.page_height;
+        this.page_height = w;
+    }
+
+}

+ 30 - 0
src/main/java/com/qmth/exam/reserve/bean/stdapply/MaterialTitleInfo.java

@@ -0,0 +1,30 @@
+package com.qmth.exam.reserve.bean.stdapply;
+
+import com.qmth.exam.reserve.bean.IModel;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class MaterialTitleInfo implements IModel {
+
+    private static final long serialVersionUID = -8349049302217270697L;
+
+    @ApiModelProperty("任务名称")
+    private String taskName;
+
+    @ApiModelProperty("考点名称")
+    private String siteName;
+
+    @ApiModelProperty("考点地址")
+    private String address;
+
+    @ApiModelProperty("考试时间")
+    private String timePeriod;
+
+    @ApiModelProperty("考场代码")
+    private String roomCode;
+
+}

+ 13 - 14
src/main/java/com/qmth/exam/reserve/controller/admin/StudentApplyController.java

@@ -1,5 +1,6 @@
 package com.qmth.exam.reserve.controller.admin;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -56,9 +57,6 @@ public class StudentApplyController extends BaseController {
     @Autowired
     private ExamSiteService examSiteService;
 
-    // @Autowired
-    // private MaterialGenerateService materialService;
-
     @ApiOperation(value = "预约任务列表")
     @PostMapping(value = "/task/list")
     public List<CategoryVO> listTask() {
@@ -138,17 +136,18 @@ public class StudentApplyController extends BaseController {
 
     @ApiOperation(value = "打印签到表")
     @GetMapping(value = "/std/auto/sign/in/print")
-    public void printSignIn(@ApiParam("教学点ID") @RequestParam Long teachingId) {
-        // TODO 教学点才能打印
-        // LoginUser user = this.curLoginUser();
-        // if (Role.ADMIN.equals(user.getRole()) && teachingId == null) {
-        // throw new StatusException("请选择教学点");
-        // }
-        // if (Role.TEACHING.equals(user.getRole())) {
-        // teachingId = user.getCategoryId();
-        // }
-        // exportFile("测试.pdf", materialService.generateSignInForm(1l));
-
+    public void printSignIn(@ApiParam("教学点ID") @RequestParam Long teachingId,
+            @ApiParam("考点ID") @RequestParam(required = false) Long agentId) {
+        LoginUser user = this.curLoginUser();
+        if (Role.ADMIN.equals(user.getRole()) && teachingId == null) {
+            throw new StatusException("请选择教学点");
+        }
+        if (Role.TEACHING.equals(user.getRole())) {
+            teachingId = user.getCategoryId();
+        }
+        File signInZip = studentApplyService.downloadSignIn(teachingId, agentId);
+        exportFile(signInZip.getName(), signInZip);
+        signInZip.delete();
     }
 
     @ApiOperation(value = "自动排考")

+ 2 - 0
src/main/java/com/qmth/exam/reserve/dao/StudentApplyDao.java

@@ -27,4 +27,6 @@ public interface StudentApplyDao extends BaseMapper<StudentApplyEntity> {
     List<StudentApplyEntity> listTimePeriod(@Param(value = "timePeriodIds") List<Long> timePeriodIds,
             @Param(value = "cancel") Boolean cancel);
 
+    List<StudentApplyVO> listStudentApply(@Param("timePeriodId") Long timePeriodId, @Param("roomId") Long roomId);
+
 }

+ 12 - 0
src/main/java/com/qmth/exam/reserve/service/MaterialGenerateService.java

@@ -0,0 +1,12 @@
+package com.qmth.exam.reserve.service;
+
+import java.io.File;
+import java.util.List;
+
+import com.qmth.exam.reserve.bean.stdapply.MaterialTitleInfo;
+import com.qmth.exam.reserve.bean.stdapply.StudentApplyVO;
+
+public interface MaterialGenerateService {
+
+    File generateSignInForm(MaterialTitleInfo title, List<StudentApplyVO> studentList);
+}

+ 3 - 0
src/main/java/com/qmth/exam/reserve/service/StudentApplyService.java

@@ -1,5 +1,6 @@
 package com.qmth.exam.reserve.service;
 
+import java.io.File;
 import java.io.InputStream;
 import java.util.List;
 import java.util.Map;
@@ -23,4 +24,6 @@ public interface StudentApplyService extends IService<StudentApplyEntity> {
 
     void autoLayout(Long teachingId);
 
+    File downloadSignIn(Long teachingId, Long agentId);
+
 }

+ 158 - 0
src/main/java/com/qmth/exam/reserve/service/impl/MaterialGenerateServiceImpl.java

@@ -0,0 +1,158 @@
+package com.qmth.exam.reserve.service.impl;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.stereotype.Service;
+
+import com.itextpdf.layout.Document;
+import com.itextpdf.layout.element.AreaBreak;
+import com.itextpdf.layout.element.Cell;
+import com.itextpdf.layout.element.Paragraph;
+import com.itextpdf.layout.element.Table;
+import com.itextpdf.layout.property.TextAlignment;
+import com.itextpdf.layout.property.VerticalAlignment;
+import com.qmth.boot.core.exception.StatusException;
+import com.qmth.boot.tools.uuid.FastUUID;
+import com.qmth.exam.reserve.bean.stdapply.ItextDocumentInfo;
+import com.qmth.exam.reserve.bean.stdapply.MaterialTitleInfo;
+import com.qmth.exam.reserve.bean.stdapply.StudentApplyVO;
+import com.qmth.exam.reserve.service.MaterialGenerateService;
+import com.qmth.exam.reserve.util.ItextPdfUtil;
+
+@Service
+public class MaterialGenerateServiceImpl implements MaterialGenerateService {
+
+    private static final int LINE_NUMBER = 30;
+    private static final int STUDENT_NUMBER_ROW = 2;
+    private static final int FONT_SIZE = 12;
+    private static final int LINE_HEIGHT = 25;
+
+    @Override
+    public File generateSignInForm(MaterialTitleInfo title, List<StudentApplyVO> studentList) {
+        Document doc = null;
+        ItextDocumentInfo pageModel = new ItextDocumentInfo();
+        List<StudentApplyVO> tempList = new ArrayList<StudentApplyVO>();
+        try {
+            File file = File.createTempFile("Material" + FastUUID.get(), ".tmp");
+            doc = pageModel.prepareDocument(file);
+            doc.setMargins(20, 20, 20, 20);
+
+            Paragraph p1 = new Paragraph(title.getTaskName()).setFontSize(18).setBold()
+                    .setTextAlignment(TextAlignment.CENTER).setMarginTop(-2);
+            doc.add(p1);
+            int fontSize = 12;
+            doc.add(subHead(title, studentList.size(), fontSize));
+            for (int k = 0; k < studentList.size(); k++) {
+                tempList.add(studentList.get(k));
+                if (tempList.size() == LINE_NUMBER * STUDENT_NUMBER_ROW || k == studentList.size() - 1) {
+                    createSignInTable(tempList, doc);
+                    if (tempList.size() == LINE_NUMBER * STUDENT_NUMBER_ROW) {
+                        doc.add(new AreaBreak());
+                    }
+                    tempList.clear();
+                }
+            }
+            return file;
+        } catch (Exception e) {
+            e.printStackTrace();
+            ItextPdfUtil.closePdf(doc);
+            throw new StatusException("无法生成pdf");
+        } finally {
+            ItextPdfUtil.closePdf(doc);
+        }
+
+    }
+
+    private void createSignInTable(List<StudentApplyVO> tempList, Document doc) {
+        Table tableTitle = tableTitle();
+        int number = LINE_NUMBER;
+        if (tempList.size() < LINE_NUMBER) {
+            number = tempList.size();
+        }
+        for (int i = 0; i < number; i++) {
+            StudentApplyVO result = null;
+            if (tempList.size() >= i + 1) {
+                result = tempList.get(i);
+                tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getName() : " ")
+                        .setTextAlignment(TextAlignment.CENTER).setVerticalAlignment(VerticalAlignment.MIDDLE)
+                        .setFontSize(FONT_SIZE));
+                tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getStudentCode() : " ")
+                        .setTextAlignment(TextAlignment.CENTER).setVerticalAlignment(VerticalAlignment.MIDDLE)
+                        .setFontSize(FONT_SIZE));
+                tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getSeatNumber() : " ")
+                        .setTextAlignment(TextAlignment.CENTER).setVerticalAlignment(VerticalAlignment.MIDDLE)
+                        .setFontSize(FONT_SIZE));
+                tableTitle.addCell(new Cell(1, 1).add(" ").setTextAlignment(TextAlignment.CENTER)
+                        .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(FONT_SIZE));
+            } else {
+                tableTitle.addCell(new Cell().add(" ").setTextAlignment(TextAlignment.CENTER)
+                        .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(10).setHeight(LINE_HEIGHT));
+                tableTitle.addCell(new Cell().add(" ").setTextAlignment(TextAlignment.CENTER)
+                        .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(10).setHeight(LINE_HEIGHT));
+                tableTitle.addCell(new Cell().add(" ").setTextAlignment(TextAlignment.CENTER)
+                        .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(10).setHeight(LINE_HEIGHT));
+                tableTitle.addCell(new Cell().add(" ").setTextAlignment(TextAlignment.CENTER)
+                        .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(10).setHeight(LINE_HEIGHT));
+            }
+            if (tempList.size() >= i + number + 1) {
+                result = tempList.get(i + 30);
+                tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getName() : " ")
+                        .setTextAlignment(TextAlignment.CENTER).setVerticalAlignment(VerticalAlignment.MIDDLE)
+                        .setFontSize(FONT_SIZE));
+                tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getStudentCode() : " ")
+                        .setTextAlignment(TextAlignment.CENTER).setVerticalAlignment(VerticalAlignment.MIDDLE)
+                        .setFontSize(FONT_SIZE));
+                tableTitle.addCell(new Cell(1, 1).add(result != null ? result.getSeatNumber() : " ")
+                        .setTextAlignment(TextAlignment.CENTER).setVerticalAlignment(VerticalAlignment.MIDDLE)
+                        .setFontSize(FONT_SIZE));
+                tableTitle.addCell(new Cell(1, 1).add(" ").setTextAlignment(TextAlignment.CENTER)
+                        .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(FONT_SIZE));
+            } else {
+                tableTitle.addCell(new Cell().add(" ").setTextAlignment(TextAlignment.CENTER)
+                        .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(10).setHeight(LINE_HEIGHT));
+                tableTitle.addCell(new Cell().add(" ").setTextAlignment(TextAlignment.CENTER)
+                        .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(10).setHeight(LINE_HEIGHT));
+                tableTitle.addCell(new Cell().add(" ").setTextAlignment(TextAlignment.CENTER)
+                        .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(10).setHeight(LINE_HEIGHT));
+                tableTitle.addCell(new Cell().add(" ").setTextAlignment(TextAlignment.CENTER)
+                        .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(10).setHeight(LINE_HEIGHT));
+            }
+        }
+        doc.add(tableTitle);
+    }
+
+    private Table subHead(MaterialTitleInfo title, int studentSize, int titleFontSize) {
+        Table table = new Table(new float[] { 1f, 1f }).setWidthPercent(100);
+        table.addCell(new Cell(1, 1).add("考点名称:" + title.getSiteName()).setTextAlignment(TextAlignment.LEFT)
+                .setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(null).setFontSize(titleFontSize)
+                .setMarginLeft(20f));
+        table.addCell(new Cell(1, 1).add("考试时间:" + title.getTimePeriod()).setTextAlignment(TextAlignment.LEFT)
+                .setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(null).setFontSize(titleFontSize)
+                .setMarginLeft(40f));
+        table.addCell(new Cell(1, 1).add("考场名称:" + title.getAddress()).setTextAlignment(TextAlignment.LEFT)
+                .setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(null).setFontSize(titleFontSize)
+                .setMarginLeft(20f));
+        table.addCell(new Cell(1, 1).add("考生数量:" + studentSize).setTextAlignment(TextAlignment.LEFT)
+                .setVerticalAlignment(VerticalAlignment.MIDDLE).setBorder(null).setFontSize(titleFontSize)
+                .setMarginLeft(40f));
+        return table;
+    }
+
+    private Table tableTitle() {
+        Table signTable = new Table(new float[] { 1f, 1.3f, 0.5f, 1f, 1f, 1.3f, 0.5f, 1f }).setWidthPercent(100);
+        for (int i = 0; i < STUDENT_NUMBER_ROW; i++) {
+            signTable.addCell(new Cell(1, 1).add("姓名").setTextAlignment(TextAlignment.CENTER)
+                    .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(FONT_SIZE).setBold());
+            signTable.addCell(new Cell(1, 1).add("学号").setTextAlignment(TextAlignment.CENTER)
+                    .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(FONT_SIZE).setBold());
+            signTable.addCell(new Cell(1, 1).add("座号").setTextAlignment(TextAlignment.CENTER)
+                    .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(FONT_SIZE).setBold());
+            signTable.addCell(new Cell(1, 1).add("签字").setTextAlignment(TextAlignment.CENTER)
+                    .setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(FONT_SIZE).setBold());
+        }
+        return signTable;
+    }
+
+}

+ 68 - 3
src/main/java/com/qmth/exam/reserve/service/impl/StudentApplyServiceImpl.java

@@ -1,5 +1,7 @@
 package com.qmth.exam.reserve.service.impl;
 
+import java.io.File;
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -32,9 +34,11 @@ import com.qmth.boot.core.exception.StatusException;
 import com.qmth.boot.tools.excel.ExcelReader;
 import com.qmth.boot.tools.excel.enums.ExcelType;
 import com.qmth.boot.tools.excel.model.DataMap;
+import com.qmth.boot.tools.io.ZipWriter;
 import com.qmth.boot.tools.uuid.FastUUID;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.stdapply.AgentAndTimeVO;
+import com.qmth.exam.reserve.bean.stdapply.MaterialTitleInfo;
 import com.qmth.exam.reserve.bean.stdapply.StudentApplyReq;
 import com.qmth.exam.reserve.bean.stdapply.StudentApplyVO;
 import com.qmth.exam.reserve.bean.stdapply.StudentImportVO;
@@ -54,6 +58,7 @@ import com.qmth.exam.reserve.service.ApplyTaskService;
 import com.qmth.exam.reserve.service.CategoryService;
 import com.qmth.exam.reserve.service.ExamRoomService;
 import com.qmth.exam.reserve.service.ExamSiteService;
+import com.qmth.exam.reserve.service.MaterialGenerateService;
 import com.qmth.exam.reserve.service.OperateLogService;
 import com.qmth.exam.reserve.service.StudentApplyService;
 import com.qmth.exam.reserve.service.StudentService;
@@ -97,6 +102,9 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
     @Autowired
     private ExamRoomService examRoomService;
 
+    @Autowired
+    private MaterialGenerateService materialService;
+
     @Override
     public PageResult<StudentApplyVO> page(StudentApplyReq req) {
         IPage<StudentApplyVO> iPage = this.baseMapper
@@ -463,7 +471,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
             checkTeachingCapacity(map, timeList, taskId);
             // 3、按照教学点安排考位。规则:不能和已预约的时间上有冲突
             for (Long key : map.keySet()) {
-                List<ExamSiteEntity> siteList = listExamSite(key);
+                List<ExamSiteEntity> siteList = listExamSite(key, null);
                 List<StudentEntity> teachingStudentList = map.get(key);
                 for (TimePeriodEntity time : timeList) {
                     for (ExamSiteEntity site : siteList) {
@@ -544,7 +552,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
     private void checkTeachingCapacity(Map<Long, List<StudentEntity>> map, List<TimePeriodEntity> timeList,
             Long taskId) {
         for (Long key : map.keySet()) {
-            List<ExamSiteEntity> siteList = listExamSite(key);
+            List<ExamSiteEntity> siteList = listExamSite(key, null);
             // 总考位数量
             Integer total = siteList.stream().collect(Collectors.summingInt(ExamSiteEntity::getCapacity))
                     * timeList.size();
@@ -592,9 +600,11 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         return timeList;
     }
 
-    private List<ExamSiteEntity> listExamSite(Long categoryId) {
+    private List<ExamSiteEntity> listExamSite(Long categoryId, Long examsiteId) {
         LambdaQueryWrapper<ExamSiteEntity> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(ExamSiteEntity::getCategoryId, categoryId);
+        wrapper.eq(examsiteId != null, ExamSiteEntity::getId, examsiteId);
+        wrapper.eq(ExamSiteEntity::getEnable, Boolean.TRUE);
         return examSiteService.list(wrapper);
     }
 
@@ -723,4 +733,59 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         return DateUtil.addValues(Calendar.DAY_OF_MONTH, allowApplyCancelDays);
     }
 
+    @Override
+    public File downloadSignIn(Long teachingId, Long agentId) {
+        ApplyTaskEntity applyTask = getApplyTask();
+        List<TimePeriodEntity> timePeriodList = listTimePeroid(applyTask.getId());
+        List<TimePeriodEntity> noCancelTimePeroidList = listNoCancelApplyTimePeroid(timePeriodList,
+                applyTask.getAllowApplyCancelDays());
+        if (noCancelTimePeroidList.isEmpty()) {
+            throw new StatusException("当前时间没有可下载的签到表");
+        }
+        List<ExamSiteEntity> siteList = listExamSite(teachingId, agentId);
+        if (siteList.isEmpty())
+            throw new StatusException("当前教学点下没有可用的考点");
+        CategoryEntity category = categoryService.getById(teachingId);
+        File tempFolder = new File("temp");
+        if (!tempFolder.exists()) {
+            tempFolder.mkdirs();
+        }
+        ZipWriter writer = null;
+        File zipFile = new File(tempFolder, category.getName() + "签到表.zip");
+        try {
+            writer = ZipWriter.create(zipFile);
+            for (ExamSiteEntity site : siteList) {
+                downloadByExamSite(writer, applyTask.getName(), site, noCancelTimePeroidList);
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+            throw new StatusException("文件写入异常");
+        }
+        writer.close();
+        return zipFile;
+    }
+
+    public List<File> downloadByExamSite(ZipWriter writer, String taskName, ExamSiteEntity site,
+            List<TimePeriodEntity> timeList) throws IOException {
+        List<File> fileList = new ArrayList<>();
+        List<ExamRoomEntity> roomList = listExamRoom(site.getId());
+        MaterialTitleInfo title = new MaterialTitleInfo();
+        title.setTaskName(taskName);
+        title.setSiteName(site.getName());
+        for (TimePeriodEntity time : timeList) {
+            title.setTimePeriod(DateUtil.getStartAndEndTime(time.getStartTime(), time.getEndTime()));
+            for (ExamRoomEntity room : roomList) {
+                title.setAddress(room.getAddress());
+                title.setRoomCode(room.getCode());
+                List<StudentApplyVO> studentList = baseMapper.listStudentApply(time.getId(), room.getId());
+                if (!studentList.isEmpty()) {
+                    File file = materialService.generateSignInForm(title, studentList);
+                    writer.write(file, title.getSiteName(),
+                            title.getTimePeriod() + " 第【" + title.getRoomCode() + "】考场" + ".pdf");
+                }
+            }
+        }
+        return fileList;
+    }
+
 }

+ 26 - 6
src/main/java/com/qmth/exam/reserve/util/DateUtil.java

@@ -19,6 +19,7 @@ public class DateUtil {
 
     public final static String LongDateString = "yyyy-MM-dd HH:mm:ss";
     public final static String LongZHDateString = "yyyy年MM月dd日 HH:mm:ss";
+    public final static String LongZHNoSecondString = "yyyy年MM月dd日 HH:mm";
     public final static String ShortDateString = "yyyy-MM-dd";
     public final static String ShortDateStringWithoutSplit = "yyyyMMdd";
     public final static String ShortTimeString = "HH:mm:ss";
@@ -87,8 +88,13 @@ public class DateUtil {
     }
 
     public static void main(String[] args) {
-        String result = formatShortDateString(new Date());
-        System.out.println(result);
+        // String result = formatShortDateString(new Date());
+        // System.out.println(result);
+        // Date date = new Date(1715749200000l);
+        // String result = format(date, "yyyy-MM-dd HH:mm:ss");
+        // System.out.println(result);
+
+        System.out.println(getLongTimeByDate("2024-05-15 12:00:00"));
     }
 
     public static Date addValues(int filed, int value) {
@@ -177,8 +183,10 @@ public class DateUtil {
     /**
      * 获取某天的起点时间
      *
-     * @param date       某个日期
-     * @param changeDays 日期前后调整几天
+     * @param date
+     *            某个日期
+     * @param changeDays
+     *            日期前后调整几天
      * @return 示例:2024-01-01 00:00:00
      */
     public static Date changeDateAndTimeBegin(Date date, int changeDays) {
@@ -196,8 +204,10 @@ public class DateUtil {
     /**
      * 获取某天的终点时间
      *
-     * @param date       某个日期
-     * @param changeDays 日期前后调整几天
+     * @param date
+     *            某个日期
+     * @param changeDays
+     *            日期前后调整几天
      * @return 示例:2024-01-01 23:59:59
      */
     public static Date changeDateAndTimeEnd(Date date, int changeDays) {
@@ -212,4 +222,14 @@ public class DateUtil {
         return calendar.getTime();
     }
 
+    public static String getStartAndEndTime(long startTime, long endTime) {
+        try {
+            Date start = new Date(startTime);
+            Date end = new Date(endTime);
+            return format(start, LongZHNoSecondString) + "-" + format(end, HourMinuteString);
+        } catch (Exception e) {
+            throw new StatusException("日期转化异常");
+        }
+    }
+
 }

+ 151 - 0
src/main/java/com/qmth/exam/reserve/util/ItextPdfUtil.java

@@ -0,0 +1,151 @@
+package com.qmth.exam.reserve.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.lang3.StringUtils;
+
+import com.itextpdf.io.font.PdfEncodings;
+import com.itextpdf.kernel.font.PdfFont;
+import com.itextpdf.kernel.font.PdfFontFactory;
+import com.itextpdf.kernel.geom.PageSize;
+import com.itextpdf.kernel.pdf.EncryptionConstants;
+import com.itextpdf.kernel.pdf.PdfDocument;
+import com.itextpdf.kernel.pdf.PdfWriter;
+import com.itextpdf.kernel.pdf.WriterProperties;
+import com.itextpdf.layout.Document;
+import com.qmth.boot.core.exception.StatusException;
+
+public class ItextPdfUtil {
+
+    /*********************
+     * 默认页面72像素/英寸
+     */
+    public static int ItextPagePix = 72;
+    // 一英寸等于25.4毫米
+    public final static double InchMillimeter = 25.4;
+
+    /********************
+     * 获取pdf默认字体
+     */
+    public static PdfFont getPdfFont() {
+        try {
+            return PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H", false);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    /**********************
+     * 获取宋体字体,如无法获取,获取默认字体
+     */
+    public static PdfFont getPdfFontSTSong() {
+        try {
+            InputStream in = ResourceUtil.getStream("font" + File.separator + "STSONG.TTF");
+            return PdfFontFactory.createFont(getByte(in), PdfEncodings.IDENTITY_H, false);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return getPdfFont();
+        }
+    }
+
+    public static byte[] getByte(InputStream in) {
+        InputStream stream = ResourceUtil.getStream("font" + File.separator + "STSONG.TTF");
+        ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
+        byte[] buff = new byte[100];
+        int rc = 0;
+        try {
+            while ((rc = stream.read(buff, 0, 100)) > 0) {
+                swapStream.write(buff, 0, rc);
+            }
+        } catch (IOException e) {
+            throw new StatusException("读取文件异常");
+        }
+        return swapStream.toByteArray();
+    }
+
+    public static Document createPdf(File file, PageSize pageSize, String passwd) {
+        PdfDocument pdfDoc = null;
+        Document doc = null;
+        try {
+
+            if (StringUtils.isNotEmpty(passwd))
+                pdfDoc = new PdfDocument(new PdfWriter(file.getPath(),
+                        new WriterProperties().setStandardEncryption(null, passwd.getBytes(),
+                                EncryptionConstants.ALLOW_PRINTING,
+                                EncryptionConstants.ENCRYPTION_AES_128 | EncryptionConstants.DO_NOT_ENCRYPT_METADATA)));
+            else
+                pdfDoc = new PdfDocument(new PdfWriter(file.getPath()));
+            doc = new Document(pdfDoc, pageSize);
+            return doc;
+        } catch (Exception e) {
+            throw new StatusException("无法创建临时文件!");
+        }
+    }
+
+    /**********************
+     * 创建A4,自带加密
+     */
+    public static Document createPdf(File file, String passwd) {
+        return createPdf(file, PageSize.A4, passwd);
+    }
+
+    /**********************
+     * 创建A4,自带加密
+     */
+    public static Document createPdf(File file, PageSize pageSize) {
+        return createPdf(file, pageSize, null);
+    }
+
+    public static Document createPdf(File file) {
+        return createPdf(file, PageSize.A4, null);
+    }
+
+    public static void closePdf(Document doc) {
+        if (doc != null) {
+            try {
+
+                doc.flush();
+                doc.close();
+            } catch (Exception ex) {
+                ex.printStackTrace();
+            }
+            try {
+                doc.getPdfDocument().close();
+            } catch (Exception ex) {
+                ex.printStackTrace();
+            }
+            doc = null;
+
+        }
+    }
+
+    /*********************
+     * 获取纸张大小
+     * 
+     * @param width
+     *            宽度 单位毫米
+     * @param heigth
+     *            高度 单位毫米 72像素/英寸=28.346像素/厘米 A4:595, 842 A3:842, 1190
+     */
+    public static PageSize getPageSizeByMillimeter(int width, int heigth) {
+        return new PageSize(getPixByMillimeter(width), getPixByMillimeter(heigth));
+
+    }
+
+    /****************
+     * 根据毫米返回itext的像素
+     */
+    public static int getPixByMillimeter(int millimeter) {
+        return (int) Math.round(millimeter / InchMillimeter * ItextPagePix);
+    }
+
+    /****************
+     * 根据itext像素返回的毫米
+     */
+    public static int getMillimeterByPix(int pix) {
+        return (int) Math.round((double) pix / ItextPagePix * InchMillimeter);
+    }
+}

BIN
src/main/resources/font/STSONG.TTF


+ 13 - 0
src/main/resources/mapper/StudentApplyMapper.xml

@@ -98,5 +98,18 @@
 		</foreach>
 		 order by s.student_code
 	</select>
+	
+	<select id="listStudentApply" resultType="com.qmth.exam.reserve.bean.stdapply.StudentApplyVO">
+		select s.name,s.student_code studentCode,sa.seat_number seatNumber from t_student_apply sa,t_student s where sa.student_id=s.id and seat_number is not null
+		and cancel=0
+		<if test="timePeriodId!=null">
+			and sa.time_period_id=#{timePeriodId}
+		</if>
+		<if test="roomId!=null">
+			and sa.exam_room_id=#{roomId}
+		</if>
+		order by sa.seat_number
+	
+	</select>
 
 </mapper>