瀏覽代碼

知识图谱和大数据推送结果合并

louhr 6 年之前
父節點
當前提交
463a86c235

+ 17 - 0
algorithm/pom.xml

@@ -38,6 +38,23 @@
     </dependencies>
 
     <build>
+        <resources>
+            <resource>
+                <directory>src/main/java</directory>
+                <includes>
+                    <include>**/*.properties</include>
+                    <include>**/*.xml</include>
+                    <include>**/*.json</include>
+                </includes>
+                <filtering>false</filtering>
+            </resource>
+            <resource>
+                <directory>src/main/resources</directory>
+                <includes>
+                    <include>**/*.*</include>
+                </includes>
+            </resource>
+        </resources>
         <finalName>algorithm</finalName>
     </build>
 </project>

+ 13 - 4
bigdata-web/pom.xml

@@ -10,7 +10,7 @@
 	</parent>
 	<groupId>org.diagbot</groupId>
 	<artifactId>bigdata-web</artifactId>
-	<version>0.0.1-SNAPSHOT</version>
+	<version>0.0.1</version>
 	<name>bigdata-web</name>
 	<description>bigdata push for diagbot</description>
 
@@ -57,7 +57,6 @@
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-test</artifactId>
-			<scope>test</scope>
 		</dependency>
 
         <dependency>
@@ -97,9 +96,19 @@
 
 	<build>
 		<plugins>
+			<!--<plugin>-->
+				<!--<groupId>org.springframework.boot</groupId>-->
+				<!--<artifactId>spring-boot-maven-plugin</artifactId>-->
+			<!--</plugin>-->
 			<plugin>
-				<groupId>org.springframework.boot</groupId>
-				<artifactId>spring-boot-maven-plugin</artifactId>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.8.0</version>
+				<configuration>
+					<compilerVersion>1.8</compilerVersion>
+					<source>1.8</source>
+					<target>1.8</target>
+				</configuration>
 			</plugin>
 		</plugins>
 

+ 4 - 4
bigdata-web/src/main/java/org/diagbot/bigdata/controller/AlgorithmController.java

@@ -1,8 +1,8 @@
 package org.diagbot.bigdata.controller;
 
 import org.diagbot.bigdata.work.AlgorithmCore;
-import org.diagbot.bigdata.work.BigDataSearchData;
 import org.diagbot.common.work.ResponseData;
+import org.diagbot.common.work.SearchData;
 import org.diagbot.nlp.util.Constants;
 import org.diagbot.pub.api.Response;
 import org.diagbot.pub.web.BaseController;
