| | |
| | | @Component |
| | | public class DictionaryUtil { |
| | | // private static final String CONFIG_PATH = "/Users/chacca/开发相关/代码/ltkj_peis_sjpt/src/main/resources/config.properties"; |
| | | private static final String CONFIG_PATH = "/Users/chacca/开发相关/代码/ltkj_peis_sjpt/src/main/resources/ltkj.properties"; |
| | | // private static final String CONFIG_PATH = "/Users/chacca/开发相关/代码/ltkj_peis_sjpt/src/main/resources/ltkj.properties"; |
| | | private static final String CONFIG_PATH = "D:\\ltkjprojectconf\\config.properties"; |
| | | private static String BASE_API_URL = ""; |
| | | // 请求代码总集合 |
| | | private static List<String> methods = new ArrayList<>(); |
| | |
| | | |
| | | // 分页每次1000条 |
| | | static { |
| | | try { |
| | | Class.forName("com.mysql.cj.jdbc.Driver"); |
| | | } catch (ClassNotFoundException e) {} |
| | | methods.add("JGDM"); |
| | | methods.add("ZDZYZ"); |
| | | methods.add("YQZD"); |
| | |
| | | return jsonObject; |
| | | } |
| | | |
| | | public void execSync(){ |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 单线程执行 |
| | | * @throws IOException |
| | | */ |
| | | public void exec1() throws IOException { |
| | | log.info("开始执行同步"); |
| | | int size = 1000; |
| | | FileInputStream inputStream = new FileInputStream(CONFIG_PATH); |
| | | Properties props = new Properties(); |
| | |
| | | assert entries != null; |
| | | JSONObject response = entries.getJSONObject("Response"); |
| | | if ("0".equals(response.getStr("ResultCode"))) { |
| | | try { |
| | | dropTable(tabName,connection); |
| | | } catch (SQLException e) { |
| | | log.error("删除表异常 ->{}",e.getMessage()); |
| | | } |
| | | if (isLimit) { |
| | | maxPage = LimitInsertData(connection, tabName, response,name,page); |
| | | log.info("计算页码为 ->{}", maxPage); |
| | |
| | | log.error("{}请求失败 - 请求状态码不为0,请求参数 ->{},请求返回 ->{}", method,object.toString(),response.toString()); |
| | | } |
| | | }); |
| | | log.info("执行同步完毕"); |
| | | } |
| | | |
| | | /** |
| | |
| | | connection.setRequestMethod("POST"); |
| | | connection.setRequestProperty("Accept", "application/json"); |
| | | // connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); |
| | | connection.setRequestProperty("Content-Type", "application/json;utf-8"); |
| | | connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); |
| | | connection.setDoOutput(true); |
| | | OutputStream stream = connection.getOutputStream(); |
| | | stream.write(params.getBytes(StandardCharsets.UTF_8)); |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),StandardCharsets.UTF_8)); |
| | | StringBuilder builder = new StringBuilder(); |
| | | String str; |
| | | while ((str = reader.readLine()) != null) { |
| | |
| | | insertSqlBuilder.append("insert into ").append(tabName).append(" ("); |
| | | selectSqlBuilder.append("select count(1) as count from ").append(tabName).append(" where "); |
| | | for (Map.Entry<String, Object> entry : jsonObject.entrySet()) { |
| | | if (entry.getValue().toString().equals("null")) |
| | | continue; |
| | | insertSqlBuilder.append(entry.getKey()).append(", "); |
| | | valueBuilder.append("'").append(entry.getValue().toString().replaceAll("'","‘")).append("', "); |
| | | selectSqlBuilder.append(entry.getKey()).append(" = '").append(entry.getValue().toString().replaceAll("'","‘")).append("' and "); |
| | |
| | | Statement statement = connection.createStatement(); |
| | | statement.execute(sql.toString()); |
| | | } |
| | | |
| | | /** |
| | | * 删除表 |
| | | * @param tabName |
| | | * @param connection |
| | | * @throws SQLException |
| | | */ |
| | | private void dropTable(String tabName,Connection connection) throws SQLException { |
| | | String sql = "DROP TABLE IF EXISTS " + tabName; |
| | | Statement statement = connection.createStatement(); |
| | | statement.executeUpdate(sql); |
| | | } |
| | | } |