CacheFileManagerTest.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package org.diagbot;
  2. import org.diagbot.pub.jdbc.MysqlJdbc;
  3. import org.diagbot.pub.utils.security.EncrypDES;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.sql.Connection;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.sql.Statement;
  10. import java.util.*;
  11. /**
  12. * @ClassName org.diagbot.CacheFileManagerTest
  13. * @Description TODO
  14. * @Author fyeman
  15. * @Date 2019/3/8/008 14:05
  16. * @Version 1.0
  17. **/
  18. public class CacheFileManagerTest {
  19. public static void main(String[] args) {
  20. CacheFileManagerTest test = new CacheFileManagerTest();
  21. test.contextMappingInitialized();
  22. }
  23. public void contextMappingInitialized() {
  24. MysqlJdbc nlpJdbc = new MysqlJdbc("root", "lantone", "jdbc:mysql://192.168.2.121:3306/med?useUnicode=true&characterEncoding=UTF-8");
  25. Connection conn = nlpJdbc.connect();
  26. Statement st = null;
  27. ResultSet rs = null;
  28. try {
  29. EncrypDES encrypDES = new EncrypDES();
  30. String path = this.getClass().getClassLoader().getResource("").getPath();
  31. path = path.substring(0, path.indexOf("target"));
  32. //体征衍射
  33. // String sql = "select distinct name, name_mapping from doc_result_mapping_vital order by name";
  34. // st = conn.createStatement();
  35. // rs = st.executeQuery(sql);
  36. // List<Map.Entry<String, String>> libraryList = rsToMap(rs, true);
  37. //
  38. // FileWriter fw = new FileWriter(path + "src/main/resources/doc_result_mapping_vital.dict");
  39. // for (Map.Entry<String, String> entry : libraryList) {
  40. // fw.write(encrypDES.encrytor(entry.getKey() + "|" + entry.getValue()));
  41. // fw.write("\n");
  42. // }
  43. // fw.close();
  44. //疾病科室
  45. String sql = "SELECT k1.lib_name diag_name, k2.lib_name dept_name FROM kl_concept_common kcc, kl_concept k1, kl_concept k2 " +
  46. "where kcc.concept_id = k1.id and kcc.dept_id = k2.id " +
  47. "and k1.lib_type = 18 and kcc.dept_id is not null";
  48. st = conn.createStatement();
  49. rs = st.executeQuery(sql);
  50. List<Map.Entry<String, String>> libraryList = rsToMap(rs, true);
  51. FileWriter fw = new FileWriter(path + "src/main/resources/doc_result_mapping_diag.dict");
  52. for (Map.Entry<String, String> entry : libraryList) {
  53. fw.write(encrypDES.encrytor(entry.getKey() + "|" + entry.getValue()));
  54. fw.write("\n");
  55. }
  56. fw.close();
  57. //性别年龄
  58. sql = "SELECT k1.lib_name, k1.lib_type, kcc.sex_type, kcc.min_age, kcc.max_age " +
  59. "FROM kl_concept_common kcc, kl_concept k1 " +
  60. "where kcc.concept_id = k1.id " +
  61. "and k1.lib_type in (1, 18)";
  62. st = conn.createStatement();
  63. rs = st.executeQuery(sql);
  64. fw = new FileWriter(path + "src/main/resources/doc_result_mapping_filter.dict");
  65. String r1, r2, r3, r4, r5;
  66. while (rs.next()) {
  67. r1 = rs.getString(1);
  68. r2 = rs.getString(2);
  69. r3 = rs.getString(3);
  70. r4 = rs.getString(4);
  71. r5 = rs.getString(5);
  72. if ("18".equals(r2)) {
  73. r2 = "2";
  74. }
  75. fw.write(encrypDES.encrytor(r1 + "|" + r2 + "|" + r3 + "|" + r4 + "|" + r5));
  76. fw.write("\n");
  77. }
  78. fw.close();
  79. } catch (IOException ioe) {
  80. ioe.printStackTrace();
  81. } catch (SQLException sqle) {
  82. sqle.printStackTrace();
  83. } catch (Exception e) {
  84. e.printStackTrace();
  85. } finally {
  86. nlpJdbc.close(rs, st, conn);
  87. }
  88. }
  89. public void standwordMappingInitialized() {
  90. MysqlJdbc nlpJdbc = new MysqlJdbc("root", "diagbot@20180822", "jdbc:mysql://192.168.2.235:3306/med-s?useUnicode=true&characterEncoding=UTF-8");
  91. Connection conn = nlpJdbc.connect();
  92. Statement st = null;
  93. ResultSet rs = null;
  94. try {
  95. EncrypDES encrypDES = new EncrypDES();
  96. String path = this.getClass().getClassLoader().getResource("").getPath();
  97. path = path.substring(0, path.indexOf("target"));
  98. String sql = "SELECT lib_name FROM kl_concept WHERE is_deleted = 'N' AND lib_type = 70 AND lib_name regexp '[0-9]'";
  99. st = conn.createStatement();
  100. rs = st.executeQuery(sql);
  101. FileWriter fw = new FileWriter(path + "src/main/resources/kl_result_mapping_standword.dict");
  102. while (rs.next()) {
  103. fw.write(encrypDES.encrytor(rs.getString(1)));
  104. fw.write("\n");
  105. }
  106. fw.close();
  107. } catch (IOException ioe) {
  108. ioe.printStackTrace();
  109. } catch (SQLException sqle) {
  110. sqle.printStackTrace();
  111. } catch (Exception e) {
  112. e.printStackTrace();
  113. } finally {
  114. nlpJdbc.close(rs, st, conn);
  115. }
  116. }
  117. private List<Map.Entry<String, String>> rsToMap(ResultSet rs, boolean isJoin) throws SQLException{
  118. String r1 = "";
  119. String r2 = "";
  120. Map<String, String> libraryMap = new HashMap<>(10);
  121. while (rs.next()) {
  122. r1 = rs.getString(1);
  123. r2 = rs.getString(2);
  124. if (libraryMap.get(r1) == null) {
  125. libraryMap.put(r1, r2);
  126. } else if (isJoin && libraryMap.get(r1) != null) {
  127. libraryMap.put(r1, libraryMap.get(r1) + "," + r2);
  128. }
  129. }
  130. List<Map.Entry<String, String>> libraryList = new ArrayList<Map.Entry<String, String>>(libraryMap.entrySet());
  131. Collections.sort(libraryList, new Comparator<Map.Entry<String, String>>() {
  132. public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {
  133. return o1.getKey().compareTo(o2.getKey());
  134. }
  135. });
  136. return libraryList;
  137. }
  138. }