From 362f93aff9b6d2162933b12a44a82219b3db5dbc Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Sat, 18 Jun 2022 14:23:22 +0800 Subject: [PATCH] =?UTF-8?q?webreaddoc=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ts_obj/controller/DataapiController.java | 4 +- .../ts_obj/controller/TypesetController.java | 256 +++--------------- .../example/ts_obj/entity/TypesetInfo.java | 96 ++++--- 3 files changed, 112 insertions(+), 244 deletions(-) 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 004a7cc..4e54804 100644 --- a/src/main/java/com/example/ts_obj/controller/DataapiController.java +++ b/src/main/java/com/example/ts_obj/controller/DataapiController.java @@ -27,8 +27,8 @@ public class DataapiController { private final static Logger logger = LoggerFactory.getLogger(DataapiController.class); - private String BASE_DIR="d:/upload/"; -// private String BASE_DIR = "/home/wwwroot/ts.tmrjournals.com/upload/"; +// private String BASE_DIR="d:/upload/"; + private String BASE_DIR = "/home/wwwroot/ts.tmrjournals.com/upload/"; /** * 模板生成work文档 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 721df28..5b1d993 100644 --- a/src/main/java/com/example/ts_obj/controller/TypesetController.java +++ b/src/main/java/com/example/ts_obj/controller/TypesetController.java @@ -1,5 +1,7 @@ package com.example.ts_obj.controller; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.example.ts_obj.Util.*; import com.spire.doc.*; import com.spire.doc.Document; @@ -60,11 +62,12 @@ public class TypesetController { private final static Logger logger = LoggerFactory.getLogger(UserController.class); - private String BASE_DIR="C:\\Users\\Administrator\\Desktop\\typesetcode\\upload\\"; + private String BASE_DIR="E:\\"; 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 Man_base_url = "/home/wwwroot/"; @Autowired private TypesetService typesetservice; @@ -202,156 +205,16 @@ 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(); 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 = ""; @@ -368,36 +231,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(); } @@ -723,16 +560,9 @@ public class TypesetController { @ApiOperation(value = "网上专用获取生成的docx") @PostMapping("/webGetDocx") - public ReturnValue webGetDocx(@RequestBody TypesetInfo typesetInfo,@RequestParam("filename") String filename) throws IOException { - - Long typesetId = typesetInfo.getTypesetId(); - Map m = typesetservice.getTypesetDetail(typesetId); + public ReturnValue webGetDocx(@RequestBody TypesetInfo typesetInfo) throws IOException { Map frag = new HashMap(); - Typeset t = (Typeset) m.get("info"); -// TypesetInfo typesetInfo = t.getU_typeset_info(); - List refList = (List) m.get("refers"); ZipSecureFile.setMinInflateRatio(-1.0d); - User user = userservice.getUser(t.getUserId()); HashMap map = new HashMap<>(); map.put("type", typesetInfo.getInfo_type().toUpperCase()); map.put("journaltitle", typesetInfo.getJournal()); @@ -761,25 +591,26 @@ 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()); - SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM yyyy", Locale.ENGLISH); - if (typesetInfo.getReceived_date().toString().equals("")) { +// 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()); - } else { - map.put("received_date", sdf.format(new Date(Long.valueOf(typesetInfo.getReceived_date())))); - } +// } // map.put("received_date",sdf.format(new Date(Long.valueOf(typesetInfo.getReceived_date())))); - if (typesetInfo.getAccepted_date().toString().equals("")) { +// if (typesetInfo.getAccepted_date().toString().equals("")) { +// map.put("accept_date", typesetInfo.getAccepted_date()); +// } else { map.put("accept_date", typesetInfo.getAccepted_date()); - } else { - map.put("accept_date", sdf.format(new Date(Long.valueOf(typesetInfo.getAccepted_date())))); - } +// } // map.put("accept_date",sdf.format(new Date(Long.valueOf(typesetInfo.getAccepted_date())))); - if (typesetInfo.getOnline_date().toString().equals("")) { +// if (typesetInfo.getOnline_date().toString().equals("")) { +// map.put("online_date", typesetInfo.getOnline_date()); +// } else { map.put("online_date", typesetInfo.getOnline_date()); - } else { - map.put("online_date", sdf.format(new Date(Long.valueOf(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())); @@ -788,20 +619,19 @@ public class TypesetController { ArrayList arrayList = new ArrayList<>(); - //读取原文件表格数据 - Document doc = new Document(); - doc.loadFromFile(this.BASE_DIR+filename); + InputStream inputStream = FileDownloadUtil.getInputStream(typesetInfo.getFilename()); + + Document doc = new Document(inputStream); 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); +// //保存文本 +// 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(); +// bw.flush(); +// bw.close(); +// fw.close(); // List list = new ArrayList<>(); @@ -876,7 +706,7 @@ public class TypesetController { } } - System.out.println("list===============>"+list); +// System.out.println("list===============>"+list); map.put("table", list); @@ -898,19 +728,23 @@ public class TypesetController { + //测试 + + JSONArray ja = (JSONArray) JSON.parse(typesetInfo.getRefers()); + List refsl = new ArrayList(); - for (TypesetInfoReference tif : refList) { - String tttt = tif.getRefer_title().replace("", "").replace("", "").replace("", "").replace("", "").trim().toUpperCase(); - if (tttt.equals("REFERENCE") || tttt.equals("REFERENCES")) { - continue; - } + 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(); chch.setFontFamily("Charis SIL"); chch.setFontSize(7.5); - String tgh_title = tif.getRefer_title().replace("", "").replace("", "").replace("", "").replace("", ""); + String tgh_title = String.valueOf(tif).replace("", "").replace("", "").replace("", "").replace("", ""); chc_pd.addText(new TextRenderData(tgh_title, chch)); refsl.add(chc_pd); } 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 dc92f0d..b3ff8b6 100644 --- a/src/main/java/com/example/ts_obj/entity/TypesetInfo.java +++ b/src/main/java/com/example/ts_obj/entity/TypesetInfo.java @@ -57,8 +57,14 @@ public class TypesetInfo implements Serializable { private String keywords; + private String filename; + + private String refers; + private Byte info_state; + private String userAccount; + private static final long serialVersionUID = 1L; public Long getTypesetInfoId() { @@ -129,6 +135,49 @@ 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; + } + + public void setUserAccount(String userAccount) { + this.userAccount = userAccount; + } + public void setTraditon(String traditon) { this.traditon = traditon; } @@ -145,6 +194,22 @@ public class TypesetInfo implements Serializable { return keywords; } + public String getFilename() { + return filename; + } + + public void setFilename(String filename) { + this.filename = filename; + } + + public String getRefers() { + return refers; + } + + public void setRefers(String refers) { + this.refers = refers; + } + public void setKeywords(String keywords) { this.keywords = keywords; } @@ -269,35 +334,4 @@ 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 + '\'' + - ", info_state=" + info_state + - '}'; - } } \ No newline at end of file