浏览代码

Merge branch 'push-test' of http://192.168.2.236:10080/louhr/push into push-test

louhr 5 年之前
父节点
当前提交
cb2aa317c8

+ 7 - 0
common-push/src/main/java/org/diagbot/common/push/filter/ClassifyDiag.java

@@ -223,6 +223,13 @@ public class ClassifyDiag {
                 String s = diagClassifyCache.get(dis);
                 if(s != null){
                     queAll.add(s);
+                    List<Object> key = this.getKey(diagClassifyCache, s);
+                    if(key.size()>0){
+                        for (Object o:key
+                             ) {
+                            queAll.add(o.toString());
+                        }
+                    }
                 }
                 queAll.add(dis);
                 List<Object> key = this.getKey(diagClassifyCache, dis);

+ 1 - 1
graph/src/main/resources/bolt.properties

@@ -5,7 +5,7 @@ pass_235 = diagbot@20180822
 
 # neo4j bolt credentials
 #\u7EBF\u4E0A\u4F7F\u7528
-bolt.uri=bolt://192.168.2.234
+bolt.uri=bolt://192.168.2.232
 bolt.user=neo4j
 bolt.passwd=root
 

+ 3 - 0
graphdb/src/main/java/org/diagbot/repository/DiseaseRepository.java

@@ -50,6 +50,9 @@ public interface DiseaseRepository extends Neo4jRepository<Disease, Long> {
     //删除排除关系10
     @Query("match(c:Condition) where c.name={0} detach delete c")
     void deleteRelation10(String conditionName);
+    //删除诊断
+    @Query("match(c:Disease) where c.disId={0} detach delete c")
+    void deleteRelation11(Long disId);
     //更新图谱
     //存储疾病
     @Query("merge(d:Disease{name:{0},disId:{1},emergency:{2}})")

+ 2 - 0
graphdb/src/main/java/org/diagbot/service/KnowledgeService.java

@@ -56,5 +56,7 @@ public interface KnowledgeService {
     RespDTO updateNeoDisease(NeoParamVO singleDisease);
     //删除图谱
     RespDTO deleteNeoDisease(NeoParamVO singleDisease);
+    //批量插入
+    RespDTO<Boolean> batchInsertDis();
 
 }

+ 136 - 58
graphdb/src/main/java/org/diagbot/service/impl/KnowledgeServiceImpl.java

@@ -55,16 +55,10 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
     private KnowledgeMapper knowledgeMapper;
 
     private List<BaseNode> baseNodes;
-
+    private String user = "root";
+    private String password = "lantone";
+    private String url = "jdbc:mysql://192.168.2.241:3306/med?useUnicode=true&characterEncoding=UTF-8";
     private Pageable pageable;
-    private Connection conn = null;
-    private MysqlJdbc nlpJdbc = new MysqlJdbc("root", "lantone", "jdbc:mysql://192.168.2.236:3306/med?useSSL=false&useUnicode=true&characterEncoding=UTF-8");
-    public Connection getConn(){
-        if(conn == null){
-            conn = nlpJdbc.connect();
-        }
-        return conn;
-    }
     /**
      * 处理症状节点相关的申请
      */
@@ -1412,6 +1406,12 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
         indicators1.setDetails(detailList1);
         return indicators1;
     }
+    //获取mysql链接
+    public Connection getConnect(){
+        MysqlJdbc mysqlJdbc = new MysqlJdbc(user, password, url);
+        Connection connect = mysqlJdbc.connect();
+        return connect;
+    }
 
     /**
      * 更新图谱
@@ -1421,22 +1421,35 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
      */
     @Override
     public RespDTO updateNeoDisease(NeoParamVO singleDisease) {
-        RespDTO respDTO = RespDTO.onSuc(true);;
+        RespDTO respDTO = RespDTO.onSuc(true);
+        RespDTO respDTO1 = null;
+        try {
+        Connection connect = getConnect();
         Long disId = singleDisease.getId();
+            //把数据库中的所有词读进map缓存
+        Map<String, Map<String, String>> ciKu = this.allStandWord2Map(connect);
+        respDTO1 = this.updateNeo(respDTO, disId,connect,ciKu);
+        connect.close();
+        } catch (SQLException e) {
+            e.printStackTrace();
+        }
+        return respDTO1;
+    }
+
+    public RespDTO updateNeo(RespDTO respDTO,Long disId,Connection connection, Map<String, Map<String, String>> ciKu){
         //先删除
-        this.neo4jDelete(disId);
-        String disName = this.getDisName(disId);
+        this.neo4jDelete(disId,connection);
+        String disName = this.getDisName(disId,connection);
         if(StringUtils.isNotEmpty(disName)){
             diseaseRepository.mergeDis(disName,disId,0);
         }else {
             respDTO = RespDTO.onError("在数据库中没有找到"+disId+"对应的疾病!!");
         }
-        //把数据库中的所有词读进map缓存
-        Map<String, Map<String, String>> ciKu = this.allStandWord2Map();
+
         //获取每个诊断依据的全部数据
-        List<Map<String, String>> allData = this.getAllData(disId);
+        List<Map<String, String>> allData = this.getAllData(disId,connection);
         //获取拟诊,确诊,警惕组合
-        Map<String, List<String>> allNiQueZhenCollection = this.getAllNiQueZhenCollection(disId);
+        Map<String, List<String>> allNiQueZhenCollection = this.getAllNiQueZhenCollection(disId,connection);
         this.saveNiQue2Neo(allData,allNiQueZhenCollection,disName,disId);
         this.saveData2Neo4j(allData,disId,disName,ciKu);
         return respDTO;
@@ -1447,15 +1460,14 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
      * @param disId
      * @return
      */
-    public List<Map<String,String>> getAllData(Long disId){
+    public List<Map<String,String>> getAllData(Long disId,Connection connection){
         List<Map<String,String>> contentList = new ArrayList<>();
-        conn = this.getConn();
         Statement st = null;
         ResultSet rs = null;
         try {
             String type, code ,standard,relation,result,formula,name;
-            String sql = "SELECT diagnose_id,dis_name,`type`,`code`,standard,relation,result,formula FROM `kl_diagnose_detail` where diagnose_id = "+disId+"";
-            st = conn.createStatement();
+            String sql = "SELECT diagnose_id,dis_name,`type`,`code`,standard,relation,result,formula FROM `kl_diagnose_detail` where diagnose_id = "+disId+"  and is_deleted = 'N'";
+            st = connection.createStatement();
             rs = st.executeQuery(sql);
             while (rs.next()){
                 Map<String,String> content = new HashMap<>();
@@ -1494,9 +1506,8 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
      * @param disId
      * @return
      */
-    public Map<String,List<String>> getAllNiQueZhenCollection(Long disId)  {
+    public Map<String,List<String>> getAllNiQueZhenCollection(Long disId,Connection connection)  {
         Map<String,List<String>> queNiMap = new HashMap<>();
-        conn = this.getConn();
         Statement st = null;
         ResultSet rs = null;
         List<String> queList = new ArrayList<>();
@@ -1505,36 +1516,36 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
         try {
             String type, formula,  label,name;
             String sql = "SELECT type,formula FROM `kl_diagnose_detail` where diagnose_id = "+disId+" and type in (91,92,93)";
-            st = conn.createStatement();
+            st = connection.createStatement();
             rs = st.executeQuery(sql);
             while (rs.next()) {
                 type = rs.getString(1);
                 formula = rs.getString(2);
                 name = Type.getName(Integer.parseInt(type));
-                if("拟诊".equals(name)){
+                if ("拟诊".equals(name)) {
                     niList.add(formula);
-                }else if("确诊".equals(name)){
+                } else if ("确诊".equals(name)) {
                     queList.add(formula);
-                }else if("警惕".equals(name)){
+                } else if ("警惕".equals(name)) {
                     highList.add(formula);
                 }
-                if(queList != null){
-                    for (String que:queList) {
-                        if(que.contains("拟诊")){
-                            for (String ni:niList
-                                    ) {
-                                String newNi = que.replaceAll("拟诊", ni);
-                                queList.add(newNi);
-                            }
-                            queList.remove(que);
+            }
+            List<String> newQueList = new ArrayList<>();
+            if(queList.size()>0){
+                for (String que:queList) {
+                    if(que.contains("拟诊")){
+                        for (String ni:niList
+                             ) {
+                            newQueList.add(que.replaceAll("拟诊",ni));
                         }
+                    }else {
+                        newQueList.add(que);
                     }
                 }
-                queNiMap.put("拟诊",niList);
-                queNiMap.put("确诊",queList);
-                queNiMap.put("警惕",highList);
-
             }
+            queNiMap.put("拟诊",niList);
+            queNiMap.put("确诊",newQueList);
+            queNiMap.put("警惕",highList);
         }catch (Exception e) {
             e.printStackTrace();
         } finally {
@@ -1552,9 +1563,8 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
      * 加载所有词库
      * @return
      */
-    public  Map<String,Map<String,String>> allStandWord2Map(){
+    public  Map<String,Map<String,String>> allStandWord2Map(Connection connection){
         Map<String,Map<String,String>> ciKu = new HashMap<>();
-        conn = this.getConn();
         Statement st = null;
         ResultSet rs = null;
         try {
@@ -1562,7 +1572,7 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
             String sql = "SELECT name, type_id,is_concept,IF(is_concept=1,a.name,(select lib_name from kl_concept b where b.id = a.concept_id) ) lib_name \n" +
                     "from kl_library_info a where  a.is_deleted = 'N'\n" +
                     "and type_id in (1,5,12,13,14,16,17,18,35,70)";
-            st = conn.createStatement();
+            st = connection.createStatement();
             rs = st.executeQuery(sql);
             Map<String,String> detail =null;
             while (rs.next()) {
@@ -1593,14 +1603,13 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
      * @param disId
      * @return
      */
-    public String getDisName(Long disId){
+    public String getDisName(Long disId,Connection connection){
         Statement st = null;
         ResultSet rs = null;
-        conn = this.getConn();
         String name="";
         try {
-            String sql = "SELECT dis_name FROM `kl_diagnose_detail` where diagnose_id = "+disId+"";
-            st = conn.createStatement();
+            String sql = "SELECT dis_name FROM `kl_diagnose_detail` where diagnose_id = "+disId+" and is_deleted = 'N'";
+            st = connection.createStatement();
             rs = st.executeQuery(sql);
             while (rs.next()) {
                 name = rs.getString(1);
@@ -1634,6 +1643,7 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
                         path = nisplits.length;
                         diseaseRepository.mergeCondition(disName+"-"+type+"组块"+(i+1),path);
                         diseaseRepository.mergeQueNiHigh(disName+"-"+type+"组块"+(i+1),disId);
+                        this.splitConditionContent(nisplits,disName,disName+"-"+type+"组块"+(i+1),allData);
                     }
                 }
             }else if("拟诊".equals(type)){
@@ -1673,6 +1683,7 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
         Integer path = 1;
         String rel = "";
         for (String ni:nisplits) {
+
             if(ni.contains("/")){
                 if(ni.contains("任一")){
                     path = 1;
@@ -1710,7 +1721,7 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
                     }
                 }
             }else {
-                this.processDetailNum(disName,ni,disName+ni,allData);
+                this.processDetailNum(disName,ni,startNode,allData);
             }
         }
     }
@@ -1730,7 +1741,12 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
                     String numSplit = numSplits[i];
                     int i1 = numSplit.indexOf(")");
                     System.out.println(numSplit+"\t"+i1);
-                    numList.add(numSplits[i].substring(0,numSplits[i].indexOf(")")));
+                    if(i1 >= 0){
+                        numList.add(numSplits[i].substring(0,numSplits[i].indexOf(")")));
+                    }else {
+                        numList.add(numSplit);
+                    }
+
                 }else {
                     numList.add(numSplits[i]);
                 }
@@ -2053,27 +2069,35 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
     public RespDTO deleteNeoDisease(NeoParamVO singleDisease) {
         Long disId = singleDisease.getId();
         RespDTO respDTO = null;
+        try {
+        Connection connect = getConnect();
         if(disId != null){
-            this.neo4jDelete(disId);
+            this.neo4jDelete(disId,connect);
+            connect.close();
             respDTO = RespDTO.onSuc(true);
         }else {
             respDTO = RespDTO.onError(disId +" 删除失败!!!");
         }
+        } catch (SQLException e) {
+            e.printStackTrace();
+        }
         return respDTO;
     }
     //删除
-    public void neo4jDelete(Long disId) {
+    public void neo4jDelete(Long disId,Connection connection) {
         if (disId != null) {
             diseaseRepository.deleteRelation1(disId);
             diseaseRepository.deleteRelation2(disId);
             diseaseRepository.deleteRelation3(disId);
             diseaseRepository.deleteRelation4(disId);
 //            diseaseRepository.deleteRelation5(disId);
-            diseaseRepository.deleteRelation6(disId);
-            diseaseRepository.deleteRelation7(disId);
-            diseaseRepository.deleteRelation8(disId);
-            diseaseRepository.deleteRelation9(disId);
-            List<String> allCode = this.getAllCode(disId);
+//            diseaseRepository.deleteRelation6(disId);
+//            diseaseRepository.deleteRelation7(disId);
+//            diseaseRepository.deleteRelation8(disId);
+//            diseaseRepository.deleteRelation9(disId);
+            //删除disId
+            diseaseRepository.deleteRelation11(disId);
+            List<String> allCode = this.getAllCode(disId,connection);
             if(allCode.size()>0){
                 for (String conName:allCode) {
                     diseaseRepository.deleteRelation10(conName);
@@ -2083,20 +2107,74 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
         }
     }
 
+    /**
+     * 批量插入
+     *
+     * @return
+     */
+    @Override
+    public RespDTO<Boolean> batchInsertDis() {
+        //获取mysql链接
+        Connection connect = getConnect();
+        //把数据库中的所有词读进map缓存
+        Map<String, Map<String, String>> ciKu = this.allStandWord2Map(connect);
+        RespDTO<Boolean> respDTO = new RespDTO<>();
+        try {
+            List<Long> disList = getDisList(connect);
+            if(disList != null && disList.size()>0){
+                for (Long disId:disList) {
+                   respDTO = this.updateNeo(respDTO, disId, connect, ciKu);
+
+                }
+            }
+            connect.close();
+        } catch (SQLException e) {
+            e.printStackTrace();
+        }
+
+        return respDTO;
+    }
+    public void updateDate(Connection connection,Long disId){
+        String sql = "UPDATE `kl_diagnose` set neo_update='1970-01-01 12:00:00' where id="+disId+";";
+    }
+    public List<Long> getDisList(Connection connection){
+        List<Long> disIds = new ArrayList<>();
+        Statement st = null;
+        ResultSet rs = null;
+        try {
+            Long id ;
+            String sql = "SELECT id FROM `kl_diagnose` where has_question=0 and is_deleted='N'";
+            st = connection.createStatement();
+            rs = st.executeQuery(sql);
+            while (rs.next()){
+                disIds.add(rs.getLong(1));
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                rs.close();
+                st.close();
+            } catch (SQLException e) {
+                e.printStackTrace();
+            }
+        }
+        return disIds;
+    }
+
     /**
      * 获取一个诊断依据的全部code
      * @param disId
      * @return
      */
-    public List<String> getAllCode(Long disId){
+    public List<String> getAllCode(Long disId,Connection connection){
         List<String> codeList = new ArrayList<>();
-        conn = this.getConn();
         Statement st = null;
         ResultSet rs = null;
         try {
             String code ,name;
             String sql = "SELECT dis_name,code FROM `kl_diagnose_detail` where diagnose_id="+disId+" and code != \"\"";
-            st = conn.createStatement();
+            st = connection.createStatement();
             rs = st.executeQuery(sql);
             while (rs.next()){
                 name = rs.getString("dis_name");

+ 5 - 0
graphdb/src/main/java/org/diagbot/web/KnowledgeController.java

@@ -206,4 +206,9 @@ public class KnowledgeController {
         RespDTO respDTO = knowledgeService.updateNeoDisease(disease);
         return respDTO;
     }
+    @RequestMapping("/init")
+    public RespDTO batchInsert( ){
+        RespDTO respDTO = knowledgeService.batchInsertDis();
+        return respDTO;
+    }
 }

+ 2 - 2
graphdb/src/main/resources/application.yml

@@ -6,14 +6,14 @@ spring:
     active: local
   data:
     neo4j:
-      uri: bolt://192.168.2.234:7687
+      uri: bolt://192.168.2.232:7687
       username: neo4j
       password: root
 
 # 驱动配置信息
   datasource:
     driver-class-name: org.neo4j.jdbc.Driver
-    url: jdbc:neo4j:http://192.168.2.234:7474
+    url: jdbc:neo4j:http://192.168.2.232:7474
     username: neo4j
     password: root
     #定义初始连接数