|
@@ -3,16 +3,17 @@ package cn.cslg.report.controller;
|
|
|
|
|
|
import cn.cslg.report.common.core.base.Constants;
|
|
|
import cn.cslg.report.common.model.BaseVO;
|
|
|
-import cn.cslg.report.common.model.vo.AssignTaskVO;
|
|
|
-import cn.cslg.report.common.model.vo.AuditTaskVO;
|
|
|
-import cn.cslg.report.common.model.vo.TaskParams;
|
|
|
-import cn.cslg.report.common.model.vo.TaskVO;
|
|
|
+import cn.cslg.report.common.model.vo.*;
|
|
|
import cn.cslg.report.common.utils.DataUtils;
|
|
|
import cn.cslg.report.common.utils.Response;
|
|
|
import cn.cslg.report.entity.Task;
|
|
|
import cn.cslg.report.service.BaseService;
|
|
|
import cn.cslg.report.service.OutInterfaceService;
|
|
|
import cn.cslg.report.service.business.TaskService;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.deepoove.poi.XWPFTemplate;
|
|
|
+import com.deepoove.poi.config.Configure;
|
|
|
+import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
@@ -23,8 +24,13 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.text.ParseException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
@@ -101,4 +107,35 @@ public class TaskController {
|
|
|
return Response.success();
|
|
|
}
|
|
|
|
|
|
+ @RequestMapping(value = "/temple", method = RequestMethod.GET)
|
|
|
+ @Operation(summary = "测试")
|
|
|
+ public String temple() throws ParseException, IOException {
|
|
|
+ String filePath= "C:\\Users\\admin\\Desktop\\1.docx";
|
|
|
+ // 读取模板后保存生成word的地址
|
|
|
+ String outPath = "C:\\Users\\admin\\Desktop\\2.docx";
|
|
|
+ // 为表格的显示绑定行循环
|
|
|
+ LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
|
|
+ // 将bz设置为行循环绑定的数据源的key,即key是bz的value会在模板中的{{bz}}处进行解析
|
|
|
+ Configure configure = Configure.builder().bind("bz", policy).build();
|
|
|
+ List<CompareFilesVO> aa =new ArrayList<>();
|
|
|
+ CompareFilesVO compareFilesVO =new CompareFilesVO();
|
|
|
+ compareFilesVO.setCurrent(111);
|
|
|
+ aa.add(compareFilesVO);
|
|
|
+ Map<String,Object> map =new HashMap<>();
|
|
|
+ map.put("bz",aa);
|
|
|
+ map.put("sss","saeqeq");
|
|
|
+
|
|
|
+ // 读取模板、数据并渲染
|
|
|
+ XWPFTemplate template = XWPFTemplate.compile(filePath, configure).render(map);
|
|
|
+// 文件是否已存在,则删除map = {TaskController$1@15526} size = 7
|
|
|
+ File file = new File(outPath);
|
|
|
+ if (file.exists()){
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+// 生成word保存在指定目录
|
|
|
+ template.writeToFile(outPath);
|
|
|
+ template.close();
|
|
|
+
|
|
|
+return Response.success();
|
|
|
+ }
|
|
|
}
|