From b8306ffae5dad8cf70718f7f174c09a565935c6b Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Thu, 23 Jan 2025 15:46:22 +0800 Subject: [PATCH] 1 --- .../ts_obj/config/MyContentPolicy.java | 3 - .../ts_obj/controller/TypesetController.java | 537 ++++++++---------- .../example/ts_obj/entity/TypesetInfo.java | 29 +- 3 files changed, 250 insertions(+), 319 deletions(-) diff --git a/src/main/java/com/example/ts_obj/config/MyContentPolicy.java b/src/main/java/com/example/ts_obj/config/MyContentPolicy.java index 56d6b85..5cfa85d 100644 --- a/src/main/java/com/example/ts_obj/config/MyContentPolicy.java +++ b/src/main/java/com/example/ts_obj/config/MyContentPolicy.java @@ -50,9 +50,6 @@ public class MyContentPolicy extends AbstractRenderPolicy Iterator var6 = contents.iterator(); while(var6.hasNext()) { RenderData content = (RenderData)var6.next(); - -// String name = content.getClass().getSimpleName(); -// System.out.println(name); XWPFRun fragment = parentContext.insertNewRun(ParagraphUtils.getRunPos(run)); StyleUtils.styleRun(fragment, run); if (content instanceof TextRenderData) { diff --git a/src/main/java/com/example/ts_obj/controller/TypesetController.java b/src/main/java/com/example/ts_obj/controller/TypesetController.java index a6e85c1..fd417bb 100644 --- a/src/main/java/com/example/ts_obj/controller/TypesetController.java +++ b/src/main/java/com/example/ts_obj/controller/TypesetController.java @@ -34,10 +34,7 @@ import org.apache.poi.xwpf.usermodel.*; import org.freehep.graphicsio.emf.EMFHeader; import org.freehep.graphicsio.emf.EMFInputStream; import org.freehep.graphicsio.emf.EMFRenderer; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblBorders; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcBorders; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -54,6 +51,7 @@ import java.awt.image.BufferedImage; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; +import java.sql.Array; import java.text.SimpleDateFormat; import java.util.*; import java.util.List; @@ -67,13 +65,12 @@ public class TypesetController { private final static Logger logger = LoggerFactory.getLogger(UserController.class); - private String BASE_DIR = "/home/wwwroot/ts.tmrjournals.com/upload/"; - private String IMG_BASE_DIR = "/home/wwwroot/api.tmrjournals.com/public/articleImage/"; - private String IMG_DIR = "/home/wwwroot/ts.tmrjournals.com/upload/pictures/"; - - // private String BASE_DIR = "/home/wwwroot/ts.tmrjournals.com/upload/"; -// private String IMG_BASE_DIR = "D:/phpstudy_pro/WWW/tougao/public/articleImage/"; +// private String IMG_BASE_DIR = "/home/wwwroot/api.tmrjournals.com/public/articleImage/"; + + + private String BASE_DIR = "D:/tsfile/"; + private String IMG_BASE_DIR = "D:/phpstudy_pro/WWW/tougao/public/articleImage/"; @Autowired @@ -340,10 +337,18 @@ public class TypesetController { try (FileOutputStream fos = new FileOutputStream(f) ){ IOUtils.copy(new ByteArrayInputStream(imageData), fos); } - flagImages.add("image-"+randomNumber + imgNum+"."+imageFileName); - String img_str = ""; - //存储图片数据到总数组 - al.add(img_str); + if(imageFileName=="tif"){ + ReturnValue returnValue = this.crossImage(article_id + "/" + "image-" + randomNumber + imgNum + "." + imageFileName); + String file = ((Map) returnValue.getData()).get("file").toString(); + flagImages.add("image-" + randomNumber + imgNum + ".png"); + String img_str = ""; + al.add(img_str); + }else{ + flagImages.add("image-"+randomNumber + imgNum+"."+imageFileName); + String img_str = ""; + //存储图片数据到总数组 + al.add(img_str); + } imgNum++; } } @@ -662,46 +667,6 @@ public class TypesetController { return new ReturnValue(ReturnCodeAndMsgEnum.Success, frag); } - - @PostMapping("/myTest") - public ReturnValue myTest(@RequestBody TypesetInfo typesetInfo) throws IOException { - HashMap frag = new HashMap<>(); - HashMap map = new HashMap<>(); - String main = typesetInfo.getMainText(); - List l = JSON.parseArray(main, String.class); - ArrayList mainArr = new ArrayList(); - for (String s : l) { - Map cache = new HashMap(); -// ParagraphRenderData capd = this.crowStrNew(s); -// cache.put("content", capd); - - mainArr.add(cache); - } - map.put("main", mainArr); - -// Configure config = Configure.builder().bind("content", new ParagraphRenderPolicy()).build(); - Configure config = Configure.builder().bind("content", new MyContentPolicy()).build(); - - String myTemplate = "D:/tt1.docx"; - XWPFTemplate template = XWPFTemplate.compile( myTemplate, config).render(map); - try { - Date date = new Date(); - String dirpath = "D:/" + new SimpleDateFormat("yyyyMMdd").format(date); - //如果不存在,创建文件夹 - File f = new File(dirpath); - if (!f.exists()) { - f.mkdirs(); - } - String goFileName = System.currentTimeMillis() + ".docx"; - template.writeAndClose(new FileOutputStream(dirpath + "/" + goFileName)); - frag.put("file", goFileName); - } catch (IOException e) { - e.printStackTrace(); - } - - return new ReturnValue(ReturnCodeAndMsgEnum.Success,frag); - } - @PostMapping("/createDocx") public ReturnValue createDocx(@RequestBody TypesetInfo typesetInfo) throws IOException { Map frag = new HashMap(); @@ -779,24 +744,96 @@ public class TypesetController { abstract_p.addText(new TextRenderData("input abstract", doi_s)); map.put("abstract", abstract_p); map.put("keywords", typesetInfo.getKeywords().replace("", "").replace("", "")); + + //主体部分 String main = typesetInfo.getMainText(); List l = JSON.parseArray(main, String.class); ArrayList mainArr = new ArrayList(); - ArrayList otherArr = new ArrayList(); +// ArrayList otherArr = new ArrayList(); + Map>> otherAll = new HashMap(); + int otherNum=1; + Map> imageDatas = typesetInfo.getImages(); + Map> tableDatas = typesetInfo.getTables(); for (String s : l) { - Map cache = new HashMap(); - Map otherData = new HashMap(); - MyParagraphRenderData capd = crowStrNew(s,typesetInfo.getTables(),typesetInfo.getImages()); - if(checkImg(s)||s.contains("(); + if(checkImg(s)){ + cache.put("data",myParagraphRenderData); + otherAllList.add(cache); + }else { + cache.put("content",myParagraphRenderData); + mainArr.add(cache); + } + String regex = "imageId='(\\d+)'"; + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(s); + int image_id = 0; + if (matcher.find()) { + image_id= Integer.valueOf(matcher.group(1)); + } + Map stringStringMap = imageDatas.get(image_id); + String s1 = stringStringMap.get("note"); + MyParagraphRenderData myParagraphRenderData1 = crowStrNew(s1, tableDatas, imageDatas); + Map cache1 = new HashMap(); + myParagraphRenderData1.setParagraphStyle(paragraphStyle); + if(checkImg(s)){ + cache1.put("data",myParagraphRenderData1); + otherAllList.add(cache1); + otherAll.put("otherall"+otherNum,otherAllList); + MyParagraphRenderData myParagraphRenderData2 = new MyParagraphRenderData(); + myParagraphRenderData2.addText("{{+otherall"+otherNum+"}}"); + HashMap hashMap = new HashMap(); + hashMap.put("content",myParagraphRenderData2); + mainArr.add(hashMap); + otherNum++; + }else { + cache1.put("content",myParagraphRenderData1); + mainArr.add(cache1); + } + } else if (s.contains(" stringStringMap = tableDatas.get(tid); + MyParagraphRenderData myParagraphRenderData = crowStrNew(stringStringMap.get("title"), tableDatas, imageDatas); + myParagraphRenderData.setParagraphStyle(paragraphStyle); + Map cache = new HashMap(); + cache.put("data",myParagraphRenderData); + arrayList.add(cache); + MyParagraphRenderData myParagraphRenderData1 = crowStrNew(s, tableDatas, imageDatas); + Map cache1 = new HashMap(); + cache1.put("data",myParagraphRenderData1); + arrayList.add(cache1); + MyParagraphRenderData myParagraphRenderData2 = crowStrNew(stringStringMap.get("note"), tableDatas, imageDatas); + myParagraphRenderData2.setParagraphStyle(paragraphStyle); + Map cache2 = new HashMap(); + cache2.put("data",myParagraphRenderData2); + arrayList.add(cache2); + otherAll.put("otherall"+otherNum,arrayList); + MyParagraphRenderData myParagraphRenderData3 = new MyParagraphRenderData(); + myParagraphRenderData3.addText("{{+otherall"+otherNum+"}}"); + HashMap hashMap1 = new HashMap(); + hashMap1.put("content",myParagraphRenderData3); + mainArr.add(hashMap1); + otherNum++; + }else{ + Map cache = new HashMap(); + MyParagraphRenderData capd = crowStrNew(s,typesetInfo.getTables(),typesetInfo.getImages()); cache.put("content", capd); mainArr.add(cache); } } map.put("main", mainArr); - map.put("other",otherArr); //参考文献部分 JSONArray ja = (JSONArray) JSON.parse(typesetInfo.getRefers()); List refsl = new ArrayList(); @@ -877,18 +914,15 @@ public class TypesetController { .bind("peer", new ParagraphRenderPolicy()) .build(); XWPFTemplate template = XWPFTemplate.compile(this.BASE_DIR + myTemplate, config).render(map); -// XWPFTemplate template = XWPFTemplate.compile("D:/tt1.docx", config).render(map); - XWPFDocument document = template.getXWPFDocument(); - List tables = document.getTables(); - for (int i = 1; i < tables.size(); i++) { // 从索引 1 开始,跳过第一个表格 - XWPFTable table = tables.get(i); - setThreeLineTableStyle(table); // 应用三线表样式 - } +// XWPFDocument document = template.getXWPFDocument(); +// List tables = document.getTables(); +// for (int i = 1; i < tables.size(); i++) { // 从索引 1 开始,跳过第一个表格 +// XWPFTable table = tables.get(i); +// setThreeLineTableStyle(table); // 应用三线表样式 +// } try { Date date = new Date(); String dirpath = this.BASE_DIR + new SimpleDateFormat("yyyyMMdd").format(date); -// String dirpath = "D:/" + new SimpleDateFormat("yyyyMMdd").format(date); - //如果不存在,创建文件夹 File f = new File(dirpath); if (!f.exists()) { @@ -896,7 +930,40 @@ public class TypesetController { } String goFileName = System.currentTimeMillis() + ".docx"; template.writeAndClose(new FileOutputStream(dirpath + "/" + goFileName)); - frag.put("file", goFileName); + //二次写入 + if(otherAll.size()>0){ + HashMap othermap = new HashMap<>(); + for (Map.Entry>> entry : otherAll.entrySet()) { + String key = entry.getKey(); + ArrayList> value = entry.getValue(); + HashMap map1 = new HashMap<>(); + map1.put("other",value); + othermap.put(key,Includes.ofLocal(this.BASE_DIR+"table.docx").setRenderModel(map1).create()); + } + Configure config1 = Configure.builder().bind("data",new MyContentPolicy()).build(); + XWPFTemplate template1 = XWPFTemplate.compile(dirpath + "/" + goFileName, config1).render(othermap); + Date date1 = new Date(); + String dirpath1 = this.BASE_DIR + new SimpleDateFormat("yyyyMMdd").format(date1); + XWPFDocument document1 = template1.getXWPFDocument(); + List tables1 = document1.getTables(); + for (int i = 1; i < tables1.size(); i++) { // 从索引 1 开始,跳过第一个表格 + XWPFTable table22 = tables1.get(i); + setThreeLineTableStyle(table22); // 应用三线表样式 + } + + + + //如果不存在,创建文件夹 + File f1 = new File(dirpath1); + if (!f1.exists()) { + f1.mkdirs(); + } + String goFileName1 = System.currentTimeMillis() + ".docx"; + template1.writeAndClose(new FileOutputStream(dirpath1 + "/" + goFileName1)); + frag.put("file", goFileName1); + }else { + frag.put("file", goFileName); + } } catch (IOException e) { e.printStackTrace(); } @@ -904,6 +971,7 @@ public class TypesetController { } + @PostMapping("/crossImage") public ReturnValue crossImage(String url) throws FileNotFoundException { String fileUrl = IMG_BASE_DIR+url; @@ -1270,17 +1338,26 @@ public class TypesetController { Map stringStringMap = images.get(image_id); String imagePath = stringStringMap.get("image"); BufferedImage image = ImageIO.read(new File(IMG_BASE_DIR+imagePath)); - PictureRenderData pictureRenderData = new PictureRenderData(image.getWidth(), image.getHeight(),IMG_BASE_DIR+imagePath); - PictureStyle pictureStyle = new PictureStyle(); - pictureStyle.setAlign(PictureStyle.PictureAlign.CENTER); - pictureRenderData.setPictureStyle(pictureStyle); + int width = image.getWidth(); + int height = image.getHeight(); + if(width>650){ + height = 650*height/width; + width = 650; + } + + + PictureRenderData pictureRenderData = new PictureRenderData(width, height,IMG_BASE_DIR+imagePath); +// PictureStyle pictureStyle = new PictureStyle(); +// pictureStyle.setAlign(PictureStyle.PictureAlign.CENTER); +// pictureRenderData.setPictureStyle(pictureStyle); p.addPicture(pictureRenderData); ParagraphStyle paragraphStyle = new ParagraphStyle(); + paragraphStyle.setAllowWordBreak(false); + paragraphStyle.setSpacingBeforeLines(Double.valueOf(1)); + paragraphStyle.setSpacingAfterLines(Double.valueOf(1)); paragraphStyle.setAlign(ParagraphAlignment.CENTER); paragraphStyle.setSpacing(Double.valueOf(10)); p.setParagraphStyle(paragraphStyle); - String note = stringStringMap.get("note"); - textRenderCreate(note,p); return p; } @@ -1293,42 +1370,45 @@ public class TypesetController { if(matcher.find()){ tid = matcher.group(1); } - int tableId = Integer.valueOf(tid); - Map stringStringMap = map.get(tableId); - String title_table = stringStringMap.get("title"); - String note_table = stringStringMap.get("note"); - textRenderCreate(title_table,p); +// int tableId = Integer.valueOf(tid); + Map stringStringMap = map.get(tid); ArrayList>> tableData = JSON.parseObject(stringStringMap.get("table_data"), new TypeReference>>>() {}); TableRenderData tableRenderData = new TableRenderData(); for (ArrayList> row:tableData){ RowRenderData rowRenderData = new RowRenderData(); for (Map rowBean:row){ CellRenderData cellRenderData = new CellRenderData(); - ParagraphRenderData paragraphRenderData = new ParagraphRenderData(); - ParagraphRenderData text = crowStrNew(rowBean.get("text"), map,images); + ParagraphRenderData text = crowStrNew(rowBean.get("text").trim(), map,images); List plist = new ArrayList<>(); plist.add(text); - plist.add(paragraphRenderData); cellRenderData.setParagraphs(plist); rowRenderData.addCell(cellRenderData); } + RowStyle rowStyle = new RowStyle(); + rowStyle.setHeight(12); + rowRenderData.setRowStyle(rowStyle); tableRenderData.addRow(rowRenderData); } +// TableStyle tableStyle = new TableStyle(); +// tableStyle.setAlign(TableRowAlign.CENTER); +// tableRenderData.setTableStyle(tableStyle); + p.addTable(tableRenderData); - ParagraphStyle paragraphStyle = new ParagraphStyle(); - paragraphStyle.setAlign(ParagraphAlignment.CENTER); - paragraphStyle.setSpacing(Double.valueOf(12)); - textRenderCreate(note_table,p); return p; } + if(s.isEmpty()){ p.addText(s); + }else{ + textRenderCreate(s,p); } - textRenderCreate(s,p); return p; + } + + private void textRenderCreate(String s,MyParagraphRenderData p){ while (!s.isEmpty()){ String s1 = determineNextTag(s); @@ -1337,7 +1417,7 @@ public class TypesetController { s = ""; }else{ int beginTag = s.indexOf("<"+s1+">"); - int endTag = s.indexOf(""); + int endTag = getLastTabIndex(s,s1); if(beginTag>0){ p.addText(s.substring(0,beginTag)); } @@ -1353,6 +1433,55 @@ public class TypesetController { } } + + public Integer getLastTabIndex(String s,String tab){ + int beginTag = s.indexOf("<"+tab+">"); + int endTag_ca = s.indexOf(""); + int endTag = 0; + Pattern pattern = Pattern.compile("<" + tab + ">"); + String ca_now_str = s.substring(beginTag,endTag_ca+ tab.length() + 3); + Matcher matcher = pattern.matcher(ca_now_str); + int ca_count = 0; + while (matcher.find()) { + ca_count++; + } + if(ca_count==1){ + endTag = endTag_ca; + }else{ + int really_num = 0; + while (really_num!=ca_count){ + String substring = s.substring(beginTag, getNumIndex(s, tab, ca_count)); + Matcher matcher1 = pattern.matcher(substring); + int cca_count = 0; + while (matcher1.find()){ + cca_count++; + } + if(cca_count!=ca_count){ + ca_count = cca_count; + }else{ + really_num = cca_count; + } + } + endTag = getNumIndex(s,tab,really_num); + } + return endTag; + } + + + + + private Integer getNumIndex(String s,String tab,Integer num){ + int count_cc_n = 0; + int index_aa = -1; // 初始化为-1表示开始时未找到 + while ((index_aa = s.indexOf("", index_aa + 1)) != -1) { + count_cc_n++; + if (count_cc_n == num) { + break; + } + } + return index_aa; + } + public boolean isImgTag(String str) { // 定义正则表达式,用于匹配 标签 String imgTagPattern = "<\\s*img\\s+[^>]*\\s*\\/?>"; @@ -1377,8 +1506,9 @@ public class TypesetController { textRenderData.add(textRenderData1); content = ""; }else{ + int beginTag = content.indexOf("<"+s+">"); - int endTag = content.indexOf(""); + int endTag = getLastTabIndex(content,s); if(beginTag>0){ TextRenderData textRenderData1 = new TextRenderData(content.substring(0, beginTag), style); textRenderData.add(textRenderData1); @@ -1463,7 +1593,8 @@ public class TypesetController { s.setVertAlign("superscript"); break; case "blue": - s.setColor("0000FF"); + s.setColor("0082AA"); + break; case "sub": s.setVertAlign("subscript"); @@ -1777,221 +1908,5 @@ public class TypesetController { return new ReturnValue(ReturnCodeAndMsgEnum.Success, m); } - public String addPic1(String OldFileName, String newFileName) { - //1.操作初始文档获取图片 和 图片所在的位置 - String filePath = ""; - try { -// File file = new File(this.BASE_DIR + OldFileName); - InputStream inputStream = FileDownloadUtil.getInputStream(OldFileName); -// FileInputStream fis = new FileInputStream(inputStream); - XWPFDocument xdoc = new XWPFDocument(inputStream); - List list = xdoc.getParagraphs(); - String lastParagraphText = ""; - //TODO 读取文档在数据库的内容 - - //准备一个图片名称list - ArrayList picNameList = new ArrayList<>(); - //准备一个Map key为图片名称,值为位置 - HashMap picMap = new HashMap<>(); - - String randomFix = String.valueOf(System.currentTimeMillis()) + "/"; - - String path = IMG_DIR + randomFix; - File folder = new File(IMG_DIR + randomFix); - if (!folder.exists()) { - folder.mkdirs(); - } - - //获取图片所在位置保存 - for (int i = 0; i < list.size(); i++) { - List imageBundleList = XWPFUtils.readImageInParagraph(list.get(i)); - if (CollectionUtils.isNotEmpty(imageBundleList)) { - for (String pictureId : imageBundleList) { - XWPFPictureData pictureData = xdoc.getPictureDataByID(pictureId); - String imageName = pictureData.getFileName(); - picNameList.add(imageName); -// for (int j=1; j"+valCode); -// //正则表达式 -// Pattern p = Pattern.compile("[\u4e00-\u9fa5]"); -// Matcher m = p.matcher(valCode); -// //System.out.println(m.find()); -// if (m.find()){ -// //System.out.println("查找到了文字"); -// //1.包含中文 单栏 -// DocPicture docPicture = paragraph.appendPicture(imgPath); -// docPicture.setWidth(500f); -// docPicture.setHeight(180f); -// docPicture.setTextWrappingStyle(TextWrappingStyle.Top_And_Bottom); -// docPicture.setTextWrappingType(TextWrappingType.Both); -// }else { - //2.不包含 判断图片大小决定 图片为单栏还是双栏 - if (width <= 782f) { - //图片为小图 双栏 - DocPicture docPicture = paragraph.appendPicture(imgPath); - docPicture.setWidth(250f); -// docPicture.setHeight(216f); - docPicture.setTextWrappingStyle(TextWrappingStyle.Top_And_Bottom); - docPicture.setTextWrappingType(TextWrappingType.Both); - float x = docPicture.getHorizontalPosition(); - float y = docPicture.getVerticalPosition(); - - //获取图片宽度、高度 - float width1 = docPicture.getWidth(); - float height = docPicture.getHeight(); - - //获取图片文字环绕 - String wrappingstyle = docPicture.getTextWrappingStyle().toString();//图片文字环绕方式 - String wrappingtype = docPicture.getTextWrappingType().toString();//环绕文字类型 - } else { - //图片为大图 单栏 - DocPicture docPicture = paragraph.appendPicture(imgPath); - docPicture.setWidth(495f); -// docPicture.setHeight(150f); - docPicture.setHorizontalPosition(0.0f); - docPicture.setVerticalPosition(10.0f); - docPicture.setTextWrappingStyle(TextWrappingStyle.Top_And_Bottom); - docPicture.setTextWrappingType(TextWrappingType.Both); - float x = docPicture.getHorizontalPosition(); - float y = docPicture.getVerticalPosition(); - - //获取图片宽度、高度 - float width1 = docPicture.getWidth(); - float height = docPicture.getHeight(); - - //获取图片文字环绕 - String wrappingstyle = docPicture.getTextWrappingStyle().toString();//图片文字环绕方式 - String wrappingtype = docPicture.getTextWrappingType().toString();//环绕文字类型 - } -// } - - } - } - - } - } -// SectionCollection secs = doc.getSections(); -// //处理表格 -// for (int i = 0; i < secs.getCount(); i++) { -// //获取第一个section -//// Section section = doc.getSections().get(0); -// -// TableCollection tables = secs.get(i).getTables(); -// //System.out.println(tables); -// //获取section中第一个表格 -//// Table table = sec.getTables().get(0); -// int count = tables.getCount(); -// //System.out.println("===================>"+count); -// for (int j = 0; j < tables.getCount(); j++) { -// //给表格应用样式 -// tables.get(j).applyStyle(DefaultTableStyle.Table_Classic_1); -//// //设置表格的右边框 -//// tables.get(j).getTableFormat().getBorders().getRight().setBorderType(BorderStyle.Hairline); -//// tables.get(j).getTableFormat().getBorders().getRight().setLineWidth(0F); -//// tables.get(j).getTableFormat().getBorders().getRight().setColor(Color.white); -//// -// //设置表格的顶部边框 -// tables.get(j).getTableFormat().getBorders().getTop().setBorderType(BorderStyle.Hairline); -// tables.get(j).getTableFormat().getBorders().getTop().setLineWidth(0.2F); -// tables.get(j).getTableFormat().getBorders().getTop().setColor(Color.black); -//// -//// //设置表格的左边框 -//// tables.get(j).getTableFormat().getBorders().getLeft().setBorderType(BorderStyle.Hairline); -//// tables.get(j).getTableFormat().getBorders().getLeft().setLineWidth(0F); -//// tables.get(j).getTableFormat().getBorders().getLeft().setColor(Color.white); -//// -// //设置表格的底部边框 -// tables.get(j).getTableFormat().getBorders().getBottom().setBorderType(BorderStyle.Hairline); -//// tables.get(j).getTableFormat().getBorders().getLeft().setColor(Color.black); -// tables.get(j).getTableFormat().getBorders().getBottom().setLineWidth(0.2F); -// //设置表格的水平和垂直边框 -//// tables.get(j).getTableFormat().getBorders().getVertical().setBorderType(BorderStyle.Hairline); -//// tables.get(j).getTableFormat().getBorders().getHorizontal().setBorderType(BorderStyle.Hairline); -//// tables.get(j).getTableFormat().getBorders().getVertical().setLineWidth(0F); -//// tables.get(j).getTableFormat().getBorders().getHorizontal().setLineWidth(0F); -//// tables.get(j).getTableFormat().getBorders().getVertical().setColor(Color.white); -// -//// tables.get(j).getRows().get(0).setHeight(99F); -//// tables.get(j).getRows().get(0).getRowFormat().getBorders().setBorderType(BorderStyle.Hairline); -//// RowCollection rows = tables.get(j).getRows(); -//// for (int l = 0; l < rows.getCount(); l++) { -//// rows.get(l).setHeight(15F); -//// } -// -// -// CellCollection rowCollection = tables.get(j).getRows().get(0).getCells(); -// for (int k = 0; k < rowCollection.getCount(); k++) { -// rowCollection.get(k).getCellFormat().getBorders().getBottom().setBorderType(BorderStyle.Hairline); -// rowCollection.get(k).getCellFormat().getBorders().getBottom().setLineWidth(0.2F); -//// rowCollection.get(k).getCellFormat().getBorders().getBottom().setColor(Color.red); -// } -//// tables.get(j).getRows().get(0).getCells().get(0).getCellFormat().getBorders().getBottom().setBorderType(BorderStyle.Hairline); -// tables.get(j).autoFit(AutoFitBehaviorType.Auto_Fit_To_Window); -// -//// tables.get(j).getTableFormat().setHorizontalAlignment(RowAlignment.Right); -// } -// } - - - String uuid = UUID.randomUUID().toString().trim().replaceAll("-", ""); - doc.saveToFile(path + uuid + ".docx"); - inputStream.close(); - filePath = randomFix + uuid + ".docx"; - } catch (Exception e) { - e.printStackTrace(); - } - return filePath; - } } diff --git a/src/main/java/com/example/ts_obj/entity/TypesetInfo.java b/src/main/java/com/example/ts_obj/entity/TypesetInfo.java index 6849533..62e362e 100644 --- a/src/main/java/com/example/ts_obj/entity/TypesetInfo.java +++ b/src/main/java/com/example/ts_obj/entity/TypesetInfo.java @@ -1,6 +1,11 @@ package com.example.ts_obj.entity; +import com.fasterxml.jackson.annotation.JsonSetter; + import java.io.Serializable; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; /** @@ -67,9 +72,9 @@ public class TypesetInfo implements Serializable { private String userAccount; - private Map> images; + private Map> images=new LinkedHashMap<>();; - private Map> tables; + private Map> tables=new LinkedHashMap<>();; private static final long serialVersionUID = 1L; @@ -205,16 +210,30 @@ public class TypesetInfo implements Serializable { return images; } + @JsonSetter public void setImages(Map> images) { - this.images = images; + if (images instanceof List) { + // 处理数组 + this.images = new HashMap<>(); + // 根据需要将数组转化为 Map + } else { + this.images = (Map>) images; + } } public Map> getTables() { return tables; } - public void setTables(Map> tables) { - this.tables = tables; + @JsonSetter + public void setTables(Object tables) { + if (tables instanceof List) { + // 处理数组 + this.tables = new HashMap<>(); + // 根据需要将数组转化为 Map + } else { + this.tables = (Map>) tables; + } } public void setStage(String stage) {