Commit 046c6fdf authored by 廖旭伟's avatar 廖旭伟

修改接口文档,增加主页接口

parent 0421bb2c
...@@ -134,6 +134,12 @@ ...@@ -134,6 +134,12 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>2.0.8</version>
</dependency>
<dependency> <dependency>
<groupId>com.aspose.words</groupId> <groupId>com.aspose.words</groupId>
<artifactId>aspose-words</artifactId> <artifactId>aspose-words</artifactId>
......
...@@ -410,156 +410,18 @@ public class ExportDocUtil { ...@@ -410,156 +410,18 @@ public class ExportDocUtil {
//log.info("deletePathList:" + JSON.toJSONString(deletePathList)); //log.info("deletePathList:" + JSON.toJSONString(deletePathList));
} }
public static String createCheckBoxStrOther(Boolean checked, String label) {
StringBuilder sb = new StringBuilder();
if (checked) {
String ckHeader = "☑";
@SneakyThrows sb.append(ckHeader);
public static void main(String[] args) { } else {
//解析xml文档,修改非法的$表达式为合法 String ckHeader = "□";
File file = new File("E:\\pic\\doc\\临时占用城市道路申请表(样表).xml"); sb.append(ckHeader);
}
Document document = XmlUtil.readXML(file); sb.append(label);
return sb.toString();
List<NodeEntity> list = new ArrayList<>();
ExportDocUtil.parseXMLFile(list, "E:\\pic\\doc\\临时占用城市道路申请表(样表).xml");
//log.info(JSON.toJSONString(list));
//list.stream().filter(f -> "3".equals(f.get("NodeType")) && !"".equals(f.get("content"))).peek(item -> log.info(item.get("content"))).count();
ExportDocUtil.checkAndUpdateExpressionByDocument(document, list);
XmlUtil.toFile(document, "E:\\pic\\doc\\临时占用城市道路申请表(样表)修正.xml");
//System.out.println(XmlUtil.format(document));
// Map root = new HashMap();
// root.put(
// "doc",
// freemarker.ext.dom.NodeModel.parse(new File("the/path/of/the.xml")));
//
//
// String ckStr=" <#list><w:r>\n" +
// "\t\t\t\t\t\t\t\t\t\t<w:rPr>\n" +
// "\t\t\t\t\t\t\t\t\t\t\t<w:rFonts w:ascii=\"宋体\" w:h-ansi=\"宋体\"/>\n" +
// "\t\t\t\t\t\t\t\t\t\t\t<wx:font wx:val=\"宋体\"/>\n" +
// "\t\t\t\t\t\t\t\t\t\t</w:rPr>\n" +
// "\t\t\t\t\t\t\t\t\t\t<w:sym w:font=\"Wingdings 2\" w:char=\"0052\"/>\n" +
// "\t\t\t\t\t\t\t\t\t</w:r></#list>";
//
// XmlUtil.parseXml(ckStr);
//<#list columns as column>
// Document xml = XmlUtil.createXml();
// Element element = xml.createElement("#list");
// xml.appendChild(element);
// Element elementPr = xml.createElement("w:rPr");
// element.appendChild(elementPr);
//
// Element elementFonts = xml.createElement("w:rFonts");
// elementFonts.setAttribute("w:ascii","宋体");
// elementFonts.setAttribute("w:h-ansi","宋体");
// elementPr.appendChild(elementFonts);
// Element elementFont = xml.createElement("wx:font");
// elementFont.setAttribute("wx:val","宋体");
// elementPr.appendChild(elementFont);
// System.out.println(ExportDocUtil.getStringFromDocument(xml));
// System.out.println(XmlUtil.format(xml));
// System.out.println(XmlUtil.toStr(element,"utf-8",true,false));
// String imagepath="E:\\pic\\1.png";
//
// BufferedImage image = ImgUtil.read(imagepath);
//
// String png = ImgUtil.toBase64(image, "png");
//
// System.out.println(png);
//
// String path = "E:\\新建文件夹\\测试.doc";
//
//// String path = "E:\\pic\\doc\\附件1-四川省危险废物经营许可证申请表(补办)空白.xml";
////
// List<Map<String, String>> list = new ArrayList<>();
//
// ExportDocUtil.parseXMLFile(list, path);
//
// //查找w:binData的节点路径
//
// //1.
// String id = "";
// List<String> paths = new ArrayList<>();
// for (Map<String, String> map : list) {
// if ("w:binData".equals(map.get("TagName"))) {
// System.out.println("id:" + map.get("id"));
// System.out.println("parentId:" + map.get("parentId"));
// id = map.get("parentId");
// paths.add(map.get("TagName"));
// break;
// }
// }
// ExportDocUtil.getPath(paths, list, id);
// System.out.println(JSON.toJSONString(paths));
// Document document = XmlUtil.readXML(new File(path));
// NamespaceContext ns = ExportDocUtil.buildNsByDocument(document);
// paths = CollUtil.reverse(paths);
//
// String xpath = "/" + paths.stream().collect(Collectors.joining("/"));
//
// System.out.println("xpath:" + xpath);
//
// Node byXPath = (Node) XmlUtil.getByXPath(xpath, document, XPathConstants.NODE, ns);
// byXPath.setTextContent("${image1}");
//
// System.out.println(XmlUtil.toStr(document));
//System.out.println("xPath"+byXPath.setTextContent(););
// xpath="//*[name()='wordml://02000001.jpg']";
// document.getElementById()
//List<Element> nodeList = document.selectNodes(xpath).selectNodes("//w:tbl//w:tr//w:tc//w:p//w:r//w:t");
//DefaultNamespaceContext defaultNamespaceContext = DefaultNamespaceContext.create(document);
//通过dom xpath 获取节点值 并修改
//Element elementByXPath = XmlUtil.getRootElement(document).getElementsByTagName(document., "w:binData");
//System.out.println("xpath element:"+elementByXPath.getTextContent());
//System.out.println(JSON.toJSONString(list));
// File file = new File("E:\\pic\\doc\\doc.xml");
//
// Document document = XmlUtil.readXML(file);
//
// Element element = document.getDocumentElement();
//
// // 第一次调用,就是第一级,parent_id 就给空
// ExportDocUtil.parseElement(list,element,"");
//
// NodeList childNodes = document.getChildNodes();
// System.out.println("size:"+childNodes.getLength());
// for(int i=0;i<childNodes.getLength();i++){
// Node item = childNodes.item(i);
//
// if(!"".equals(item.getTextContent().trim())){
// //System.out.println(item.getNodeValue());
//
// System.out.println(item.getTextContent().trim());
// }
// }
} }
} }
...@@ -3,6 +3,9 @@ package com.mortals.xhx.common.utils; ...@@ -3,6 +3,9 @@ package com.mortals.xhx.common.utils;
//import com.aspose.words.Document; //import com.aspose.words.Document;
//import com.aspose.words.ImageSaveOptions; //import com.aspose.words.ImageSaveOptions;
//import com.aspose.words.SaveFormat; //import com.aspose.words.SaveFormat;
import com.aspose.words.Document;
import com.aspose.words.ImageSaveOptions;
import com.aspose.words.SaveFormat;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.util.DateUtils; import com.mortals.framework.util.DateUtils;
import freemarker.template.Configuration; import freemarker.template.Configuration;
...@@ -89,49 +92,48 @@ public class WordUtil { ...@@ -89,49 +92,48 @@ public class WordUtil {
} }
public static String convertWordToJPEG(String inputFile, String jpegPath) { public static String convertWordToJPEG(String inputFile, String jpegPath) {
// try { try {
// System.out.println(String.format("文件转换开始:%s", DateUtils.getCurrStrDateTime())); System.out.println(String.format("文件转换开始:%s", DateUtils.getCurrStrDateTime()));
// // 转换开始前时间 // 转换开始前时间
// long old = System.currentTimeMillis(); long old = System.currentTimeMillis();
// // 新建的PDF文件路径 // 新建的PDF文件路径
// File file = new File(jpegPath); File file = new File(jpegPath);
// //FileOutputStream os = new FileOutputStream(file); //FileOutputStream os = new FileOutputStream(file);
// // 要转换的word文档的路径 // 要转换的word文档的路径
// Document doc = new Document(inputFile); Document doc = new Document(inputFile);
//
// // 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换 // 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
// //doc.save(os, SaveFormat.JPEG); //doc.save(os, SaveFormat.JPEG);
//
//
//
// ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG); ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);
// options.setPrettyFormat(true); options.setPrettyFormat(true);
// options.setUseAntiAliasing(true); options.setUseAntiAliasing(true);
// options.setUseHighQualityRendering(true); options.setUseHighQualityRendering(true);
// int pageCount = doc.getPageCount(); int pageCount = doc.getPageCount();
//
// List<BufferedImage> imageList = new ArrayList<BufferedImage>(); List<BufferedImage> imageList = new ArrayList<BufferedImage>();
// for (int i = 0; i < pageCount; i++) { for (int i = 0; i < pageCount; i++) {
// OutputStream output = new ByteArrayOutputStream(); OutputStream output = new ByteArrayOutputStream();
// options.setPageIndex(i); options.setPageIndex(i);
// doc.save(output, options); doc.save(output, options);
// ImageInputStream imageInputStream = ImageIO.createImageInputStream(parse(output)); ImageInputStream imageInputStream = ImageIO.createImageInputStream(parse(output));
// imageList.add(ImageIO.read(imageInputStream)); imageList.add(ImageIO.read(imageInputStream));
// } }
//
// BufferedImage mergeImage = mergeImage(false, imageList); BufferedImage mergeImage = mergeImage(false, imageList);
//
// ImageIO.write(mergeImage, "png", file); ImageIO.write(mergeImage, "png", file);
// // 转换结束后时间 // 转换结束后时间
// long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
// //os.close(); //os.close();
// System.out.println("文件转换结束,共耗时:" + ((now - old) / 1000.0) + "秒"); System.out.println("文件转换结束,共耗时:" + ((now - old) / 1000.0) + "秒");
// return jpegPath; return jpegPath;
// } catch (Exception e) { } catch (Exception e) {
// e.printStackTrace(); e.printStackTrace();
// throw new AppException(String.format("文件转换异常!", e.getMessage())); throw new AppException(String.format("文件转换异常!", e.getMessage()));
// } }
return "";
} }
......
...@@ -21,6 +21,8 @@ import com.mortals.xhx.feign.device.IApiDeviceFeign; ...@@ -21,6 +21,8 @@ import com.mortals.xhx.feign.device.IApiDeviceFeign;
import com.mortals.xhx.feign.device.pdu.DevicePdu; import com.mortals.xhx.feign.device.pdu.DevicePdu;
import com.mortals.xhx.feign.rsp.ApiResp; import com.mortals.xhx.feign.rsp.ApiResp;
import com.mortals.xhx.module.home.pdu.HomeQueryPdu; import com.mortals.xhx.module.home.pdu.HomeQueryPdu;
import com.mortals.xhx.module.matter.model.MatterDatumEntity;
import com.mortals.xhx.module.matter.service.MatterDatumService;
import org.checkerframework.checker.units.qual.A; import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
...@@ -38,6 +40,8 @@ public class HomeController extends BaseJsonBodyController { ...@@ -38,6 +40,8 @@ public class HomeController extends BaseJsonBodyController {
private IApiBaseManagerFeign iApiBaseManagerFeign; private IApiBaseManagerFeign iApiBaseManagerFeign;
@Autowired @Autowired
private IApiDeviceFeign iApiDeviceFeign; private IApiDeviceFeign iApiDeviceFeign;
@Autowired
private MatterDatumService matterDatumService;
@PostMapping({"site/list"}) @PostMapping({"site/list"})
public Rest<Object> list() { public Rest<Object> list() {
...@@ -171,4 +175,30 @@ public class HomeController extends BaseJsonBodyController { ...@@ -171,4 +175,30 @@ public class HomeController extends BaseJsonBodyController {
ret.setMsg(model.get("message_info") == null ? "" : model.remove("message_info").toString()); ret.setMsg(model.get("message_info") == null ? "" : model.remove("message_info").toString());
return ret; return ret;
} }
/**
* 合成表单与模板
*/
@PostMapping(value = "mergeFormToDocx")
@UnAuth
public String mergeFormToDocx(@RequestBody MatterDatumEntity docFormVo) {
JSONObject jsonObject = new JSONObject();
try {
String paths = matterDatumService.mergeFormToDoc(docFormVo, getContext());
String[] vals = paths.split(";");
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
jsonObject.put("mergeDoc", vals[0]);
jsonObject.put("preview", vals[1]);
//todo 保存表单数据
// docFormVo.setCreateTime(new Date());
// docFormVo.setCreateUserId(getContextUserId(getContext()));
// docFormVo.setCreateUser("");
// docFormService.save(docFormVo, getContext());
} catch (Exception e) {
log.error("合成表单异常", e);
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
jsonObject.put(KEY_RESULT_MSG, super.convertException(e));
}
return jsonObject.toJSONString();
}
} }
package com.mortals.xhx.module.matter.service; package com.mortals.xhx.module.matter.service;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICRUDService; import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.matter.model.MatterDatumEntity; import com.mortals.xhx.module.matter.model.MatterDatumEntity;
/** /**
...@@ -11,4 +12,12 @@ import com.mortals.xhx.module.matter.model.MatterDatumEntity; ...@@ -11,4 +12,12 @@ import com.mortals.xhx.module.matter.model.MatterDatumEntity;
*/ */
public interface MatterDatumService extends ICRUDService<MatterDatumEntity,Long>{ public interface MatterDatumService extends ICRUDService<MatterDatumEntity,Long>{
/**
* 合成doc数据模板
* @param context
* @return
*/
String mergeFormToDoc(MatterDatumEntity docFormVo, Context context);
} }
\ No newline at end of file
...@@ -47,5 +47,4 @@ public class MatterDatumController extends BaseCRUDJsonBodyMappingController<Mat ...@@ -47,5 +47,4 @@ public class MatterDatumController extends BaseCRUDJsonBodyMappingController<Mat
super.init(model, context); super.init(model, context);
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment