| | |
| | | import com.deepoove.poi.policy.HackLoopTableRenderPolicy; |
| | | |
| | | import com.zt.life.export.dto.WordFile; |
| | | import com.zt.life.oss.OssEncryptService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | @Value("${zt.oss.local-path}") |
| | | private String localPath; |
| | | |
| | | @Autowired |
| | | private OssEncryptService ossEncryptService; |
| | | |
| | | |
| | | public void exportWordFile(HttpServletRequest request, Object dataObj, WordFile wordFile, HttpServletResponse response) throws UnsupportedEncodingException, FileNotFoundException { |
| | | // 数据map集合 |
| | | Map<String, Object> wordData = new HashMap<>(); |
| | |
| | | this.formatWordData(dataObj, wordData, builder); |
| | | |
| | | config = builder.build(); |
| | | File fl = new File(localPath+"/template/"+wordFile.getModulePath()); |
| | | File fl = new File(localPath + "/template/" + wordFile.getModulePath()); |
| | | FileInputStream fs = new FileInputStream(fl); |
| | | XWPFTemplate template; |
| | | if (config != null) { |
| | |
| | | formatWordData(staticFieldValue, wordData, builder); |
| | | } else { |
| | | if (field.getType().getName().equals("java.util.List")) { |
| | | builder.bind(fieldName, new HackLoopTableRenderPolicy()); |
| | | builder.bind(fieldName, new HackLoopTableRenderPolicy()); |
| | | } else if (staticFieldValue != null) { |
| | | String valStr = staticFieldValue.toString(); |
| | | if (valStr.contains("签名图片:")) { |
| | | valStr = valStr.replace("签名图片:", ""); |
| | | staticFieldValue = new PictureRenderData(80, 100, "d://" + valStr); |
| | | /*put("localbyte", new PictureRenderData(80, 100, ".png", new FileInputStream("./logo.png")));*/ |
| | | if (valStr.contains("文件图片:")) { |
| | | valStr = valStr.replace("文件图片:", ""); |
| | | File file = new File(valStr); |
| | | if (file.exists()) { |
| | | try (InputStream in = ossEncryptService.decrypt(file)) { |
| | | staticFieldValue = new PictureRenderData(500, 500, ".png", in); |
| | | /*staticFieldValue = new PictureRenderData(80, 100, "d://" + valStr);*/ |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if (wordData.get(fieldName) == null) |
| | | wordData.put(fieldName, staticFieldValue); |
| | | } |
| | | } |
| | | if (wordData.get(fieldName) == null) |
| | | wordData.put(fieldName, staticFieldValue); |
| | | } |
| | | } |
| | | } |