From 79f9fbd9f999e26af3f0bca534d825eb687e092c Mon Sep 17 00:00:00 2001
From: zjh <1084500556@qq.com>
Date: 星期三, 25 十二月 2024 08:47:24 +0800
Subject: [PATCH] 20241225

---
 ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisApiGetMethodService.java |  405 ++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 309 insertions(+), 96 deletions(-)

diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisApiGetMethodService.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisApiGetMethodService.java
index de2736f..083f3d5 100644
--- a/ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisApiGetMethodService.java
+++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisApiGetMethodService.java
@@ -1,17 +1,22 @@
 package com.ltkj.web.controller.his;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.ltkj.common.core.domain.AjaxResult;
+import com.ltkj.hosp.domain.ApiConfig;
 import com.ltkj.hosp.domain.HisApiConfig;
+import com.ltkj.hosp.service.ApiConfigService;
 import com.ltkj.hosp.service.HisApiConfigService;
 import com.ltkj.web.wxUtils.HttpClientUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.io.FileInputStream;
@@ -32,19 +37,55 @@
 @Slf4j
 @Component
 public class HisApiGetMethodService {
+
+
     // 鏁版嵁搴撻厤缃枃浠惰矾寰�
-    private static final String CONFIG_PATH = "D:\\ltkjprojectconf\\config.properties";
-//    private static final String CONFIG_PATH = "D:\\ltkjprojectconf\\config.properties";
+//    private static final String CONFIG_PATH = url;
+//    private static final String CONFIG_PATH = "/Users/chacca/寮�鍙戠浉鍏�/浠g爜/ltkj_peis/ltkj-admin/src/main/resources/config.properties";
     // 鏁版嵁搴撳悕
     private static String DB_NAME = "";
     private static String HIS_URL = "";
     private static String DATA_URL = "";
     private static String DATA_USER ="";
     private static String DATA_PASS = "";
+    private static String LIS_URL = "";
+    private static String PACS_URL = "";
     @Autowired
     private HisApiMethodService controller;
     @Autowired
     private HisApiConfigService hisApiConfigService;
+    @Autowired
+    private ApiConfigService apiConfigService;
+
+    private static String url;
+
+
+    @Value ("${config.properties}")
+    public  void set(String urls){
+         url=urls;
+        FileInputStream inputStream = null;
+        try {
+            inputStream = new FileInputStream(url);
+            Properties props = new Properties();
+            props.load(inputStream);
+            DB_NAME = props.getProperty("name");
+            DATA_URL = "jdbc:mysql://" + props.getProperty("ip") + ":" + props.getProperty("prot") + "/" + DB_NAME + "" +
+                    "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8";
+            DATA_USER = props.getProperty("username");
+            DATA_PASS = props.getProperty("password");
+            String apiUrl = props.getProperty("his_api_url");
+            String apiPort = props.getProperty("his_api_port");
+            HIS_URL = apiUrl+":"+apiPort;
+            String lisApiUrl = props.getProperty("lis_api_url");
+            String lisApiPort = props.getProperty("lis_api_port");
+            LIS_URL = lisApiUrl+":"+lisApiPort;
+            String pacsApiUrl = props.getProperty("pacs_api_url");
+            String pacsApiPort = props.getProperty("pacs_api_port");
+            PACS_URL = pacsApiUrl+":"+pacsApiPort;
+        } catch (IOException e) {
+            System.out.println("鍒濆鍖栨暟鎹簱寮傚父 ->"+e.getMessage());
+        }
+    }
 
     static {
         try {
@@ -52,21 +93,21 @@
         } catch (ClassNotFoundException e) {
             e.printStackTrace();
         }
-        try {
-            InputStreamReader reader = new InputStreamReader(new FileInputStream(CONFIG_PATH), StandardCharsets.UTF_8);
-            Properties props = new Properties();
-            props.load(reader);
-            String api_url = props.getProperty("his_api_url");
-            String port = props.getProperty("his_api_port");
-            DB_NAME = props.getProperty("name");
-            DATA_URL = "jdbc:mysql://" + props.getProperty("ip") + ":" + props.getProperty("prot") + "/" + DB_NAME +
-                    "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8";
-            DATA_USER = props.getProperty("username");
-            DATA_PASS = props.getProperty("password");
-            HIS_URL=api_url+":"+port;
-        } catch (IOException throwables) {
-            throwables.printStackTrace();
-        }
+//        try {
+//            InputStreamReader reader = new InputStreamReader(new FileInputStream(url), StandardCharsets.UTF_8);
+//            Properties props = new Properties();
+//            props.load(reader);
+//            String api_url = props.getProperty("his_api_url");
+//            String port = props.getProperty("his_api_port");
+//            DB_NAME = props.getProperty("name");
+//            DATA_URL = "jdbc:mysql://" + props.getProperty("ip") + ":" + props.getProperty("prot") + "/" + DB_NAME +
+//                    "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8";
+//            DATA_USER = props.getProperty("username");
+//            DATA_PASS = props.getProperty("password");
+//            HIS_URL=api_url+":"+port;
+//        } catch (IOException throwables) {
+//            throwables.printStackTrace();
+//        }
     }
 
 
@@ -76,7 +117,10 @@
      * @param type   鎺ュ彛浠g爜
      * @param params 璇锋眰鍙傛暟
      * @return
+     * @deprecated
+     * 鏂规硶宸插純鐢�,灏唖witch鏇存敼涓烘暟鎹簱鍖归厤 浣跨敤鏂版柟娉晎@link #getHISDataNew(String, Map)}
      */
+    @Deprecated
     @Transactional
     public AjaxResult getHISData(String type, Map<String, Object> params) {
         AjaxResult result = null;
@@ -138,7 +182,7 @@
             List<Map<String, String>> list = new ArrayList<>();
             for (Object resultDatum : resultData) {
                 JSONObject object = (JSONObject) resultDatum;
-                ajaxResult = save(object, type,null);
+                ajaxResult = save(object, type,null,JSONUtil.toJsonStr(params));
                 Map<String, String> map = new HashMap<>();
                 for (String key : object.keySet()) {
                     String defaultVal = object.get(key).toString();
@@ -170,21 +214,27 @@
             return AjaxResult.error().put("result", JSONUtil.parseObj(json));
         }
     }
-    
-    @Transactional
+
+//    @Transactional
     public AjaxResult getHISDataNew(String type, Map<String, Object> params){
         LambdaQueryWrapper<HisApiConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>();
         lambdaQueryWrapper.eq(HisApiConfig::getApiMethod, type);
         HisApiConfig hisApiConfig = hisApiConfigService.getOne(lambdaQueryWrapper);
         String responseJson = HttpClientUtils.sendPost(HIS_URL + hisApiConfig.getApiUrl(), params);
-        JSONObject response = JSONUtil.parseObj(responseJson).getJSONObject("Response");
-        if (response.getStr("ResultCode").equals("0")) {
+        Integer isResponse = hisApiConfig.getIsResponse();
+        JSONObject response = null;
+        if (isResponse == 1) {
+            response = JSONUtil.parseObj(responseJson).getJSONObject("Response");
+        } else{
+            response = JSONUtil.parseObj(responseJson);
+        }
+        if (response.getStr(hisApiConfig.getResultCodeKey()).equals("0")) {
             AjaxResult ajaxResult = AjaxResult.success();
-            JSONArray resultData = response.getJSONArray("ResultData");
+            JSONArray resultData = response.getJSONArray(hisApiConfig.getResultDataKey());
             List<Map<String, String>> list = new ArrayList<>();
             for (Object resultDatum : resultData) {
                 JSONObject object = (JSONObject) resultDatum;
-                ajaxResult = save(object, type,hisApiConfig);
+                ajaxResult = save(object, type,hisApiConfig,JSONUtil.toJsonStr(params));
                 Map<String, String> map = new HashMap<>();
                 for (String key : object.keySet()) {
                     String defaultVal = object.get(key).toString();
@@ -200,6 +250,64 @@
         }
     }
 
+    public AjaxResult getLisData(String type,Map<String ,Object> params){
+        LambdaQueryWrapper<ApiConfig> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(ApiConfig::getType,"lis");
+        wrapper.eq(ApiConfig::getApiMethod,type);
+        return getAjaxResult("lis", params, wrapper);
+    }
+
+    public AjaxResult getPacsData(String type,Map<String ,Object> params){
+        LambdaQueryWrapper<ApiConfig> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(ApiConfig::getType,"pacs");
+        wrapper.eq(ApiConfig::getApiMethod,type);
+        return getAjaxResult("pacs", params, wrapper);
+    }
+
+    private AjaxResult getAjaxResult(String type, Map<String, Object> params, LambdaQueryWrapper<ApiConfig> wrapper) {
+        ApiConfig apiConfig = apiConfigService.getOne(wrapper);
+        String responseJson;
+        switch (type){
+            case "pacs":
+                responseJson = HttpClientUtils.sendPost(PACS_URL + apiConfig.getApiUrl(), params);
+                break;
+            default:
+                responseJson = HttpClientUtils.sendPost(LIS_URL + apiConfig.getApiUrl(), params);
+                break;
+        }
+        Integer isResponse = apiConfig.getIsResponse();
+        JSONObject response = null;
+        if (isResponse == 1) {
+            response = JSONUtil.parseObj(responseJson).getJSONObject("Response");
+        } else{
+            response = JSONUtil.parseObj(responseJson);
+        }
+        if (response.getStr(apiConfig.getResultCodeKey()).equals("1")) {
+            AjaxResult ajaxResult = AjaxResult.success();
+            if (response.getStr(apiConfig.getResultDataKey()) != null && StrUtil.isNotBlank(response.getStr(apiConfig.getResultDataKey()))){
+                JSONArray resultData = response.getJSONArray(apiConfig.getResultDataKey());
+                List<Map<String, String>> list = new ArrayList<>();
+                for (Object resultDatum : resultData) {
+                    JSONObject object = (JSONObject) resultDatum;
+                    ajaxResult = save(object, type,apiConfig,JSONUtil.toJsonStr(params));
+                    Map<String, String> map = new HashMap<>();
+                    for (String key : object.keySet()) {
+                        String defaultVal = object.get(key).toString();
+                        String val = defaultVal.trim().replaceAll("\\s+", "");
+                        map.put(key, val);
+                    }
+                    list.add(map);
+                }
+                ajaxResult.put("data", list);
+            }else {
+                ajaxResult.put("data",response);
+            }
+            return ajaxResult;
+        } else {
+            return AjaxResult.error().put("result", JSONUtil.parseObj(responseJson));
+        }
+    }
+
     /**
      * ResultData涓哄璞�
      * 鏍规嵁his鎺ュ彛杩斿洖鍊� 鎻掑叆鏁版嵁
@@ -208,14 +316,18 @@
      * @param code 鎺ュ彛浠g爜
      * @return 鎵ц鏄惁鎴愬姛
      */
-    public AjaxResult save(JSONObject object, String code,HisApiConfig hisApiConfig) {
+    public AjaxResult save(JSONObject object, String code,Object hisApiConfig,String paramsJson) {
+        String tabName = "";
+        if (code.equals("lis") || code.equals("pacs"))
+            tabName = ((ApiConfig)hisApiConfig).getTabName();
+        else tabName = ((HisApiConfig) hisApiConfig).getTabName();
         Connection connection = getConnection();
-        Boolean isExists = tabIsExists(connection, hisApiConfig.getTabName());
+        Boolean isExists = tabIsExists(connection, tabName);
         if (null == isExists)
             return AjaxResult.error();
         if (!isExists) {
             try {
-                creatTable(object, hisApiConfig.getTabName(), connection);
+                creatTable(object, tabName, connection);
             } catch (SQLException e) {
                 e.printStackTrace();
                 return AjaxResult.error();
@@ -223,59 +335,14 @@
         }
         //鎻掑叆鏁版嵁
         try {
-            operationTable(object,connection,hisApiConfig);
+            operationTable(object,connection,hisApiConfig,paramsJson,code);
         } catch (SQLException e) {
             e.printStackTrace();
             return AjaxResult.error();
-        }
-        try {
-            connection.close();
-        } catch (SQLException ignored) {
-        }
-        return AjaxResult.success();
-    }
-
-    /**
-     * ResultData涓洪泦鍚�
-     * 鏍规嵁his鎺ュ彛杩斿洖鍊� 鎻掑叆鏁版嵁
-     * 濡傛灉娌℃湁琛ㄥ垯鍒涘缓琛� 鎺ュ彛澧炲姞浜嗗瓧娈靛垯涓鸿〃澧炲姞瀛楁
-     *
-     * @param code 鎺ュ彛浠g爜
-     * @return 鎵ц鏄惁鎴愬姛
-     */
-    public AjaxResult saveArray(String json, String code) {
-        code = code.toLowerCase();
-        JSONObject jsonObject = JSONUtil.parseObj(json);
-        JSONObject response = jsonObject.getJSONObject("Response");
-        String tabName = "ltkj_" + code;
-        if (response.getStr("ResultCode").equals("0")) {
-            JSONArray resultData = response.getJSONArray("ResultData");
-            Connection connection = getConnection();
-            for (Object resultDatum : resultData) {
-                JSONObject object = (JSONObject) resultDatum;
-                Boolean isExists = tabIsExists(connection, tabName);
-                if (null == isExists)
-                    return AjaxResult.error();
-                if (!isExists) {
-                    try {
-                        creatTable(object, tabName, connection);
-                    } catch (SQLException throwables) {
-                        throwables.printStackTrace();
-                        return AjaxResult.error();
-                    }
-                }
-                //鎻掑叆鏁版嵁
-                try {
-                    operationTable(object,connection,null);
-                } catch (SQLException throwables) {
-                    throwables.printStackTrace();
-                    return AjaxResult.error();
-                }
-            }
+        }finally {
             try {
-                if (connection != null)
-                    connection.close();
-            } catch (SQLException throwables) {
+                connection.close();
+            } catch (SQLException ignored) {
             }
         }
         return AjaxResult.success();
@@ -287,45 +354,52 @@
      * @param connection
      * @throws SQLException
      */
-    private void operationTable(JSONObject jsonObject, Connection connection,HisApiConfig hisApiConfig) throws SQLException {
-        List<String> columns = getColumns(hisApiConfig.getTabName(), connection);
+    private void operationTable(JSONObject jsonObject, Connection connection,Object hisApiConfig,String paramsJson,String code) throws SQLException {
+        String tabName = "";
+        if (code.equals("lis") || code.equals("pacs"))
+            tabName = ((ApiConfig)hisApiConfig).getTabName();
+        else tabName = ((HisApiConfig) hisApiConfig).getTabName();
+        List<String> columns = getColumns(tabName, connection);
         ArrayList<String> responseColums = new ArrayList<>();
         for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
             String key = entry.getKey().trim().toLowerCase();
             responseColums.add(key);
         }
+        Map<String, Object> beanToMap = BeanUtil.beanToMap(JSONUtil.parseObj(paramsJson));
+        Set<Map.Entry<String, Object>> entries = beanToMap.entrySet();
+        for (Map.Entry<String, Object> entry : entries) {
+            String key = "request_params_"+entry.getKey().trim().toLowerCase();
+            if (!columns.contains(key))
+                responseColums.add(key);
+        }
         responseColums.removeAll(columns);
         if (!responseColums.isEmpty()) {
             for (String colum : responseColums) {
-                String sql = "alter table " + hisApiConfig.getTabName() + " add column " + colum + " VARCHAR(200) null";
+                String sql = "alter table " + tabName + " add column " + colum + " VARCHAR(200) null";
                 Statement statement = connection.createStatement();
                 statement.executeUpdate(sql);
                 statement.close();
             }
-            if (hisApiConfig == null)
-            insertData(hisApiConfig.getTabName(), connection, jsonObject);
-            else insertDataNew(connection, jsonObject,hisApiConfig);
+            insertDataNew(connection, jsonObject,hisApiConfig,paramsJson,code);
         } else {
-            if (hisApiConfig == null)
-            insertData(hisApiConfig.getTabName(), connection, jsonObject);
-            else insertDataNew(connection, jsonObject,hisApiConfig);
+            insertDataNew(connection, jsonObject,hisApiConfig,paramsJson,code);
         }
     }
 
     /**
      * 鎻掑叆鏁版嵁
      *
-     * @param tabName
+     * @param hisApiConfig
      * @param connection
      * @param jsonObject
      * @throws SQLException
      */
-    private void insertData(String tabName, Connection connection, JSONObject jsonObject) throws SQLException {
+    private void insertData(HisApiConfig hisApiConfig, Connection connection, JSONObject jsonObject) throws SQLException {
         StringBuilder insertSqlBuilder = new StringBuilder();
         StringBuilder valueBuilder = new StringBuilder();
         StringBuilder selectSqlBuilder = new StringBuilder();
-        insertSqlBuilder.append("insert into ").append(tabName).append(" (");
-        selectSqlBuilder.append("select count(1) as count from ").append(tabName).append(" where ");
+        insertSqlBuilder.append("insert into ").append(hisApiConfig.getTabName()).append(" (");
+        selectSqlBuilder.append("select count(1) as count from ").append(hisApiConfig.getTabName()).append(" where ");
         for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
             String defaultVal = entry.getValue().toString();
             String key = entry.getKey().trim().toLowerCase();
@@ -335,6 +409,19 @@
             insertSqlBuilder.append(key).append(", ");
             valueBuilder.append("'").append(val).append("', ");
             selectSqlBuilder.append(key).append(" = '").append(val).append("' and ");
+            // 鍒ゆ柇鏁版嵁鏄惁澶т簬瀛楁鍒涘缓鍊煎鏋滃ぇ浜庡垯澧炲姞瓒呰繃闃堝�煎垯浣跨敤text
+            String columnType = getColumnType(connection, hisApiConfig.getTabName(), key);
+            if (!"text".equalsIgnoreCase(columnType)){
+                int currentSize = getColumnSize(connection, hisApiConfig.getTabName(), key);
+                if (currentSize < val.length()){
+                    if (val.length()>= 1000){
+                        alterColumnTypeToText(connection, hisApiConfig.getTabName(), key);
+                    }else {
+                        int newSize = ((val.length() / 100) + 1) * 100;
+                        alterColumnSize(connection, hisApiConfig.getTabName(), key, newSize);
+                    }
+                }
+            }
         }
         selectSqlBuilder.delete(selectSqlBuilder.length() - 5, selectSqlBuilder.length());
         Statement statement = connection.prepareStatement(selectSqlBuilder.toString());
@@ -366,13 +453,22 @@
      * @param jsonObject
      * @throws SQLException
      */
-    private void insertDataNew(Connection connection, JSONObject jsonObject,HisApiConfig hisApiConfig) throws SQLException {
-        List<String> primaryKesList = Arrays.stream(hisApiConfig.getPrimaryKeys().split(",")).map(String::toLowerCase).collect(Collectors.toList());
+    @Transactional
+    public void insertDataNew(Connection connection, JSONObject jsonObject, Object hisApiConfig, String paramsJson, String code) throws SQLException {
+        String tabName = "";
+        List<String> primaryKesList;
+        if (code.equals("lis") || code.equals("pacs")) {
+            tabName = ((ApiConfig) hisApiConfig).getTabName();
+            primaryKesList = Arrays.stream(((ApiConfig)hisApiConfig).getPrimaryKeys().split(",")).map(String::toLowerCase).collect(Collectors.toList());
+        } else {
+            tabName = ((HisApiConfig) hisApiConfig).getTabName();
+            primaryKesList = Arrays.stream(((HisApiConfig)hisApiConfig).getPrimaryKeys().split(",")).map(String::toLowerCase).collect(Collectors.toList());
+        }
         StringBuilder deleteSqlBuilder = new StringBuilder();
         StringBuilder insertSqlBuilder = new StringBuilder();
         StringBuilder valueBuilder = new StringBuilder();
-        insertSqlBuilder.append("insert into ").append(hisApiConfig.getTabName()).append(" (");
-        deleteSqlBuilder.append("delete from ").append(hisApiConfig.getTabName()).append(" where ");
+        insertSqlBuilder.append("insert into ").append(tabName).append(" (");
+        deleteSqlBuilder.append("delete from ").append(tabName).append(" where ");
         for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
             String defaultVal = entry.getValue().toString();
             String key = entry.getKey().trim().toLowerCase();
@@ -384,24 +480,140 @@
             }
             insertSqlBuilder.append(key).append(", ");
             valueBuilder.append("'").append(val).append("', ");
+            // 鍒ゆ柇鏁版嵁鏄惁澶т簬瀛楁鍒涘缓鍊煎鏋滃ぇ浜庡垯澧炲姞瓒呰繃闃堝�煎垯浣跨敤text
+            String columnType = getColumnType(connection, tabName, key);
+            if (!"text".equalsIgnoreCase(columnType)){
+                int currentSize = getColumnSize(connection, tabName, key);
+                if (currentSize < val.length()){
+                    if (val.length()>= 1000){
+                        alterColumnTypeToText(connection, tabName, key);
+                    }else {
+                        int newSize = ((val.length() / 100) + 1) * 100;
+                        alterColumnSize(connection, tabName, key, newSize);
+                    }
+                }
+            }
         }
         deleteSqlBuilder.delete(deleteSqlBuilder.length() - 5, deleteSqlBuilder.length());
         Statement statement = connection.prepareStatement(deleteSqlBuilder.toString());
-//        log.info("鎵ц鍒犻櫎 ->{}",deleteSqlBuilder.toString());
+        log.info("HIS鏁版嵁淇濆瓨绫� 鎵ц鍒犻櫎 ->{}",deleteSqlBuilder.toString());
         int i = statement.executeUpdate(deleteSqlBuilder.toString());
-//        log.info("鍒犻櫎鏉℃暟 ->{}",i);
+        log.info("HIS鏁版嵁淇濆瓨绫� 鍒犻櫎鏉℃暟 ->{}",i);
         statement.close();
         insertSqlBuilder.append("insert_time, ");
+        insertSqlBuilder.append("request_params, ");
+        DatabaseMetaData metaData = connection.getMetaData();
+        try (ResultSet resultSet = metaData.getColumns(null, null, tabName, "request_params")) {
+            if (!resultSet.next()){
+                String alterTableSQL = String.format("ALTER TABLE %s ADD COLUMN %s %s", tabName, "request_params", "text");
+                statement = connection.createStatement();
+                statement.execute(alterTableSQL);
+            }
+        }
         String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
         valueBuilder.append("'").append(time).append("'").append(", ");
+        valueBuilder.append("'").append(paramsJson).append("'").append(", ");
+        Map<String, Object> beanToMap = BeanUtil.beanToMap(JSONUtil.parseObj(paramsJson));
+        Set<Map.Entry<String, Object>> entries = beanToMap.entrySet();
+        for (Map.Entry<String, Object> entry : entries) {
+            String key = "request_params_"+entry.getKey().trim().toLowerCase();
+            insertSqlBuilder.append(key).append(", ");
+            valueBuilder.append("'").append(entry.getValue().toString()).append("', ");
+        }
         insertSqlBuilder.delete(insertSqlBuilder.length() - 2, insertSqlBuilder.length());
         valueBuilder.delete(valueBuilder.length() - 2, valueBuilder.length());
         insertSqlBuilder.append(") values (").append(valueBuilder).append(")");
 //        log.info("鎵ц鎻掑叆 ->{}",insertSqlBuilder.toString());
         // 鎻掑叆鏁版嵁
+//        boolean execute = statement.execute(insertSqlBuilder.toString());
+//        for (int j = 0; j < 10; j++) {
+//            statement = connection.createStatement();
+//            log.info("HIS鏁版嵁淇濆瓨绫� 鎵ц鎻掑叆 ->{}",insertSqlBuilder.toString());
+//            boolean execute = statement.execute(insertSqlBuilder.toString());
+//            log.info("HIS鏁版嵁淇濆瓨绫� 鎵ц鎻掑叆鐘舵�� ->{},娆℃暟->{}",execute,(j+1));
+//            statement.close();
+//            if (execute)
+//                break;
+//        }
         statement = connection.createStatement();
-        statement.execute(insertSqlBuilder.toString());
+        log.info("HIS鏁版嵁淇濆瓨绫� 鎵ц鎻掑叆 ->{}",insertSqlBuilder.toString());
+        boolean execute = statement.execute(insertSqlBuilder.toString());
+        if (!execute){
+            int updateCount = statement.getUpdateCount();
+            log.info("HIS鏁版嵁淇濆瓨绫� 鎵ц鎻掑叆鎴愬姛 褰卞搷琛屾暟->{}",updateCount);
+        }
         statement.close();
+    }
+
+    /**
+     * 鑾峰彇鍒楃被鍨�
+     * @param connection
+     * @param tableName
+     * @param columnName
+     * @return
+     * @throws SQLException
+     */
+    private static String getColumnType(Connection connection, String tableName, String columnName) throws SQLException {
+        String query = "SELECT DATA_TYPE FROM information_schema.COLUMNS WHERE TABLE_NAME = ? AND COLUMN_NAME = ?";
+        try (PreparedStatement statement = connection.prepareStatement(query)) {
+            statement.setString(1, tableName);
+            statement.setString(2, columnName);
+            ResultSet resultSet = statement.executeQuery();
+            if (resultSet.next()) {
+                return resultSet.getString("DATA_TYPE");
+            }
+        }
+        return "";
+    }
+
+    /**
+     * 鑾峰彇鍒楅暱搴�
+     * @param connection
+     * @param tableName
+     * @param columnName
+     * @return
+     * @throws SQLException
+     */
+    private static int getColumnSize(Connection connection, String tableName, String columnName) throws SQLException {
+        String query = "SELECT CHARACTER_MAXIMUM_LENGTH FROM information_schema.COLUMNS WHERE TABLE_NAME = ? AND COLUMN_NAME = ?";
+        try (PreparedStatement statement = connection.prepareStatement(query)) {
+            statement.setString(1, tableName);
+            statement.setString(2, columnName);
+            ResultSet resultSet = statement.executeQuery();
+            if (resultSet.next()) {
+                return resultSet.getInt("CHARACTER_MAXIMUM_LENGTH");
+            }
+        }
+        return 0;
+    }
+
+    /**
+     * 淇敼鍒楅暱搴�
+     * @param connection
+     * @param tableName
+     * @param columnName
+     * @param newSize
+     * @throws SQLException
+     */
+    private static void alterColumnSize(Connection connection, String tableName, String columnName, int newSize) throws SQLException {
+        String alterQuery = String.format("ALTER TABLE %s MODIFY %s VARCHAR(%d)", tableName, columnName, newSize);
+        try (Statement statement = connection.createStatement()) {
+            statement.executeUpdate(alterQuery);
+        }
+    }
+
+    /**
+     * 瓒呰繃闃堝�煎垯淇敼涓簍ext绫诲瀷
+     * @param connection
+     * @param tableName
+     * @param columnName
+     * @throws SQLException
+     */
+    private static void alterColumnTypeToText(Connection connection, String tableName, String columnName) throws SQLException {
+        String alterQuery = String.format("ALTER TABLE %s MODIFY %s TEXT", tableName, columnName);
+        try (Statement statement = connection.createStatement()) {
+            statement.executeUpdate(alterQuery);
+        }
     }
 
     /**
@@ -438,6 +650,7 @@
             sql.append(key).append(" VARCHAR(200) null,");
         }
         sql.append("insert_time").append(" VARCHAR(200) null,");
+        sql.append("request_params").append(" text null COMMENT '璇锋眰鍙傛暟',");
         sql = new StringBuilder(sql.substring(0, sql.length() - 1));
         sql.append(");");
         Statement statement = connection.createStatement();

--
Gitblit v1.8.0