@@ -21,17 +21,17 @@ public class AlgorithmController extends BaseController {
 
     @RequestMapping(value = "/page_neural")
     @ResponseBody
-    public Response<ResponseData> neuralData(HttpServletRequest request, BigDataSearchData searchData) throws Exception {
+    public Response<ResponseData> neuralData(HttpServletRequest request, SearchData searchData) throws Exception {
         return algorithm(request, searchData);
     }
 
     @RequestMapping(value = "/neural", method = RequestMethod.POST)
     @ResponseBody
-    public Response<ResponseData> bayesPageData(HttpServletRequest request, @RequestBody BigDataSearchData searchData) throws Exception {
+    public Response<ResponseData> bayesPageData(HttpServletRequest request, @RequestBody SearchData searchData) throws Exception {
         return algorithm(request, searchData);
     }
 
-    public Response<ResponseData> algorithm(HttpServletRequest request, BigDataSearchData searchData) throws Exception {
+    public Response<ResponseData> algorithm(HttpServletRequest request, SearchData searchData) throws Exception {
         Response<ResponseData> response = new Response();
         AlgorithmCore core = new AlgorithmCore();
         ResponseData responseData = core.algorithm(request, searchData);

+ 12 - 7
bigdata-web/src/main/java/org/diagbot/bigdata/work/AlgorithmCore.java

@@ -5,7 +5,9 @@ import org.algorithm.factory.AlgorithmFactory;
 import org.algorithm.util.AlgorithmClassify;
 import org.diagbot.common.work.FeatureRate;
 import org.diagbot.common.work.ResponseData;
+import org.diagbot.common.work.SearchData;
 import org.diagbot.nlp.feature.FeatureType;
+import org.springframework.beans.BeanUtils;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.*;
@@ -18,15 +20,18 @@ import java.util.*;
  * @Version 1.0
  **/
 public class AlgorithmCore {
-    public ResponseData algorithm(HttpServletRequest request, BigDataSearchData searchData) throws Exception {
+    public ResponseData algorithm(HttpServletRequest request, SearchData searchData) throws Exception {
         ResponseData responseData = new ResponseData();
+        //对象拷贝至BigDataSearchData处理
+        BigDataSearchData bigDataSearchData = new BigDataSearchData();
+        BeanUtils.copyProperties(searchData, bigDataSearchData);
         //录入文本处理,包括提取特征、推送类型转换等
         ParamsDataProxy paramsDataProxy = new ParamsDataProxy();
-        paramsDataProxy.createSearchData(request, searchData);
-        responseData.setInputs(searchData.getInputs());
+        paramsDataProxy.createSearchData(request, bigDataSearchData);
+        responseData.setInputs(bigDataSearchData.getInputs());
         //推送模型类型集合
-        AlgorithmClassify[] classifies = searchData.getAlgorithmClassify();
-        String[] featureTypes = searchData.getFeatureTypes();
+        AlgorithmClassify[] classifies = bigDataSearchData.getAlgorithmClassify();
+        String[] featureTypes = bigDataSearchData.getFeatureTypes();
         //推送结果处理
         ResultDataProxy resultDataProxy = new ResultDataProxy();
         for (int i = 0; i < classifies.length; i++) {
@@ -37,7 +42,7 @@ public class AlgorithmCore {
             AlgorithmExecutor executor = AlgorithmFactory.getInstance(classifies[i]);
             Map<String, Float> featuresMap = null;
             if (executor != null) {
-                featuresMap = executor.execute(searchData.getInputs());;
+                featuresMap = executor.execute(bigDataSearchData.getInputs());;
             }
             List<Map.Entry<String, Float>> featuresOrderList = null;
             if (featuresMap == null) {
@@ -61,7 +66,7 @@ public class AlgorithmCore {
                     }
                 });
             }
-            List<FeatureRate> featureRates = resultDataProxy.proxy(request, searchData, featuresOrderList, featureTypes[i]);
+            List<FeatureRate> featureRates = resultDataProxy.proxy(request, bigDataSearchData, featuresOrderList, featureTypes[i]);
 
 
             switch (FeatureType.parse(featureTypes[i])) {

+ 1 - 11
bigdata-web/src/main/java/org/diagbot/bigdata/work/BigDataSearchData.java

@@ -6,8 +6,6 @@ import org.diagbot.common.work.SearchData;
 public class BigDataSearchData extends SearchData {
     //模型
     private AlgorithmClassify algorithmClassify[];
-    //模型
-    private String algorithmClassifyValue;
 
     public AlgorithmClassify[] getAlgorithmClassify() {
         return algorithmClassify;
@@ -16,12 +14,4 @@ public class BigDataSearchData extends SearchData {
     public void setAlgorithmClassify(AlgorithmClassify[] algorithmClassify) {
         this.algorithmClassify = algorithmClassify;
     }
-
-    public String getAlgorithmClassifyValue() {
-        return algorithmClassifyValue;
-    }
-
-    public void setAlgorithmClassifyValue(String algorithmClassifyValue) {
-        this.algorithmClassifyValue = algorithmClassifyValue;
-    }
-}
+}

+ 3 - 1
bigdata-web/src/main/java/org/diagbot/bigdata/work/ResultDataProxy.java

@@ -6,6 +6,7 @@ import org.diagbot.bigdata.dao.model.ResultMappingFilter;
 import org.diagbot.bigdata.util.BigDataConstants;
 import org.diagbot.common.work.FeatureRate;
 import org.diagbot.nlp.feature.FeatureType;
+import org.diagbot.nlp.util.NlpCache;
 
 import javax.servlet.http.HttpServletRequest;
 import java.text.DecimalFormat;
@@ -91,7 +92,8 @@ public class ResultDataProxy {
     }
 
     public Map<String, Float> synonymConvert(HttpServletRequest request, Map<String, Float> map) {
-        Map<String, String> standardInfoSynonymMap = (Map<String, String>) request.getServletContext().getAttribute(BigDataConstants.standard_info_synonym_cache);
+//        Map<String, String> standardInfoSynonymMap = (Map<String, String>) request.getServletContext().getAttribute(BigDataConstants.standard_info_synonym_cache);
+        Map<String, String> standardInfoSynonymMap = NlpCache.getStandard_info_synonym_map();
         Map<String, Float> result = new HashMap<>();
         String synonym = "";
         for (Map.Entry<String, Float> entry : map.entrySet()) {

+ 24 - 0
common-service/pom.xml

@@ -25,6 +25,30 @@
             <artifactId>public</artifactId>
             <version>1.0.0</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+            <version>2.1.1.RELEASE</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <version>2.1.1.RELEASE</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.mybatis</groupId>
+            <artifactId>mybatis</artifactId>
+            <version>3.4.6</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.mybatis</groupId>
+            <artifactId>mybatis-spring</artifactId>
+            <version>1.3.1</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 2 - 2
bigdata-web/src/main/java/org/diagbot/bigdata/config/MybatisConfiguration.java

@@ -1,4 +1,4 @@
-package org.diagbot.bigdata.config;
+package org.diagbot.common.config;
 
 import com.alibaba.druid.pool.DruidDataSource;
 import org.apache.ibatis.session.SqlSessionFactory;
@@ -21,7 +21,7 @@ import javax.sql.DataSource;
  **/
 
 @Configuration
-@MapperScan({"org.diagbot.bigdata.dao.mapper", "org.diagbot.common.dao.mapper"})
+@MapperScan({"org.diagbot.*.dao.mapper"})
 public class MybatisConfiguration {
     @Bean
     public SqlSessionFactory sqlSessionFactory() throws Exception {

+ 11 - 0
common-service/src/main/java/org/diagbot/common/work/SearchData.java

@@ -30,6 +30,9 @@ public class SearchData {
     protected String past = "";
     protected String other = "";
 
+    //模型
+    protected String algorithmClassifyValue;
+
     private Map<String, Map<String, String>> inputs = new HashMap<>(10, 0.8f);
 
     public List<LisDetail> getLisArr() {
@@ -181,4 +184,12 @@ public class SearchData {
     public void setOther(String other) {
         this.other = other;
     }
+
+    public String getAlgorithmClassifyValue() {
+        return algorithmClassifyValue;
+    }
+
+    public void setAlgorithmClassifyValue(String algorithmClassifyValue) {
+        this.algorithmClassifyValue = algorithmClassifyValue;
+    }
 }

+ 13 - 4
graph-web/pom.xml

@@ -10,7 +10,7 @@
 	</parent>
 	<groupId>org.diagbot</groupId>
 	<artifactId>graph-web</artifactId>
-	<version>0.0.1-SNAPSHOT</version>
+	<version>0.0.1</version>
 	<name>graph-web</name>
 	<description>Demo project for Spring Boot</description>
 
@@ -47,7 +47,6 @@
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-test</artifactId>
-			<scope>test</scope>
 		</dependency>
 
 		<dependency>
@@ -70,9 +69,19 @@
 
 	<build>
 		<plugins>
+			<!--<plugin>-->
+				<!--<groupId>org.springframework.boot</groupId>-->
+				<!--<artifactId>spring-boot-maven-plugin</artifactId>-->
+			<!--</plugin>-->
 			<plugin>
-				<groupId>org.springframework.boot</groupId>
-				<artifactId>spring-boot-maven-plugin</artifactId>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.8.0</version>
+				<configuration>
+					<compilerVersion>1.8</compilerVersion>
+					<source>1.8</source>
+					<target>1.8</target>
+				</configuration>
 			</plugin>
 		</plugins>
 

+ 0 - 43
nlp-web/src/main/java/org/diagbot/nlp/config/MybatisConfiguration.java

@@ -1,43 +0,0 @@
-package org.diagbot.nlp.config;
-
-import com.alibaba.druid.pool.DruidDataSource;
-import com.github.pagehelper.PageHelper;
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.mybatis.spring.SqlSessionFactoryBean;
-import org.mybatis.spring.annotation.MapperScan;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.core.io.support.ResourcePatternResolver;
-
-import javax.sql.DataSource;
-import java.util.Properties;
-
-/**
- *@ClassName org.diagbot.nlp.config.MybatisConfiguration
- *@Description Spring 配置
- *@Author fyeman
- *@Date 2019/1/11/011 10:07
- *@Version 1.0
- **/
-
-@Configuration
-@MapperScan({"org.diagbot.nlp.dao.mapper", "org.diagbot.common.dao.mapper"})
-public class MybatisConfiguration {
-    @Bean
-    public SqlSessionFactory sqlSessionFactory() throws Exception {
-        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
-        sqlSessionFactoryBean.setDataSource(dataSource());
-        // 设置mybatis的主配置文件
-        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
-        sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath*:org/diagbot/*/dao/xml/*.xml"));
-        return sqlSessionFactoryBean.getObject();
-    }
-
-    @Bean
-    @ConfigurationProperties(prefix = "spring.datasource")
-    public DataSource dataSource(){
-        return new DruidDataSource();
-    }
-}

+ 17 - 0
nlp/pom.xml

@@ -35,6 +35,23 @@
     </dependencies>
 
     <build>
+        <resources>
+            <resource>
+                <directory>src/main/java</directory>
+                <includes>
+                    <include>**/*.properties</include>
+                    <include>**/*.xml</include>
+                    <include>**/*.json</include>
+                </includes>
+                <filtering>false</filtering>
+            </resource>
+            <resource>
+                <directory>src/main/resources</directory>
+                <includes>
+                    <include>**/*.*</include>
+                </includes>
+            </resource>
+        </resources>
         <finalName>nlp</finalName>
     </build>
 </project>

+ 21 - 0
nlp/src/main/java/org/diagbot/nlp/util/NlpCache.java

@@ -35,4 +35,25 @@ public class NlpCache {
         Configuration configuration = new DefaultConfig();
         standard_info_classify_map = configuration.loadMapDict("classify.dict");
     }
+
+    public static Segment getSegment_cache() {
+        if (segment_cache == null) {
+            createSegmentCache();
+        }
+        return segment_cache;
+    }
+
+    public static Map<String, String> getStandard_info_synonym_map() {
+        if (standard_info_synonym_map == null) {
+            createSynonymCache();
+        }
+        return standard_info_synonym_map;
+    }
+
+    public static Map<String, String> getStandard_info_classify_map() {
+        if (standard_info_classify_map == null) {
+            createClassifyCache();
+        }
+        return standard_info_classify_map;
+    }
 }

+ 1 - 12
pom.xml

@@ -47,18 +47,6 @@
             <version>${mysql.version}</version>
         </dependency>
 
-        <dependency>
-            <groupId>org.mybatis</groupId>
-            <artifactId>mybatis</artifactId>
-            <version>${mybatis.version}</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.mybatis</groupId>
-            <artifactId>mybatis-spring</artifactId>
-            <version>1.2.2</version>
-        </dependency>
-
         <!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/sqljdbc4 -->
         <dependency>
             <groupId>com.microsoft.sqlserver</groupId>
@@ -310,6 +298,7 @@
                     <include>**/*.properties</include>
                     <include>**/*.xml</include>
                     <include>**/*.json</include>
+                    <include>**/*.dict</include>
                 </includes>
                 <filtering>false</filtering>
             </resource>

+ 117 - 0
public/src/main/java/org/diagbot/pub/utils/http/HttpApi.java

@@ -0,0 +1,117 @@
+package org.diagbot.pub.utils.http;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.util.EntityUtils;
+import org.codehaus.jackson.JsonParseException;
+import org.diagbot.pub.utils.mapper.JsonMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import java.net.ConnectException;
+
+
+/**
+ * 
+ * ClassName: HttpApi 
+ * Function: HTTP请求工具类 
+ * date: 2015年7月10日 下午10:50:24  
+ * 
+ * @author 楼辉荣(Fyeman) 
+ * @version 1.0 
+ * @since JDK 1.7
+ */
+@Component
+public class HttpApi<T> {
+	private static Logger log = LoggerFactory.getLogger(HttpApi.class);
+
+	/**
+	 * Description : HttpPost方式访问远程URL
+	 * 
+	 * @param httpUrl
+	 *            URL
+	 * @param obj
+	 *            post方式传入参数对象
+	 * @param type
+	 *            返回Json构造对象类
+	 * @return post访问返回数据对象
+	 */
+	@SuppressWarnings({ "deprecation", "unused" })
+	public T doPost(String httpUrl, Object obj, Class<T> type) throws ConnectException, Exception {
+		JsonMapper mapper = JsonMapper.nonEmptyMapper();
+		try {
+			/* post向服务器请求数据 */
+			HttpPost httppost = new HttpPost(httpUrl);
+			if (obj != null) {
+				String post = mapper.toJson(obj);
+				log.info("开始发起远程请求Param String:" + post);
+				StringEntity se = new StringEntity(post, HTTP.UTF_8);
+				se.setContentType("application/json");
+				se.setContentEncoding("utf-8");
+				httppost.setEntity(se);
+			}
+
+			CloseableHttpResponse response = HttpConnectionManager.getHttpClient().execute(httppost, HttpClientContext.create());
+			int code = response.getStatusLine().getStatusCode();
+			HttpEntity entity = response.getEntity();
+			String receive = EntityUtils.toString(entity, "UTF-8").trim();
+			log.info("服务器返回Response String:" + receive);
+			return mapper.fromJson(receive, type);
+		} catch (ConnectException connException) {
+			throw connException;
+		} catch (JsonParseException jsonException) {
+			throw new Exception("Json映射对象错误!----" + jsonException.getMessage(), jsonException);
+		} catch (Exception e) {
+			throw new Exception("远程服务器调用接口失败!----" + e.getMessage(), e);
+		}
+
+	}
+	
+	/**
+	 * Description : HttpPost方式访问远程URL
+	 * 
+	 * @param httpUrl
+	 *            URL
+	 * @param obj
+	 *            post方式传入参数对象
+	 * @param type
+	 *            返回Json构造对象类
+	 * @return post访问返回数据对象
+	 */
+	@SuppressWarnings({ "deprecation", "unused" })
+	public T doPostReplace(String httpUrl, Object obj, Class<T> type) throws ConnectException, Exception {
+		JsonMapper mapper = JsonMapper.nonEmptyMapper();
+		try {
+			/* post向服务器请求数据 */
+			HttpPost httppost = new HttpPost(httpUrl);
+			if (obj != null) {
+				String post = mapper.toJson(obj);
+				log.info("开始发起远程请求Param String:" + post);
+				StringEntity se = new StringEntity(post, HTTP.UTF_8);
+				se.setContentType("application/json");
+				se.setContentEncoding("utf-8");
+				httppost.setEntity(se);
+			}
+
+			CloseableHttpResponse response = HttpConnectionManager.getHttpClient().execute(httppost, HttpClientContext.create());
+			int code = response.getStatusLine().getStatusCode();
+			HttpEntity entity = response.getEntity();
+			String receive = EntityUtils.toString(entity, "UTF-8").trim();
+			log.info("服务器返回Response String:" + receive);			
+			receive=receive.replace("\\\"", "\"").replace("\"[{", "[{").replace("}]\"", "}]").replace("\"{", "{").replace("}\"", "}").replace("\"data\":\"[]\"", "\"data\":null");			
+			return mapper.fromJson(receive, type);
+		} catch (ConnectException connException) {
+			throw connException;
+		} catch (JsonParseException jsonException) {
+			throw new Exception("Json映射对象错误!----" + jsonException.getMessage(), jsonException);
+		} catch (Exception e) {
+			throw new Exception("远程服务器调用接口失败!----" + e.getMessage(), e);
+		}
+
+	}
+}

+ 79 - 0
public/src/main/java/org/diagbot/pub/utils/http/HttpConnectionManager.java

@@ -0,0 +1,79 @@
+package org.diagbot.pub.utils.http;
+
+import java.io.IOException;
+
+import org.apache.http.HttpHost;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ * ClassName: HttpConnectionManager 
+ * Function: HTTP连接池 
+ * date: 2015年7月10日 下午10:50:48  
+ * 
+ * @author 楼辉荣(Fyeman) 
+ * @version 1.0 
+ * @since JDK 1.7
+ */
+public class HttpConnectionManager {
+	private static Logger log = LoggerFactory.getLogger(HttpConnectionManager.class);
+	private static PoolingHttpClientConnectionManager cm;
+	static {
+		try {
+			cm = new PoolingHttpClientConnectionManager();
+		    // 将最大连接数增加到200
+		    cm.setMaxTotal(200);
+		    // 将每个路由基础的连接增加到20
+		    cm.setDefaultMaxPerRoute(20);
+		    //将目标主机的最大连接数增加到50
+		    HttpHost localhost = new HttpHost("http://115.28.138.12", 7070);
+		    cm.setMaxPerRoute(new HttpRoute(localhost), 50);
+		} catch (Exception e) {
+			log.error("初始化HTTP连接池出错", e);
+		}
+	}
+
+	/**
+	 * 
+	 * @Title: getHttpClient
+	 * @Description: HTTP链接池返回空闲链接
+	 * 
+	 * @author 楼辉荣(Fyeman) 
+	 * @return 
+	 * @since JDK 1.7
+	 */
+	public static CloseableHttpClient getHttpClient() throws Exception {
+		try {
+			CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).build();
+			return httpClient;
+		} catch (Exception e) {
+			log.error("获取CloseableHttpClient出错", e);
+			throw e;
+		}
+	}
+	
+	/**
+	 * 
+	 * @Title: closeHttpClient
+	 * @Description: HTTP放回链接
+	 * 
+	 * @author 楼辉荣(Fyeman) 
+	 * @param httpClient 
+	 * @since JDK 1.7
+	 */
+	public static void closeHttpClient(CloseableHttpClient httpClient) throws IOException {
+		if (httpClient != null) {
+			try {
+				httpClient.close();
+			} catch (IOException ioe) {
+				log.error("关闭HTTP连接出错", ioe);
+				throw ioe;
+			}
+		}
+	}
+}

+ 175 - 0
public/src/main/java/org/diagbot/pub/utils/mapper/JsonMapper.java

@@ -0,0 +1,175 @@
+/**   
+* @Company: 杭州朗通信息技术有限公司 
+* @Department: 系统软件部 
+* @Description: 朗通智能辅助诊疗系统 
+* @Address: 浙江省杭州市西湖区西斗门路3号 天堂软件园D-7B 
+*/
+package org.diagbot.pub.utils.mapper;
+
+import java.io.IOException;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.util.JSONPObject;
+import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
+
+/**
+ * @Title: JsonMapper.java
+ * @Package com.lantone.core.utils.mapper
+ * @Description: 简单封装Jackson,实现JSON String<->Java Object的Mapper,封装不同的输出风格,
+ *               使用不同的builder函数创建实例
+ * @author 楼辉荣(Fyeman)
+ * @date 2015年4月23日 下午11:58:46
+ * @version V1.0
+ */
+@SuppressWarnings("unchecked")
+public class JsonMapper {
+
+	private static Logger logger = LoggerFactory.getLogger(JsonMapper.class);
+
+	private ObjectMapper mapper;
+
+	public JsonMapper() {
+		this(null);
+	}
+
+	public JsonMapper(Include include) {
+		mapper = new ObjectMapper();
+		// 设置输出时包含属性的风格
+		if (include != null) {
+			mapper.setSerializationInclusion(include);
+		}
+		// 设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性
+		mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+	}
+
+	/**
+	 * 创建只输出非Null且非Empty(如List.isEmpty)的属性到Json字符串的Mapper,建议在外部接口中使用.
+	 */
+	public static JsonMapper nonEmptyMapper() {
+		return new JsonMapper(Include.NON_EMPTY);
+	}
+
+	/**
+	 * 创建只输出初始值被改变的属性到Json字符串的Mapper, 最节约的存储方式,建议在内部接口中使用。
+	 */
+	public static JsonMapper nonDefaultMapper() {
+		return new JsonMapper(Include.NON_DEFAULT);
+	}
+
+	/**
+	 * Object可以是POJO,也可以是Collection或数组。 如果对象为Null, 返回"null". 如果集合为空集合, 返回"[]".
+	 */
+	public String toJson(Object object) {
+
+		try {
+			return mapper.writeValueAsString(object);
+		} catch (IOException e) {
+			logger.warn("write to json string error:" + object, e);
+			return null;
+		}
+	}
+
+	/**
+	 * 反序列化POJO或简单Collection如List<String>.
+	 * 
+	 * 如果JSON字符串为Null或"null"字符串, 返回Null. 如果JSON字符串为"[]", 返回空集合.
+	 * 
+	 * 如需反序列化复杂Collection如List<MyBean>, 请使用fromJson(String,JavaType)
+	 * 
+	 * @see #fromJson(String, JavaType)
+	 */
+	public <T> T fromJson(String jsonString, Class<T> clazz) {
+		if (StringUtils.isEmpty(jsonString)) {
+			return null;
+		}
+
+		try {
+			return mapper.readValue(jsonString, clazz);
+		} catch (IOException e) {
+			logger.warn("parse json string error:" + jsonString, e);
+			return null;
+		}
+	}
+
+	/**
+	 * 反序列化复杂Collection如List<Bean>, 先使用函數createCollectionType构造类型,然后调用本函数.
+	 * 
+	 * @see #createCollectionType(Class, Class...)
+	 */
+	public <T> T fromJson(String jsonString, JavaType javaType) {
+		if (StringUtils.isEmpty(jsonString)) {
+			return null;
+		}
+
+		try {
+			return (T) mapper.readValue(jsonString, javaType);
+		} catch (IOException e) {
+			logger.warn("parse json string error:" + jsonString, e);
+			return null;
+		}
+	}
+
+	/**
+	 * 構造泛型的Collection Type如: ArrayList<MyBean>,
+	 * 则调用constructCollectionType(ArrayList.class,MyBean.class)
+	 * HashMap<String,MyBean>, 则调用(HashMap.class,String.class, MyBean.class)
+	 */
+	public JavaType createCollectionType(Class<?> collectionClass, Class<?>... elementClasses) {
+		return mapper.getTypeFactory().constructParametricType(collectionClass, elementClasses);
+	}
+
+	/**
+	 * 當JSON裡只含有Bean的部分屬性時,更新一個已存在Bean,只覆蓋該部分的屬性.
+	 */
+	public <T> T update(String jsonString, T object) {
+		try {
+			return (T) mapper.readerForUpdating(object).readValue(jsonString);
+		} catch (JsonProcessingException e) {
+			logger.warn("update json string:" + jsonString + " to object:" + object + " error.", e);
+		} catch (IOException e) {
+			logger.warn("update json string:" + jsonString + " to object:" + object + " error.", e);
+		}
+		return null;
+	}
+
+	/**
+	 * 輸出JSONP格式數據.
+	 */
+	public String toJsonP(String functionName, Object object) {
+		return toJson(new JSONPObject(functionName, object));
+	}
+
+	/**
+	 * 設定是否使用Enum的toString函數來讀寫Enum, 為False時時使用Enum的name()函數來讀寫Enum, 默認為False.
+	 * 注意本函數一定要在Mapper創建後, 所有的讀寫動作之前調用.
+	 */
+	public void enableEnumUseToString() {
+		mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
+		mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
+	}
+
+	/**
+	 * 支持使用Jaxb的Annotation,使得POJO上的annotation不用与Jackson耦合。
+	 * 默认会先查找jaxb的annotation,如果找不到再找jackson的。
+	 */
+	public void enableJaxbAnnotation() {
+		JaxbAnnotationModule module = new JaxbAnnotationModule();
+		mapper.registerModule(module);
+	}
+
+	/**
+	 * 取出Mapper做进一步的设置或使用其他序列化API.
+	 */
+	public ObjectMapper getMapper() {
+		return mapper;
+	}
+}

+ 70 - 7
push-web/pom.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
 	<parent>
 		<groupId>org.springframework.boot</groupId>
@@ -10,12 +10,18 @@
 	</parent>
 	<groupId>org.diagbot</groupId>
 	<artifactId>push-web</artifactId>
-	<version>0.0.1-SNAPSHOT</version>
+	<version>0.0.1</version>
 	<name>push-web</name>
 	<description>Demo project for Spring Boot</description>
 
 	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 		<java.version>1.8</java.version>
+		<druid.version>1.0.23</druid.version>
+		<mybatis.version>1.1.1</mybatis.version>
+		<mysql.version>5.1.38</mysql.version>
+		<swagger2.version>2.7.0</swagger2.version>
 	</properties>
 
 	<dependencies>
@@ -25,6 +31,36 @@
 			<version>1.0.0</version>
 		</dependency>
 
+		<dependency>
+			<groupId>org.diagbot</groupId>
+			<artifactId>algorithm</artifactId>
+			<version>1.0.0</version>
+		</dependency>
+
+		<dependency>
+			<groupId>org.diagbot</groupId>
+			<artifactId>nlp</artifactId>
+			<version>1.0.0</version>
+		</dependency>
+
+		<dependency>
+			<groupId>org.diagbot</groupId>
+			<artifactId>common-service</artifactId>
+			<version>1.0.0</version>
+		</dependency>
+
+		<dependency>
+			<groupId>org.diagbot</groupId>
+			<artifactId>bigdata-web</artifactId>
+			<version>0.0.1</version>
+		</dependency>
+
+		<dependency>
+			<groupId>org.diagbot</groupId>
+			<artifactId>graph-web</artifactId>
+			<version>0.0.1</version>
+		</dependency>
+
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-web</artifactId>
@@ -33,13 +69,40 @@
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-test</artifactId>
-			<scope>test</scope>
 		</dependency>
 
 		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-devtools</artifactId>
-			<optional>true</optional>
+		<groupId>org.mybatis.spring.boot</groupId>
+		<artifactId>mybatis-spring-boot-starter</artifactId>
+		<version>1.3.2</version>
+		</dependency>
+		<!-- 分页插件 -->
+		<dependency>
+		<groupId>com.github.pagehelper</groupId>
+		<artifactId>pagehelper-spring-boot-starter</artifactId>
+		<version>1.2.5</version>
+		</dependency>
+
+		<dependency>
+		<groupId>mysql</groupId>
+		<artifactId>mysql-connector-java</artifactId>
+		<version>${mysql.version}</version>
+		</dependency>
+		<dependency>
+		<groupId>com.alibaba</groupId>
+		<artifactId>druid</artifactId>
+		<version>${druid.version}</version>
+		</dependency>
+
+		<dependency>
+			<groupId>io.springfox</groupId>
+			<artifactId>springfox-swagger2</artifactId>
+			<version>${swagger2.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>io.springfox</groupId>
+			<artifactId>springfox-swagger-ui</artifactId>
+			<version>${swagger2.version}</version>
 		</dependency>
 	</dependencies>
 
@@ -68,7 +131,7 @@
 				</includes>
 			</resource>
 		</resources>
-        <finalName>push-web</finalName>
+		<finalName>push-web</finalName>
 	</build>
 
 </project>

+ 1 - 1
push-web/src/main/java/org/diagbot/PushWebApplication.java

@@ -18,7 +18,7 @@ public class PushWebApplication {
 
 	@RequestMapping("/index")
 	public String index() {
-		return "/index.html";
+		return "index.html";
 	}
 }
 

+ 99 - 0
push-web/src/main/java/org/diagbot/push/controller/AlgorithmController.java

@@ -1,8 +1,23 @@
 package org.diagbot.push.controller;
 
+import org.diagbot.bigdata.work.AlgorithmCore;
+import org.diagbot.common.work.FeatureRate;
+import org.diagbot.common.work.ResponseData;
+import org.diagbot.common.work.SearchData;
+import org.diagbot.graphWeb.work.GraphCalculate;
+import org.diagbot.pub.api.Response;
+import org.diagbot.pub.utils.http.HttpApi;
 import org.diagbot.pub.web.BaseController;
 import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
 
 /**
  * @ClassName org.diagbot.push.controller.AlgorithmController
@@ -22,4 +37,88 @@ public class AlgorithmController extends BaseController {
     public String index() {
         return listView;
     }
+
+    @RequestMapping(value = "/page_neural")
+    @ResponseBody
+    public Response<ResponseData> neuralData(HttpServletRequest request, SearchData searchData) throws Exception {
+        return algorithm(request, searchData);
+    }
+
+    @RequestMapping(value = "/neural", method = RequestMethod.POST)
+    @ResponseBody
+    public Response<ResponseData> bayesPageData(HttpServletRequest request, @RequestBody SearchData searchData) throws Exception {
+        return algorithm(request, searchData);
+    }
+
+    public Response<ResponseData> algorithm(HttpServletRequest request, SearchData searchData) throws Exception {
+        Response<ResponseData> response = new Response();
+        //大数据推送
+        HttpApi<Response> api = new HttpApi<Response>();
+        // 根据hospitalCode从his获取所有疾病库信息
+        Response bigDataResponse = api.doPost("http://192.168.3.180:5001/bigdata-web/algorithm/neural", searchData,
+                Response.class);
+        LinkedHashMap bigDataLinkedHashMap = (LinkedHashMap) bigDataResponse.getData();
+        //转FeatureRate对象
+        ResponseData bigDataResponseData = map2ResponseData(bigDataLinkedHashMap);
+        //知识图谱推送
+        Response graphResponse = api.doPost("http://192.168.3.180:5003/graph-web/graph/push", searchData,
+                Response.class);
+        LinkedHashMap graphLinkedHashMap = (LinkedHashMap) graphResponse.getData();
+        //转FeatureRate对象
+        ResponseData graphResponseData = map2ResponseData(graphLinkedHashMap);
+        if (graphResponseData.getDis().size() > 0) {
+            List<FeatureRate> disFeatureRates = new ArrayList<>();
+            boolean isFind = false;
+            for (int i = 0; i < bigDataResponseData.getDis().size(); i++) {
+                FeatureRate bigdata_fr = bigDataResponseData.getDis().get(i);
+                isFind = false;
+                for (FeatureRate graph_fr : graphResponseData.getDis()) {
+                    if (bigdata_fr.getFeatureName().equals(graph_fr.getFeatureName())) {
+                        isFind = true;
+                    }
+                }
+                if (!isFind) {
+                    disFeatureRates.add(bigdata_fr);
+                }
+            }
+            List<FeatureRate> graphFeatureRates = graphResponseData.getDis();
+            graphFeatureRates.addAll(disFeatureRates);
+            //大数据推送疾病数据用知识图谱替换
+            bigDataResponseData.setDis(graphFeatureRates);
+        }
+        response.setData(bigDataResponseData);
+        return response;
+    }
+
+    private ResponseData map2ResponseData(LinkedHashMap bigDataLinkedHashMap) {
+        ResponseData responseData = new ResponseData();
+        if (bigDataLinkedHashMap.get("dis") != null) {
+            responseData.setDis(map2FeatureRates((List<LinkedHashMap<String, String>>)bigDataLinkedHashMap.get("dis")));
+        }
+        if (bigDataLinkedHashMap.get("symptom") != null) {
+            responseData.setSymptom(map2FeatureRates((List<LinkedHashMap<String, String>>)bigDataLinkedHashMap.get("symptom")));
+        }
+        if (bigDataLinkedHashMap.get("vitals") != null) {
+            responseData.setVitals(map2FeatureRates((List<LinkedHashMap<String, String>>)bigDataLinkedHashMap.get("vitals")));
+        }
+        if (bigDataLinkedHashMap.get("labs") != null) {
+            responseData.setLabs(map2FeatureRates((List<LinkedHashMap<String, String>>)bigDataLinkedHashMap.get("labs")));
+        }
+        if (bigDataLinkedHashMap.get("pacs") != null) {
+            responseData.setPacs(map2FeatureRates((List<LinkedHashMap<String, String>>)bigDataLinkedHashMap.get("pacs")));
+        }
+        return responseData;
+    }
+
+    private List<FeatureRate> map2FeatureRates(List<LinkedHashMap<String, String>> data) {
+        List<FeatureRate> featureRates = new ArrayList<>();
+        for (LinkedHashMap<String, String> map : data) {
+            FeatureRate fr = new FeatureRate();
+            fr.setFeatureName(map.get("featureName"));
+            fr.setRate(map.get("rate"));
+            fr.setExtraProperty(map.get("extraProperty"));
+            featureRates.add(fr);
+        }
+        return featureRates;
+    }
 }

+ 19 - 2
push-web/src/main/resources/application.yml

@@ -6,13 +6,30 @@ server:
 spring:
   application:
     name: /push-web    # 项目名称
-  view:
-    static-path-pattern: /static/**
   http:
     encoding:     # http编码
       force: true
       charset: UTF-8
       enabled: true
+  datasource:       # mybatis 配置,使用druid数据源
+      url: jdbc:mysql://192.168.2.235:3306/bigdata-web?useUnicode=true&characterEncoding=UTF-8
+      username: root
+      password: diagbot@20180822
+      type: com.alibaba.druid.pool.DruidDataSource
+      driver-class-name: com.mysql.jdbc.Driver
+      filters: stat
+      maxActive: 20
+      initialSize: 1
+      maxWait: 60000
+      minIdle: 1
+      timeBetweenEvictionRunsMillis: 60000
+      minEvictableIdleTimeMillis: 300000
+      validationQuery: select 'x'
+      testWhileIdle: true
+      testOnBorrow: false
+      testOnReturn: false
+      poolPreparedStatements: true
+      maxOpenPreparedStatements: 20
 
 logging:          # 日志
   level.root: info

+ 2 - 1
push-web/src/main/resources/static/dist/js/push.js

@@ -1,3 +1,4 @@
 var nlp_web_url = "http://localhost:5002/nlp-web";
 var bigdata_web_url = "http://localhost:5001/bigdata-web";
-var graph_web_url = "http://localhost:5003/graph-web";
+var graph_web_url = "http://localhost:5003/graph-web";
+var push_web_url = "http://localhost:5008/push-web";

+ 11 - 11
push-web/src/main/resources/static/pages/algorithm/list.html

@@ -343,18 +343,18 @@
     function bayesPage(resourceType) {
         var diag = $("#diag_id").val();
         if (diag == '') {
-            startDiag('/algorithm/page_neural', '#symptom_list', '1', resourceType, '11');
-            startDiag('/algorithm/page_neural', '#vital_list', '3', resourceType, '31');
-            startDiag('/algorithmp/age_neural', '#lis_list', '4', resourceType, '41');
-            startDiag('/algorithmp/page_neural', '#pacs_list', '5', resourceType, '51');
+//            startDiag('/algorithm/page_neural', '#symptom_list', '1', resourceType, '11');
+//            startDiag('/algorithm/page_neural', '#vital_list', '3', resourceType, '31');
+//            startDiag('/algorithm/page_neural', '#lis_list', '4', resourceType, '41');
+//            startDiag('/algorithm/page_neural', '#pacs_list', '5', resourceType, '51');
 
-            startDiagMapping('/algorithmp/page_neural', '#diag_list', '2', resourceType, '21');
+            startDiagMapping('/algorithm/page_neural', '#diag_list', '2', resourceType, '21');
         } else {
             $('#diag_list').html("");
-            startDiag('/algorithmp/page_neural', '#symptom_list', '1', resourceType, '111');
-            startDiag('/algorithmp/page_neural', '#vital_list', '3', resourceType, '131');
-            startDiag('/algorithmp/page_neural', '#lis_list', '4', resourceType, '141');
-            startDiag('/algorithmp/page_neural', '#pacs_list', '5', resourceType, '151');
+            startDiag('/algorithm/page_neural', '#symptom_list', '1', resourceType, '111');
+            startDiag('/algorithm/page_neural', '#vital_list', '3', resourceType, '131');
+            startDiag('/algorithm/page_neural', '#lis_list', '4', resourceType, '141');
+            startDiag('/algorithm/page_neural', '#pacs_list', '5', resourceType, '151');
 
 //            startDiag('page_neural', '#symptom_list', '6', resourceType, '111');
         }
@@ -378,7 +378,7 @@
                 {"data": "rate"}
             ],
             "ajax": {
-                "url": bigdata_web_url + url,
+                "url": push_web_url + url,
                 "data": function ( d ) {
                     d.featureType = featureType;
                     d.resourceType = resourceType;
@@ -468,7 +468,7 @@
                 {"data": "rate"}
             ],
             "ajax": {
-                "url": bigdata_web_url + url,
+                "url": push_web_url + url,
                 "data": function ( d ) {
                     d.featureType = featureType;
                     d.resourceType = resourceType;