Browse Source

添加图谱的controller和response

kongwz 6 years ago
parent
commit
508ea97caf

+ 7 - 1
graph-web/pom.xml

@@ -50,7 +50,13 @@
 			<artifactId>druid</artifactId>
 			<artifactId>druid</artifactId>
 			<version>${druid.version}</version>
 			<version>${druid.version}</version>
 		</dependency>
 		</dependency>
-	</dependencies>
+        <dependency>
+            <groupId>org.diagbot</groupId>
+            <artifactId>graph</artifactId>
+            <version>1.0.0</version>
+            <scope>compile</scope>
+        </dependency>
+    </dependencies>
 
 
 	<build>
 	<build>
 		<plugins>
 		<plugins>

+ 166 - 0
graph-web/src/main/java/org/diagbot/graphWeb/controller/gdbcontroller.java

@@ -0,0 +1,166 @@
+package org.diagbot.graphWeb.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import org.diagbot.graph.jdbc.DriverManager;
+import org.diagbot.graph.jdbc.Neo4jAPI;
+import org.diagbot.graph.jdbc.Neo4jModel;
+import org.diagbot.graphWeb.dao.GdbResponse;
+import org.diagbot.graphWeb.dao.TestResponse;
+import org.diagbot.pub.api.Response;
+import org.diagbot.pub.web.BaseController;
+import org.neo4j.driver.v1.Driver;
+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.Map;
+
+@Controller
+@RequestMapping("/graphdb")
+public class gdbcontroller extends BaseController {
+    private Driver drive = null;
+    private Neo4jAPI n4api = null;
+
+    /**
+     * 诊断接口
+     * @param request
+     * @param bodyobj
+     * @return
+     * @throws Exception
+     */
+    @RequestMapping(value = "/condition", method = RequestMethod.POST)
+    @ResponseBody
+    public Response<GdbResponse> condition(HttpServletRequest request, @RequestBody JSONObject bodyobj) throws Exception {
+//        System.out.println(bodyobj.toJSONString());
+        Response<GdbResponse> response = ProcessCondition(request, bodyobj);
+        return response;
+    }
+    public Response<GdbResponse> ProcessCondition(HttpServletRequest request, JSONObject bodyobj) {
+        Response<GdbResponse> response = new Response<>();
+        GdbResponse gdbdata = new GdbResponse();
+        String name = null;
+//        Map<String,String> RSet = null;
+        Map<String,String> RSet = null;
+        String disease = null;
+        try {
+            if (drive == null) {
+                drive = DriverManager.newDrive();
+            }
+            if (drive != null && drive.session() != null) {
+                name = bodyobj.getString(Neo4jModel.name);
+                String[] keys = name.split(",|,|、");
+                n4api = new Neo4jAPI(drive);
+                RSet = n4api.getCondition(keys);
+            }
+            gdbdata.setResult(RSet);
+            response.setData(gdbdata);
+        }
+        catch (Exception ex) {
+            ex.printStackTrace();
+        } finally {
+            return response;
+        }
+    }
+
+    /**
+     * 一个或多个疾病下的治疗接口
+     * @param request
+     * @param bodyobj
+     * @return
+     * @throws Exception
+     */
+    @RequestMapping(value = "/multipleDiseaseTreat", method = RequestMethod.POST)
+    @ResponseBody
+    public Response<GdbResponse> multipleDiseaseTreat(HttpServletRequest request, @RequestBody JSONObject bodyobj) throws Exception {
+        Response<GdbResponse> response = processMulDiseaseTreat(request, bodyobj);
+        return response;
+    }
+
+    public Response<GdbResponse> processMulDiseaseTreat(HttpServletRequest request, JSONObject bodyobj) {
+        Response<GdbResponse> response = new Response<>();
+        GdbResponse gdbdata = new GdbResponse();
+        String diseases = null;
+        String filds = null;
+        ArrayList<String> strings = new ArrayList<>();
+        Map<String,String> RSet = null;
+        try {
+            if (drive == null) {
+                drive = DriverManager.newDrive();
+            }
+            if (drive != null && drive.session() != null) {
+                diseases = bodyobj.getString("disease");//疾病组合
+                filds = bodyobj.getString("filds");//其他组合(症状,体征结果,化验结果,检查结果,病史等)
+                n4api = new Neo4jAPI(drive);
+                RSet = n4api.getMulDiseaseTreat(diseases, filds);
+            }
+            gdbdata.setResult(RSet);
+            response.setData(gdbdata);
+        }catch (Exception e){
+            e.printStackTrace();
+        }finally {
+            return response;
+        }
+    }
+
+    /**
+     * 高危病接口
+     * @param request
+     * @param bodyobj
+     * @return
+     * @throws Exception
+     */
+    @RequestMapping(value = "/HighRisk", method = RequestMethod.POST)
+    @ResponseBody
+    public Response<GdbResponse> HighRisk(HttpServletRequest request, @RequestBody JSONObject bodyobj) throws Exception {
+        Response<GdbResponse> response = processHighRisk(request, bodyobj);
+        return response;
+    }
+    public Response<GdbResponse> processHighRisk(HttpServletRequest request, JSONObject bodyobj) {
+        Response<GdbResponse> response = new Response<>();
+        GdbResponse gdbdata = new GdbResponse();
+        String diseases = null;
+        Map<String,String> RSet = null;
+        try {
+            if (drive == null) {
+                drive = DriverManager.newDrive();
+            }
+            if (drive != null && drive.session() != null) {
+                diseases = bodyobj.getString("disease");//疾病
+                n4api = new Neo4jAPI(drive);
+                RSet = n4api.getHighRisk(diseases);
+            }
+            gdbdata.setResult(RSet);
+            response.setData(gdbdata);
+        }catch (Exception e){
+            e.printStackTrace();
+        }finally {
+            return response;
+        }
+    }
+
+    /**
+     * 自定义接口数据结构
+     * @param request
+     * @param bodyobj
+     * @return
+     * @throws Exception
+     */
+    @RequestMapping(value = "/HighRisk1", method = RequestMethod.POST)
+    @ResponseBody
+    public Response<TestResponse> HighRisk1(HttpServletRequest request, @RequestBody JSONObject bodyobj) throws Exception {
+        Response<TestResponse> response = new Response<TestResponse>();
+        TestResponse testResponse = new TestResponse();
+        String diseases = bodyobj.getString("disease");//疾病
+        JSONObject JS = new JSONObject();
+        JS.put("name","jack");
+        JS.put("hobby",new String[]{"swing","sing"});
+        testResponse.setResult(JS);
+        response.setData(testResponse);
+        return response;
+    }
+
+}

