浏览代码

诊断依据后台维护链接优化

kongwz 5 年之前
父节点
当前提交
ea473d6f49

+ 1 - 1
common-push/src/main/java/org/diagbot/common/push/cache/CacheFileManager.java

@@ -23,7 +23,7 @@ public class CacheFileManager {
 
     private String user = "root";
     private String password = "lantone";
-    private String url = "jdbc:mysql://192.168.2.121:3306/med?useUnicode=true&characterEncoding=UTF-8";
+    private String url = "jdbc:mysql://192.168.2.236:3306/med?useUnicode=true&characterEncoding=UTF-8";
 
     private String path = "";
 

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

@@ -57,6 +57,6 @@ public interface KnowledgeService {
     //删除图谱
     RespDTO deleteNeoDisease(NeoParamVO singleDisease);
     //批量插入
-    RespDTO<Boolean> batchInsertDis(List<Long> idList);
+    RespDTO<Boolean> batchInsertDis();
 
 }

+ 90 - 42
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.236: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,26 +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();
-        RespDTO respDTO1 = this.updateNeo(respDTO, disId);
+            //把数据库中的所有词读进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){
+
+    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;
@@ -1451,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+"  and is_deleted = 'N'";
-            st = conn.createStatement();
+            st = connection.createStatement();
             rs = st.executeQuery(sql);
             while (rs.next()){
                 Map<String,String> content = new HashMap<>();
@@ -1498,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<>();
@@ -1509,7 +1516,7 @@ 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);
@@ -1556,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 {
@@ -1566,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()) {
@@ -1597,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+" and is_deleted = 'N'";
-            st = conn.createStatement();
+            st = connection.createStatement();
             rs = st.executeQuery(sql);
             while (rs.next()) {
                 name = rs.getString(1);
@@ -2064,16 +2069,22 @@ 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);
@@ -2086,7 +2097,7 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
 //            diseaseRepository.deleteRelation9(disId);
             //删除disId
             diseaseRepository.deleteRelation11(disId);
-            List<String> allCode = this.getAllCode(disId);
+            List<String> allCode = this.getAllCode(disId,connection);
             if(allCode.size()>0){
                 for (String conName:allCode) {
                     diseaseRepository.deleteRelation10(conName);
@@ -2098,35 +2109,72 @@ public class    KnowledgeServiceImpl implements KnowledgeService {
 
     /**
      * 批量插入
-     * @param idList
+     *
      * @return
      */
     @Override
-    public RespDTO<Boolean> batchInsertDis(List<Long> idList) {
+    public RespDTO<Boolean> batchInsertDis() {
+        //获取mysql链接
+        Connection connect = getConnect();
+        //把数据库中的所有词读进map缓存
+        Map<String, Map<String, String>> ciKu = this.allStandWord2Map(connect);
         RespDTO<Boolean> respDTO = new RespDTO<>();
-        if(idList.size()>0){
-            for (Long disID:idList) {
-                this.neo4jDelete(disID);
-                respDTO = this.updateNeo(respDTO, disID);
+        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");

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

@@ -207,8 +207,8 @@ public class KnowledgeController {
         return respDTO;
     }
     @RequestMapping("/init")
-    public RespDTO batchInsert( @RequestBody List<Long> idList){
-        RespDTO respDTO = knowledgeService.batchInsertDis(idList);
+    public RespDTO batchInsert( ){
+        RespDTO respDTO = knowledgeService.batchInsertDis();
         return respDTO;
     }
 }