From 972bf0eac06314ff10876dba7766c369ebf6ab7e Mon Sep 17 00:00:00 2001 From: zhaowenxuan <chacca165@163.com> Date: 星期一, 03 六月 2024 18:09:18 +0800 Subject: [PATCH] 代码提交 --- src/main/resources/application.properties | 5 src/main/java/com/example/utils/DictionaryUtil.java | 216 +++++++++++++++++++---------------- src/test/java/com/example/ImgCheckApplicationTests.java | 4 pom.xml | 58 +++------ src/main/java/com/example/controller/TestController.java | 20 +++ 5 files changed, 158 insertions(+), 145 deletions(-) diff --git a/pom.xml b/pom.xml index afdf89a..0013b83 100644 --- a/pom.xml +++ b/pom.xml @@ -1,24 +1,30 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-parent</artifactId> + <version>2.5.2</version> + <relativePath/> + </parent> <groupId>com.example</groupId> <artifactId>ltkj_peis_sjpt</artifactId> <version>0.0.1-SNAPSHOT</version> - <name>imgCheck</name> + <name>ltkj_peis_sjpt</name> + <packaging>war</packaging> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> - <spring-boot.version>2.6.13</spring-boot.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> - <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> @@ -34,48 +40,22 @@ <artifactId>mysql-connector-java</artifactId> </dependency> </dependencies> - <dependencyManagement> - <dependencies> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-dependencies</artifactId> - <version>${spring-boot.version}</version> - <type>pom</type> - <scope>import</scope> - </dependency> - </dependencies> - </dependencyManagement> <build> <plugins> <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.8.1</version> - <configuration> - <source>1.8</source> - <target>1.8</target> - <encoding>UTF-8</encoding> - </configuration> - </plugin> - <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> - <version>${spring-boot.version}</version> - <configuration> - <mainClass>com.example.ImgCheckApplication</mainClass> - <skip>true</skip> - </configuration> - <executions> - <execution> - <id>repackage</id> - <goals> - <goal>repackage</goal> - </goals> - </execution> - </executions> </plugin> +<!-- <plugin>--> +<!-- <groupId>org.apache.maven.plugins</groupId>--> +<!-- <artifactId>maven-war-plugin</artifactId>--> +<!-- <version>3.2.2</version>--> +<!-- <configuration>--> +<!-- <failOnMissingWebXml>false</failOnMissingWebXml>--> +<!-- </configuration>--> +<!-- </plugin>--> </plugins> + <finalName>ltkj_peis_sjpt</finalName> </build> - </project> diff --git a/src/main/java/com/example/controller/TestController.java b/src/main/java/com/example/controller/TestController.java new file mode 100644 index 0000000..54e00ae --- /dev/null +++ b/src/main/java/com/example/controller/TestController.java @@ -0,0 +1,20 @@ +package com.example.controller; + +import com.example.utils.DictionaryUtil; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Company: 瑗垮畨璺嘲绉戞妧鏈夐檺鍏徃 + * @Author: zhaowenxuan + * @Date: 2024/6/3 15:25 + */ +@RestController +public class TestController { + @GetMapping("test") + public String test(){ + DictionaryUtil util = new DictionaryUtil(); + util.exec1(); + return "123"; + } +} diff --git a/src/main/java/com/example/utils/DictionaryUtil.java b/src/main/java/com/example/utils/DictionaryUtil.java index cc581e0..08cd5c7 100644 --- a/src/main/java/com/example/utils/DictionaryUtil.java +++ b/src/main/java/com/example/utils/DictionaryUtil.java @@ -1,25 +1,19 @@ package com.example.utils; -import cn.hutool.core.util.RandomUtil; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; +import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; import java.sql.*; import java.text.SimpleDateFormat; -import java.util.ArrayList; +import java.util.*; import java.util.Date; -import java.util.List; -import java.util.Map; /** * @Company: 瑗垮畨璺嘲绉戞妧鏈夐檺鍏徃 @@ -27,13 +21,14 @@ * @Date: 2024/5/21 16:41 */ public class DictionaryUtil { + private static final String CONFIG_PATH = "D:\\ltkjprojectconf\\config.properties"; private static final Logger log = LoggerFactory.getLogger(DictionaryUtil.class); - private static String BASE_API_URL = "https://mock.mengxuegu.com/mock/664d3dbce45d2156fa209c80/example/api/His/HisRequest"; + private static String BASE_API_URL = ""; // 璇锋眰浠g爜鎬婚泦鍚� private static List<String> methods = new ArrayList<>(); - private static final String url = "jdbc:mysql://localhost:3306/test_urlreq"; - private static final String user = "root"; - private static final String password = "Root_ltkj123"; +// private static final String url = "jdbc:mysql://localhost:3306/test_urlreq"; +// private static final String user = "root"; +// private static final String password = "Root_ltkj123"; // 闇�瑕佸垎椤电殑浠g爜闆嗗悎 private static List<String> limits = new ArrayList<>(); @@ -59,7 +54,7 @@ // methods.add("XYZDZD"); // methods.add("ZYZDZD"); // methods.add("SSZD"); -// methods.add("ZLXTXZD"); + methods.add("ZLXTXZD"); // methods.add("ZYZZZFZD"); // methods.add("YJJFXMZD"); // methods.add("EJJFXMZD"); @@ -89,7 +84,7 @@ // methods.add("JCBWFLZD"); // methods.add("JCBWZD"); // methods.add("JCBWMSZD"); -// methods.add("JFXMGLJCBWZD"); + methods.add("JFXMGLJCBWZD"); // methods.add("JFZHXMGLJCBWZD"); // // methods.add("TJDWXZZD"); @@ -140,17 +135,29 @@ public static void main(String[] args) { DictionaryUtil util = new DictionaryUtil(); -// util.exec(); +// String json = "{\"Response\":{\"ResultCode\":\"0\",\"ResultContent\":\"鏌ヨ鎴愬姛\",\"ResultData\":[{\"RowNumber\":1,\"totalCount\":171,\"YLJGDM\":\"43899007-X\",\"YLJGMC\":\"娉惧窛鍘夸汉姘戝尰闄",\"KSDM\":\"0000000002\",\"KSMC\":\"璐ㄦ帶鑲",\"KSPY\":\"ZKG\",\"FLKSDM\":\"0000000001\",\"FLKSMC\":\"鍔炲叕\",\"KSLXDM\":\"0\",\"KSLXMC\":\"鍏敤\",\"BZNCW\":null,\"BZWCW\":null,\"KSJJ\":\"\",\"KSMS\":null,\"KSDZ\":null,\"LXDH\":null,\"ZKDM\":null,\"BQDM\":null,\"YQDM\":null,\"CJRQ\":\"2022-04-15T10:01:06.77\",\"JLZT\":\"0\",\"BZ\":\"\"},{\"RowNumber\":2,\"totalCount\":171,\"YLJGDM\":\"43899007-X\",\"YLJGMC\":\"娉惧窛鍘夸汉姘戝尰闄",\"KSDM\":\"0001\",\"KSMC\":\"鎬诲姟搴撴埧\",\"KSPY\":\"ZWKF\",\"FLKSDM\":\"01\",\"FLKSMC\":\"鍖荤枟\",\"KSLXDM\":\"0\",\"KSLXMC\":\"鍏敤\",\"BZNCW\":null,\"BZWCW\":null,\"KSJJ\":\"\",\"KSMS\":\"\",\"KSDZ\":null,\"LXDH\":\"\",\"ZKDM\":null,\"BQDM\":null,\"YQDM\":null,\"CJRQ\":\"2022-04-15T10:01:06.77\",\"JLZT\":\"0\",\"BZ\":\"\"},{\"RowNumber\":3,\"totalCount\":171,\"YLJGDM\":\"43899007-X\",\"YLJGMC\":\"娉惧窛鍘夸汉姘戝尰闄",\"KSDM\":\"0002\",\"KSMC\":\"瑗胯嵂搴撴埧\",\"KSPY\":\"XYKF\",\"FLKSDM\":\"01\",\"FLKSMC\":\"鍖荤枟\",\"KSLXDM\":\"0\",\"KSLXMC\":\"鍏敤\",\"BZNCW\":null,\"BZWCW\":null,\"KSJJ\":null,\"KSMS\":null,\"KSDZ\":null,\"LXDH\":null,\"ZKDM\":null,\"BQDM\":null,\"YQDM\":null,\"CJRQ\":\"2022-04-15T10:01:06.77\",\"JLZT\":\"0\",\"BZ\":\"\"},{\"RowNumber\":4,\"totalCount\":171,\"YLJGDM\":\"43899007-X\",\"YLJGMC\":\"娉惧窛鍘夸汉姘戝尰闄",\"KSDM\":\"0003\",\"KSMC\":\"闂ㄨ瘖瑗胯嵂鎴縗",\"KSPY\":\"MZXYF\",\"FLKSDM\":\"01\",\"FLKSMC\":\"鍖荤枟\",\"KSLXDM\":\"0\",\"KSLXMC\":\"鍏敤\",\"BZNCW\":null,\"BZWCW\":null,\"KSJJ\":\"\",\"KSMS\":\"闂ㄨ瘖涓�妤艰タ鑽埧鍙栬嵂\",\"KSDZ\":null,\"LXDH\":null,\"ZKDM\":null,\"BQDM\":null,\"YQDM\":null,\"CJRQ\":\"2022-04-15T10:01:06.77\",\"JLZT\":\"0\",\"BZ\":\"\"},{\"RowNumber\":5,\"totalCount\":171,\"YLJGDM\":\"43899007-X\",\"YLJGMC\":\"娉惧窛鍘夸汉姘戝尰闄",\"KSDM\":\"0004\",\"KSMC\":\"闂ㄨ瘖涓嵂鎴縗",\"KSPY\":\"MZZYF\",\"FLKSDM\":\"01\",\"FLKSMC\":\"鍖荤枟\",\"KSLXDM\":\"0\",\"KSLXMC\":\"鍏敤\",\"BZNCW\":null,\"BZWCW\":null,\"KSJJ\":\"\",\"KSMS\":\"闂ㄨ瘖涓�妤间腑鑽埧鍙栬嵂\",\"KSDZ\":null,\"LXDH\":null,\"ZKDM\":null,\"BQDM\":null,\"YQDM\":null,\"CJRQ\":\"2022-04-15T10:01:06.77\",\"JLZT\":\"0\",\"BZ\":\"\"},{\"RowNumber\":6,\"totalCount\":171,\"YLJGDM\":\"43899007-X\",\"YLJGMC\":\"娉惧窛鍘夸汉姘戝尰闄",\"KSDM\":\"0005\",\"KSMC\":\"浣忛櫌鑽埧\",\"KSPY\":\"ZYYF\",\"FLKSDM\":\"01\",\"FLKSMC\":\"鍖荤枟\",\"KSLXDM\":\"0\",\"KSLXMC\":\"鍏敤\",\"BZNCW\":null,\"BZWCW\":null,\"KSJJ\":\"\",\"KSMS\":\"浣忛櫌閮ㄤ簩妤艰嵂鎴垮彇鑽痋",\"KSDZ\":null,\"LXDH\":null,\"ZKDM\":null,\"BQDM\":null,\"YQDM\":null,\"CJRQ\":\"2022-04-15T10:01:06.77\",\"JLZT\":\"0\",\"BZ\":\"\"},{\"RowNumber\":7,\"totalCount\":171,\"YLJGDM\":\"43899007-X\",\"YLJGMC\":\"娉惧窛鍘夸汉姘戝尰闄",\"KSDM\":\"0006\",\"KSMC\":\"鍔炲叕瀹",\"KSPY\":\"BGS\",\"FLKSDM\":\"01\",\"FLKSMC\":\"鍖荤枟\",\"KSLXDM\":\"0\",\"KSLXMC\":\"鍏敤\",\"BZNCW\":null,\"BZWCW\":null,\"KSJJ\":null,\"KSMS\":null,\"KSDZ\":null,\"LXDH\":null,\"ZKDM\":null,\"BQDM\":null,\"YQDM\":null,\"CJRQ\":\"2022-04-15T10:01:06.77\",\"JLZT\":\"0\",\"BZ\":\"\"},{\"RowNumber\":8,\"totalCount\":171,\"YLJGDM\":\"43899007-X\",\"YLJGMC\":\"娉惧窛鍘夸汉姘戝尰闄",\"KSDM\":\"0007\",\"KSMC\":\"鎬诲姟鑲",\"KSPY\":\"ZWG\",\"FLKSDM\":\"01\",\"FLKSMC\":\"鍖荤枟\",\"KSLXDM\":\"0\",\"KSLXMC\":\"鍏敤\",\"BZNCW\":null,\"BZWCW\":null,\"KSJJ\":null,\"KSMS\":null,\"KSDZ\":null,\"LXDH\":null,\"ZKDM\":null,\"BQDM\":null,\"YQDM\":null,\"CJRQ\":\"2022-04-15T10:01:06.77\",\"JLZT\":\"0\",\"BZ\":\"\"},{\"RowNumber\":9,\"totalCount\":171,\"YLJGDM\":\"43899007-X\",\"YLJGMC\":\"娉惧窛鍘夸汉姘戝尰闄",\"KSDM\":\"0008\",\"KSMC\":\"鍖诲姟鑲",\"KSPY\":\"YWG\",\"FLKSDM\":\"01\",\"FLKSMC\":\"鍖荤枟\",\"KSLXDM\":\"0\",\"KSLXMC\":\"鍏敤\",\"BZNCW\":null,\"BZWCW\":null,\"KSJJ\":null,\"KSMS\":null,\"KSDZ\":null,\"LXDH\":null,\"ZKDM\":null,\"BQDM\":null,\"YQDM\":null,\"CJRQ\":\"2022-04-15T10:01:06.77\",\"JLZT\":\"0\",\"BZ\":\"\"},{\"RowNumber\":10,\"totalCount\":171,\"YLJGDM\":\"43899007-X\",\"YLJGMC\":\"娉惧窛鍘夸汉姘戝尰闄",\"KSDM\":\"0009\",\"KSMC\":\"闂ㄨ瘖鏀惰垂瀹",\"KSPY\":\"MZSFS\",\"FLKSDM\":\"01\",\"FLKSMC\":\"鍖荤枟\",\"KSLXDM\":\"0\",\"KSLXMC\":\"鍏敤\",\"BZNCW\":null,\"BZWCW\":null,\"KSJJ\":\"\",\"KSMS\":\"闂ㄨ瘖妤间竴妤笺�侀棬璇婃ゼ浜屾ゼ缂磋垂\",\"KSDZ\":null,\"LXDH\":null,\"ZKDM\":null,\"BQDM\":null,\"YQDM\":null,\"CJRQ\":\"2022-04-15T10:01:06.77\",\"JLZT\":\"0\",\"BZ\":\"\"}]}}"; util.exec1(); +// Connection connection = util.getConnection(); +// String tabName = "ltkj_kszd"; +// JSONObject entries = JSONUtil.parseObj(json); +// util.LimitInsertData(connection,tabName,entries.getJSONObject("Response")); } - private void exec1() { + public JSONObject addInputVal(JSONObject jsonObject){ + JSONObject obj = JSONUtil.createObj(); + obj.putOpt("jgbm",""); + obj.putOpt("bm",""); + obj.putOpt("flbm",""); + jsonObject.putOpt("input",obj); + return jsonObject; + } + + public void exec1() { int size = 1000; Connection connection = getConnection(); methods.forEach(method -> { - System.out.println("寰潖鐨勬帴鍙d唬鐮� ->" + method); - String tabName = "ltkj_" + method; -// String params = "method="+method; + log.info("寮�濮嬭姹備唬鐮� ->{}",method); + String tabName = "ltkj_" + method.toLowerCase(); boolean isLimit = false; int page = 1; int maxPage = 1; @@ -158,12 +165,13 @@ object.putOpt("method", method); if (limits.contains(method)) { isLimit = true; -// params+="&pagecount="+size+"&page="+page; object.putOpt("pagecount", size); object.putOpt("page", page); } + object = addInputVal(object); + log.info("璇锋眰鎺ュ彛 ->{},璇锋眰鍙傛暟 ->{}",BASE_API_URL,object.toString()); JSONObject entries = execRequest(object.toString()); -// JSONObject entries = execRequest(params); + log.info("璇锋眰杩斿洖 ->{}",entries.toString()); assert entries != null; JSONObject response = entries.getJSONObject("Response"); if ("0".equals(response.getStr("ResultCode"))) { @@ -173,20 +181,19 @@ if (maxPage > 1) { page += 1; for (int i = page; i <= maxPage; i++) { -// params+="&pagecount="+size+"&page="+page; object.clear(); object.putOpt("method", method); object.putOpt("pagecount", size); object.putOpt("page", page); -// entries = execRequest(params); + object = addInputVal(object); + log.info("璇锋眰鎺ュ彛 ->{},璇锋眰鍙傛暟 ->{}",BASE_API_URL,object.toString()); entries = execRequest(object.toString()); - assert entries != null; + log.info("璇锋眰杩斿洖 ->{}",entries.toString()); response = entries.getJSONObject("Response"); if ("0".equals(response.getStr("ResultCode"))) { LimitInsertData(connection, tabName, response); } else { -// log.error("璇锋眰澶辫触锛�"+params); - log.error("璇锋眰澶辫触锛�" + object.toString()); + log.error("{} 璇锋眰澶辫触锛歿}",method,object.toString()); } page++; } @@ -197,8 +204,7 @@ editDataBase(connection, tabName, resultData, jsonObject); } } else { -// log.error("璇锋眰澶辫触锛�"+params); - log.error("璇锋眰澶辫触锛�" + object.toString()); + log.error("{}璇锋眰澶辫触 - 璇锋眰鐘舵�佺爜涓嶄负0锛歿}", method,object.toString()); } }); } @@ -212,14 +218,15 @@ * @return */ private int LimitInsertData(Connection connection, String tabName, JSONObject response) { - int maxPage; - // 琛屾暟 - Integer rowNumber = response.getInt("RowNumber"); - // 鎬绘潯鏁� - Integer totalCount = response.getInt("totalCount"); JSONArray jsonArray = response.getJSONArray("ResultData"); + JSONObject entries = (JSONObject) jsonArray.get(0); + int maxPage; + // 琛屾暟 鏁版嵁杩斿洖鐨勭鍑犺 + Integer rowNumber = entries.getInt("RowNumber"); + // 鎬绘潯鏁� + Integer totalCount = entries.getInt("totalCount"); maxPage = (totalCount + 1000 - 1) / 1000; - System.out.println("闆嗗悎澶у皬 ->" + jsonArray.size()); + log.info("璇锋眰杩斿洖闆嗗悎澶у皬 ->{},鎬婚〉鏁� ->{}",jsonArray.size(),maxPage); jsonArray.forEach(obj -> { editDataBase(connection, tabName, jsonArray, (JSONObject) obj); }); @@ -249,30 +256,30 @@ } } - private void exec() { - JSONObject entries = execRequest(); - if (entries != null) { - JSONObject response = entries.getJSONObject("Response"); - // 0 鎴愬姛 -1澶辫触 - if ("0".equals(response.getStr("ResultCode"))) { - JSONArray jsonArray = response.getJSONArray("ResultData"); - JSONObject resultDataIndex1 = jsonArray.getJSONObject(0); - String method = entries.getStr("method"); - String tabName = "ltkj_" + method; - Connection connection = getConnection(); - try { - if (!tabIsExists(connection, tabName)) { - // 鍒涘缓琛� - creatTable(resultDataIndex1, tabName, connection); - } - // 瀵规瘮瀛楁 骞舵彃鍏ユ暟鎹� - operationTable((JSONObject) jsonArray.get(0), tabName, connection); - } catch (SQLException throwables) { - throwables.printStackTrace(); - } - } - } - } +// private void exec() { +// JSONObject entries = execRequest(); +// if (entries != null) { +// JSONObject response = entries.getJSONObject("Response"); +// // 0 鎴愬姛 -1澶辫触 +// if ("0".equals(response.getStr("ResultCode"))) { +// JSONArray jsonArray = response.getJSONArray("ResultData"); +// JSONObject resultDataIndex1 = jsonArray.getJSONObject(0); +// String method = entries.getStr("method"); +// String tabName = "ltkj_" + method; +// Connection connection = getConnection(); +// try { +// if (!tabIsExists(connection, tabName)) { +// // 鍒涘缓琛� +// creatTable(resultDataIndex1, tabName, connection); +// } +// // 瀵规瘮瀛楁 骞舵彃鍏ユ暟鎹� +// operationTable((JSONObject) jsonArray.get(0), tabName, connection); +// } catch (SQLException throwables) { +// throwables.printStackTrace(); +// } +// } +// } +// } /** * 鎵цpost璇锋眰 @@ -285,7 +292,6 @@ URL url = null; HttpURLConnection connection = null; try { - BASE_API_URL = "http://localhost:5011/api/His/HisRequest"; url = new URL(BASE_API_URL); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); @@ -295,15 +301,12 @@ connection.setDoOutput(true); OutputStream stream = connection.getOutputStream(); stream.write(params.getBytes(StandardCharsets.UTF_8)); -// System.out.println(connection.getResponseCode()); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder builder = new StringBuilder(); String str; while ((str = reader.readLine()) != null) { builder.append(str); } - log.info("璇锋眰鍙傛暟 ->{}", params); -// log.info("鎵ц璇锋眰鍝嶅簲锛歿}", builder.toString()); return JSONUtil.parseObj(builder.toString()); } catch (IOException e) { e.printStackTrace(); @@ -320,48 +323,60 @@ * * @return */ - private JSONObject execRequest() { - URL url = null; - HttpURLConnection connection = null; - try { - url = new URL(BASE_API_URL); - connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("POST"); - connection.setDoOutput(true); - connection.setRequestProperty("Accept", "application/json"); - connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - OutputStream stream = connection.getOutputStream(); - int index = 0; - if (methods.size() > 1) { - index = RandomUtil.randomInt(0, methods.size() - 1); - } - String method = methods.get(index); - String param = "method=" + method; - stream.write(param.getBytes(StandardCharsets.UTF_8)); - BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - StringBuilder builder = new StringBuilder(); - String str; - while ((str = reader.readLine()) != null) { - builder.append(str); - } - log.info("鎵ц璇锋眰鍝嶅簲锛歿}", builder.toString()); - JSONObject entries = JSONUtil.parseObj(builder.toString()); - entries.set("method", method); - return entries; - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (connection != null) { - connection.disconnect(); - } - } - return null; - } +// private JSONObject execRequest() { +// URL url = null; +// HttpURLConnection connection = null; +// try { +// url = new URL(BASE_API_URL); +// connection = (HttpURLConnection) url.openConnection(); +// connection.setRequestMethod("POST"); +// connection.setDoOutput(true); +// connection.setRequestProperty("Accept", "application/json"); +// connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); +// OutputStream stream = connection.getOutputStream(); +// int index = 0; +// if (methods.size() > 1) { +// index = RandomUtil.randomInt(0, methods.size() - 1); +// } +// String method = methods.get(index); +// String param = "method=" + method; +// stream.write(param.getBytes(StandardCharsets.UTF_8)); +// BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); +// StringBuilder builder = new StringBuilder(); +// String str; +// while ((str = reader.readLine()) != null) { +// builder.append(str); +// } +// log.info("鎵ц璇锋眰鍝嶅簲锛歿}", builder.toString()); +// JSONObject entries = JSONUtil.parseObj(builder.toString()); +// entries.set("method", method); +// return entries; +// } catch (IOException e) { +// e.printStackTrace(); +// } finally { +// if (connection != null) { +// connection.disconnect(); +// } +// } +// return null; +// } private Connection getConnection() { try { + FileInputStream inputStream = new FileInputStream(CONFIG_PATH); + Properties props = new Properties(); + props.load(inputStream); + String name = props.getProperty("name"); + String url = "jdbc:mysql://" + props.getProperty("ip") + ":" + props.getProperty("prot") + "/" + name + "" + + "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8"; + String user = props.getProperty("username"); + String password = props.getProperty("password"); + String apiUrl = props.getProperty("his_api_url"); + String apiPort = props.getProperty("his_api_port"); + BASE_API_URL = apiUrl+":"+apiPort+"/api/His/HisRequest"; return DriverManager.getConnection(url, user, password); - } catch (SQLException throwables) { + } catch (Exception throwables) { + log.error("鑾峰彇sql杩炴帴澶辫触"); throwables.printStackTrace(); } return null; @@ -427,7 +442,6 @@ * @throws SQLException */ private void insertData(String tabName, Connection connection, JSONObject jsonObject) throws SQLException { -// System.out.println("jsonObject = " + jsonObject); // 鎻掑叆鏁版嵁鍓� 鍏堟煡璇㈡暟鎹槸鍚﹀瓨鍦� StringBuilder selectSqlBuilder = new StringBuilder(); StringBuilder insertSqlBuilder = new StringBuilder(); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2eeb8b2..1633702 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,4 +1,3 @@ # 搴旂敤鏈嶅姟 WEB 璁块棶绔彛 -server.port=8080 -img.local.path=E:\\mycode\\img -img.server.path= +server.port=14765 +server.servlet.context-path=/ diff --git a/src/test/java/com/example/ImgCheckApplicationTests.java b/src/test/java/com/example/ImgCheckApplicationTests.java index 991fde3..6c95db4 100644 --- a/src/test/java/com/example/ImgCheckApplicationTests.java +++ b/src/test/java/com/example/ImgCheckApplicationTests.java @@ -1,9 +1,9 @@ package com.example; import org.junit.jupiter.api.Test; -//import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest; -//@SpringBootTest +@SpringBootTest class ImgCheckApplicationTests { @Test -- Gitblit v1.8.0