Ver código fonte

原文本显示新增xml显示

songxinlu 3 anos atrás
pai
commit
136759e448

+ 4 - 1
kernel/pom.xml

@@ -47,7 +47,10 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
-
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-thymeleaf</artifactId>
+        </dependency>
         <!-- LOGGING begin -->
         <!-- 代码直接调用commons-logging会被桥接到slf4j -->
         <dependency>

+ 54 - 0
kernel/src/main/java/com/lantone/qc/kernel/web/controller/XmlShowController.java

@@ -0,0 +1,54 @@
+package com.lantone.qc.kernel.web.controller;
+
+import com.lantone.qc.dbanaly.lt.entity.MedicalRecordContent;
+import com.lantone.qc.dbanaly.lt.service.MedicalRecordContentService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ * @Description:
+ * @author: rengb
+ * @time: 2021/12/17 14:05
+ */
+@Slf4j
+@Controller
+@RequestMapping("/xmlShow")
+public class XmlShowController {
+
+    @Autowired
+    private MedicalRecordContentService medicalRecordContentService;
+
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "dataType", value = "文书数据类型,html或者xml", required = true, paramType = "path", dataType = "String"),
+            @ApiImplicitParam(name = "recId", value = "文书记录编号", required = true, paramType = "path", dataType = "String")
+    })
+    @GetMapping("/dataShow/{dataType}/{recId}")
+    public String xmlDataShow(@PathVariable("recId") String recId, @PathVariable("dataType") String dataType, ModelMap model) {
+        MedicalRecordContent medicalRecordContent = medicalRecordContentService.getById(recId);
+        String xml = "";
+        if (dataType.equals("html")) {
+            xml = medicalRecordContent.getHtmlText().replaceAll("\r\n","")
+                    .replaceAll("\r","")
+                    .replaceAll("\n","");
+        } else if (dataType.equals("xml")) {
+            xml = medicalRecordContent.getXmlText().replaceAll("\r\n","")
+                    .replaceAll("\r","")
+                    .replaceAll("\n","");
+        } else {
+            xml = medicalRecordContent.getContentText().replaceAll("\r\n","")
+                    .replaceAll("\r","")
+                    .replaceAll("\n","");
+        }
+
+        model.addAttribute("xml_data", xml);
+        return "datashow";
+    }
+}

+ 6 - 0
kernel/src/main/resources/bootstrap.yml

@@ -11,6 +11,12 @@ spring:
       force: true
       charset: UTF-8
       enabled: true
+  thymeleaf:
+    cache: false
+  mvc:
+    static-path-pattern: /**
+  resources:
+    static-locations: classpath:/
   profiles:
     active: debug
 

Diferenças do arquivo suprimidas por serem muito extensas
+ 19 - 0
kernel/src/main/resources/static/jquery.min.js


+ 109 - 0
kernel/src/main/resources/templates/datashow.html

@@ -0,0 +1,109 @@
+<!doctype html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Xml网页格式化展示</title>
+<script type="text/javascript" src="/static/jquery.min.js"></script>
+<style>
+	body { margin:0; font-family:"微软雅黑"; font-size:12px; }
+	table textarea { width:100%; height:800px; }
+    #showXml {width:100%; height:800px; }
+</style>
+<script>
+	function showXml(){
+        text = '[[${xml_data}]]';
+        text = text.replace(/&lt;/g, "<").replace(/&gt;/g, ">")
+            .replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&apos;/g, "'");
+		//去掉多余的空格
+        text = '\n' + text.replace(/(<\w+)(\s.*?>)/g,function($0, name, props)
+        {
+            return name + ' ' + props.replace(/\s+(\w+=)/g," $1");
+        }).replace(/>\s*?</g,">\n<");
+ 
+        //把注释编码
+        text = text.replace(/\n/g,'\r').replace(/<!--(.+?)-->/g,function($0, text)
+        {
+            var ret = '<!--' + escape(text) + '-->';
+            return ret;
+        }).replace(/\r/g,'\n');
+ 
+        //调整格式
+        var rgx = /\n(<(([^\?]).+?)(?:\s|\s*?>|\s*?(\/)>)(?:.*?(?:(?:(\/)>)|(?:<(\/)\2>)))?)/mg;
+        var nodeStack = [];
+        var output = text.replace(rgx,function($0,all,name,isBegin,isCloseFull1,isCloseFull2 ,isFull1,isFull2){
+            var isClosed = (isCloseFull1 == '/') || (isCloseFull2 == '/' ) || (isFull1 == '/') || (isFull2 == '/');
+            var prefix = '';
+            if(isBegin == '!')
+            {
+                prefix = getPrefix(nodeStack.length);
+            }
+            else 
+            {
+                if(isBegin != '/')
+                {
+                    prefix = getPrefix(nodeStack.length);
+                    if(!isClosed)
+                    {
+                        nodeStack.push(name);
+                    }
+                }
+                else
+                {
+                    nodeStack.pop();
+                    prefix = getPrefix(nodeStack.length);
+                }
+ 
+            }
+                var ret =  '\n' + prefix + all;
+                return ret;
+        });
+ 
+        var prefixSpace = -1;
+        var outputText = output.substring(1);
+ 
+        //把注释还原并解码,调格式
+        outputText = outputText.replace(/\n/g,'\r').replace(/(\s*)<!--(.+?)-->/g,function($0, prefix,  text)
+        {
+            if(prefix.charAt(0) == '\r')
+                prefix = prefix.substring(1);
+            text = unescape(text).replace(/\r/g,'\n');
+            var ret = '\n' + prefix + '<!--' + text.replace(/^\s*/mg, prefix ) + '-->';
+            return ret;
+        });
+		
+		outputText=	outputText.replace(/\s+$/g,'').replace(/\r/g,'\r\n');
+		
+		$('#showXml').val(outputText);
+ 
+		//div内展示,需替换“<”以及“>”
+/*		var reg = new RegExp("<","g");//g,表示全部替换。
+		outputText = outputText.replace(reg,"<");
+		var reg2 = new RegExp(">","g");//g,表示全部替换。
+		outputText = outputText.replace(reg2,">");
+		$('#container').html(outputText);
+		alert(outputText);*/
+	
+    }
+	
+	function getPrefix(prefixIndex)
+    {
+        var span = '    ';
+        var output = [];
+        for(var i = 0 ; i < prefixIndex; ++i)
+        {
+            output.push(span);
+        }
+ 
+        return output.join('');
+    }     
+ 
+</script>
+</head>
+<body onload="showXml()">
+	
+    <div id="container">
+        <textarea id="showXml" ></textarea>
+    </div>
+    
+</body>
+</html>