|
|
@@ -1,12 +1,15 @@
|
|
|
package com.zhongzheng.modules.base.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
|
import cn.hutool.extra.template.TemplateException;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
|
|
|
+import com.openhtmltopdf.swing.Java2DRenderer;
|
|
|
+import com.openhtmltopdf.util.FSImageWriter;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
import com.zhongzheng.common.utils.SecurityUtils;
|
|
|
import com.zhongzheng.modules.alioss.bo.OssRequest;
|
|
|
@@ -48,6 +51,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import sun.misc.BASE64Encoder;
|
|
|
|
|
|
import java.awt.*;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
import java.io.*;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
@@ -200,6 +204,7 @@ public class UserProfileServiceImpl extends ServiceImpl<UserProfileMapper, UserP
|
|
|
/* TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("templates", TemplateConfig.ResourceMode.CLASSPATH));
|
|
|
Template template = engine.getTemplate("word.ftl");*/
|
|
|
//给STRING_TEMPLATE绑定数据
|
|
|
+ Calendar rightNow= Calendar.getInstance();
|
|
|
Map<String, Object> bindingMap = new HashMap<>();
|
|
|
bindingMap.put("name", JSONObject.parseObject(String.valueOf(maps.get("name")), UserProfileFit.class).getValue());
|
|
|
bindingMap.put("s", JSONObject.parseObject(String.valueOf(maps.get("sex")), UserProfileFit.class).getValue());
|
|
|
@@ -211,21 +216,21 @@ public class UserProfileServiceImpl extends ServiceImpl<UserProfileMapper, UserP
|
|
|
bindingMap.put("major", JSONObject.parseObject(String.valueOf(maps.get("major")), UserProfileFit.class).getValue());
|
|
|
bindingMap.put("cname", JSONObject.parseObject(String.valueOf(maps.get("unit_contact")), UserProfileFit.class).getValue());
|
|
|
bindingMap.put("cphone", JSONObject.parseObject(String.valueOf(maps.get("unit_tel")), UserProfileFit.class).getValue());
|
|
|
- bindingMap.put("image", Image2Base64(ALIYUN_OSS_ENDPOINT+"/"+JSONObject.parseObject(String.valueOf(maps.get("commitment_electr_signature")), UserProfileFit.class).getValue()));
|
|
|
- bindingMap.put("y", 1);
|
|
|
- bindingMap.put("m", 1);
|
|
|
- bindingMap.put("d", 1);
|
|
|
+ bindingMap.put("image", ALIYUN_OSS_ENDPOINT+"/"+JSONObject.parseObject(String.valueOf(maps.get("commitment_electr_signature")), UserProfileFit.class).getValue());
|
|
|
+ bindingMap.put("y", Convert.toStr(rightNow.get(Calendar.YEAR)));
|
|
|
+ bindingMap.put("m", rightNow.get(Calendar.MONTH)+1);
|
|
|
+ bindingMap.put("d", rightNow.get(Calendar.DAY_OF_MONTH));
|
|
|
bindingMap.put("time", JSONObject.parseObject(String.valueOf(maps.get("graduation_time")), UserProfileFit.class).getValue());
|
|
|
bindingMap.put("year", JSONObject.parseObject(String.valueOf(maps.get("working_years")), UserProfileFit.class).getValue());
|
|
|
- File touch = FileUtil.touch(ZHONGZHENG_PROFILE+"word.doc");
|
|
|
+ File touch = FileUtil.touch(ZHONGZHENG_PROFILE+"word.html");
|
|
|
//最终渲染出来的样子
|
|
|
/*template.render(bindingMap,touch);*/
|
|
|
|
|
|
|
|
|
Configuration configuration = new Configuration();
|
|
|
- configuration.setDefaultEncoding("utf-8");
|
|
|
+ configuration.setDefaultEncoding("UTF-8");
|
|
|
configuration.setClassForTemplateLoading(this.getClass(), "/templates");
|
|
|
- Template template = configuration.getTemplate("word.ftl");
|
|
|
+ Template template = configuration.getTemplate("wordPhone.ftl");
|
|
|
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(touch),"UTF-8"));
|
|
|
try {
|
|
|
template.process(bindingMap,out);
|
|
|
@@ -235,11 +240,15 @@ public class UserProfileServiceImpl extends ServiceImpl<UserProfileMapper, UserP
|
|
|
} catch (TemplateException | freemarker.template.TemplateException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
-
|
|
|
+ final Java2DRenderer renderer = new Java2DRenderer(touch, 1000, 1000);
|
|
|
+ final BufferedImage img = renderer.getImage();
|
|
|
+ final FSImageWriter imageWriter = new FSImageWriter();
|
|
|
+ imageWriter.setWriteCompressionQuality(1.0f);
|
|
|
+ imageWriter.write(img, ZHONGZHENG_PROFILE+"wordJpg.jpg");//输出路径
|
|
|
|
|
|
OssRequest ossRequest = new OssRequest();
|
|
|
- FileInputStream fileInputStream = new FileInputStream(touch);
|
|
|
- MultipartFile multipartFile = new MockMultipartFile(touch.getName(), touch.getName(),
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(ZHONGZHENG_PROFILE+"wordJpg.jpg");
|
|
|
+ MultipartFile multipartFile = new MockMultipartFile(ZHONGZHENG_PROFILE+"wordJpg.jpg", ZHONGZHENG_PROFILE+"wordJpg.jpg",
|
|
|
ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
|
|
|
ossRequest.setFile(multipartFile);
|
|
|
ossRequest.setImageStatus(6);
|