|
|
@@ -18,23 +18,20 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.File;
|
|
|
import java.io.PrintWriter;
|
|
|
-import java.net.URLEncoder;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
import java.nio.file.Paths;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class RateService {
|
|
|
|
|
|
- private RateRepo rateRepo;
|
|
|
+ private final RateRepo rateRepo;
|
|
|
|
|
|
public Page<Rate> all(PageQuery pageQuery) {
|
|
|
return rateRepo.findAll(JpaUtils.toSpecification(pageQuery, Rate.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
@@ -74,7 +71,8 @@ public class RateService {
|
|
|
//单位
|
|
|
dataMap.put("name", rate.getName());
|
|
|
//日期
|
|
|
- dataMap.put("date", DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_FORMAT).format(rate.getCreatedAt()));
|
|
|
+ dataMap.put("date", DateTimeFormatter.ofPattern(DateConfig.DEFAULT_DATE_FORMAT)
|
|
|
+ .format(rate.getCreatedAt()));
|
|
|
//负责人
|
|
|
dataMap.put("owner", rate.getOwner());
|
|
|
//电话
|
|
|
@@ -84,7 +82,7 @@ public class RateService {
|
|
|
//承办过
|
|
|
dataMap.put("undertake", rate.isUndertakeExamination() ? "是" : "否");
|
|
|
//考级机构名称
|
|
|
- if (rate.isUndertakeExamination()){
|
|
|
+ if (rate.isUndertakeExamination()) {
|
|
|
dataMap.put("examination", String.join(",", rate.getExamination()));
|
|
|
}
|
|
|
//单位概况
|
|
|
@@ -92,13 +90,13 @@ public class RateService {
|
|
|
//Configuration 用于读取ftl文件
|
|
|
Configuration configuration = new Configuration(new Version("2.3.0"));
|
|
|
|
|
|
-
|
|
|
configuration.setDefaultEncoding("utf-8");
|
|
|
|
|
|
configuration.setDirectoryForTemplateLoading(new File(Paths.get(System.getProperty("user.dir"), "src", "main", "resources", "templates")
|
|
|
.toString()));//指定ftl所在目录,根据自己的改
|
|
|
response.setContentType("application/msword");
|
|
|
- response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("等级评定申报表", "UTF-8")+".doc");
|
|
|
+ String fileName = DateTimeFormatter.ofPattern("yyyyMMdd").format(LocalDate.now());
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".doc");
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
PrintWriter out = response.getWriter();
|
|
|
Template template = configuration.getTemplate("RateTemplate.ftl", "utf-8");//以utf-8的编码读取ftl文件
|