feat: 学生评价报告 pdf 导出

11111
winter 11 months ago
parent f3e3f48422
commit 8b25e112e8

@ -42,6 +42,24 @@
<artifactId>spring-boot-configuration-processor</artifactId> <artifactId>spring-boot-configuration-processor</artifactId>
</dependency> </dependency>
<!-- pdf操作类 -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.10</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
<!--用于jfreechart制作统计图 -->
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.5.0</version>
</dependency>
<dependency> <dependency>
<groupId>com.squareup.okhttp3</groupId> <groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId> <artifactId>okhttp</artifactId>

@ -7,6 +7,7 @@ import cn.teammodel.model.entity.appraise.Appraise;
import cn.teammodel.model.vo.appraise.AppraiseRecordVo; import cn.teammodel.model.vo.appraise.AppraiseRecordVo;
import cn.teammodel.model.vo.appraise.StudentReportVo; import cn.teammodel.model.vo.appraise.StudentReportVo;
import cn.teammodel.service.EvaluationService; import cn.teammodel.service.EvaluationService;
import com.itextpdf.text.DocumentException;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -15,7 +16,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
@ -83,6 +86,9 @@ public class AppraiseController {
return R.success(res); return R.success(res);
} }
@PostMapping("studentReportPDF")
@ApiOperation(value = "导出学生当前的学期的实时评价报告 PDF")
public void exportStuReportPdf(@Valid @RequestBody IdRequest idRequest, HttpServletResponse response) throws DocumentException, IOException {
evaluationService.exportStuReportPdf(idRequest, response);
}
} }

@ -1,7 +1,11 @@
package cn.teammodel.controller.frontend; package cn.teammodel.controller.frontend;
import cn.hutool.core.map.MapUtil;
import cn.teammodel.common.R; import cn.teammodel.common.R;
import cn.teammodel.repository.AppraiseRepository; import cn.teammodel.repository.AppraiseRepository;
import cn.teammodel.service.EvaluationService;
import cn.teammodel.utils.PdfUtil;
import com.itextpdf.text.DocumentException;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
@ -10,12 +14,17 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
@RestController @RestController
@RequestMapping("/") @RequestMapping("/")
@Api(tags = "鉴权测试") @Api(tags = "鉴权测试")
public class HelloController { public class HelloController {
@Resource
private EvaluationService evaluationService;
@Resource @Resource
private AppraiseRepository appraiseRepository; private AppraiseRepository appraiseRepository;
@ -31,4 +40,12 @@ public class HelloController {
public R<String> free() { public R<String> free() {
return new R(200, "success","hello world"); return new R(200, "success","hello world");
} }
@GetMapping("public/pdf")
public void freepdf(HttpServletResponse response) throws DocumentException, IOException {
Map<String, String> data = MapUtil.ofEntries(MapUtil.entry("Text1", "1000"), MapUtil.entry("Text2", "2000"), MapUtil.entry("Text3", "3000"));
PdfUtil.fillStudentPdfForm(data, response);
}
} }

@ -6,7 +6,10 @@ import cn.teammodel.model.entity.appraise.Appraise;
import cn.teammodel.model.entity.appraise.AppraiseTreeNode; import cn.teammodel.model.entity.appraise.AppraiseTreeNode;
import cn.teammodel.model.vo.appraise.AppraiseRecordVo; import cn.teammodel.model.vo.appraise.AppraiseRecordVo;
import cn.teammodel.model.vo.appraise.StudentReportVo; import cn.teammodel.model.vo.appraise.StudentReportVo;
import com.itextpdf.text.DocumentException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
@ -59,4 +62,6 @@ public interface EvaluationService {
* *
*/ */
StudentReportVo studentReport(IdRequest idRequest); StudentReportVo studentReport(IdRequest idRequest);
void exportStuReportPdf(IdRequest idRequest, HttpServletResponse response) throws IOException, DocumentException;
} }

@ -22,6 +22,7 @@ import cn.teammodel.utils.RepositoryUtil;
import cn.teammodel.utils.SchoolDateUtil; import cn.teammodel.utils.SchoolDateUtil;
import com.azure.cosmos.models.CosmosPatchOperations; import com.azure.cosmos.models.CosmosPatchOperations;
import com.azure.spring.data.cosmos.core.query.CosmosPageRequest; import com.azure.spring.data.cosmos.core.query.CosmosPageRequest;
import com.itextpdf.text.DocumentException;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@ -29,6 +30,9 @@ import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.*; import java.util.*;
@ -602,6 +606,14 @@ public class EvaluationServiceImpl implements EvaluationService {
.build(); .build();
} }
@Override
public void exportStuReportPdf(IdRequest idRequest, HttpServletResponse response) throws IOException, DocumentException{
ServletOutputStream os = response.getOutputStream();
}
/** /**
* id id () * id id ()
*/ */

@ -0,0 +1,43 @@
package cn.teammodel.utils;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import org.springframework.core.io.ClassPathResource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
/**
* @author winter
* @create 2024-01-24 16:02
*/
public class PdfUtil {
public static void fillStudentPdfForm(Map<String, String> data, HttpServletResponse response) throws IOException, DocumentException {
response.reset();
response.setContentType("application/pdf");
response.setHeader("Content-disposition",
"attachment;filename=report_student_" + System.currentTimeMillis() + ".pdf");
ClassPathResource resource = new ClassPathResource("templates/pdf_templates/template.pdf");
InputStream in = resource.getInputStream();
ServletOutputStream os = response.getOutputStream();
fillPdfForm(in, os, data);
}
public static void fillPdfForm(InputStream in, OutputStream os, Map<String, String> data) throws IOException, DocumentException {
PdfReader pdfReader = new PdfReader(in);
PdfStamper stamper = new PdfStamper(pdfReader, os);
AcroFields fields = stamper.getAcroFields();
for (Map.Entry<String, String> entry : data.entrySet()) {
fields.setField(entry.getKey(), entry.getValue());
}
stamper.close();
os.close();
}
}
Loading…
Cancel
Save