|
@@ -0,0 +1,103 @@
|
|
|
|
+package com.lantone.qc.kernel.util;
|
|
|
|
+
|
|
|
|
+import com.lantone.qc.pub.jdbc.MysqlJdbc;
|
|
|
|
+import com.lantone.qc.pub.util.PropertiesUtil;
|
|
|
|
+import com.lantone.qc.security.util.EncrypDES;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileWriter;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.sql.Connection;
|
|
|
|
+import java.sql.ResultSet;
|
|
|
|
+import java.sql.SQLException;
|
|
|
|
+import java.sql.Statement;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Created by louhr on 2019/8/16.
|
|
|
|
+ */
|
|
|
|
+public class CacheFileManager {
|
|
|
|
+ Logger logger = LoggerFactory.getLogger(CacheFileManager.class);
|
|
|
|
+
|
|
|
|
+ private String user;
|
|
|
|
+ private String password;
|
|
|
|
+ private String url;
|
|
|
|
+
|
|
|
|
+ private String path = "";
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ CacheFileManager cacheFileManager = new CacheFileManager();
|
|
|
|
+ PropertiesUtil propertiesUtil = new PropertiesUtil("nlp.properties");
|
|
|
|
+ String p = propertiesUtil.getProperty("cache.file.dir");
|
|
|
|
+ File file = new File(p);
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
+ file.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public CacheFileManager() {
|
|
|
|
+ try {
|
|
|
|
+ PropertiesUtil propertiesUtil = new PropertiesUtil("kernel.properties");
|
|
|
|
+ EncrypDES encrypDES = new EncrypDES();
|
|
|
|
+ user = encrypDES.decryptor(propertiesUtil.getProperty("mysql.user"));
|
|
|
|
+ password = encrypDES.decryptor(propertiesUtil.getProperty("mysql.password"));
|
|
|
|
+ url = encrypDES.decryptor(propertiesUtil.getProperty("mysql.url"));
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ logger.info("数据库连接信息出错...." + e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void createCacheFile(String path) {
|
|
|
|
+ MysqlJdbc nlpJdbc = new MysqlJdbc(user, password, url);
|
|
|
|
+ Connection conn = nlpJdbc.connect();
|
|
|
|
+ Statement st = null;
|
|
|
|
+ ResultSet rs = null;
|
|
|
|
+ try {
|
|
|
|
+ EncrypDES encrypDES = new EncrypDES();
|
|
|
|
+ //所有词典库 不能用concat_group 大小写不区分
|
|
|
|
+ String sql = "select l_1.name l_1_name, l_1.type_id type_id, l_2.name l_2_name, kc.lib_name, group_concat(l_1.name) group_name from kl_library_info l_1\n" +
|
|
|
|
+ "left join kl_library_info l_2 on l_1.concept_id = l_2.concept_id and l_2.is_concept = 1\n" +
|
|
|
|
+ "left join kl_concept kc on l_1.concept_id = kc.id\n" +
|
|
|
|
+ "left join kl_disease dis on l_1.concept_id = dis.concept_id\n" +
|
|
|
|
+ "where kc.is_deleted = 'N' group by l_1.concept_id";
|
|
|
|
+ st = conn.createStatement();
|
|
|
|
+ rs = st.executeQuery(sql);
|
|
|
|
+ FileWriter fw = new FileWriter(path + "tc.dict");
|
|
|
|
+ fw.close();
|
|
|
|
+ } catch (IOException ioe) {
|
|
|
|
+ ioe.printStackTrace();
|
|
|
|
+ } catch (SQLException sqle) {
|
|
|
|
+ sqle.printStackTrace();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ nlpJdbc.close(rs, st, conn);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<Map.Entry<String, String>> rsToMap(ResultSet rs, boolean isJoin) throws SQLException {
|
|
|
|
+ String r1 = "";
|
|
|
|
+ String r2 = "";
|
|
|
|
+ Map<String, String> libraryMap = new HashMap<>(10);
|
|
|
|
+ while (rs.next()) {
|
|
|
|
+// r1 = CryptUtil.decrypt_char(rs.getString(1));
|
|
|
|
+// r2 = CryptUtil.decrypt_char(rs.getString(2));
|
|
|
|
+ if (libraryMap.get(r1) == null) {
|
|
|
|
+ libraryMap.put(r1, r2);
|
|
|
|
+ } else if (isJoin && libraryMap.get(r1) != null) {
|
|
|
|
+ libraryMap.put(r1, libraryMap.get(r1) + "," + r2);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Map.Entry<String, String>> libraryList = new ArrayList<Map.Entry<String, String>>(libraryMap.entrySet());
|
|
|
|
+ Collections.sort(libraryList, new Comparator<Map.Entry<String, String>>() {
|
|
|
|
+ public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {
|
|
|
|
+ return o1.getKey().compareTo(o2.getKey());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return libraryList;
|
|
|
|
+ }
|
|
|
|
+}
|