Commit 89126d4c authored by linjian's avatar linjian

合同导出修改

parent 69e4a878
...@@ -10,6 +10,8 @@ import com.yundong.third.ht.api.database.ContractWordServiceld; ...@@ -10,6 +10,8 @@ import com.yundong.third.ht.api.database.ContractWordServiceld;
import com.yundong.third.ht.api.database.dto.request.Contract; import com.yundong.third.ht.api.database.dto.request.Contract;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.config.annotation.Service;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import javax.validation.Valid; import javax.validation.Valid;
...@@ -32,7 +34,7 @@ public class ContractWordServiceldImpl implements ContractWordServiceld { ...@@ -32,7 +34,7 @@ public class ContractWordServiceldImpl implements ContractWordServiceld {
for(int i = 0; i < request.getData().size(); i++) { for(int i = 0; i < request.getData().size(); i++) {
Contract obj = request.getData().get(i); Contract obj = request.getData().get(i);
String fileName = obj.getDESC1()+"-合同会签单.docx"; String fileName = obj.getDESC1()+"-合同会签单.doc";
HashMap<String, Object> map = new HashMap<>(); HashMap<String, Object> map = new HashMap<>();
map.put("DESC1", obj.getDESC1()); map.put("DESC1", obj.getDESC1());
map.put("DESC3", obj.getDESC3()); map.put("DESC3", obj.getDESC3());
...@@ -44,20 +46,21 @@ public class ContractWordServiceldImpl implements ContractWordServiceld { ...@@ -44,20 +46,21 @@ public class ContractWordServiceldImpl implements ContractWordServiceld {
map.put("handling_dept", obj.getHandling_dept()); map.put("handling_dept", obj.getHandling_dept());
map.put("leader", obj.getLeader()); map.put("leader", obj.getLeader());
try { try {
File catchFile = File.createTempFile(UUID.randomUUID().toString(), ".docx"); File catchFile = File.createTempFile(UUID.randomUUID().toString(), ".doc");
try ( try (
InputStream resource = ContractWordServiceldImpl.class.getClassLoader().getResourceAsStream("word/contract.docx"); InputStream resource = ContractWordServiceldImpl.class.getClassLoader().getResourceAsStream("word/contract.doc");
FileOutputStream fileOutputStream = new FileOutputStream(catchFile); FileOutputStream fileOutputStream = new FileOutputStream(catchFile);
FileInputStream fileInputStream = new FileInputStream(catchFile); FileInputStream fileInputStream = new FileInputStream(catchFile);
) { ) {
XWPFDocument word = null; HWPFDocument word = new HWPFDocument(resource);
if (resource != null) { Range range = word.getRange();
word = new XWPFDocument(resource); for (Map.Entry<String, Object> entry : map.entrySet()) {
WordExportUtil.exportWord07(word, map); range.replaceText(entry.getKey(), String.valueOf(entry.getValue()));
word.write(fileOutputStream);
String fileUrl = ossService.uploadOssObject(request.getTenantId(), System.currentTimeMillis() + "/" + fileName, fileInputStream);
fileUrls.add(fileUrl);
} }
// WordExportUtil.exportWord07(word, map);
word.write(fileOutputStream);
String fileUrl = ossService.uploadOssObject(request.getTenantId(), System.currentTimeMillis() + "/" + fileName, fileInputStream);
fileUrls.add(fileUrl);
} }
} catch (Exception e) { } catch (Exception e) {
......
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