+ 28 - 0
graph-web/src/main/java/org/diagbot/graphWeb/dao/GdbResponse.java

@@ -0,0 +1,28 @@
+package org.diagbot.graphWeb.dao;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 图形数据库数据返回结构
+ * Created by Mark Huang on 2018/10/26.
+ */
+public class GdbResponse {
+    private Map<String, String> Result = new HashMap<>();
+    private String status = "unknown";
+
+    public Map<String, String> getResult() {
+        return Result;
+    }
+
+    public void setResult(Map<String, String> Result ) {
+        this.Result = Result;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) { this.status = status; }
+
+}

+ 127 - 0
graph-web/src/main/java/org/diagbot/graphWeb/dao/Parameters.java

@@ -0,0 +1,127 @@
+package org.diagbot.graphWeb.dao;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 通过Web接口调用API时输入的访问Neo4j的参数
+ * Created by Mark Huang on 2018/10/26.
+ */
+public class Parameters {
+    // 基本信息
+    private String uri = "";
+    private String port = "";
+    private String user = "";
+    private String password = "";
+
+    // 连接参数
+    private int ConnLifeTime = 30;
+    private int TransRetryTime = 5;
+    private int ConnPoolSize = 50;
+    private int ConnTimeout = 2;
+
+    // Node参数
+    private String Label = "";
+    private Map<String, String> Property = new HashMap<>();
+    private String Relation = "";
+
+    private Map<String, Map<String, String>> Node = new HashMap<>();
+
+
+    public String getURI() {
+        return uri;
+    }
+
+    public void setURI(String uri) {
+        this.uri = uri;
+    }
+
+    public String getPort() {
+        return port;
+    }
+
+    public void setPort(String port) {
+        this.port = port;
+    }
+
+    public String getUser() {
+        return user;
+    }
+
+    public void setUser(String user) {
+        this.user = user;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public int getConnLifeTime() {
+        return ConnLifeTime;
+    }
+
+    public void setConnLifeTime(int ConnLifeTime) {
+        this.ConnLifeTime = ConnLifeTime;
+    }
+
+    public int getTransRetryTime() {
+        return TransRetryTime;
+    }
+
+    public void setTransRetryTime(int TransRetryTime) {
+        this.TransRetryTime = TransRetryTime;
+    }
+
+    public int getConnPoolSize() {
+        return ConnPoolSize;
+    }
+
+    public void setConnPoolSize(int ConnPoolSize) {
+        this.ConnPoolSize = ConnPoolSize;
+    }
+
+    public int getConnTimeout() {
+        return ConnTimeout;
+    }
+
+    public void setConnTimeout(int ConnTimeout) {
+        this.ConnTimeout = ConnTimeout;
+    }
+
+    public String getLabel() {
+        return Label;
+    }
+
+    public void setLabel(String Label) {
+        this.Label = Label;
+    }
+
+    public Map<String, String> getProperty() {
+        return Property;
+    }
+
+    public void setProperty(Map<String, String> Property) {
+        this.Property = Property;
+    }
+
+    public String getRelation() {
+        return Relation;
+    }
+
+    public void setRelation(String Relation) {
+        this.Relation = Relation;
+    }
+
+    public Map<String, Map<String, String>> getNode() {
+        return Node;
+    }
+
+    public void setNode(Map<String, Map<String, String>> Property) {
+        this.Node = Node;
+    }
+
+}

+ 24 - 0
graph-web/src/main/java/org/diagbot/graphWeb/dao/TestResponse.java

@@ -0,0 +1,24 @@
+package org.diagbot.graphWeb.dao;
+
+import com.alibaba.fastjson.JSONObject;
+
+public class TestResponse {
+    private String status = "unknown";
+    private JSONObject Result=new JSONObject();
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public JSONObject getResult() {
+        return Result;
+    }
+
+    public void setResult(JSONObject js) {
+        this.Result = js;
+    }
+}