Commit 69e4a878 authored by linjian's avatar linjian

合同导出修改

parent e5d9dc67
......@@ -4,12 +4,11 @@ import com.yundong.base.result.Result;
import com.yundong.third.ht.api.database.dto.request.Contract;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
public interface ContractWordServiceld {
Result<List<String>> contractWordExport(@Valid Contract request ) throws IllegalAccessException, IOException;
Result<List<String>> contractWordExport(@Valid Contract request );
}
......@@ -2,6 +2,7 @@ package com.yundong.third.ht.api.database.impl;
import cn.afterturn.easypoi.word.WordExportUtil;
import cn.afterturn.easypoi.word.entity.MyXWPFDocument;
import com.alibaba.fastjson.JSONObject;
import com.yundong.base.result.Result;
import com.yundong.base.service.oss.OssService;
import com.yundong.gateway.register.annotation.YdcGateway;
......@@ -24,57 +25,41 @@ public class ContractWordServiceldImpl implements ContractWordServiceld {
private OssService ossService;
@YdcGateway(name = "contract-word", url = "biz/third/md/database/ContractWord.json")
@Override
public Result<List<String>> contractWordExport(@Valid Contract request ) throws IllegalAccessException, IOException {
public Result<List<String>> contractWordExport(@Valid Contract request ) {
Result<List<String>> result = new Result<>();
List<String> fileUrls = new ArrayList();
List<String> fileUrls = new ArrayList<>();
/*String str = "[{\"DESC1\":\"123\",\"DESC13\":\"浙江鑫诺检测技术有限公司\",\"DESC3\":\"123\",\"handling_dept\":\"中国能源建设集团浙江火电建设有限公司\",\"handled_by\":\"林建\",\"dept\":\"林建 2023-12-21\",\"deptLeader\":\"【林健】林健 2023-12-21 14:25:37\\n 同意\",\"depts\":\"【林健】林健 2023-12-21 14:26:01\\n同意\"},{\"DESC1\":\"4\",\"DESC13\":\"保定市方为电气制造有限公司\",\"DESC3\":\"4\",\"handling_dept\":\"林建\",\"handled_by\":\"林建\",\"dept\":\"林健 2023-12-20\",\"deptLeader\":\"【林健】林健 2023-12-21 13:46:39\\n 同意\",\"depts\":\"【林健】林健 2023-12-21 13:47:21\\n同意\\n【卢太春】卢太春 2023-12-21 13:47:56\\n同意\\n【杜文浩】杜文浩 2023-12-21 13:48:13\\n同意\\n\"}]";
JSONArray array = JSONObject.parseArray(str);*/
System.out.println(request.getData());
for(int i = 0; i < request.getData().size(); i++) {
Map<String, Object> map = new HashMap<>();
/*JSONObject item = array.getJSONObject(i);*/
String fileUrl = "";
map.put("DESC1", request.getData().get(i).getDESC1());
map.put("DESC3", request.getData().get(i).getDESC3());
map.put("DESC13", request.getData().get(i).getDESC13());
map.put("dept", request.getData().get(i).getDept());
map.put("deptLeader", request.getData().get(i).getDeptLeader());
map.put("depts", request.getData().get(i).getDepts());
map.put("handled_by", request.getData().get(i).getHandled_by());
map.put("handling_dept", request.getData().get(i).getHandling_dept());
map.put("leader", request.getData().get(i).getLeader());
/*map.put("DESC1", item.getString("DESC1"));
map.put("DESC3", item.getString("DESC3"));
map.put("DESC13", item.getString("DESC13"));
map.put("dept", item.getString("dept"));
map.put("deptLeader", item.getString("deptLeader"));
map.put("depts", item.getString("depts"));
map.put("handled_by", item.getString("handled_by"));
map.put("handling_dept", item.getString("handling_dept"));*/
Contract obj = request.getData().get(i);
String fileName = obj.getDESC1()+"-合同会签单.docx";
HashMap<String, Object> map = new HashMap<>();
map.put("DESC1", obj.getDESC1());
map.put("DESC3", obj.getDESC3());
map.put("DESC13", obj.getDESC13());
map.put("dept", obj.getDept());
map.put("deptLeader", obj.getDeptLeader());
map.put("depts", obj.getDepts());
map.put("handled_by", obj.getHandled_by());
map.put("handling_dept", obj.getHandling_dept());
map.put("leader", obj.getLeader());
try {
String fileName = "合同会签单.docx";
InputStream resource = this.getClass().getClassLoader().getResourceAsStream("word/contract.docx");
File catchFile = File.createTempFile(UUID.randomUUID().toString(), ".docx");
FileOutputStream fileOutputStream = new FileOutputStream(catchFile);
FileInputStream fileInputStream = new FileInputStream(catchFile);
XWPFDocument word = new MyXWPFDocument(resource);
WordExportUtil.exportWord07(word, map);
word.write(fileOutputStream);
// response.setHeader("Content-disposition", "attachment;filename=\""
// + new String(fileName.getBytes("UTF-8"), "ISO8859_1") + "\"");
// response.setContentType("application/download;charset=UTF-8");
//
// OutputStream outputStream = response.getOutputStream();
// word.write(outputStream);
//文件上传oss
try (
InputStream resource = ContractWordServiceldImpl.class.getClassLoader().getResourceAsStream("word/contract.docx");
FileOutputStream fileOutputStream = new FileOutputStream(catchFile);
FileInputStream fileInputStream = new FileInputStream(catchFile);
) {
XWPFDocument word = null;
if (resource != null) {
word = new XWPFDocument(resource);
WordExportUtil.exportWord07(word, map);
word.write(fileOutputStream);
String fileUrl = ossService.uploadOssObject(request.getTenantId(), System.currentTimeMillis() + "/" + fileName, fileInputStream);
fileUrls.add(fileUrl);
}
fileUrl = ossService.uploadOssObject(request.getTenantId(), System.currentTimeMillis() + "/" + fileName, fileInputStream);
System.out.println(fileUrl);
fileUrls.add(fileUrl);
}
} catch (Exception e) {
e.printStackTrace();
}
......
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 to comment