|
@@ -2,12 +2,8 @@ package com.zhongzheng.modules.base.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.hutool.extra.template.Template;
|
|
|
-import cn.hutool.extra.template.TemplateConfig;
|
|
|
-import cn.hutool.extra.template.TemplateEngine;
|
|
|
-import cn.hutool.extra.template.TemplateUtil;
|
|
|
-import cn.hutool.poi.word.Word07Writer;
|
|
|
+
|
|
|
+import cn.hutool.extra.template.TemplateException;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
|
|
@@ -26,6 +22,9 @@ import com.zhongzheng.modules.inform.vo.InformRemindVo;
|
|
|
import com.zhongzheng.modules.order.vo.OrderGoodsVo;
|
|
|
import com.zhongzheng.modules.user.service.IUserService;
|
|
|
import com.zhongzheng.modules.user.vo.UserVo;
|
|
|
+import freemarker.template.Configuration;
|
|
|
+import freemarker.template.Template;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.http.entity.ContentType;
|
|
|
import org.apache.poi.xwpf.usermodel.BreakType;
|
|
|
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
|
|
@@ -198,8 +197,8 @@ public class UserProfileServiceImpl extends ServiceImpl<UserProfileMapper, UserP
|
|
|
//第一种方式
|
|
|
Map<String, String> maps = JSONObject.parseObject(info.getKeyValue(),Map.class);
|
|
|
//默认配置就够用了
|
|
|
- TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("templates", TemplateConfig.ResourceMode.CLASSPATH));
|
|
|
- Template template = engine.getTemplate("word.ftl");
|
|
|
+ /* TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("templates", TemplateConfig.ResourceMode.CLASSPATH));
|
|
|
+ Template template = engine.getTemplate("word.ftl");*/
|
|
|
//给STRING_TEMPLATE绑定数据
|
|
|
Map<String, Object> bindingMap = new HashMap<>();
|
|
|
bindingMap.put("name", JSONObject.parseObject(String.valueOf(maps.get("name")), UserProfileFit.class).getValue());
|
|
@@ -218,9 +217,26 @@ public class UserProfileServiceImpl extends ServiceImpl<UserProfileMapper, UserP
|
|
|
bindingMap.put("d", 1);
|
|
|
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.docx");
|
|
|
+ File touch = FileUtil.touch(ZHONGZHENG_PROFILE+"word.doc");
|
|
|
//最终渲染出来的样子
|
|
|
- template.render(bindingMap,touch);
|
|
|
+ /*template.render(bindingMap,touch);*/
|
|
|
+
|
|
|
+
|
|
|
+ Configuration configuration = new Configuration();
|
|
|
+ configuration.setDefaultEncoding("utf-8");
|
|
|
+ configuration.setClassForTemplateLoading(this.getClass(), "/templates");
|
|
|
+ Template template = configuration.getTemplate("word.ftl");
|
|
|
+ Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(touch),"UTF-8"));
|
|
|
+ try {
|
|
|
+ template.process(bindingMap,out);
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
+
|
|
|
+ } catch (TemplateException | freemarker.template.TemplateException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
OssRequest ossRequest = new OssRequest();
|
|
|
FileInputStream fileInputStream = new FileInputStream(touch);
|
|
|
MultipartFile multipartFile = new MockMultipartFile(touch.getName(), touch.getName(),
|