| | |
| | | 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; |
| | |
| | | @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 = ""; |
| | |
| | | @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(); |
| | | // } |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | // @Transactional |
| | | public AjaxResult getHISDataNew(String type, Map<String, Object> params){ |
| | | LambdaQueryWrapper<HisApiConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | lambdaQueryWrapper.eq(HisApiConfig::getApiMethod, type); |
| | |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | return AjaxResult.error(); |
| | | } |
| | | try { |
| | | connection.close(); |
| | | } catch (SQLException ignored) { |
| | | }finally { |
| | | try { |
| | | connection.close(); |
| | | } catch (SQLException ignored) { |
| | | } |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | |
| | | * @param jsonObject |
| | | * @throws SQLException |
| | | */ |
| | | @Transactional |
| | | private void insertDataNew(Connection connection, JSONObject jsonObject,HisApiConfig hisApiConfig,String paramsJson) throws SQLException { |
| | | List<String> primaryKesList = Arrays.stream(hisApiConfig.getPrimaryKeys().split(",")).map(String::toLowerCase).collect(Collectors.toList()); |
| | | StringBuilder deleteSqlBuilder = new StringBuilder(); |
| | |
| | | } |
| | | 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, "); |
| | |
| | | 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(); |
| | | } |
| | | |