Commit c5291016 by zwb

添加简历html转为小图png

parent 686c074b
...@@ -86,6 +86,22 @@ public interface CacheConstants { ...@@ -86,6 +86,22 @@ public interface CacheConstants {
*/ */
String RESUME_TEMPLATE_PDF_ID = "template:resume:pdf:download:%s"; String RESUME_TEMPLATE_PDF_ID = "template:resume:pdf:download:%s";
/**
* 简历下载数据缓存数据png min
*/
String CREATE_RESUME_HTML_PNG_MIN_DATA = "create:resume:html:png:min:data:%s";
/**
* 简历下载数据缓存png min
*/
String CREATE_RESUME_PNG_MIN_HTML = "create:resume:png:min:html:%s";
/**
* 下载使用简历对应模版缓存png min
*/
String RESUME_TEMPLATE_PNG_MIN_ID = "template:resume:png:min:download:%s";
/**分析职业期望数据*/ /**分析职业期望数据*/
String REDIS_USER_ANALYSIS_KEY = "user:analysis:%s"; String REDIS_USER_ANALYSIS_KEY = "user:analysis:%s";
} }
...@@ -27,7 +27,8 @@ public class AiConfigProperties { ...@@ -27,7 +27,8 @@ public class AiConfigProperties {
public String htmlDown; public String htmlDown;
// public String imagesDown = "https://xzt-dev.jinsehuaqin.com/images_down/"; public String imagesDown;
// = "https://xzt-dev.jinsehuaqin.com/images_down/"
// //
// public String avatarPath = "/resume/avatarImages/"; // public String avatarPath = "/resume/avatarImages/";
// //
......
...@@ -164,6 +164,19 @@ public class NewEditionResumeController { ...@@ -164,6 +164,19 @@ public class NewEditionResumeController {
} }
/** /**
* 根据html生成小png图片
* @param dto
* @return
*/
@PostMapping("/create-resume-min-png")
public R<ResumeByPdfVo> createResumeMinPng(@RequestBody ResumeByPdfDto dto){
ResumeByPdfVo vo = this.newEditionResumeService.createResumeMinPng(dto);
return new R<>(vo);
}
/**
* 简历模块优化 * 简历模块优化
* @param dto * @param dto
* @return * @return
......
...@@ -139,7 +139,6 @@ public class JobRecommendServiceImpl implements JobRecommendService { ...@@ -139,7 +139,6 @@ public class JobRecommendServiceImpl implements JobRecommendService {
return; return;
} }
Integer orlStatus = aiRecommendBase.getRecommendStatus(); Integer orlStatus = aiRecommendBase.getRecommendStatus();
log.info("修改岗位意向数据为推送中"); log.info("修改岗位意向数据为推送中");
aiAnalysisMapper.updateAnalysis(analysisId, 1, thisUserId, 1); aiAnalysisMapper.updateAnalysis(analysisId, 1, thisUserId, 1);
......
...@@ -122,4 +122,10 @@ public interface NewEditionResumeService { ...@@ -122,4 +122,10 @@ public interface NewEditionResumeService {
void reversalExperience(ResumeExpChangeDto dto) throws Exception; void reversalExperience(ResumeExpChangeDto dto) throws Exception;
/**
* 根据html生成小png图片
* @param dto
* @return
*/
ResumeByPdfVo createResumeMinPng(ResumeByPdfDto dto);
} }
...@@ -964,6 +964,111 @@ public class NewEditionResumeServiceImpl implements NewEditionResumeService { ...@@ -964,6 +964,111 @@ public class NewEditionResumeServiceImpl implements NewEditionResumeService {
} }
} }
@Override
public ResumeByPdfVo createResumeMinPng(ResumeByPdfDto dto) {
if (StringUtils.isBlank(dto.getResumeId())){
throw new WarnException("简历ID不能为空");
}
if (StringUtils.isBlank(dto.getTemplateName())){
dto.setTemplateName("tpl21.ejs");
}
ResumeByPdfVo vo = new ResumeByPdfVo();
/**是否展示0.显示 1.不显示*/
Map<String, Object> objectMap = newEditionResumeUtil.queryAllModelData(dto.getResumeId(), "0");
Object baseInfo = objectMap.get("base");
if (baseInfo != null) {
JSONObject jsonObject = (JSONObject) JSON.toJSON(baseInfo);
String age = jsonObject.getString("birthday");
// 计算年龄
String calculatedAge = calculationAge(age);
// 放回 JSON 对象中
jsonObject.put("birthday", calculatedAge);
jsonObject.put("workTime", "");
// 更新 base_info
objectMap.put("base", jsonObject);
}
log.info("========导出简历数据1=========:{}", objectMap);
String jsonString = JSON.toJSONString(objectMap);
log.info("========导出简历数据2=========:{}", jsonString);
if(objectMap.get("base") != null){
Map<String, Object> map = JSON.parseObject(String.valueOf(objectMap.get("base")), Map.class);
if(map.get("resumeName") != null){
vo.setResumeName(map != null ? String.valueOf(map.get("resumeName")) : "");
}else {
FunctionResumeBase resumeBase = this.functionResumeBaseMapper.selectById(dto.getResumeId());
vo.setResumeName(resumeBase.getResumeName());
this.resumeCacheService.saveResumeModelDataCache(Long.valueOf(dto.getResumeId()), Long.valueOf(dto.getResumeId()), JSON.toJSONString(resumeBase));
}
vo.setUserName(map != null ? String.valueOf(map.get("username")) : "");
}
String data = redisTemplate.opsForValue().get(CacheConstants.CREATE_RESUME_HTML_PNG_MIN_DATA.formatted(dto.getResumeId()));
if (com.alibaba.excel.util.StringUtils.isNotBlank(data)){
if(jsonString.equals(data)){
String template = redisTemplate.opsForValue().get(CacheConstants.RESUME_TEMPLATE_PNG_MIN_ID.formatted(dto.getResumeId()));
if(com.alibaba.excel.util.StringUtils.isNotBlank(template) && template.equals(dto.getTemplateName())){
String json = redisTemplate.opsForValue().get(CacheConstants.CREATE_RESUME_PNG_MIN_HTML.formatted(dto.getResumeId()));
if(com.alibaba.excel.util.StringUtils.isNotBlank(json)){
ResumeByPdfVo resume = JSON.parseObject(json, ResumeByPdfVo.class);
return resume;
}
}
}
}
log.info("简历预览数据: {}", jsonString);
String htmlName = dto.getResumeId() + ".html";
FileProcessor.processFile(properties.getPath() + "template/" + dto.getTemplateName(), properties.getPath() + "output/" + htmlName, "<%- data %>", jsonString);
// Node.js 命令及参数
String nodeExecutable = "node"; // 如果环境变量已配置 Node.js,可直接用 "node"
String pngPathMin = properties.getPath() + "screenshot_min";
String inputFile = "file:///"+properties.getPath()+"output/"+ dto.getResumeId() +".html";
String pngNameMin = SnowFlakeUtil.newIdString() + "min.png";
//小图片
try {
// 构建 ProcessBuilder 并传递参数
ProcessBuilder processBuilder = new ProcessBuilder(
nodeExecutable, pngPathMin, inputFile, properties.getPath() + "images/" + pngNameMin);
// 合并标准输出和错误输出
processBuilder.redirectErrorStream(true);
// 启动进程
Process process = processBuilder.start();
// 读取 Node.js 命令行输出
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
log.info("Node.js 输出png: {}", line);
}
// 等待命令执行完成
int exitCode = process.waitFor();
log.info("Node.js 命令执行完成,退出码: {}", exitCode);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
String header = WebUtils.getRequest().getHeader(SecurityConstants.QQXB_FROM);
// if(StringUtils.isNotBlank(header) && !SecurityConstants.QQXB_OUT.equals(header) && !SecurityConstants.JYXZ_OUT.equals(header)){
vo.setHtmlName(properties.getHtmlDown() + htmlName);
vo.setPngNameMin(properties.getImagesDown() + pngNameMin);
// }else {
// vo.setHtmlName(properties.getHtmlDownZs() + htmlName);
// vo.setPngNameMin(properties.getImagesDownZs() + pngNameMin);
// }
redisTemplate.opsForValue().set(CacheConstants.CREATE_RESUME_HTML_PNG_MIN_DATA.formatted(dto.getResumeId()), jsonString);
redisTemplate.opsForValue().set(CacheConstants.CREATE_RESUME_PNG_MIN_HTML.formatted(dto.getResumeId()), JSON.toJSONString(vo));
redisTemplate.opsForValue().set(CacheConstants.RESUME_TEMPLATE_PNG_MIN_ID.formatted(dto.getResumeId()), dto.getTemplateName());
return vo;
}
public String sanitizeFileName(String fileName) { public String sanitizeFileName(String fileName) {
if (fileName == null) return null; if (fileName == null) return null;
......
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