Commit fa8137f8 by zwb

修改简历生成html文件添加字体参数

parent 1ed5c8ba
...@@ -156,7 +156,7 @@ public class NewEditionResumeController { ...@@ -156,7 +156,7 @@ public class NewEditionResumeController {
if (dto.getResumeId() == null) { if (dto.getResumeId() == null) {
throw new WarnException("简历ID不能为空"); throw new WarnException("简历ID不能为空");
} }
return new R<>(this.newEditionResumeService.createResumeHtml(dto.getResumeId(), dto.getTemplateName())); return new R<>(this.newEditionResumeService.createResumeHtml(dto.getResumeId(), dto.getTemplateName(), dto.getFontSize(), dto.getLineHeight()));
} }
/** /**
......
...@@ -15,4 +15,10 @@ public class ResumeByPdfDto { ...@@ -15,4 +15,10 @@ public class ResumeByPdfDto {
@Schema(description = "权益id") @Schema(description = "权益id")
private String vipId; private String vipId;
@Schema(description = "字体大小")
private String fontSize;
@Schema(description = "行高")
private String lineHeight;
} }
package com.bkty.system.domain.dto; package com.bkty.system.domain.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
...@@ -60,4 +61,10 @@ public class ResumeMakeDto { ...@@ -60,4 +61,10 @@ public class ResumeMakeDto {
/**模块名称*/ /**模块名称*/
private String modelName; private String modelName;
/**字体大小*/
private String fontSize;
/**行高*/
private String lineHeight;
} }
...@@ -72,7 +72,7 @@ public interface NewEditionResumeService { ...@@ -72,7 +72,7 @@ public interface NewEditionResumeService {
* @param templateName * @param templateName
* @return * @return
*/ */
String createResumeHtml(String resumeId, String templateName); String createResumeHtml(String resumeId, String templateName, String fontSize, String lineHeight);
/** /**
* 简历模块优化 * 简历模块优化
...@@ -128,4 +128,5 @@ public interface NewEditionResumeService { ...@@ -128,4 +128,5 @@ public interface NewEditionResumeService {
* @return * @return
*/ */
ResumeByPdfVo createResumeMinPng(ResumeByPdfDto dto); ResumeByPdfVo createResumeMinPng(ResumeByPdfDto dto);
} }
...@@ -662,7 +662,7 @@ public class NewEditionResumeServiceImpl implements NewEditionResumeService { ...@@ -662,7 +662,7 @@ public class NewEditionResumeServiceImpl implements NewEditionResumeService {
} }
//缓存简历大JSON //缓存简历大JSON
queryNewEditionResumeId(resumeMakeDto.getResumeId()); queryNewEditionResumeId(resumeMakeDto.getResumeId());
return createResumeHtml(resumeMakeDto.getResumeId(), resumeMakeDto.getTemplateName()); return createResumeHtml(resumeMakeDto.getResumeId(), resumeMakeDto.getTemplateName(),resumeMakeDto.getFontSize(),resumeMakeDto.getLineHeight());
} }
@Override @Override
...@@ -698,10 +698,16 @@ public class NewEditionResumeServiceImpl implements NewEditionResumeService { ...@@ -698,10 +698,16 @@ public class NewEditionResumeServiceImpl implements NewEditionResumeService {
} }
@Override @Override
public String createResumeHtml(String resumeId, String templateName) { public String createResumeHtml(String resumeId, String templateName, String fontSize, String lineHeight) {
if (StringUtils.isBlank(templateName)) { if (StringUtils.isBlank(templateName)) {
templateName = "tpl21.ejs"; templateName = "tpl21.ejs";
} }
if (fontSize==null || fontSize.equals("")) {
fontSize = "14px";
}
if (lineHeight == null || lineHeight.equals("")) {
lineHeight = "1.7";
}
if (StringUtils.isBlank(resumeId)) { if (StringUtils.isBlank(resumeId)) {
throw new WarnException("简历ID不能为空"); throw new WarnException("简历ID不能为空");
} }
...@@ -721,6 +727,8 @@ public class NewEditionResumeServiceImpl implements NewEditionResumeService { ...@@ -721,6 +727,8 @@ public class NewEditionResumeServiceImpl implements NewEditionResumeService {
// 更新 base_info // 更新 base_info
objectMap.put("base", jsonObject); objectMap.put("base", jsonObject);
} }
// objectMap.put("fontSize",fontSize!=null?fontSize:"14px");
// objectMap.put("lineHeight",lineHeight!=null?lineHeight:"1.7");
String jsonString = JSON.toJSONString(objectMap); String jsonString = JSON.toJSONString(objectMap);
if (objectMap.get("base") != null) { if (objectMap.get("base") != null) {
...@@ -748,7 +756,7 @@ public class NewEditionResumeServiceImpl implements NewEditionResumeService { ...@@ -748,7 +756,7 @@ public class NewEditionResumeServiceImpl implements NewEditionResumeService {
String htmlName = resumeId + ".html"; String htmlName = resumeId + ".html";
FileProcessor.processFile(properties.getPath() + "template/" + templateName, properties.getPath() + "output/" + htmlName, "<%- data %>", jsonString); FileProcessor.processFileWithSize(properties.getPath() + "template/" + templateName, properties.getPath() + "output/" + htmlName, "<%- data %>", jsonString,"<%- FontSize %>", fontSize,"<%- LineHeight %>", lineHeight);
redisTemplate.opsForValue().set(CacheConstants.CREATE_RESUME_HTML_DATA.formatted(resumeId), jsonString); redisTemplate.opsForValue().set(CacheConstants.CREATE_RESUME_HTML_DATA.formatted(resumeId), jsonString);
redisTemplate.opsForValue().set(CacheConstants.CREATE_RESUME_HTML.formatted(resumeId), properties.getHtmlDown() + htmlName); redisTemplate.opsForValue().set(CacheConstants.CREATE_RESUME_HTML.formatted(resumeId), properties.getHtmlDown() + htmlName);
......
...@@ -34,6 +34,35 @@ public class FileProcessor { ...@@ -34,6 +34,35 @@ public class FileProcessor {
e.printStackTrace(); e.printStackTrace();
} }
} }
public static void processFileWithSize(String sourceFilePath, String targetFilePath, String oldData, String newData, String oldFontSize, String newFontSize, String oldLineHeight, String newLineHeight) {
File sourceFile = new File(sourceFilePath);
File targetFile = new File(targetFilePath);
// 读取和替换逻辑
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(sourceFile), StandardCharsets.UTF_8));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(targetFile), StandardCharsets.UTF_8))) {
String line;
while ((line = reader.readLine()) != null) {
// 替换字符串
String replacedLine = line;
if (line.contains(oldData)) {
replacedLine = line.replace(oldData, newData);
}
if (line.contains(oldFontSize)) {
replacedLine = line.replace(oldFontSize, newFontSize);
}
if (line.contains(oldLineHeight)) {
replacedLine = line.replace(oldLineHeight, newLineHeight);
}
writer.write(replacedLine);
writer.newLine(); // 写入换行符
}
System.out.println("文件处理完成,已生成新的HTML文件:" + targetFilePath);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) { public static void main(String[] args) {
// 示例:读取 `/data/test.txt`,将 `Hello` 替换为 `Hi`,生成 `/data/result.html` // 示例:读取 `/data/test.txt`,将 `Hello` 替换为 `Hi`,生成 `/data/result.html`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment