diff --git a/src/main/java/com/example/ts_obj/controller/DataapiController.java b/src/main/java/com/example/ts_obj/controller/DataapiController.java index 4e54804..580a503 100644 --- a/src/main/java/com/example/ts_obj/controller/DataapiController.java +++ b/src/main/java/com/example/ts_obj/controller/DataapiController.java @@ -1,6 +1,8 @@ package com.example.ts_obj.controller; import cn.hutool.core.io.FileUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.deepoove.poi.XWPFTemplate; import com.example.ts_obj.bean.ReturnCodeAndMsgEnum; import com.example.ts_obj.bean.ReturnValue; @@ -32,16 +34,19 @@ public class DataapiController { /** * 模板生成work文档 - * @param map * @return 文档路径 */ @PostMapping("/createTemplate") - public ReturnValue createTemplate (Map map){ + public ReturnValue createTemplate (String issue,String date_list){ + + JSONArray ja = (JSONArray) JSON.parse(date_list); + HashMap result = Maps.newHashMap(); - if (map.size() == 0) { - return new ReturnValue(ReturnCodeAndMsgEnum.No_Data); - } - XWPFTemplate template = XWPFTemplate.compile(BASE_DIR + "data_template").render(map); + HashMap map = new HashMap<>(); + map.put("date",issue); + map.put("list",ja); + + XWPFTemplate template = XWPFTemplate.compile(BASE_DIR + "data_template.docx").render(map); try { Date date = new Date(); String dirpath = BASE_DIR + new SimpleDateFormat("yyyyMMdd").format(date); @@ -53,6 +58,6 @@ public class DataapiController { } catch (IOException e) { e.printStackTrace(); } - return new ReturnValue(ReturnCodeAndMsgEnum.Success, result); + return new ReturnValue(ReturnCodeAndMsgEnum.Success,result); } } 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 c5cb42f..4bb2b53 100644 --- a/src/main/java/com/example/ts_obj/controller/TypesetController.java +++ b/src/main/java/com/example/ts_obj/controller/TypesetController.java @@ -61,11 +61,10 @@ public class TypesetController { private final static Logger logger = LoggerFactory.getLogger(UserController.class); - private String BASE_DIR="C:\\Users\\Administrator\\Desktop\\typesetcode\\upload\\"; - private static String NEW_BASE_DIR="C:\\Users\\Administrator\\Desktop\\typesetcode\\upload\\20220520\\"; - - private static String IMG_DIR="C:\\Users\\Administrator\\Desktop\\typesetcode\\pictures\\"; -// private String BASE_DIR = "/home/wwwroot/ts.tmrjournals.com/upload/"; +// private String BASE_DIR = "E:/"; +// private static String IMG_DIR = "E:/"; + private String BASE_DIR = "/home/wwwroot/ts.tmrjournals.com/upload/"; + private String IMG_DIR = "/home/wwwroot/ts.tmrjournals.com/upload/pictures/"; @Autowired private TypesetService typesetservice; @@ -203,163 +202,20 @@ public class TypesetController { @ApiOperation(value = "读取文件") @PostMapping("readdoc") public ReturnValue myDocReader(String filename) { - -// String filename = "300641ce-cb9b-4a41-b5d9-de7028e46b171639634304222.docx"; - ArrayList al = new ArrayList(); try { File file = new File(this.BASE_DIR + filename); FileInputStream fis = new FileInputStream(file); XWPFDocument xdoc = new XWPFDocument(fis); List list = xdoc.getParagraphs(); - List tables = xdoc.getTables(); - for (XWPFTable table : tables) { - //表格属性 - CTTblPr pr = table.getCTTbl().getTblPr(); - //获取表格对应的行 - List rows = table.getRows(); - for (XWPFTableRow row : rows) { - //获取行对应的单元格 - List cells = row.getTableCells(); - for (XWPFTableCell cell : cells) { - //System.out.println(cell.getText()); - } - } - } -// String lastParagraphText = ""; -// //读取文档在数据库的内容 -// -// -// //获取图片所在位置保存 -// 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(); -// lastParagraphText = list.get(i - 1).getParagraphText(); -// if (StringUtils.isBlank(lastParagraphText)){ -// for (int j = 2 ; j allPictures = xdoc.getAllPictures(); -// //遍历照片 -//// for (XWPFPictureData picture: allPictures) { -// byte[] data = pictureData.getData(); -// File filePicture = new File("C:\\Users\\yl\\Desktop\\pictures\\" + imageName.replace("image","")); -// if (!filePicture.exists()){ -// if (filePicture.getParentFile().exists()) { -// filePicture.getParentFile().mkdirs(); -// } -// filePicture.createNewFile(); -// } -// FileOutputStream fileOutputStream = new FileOutputStream(filePicture); -// fileOutputStream.write(data,0,data.length); -// fileOutputStream.close(); -// //System.out.println("执行结束了"); -//// } -// } -// } -// } - - -// List tables = xdoc.getTables(); -// for (XWPFTable table : tables) { -// List rowList = table.getRows(); -// CTTblBorders borders = table.getCTTbl().getTblPr().addNewTblBorders(); -// CTBorder hBorder = borders.addNewInsideH(); -// hBorder.setVal(STBorder.Enum.forString("nil")); -// hBorder.setSz(new BigInteger("1")); -// -// CTBorder vBorder = borders.addNewInsideV(); -// vBorder.setVal(STBorder.Enum.forString("nil")); -// vBorder.setSz(new BigInteger("1")); -// -// CTBorder lBorder = borders.addNewLeft(); -// lBorder.setVal(STBorder.Enum.forString("nil")); -// lBorder.setSz(new BigInteger("1")); -// -// CTBorder rBorder = borders.addNewRight(); -// rBorder.setVal(STBorder.Enum.forString("nil")); -// rBorder.setSz(new BigInteger("1")); -// -// CTBorder tBorder = borders.addNewTop(); -// tBorder.setVal(STBorder.Enum.forString("thick")); -// tBorder.setSz(new BigInteger("10")); -// -// CTBorder bBorder = borders.addNewBottom(); -// bBorder.setVal(STBorder.Enum.forString("thick")); -// bBorder.setSz(new BigInteger("10")); -// -// CTTbl ttbl = table.getCTTbl(); -// CTTblPr tblPr = ttbl.getTblPr() == null ? ttbl.addNewTblPr() : ttbl.getTblPr(); -// CTTblWidth tblWidth = tblPr.isSetTblW() ? tblPr.getTblW() : tblPr.addNewTblW(); -// CTJc cTJc = tblPr.addNewJc(); -// cTJc.setVal(STJc.Enum.forString("center")); -// tblWidth.setW(new BigInteger("8000")); -// tblWidth.setType(STTblWidth.DXA); - - //设置表头样式与标题 -// List tableCells = rowList.get(0).getTableCells(); -// Iterator fieldIterator = Arrays.stream(TableDetail.class.getDeclaredFields()).iterator(); -// for (XWPFTableCell tableCell : tableCells) { -// Field field = fieldIterator.next(); -// TableField annotation = field.getAnnotation(TableField.class); -// String value = annotation.value(); -// CTTcBorders ctTcBorders = tableCell.getCTTc().addNewTcPr().addNewTcBorders(); -// CTBorder ctBorder = ctTcBorders.addNewBottom(); -// ctBorder.setVal(STBorder.Enum.forString("single")); -// ctBorder.setSz(new BigInteger("1")); -// setCellText(tableCell, value, "FFFFFF", 1600); -// } -// } -// Boolean bold = false; - for (int i=0 ; i < list.size() ; i++){ -// for (XWPFParagraph para : list) { - //System.out.println("内容为"+list.get(i).getRuns()); -// ArrayList cac_al = new ArrayList();//加粗 -// ArrayList cac_it = new ArrayList();//斜体 -// String cache = para.getText().trim(); + for (int i = 0; i < list.size(); i++) { String cache = ""; -// if(cache.trim().toUpperCase().equals("ABSTRACT")){ -// bold = true; -// } List runs = list.get(i).getRuns(); - String replace = String.valueOf(runs).replace(",", "").replace(" ",""); - if (replace.contains("Objective. A comprehensive and updated systematic review is needed to evaluate the effectiveness and safety of HuangQiXiXin decoction (HQXXD) for cough variant asthma (CVA). The aim of this systematic review protocol is to comprehensively assess the effectiveness and safety of HQXXD for CVA. Methods. An overall search for studies in main English and Chinese electronic databases from their inception to January 2021 will be performed. Randomized controlled trials (RCTs) regarding HQXXD for CVA will be included. We will use RevMan 5.3 software to perform statistical analysis and meta-analysis. Results. The findings of this systematic review will be disseminated through peer-reviewed publications. Conclusion. The systematic review will provide more evidence regarding the effectiveness and safety of HQXXD for CVA.".replace(",","").replace(" ",""))){ - //System.out.println("确实包含"); -// for (int r=0 ; r < runs.size() ; r++){ -// runs.get(r); -// -// } - //获取光标 - XmlCursor xmlCursor = list.get(i+1).getCTP().newCursor(); - XWPFParagraph xwpfParagraph = xdoc.insertNewParagraph(xmlCursor); - XWPFRun run = xwpfParagraph.createRun(); -// run.setText("{{@image}}"); - FileInputStream inputStream = new FileInputStream("C:\\Users\\yl\\Desktop\\pictures\\1.png"); - run.addPicture(inputStream,XWPFDocument.PICTURE_TYPE_JPEG,"1.jgp", Units.toEMU(180),Units.toEMU(180)); - } - - - for (XWPFRun r : runs) { -// if(!bold){ -// break; -// } - String cach = ""; - if (r.getText(0) == null) { continue; } - if (r.isItalic() && r.isBold()) { cach = "" + r.getText(0) + ""; } else if (r.isItalic()) { @@ -369,36 +225,10 @@ public class TypesetController { } else { cach = r.getText(0); } - -// //System.out.println(cach); - -// if(r.isItalic()&&r.getText(0)!=null){ -// cach = ""+r.getText(0)+""; -//// cac_it.add(r.getText(0)); -// } -// if(r.isBold()&&r.getText(0)!=null){ -// cach = ""+cach+""; -//// cac_al.add(r.getText(0)); -// } -// cache += cach; } -// for(Object cc:cac_al){ -// cache = cache.replace(cc.toString(),""+cc.toString()+""); -// } -// for(Object ii:cac_it){ -// cache = cache.replace(ii.toString(),""+ii.toString()+""); -// } al.add(cache); } - - FileOutputStream os = new FileOutputStream("C:\\Users\\yl\\Desktop\\pictures\\1.doc"); - xdoc.write(os); - //System.out.println("输出完毕"); - - //获取word文本中的所有表格 -// Iterator tablesIterator = xdoc.getTablesIterator(); - } catch (Exception e) { e.getStackTrace(); } @@ -416,7 +246,7 @@ public class TypesetController { // FileDownloadUtil.writeFile(response, inputStream); XWPFDocument xdoc = new XWPFDocument(inputStream); List list = xdoc.getParagraphs(); - for (XWPFParagraph para:list) { + for (XWPFParagraph para : list) { String cache = ""; List runs = para.getRuns(); for (XWPFRun r : runs) { @@ -474,7 +304,7 @@ public class TypesetController { @ApiOperation(value = "获取生成的docx") @PostMapping("/getDocx") - public ReturnValue getDocx(Long typesetId,@RequestParam("filename") String filename) throws IOException { + public ReturnValue getDocx(Long typesetId) throws IOException { Map m = typesetservice.getTypesetDetail(typesetId); Map frag = new HashMap(); Typeset t = (Typeset) m.get("info"); @@ -535,110 +365,9 @@ public class TypesetController { map.put("keywords", ti.getKeywords().replace("", "").replace("", "")); // map.put("img", this.BASE_DIR + "p1.png"); - ArrayList arrayList = new ArrayList<>(); - //读取原文件表格数据 - Document doc = new Document(); - doc.loadFromFile(this.BASE_DIR+filename); - SectionCollection sections = doc.getSections(); - - //保存文本 - String output = "C:\\Users\\Administrator\\Desktop\\typesetcode\\a.txt"; - File file = new File(output); - if (!file.exists()) { - file.delete(); - } - file.createNewFile(); - FileWriter fw = new FileWriter(file, true); - BufferedWriter bw = new BufferedWriter(fw); - - for (int i = 0; i "+arrayList); - } - } - bw.flush(); - bw.close(); - fw.close(); - - // - List list = new ArrayList<>(); - LinkedHashMap params = new LinkedHashMap<>(); - for (int i = 0; i < arrayList.size(); i++){ - List o = (List) arrayList.get(i); - if (i == 0) { - for (int j = 0; j < o.size(); j++) { - params.put(j,o.get(j)); - } - list.add(params); - }else { - LinkedHashMap hashMap = new LinkedHashMap<>(); - for (int j = 0; j < o.size(); j++) { - String o1 = (String) o.get(j); - hashMap.put(j, o1); - } - list.add(hashMap); - } - - } - //System.out.println("list===============>"+list); - map.put("table", list); - Configure config = Configure.builder().bind("content", new ParagraphRenderPolicy()). bind("abstract", new ParagraphRenderPolicy()).bind("table", new CustomTableRenderPolicy()). build(); -// ParagraphRenderData pds = new ParagraphRenderData(); -// Style sss1 = new Style(); -// Style sss2 = new Style(); -// sss1.setBold(true); -// sss1.setItalic(true); -// sss2.setItalic(true); -// pds.addText(new TextRenderData("nininini",sss1)); -// pds.addText(new TextRenderData("wowowowo",sss2)); -// map.put("keywords",pds); //part2 String main = ti.getMainText(); List l = JSON.parseArray(main, String.class); @@ -647,35 +376,11 @@ public class TypesetController { Map cache = new HashMap(); ParagraphRenderData capd = this.crowStr(s); cache.put("content", capd); -// if(s.indexOf("")>=0){ -// s = s.replace("","").replace("",""); -// Style sty = new Style(); -// sty.setBold(true); -// cache.put("content", new TextRenderData(s,sty)); -// }else{ -// cache.put("content",s); -// } mainArr.add(cache); } map.put("main", mainArr); - //part3 -// ArrayList refArr = new ArrayList(); -// Integer bh = 0; -// for(TypesetInfoReference tif: refList){ -// Map cache = new HashMap(); -// String cache_ref = ""; -// if(Util.HasDigit(tif.getRefer_title().substring(0,5))||tif.getRefer_title().trim().toUpperCase().equals("REFERENCE")){ -// cache_ref = tif.getRefer_title().replace("","").replace("",""); -// }else{ -// cache_ref = (++bh).toString()+tif.getRefer_title().replace("","").replace("",""); -// } -// cache.put("refercontent",cache_ref); -// refArr.add(cache); -// } -// map.put("reference",refArr); - //测试 List refsl = new ArrayList(); for (TypesetInfoReference tif : refList) { @@ -734,26 +439,26 @@ public class TypesetController { map.put("doi", typesetInfo.getDoi()); map.put("topic", typesetInfo.getTopic()); map.put("articletitle", typesetInfo.getInfo_title().replace("", "").replace("", "").replace("", "").replace("", "")); - + //解决作者小标问题 String author = typesetInfo.getAuthor(); String[] s_author = author.split(""); ParagraphRenderData author_p = new ParagraphRenderData(); -// for (String i:s_author){ -// if(i.equals("")){ -// continue; -// } -// String[] cache_author = i.split(""); -// String au = cache_author[0]; -// String bu = cache_author[1]; -// Style ca_sty = new Style(); -// ca_sty.setVertAlign("superscript"); -// author_p.addText(new TextRenderData(au.replace("", "").replace("", ""))); -// author_p.addText(new TextRenderData(bu.replace("", "").replace("", ""),ca_sty)); -// } -// -// map.put("author",author_p); - - map.put("author", typesetInfo.getAuthor().replace("", "").replace("", "").replace("", "").replace("", "")); + for (int i = 0; i < s_author.length; i++) { + if (s_author[i].equals("")) { + continue; + } + String[] cache_author = s_author[i].split(""); + String au = cache_author[0]; + String bu = cache_author[1]; + Style ca_sty = new Style(); + ca_sty.setVertAlign("superscript"); + author_p.addText(au); + author_p.addText(new TextRenderData(bu.replace("", "").replace("", ""), ca_sty)); + if (i < s_author.length - 1) { + author_p.addText(","); + } + } + map.put("author", author_p); map.put("authoraddress", typesetInfo.getAuthorAddress().replace("", "").replace("", "").replace("", "").replace("", "")); map.put("corresponding", typesetInfo.getAuthorCorresponding().replace("", "").replace("", "").replace("", "").replace("", "")); map.put("coremail", typesetInfo.getAuthorCorrespondingEmail().replace("", "").replace("", "").replace("", "").replace("", "")); @@ -774,133 +479,68 @@ public class TypesetController { } map.put("abbreviation", typesetInfo.getAbbreviation()); map.put("citation", (typesetInfo.getLittle_author() + ". " + typesetInfo.getInfo_title() + ". " + typesetInfo.getJabbr() + ". " + typesetInfo.getStage() + ". doi: " + typesetInfo.getDoi() + ".").replace("", "").replace("", "").replace("", "").replace("", "")); -// map.put("exeditor", user.getAccount()); map.put("exeditor", typesetInfo.getUserAccount()); -// SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM yyyy", Locale.ENGLISH); -// if (typesetInfo.getReceived_date().toString().equals("")) { -// map.put("received_date", typesetInfo.getReceived_date()); -// } else { - map.put("received_date", typesetInfo.getReceived_date()); -// } -// map.put("received_date",sdf.format(new Date(Long.valueOf(typesetInfo.getReceived_date())))); -// if (typesetInfo.getAccepted_date().toString().equals("")) { -// map.put("accept_date", typesetInfo.getAccepted_date()); -// } else { - map.put("accept_date", typesetInfo.getAccepted_date()); -// } -// map.put("accept_date",sdf.format(new Date(Long.valueOf(typesetInfo.getAccepted_date())))); -// if (typesetInfo.getOnline_date().toString().equals("")) { -// map.put("online_date", typesetInfo.getOnline_date()); -// } else { - map.put("online_date", typesetInfo.getOnline_date()); -// } + map.put("received_date", typesetInfo.getReceived_date()); + map.put("accept_date", typesetInfo.getAccepted_date()); + map.put("online_date", typesetInfo.getOnline_date()); map.put("ye", typesetInfo.getStage().substring(0, 4)); -// map.put("abstract",typesetInfo.getAbstractText().replace("","").replace("","")); map.put("abstract", this.crowStr(typesetInfo.getAbstractText())); map.put("keywords", typesetInfo.getKeywords().replace("", "").replace("", "")); -// map.put("img", this.BASE_DIR + "p1.png"); - - InputStream inputStream = FileDownloadUtil.getInputStream(typesetInfo.getFilename()); - Document doc = new Document(inputStream); SectionCollection sections = doc.getSections(); - -// //保存文本 -// File file = new File(output); -// if (!file.exists()) { -// file.delete(); -// } -// file.createNewFile(); -// FileWriter fw = new FileWriter(file, true); -// BufferedWriter bw = new BufferedWriter(fw); ArrayList tablesList = new ArrayList<>(); - for (int i = 0; i arrayList = new ArrayList<>(); - Table table = tables.get(j); //创建String List table.applyStyle(DefaultTableStyle.Table_Classic_1); List images = new ArrayList(); - //遍历表格中的行 - for (int l = 0; l < table.getRows().getCount(); l++) - { + for (int l = 0; l < table.getRows().getCount(); l++) { ArrayList prList = new ArrayList(); - TableRow row = table.getRows().get(l); //遍历每行中的单元格 - for (int k = 0; k < row.getCells().getCount(); k++) - { + for (int k = 0; k < row.getCells().getCount(); k++) { TableCell cell = row.getCells().get(k); //遍历单元格中的段落 String myText = ""; - for (int n = 0; n < cell.getParagraphs().getCount(); n++) - { - + for (int n = 0; n < cell.getParagraphs().getCount(); n++) { Paragraph paragraph = cell.getParagraphs().get(n); myText += paragraph.getText(); -// bw.write(paragraph.getText() + "\t");//获取文本内容 - //System.out.println("表格数据"+paragraph.getText()); - //System.out.println("prlist=========="+prList); - -// //遍历段落中的所有子对象 -// for (int x = 0; x < paragraph.getChildObjects().getCount(); x++) -// { -// Object object = paragraph.getChildObjects().get(x); -// //判定对象是否为图片 -// if (object instanceof DocPicture) -// { -// //获取图片 -// DocPicture picture = (DocPicture) object; -// images.add(picture.getImage()); -// } -// } } prList.add(myText); } arrayList.add(prList); -// bw.write("\r\n");//写入内容到txt文件 } -// //System.out.println("List=====================>"+arrayList); tablesList.add(arrayList); } - } -// //System.out.println("tablesList============>"+tablesList); -// bw.flush(); -// bw.close(); -// fw.close(); int num = 0; int length = 0; - if (tablesList.size() > 1){ - for (List ls:tablesList - ) { -// //System.out.println("ls================"+ls); + if (tablesList.size() > 1) { + for (List ls : tablesList + ) { List list = new ArrayList<>(); LinkedHashMap params = new LinkedHashMap<>(); - for (int i = 0; i < ls.size(); i++){ - + for (int i = 0; i < ls.size(); i++) { List o = (List) ls.get(i); List p = (List) ls.get(0); length = p.size(); - - if (length != o.size() ) { - map.remove("table"+num); - map.put("error","table"+num+"格式错误"); + if (length != o.size()) { + map.remove("table" + num); + map.put("error", "table" + num + "格式错误"); break; } - if (i == 0) { for (int j = 0; j < o.size(); j++) { - params.put(j,o.get(j)); + params.put(j, o.get(j)); } list.add(params); - }else { + } else { LinkedHashMap hashMap = new LinkedHashMap<>(); for (int j = 0; j < o.size(); j++) { String o1 = (String) o.get(j); @@ -908,49 +548,18 @@ public class TypesetController { } list.add(hashMap); } - } num++; - map.put("table"+num, list); - //System.out.println("测试=====================》"+map.get("table"+num)); + map.put("table" + num, list); } - }else { - // - List list = new ArrayList<>(); - LinkedHashMap params = new LinkedHashMap<>(); - for (int i = 0; i < tablesList.get(0).size(); i++){ - List o = (List) tablesList.get(0).get(i); - if (i == 0) { - for (int j = 0; j < o.size(); j++) { - params.put(j,o.get(j)); - } - list.add(params); - }else { - LinkedHashMap hashMap = new LinkedHashMap<>(); - for (int j = 0; j < o.size(); j++) { - String o1 = (String) o.get(j); - hashMap.put(j, o1); - } - list.add(hashMap); - } - - } - //System.out.println("list9===============>"+list); - map.put("table1", list); } - - - - - - - Configure config = Configure.builder().bind("content", new ParagraphRenderPolicy()). - bind("abstract", new ParagraphRenderPolicy()).bind("table1", new CustomTableRenderPolicy()) + Configure config = Configure.builder().bind("content", new ParagraphRenderPolicy()) + .bind("abstract", new ParagraphRenderPolicy()).bind("author", new ParagraphRenderPolicy()) + .bind("table1", new CustomTableRenderPolicy()) .bind("table2", new CustomTableRenderPolicy()).bind("table3", new CustomTableRenderPolicy()) .bind("table4", new CustomTableRenderPolicy()).bind("table5", new CustomTableRenderPolicy()) .bind("table6", new CustomTableRenderPolicy()).bind("table7", new CustomTableRenderPolicy()) - .bind("table8", new CustomTableRenderPolicy()).bind("table9", new CustomTableRenderPolicy()). - build(); + .bind("table8", new CustomTableRenderPolicy()).bind("table9", new CustomTableRenderPolicy()).build(); String main = typesetInfo.getMainText(); List l = JSON.parseArray(main, String.class); ArrayList mainArr = new ArrayList(); @@ -963,33 +572,11 @@ public class TypesetController { } map.put("main", mainArr); -// JSONArray ja = (JSONArray) JSON.parse(typesetInfo.getRefers()); -// ArrayList referArr = new ArrayList(); -// int keyn = 0; -// for (Object tif : ja){ -// keyn++; -// String tttt = keyn+" "+String.valueOf(tif).replace("", "").replace("", "").replace("", "").replace("", "").trim().toUpperCase(); -// Map cache = new HashMap(); -// Style chch = new Style(); -// chch.setFontFamily("Charis SIL"); -// chch.setFontSize(7.5); -// cache.put("ref",new TextRenderData(tttt, chch)); -// referArr.add(cache); -// } -// -// map.put("refers",referArr); - - - //测试 - + //参考文献部分 JSONArray ja = (JSONArray) JSON.parse(typesetInfo.getRefers()); - List refsl = new ArrayList(); for (Object tif : ja) { String tttt = String.valueOf(tif).replace("", "").replace("", "").replace("", "").replace("", "").trim().toUpperCase(); -// if (tttt.equals("REFERENCE") || tttt.equals("REFERENCES")) { -// continue; -// } ParagraphRenderData chc_pd = new ParagraphRenderData(); Style chch = new Style(); @@ -999,9 +586,9 @@ public class TypesetController { chc_pd.addText(new TextRenderData(tgh_title, chch)); refsl.add(chc_pd); } - map.put("refs", new NumberingRenderData(NumberingFormat.DECIMAL, refsl)); + //最终生成 String myTemplate = ""; //确定使用的模板 if (typesetInfo.getInfo_type().toUpperCase().equals("COMMENT") || typesetInfo.getInfo_type().toUpperCase().equals("NEWS")) { @@ -1009,7 +596,6 @@ public class TypesetController { } else { myTemplate = "template1.docx"; } - XWPFTemplate template = XWPFTemplate.compile(this.BASE_DIR + myTemplate, config).render(map); try { Date date = new Date(); @@ -1020,17 +606,15 @@ public class TypesetController { f.mkdirs(); } String goFileName = System.currentTimeMillis() + ".docx"; -// frag.put("file", new SimpleDateFormat("yyyyMMdd").format(date) + "/" + goFileName); template.writeAndClose(new FileOutputStream(dirpath + "/" + goFileName)); String filePath = addPic1(typesetInfo.getFilename(), dirpath + "/" + goFileName); frag.put("file", filePath); } catch (IOException e) { e.printStackTrace(); } - return new ReturnValue(ReturnCodeAndMsgEnum.Success, frag); } - + private ParagraphRenderData crowStr(String s) { ParagraphRenderData p = new ParagraphRenderData(); @@ -1051,7 +635,7 @@ public class TypesetController { } else if (s.indexOf("") >= 0) { cache_act = "b"; } else { - cache_act = "i"; + cache_act = "i"; } if (cache_act == "b") { @@ -1127,241 +711,240 @@ public class TypesetController { return p; } - @ApiOperation(value = "生成图片") - @PostMapping("/addPic") - public ReturnValue addPic(String OldFileName,String newFileName){ - //1.操作初始文档获取图片 和 图片所在的位置 - try { - File file = new File(this.BASE_DIR + OldFileName); - FileInputStream fis = new FileInputStream(file); - XWPFDocument xdoc = new XWPFDocument(fis); - List list = xdoc.getParagraphs(); - String lastParagraphText = ""; - //TODO 读取文档在数据库的内容 - - //准备一个图片名称list - ArrayList picNameList = new ArrayList<>(); - //准备一个Map key为图片名称,值为位置 - HashMap picMap = new HashMap<>(); - - String randomFix = String.valueOf(System.currentTimeMillis()) + "\\"; - - //获取图片所在位置保存 - 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 list = xdoc.getParagraphs(); +// String lastParagraphText = ""; +// //TODO 读取文档在数据库的内容 +// +// //准备一个图片名称list +// ArrayList picNameList = new ArrayList<>(); +// //准备一个Map key为图片名称,值为位置 +// HashMap picMap = new HashMap<>(); +// +// String randomFix = String.valueOf(System.currentTimeMillis()) + "\\"; +// +// //获取图片所在位置保存 +// 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 allPictures = xdoc.getAllPictures(); - //遍历照片 -// for (XWPFPictureData picture: allPictures) { - byte[] data = pictureData.getData(); - File filePicture = new File(IMG_DIR + randomFix + imageName.replace("image","")); - if (!filePicture.exists()){ - if (filePicture.getParentFile().exists()) { - filePicture.getParentFile().mkdirs(); - } - filePicture.createNewFile(); - } - FileOutputStream fileOutputStream = new FileOutputStream(filePicture); - fileOutputStream.write(data,0,data.length); - fileOutputStream.close(); -// //System.out.println("执行结束了"); -// } - } - } - } -// //System.out.println("picNameList===========>"+picNameList); -// //System.out.println("picMap===========>"+picMap); - //2.获取按模板新生成的文档添加图片 - File newFile = new File(this.NEW_BASE_DIR + newFileName); - FileInputStream newFis = new FileInputStream(newFile); - XWPFDocument newXdoc = new XWPFDocument(newFis); - List paragraphs = newXdoc.getParagraphs(); - - - //其他方式 - Document doc = new Document(); - doc.loadFromFile(this.NEW_BASE_DIR + newFileName); - Section sec = doc.getSections().get(0); -// //System.out.println("sec=================>"+sec); - String text = doc.getText(); -// //System.out.println("text=================>"+text); - Paragraph para = sec.getParagraphs().get(0); -// //System.out.println("para=================>"+para); - for(int i = 0; i < doc.getSections().getCount(); i++) { - Section section = doc.getSections().get(i); - for (int j = 0; j < section.getParagraphs().getCount(); j++) { - Paragraph paragraph = section.getParagraphs().get(j); -// //System.out.println(j+"新方式内容"+paragraph.getText()); - for (String pic: picNameList) { - String replace = String.valueOf(paragraph.getText()).replace(",", "").replace(" ", ""); - if (replace.contains(picMap.get(pic).replace(",", "").replace(" ", ""))) { -// //System.out.println("包含"); - String imgPath = IMG_DIR + randomFix +pic.replace("image", ""); - - File picture=new File(imgPath); - BufferedImage sourceImg= ImageIO.read(new FileInputStream(picture)); - int width = sourceImg.getWidth(); - sourceImg.getHeight(); - - //判断图片中是否包含 文字 -// String valCode = new OCRUtil().recognizeText(new File(imgPath)); -// //System.out.println("valCode==============>"+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 <= 220f){ - //图片为小图 双栏 - DocPicture docPicture = paragraph.appendPicture(imgPath); - docPicture.setWidth(220f); - docPicture.setHeight(180f); - docPicture.setTextWrappingStyle(TextWrappingStyle.Top_And_Bottom); - docPicture.setTextWrappingType(TextWrappingType.Both); - }else { - //图片为大图 单栏 - DocPicture docPicture = paragraph.appendPicture(imgPath); - docPicture.setWidth(500f); - docPicture.setHeight(180f); - docPicture.setTextWrappingStyle(TextWrappingStyle.Top_And_Bottom); - docPicture.setTextWrappingType(TextWrappingType.Both); - } +// picMap.put(imageName,lastParagraphText); +//// //System.out.println(pictureId +"\t|" + imageName + "\t|" + lastParagraphText); +// //获取word文本中所有的图片 +//// List allPictures = xdoc.getAllPictures(); +// //遍历照片 +//// for (XWPFPictureData picture: allPictures) { +// byte[] data = pictureData.getData(); +// File filePicture = new File(IMG_DIR + randomFix + imageName.replace("image","")); +// if (!filePicture.exists()){ +// if (filePicture.getParentFile().exists()) { +// filePicture.getParentFile().mkdirs(); // } - - } - } - - } - } - 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("-", ""); - -// for (int i=0 ; i < paragraphs.size() ; i++){ -// //System.out.println("内容为"+paragraphs.get(i).getRuns()); -// List runs = paragraphs.get(i).getRuns(); -// String replace = String.valueOf(runs).replace(",", "").replace(" ",""); -// for (String pic: picNameList){ -// if (replace.contains(picMap.get(pic).replace(",","").replace(" ",""))){ -// //System.out.println("包含执行了"); -// //获取光标 -// XmlCursor xmlCursor = paragraphs.get(i+1).getCTP().newCursor(); -// XWPFParagraph xwpfParagraph = newXdoc.insertNewParagraph(xmlCursor); -// -// XWPFRun run = xwpfParagraph.createRun(); -//// run.addBreak(BreakClear.ALL); -//// run.setText("{{@image}}"); -// FileInputStream inputStream = new FileInputStream("C:\\Users\\yl\\Desktop\\pictures\\"+pic.replace("image","")); -// run.addPicture2(inputStream,XWPFDocument.PICTURE_TYPE_JPEG,pic, Units.toEMU(500),Units.toEMU(180)); -// // +// filePicture.createNewFile(); +// } +// FileOutputStream fileOutputStream = new FileOutputStream(filePicture); +// fileOutputStream.write(data,0,data.length); +// fileOutputStream.close(); +//// //System.out.println("执行结束了"); +//// } // } // } -// // } -// FileOutputStream os = new FileOutputStream(IMG_DIR+"New.doc"); -// newXdoc.write(os); - doc.saveToFile(IMG_DIR + randomFix + uuid+".docx"); - //System.out.println("输出完毕"); -// os.close(); - fis.close(); - newFis.close(); - }catch (Exception e){ - e.printStackTrace(); - } - return new ReturnValue(ReturnCodeAndMsgEnum.Success); - } - +//// //System.out.println("picNameList===========>"+picNameList); +//// //System.out.println("picMap===========>"+picMap); +// //2.获取按模板新生成的文档添加图片 +// File newFile = new File(this.NEW_BASE_DIR + newFileName); +// FileInputStream newFis = new FileInputStream(newFile); +// XWPFDocument newXdoc = new XWPFDocument(newFis); +// List paragraphs = newXdoc.getParagraphs(); +// +// +// //其他方式 +// Document doc = new Document(); +// doc.loadFromFile(this.NEW_BASE_DIR + newFileName); +// Section sec = doc.getSections().get(0); +//// //System.out.println("sec=================>"+sec); +// String text = doc.getText(); +//// //System.out.println("text=================>"+text); +// Paragraph para = sec.getParagraphs().get(0); +//// //System.out.println("para=================>"+para); +// for(int i = 0; i < doc.getSections().getCount(); i++) { +// Section section = doc.getSections().get(i); +// for (int j = 0; j < section.getParagraphs().getCount(); j++) { +// Paragraph paragraph = section.getParagraphs().get(j); +//// //System.out.println(j+"新方式内容"+paragraph.getText()); +// for (String pic: picNameList) { +// String replace = String.valueOf(paragraph.getText()).replace(",", "").replace(" ", ""); +// if (replace.contains(picMap.get(pic).replace(",", "").replace(" ", ""))) { +//// //System.out.println("包含"); +// String imgPath = IMG_DIR + randomFix +pic.replace("image", ""); +// +// File picture=new File(imgPath); +// BufferedImage sourceImg= ImageIO.read(new FileInputStream(picture)); +// int width = sourceImg.getWidth(); +// sourceImg.getHeight(); +// +// //判断图片中是否包含 文字 +//// String valCode = new OCRUtil().recognizeText(new File(imgPath)); +//// //System.out.println("valCode==============>"+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 <= 220f){ +// //图片为小图 双栏 +// DocPicture docPicture = paragraph.appendPicture(imgPath); +// docPicture.setWidth(220f); +// docPicture.setHeight(180f); +// docPicture.setTextWrappingStyle(TextWrappingStyle.Top_And_Bottom); +// docPicture.setTextWrappingType(TextWrappingType.Both); +// }else { +// //图片为大图 单栏 +// DocPicture docPicture = paragraph.appendPicture(imgPath); +// docPicture.setWidth(500f); +// docPicture.setHeight(180f); +// docPicture.setTextWrappingStyle(TextWrappingStyle.Top_And_Bottom); +// docPicture.setTextWrappingType(TextWrappingType.Both); +// } +//// } +// +// } +// } +// +// } +// } +// 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("-", ""); +// +//// for (int i=0 ; i < paragraphs.size() ; i++){ +//// //System.out.println("内容为"+paragraphs.get(i).getRuns()); +//// List runs = paragraphs.get(i).getRuns(); +//// String replace = String.valueOf(runs).replace(",", "").replace(" ",""); +//// for (String pic: picNameList){ +//// if (replace.contains(picMap.get(pic).replace(",","").replace(" ",""))){ +//// //System.out.println("包含执行了"); +//// //获取光标 +//// XmlCursor xmlCursor = paragraphs.get(i+1).getCTP().newCursor(); +//// XWPFParagraph xwpfParagraph = newXdoc.insertNewParagraph(xmlCursor); +//// +//// XWPFRun run = xwpfParagraph.createRun(); +////// run.addBreak(BreakClear.ALL); +////// run.setText("{{@image}}"); +//// FileInputStream inputStream = new FileInputStream("C:\\Users\\yl\\Desktop\\pictures\\"+pic.replace("image","")); +//// run.addPicture2(inputStream,XWPFDocument.PICTURE_TYPE_JPEG,pic, Units.toEMU(500),Units.toEMU(180)); +//// // +//// } +//// } +//// +//// } +//// FileOutputStream os = new FileOutputStream(IMG_DIR+"New.doc"); +//// newXdoc.write(os); +// doc.saveToFile(IMG_DIR + randomFix + uuid+".docx"); +// //System.out.println("输出完毕"); +//// os.close(); +// fis.close(); +// newFis.close(); +// }catch (Exception e){ +// e.printStackTrace(); +// } +// return new ReturnValue(ReturnCodeAndMsgEnum.Success); +// } @ApiOperation(value = "存储上传过的文件名") @@ -1427,7 +1010,8 @@ public class TypesetController { } return new ReturnValue(ReturnCodeAndMsgEnum.Success, m); } - public String addPic1(String OldFileName,String newFileName){ + + public String addPic1(String OldFileName, String newFileName) { //1.操作初始文档获取图片 和 图片所在的位置 String filePath = ""; try { @@ -1444,13 +1028,19 @@ public class TypesetController { //准备一个Map key为图片名称,值为位置 HashMap picMap = new HashMap<>(); - String randomFix = String.valueOf(System.currentTimeMillis()) + "\\"; + 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++){ + for (int i = 0; i < list.size(); i++) { List imageBundleList = XWPFUtils.readImageInParagraph(list.get(i)); - if(CollectionUtils.isNotEmpty(imageBundleList)){ - for(String pictureId:imageBundleList){ + if (CollectionUtils.isNotEmpty(imageBundleList)) { + for (String pictureId : imageBundleList) { XWPFPictureData pictureData = xdoc.getPictureDataByID(pictureId); String imageName = pictureData.getFileName(); picNameList.add(imageName); @@ -1460,30 +1050,30 @@ public class TypesetController { // } // } lastParagraphText = list.get(i - 1).getParagraphText(); - if (StringUtils.isBlank(lastParagraphText)){ - for (int j = 2 ; j allPictures = xdoc.getAllPictures(); //遍历照片 // for (XWPFPictureData picture: allPictures) { byte[] data = pictureData.getData(); - File filePicture = new File(IMG_DIR + randomFix + imageName.replace("image","")); - if (!filePicture.exists()){ + File filePicture = new File(path + imageName.replace("image", "")); + if (!filePicture.exists()) { if (!filePicture.getParentFile().exists()) { filePicture.getParentFile().mkdirs(); } filePicture.createNewFile(); } FileOutputStream fileOutputStream = new FileOutputStream(filePicture); - fileOutputStream.write(data,0,data.length); + fileOutputStream.write(data, 0, data.length); fileOutputStream.close(); //System.out.println("执行结束了"); // } @@ -1504,19 +1094,19 @@ public class TypesetController { // //System.out.println("text=================>"+text); Paragraph para = sec.getParagraphs().get(0); // //System.out.println("para=================>"+para); - for(int i = 0; i < doc.getSections().getCount(); i++) { + for (int i = 0; i < doc.getSections().getCount(); i++) { Section section = doc.getSections().get(i); for (int j = 0; j < section.getParagraphs().getCount(); j++) { Paragraph paragraph = section.getParagraphs().get(j); // //System.out.println(j+"新方式内容"+paragraph.getText()); - for (String pic: picNameList) { + for (String pic : picNameList) { String replace = String.valueOf(paragraph.getText()).replace(",", "").replace(" ", ""); if (replace.contains(picMap.get(pic).replace(",", "").replace(" ", ""))) { // //System.out.println("包含"); - String imgPath = IMG_DIR + randomFix +pic.replace("image", ""); + String imgPath = IMG_DIR + randomFix + pic.replace("image", ""); - File picture=new File(imgPath); - BufferedImage sourceImg= ImageIO.read(new FileInputStream(picture)); + File picture = new File(imgPath); + BufferedImage sourceImg = ImageIO.read(new FileInputStream(picture)); int width = sourceImg.getWidth(); sourceImg.getHeight(); //System.out.println("图片长度"+width); @@ -1537,7 +1127,7 @@ public class TypesetController { // docPicture.setTextWrappingType(TextWrappingType.Both); // }else { //2.不包含 判断图片大小决定 图片为单栏还是双栏 - if (width <= 782f){ + if (width <= 782f) { //图片为小图 双栏 DocPicture docPicture = paragraph.appendPicture(imgPath); docPicture.setWidth(250f); @@ -1558,7 +1148,7 @@ public class TypesetController { //System.out.println("坐标位置为: X =" + x + " Y=" + y // + "\n 图片宽:"+ width1 + " 图片高:" + height // + "\n 图片的文字环绕方式:" + wrappingstyle + " 环绕文字类型:" + wrappingtype); - }else { + } else { //图片为大图 单栏 DocPicture docPicture = paragraph.appendPicture(imgPath); docPicture.setWidth(495f); @@ -1677,12 +1267,14 @@ public class TypesetController { // } // FileOutputStream os = new FileOutputStream(IMG_DIR+"New.doc"); // newXdoc.write(os); - doc.saveToFile(IMG_DIR + randomFix + uuid+".docx"); + + + doc.saveToFile(path + uuid + ".docx"); //System.out.println("输出完毕"); // os.close(); inputStream.close(); - filePath = randomFix + uuid+".docx"; + filePath = randomFix + uuid + ".docx"; // //处理角标 // File newFile = new File(filePath); // FileInputStream newFis = new FileInputStream(newFile); @@ -1777,10 +1369,9 @@ public class TypesetController { // } - // newFis.close(); - }catch (Exception e){ + } 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 b3ff8b6..944fe20 100644 --- a/src/main/java/com/example/ts_obj/entity/TypesetInfo.java +++ b/src/main/java/com/example/ts_obj/entity/TypesetInfo.java @@ -135,41 +135,6 @@ public class TypesetInfo implements Serializable { return traditon; } - @Override - public String toString() { - return "TypesetInfo{" + - "typesetInfoId=" + typesetInfoId + - ", typesetId=" + typesetId + - ", info_title='" + info_title + '\'' + - ", info_type='" + info_type + '\'' + - ", doi='" + doi + '\'' + - ", topic='" + topic + '\'' + - ", mainText='" + mainText + '\'' + - ", author='" + author + '\'' + - ", authorAddress='" + authorAddress + '\'' + - ", authorContribution='" + authorContribution + '\'' + - ", authorCorresponding='" + authorCorresponding + '\'' + - ", authorCorrespondingEmail='" + authorCorrespondingEmail + '\'' + - ", traditon='" + traditon + '\'' + - ", journal='" + journal + '\'' + - ", jabbr='" + jabbr + '\'' + - ", stage='" + stage + '\'' + - ", little_author='" + little_author + '\'' + - ", website='" + website + '\'' + - ", acknowledgment='" + acknowledgment + '\'' + - ", received_date='" + received_date + '\'' + - ", accepted_date='" + accepted_date + '\'' + - ", online_date='" + online_date + '\'' + - ", abbreviation='" + abbreviation + '\'' + - ", abstractText='" + abstractText + '\'' + - ", keywords='" + keywords + '\'' + - ", filename='" + filename + '\'' + - ", refers='" + refers + '\'' + - ", info_state=" + info_state + - ", userAccount='" + userAccount + '\'' + - '}'; - } - public String getUserAccount() { return userAccount; } @@ -334,4 +299,38 @@ public class TypesetInfo implements Serializable { this.abbreviation = abbreviation; } + @Override + public String toString() { + return "TypesetInfo{" + + "typesetInfoId=" + typesetInfoId + + ", typesetId=" + typesetId + + ", info_title='" + info_title + '\'' + + ", info_type='" + info_type + '\'' + + ", doi='" + doi + '\'' + + ", topic='" + topic + '\'' + + ", mainText='" + mainText + '\'' + + ", author='" + author + '\'' + + ", authorAddress='" + authorAddress + '\'' + + ", authorContribution='" + authorContribution + '\'' + + ", authorCorresponding='" + authorCorresponding + '\'' + + ", authorCorrespondingEmail='" + authorCorrespondingEmail + '\'' + + ", traditon='" + traditon + '\'' + + ", journal='" + journal + '\'' + + ", jabbr='" + jabbr + '\'' + + ", stage='" + stage + '\'' + + ", little_author='" + little_author + '\'' + + ", website='" + website + '\'' + + ", acknowledgment='" + acknowledgment + '\'' + + ", received_date='" + received_date + '\'' + + ", accepted_date='" + accepted_date + '\'' + + ", online_date='" + online_date + '\'' + + ", abbreviation='" + abbreviation + '\'' + + ", abstractText='" + abstractText + '\'' + + ", keywords='" + keywords + '\'' + + ", filename='" + filename + '\'' + + ", refers='" + refers + '\'' + + ", info_state=" + info_state + + ", userAccount='" + userAccount + '\'' + + '}'; + } } \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8dc36f9..911053f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 8080 + port: 8081 spring: datasource: