zjh
2024-07-11 201e9ae76d2c8d6219ceabbf4e1ebb36fc2e7a06
ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisApiGetMethodService.java
@@ -1,5 +1,6 @@
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;
@@ -11,6 +12,7 @@
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.Transactional;
@@ -32,8 +34,10 @@
@Slf4j
@Component
public class HisApiGetMethodService {
    // 数据库配置文件路径
    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/开发相关/代码/ltkj_peis/ltkj-admin/src/main/resources/config.properties";
    // 数据库名
    private static String DB_NAME = "";
@@ -46,27 +50,51 @@
    @Autowired
    private HisApiConfigService hisApiConfigService;
    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;
        } catch (IOException e) {
            System.out.println("初始化数据库异常 ->"+e.getMessage());
        }
    }
    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } 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();
//        }
    }
@@ -173,7 +201,7 @@
            return AjaxResult.error().put("result", JSONUtil.parseObj(json));
        }
    }
    @Transactional
    public AjaxResult getHISDataNew(String type, Map<String, Object> params){
        LambdaQueryWrapper<HisApiConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>();
@@ -257,6 +285,13 @@
            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) {
@@ -265,13 +300,9 @@
                statement.executeUpdate(sql);
                statement.close();
            }
            if (hisApiConfig == null)
            insertData(hisApiConfig, connection, jsonObject);
            else insertDataNew(connection, jsonObject,hisApiConfig,paramsJson);
            insertDataNew(connection, jsonObject,hisApiConfig,paramsJson);
        } else {
            if (hisApiConfig == null)
            insertData(hisApiConfig, connection, jsonObject);
            else insertDataNew(connection, jsonObject,hisApiConfig,paramsJson);
            insertDataNew(connection, jsonObject,hisApiConfig,paramsJson);
        }
    }
@@ -393,6 +424,13 @@
        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(")");