From cffd87559f2e9343ce3e5dcc5d2953272a244253 Mon Sep 17 00:00:00 2001 From: zjh <1084500556@qq.com> Date: 星期二, 24 十二月 2024 18:41:05 +0800 Subject: [PATCH] 2024-12-24 --- src/main/resources/mapper/TjFlowingWaterHisMapper.xml | 17 src/main/java/com/example/mapper/TjFlowingWaterHisMapper.java | 18 src/main/java/com/example/controller/PacsController.java | 36 src/main/java/com/example/utils/synczd/DictionaryUtilShanXiXiAnMeiJiYy.java | 460 ++++++++ src/main/java/com/example/domain/HisSyncDict.java | 6 src/main/java/com/example/service/impl/TjFlowingWaterHisServiceImpl.java | 22 src/main/resources/mapper/HisSyncDictMapper.xml | 5 src/main/java/com/example/constant/ApiParamsConstants.java | 9 src/main/java/com/example/service/PacsService.java | 10 src/main/java/com/example/utils/DictionaryUtilNew.java | 938 ++++++++-------- src/main/java/com/example/constant/HttpStatus.java | 93 + src/main/java/com/example/scheudleds/DictSyncCommon.java | 11 src/main/java/com/example/service/shanxiqin/xian/MeiJiPacsService.java | 24 src/main/java/com/example/utils/AjaxResult.java | 172 +++ src/main/java/com/example/config/ConfigValue.java | 16 src/main/java/com/example/service/TjFlowingWaterHisService.java | 13 src/main/java/com/example/controller/HisController.java | 124 + src/main/java/com/example/domain/TjFlowingWaterHis.java | 40 src/main/java/com/example/factory/ServiceFactory.java | 33 src/test/java/com/example/ImgCheckApplicationTests.java | 48 src/main/java/com/example/scheudleds/DictSync.java | 98 src/main/java/com/example/mapper/HisSyncDictMapper.java | 2 src/main/java/com/example/service/HisService.java | 8 /dev/null | 397 ------- src/main/java/com/example/config/DruidConfig.java | 2 src/main/java/com/example/service/shanxiqin/xian/MeiJiHisService.java | 305 ++++- src/main/java/com/example/utils/HttpClientUtils.java | 6 src/main/java/com/example/controller/TestController.java | 244 ++-- 28 files changed, 1,970 insertions(+), 1,187 deletions(-) diff --git a/src/main/java/com/example/config/ConfigValue.java b/src/main/java/com/example/config/ConfigValue.java index 7b58bd2..0add26b 100644 --- a/src/main/java/com/example/config/ConfigValue.java +++ b/src/main/java/com/example/config/ConfigValue.java @@ -51,4 +51,20 @@ public String getConfigValue(String key) { return configMap.get(key); } + + public void refresh(){ + HashMap<String, String> hashMap = new HashMap<>(); + Properties props = new Properties(); + FileInputStream fis = null; + try { + fis = new FileInputStream(CONFIG_PATH); + props.load(fis); + fis.close(); + for (String key : props.stringPropertyNames()) { + hashMap.put(key, props.getProperty(key)); + } + configMap = hashMap; + } catch (IOException ignored) { + } + } } diff --git a/src/main/java/com/example/config/DruidConfig.java b/src/main/java/com/example/config/DruidConfig.java index a444748..18d345d 100644 --- a/src/main/java/com/example/config/DruidConfig.java +++ b/src/main/java/com/example/config/DruidConfig.java @@ -46,7 +46,7 @@ Properties properties = new Properties(); // 杩欓噷鏄祴璇曞啓娉曪紝鍏蜂綋鐨剉alue鍙互閫氳繃璇锋眰鍙傛暟浼犻�掕繃鏉� properties.setProperty("druid.url","jdbc:mysql://"+configMap.get("ip")+":"+configMap.get("prot")+"/"+configMap.get("name")+"" + - "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8"); + "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true"); properties.setProperty("druid.username",configMap.get("username")); properties.setProperty("druid.password",configMap.get("password")); dataSource.restart(properties); diff --git a/src/main/java/com/example/constant/ApiParamsConstants.java b/src/main/java/com/example/constant/ApiParamsConstants.java index ac208ad..4e41633 100644 --- a/src/main/java/com/example/constant/ApiParamsConstants.java +++ b/src/main/java/com/example/constant/ApiParamsConstants.java @@ -19,6 +19,11 @@ public static final String CARD_ID = "cardId"; /** + * 浣撴鍙� + */ + public static final String Tj_NUM = "tjNum"; + + /** * 鐥呬汉濮撳悕 */ public static final String CUS_NAME = "cusName"; @@ -137,6 +142,10 @@ */ public static final String CUS_ACCOUNT_ID = "cusAccountId"; + public static final String YE_WU_LEIXING = "yeWuLx"; + + public static final String HOSPITAL = "hospital"; + /** * 鍏叡鏌ヨkey */ diff --git a/src/main/java/com/example/constant/HttpStatus.java b/src/main/java/com/example/constant/HttpStatus.java new file mode 100644 index 0000000..1478ca9 --- /dev/null +++ b/src/main/java/com/example/constant/HttpStatus.java @@ -0,0 +1,93 @@ +package com.example.constant; + +/** + * 杩斿洖鐘舵�佺爜 + * + * @author ltkj + */ +public class HttpStatus { + /** + * 鎿嶄綔鎴愬姛 + */ + public static final int SUCCESS = 200; + + /** + * 瀵硅薄鍒涘缓鎴愬姛 + */ + public static final int CREATED = 201; + + /** + * 璇锋眰宸茬粡琚帴鍙� + */ + public static final int ACCEPTED = 202; + + /** + * 鎿嶄綔宸茬粡鎵ц鎴愬姛锛屼絾鏄病鏈夎繑鍥炴暟鎹� + */ + public static final int NO_CONTENT = 204; + + /** + * 璧勬簮宸茶绉婚櫎 + */ + public static final int MOVED_PERM = 301; + + /** + * 閲嶅畾鍚� + */ + public static final int SEE_OTHER = 303; + + /** + * 璧勬簮娌℃湁琚慨鏀� + */ + public static final int NOT_MODIFIED = 304; + + /** + * 鍙傛暟鍒楄〃閿欒锛堢己灏戯紝鏍煎紡涓嶅尮閰嶏級 + */ + public static final int BAD_REQUEST = 400; + + /** + * 鏈巿鏉� + */ + public static final int UNAUTHORIZED = 401; + + /** + * 璁块棶鍙楅檺锛屾巿鏉冭繃鏈� + */ + public static final int FORBIDDEN = 403; + + /** + * 璧勬簮锛屾湇鍔℃湭鎵惧埌 + */ + public static final int NOT_FOUND = 404; + + /** + * 涓嶅厑璁哥殑http鏂规硶 + */ + public static final int BAD_METHOD = 405; + + /** + * 璧勬簮鍐茬獊锛屾垨鑰呰祫婧愯閿� + */ + public static final int CONFLICT = 409; + + /** + * 涓嶆敮鎸佺殑鏁版嵁锛屽獟浣撶被鍨� + */ + public static final int UNSUPPORTED_TYPE = 415; + + /** + * 绯荤粺鍐呴儴閿欒 + */ + public static final int ERROR = 500; + + /** + * 鎺ュ彛鏈疄鐜� + */ + public static final int NOT_IMPLEMENTED = 501; + + /** + * 绯荤粺璀﹀憡娑堟伅 + */ + public static final int WARN = 601; +} diff --git a/src/main/java/com/example/controller/HisController.java b/src/main/java/com/example/controller/HisController.java index 0f94c7b..9839c64 100644 --- a/src/main/java/com/example/controller/HisController.java +++ b/src/main/java/com/example/controller/HisController.java @@ -6,10 +6,7 @@ import com.example.factory.ServiceFactory; import com.example.service.HisService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Map; @@ -25,163 +22,190 @@ public class HisController { private final ServiceFactory serviceFactory; - private final HisService hisService; @Autowired public HisController(ServiceFactory serviceFactory) { this.serviceFactory = serviceFactory; - hisService= serviceFactory.getService(); + } + + @GetMapping("/{hospName}/test") + public String test(@PathVariable("hospName") String hospName){ + HisService hisService = serviceFactory.getService(hospName); + hisService.syncDict(hospName); + return "test"; } /** * 寤烘。 */ - @PostMapping("creat") - public String jianDang (@RequestBody Map<String ,Object> map) { + @PostMapping("/{hospName}/creat") + public String jianDang (@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map) { + HisService hisService = serviceFactory.getService(hospName); return hisService.jianDang(map); } /** * 楠岃瘉韬唤璇佹槸鍚﹀缓杩囨。 */ - @PostMapping("isCreat") - public String getBingRenXxByShengFenZheng (@RequestBody Map<String ,Object> map) { + @PostMapping("/{hospName}/isCreat") + public String getBingRenXxByShengFenZheng (@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map) { + HisService hisService = serviceFactory.getService(hospName); return hisService.getBingRenXxByShengFenZheng(map); } /** * 鐥呬汉鍩烘湰淇℃伅鍙樻洿 */ - @PostMapping("update") - public String saveBingRenXx (@RequestBody Map<String ,Object> map) { + @PostMapping("/{hospName}/update") + public String saveBingRenXx (@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map) { + HisService hisService = serviceFactory.getService(hospName); return hisService.saveBingRenXx(map); } /** * 寰呮敹璐硅垂鐢ㄦ煡璇� */ - @PostMapping("getPendingPaymentList") - public String getListDaiShouFei (@RequestBody Map<String ,Object> map) { + @PostMapping("/{hospName}/getPendingPaymentList") + public String getListDaiShouFei (@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map) { + HisService hisService = serviceFactory.getService(hospName); return hisService.getListDaiShouFei(map); } /** * 鐢熸垚寰呮敹璐�/寰呴��璐� 璐圭敤 */ - @PostMapping("creatCostInfo") - public String createMenZhenFy (@RequestBody Map<String ,Object> map) { + @PostMapping("/{hospName}/creatCostInfo") + public String createMenZhenFy (@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map) { + HisService hisService = serviceFactory.getService(hospName); return hisService.createMenZhenFy(map); } /** * 闂ㄨ瘖鏈敹璐硅垂鐢ㄦ挙閿� */ - @PostMapping("revokeCost") - public String cheXiaoMzFy (@RequestBody Map<String ,Object> map) { + @PostMapping("/{hospName}/revokeCost") + public String cheXiaoMzFy (@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map) { + HisService hisService = serviceFactory.getService(hospName); return hisService.cheXiaoMzFy(map); - } - - /** - * 鏀惰垂/閫�璐瑰畬鎴愰�氱煡绗笁鏂� - */ - @PostMapping("pushPayMsg") - public String pushZhiFuMsg (@RequestBody Map<String ,Object> map) { - return hisService.pushZhiFuMsg(map); } /** * 绉戝淇℃伅鏌ヨ */ - @PostMapping("getKeShiList") - public String getKeShi (@RequestBody Map<String ,Object> map) { + @PostMapping("/{hospName}/getKeShiList") + public String getKeShi (@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map) { + HisService hisService = serviceFactory.getService(hospName); return hisService.getKeShi(map); } /** * 鍖荤敓淇℃伅鏌ヨ */ - @PostMapping("getYiShengList") - public String getListYiShengZd (@RequestBody Map<String ,Object> map) { + @PostMapping("/{hospName}/getYiShengList") + public String getListYiShengZd (@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map) { + HisService hisService = serviceFactory.getService(hospName); return hisService.getListYiShengZd(map); } /** * 鑾峰彇鏀惰垂椤圭洰鍒嗛〉 */ - @PostMapping("getShouFeiXmList") - public String getShouFeiXm (@RequestBody Map<String ,Object> map) { + @PostMapping("/{hospName}/getShouFeiXmList") + public String getShouFeiXm (@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map) { + HisService hisService = serviceFactory.getService(hospName); return hisService.getShouFeiXm(map); } /** *绉戝淇℃伅鎺ㄩ�� */ - @PostMapping("getKeShiByConditionsList") - public String getKeShiByConditions (@RequestBody Map<String ,Object> map) { + @PostMapping("/{hospName}/getKeShiByConditionsList") + public String getKeShiByConditions (@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map) { + HisService hisService = serviceFactory.getService(hospName); return hisService.getKeShiByConditions(map); } /** * 鍙栨牱鏈瓧鍏� */ - @PostMapping("getYangBen") - public String getYangBen (@RequestBody Map<String ,Object> map) { + @PostMapping("/{hospName}/getYangBen") + public String getYangBen (@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map) { + HisService hisService = serviceFactory.getService(hospName); return hisService.getYangBen(map); } /** * 鐥呭尯淇℃伅鎺ㄩ�� */ - @PostMapping("getBingQuList") - public String getListBingQuZd (@RequestBody Map<String ,Object> map) { + @PostMapping("/{hospName}/getBingQuList") + public String getListBingQuZd (@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map) { + HisService hisService = serviceFactory.getService(hospName); return hisService.getListBingQuZd(map); } /** * 鑱屸集淇℃伅 */ - @PostMapping("getZhiGongList") - public String getZhiGongPage (@RequestBody Map<String ,Object> map) { + @PostMapping("/{hospName}/getZhiGongList") + public String getZhiGongPage (@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map) { + HisService hisService = serviceFactory.getService(hospName); return hisService.getZhiGongPage(map); } /** * 妫�鏌ラ」鐩� */ - @PostMapping("getJcxm") - public String getJianChaXm (@RequestBody Map<String ,Object> map) { + @PostMapping("/{hospName}/getJcxm") + public String getJianChaXm (@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map) { + HisService hisService = serviceFactory.getService(hospName); return hisService.getJianChaXm(map); } /** * 妫�楠岄」饨帹閫� */ - @PostMapping("getJyxm") - public String getJianYanXm(@RequestBody Map<String ,Object> map){ + @PostMapping("/{hospName}/getJyxm") + public String getJianYanXm(@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map){ + HisService hisService = serviceFactory.getService(hospName); return hisService.getJianYanXm(map); } /** * 妫�楠岄」饨敹璐规帹閫� */ - @PostMapping("getShouFeiXmjg") - public String getShouFeiXmJg(@RequestBody Map<String ,Object> map){ + @PostMapping("/{hospName}/getShouFeiXmjg") + public String getShouFeiXmJg(@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map){ + HisService hisService = serviceFactory.getService(hospName); return hisService.getShouFeiXmJg(map); } /** * 妫�楠屽鍣� */ - @PostMapping("getJyrqList") - public String getRongQi(@RequestBody Map<String ,Object> map){ + @PostMapping("/{hospName}/getJyrqList") + public String getRongQi(@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map){ + HisService hisService = serviceFactory.getService(hospName); return hisService.getRongQi(map); } /** * 妫�楠屾牱鏈� */ - @PostMapping("getJyybList") - public String getJyYangBen(@RequestBody Map<String ,Object> map){ + @PostMapping("/{hospName}/getJyybList") + public String getJyYangBen(@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map){ + HisService hisService = serviceFactory.getService(hospName); return hisService.getJyYangBen(map); } + + /** + * 鏀堕��璐瑰洖璋冩帴鍙� + * @param hospName 鍔ㄦ�佸洯鍖哄悕 鎴戞柟鎻愪緵 + * @param map 鍙傛暟 + * @return + */ + @PostMapping("/{hospName}/pushZhiFuMsg") + public String getPushZhiFuMsg (@PathVariable("hospName") String hospName,@RequestBody Map<String ,Object> map) { + HisService hisService = serviceFactory.getService(hospName); + return hisService.pushZhiFuMsg(hospName,map); + } } diff --git a/src/main/java/com/example/controller/PacsController.java b/src/main/java/com/example/controller/PacsController.java new file mode 100644 index 0000000..6f01225 --- /dev/null +++ b/src/main/java/com/example/controller/PacsController.java @@ -0,0 +1,36 @@ +package com.example.controller; + +import cn.hutool.core.util.XmlUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.example.constant.ApiParamsConstants; +import com.example.factory.ServiceFactory; +import com.example.service.HisService; +import com.example.service.PacsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +@RestController +@RequestMapping("/api/pacs") +public class PacsController { + + private final ServiceFactory serviceFactory; + + @Autowired + public PacsController(ServiceFactory serviceFactory) { + this.serviceFactory = serviceFactory; + } + + + /** + * 3.2.2.鐢宠鍗曟帹閫佹帴鍙� + * @return + */ + @PostMapping("/{hospName}/orderAll") + public String queryOrder(@PathVariable String hospName, @RequestBody String xml){ + PacsService pacsService = serviceFactory.getPacsService(hospName); + return pacsService.orderAdd(xml); + } +} diff --git a/src/main/java/com/example/controller/TestController.java b/src/main/java/com/example/controller/TestController.java index 155fd23..3c379d7 100644 --- a/src/main/java/com/example/controller/TestController.java +++ b/src/main/java/com/example/controller/TestController.java @@ -1,122 +1,122 @@ -package com.example.controller; - -import cn.hutool.json.JSONObject; -import cn.hutool.json.JSONUtil; -import com.example.domain.HisSyncDict; -import com.example.service.HisSyncDictService; -import com.example.utils.DictionaryUtil; -import com.example.utils.DictionaryUtilNew; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import java.io.*; -import java.util.List; - -/** - * @Company: 瑗垮畨璺嘲绉戞妧鏈夐檺鍏徃 - * @Author: zhaowenxuan - * @Date: 2024/6/3 15:25 - */ -@Slf4j -@RestController -public class TestController { - private static final String LOG_PATH = "src/main/resources/log.log"; - @Autowired - private DictionaryUtil dictionaryUtil; - @Autowired - private DictionaryUtilNew dictionaryUtilNew; - @Autowired - private HisSyncDictService hisSyncDictService; - - /** - * 鍏ㄩ儴瀛楀吀鍚屾 - * @return - */ - @GetMapping("exec") - public String exce(){ - // 灏嗘枃浠跺唴瀹硅缃负绌� - FileWriter fileWriter = null; - try { - fileWriter = new FileWriter(LOG_PATH); - fileWriter.write(""); - fileWriter.close(); - } catch (IOException ignored) {} - new Thread(()->{ - // dictionaryUtil.exec1(); - dictionaryUtilNew.exec1(); - }).start(); - return "宸叉彁浜ゆ墽琛�"; - } - - /** - * 鏄剧ず鏃ュ織 - * @return - */ - @GetMapping("/show") - public String showLog() { - StringBuilder logContent = new StringBuilder(); - try (BufferedReader reader = new BufferedReader(new FileReader(LOG_PATH))) { - String line; - while ((line = reader.readLine()) != null) { - logContent.append(line).append("<br>"); - } - return logContent.toString(); - } catch (IOException e) { - log.error("Error reading log file", e); - return e.getMessage(); - } - } - - /** - * 娓呴櫎鏃ュ織 - * @return - */ - @GetMapping("/clear") - public String cleanLog() { - try { - // 灏嗘枃浠跺唴瀹硅缃负绌� - FileWriter fileWriter = new FileWriter(LOG_PATH); - fileWriter.write(""); - fileWriter.close(); - return "Log content cleared successfully."; - } catch (IOException e) { - e.printStackTrace(); - return "Failed to clear log content."; - } - } - - /** - * 鎵嬪姩鍚屾 - * @param data json鏍煎紡 methods涓篠tring闆嗗悎 瀛樺偍瀛楀吀鍚� type涓哄竷灏旂被鍨� 鏄惁娓呯悊鏃ュ織 - * @return - */ - @PostMapping("exec") - public String execPost(@RequestBody String data){ - JSONObject entries = JSONUtil.parseObj(data); - List<String> methods = entries.getBeanList("methods", String.class); - Boolean type = entries.getBool("type"); - if (type){ - FileWriter fileWriter = null; - try { - fileWriter = new FileWriter(LOG_PATH); - fileWriter.write(""); - fileWriter.close(); - } catch (IOException ignored) {} - } - new Thread(()->{ - // dictionaryUtil.exec1(); - dictionaryUtilNew.execMethods(methods); - }).start(); - return "宸叉彁浜ゆ墽琛� 鎻愪氦瀛楀吀涓� ->"+methods+",鏄惁娓呯悊鏃ュ織 ->"+type; - } - - @GetMapping("list") - public String listDict(){ - List<HisSyncDict> list = hisSyncDictService.list(); - JSONObject obj = JSONUtil.createObj(); - obj.putOpt("code",200); - obj.putOpt("data",list); - return obj.toString(); - } -} +//package com.example.controller; +// +//import cn.hutool.json.JSONObject; +//import cn.hutool.json.JSONUtil; +//import com.example.domain.HisSyncDict; +//import com.example.service.HisSyncDictService; +//import com.example.utils.DictionaryUtil; +//import com.example.utils.DictionaryUtilNew; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.web.bind.annotation.*; +// +//import java.io.*; +//import java.util.List; +// +///** +// * @Company: 瑗垮畨璺嘲绉戞妧鏈夐檺鍏徃 +// * @Author: zhaowenxuan +// * @Date: 2024/6/3 15:25 +// */ +//@Slf4j +//@RestController +//public class TestController { +// private static final String LOG_PATH = "src/main/resources/log.log"; +// @Autowired +// private DictionaryUtil dictionaryUtil; +// @Autowired +// private DictionaryUtilNew dictionaryUtilNew; +// @Autowired +// private HisSyncDictService hisSyncDictService; +// +// /** +// * 鍏ㄩ儴瀛楀吀鍚屾 +// * @return +// */ +// @GetMapping("exec") +// public String exce(){ +// // 灏嗘枃浠跺唴瀹硅缃负绌� +// FileWriter fileWriter = null; +// try { +// fileWriter = new FileWriter(LOG_PATH); +// fileWriter.write(""); +// fileWriter.close(); +// } catch (IOException ignored) {} +// new Thread(()->{ +// // dictionaryUtil.exec1(); +// dictionaryUtilNew.exec1(); +// }).start(); +// return "宸叉彁浜ゆ墽琛�"; +// } +// +// /** +// * 鏄剧ず鏃ュ織 +// * @return +// */ +// @GetMapping("/show") +// public String showLog() { +// StringBuilder logContent = new StringBuilder(); +// try (BufferedReader reader = new BufferedReader(new FileReader(LOG_PATH))) { +// String line; +// while ((line = reader.readLine()) != null) { +// logContent.append(line).append("<br>"); +// } +// return logContent.toString(); +// } catch (IOException e) { +// log.error("Error reading log file", e); +// return e.getMessage(); +// } +// } +// +// /** +// * 娓呴櫎鏃ュ織 +// * @return +// */ +// @GetMapping("/clear") +// public String cleanLog() { +// try { +// // 灏嗘枃浠跺唴瀹硅缃负绌� +// FileWriter fileWriter = new FileWriter(LOG_PATH); +// fileWriter.write(""); +// fileWriter.close(); +// return "Log content cleared successfully."; +// } catch (IOException e) { +// e.printStackTrace(); +// return "Failed to clear log content."; +// } +// } +// +// /** +// * 鎵嬪姩鍚屾 +// * @param data json鏍煎紡 methods涓篠tring闆嗗悎 瀛樺偍瀛楀吀鍚� type涓哄竷灏旂被鍨� 鏄惁娓呯悊鏃ュ織 +// * @return +// */ +// @PostMapping("exec") +// public String execPost(@RequestBody String data){ +// JSONObject entries = JSONUtil.parseObj(data); +// List<String> methods = entries.getBeanList("methods", String.class); +// Boolean type = entries.getBool("type"); +// if (type){ +// FileWriter fileWriter = null; +// try { +// fileWriter = new FileWriter(LOG_PATH); +// fileWriter.write(""); +// fileWriter.close(); +// } catch (IOException ignored) {} +// } +// new Thread(()->{ +// // dictionaryUtil.exec1(); +// dictionaryUtilNew.execMethods(methods); +// }).start(); +// return "宸叉彁浜ゆ墽琛� 鎻愪氦瀛楀吀涓� ->"+methods+",鏄惁娓呯悊鏃ュ織 ->"+type; +// } +// +// @GetMapping("list") +// public String listDict(){ +// List<HisSyncDict> list = hisSyncDictService.list(); +// JSONObject obj = JSONUtil.createObj(); +// obj.putOpt("code",200); +// obj.putOpt("data",list); +// return obj.toString(); +// } +//} diff --git a/src/main/java/com/example/domain/HisSyncDict.java b/src/main/java/com/example/domain/HisSyncDict.java index c0f7dfd..272adfd 100644 --- a/src/main/java/com/example/domain/HisSyncDict.java +++ b/src/main/java/com/example/domain/HisSyncDict.java @@ -19,6 +19,12 @@ private Integer isLimit; + private String url; + + private String params; + + private String hospId; + private String remark; private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/example/domain/TjFlowingWaterHis.java b/src/main/java/com/example/domain/TjFlowingWaterHis.java new file mode 100644 index 0000000..f06b308 --- /dev/null +++ b/src/main/java/com/example/domain/TjFlowingWaterHis.java @@ -0,0 +1,40 @@ +package com.example.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import lombok.Data; + +/** + * his璁㈠崟娴佹按鍏宠仈 + * @TableName tj_flowing_water_his + */ +@TableName(value ="tj_flowing_water_his") +@Data +public class TjFlowingWaterHis implements Serializable { + /** + * 缂栧彿 + */ + @TableId + private Long id; + + /** + * 鎬诲紑鍗昳d + */ + private String parentId; + + /** + * 褰撳墠椤圭洰璁㈠崟id + */ + private String currentId; + + /** + * his椤圭洰id + */ + private String xmId; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/example/factory/ServiceFactory.java b/src/main/java/com/example/factory/ServiceFactory.java index 1249a1f..5f8eac4 100644 --- a/src/main/java/com/example/factory/ServiceFactory.java +++ b/src/main/java/com/example/factory/ServiceFactory.java @@ -2,6 +2,7 @@ import com.example.config.ConfigValue; import com.example.service.HisService; +import com.example.service.PacsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; @@ -13,34 +14,30 @@ */ @Component public class ServiceFactory { - private final ConfigValue configValue; private final ApplicationContext applicationContext; - private final String userId; @Autowired - public ServiceFactory(ApplicationContext applicationContext, ConfigValue configValue) { + public ServiceFactory(ApplicationContext applicationContext) { this.applicationContext = applicationContext; - this.configValue = configValue; - try { - this.userId = configValue.getConfigValue("hosp_service"); - } catch (Exception e) { - throw new RuntimeException("閰嶇疆鏂囦欢涓病鏈夐厤缃甴osp_service鍖婚櫌缂栫爜"); - } } - public HisService getService() { - String beanName = getServiceBeanName(userId); + public HisService getService(String hospName) { + String beanName = getServiceBeanName(hospName); return (HisService) applicationContext.getBean(beanName); } - private String getServiceBeanName(String userId) { - switch (userId) { - // 閰嶇疆鏂囦欢涓�� - case "ShanXi_Qin_XiAn_MeiJi": - // 涓氬姟Bean鐨刵ame - return "ShanXiQinXiAnMeiJi"; + public PacsService getPacsService(String hospName) { + String beanName = getServiceBeanName(hospName); + return (PacsService) applicationContext.getBean(beanName+"Pacs"); + } + + + private String getServiceBeanName(String hospName) { + switch (hospName) { + case "shanxiqinxamjyy": + return "ShanXiQinXiAnMeiJi"; // 瀵瑰簲鐨勪笟鍔� Bean 鍚嶇О default: - throw new RuntimeException("鎵句笉鍒板搴旂殑鍖婚櫌缂栫爜鏈嶅姟灞傞厤缃細" + userId); + throw new RuntimeException("鎵句笉鍒板搴旂殑鍖婚櫌鏈嶅姟閰嶇疆锛�" + hospName); } } } diff --git a/src/main/java/com/example/mapper/HisSyncDictMapper.java b/src/main/java/com/example/mapper/HisSyncDictMapper.java index b306231..e4ef12d 100644 --- a/src/main/java/com/example/mapper/HisSyncDictMapper.java +++ b/src/main/java/com/example/mapper/HisSyncDictMapper.java @@ -10,7 +10,7 @@ * @Entity com.example.domain.HisSyncDict */ public interface HisSyncDictMapper extends BaseMapper<HisSyncDict> { - + void proSyncCommonDict(); } diff --git a/src/main/java/com/example/mapper/TjFlowingWaterHisMapper.java b/src/main/java/com/example/mapper/TjFlowingWaterHisMapper.java new file mode 100644 index 0000000..32ac826 --- /dev/null +++ b/src/main/java/com/example/mapper/TjFlowingWaterHisMapper.java @@ -0,0 +1,18 @@ +package com.example.mapper; + +import com.example.domain.TjFlowingWaterHis; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** +* @author 10845 +* @description 閽堝琛ㄣ�恡j_flowing_water_his(his璁㈠崟娴佹按鍏宠仈)銆戠殑鏁版嵁搴撴搷浣淢apper +* @createDate 2024-12-21 15:53:33 +* @Entity com.example.domain.TjFlowingWaterHis +*/ +public interface TjFlowingWaterHisMapper extends BaseMapper<TjFlowingWaterHis> { + +} + + + + diff --git a/src/main/java/com/example/scheudleds/DictSync.java b/src/main/java/com/example/scheudleds/DictSync.java index a66ba58..9185fe6 100644 --- a/src/main/java/com/example/scheudleds/DictSync.java +++ b/src/main/java/com/example/scheudleds/DictSync.java @@ -1,50 +1,50 @@ -package com.example.scheudleds; - -import cn.hutool.core.util.StrUtil; -import com.example.config.ConfigValue; -import com.example.utils.DictionaryUtil; -import com.example.utils.DictionaryUtilNew; -import lombok.extern.slf4j.Slf4j; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -import java.io.FileWriter; -import java.io.IOException; - -@Slf4j -@Component -@EnableScheduling -public class DictSync { - @Autowired - private DictionaryUtil dictionaryUtil; - @Autowired - private DictionaryUtilNew dictionaryUtilNew; - @Autowired - private ConfigValue configValue; - - /** - * 瀛楀吀鍚屾 - */ - @Scheduled(cron = "0 0 22 * * ? ") - public void execDict(){ - String open = configValue.getConfigValue("sjpt_open"); - if (StrUtil.isNotBlank(open) && open.equals("false")) return; - FileWriter fileWriter = null; - try { - fileWriter = new FileWriter("src/main/resources/log.log"); - fileWriter.write(""); - fileWriter.close(); - } catch (IOException ignored) {} +//package com.example.scheudleds; +// +//import cn.hutool.core.util.StrUtil; +//import com.example.config.ConfigValue; +//import com.example.utils.DictionaryUtil; +//import com.example.utils.DictionaryUtilNew; +//import lombok.extern.slf4j.Slf4j; +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.scheduling.annotation.EnableScheduling; +//import org.springframework.scheduling.annotation.Scheduled; +//import org.springframework.stereotype.Component; +// +//import java.io.FileWriter; +//import java.io.IOException; +// +//@Slf4j +//@Component +//@EnableScheduling +//public class DictSync { +// @Autowired +// private DictionaryUtil dictionaryUtil; +// @Autowired +// private DictionaryUtilNew dictionaryUtilNew; +// @Autowired +// private ConfigValue configValue; +// +// /** +// * 瀛楀吀鍚屾 +// */ +// @Scheduled(cron = "0 0 22 * * ? ") +// public void execDict(){ +// String open = configValue.getConfigValue("sjpt_open"); +// if (StrUtil.isNotBlank(open) && open.equals("false")) return; +// FileWriter fileWriter = null; // try { -// dictionaryUtil.exec1(); -// } catch (IOException e) { -// log.error("瀹氭椂浠诲姟寮傚父"); -// e.printStackTrace(); -// } - dictionaryUtilNew.exec1(); - } -} +// fileWriter = new FileWriter("src/main/resources/log.log"); +// fileWriter.write(""); +// fileWriter.close(); +// } catch (IOException ignored) {} +//// try { +//// dictionaryUtil.exec1(); +//// } catch (IOException e) { +//// log.error("瀹氭椂浠诲姟寮傚父"); +//// e.printStackTrace(); +//// } +// dictionaryUtilNew.exec1(); +// } +//} diff --git a/src/main/java/com/example/scheudleds/DictSyncCommon.java b/src/main/java/com/example/scheudleds/DictSyncCommon.java new file mode 100644 index 0000000..31f9fae --- /dev/null +++ b/src/main/java/com/example/scheudleds/DictSyncCommon.java @@ -0,0 +1,11 @@ +package com.example.scheudleds; + + +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class DictSyncCommon { + +} diff --git a/src/main/java/com/example/service/HisService.java b/src/main/java/com/example/service/HisService.java index 16eed8e..93b6779 100644 --- a/src/main/java/com/example/service/HisService.java +++ b/src/main/java/com/example/service/HisService.java @@ -53,7 +53,7 @@ /** * 鏀惰垂/閫�璐瑰畬鎴愰�氱煡绗笁鏂� */ - String pushZhiFuMsg(Map<String ,Object> map); + String pushZhiFuMsg(String hospName,Map<String ,Object> map); /** @@ -122,4 +122,10 @@ * 妫�楠屾牱鏈� */ String getJyYangBen(Map<String ,Object> map); + + + /** + * 鍚屾瀛楀吀 + */ + void syncDict(String hospName); } diff --git a/src/main/java/com/example/service/PacsService.java b/src/main/java/com/example/service/PacsService.java new file mode 100644 index 0000000..ffdbbca --- /dev/null +++ b/src/main/java/com/example/service/PacsService.java @@ -0,0 +1,10 @@ +package com.example.service; + +import org.springframework.stereotype.Service; + +import java.util.Map; + +@Service +public interface PacsService { + String orderAdd(String xml); +} diff --git a/src/main/java/com/example/service/TjFlowingWaterHisService.java b/src/main/java/com/example/service/TjFlowingWaterHisService.java new file mode 100644 index 0000000..bc0b455 --- /dev/null +++ b/src/main/java/com/example/service/TjFlowingWaterHisService.java @@ -0,0 +1,13 @@ +package com.example.service; + +import com.example.domain.TjFlowingWaterHis; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author 10845 +* @description 閽堝琛ㄣ�恡j_flowing_water_his(his璁㈠崟娴佹按鍏宠仈)銆戠殑鏁版嵁搴撴搷浣淪ervice +* @createDate 2024-12-21 15:53:33 +*/ +public interface TjFlowingWaterHisService extends IService<TjFlowingWaterHis> { + +} diff --git a/src/main/java/com/example/service/impl/TjFlowingWaterHisServiceImpl.java b/src/main/java/com/example/service/impl/TjFlowingWaterHisServiceImpl.java new file mode 100644 index 0000000..a280848 --- /dev/null +++ b/src/main/java/com/example/service/impl/TjFlowingWaterHisServiceImpl.java @@ -0,0 +1,22 @@ +package com.example.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.example.domain.TjFlowingWaterHis; +import com.example.service.TjFlowingWaterHisService; +import com.example.mapper.TjFlowingWaterHisMapper; +import org.springframework.stereotype.Service; + +/** +* @author 10845 +* @description 閽堝琛ㄣ�恡j_flowing_water_his(his璁㈠崟娴佹按鍏宠仈)銆戠殑鏁版嵁搴撴搷浣淪ervice瀹炵幇 +* @createDate 2024-12-21 15:53:33 +*/ +@Service +public class TjFlowingWaterHisServiceImpl extends ServiceImpl<TjFlowingWaterHisMapper, TjFlowingWaterHis> + implements TjFlowingWaterHisService{ + +} + + + + diff --git a/src/main/java/com/example/service/shanxiqin/xian/MeiJiHisService.java b/src/main/java/com/example/service/shanxiqin/xian/MeiJiHisService.java index 44176ac..e6a6b43 100644 --- a/src/main/java/com/example/service/shanxiqin/xian/MeiJiHisService.java +++ b/src/main/java/com/example/service/shanxiqin/xian/MeiJiHisService.java @@ -1,23 +1,30 @@ package com.example.service.shanxiqin.xian; -import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSON; +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.example.config.ConfigValue; import com.example.constant.ApiParamsConstants; +import com.example.domain.HisSyncDict; +import com.example.domain.TjFlowingWaterHis; import com.example.service.HisService; -import com.example.service.ISysConfigService; +import com.example.service.HisSyncDictService; +import com.example.service.TjFlowingWaterHisService; +import com.example.utils.AjaxResult; import com.example.utils.FieldNameConverter; import com.example.utils.HttpClientUtils; +import com.example.utils.synczd.DictionaryUtilShanXiXiAnMeiJiYy; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.time.Instant; -import java.time.LocalDateTime; import java.util.*; import java.util.concurrent.TimeUnit; @@ -26,31 +33,37 @@ * @Author: zhaowenxuan * @Date: 2024/12/17 17:17 */ +@Slf4j @Service("ShanXiQinXiAnMeiJi") public class MeiJiHisService implements HisService { -// http://oapi.pbkwyy.com/OAPI/oauth/token + @Autowired + private DictionaryUtilShanXiXiAnMeiJiYy syncZd; + @Autowired + private ConfigValue configValue; + +// http://oapi.xamjyy.com/OAPI/oauth/token // grant_type:client_credentials // client_id:XFZZQEfXTZ7exhhi // client_secret:05a192176c21edfcc9cf5fa26fc5a9e0c5b131ad -// http://oapi.pbkwyy.com/OAPI +// http://oapi.xamjyy.com/OAPI @Autowired public MeiJiHisService(ApplicationContext applicationContext, ConfigValue configValue) { this.applicationContext = applicationContext; this.configValue = configValue; - HIS_URL = configValue.getConfigValue("his_api_url") + ":" + configValue.getConfigValue("his_api_port") + configValue.getConfigValue("hisapiappend"); + HIS_URL = configValue.getConfigValue("ShanXi_Qin_XiAn_MeiJi.his_api_url") + ":" + configValue.getConfigValue("ShanXi_Qin_XiAn_MeiJi.his_api_port") + configValue.getConfigValue("ShanXi_Qin_XiAn_MeiJi.hisapiappend"); + TJ_URL = configValue.getConfigValue("ShanXi_Qin_XiAn_MeiJi.tjUrl"); + CZY = configValue.getConfigValue("ShanXi_Qin_XiAn_MeiJi.czy"); } - - @Autowired - private ISysConfigService configService; @Autowired private RedisTemplate<Object ,Object> redisTemplate; - private ConfigValue configValue; private final ApplicationContext applicationContext; private final String HIS_URL; + private final String TJ_URL; + private final String CZY; //鑾峰彇token private JSONObject getToken () { @@ -63,19 +76,19 @@ map.put("client_id", CLIENT_ID); map.put("client_secret", CLIENT_SECRET); // map.put("scope",SCOP); - String post = sendPostTokenFormUrlencoded (HIS_URL+"/oauth/token", map); +// String post = sendPostTokenFormUrlencoded (HIS_URL+"/oauth/token", map); + String post = HttpClientUtils.sendPostTokenFormUrlencoded(HIS_URL + "/oauth/token", map, null); if (StrUtil.isBlank(post)) return null; return JSONUtil.parseObj(post); } @Override public String jianDang(Map<String, Object> params) { - String czy = configService.selectConfigByKey("dfhisczybm"); Map<String, Object> map = new HashMap<> (); map.put ("jiuZhenKh", params.get(ApiParamsConstants.CARD_ID)); map.put ("kaiLeiXing","4"); map.put ("xingMing", params.get(ApiParamsConstants.CUS_NAME)); - long cusSex = Long.parseLong(map.get(ApiParamsConstants.CUS_SEX).toString()); + long cusSex = Long.parseLong(params.get(ApiParamsConstants.CUS_SEX).toString()); if(cusSex==0L){ map.put ("xingBie","鐢�"); }else if(cusSex==1L){ @@ -83,15 +96,15 @@ }else { map.put ("xingBie","鏈煡"); } - map.put ("shenFenZh", ApiParamsConstants.CUS_ID_CARD); - map.put ("danWeiBh",""); - map.put ("chuShengRq", DateUtil.format((LocalDateTime) map.get(ApiParamsConstants.CUS_BRITHDAY),"yyyy-MM-dd")); - map.put ("lianXiDz", map.get(ApiParamsConstants.CUS_ADDR)); - map.put ("lianXiDh", map.get(ApiParamsConstants.CUS_PHONE)); + map.put ("shenFenZh", params.get(ApiParamsConstants.CUS_ID_CARD)); + map.put ("danWeiBh",params.get(ApiParamsConstants.COMP_ID)); + map.put ("chuShengRq", params.get(ApiParamsConstants.CUS_BRITHDAY)); + map.put ("lianXiDz", params.get(ApiParamsConstants.CUS_ADDR)); + map.put ("lianXiDh", params.get(ApiParamsConstants.CUS_PHONE)); map.put ("feiYongLb",""); map.put ("feiYongXz",""); map.put ("jiLuLy","3"); - map.put ("caoZuoYuan",czy); + map.put ("caoZuoYuan",CZY); map.put ("chongZhiJe",""); map.put ("yiBaoKh",""); map.put ("geRenBh",""); @@ -104,28 +117,38 @@ map.put ("minZuDm",""); map.put ("minZuMc",""); // 鑱屼笟缂栫爜 - return sendPostTokenFormData(HIS_URL+"/menZhenJz/jianDang", map); + String post = sendPost(HIS_URL + "/menZhenJz/jianDang", map); + JSONObject jsonObject = JSONUtil.parseObj(post); + if (jsonObject.getStr("returnCode").equals("1")) { + JSONObject obj = JSONUtil.createObj(); + obj.putOpt("code","200"); + obj.putOpt("data",jsonObject.getJSONObject("returnData")); + return JSONUtil.toJsonStr(obj); + }else { + JSONObject obj = JSONUtil.createObj(); + obj.putOpt("code","500"); + return JSONUtil.toJsonStr(obj); + } } @Override public String getBingRenXxByShengFenZheng(Map<String, Object> params) { - String czy = configService.selectConfigByKey("dfhisczybm"); Map<String, Object> map = new HashMap<> (); - map.put ("caoZuoYuan",czy); + map.put ("caoZuoYuan",CZY); map.put ("shenFenZh", params.get(ApiParamsConstants.CUS_ID_CARD)); - map.put ("danWeiBh",""); + map.put ("danWeiBh",params.get(ApiParamsConstants.COMP_ID)); //鑱屼笟缂栫爜 - return sendPostTokenFormData(HIS_URL+"/menZhenJz/getBingRenXxByShengFenZheng", map); + return sendPostTokenFormUrlencoded(HIS_URL+"/menZhenJz/getBingRenXxByShengFenZheng", map); } @Override public String saveBingRenXx(Map<String, Object> params) { - String czy = configService.selectConfigByKey("dfhisczybm"); Map<String, Object> map = new HashMap<> (); - map.put ("jiuZhenKh", params.get(ApiParamsConstants.PATIONID)); + map.put ("bingRenId", params.get(ApiParamsConstants.PATIONID)); map.put ("kaiLeiXing","4"); + map.put("jiuZhenKh",params.get(ApiParamsConstants.CARD_ID)); map.put ("xingMing", params.get(ApiParamsConstants.CUS_NAME)); - long cusSex = Long.parseLong(map.get(ApiParamsConstants.CUS_SEX).toString()); + long cusSex = Long.parseLong(params.get(ApiParamsConstants.CUS_SEX).toString()); if(cusSex==0L){ map.put ("xingBie","鐢�"); }else if(cusSex==1L){ @@ -135,15 +158,15 @@ } map.put ("shenFenZh", params.get(ApiParamsConstants.CUS_ID_CARD)); map.put ("danWeiBh",""); - map.put ("chuShengRq", DateUtil.format((LocalDateTime) params.get(ApiParamsConstants.CUS_BRITHDAY),"yyyy-MM-dd")); + map.put ("chuShengRq", params.get(ApiParamsConstants.CUS_BRITHDAY)); map.put ("lianXiDz", params.get(ApiParamsConstants.CUS_ADDR)); map.put ("lianXiDh", params.get(ApiParamsConstants.CUS_PHONE)); map.put ("feiYongLb",""); map.put ("feiYongXz",""); map.put ("jiLuLy","3"); - map.put ("caoZuoYuan",czy); + map.put ("caoZuoYuan",CZY); //鑱屼笟缂栫爜 - return sendPostTokenFormData(HIS_URL+"/menZhenJz/saveBingRenXx", map); + return sendPost(HIS_URL+"/menZhenJz/saveBingRenXx", map); } @Override @@ -151,26 +174,58 @@ Map<String, Object> map = new HashMap<> (); map.put ("bingRenId",params.get(ApiParamsConstants.PATIONID)); map.put ("jiuZhenKh",params.get(ApiParamsConstants.CARD_ID)); - map.put ("yuanQuId",params.get(ApiParamsConstants.YUANQU_ID)); + map.put ("yuanQuId","1"); //鑱屼笟缂栫爜 - return sendPostTokenFormData(HIS_URL+"/shouFei/getListDaiShouFei", map); + String post = sendPost(HIS_URL + "/shouFei/getListDaiShouFei", map); + JSONObject jsonObject = JSONUtil.parseObj(post); + if (jsonObject.getStr("returnCode").equals("1")) { + JSONObject data = jsonObject.getJSONObject("returnData"); + JSONArray list = data.getJSONArray("dtoMzFeiyong1List"); + JSONArray list1 = data.getJSONArray("dtoMzFeiYong2List"); + JSONObject result = JSONUtil.createObj(); + result.putOpt("list1",list); + result.putOpt("list2",list1); + return AjaxResult.success(result); + }else { + return AjaxResult.error(post); + } } @Override public String createMenZhenFy(Map<String, Object> params) { - String czy = configService.selectConfigByKey("dfhisczybm"); Map<String, Object> map = new HashMap<> (); map.put ("bingRenId",params.get(ApiParamsConstants.PATIONID)); map.put ("jiuZhenKh",params.get(ApiParamsConstants.CARD_ID)); - map.put ("caoZuoYuan",czy); - map.put ("yuanQuId",params.get(ApiParamsConstants.YUANQU_ID)); + map.put ("caoZuoYuan",CZY); + map.put ("yuanQuId","1"); map.put ("yingYongId","870101"); map.put ("kaiDanKs",params.get(ApiParamsConstants.kaiDanKeShi)); - map.put ("dengJiLsh",params.get(ApiParamsConstants.CARD_ID)); + map.put ("dengJiLsh",params.get(ApiParamsConstants.Tj_NUM)); map.put ("shouTuiBz",params.get(ApiParamsConstants.SHOU_TUI_STATUS)); map.put ("feiYongMxList",params.get(ApiParamsConstants.FEI_YONG_INFO_LIST)); //鑱屼笟缂栫爜 - return sendPostTokenFormData(HIS_URL+"/shouFei/createMenZhenFy", map); + String post = sendPost(HIS_URL + "/shouFei/createMenZhenFy", map); + JSONObject jsonObject = JSONUtil.parseObj(post); + if (jsonObject.getInt("returnCode") != 1) return AjaxResult.error(post); + JSONObject data = jsonObject.getJSONObject("returnData"); + JSONObject result = JSONUtil.createObj(); + result.putOpt(ApiParamsConstants.PATIONID,data.getStr(ApiParamsConstants.PATIONID)); + result.putOpt(ApiParamsConstants.FEI_YONG_ID,data.getStr(ApiParamsConstants.FEI_YONG_ID)); + + JSONArray feiYongMxList = data.getJSONArray("feiYongMxList"); + + ArrayList<TjFlowingWaterHis> tjFlowingWaterHis = new ArrayList<>(); + for (Object o : feiYongMxList) { + JSONObject entries = (JSONObject) o; + TjFlowingWaterHis waterHis = new TjFlowingWaterHis(); + waterHis.setId(IdUtil.getSnowflakeNextId()); + waterHis.setParentId(data.getStr(ApiParamsConstants.FEI_YONG_ID)); + waterHis.setCurrentId(entries.getStr("feiYongMxId")); + waterHis.setXmId(entries.getStr("xiangMuId")); + tjFlowingWaterHis.add(waterHis); + } + result.putOpt("mxList",tjFlowingWaterHis); + return AjaxResult.success(result); } @Override @@ -188,39 +243,34 @@ }); map.put ("feiYongIdList",ids); //鑱屼笟缂栫爜 - return sendPostTokenFormData(HIS_URL+"/shouFei/cheXiaoMzFy", map); - } - - @Override - public String pushZhiFuMsg(Map<String, Object> params) { - Map<String, Object> map = new HashMap<> (); - map.put ("feiYongId",params.get(ApiParamsConstants.FEI_YONG_ID)); - map.put ("yeWuLx",params.get(ApiParamsConstants.FEI_YONG_STATUS)); - //鑱屼笟缂栫爜 - return sendPostTokenFormData(HIS_URL+"/shouFei/pushZhiFuMsg", map); + String post = sendPost(HIS_URL + "/shouFei/cheXiaoMzFy", map); + JSONObject entries = JSONUtil.parseObj(post); + if (entries.getStr("returnCode").equals("1")) + return AjaxResult.success(); + else return AjaxResult.error(post); } @Override public String getKeShi(Map<String, Object> params) { Map<String, Object> map = new HashMap<> (); - map.put ("yuanQuId",params.get(ApiParamsConstants.YUANQU_ID)); + map.put ("yuanQuId","1"); map.put ("keShiMc",params.get(ApiParamsConstants.DEPT_NAME)); map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX)); map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE)); //鑱屼笟缂栫爜 - return sendPostTokenFormData(HIS_URL+"/zhuShuJu/getKeShi", map); + return sendPost(HIS_URL+"/zhuShuJu/getKeShi", map); } @Override public String getListYiShengZd(Map<String, Object> params) { Map<String, Object> map = new HashMap<> (); - map.put ("yuanQuId",params.get(ApiParamsConstants.YUANQU_ID)); + map.put ("yuanQuId","1"); map.put ("keShiMc",params.get(ApiParamsConstants.DEPT_NAME)); map.put ("bianGengSj",""); map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX)); map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE)); //鑱屼笟缂栫爜 - return sendPostTokenFormData(HIS_URL+"/zhuShuJu/getListYiShengZd", map); + return sendPost(HIS_URL+"/zhuShuJu/getListYiShengZd", map); } @Override @@ -231,7 +281,7 @@ map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX)); map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE)); //鑱屼笟缂栫爜 - return sendPostTokenFormData(HIS_URL+"/zhuShuJu/getShouFeiXm", map); + return sendPost(HIS_URL+"/zhuShuJu/getShouFeiXm", map); } @Override @@ -240,11 +290,11 @@ map.put ("xingZhiSx",""); map.put ("queryString",params.get(ApiParamsConstants.COMMON_QUERY_KEY)); map.put ("zuoFeiBz",params.get(ApiParamsConstants.DEPT_ZUOFEI_STATUS)); - map.put ("yuanQuId",params.get(ApiParamsConstants.YUANQU_ID)); + map.put ("yuanQuId","1"); map.put ("keShiIds",params.get(ApiParamsConstants.DEPT_IDS)); map.put ("ifPlus",""); //鑱屼笟缂栫爜 - return sendPostTokenFormData(HIS_URL+"/zhuShuJu/getKeShiByConditions", map); + return sendPost(HIS_URL+"/zhuShuJu/getKeShiByConditions", map); } @Override @@ -254,7 +304,7 @@ map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX)); map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE)); //鑱屼笟缂栫爜 - return sendPostTokenFormData(HIS_URL+"/zhuShuJu/getYangBen", map); + return sendPost(HIS_URL+"/zhuShuJu/getYangBen", map); } @Override @@ -265,7 +315,7 @@ map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX)); map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE)); //鑱屼笟缂栫爜 - return sendPostTokenFormData(HIS_URL+"/zhuShuJu/getListBingQuZd", map); + return sendPost(HIS_URL+"/zhuShuJu/getListBingQuZd", map); } @Override @@ -275,7 +325,7 @@ map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX)); map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE)); //鑱屼笟缂栫爜 - return sendPostTokenFormData(HIS_URL+"/zhuShuJu/getZhiGongPage", map); + return sendPost(HIS_URL+"/zhuShuJu/getZhiGongPage", map); } @Override @@ -286,7 +336,7 @@ map.put ("pageIndex",params.get(ApiParamsConstants.PAGE_INDEX)); map.put ("pageSize",params.get(ApiParamsConstants.PAGE_SIZE)); //鑱屼笟缂栫爜 - return sendPostTokenFormData(HIS_URL+"/zhuShuJu/getJianChaXm", map); + return sendPost(HIS_URL+"/zhuShuJu/getJianChaXm", map); } @Override @@ -295,7 +345,7 @@ hashMap.put("queryCode",map.get(ApiParamsConstants.COMMON_QUERY_KEY)); hashMap.put("page",map.get(ApiParamsConstants.PAGE_INDEX)); hashMap.put("size",map.get(ApiParamsConstants.PAGE_SIZE)); - return sendPostTokenFormData(HIS_URL+"/zhuShuJu/getJianYanXm", hashMap); + return sendPost(HIS_URL+"/zhuShuJu/getJianYanXm", hashMap); } @Override @@ -303,7 +353,7 @@ HashMap<String, Object> hashMap = new HashMap<>(); hashMap.put("shouFeiXmId",map.get(ApiParamsConstants.COMMON_QUERY_KEY)); hashMap.put("jiaGeTx",map.get(ApiParamsConstants.COMMON_QUERY_KEY2)); - return sendPostTokenFormData(HIS_URL+"/zhuShuJu/getShouFeiXmJg", hashMap); + return sendPost(HIS_URL+"/zhuShuJu/getShouFeiXmJg", hashMap); } @Override @@ -312,7 +362,7 @@ hashMap.put("queryString",map.get(ApiParamsConstants.COMMON_QUERY_KEY)); hashMap.put("pageIndex",map.get(ApiParamsConstants.PAGE_INDEX)); hashMap.put("pageSize",map.get(ApiParamsConstants.PAGE_SIZE)); - return sendPostTokenFormData(HIS_URL+"/zhuShuJu/getRongQi", hashMap); + return sendPost(HIS_URL+"/zhuShuJu/getRongQi", hashMap); } @Override @@ -321,11 +371,39 @@ hashMap.put("queryString",map.get(ApiParamsConstants.COMMON_QUERY_KEY)); hashMap.put("pageIndex",map.get(ApiParamsConstants.PAGE_INDEX)); hashMap.put("pageSize",map.get(ApiParamsConstants.PAGE_SIZE)); - return sendPostTokenFormData(HIS_URL+"/zhuShuJu/getYangBen", hashMap); + return sendPost(HIS_URL+"/zhuShuJu/getYangBen", hashMap); } + @Override + public String pushZhiFuMsg(String hospName,Map<String, Object> params) { + log.info("鍥炶皟瑙﹀彂 ->{}",params); + configValue.refresh(); + Map<String, Object> map = new HashMap<> (); + map.put ("feiYongId",params.get("feiyongid")); + String string = params.get("status").toString(); + if (!string.equals("1")) + string = "2"; + map.put ("yeWuLx",string); + // 鍙傛暟绫诲瀷鍖哄垎 + map.put("type","1"); + String post = HttpClientUtils.sendPost(TJ_URL + "/callBack/pushZhiFuMsg", map); + JSONObject jsonObject = JSONUtil.parseObj(post); + JSONObject obj = JSONUtil.createObj(); + if (jsonObject.getStr("code").equals("200")) { + obj.putOpt("returnCode",1); + obj.putOpt("exceptionContent",""); + obj.putOpt("returnData",null); + }else { + obj.putOpt("returnCode",0); + obj.putOpt("exceptionContent",jsonObject.getStr("msg")); + obj.putOpt("returnData",null); + } + return JSONUtil.toJsonStr(obj); + } + + private String sendPost(String url, Map<String, Object> hashMap){ - Map<Object, Object> entries = redisTemplate.opsForHash().entries("token:his:df"); + Map<Object, Object> entries = redisTemplate.opsForHash().entries("token:his:shanxixamjyy"); if (entries != null && !entries.isEmpty()) { String timeStr = entries.get("time").toString(); String expiresInStr = entries.get("expires_in").toString(); @@ -334,7 +412,7 @@ Instant tokenExpirationTime = Instant.ofEpochSecond(time).plusSeconds(expiresIn); Instant now = Instant.now(); if (now.isAfter(tokenExpirationTime)){ - return refreshToken(url,hashMap); + return refreshToken(url,hashMap,"json"); }else { String accessToken = entries.get("access_token").toString(); String tokenType = entries.get("token_type").toString(); @@ -342,12 +420,12 @@ return StrUtil.isNotBlank(string) ? string : JSONUtil.createObj().toString(); } }else { - return refreshToken(url, hashMap); + return refreshToken(url, hashMap,"json"); } } private String sendPostTokenFormUrlencoded(String url, Map<String, Object> hashMap){ - Map<Object, Object> entries = redisTemplate.opsForHash().entries("token:his:df"); + Map<Object, Object> entries = redisTemplate.opsForHash().entries("token:his:shanxixamjyy"); if (entries != null && !entries.isEmpty()) { String timeStr = entries.get("time").toString(); String expiresInStr = entries.get("expires_in").toString(); @@ -356,7 +434,7 @@ Instant tokenExpirationTime = Instant.ofEpochSecond(time).plusSeconds(expiresIn); Instant now = Instant.now(); if (now.isAfter(tokenExpirationTime)){ - return refreshToken(url,hashMap); + return refreshToken(url,hashMap,"url"); }else { String accessToken = entries.get("access_token").toString(); String tokenType = entries.get("token_type").toString(); @@ -364,12 +442,12 @@ return StrUtil.isNotBlank(string) ? string : JSONUtil.createObj().toString(); } }else { - return refreshToken(url, hashMap); + return refreshToken(url, hashMap,"url"); } } private String sendPostTokenFormData(String url, Map<String, Object> hashMap){ - Map<Object, Object> entries = redisTemplate.opsForHash().entries("token:his:df"); + Map<Object, Object> entries = redisTemplate.opsForHash().entries("token:his:shanxixamjyy"); if (entries != null && !entries.isEmpty()) { String timeStr = entries.get("time").toString(); String expiresInStr = entries.get("expires_in").toString(); @@ -378,7 +456,7 @@ Instant tokenExpirationTime = Instant.ofEpochSecond(time).plusSeconds(expiresIn); Instant now = Instant.now(); if (now.isAfter(tokenExpirationTime)){ - return refreshToken(url,hashMap); + return refreshToken(url,hashMap,"form"); }else { String accessToken = entries.get("access_token").toString(); String tokenType = entries.get("token_type").toString(); @@ -389,28 +467,97 @@ }else return JSONUtil.createObj().toString(); } }else { - return refreshToken(url, hashMap); + return refreshToken(url, hashMap,"form"); } } - private String refreshToken(String url, Map<String, Object> hashMap) { + private String refreshToken(String url, Map<String, Object> hashMap,String type) { JSONObject parseObj = getToken(); if (parseObj != null) { Integer expiresIn = parseObj.getInt("expires_in"); if (expiresIn != null) { parseObj.putOpt("time", Instant.now().getEpochSecond()); - redisTemplate.opsForHash().putAll("token:his:df", parseObj); - redisTemplate.expire("token:his:df", expiresIn - 10, TimeUnit.SECONDS); + redisTemplate.opsForHash().putAll("token:his:shanxixamjyy", parseObj); + redisTemplate.expire("token:his:shanxixamjyy", expiresIn - 10, TimeUnit.SECONDS); String accessToken = parseObj.getStr("access_token"); String tokenType = parseObj.getStr("token_type"); - String string = HttpClientUtils.sendPostTokenFormData(url, hashMap, tokenType + " " + accessToken); - if(StrUtil.isNotBlank(string)){ - JSON json = FieldNameConverter.convertFieldNames(JSONUtil.parse(string)); - return JSONUtil.toJsonStr(json); - } else return JSONUtil.createObj().toString(); + switch (type){ + case "json": + String string = HttpClientUtils.sendPostToken(url, hashMap, tokenType + " " + accessToken); + if(StrUtil.isNotBlank(string)){ + JSON json = FieldNameConverter.convertFieldNames(JSONUtil.parse(string)); + return JSONUtil.toJsonStr(json); + } else return JSONUtil.createObj().toString(); + case "form": + String string1 = HttpClientUtils.sendPostTokenFormData(url, hashMap, tokenType + " " + accessToken); + if(StrUtil.isNotBlank(string1)){ + JSON json = FieldNameConverter.convertFieldNames(JSONUtil.parse(string1)); + return JSONUtil.toJsonStr(json); + } else return JSONUtil.createObj().toString(); + case "url": + String string2 = HttpClientUtils.sendPostTokenFormUrlencoded(url, hashMap, tokenType + " " + accessToken); + if(StrUtil.isNotBlank(string2)){ + JSON json = FieldNameConverter.convertFieldNames(JSONUtil.parse(string2)); + return JSONUtil.toJsonStr(json); + } else return JSONUtil.createObj().toString(); + } } } return JSONUtil.createObj().toString(); } + + @Override + public void syncDict(String hospName) { + HashMap<String, Object> map = new HashMap<>(); + map.put("hosp","shanxiqinxamjyy"); + String post = HttpClientUtils.sendPost(TJ_URL + "/callBack/getZdList", map); + JSONArray jsonArray = JSONUtil.parseObj(post).getJSONArray("data"); + if (jsonArray != null && jsonArray.size() > 0) { + List<HisSyncDict> list = jsonArray.toList(HisSyncDict.class); + String token = ""; + Map<Object, Object> entries = redisTemplate.opsForHash().entries("token:his:shanxixamjyy"); + if (entries != null && !entries.isEmpty()) { + String timeStr = entries.get("time").toString(); + String expiresInStr = entries.get("expires_in").toString(); + long time = Long.parseLong(timeStr); + Long expiresIn = Long.parseLong(expiresInStr); + Instant tokenExpirationTime = Instant.ofEpochSecond(time).plusSeconds(expiresIn); + Instant now = Instant.now(); + if (now.isAfter(tokenExpirationTime)){ + JSONObject parseObj = getToken(); + if (parseObj != null) { + expiresIn = parseObj.getLong("expires_in"); + if (expiresIn != null) { + parseObj.putOpt("time", Instant.now().getEpochSecond()); + redisTemplate.opsForHash().putAll("token:his:shanxixamjyy", parseObj); + redisTemplate.expire("token:his:shanxixamjyy", expiresIn - 10, TimeUnit.SECONDS); + String accessToken = parseObj.getStr("access_token"); + String tokenType = parseObj.getStr("token_type"); + token = tokenType + " " + accessToken; + } + } + }else { + String accessToken = entries.get("access_token").toString(); + String tokenType = entries.get("token_type").toString(); + token = tokenType + " " + accessToken; + } + }else { + JSONObject parseObj = getToken(); + if (parseObj != null) { + Integer expiresIn = parseObj.getInt("expires_in"); + if (expiresIn != null) { + parseObj.putOpt("time", Instant.now().getEpochSecond()); + redisTemplate.opsForHash().putAll("token:his:shanxixamjyy", parseObj); + redisTemplate.expire("token:his:shanxixamjyy", expiresIn - 10, TimeUnit.SECONDS); + String accessToken = parseObj.getStr("access_token"); + String tokenType = parseObj.getStr("token_type"); + token = tokenType + " " + accessToken; + } + } + } + if (StrUtil.isNotBlank(token)) + syncZd.exec(list, token); + } + } } diff --git a/src/main/java/com/example/service/shanxiqin/xian/MeiJiPacsService.java b/src/main/java/com/example/service/shanxiqin/xian/MeiJiPacsService.java new file mode 100644 index 0000000..673a33b --- /dev/null +++ b/src/main/java/com/example/service/shanxiqin/xian/MeiJiPacsService.java @@ -0,0 +1,24 @@ +package com.example.service.shanxiqin.xian; + +import cn.hutool.core.util.XmlUtil; +import cn.hutool.http.HttpRequest; +import com.example.service.PacsService; +import org.springframework.stereotype.Service; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + + +@Service("ShanXiQinXiAnMeiJiPacs") +public class MeiJiPacsService implements PacsService { + + @Override + public String orderAdd(String xml) { + xml = xml.replaceAll("shanxiqinxamjyy","xamjyy"); + System.out.println("xml = " + xml); + String result = HttpRequest.post("http://10.100.100.222:8000/WebInterfaceService.asmx") + .body(xml).contentType("application/xml;charset:utf-8;").execute().body(); + System.out.println("result = " + result); + return "1"; + } +} diff --git a/src/main/java/com/example/utils/AjaxResult.java b/src/main/java/com/example/utils/AjaxResult.java new file mode 100644 index 0000000..ca5fea1 --- /dev/null +++ b/src/main/java/com/example/utils/AjaxResult.java @@ -0,0 +1,172 @@ +package com.example.utils; + +import cn.hutool.json.JSONUtil; +import com.example.constant.HttpStatus; + +import java.io.Serializable; +import java.util.HashMap; + +public class AjaxResult extends HashMap<String, Object> implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 鐘舵�佺爜 + */ + public static final String CODE_TAG = "code"; + + /** + * 杩斿洖鍐呭 + */ + public static final String MSG_TAG = "msg"; + + /** + * 鏁版嵁瀵硅薄 + */ + public static final String DATA_TAG = "data"; + + /** + * 鍒濆鍖栦竴涓柊鍒涘缓鐨� AjaxResult 瀵硅薄锛屼娇鍏惰〃绀轰竴涓┖娑堟伅銆� + */ + public AjaxResult() { + } + + /** + * 鍒濆鍖栦竴涓柊鍒涘缓鐨� AjaxResult 瀵硅薄 + * + * @param code 鐘舵�佺爜 + * @param msg 杩斿洖鍐呭 + */ + public AjaxResult(int code, String msg) { + super.put(CODE_TAG, code); + super.put(MSG_TAG, msg); + } + + /** + * 鍒濆鍖栦竴涓柊鍒涘缓鐨� AjaxResult 瀵硅薄 + * + * @param code 鐘舵�佺爜 + * @param msg 杩斿洖鍐呭 + * @param data 鏁版嵁瀵硅薄 + */ + public AjaxResult(int code, String msg, Object data) { + super.put(CODE_TAG, code); + super.put(MSG_TAG, msg); + if (StringUtils.isNotNull(data)) { + super.put(DATA_TAG, data); + } + } + + /** + * 杩斿洖鎴愬姛娑堟伅 + * + * @return 鎴愬姛娑堟伅 + */ + public static String success() { + return JSONUtil.toJsonStr(AjaxResult.success("鎿嶄綔鎴愬姛")); + } + + /** + * 杩斿洖鎴愬姛鏁版嵁 + * + * @return 鎴愬姛娑堟伅 + */ + public static String success(Object data) { + return JSONUtil.toJsonStr(AjaxResult.success("鎿嶄綔鎴愬姛", data)); + } + + /** + * 杩斿洖鎴愬姛娑堟伅 + * + * @param msg 杩斿洖鍐呭 + * @return 鎴愬姛娑堟伅 + */ + public static String success(String msg) { + return JSONUtil.toJsonStr(AjaxResult.success(msg, null)); + } + + /** + * 杩斿洖鎴愬姛娑堟伅 + * + * @param msg 杩斿洖鍐呭 + * @param data 鏁版嵁瀵硅薄 + * @return 鎴愬姛娑堟伅 + */ + public static String success(String msg, Object data) { + return JSONUtil.toJsonStr(new AjaxResult(HttpStatus.SUCCESS, msg, data)); + } + + /** + * 杩斿洖璀﹀憡娑堟伅 + * + * @param msg 杩斿洖鍐呭 + * @return 璀﹀憡娑堟伅 + */ + public static String warn(String msg) { + return JSONUtil.toJsonStr(AjaxResult.warn(msg, null)); + } + + /** + * 杩斿洖璀﹀憡娑堟伅 + * + * @param msg 杩斿洖鍐呭 + * @param data 鏁版嵁瀵硅薄 + * @return 璀﹀憡娑堟伅 + */ + public static String warn(String msg, Object data) { + return JSONUtil.toJsonStr(new AjaxResult(HttpStatus.WARN, msg, data)); + } + + /** + * 杩斿洖閿欒娑堟伅 + * + * @return + */ + public static String error() { + return JSONUtil.toJsonStr(AjaxResult.error("鎿嶄綔澶辫触")); + } + + /** + * 杩斿洖閿欒娑堟伅 + * + * @param msg 杩斿洖鍐呭 + * @return 璀﹀憡娑堟伅 + */ + public static String error(String msg) { + return AjaxResult.error(msg, null); + } + + /** + * 杩斿洖閿欒娑堟伅 + * + * @param msg 杩斿洖鍐呭 + * @param data 鏁版嵁瀵硅薄 + * @return 璀﹀憡娑堟伅 + */ + public static String error(String msg, Object data) { + return JSONUtil.toJsonStr(new AjaxResult(HttpStatus.ERROR, msg, data)); + } + + /** + * 杩斿洖閿欒娑堟伅 + * + * @param code 鐘舵�佺爜 + * @param msg 杩斿洖鍐呭 + * @return 璀﹀憡娑堟伅 + */ + public static String error(int code, String msg) { + return JSONUtil.toJsonStr(new AjaxResult(code, msg, null)); + } + + /** + * 鏂逛究閾惧紡璋冪敤 + * + * @param key 閿� + * @param value 鍊� + * @return 鏁版嵁瀵硅薄 + */ + @Override + public AjaxResult put(String key, Object value) { + super.put(key, value); + return this; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/utils/DictionaryUtilCommon.java b/src/main/java/com/example/utils/DictionaryUtilCommon.java deleted file mode 100644 index a2c156b..0000000 --- a/src/main/java/com/example/utils/DictionaryUtilCommon.java +++ /dev/null @@ -1,397 +0,0 @@ -package com.example.utils; - -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.example.config.ConfigValue; -import com.example.domain.HisSyncDict; -import com.example.service.HisSyncDictService; -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 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.Date; -import java.util.*; - -/** - * 瀛楀吀鍏叡瑙f瀽绫� - * @Company: 瑗垮畨璺嘲绉戞妧鏈夐檺鍏徃 - * @Author: zhaowenxuan - * @Date: 2024/12/19 16:41 - */ -@Slf4j -@Component -public class DictionaryUtilCommon { - - @Autowired - private HisSyncDictService hisSyncDictService; - @Autowired - private ConfigValue configValue; - - private static String CONFIG_PATH; - private static String BASE_API_URL = ""; - private static final int SIZE = 1000; - private static String USER = ""; - private static String PASSWORD = ""; - private static String URL = ""; - private static String NAME = ""; - @Value("${config.path}") - public void setConfigPath(String configPath) { - CONFIG_PATH = configPath; - NAME = configValue.getConfigValue("name"); - URL = "jdbc:mysql://" + configValue.getConfigValue("ip") + ":" + configValue.getConfigValue("prot") + "/" + NAME + - "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8"; - USER = configValue.getConfigValue("username"); - PASSWORD = configValue.getConfigValue("password"); - String apiUrl = configValue.getConfigValue("his_api_url"); - String apiPort = configValue.getConfigValue("his_api_port"); - BASE_API_URL = apiUrl+":"+apiPort+configValue.getConfigValue("hisapiappend"); - } - - - /** - * 鏆傛椂涓嶅仛 - * 1.90 闂ㄨ瘖鏄庣粏璁¤垂鍙婄粍鍚堣璐归」鐩� MZJFZHMXXM - * - */ - -// 鍒嗛〉姣忔1000鏉� - static { - try { - Class.forName("com.mysql.cj.jdbc.Driver"); - } catch (Exception e) { - System.out.println("闈欐�佷唬鐮佸潡寮傚父 ->"+e.getMessage()); - } - } - - public static void main(String[] args) { - DictionaryUtilNew util = new DictionaryUtilNew(); - util.exec1(); - } - - /** - * 杩涜鍚屾 - */ - public void exec1(){ - log.info("寮�濮嬫墽琛屽悓姝�"); - Connection connection = getConnection(); - if (connection == null) - return; - List<HisSyncDict> hisSyncDicts = hisSyncDictService.list(); - for (HisSyncDict hisSyncDict : hisSyncDicts) { - extracted(NAME, connection, hisSyncDict); - } - try { - connection.close(); - } catch (SQLException ignored) { } - log.info("鎵ц鍚屾瀹屾瘯"); - } - - private void extracted(String name, Connection connection, HisSyncDict hisSyncDict) { - String method = hisSyncDict.getDictName(); - log.info("寮�濮嬭姹備唬鐮� ->{}", method); - String tabName = "ltkj_" + method.toLowerCase(); - boolean isLimit = false; - int page = 1; - int maxPage = 1; - JSONObject object = JSONUtil.createObj(); - object.putOpt("method", method); - if (hisSyncDict.getIsLimit() == 1) { - isLimit = true; - JSONObject input = object.getJSONObject("input"); - input.putOpt("pagecount", SIZE); - input.putOpt("page", page); - } - log.info("璇锋眰鎺ュ彛 ->{}, 璇锋眰鍙傛暟 ->{}", BASE_API_URL, object.toString()); - JSONObject entries = execRequest(object.toString()); -// log.info("璇锋眰杩斿洖 ->{}", entries.toString()); - 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); - if (maxPage > 1) { - for (page = 2; page <= maxPage; page++) { - object.clear(); - object.putOpt("method", method); -// object = addInputVal(object); - JSONObject input = object.getJSONObject("input"); - input.putOpt("pagecount", SIZE); - input.putOpt("page", page); - log.info("璇锋眰鎺ュ彛 ->{}, 璇锋眰鍙傛暟 ->{}", BASE_API_URL, object.toString()); - entries = execRequest(object.toString()); -// log.info("璇锋眰杩斿洖 ->{}", entries.toString()); - response = entries.getJSONObject("Response"); - if ("0".equals(response.getStr("ResultCode"))) { - LimitInsertData(connection, tabName, response, name, page); - } else { - log.error("{} 璇锋眰澶辫触锛歿}", method, object.toString()); - } - } - } - } else { - JSONArray resultData = response.getJSONArray("ResultData"); - List<JSONObject> list = JSONUtil.toList(resultData, JSONObject.class); - for (JSONObject jsonObject : list) { - editDataBase(connection, tabName, jsonObject, name); - } - } - } else { - log.error("{}璇锋眰澶辫触 - 璇锋眰鐘舵�佺爜涓嶄负0, 璇锋眰鍙傛暟 ->{}, 璇锋眰杩斿洖 ->{}", method, object.toString(), response.toString()); - } - } - - /** - * 閽堝浜庡垎椤垫帴鍙� 鍒涘缓琛ㄣ�佹彃鍏ユ暟鎹� - * - * @param connection - * @param tabName - * @param response - * @return - */ - private int LimitInsertData(Connection connection, String tabName, JSONObject response,String name,Integer page) { - 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; - log.info("璇锋眰杩斿洖鎬绘潯鏁� ->{},褰撳墠椤� ->{},鎬婚〉鏁� ->{}",totalCount,page,maxPage); - jsonArray.forEach(obj -> { - editDataBase(connection, tabName, (JSONObject) obj,name); - }); - return maxPage; - } - - /** - * 鎿嶄綔鏁版嵁搴� - * - * @param connection - * @param tabName - * @param obj - */ - private void editDataBase(Connection connection, String tabName, JSONObject obj,String name) { - try { - if (!tabIsExists(connection, tabName,name)) { - // 鍒涘缓琛� - creatTable(obj, tabName, connection); - } - } catch (SQLException throwables) { - log.error("鍒涘缓琛ㄥ紓甯�"); - log.error(throwables.getSQLState()); - log.error(throwables.getMessage()); - } - // 瀵规瘮瀛楁 骞舵彃鍏ユ暟鎹� - try { - operationTable(obj, tabName, connection); - } catch (SQLException e) { - log.error("瀵规瘮瀛楁鎻掑叆鏁版嵁寮傚父"); - log.error(e.getSQLState()); - log.error(e.getMessage()); - } - } - - /** - * 鎵цpost璇锋眰 - * - * @param params 璇锋眰鍙傛暟 渚嬪锛� param1=val1¶m2=val2 - * @return 璇锋眰杩斿洖鐨刯son杞崲鍚庣殑JSONObject瀵硅薄 - */ - private JSONObject execRequest(String params) { - URL url = null; - HttpURLConnection connection = null; - try { - url = new URL(BASE_API_URL); - connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("POST"); - connection.setRequestProperty("Accept", "application/json"); - 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(),StandardCharsets.UTF_8)); - StringBuilder builder = new StringBuilder(); - String str; - while ((str = reader.readLine()) != null) { - builder.append(str); - } - return JSONUtil.parseObj(builder.toString()); - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (connection != null) { - connection.disconnect(); - } - } - return null; - } - - public Connection getConnection() { - try { - log.info("鏁版嵁搴撲俊鎭� ->{},{},{}",USER,PASSWORD,URL); - return DriverManager.getConnection(URL,USER,PASSWORD); - } catch (Exception throwables) { - log.error("鑾峰彇sql杩炴帴澶辫触"); - throwables.printStackTrace(); - } - return null; - } - - /** - * 琛ㄦ槸鍚﹀瓨鍦� - * - * @param connection - * @param tableName - * @return - * @throws SQLException - */ - private Boolean tabIsExists(Connection connection, String tableName,String name) throws SQLException { - String tabSql = "SELECT table_name FROM information_schema.tables WHERE table_schema = ? AND table_name = ?"; - PreparedStatement statement = connection.prepareStatement(tabSql); - statement.setString(1, name); - statement.setString(2, tableName); -// log.info("鍒ゆ柇琛ㄦ槸鍚﹀瓨鍦� sql-> {}", statement.toString()); - ResultSet resultSet = statement.executeQuery(); - boolean next = resultSet.next(); - statement.close(); - return next; - } - - /** - * 鎿嶄綔琛� - * - * @param tabName - * @param connection - * @throws SQLException - */ - private void operationTable(JSONObject jsonObject, String tabName, Connection connection) throws SQLException { - List<String> columns = getColumns(tabName, connection); -// log.info("褰撳墠琛ㄥ瓧娈典负 ->{}", columns); - ArrayList<String> responseColums = new ArrayList<>(); - for (Map.Entry<String, Object> entry : jsonObject.entrySet()) { - String key = entry.getKey().trim().toLowerCase(); - responseColums.add(key); - } -// log.info("璇锋眰杩斿洖鐨勫瓧娈典负 ->{}", responseColums); - responseColums.removeAll(columns); -// log.info("闇�瑕佸鍔犵殑瀛楁 ->{}",responseColums); - if (!responseColums.isEmpty()) { - // 闇�瑕佸鍔犲瓧娈� 骞舵彃鍏ユ暟鎹� - for (String colum : responseColums) { - String sql = "alter table " + tabName + " add column " + colum + " VARCHAR(200) null"; -// log.info("淇敼瀛楁 ->{}",sql.toString()); - Statement statement = connection.createStatement(); - statement.executeUpdate(sql); - statement.close(); - } - insertData(tabName, connection, jsonObject); - } else { - insertData(tabName, connection, jsonObject); - } - } - - /** - * 鎻掑叆鏁版嵁 - * - * @param tabName - * @param connection - * @param jsonObject - * @throws SQLException - */ - private void insertData(String tabName, Connection connection, JSONObject jsonObject) throws SQLException { - // 鎻掑叆鏁版嵁鍓� 鍏堟煡璇㈡暟鎹槸鍚﹀瓨鍦� - StringBuilder insertSqlBuilder = new StringBuilder(); - StringBuilder valueBuilder = new StringBuilder(); - insertSqlBuilder.append("insert into ").append(tabName).append(" ("); - for (Map.Entry<String, Object> entry : jsonObject.entrySet()) { - String defaultVal = entry.getValue().toString(); - String key = entry.getKey().trim().toLowerCase(); - if (StrUtil.isBlank(defaultVal) || defaultVal.equals("null")) - continue; - String val = defaultVal.trim().replaceAll("\\s+", "").replace("\\",""); - insertSqlBuilder.append(key).append(", "); - valueBuilder.append("'").append(val.replaceAll("'","鈥�")).append("', "); - } - insertSqlBuilder.append("insert_time, "); - String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); - valueBuilder.append("'").append(time).append("'").append(", "); - insertSqlBuilder.delete(insertSqlBuilder.length() - 2, insertSqlBuilder.length()); - valueBuilder.delete(valueBuilder.length() - 2, valueBuilder.length()); - insertSqlBuilder.append(") values (").append(valueBuilder).append(")"); - // 鎻掑叆鏁版嵁 - Statement statement = connection.createStatement(); - log.info("鎻掑叆鏁版嵁 sql-> {}", insertSqlBuilder.toString()); - statement.execute(insertSqlBuilder.toString()); - statement.close(); - } - - /** - * 鑾峰彇琛ㄧ殑鍒� - * - * @param tabName - * @param connection - * @return - * @throws SQLException - */ - private List<String> getColumns(String tabName, Connection connection) throws SQLException { - DatabaseMetaData metaData = connection.getMetaData(); - ResultSet columns = metaData.getColumns(null, null, tabName, null); - ArrayList<String> tabColumns = new ArrayList<>(); - while (columns.next()) { - String columnName = columns.getString("column_name"); - tabColumns.add(columnName); - } - return tabColumns; - } - - /** - * 鍒涘缓琛� - * - * @param resultDataIndex1 杩斿洖鏁版嵁涓殑绗竴涓弬鏁� - * @param tabName - * @param connection - * @throws SQLException - */ - private void creatTable(JSONObject resultDataIndex1, String tabName, Connection connection) throws SQLException { - StringBuilder sql = new StringBuilder("CREATE TABLE " + tabName + " ("); - for (Map.Entry<String, Object> entry : resultDataIndex1.entrySet()) { - String key = entry.getKey().trim().toLowerCase(); - sql.append(key).append(" VARCHAR(200) null,"); - } - sql.append("insert_time").append(" VARCHAR(100) null,"); - sql = new StringBuilder(sql.substring(0, sql.length() - 1)); - sql.append(");"); - log.info("鍒涘缓琛ㄦ牸 -> {}",sql.toString()); - 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); - statement.close(); - } -} diff --git a/src/main/java/com/example/utils/DictionaryUtilNew.java b/src/main/java/com/example/utils/DictionaryUtilNew.java index ca486a6..a281182 100644 --- a/src/main/java/com/example/utils/DictionaryUtilNew.java +++ b/src/main/java/com/example/utils/DictionaryUtilNew.java @@ -1,470 +1,470 @@ -package com.example.utils; - -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.example.domain.HisSyncDict; -import com.example.service.HisSyncDictService; -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 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.Date; -import java.util.*; - -/** - * @Company: 瑗垮畨璺嘲绉戞妧鏈夐檺鍏徃 - * @Author: zhaowenxuan - * @Date: 2024/5/21 16:41 - */ -@Slf4j -@Component -public class DictionaryUtilNew { - @Autowired - private HisSyncDictService hisSyncDictService; - private static String CONFIG_PATH; - private static String BASE_API_URL = ""; - private static final int SIZE = 1000; - private static String USER = ""; - private static String PASSWORD = ""; - private static String URL = ""; - private static String NAME = ""; - @Value("${config.path}") - public void setConfigPath(String configPath) { - CONFIG_PATH = configPath; - FileInputStream inputStream = null; - try { - inputStream = new FileInputStream(CONFIG_PATH); - Properties props = new Properties(); - props.load(inputStream); - NAME = props.getProperty("name"); - URL = "jdbc:mysql://" + props.getProperty("ip") + ":" + props.getProperty("prot") + "/" + NAME + "" + - "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8"; - USER = props.getProperty("username"); - 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"; - } catch (IOException e) { - System.out.println("鍒濆鍖栨暟鎹簱寮傚父 ->"+e.getMessage()); - } - } - - - /** - * 鏆傛椂涓嶅仛 - * 1.90 闂ㄨ瘖鏄庣粏璁¤垂鍙婄粍鍚堣璐归」鐩� MZJFZHMXXM - * - */ - -// 鍒嗛〉姣忔1000鏉� - static { - try { - Class.forName("com.mysql.cj.jdbc.Driver"); - } catch (Exception e) { - System.out.println("闈欐�佷唬鐮佸潡寮傚父 ->"+e.getMessage()); - } - } - - public static void main(String[] args) { - DictionaryUtilNew util = new DictionaryUtilNew(); - util.exec1(); - } - - /** - * 澧炲姞榛樿鍙傛暟 - * @param jsonObject - * @return - */ - public JSONObject addInputVal(JSONObject jsonObject){ - JSONObject obj = JSONUtil.createObj(); - String method = jsonObject.getStr("method"); - if (method.equals("MZJFZHMXXM") || method.equals("MXJFXMZD")){ - obj.putOpt("mode","1"); - } - obj.putOpt("jgbm",""); - obj.putOpt("bm",""); - obj.putOpt("flbm",""); - jsonObject.putOpt("input",obj); - return jsonObject; - } - - /** - * 杩涜鍚屾 - */ - public void exec1(){ - log.info("寮�濮嬫墽琛屽悓姝�"); - Connection connection = getConnection(); - if (connection == null) - return; - List<HisSyncDict> hisSyncDicts = hisSyncDictService.list(); - for (HisSyncDict hisSyncDict : hisSyncDicts) { - extracted(NAME, connection, hisSyncDict); - } - try { - connection.close(); - } catch (SQLException ignored) { } - log.info("鎵ц鍚屾瀹屾瘯"); - } - - /** - * 閫氳繃鎸囧畾瀛楀吀杩涜鍚屾 - */ - public void execMethods(List<String > methods){ - log.info("寮�濮嬫墽琛屽悓姝�"); - Connection connection = getConnection(); - if (connection == null) - return; - for (String method : methods) { - LambdaQueryWrapper<HisSyncDict> wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(HisSyncDict::getDictName,method); - HisSyncDict one = hisSyncDictService.getOne(wrapper); - if (one == null){ - log.error("{}瀛楀吀鍦ㄦ暟鎹簱涓笉瀛樺湪,璇锋鏌ユ暟鎹簱鎴栬姹傚弬鏁版槸鍚﹀~鍐欓敊璇�",method); - continue; - } - extracted(NAME,connection,one); - } - try { - connection.close(); - } catch (SQLException ignored) { } - log.info("鎵ц鍚屾瀹屾瘯"); - } - - private void extracted(String name, Connection connection, HisSyncDict hisSyncDict) { - String method = hisSyncDict.getDictName(); - log.info("寮�濮嬭姹備唬鐮� ->{}", method); - String tabName = "ltkj_" + method.toLowerCase(); - boolean isLimit = false; - int page = 1; - int maxPage = 1; - JSONObject object = JSONUtil.createObj(); - object.putOpt("method", method); - object = addInputVal(object); - if (hisSyncDict.getIsLimit() == 1) { - isLimit = true; - JSONObject input = object.getJSONObject("input"); - input.putOpt("pagecount", SIZE); - input.putOpt("page", page); - } - log.info("璇锋眰鎺ュ彛 ->{}, 璇锋眰鍙傛暟 ->{}", BASE_API_URL, object.toString()); - JSONObject entries = execRequest(object.toString()); -// log.info("璇锋眰杩斿洖 ->{}", entries.toString()); - 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); - if (maxPage > 1) { - for (page = 2; page <= maxPage; page++) { - object.clear(); - object.putOpt("method", method); - object = addInputVal(object); - JSONObject input = object.getJSONObject("input"); - input.putOpt("pagecount", SIZE); - input.putOpt("page", page); - log.info("璇锋眰鎺ュ彛 ->{}, 璇锋眰鍙傛暟 ->{}", BASE_API_URL, object.toString()); - entries = execRequest(object.toString()); -// log.info("璇锋眰杩斿洖 ->{}", entries.toString()); - response = entries.getJSONObject("Response"); - if ("0".equals(response.getStr("ResultCode"))) { - LimitInsertData(connection, tabName, response, name, page); - } else { - log.error("{} 璇锋眰澶辫触锛歿}", method, object.toString()); - } - } - } - } else { - JSONArray resultData = response.getJSONArray("ResultData"); - List<JSONObject> list = JSONUtil.toList(resultData, JSONObject.class); - for (JSONObject jsonObject : list) { - editDataBase(connection, tabName, jsonObject, name); - } - } - } else { - log.error("{}璇锋眰澶辫触 - 璇锋眰鐘舵�佺爜涓嶄负0, 璇锋眰鍙傛暟 ->{}, 璇锋眰杩斿洖 ->{}", method, object.toString(), response.toString()); - } - } - - /** - * 閽堝浜庡垎椤垫帴鍙� 鍒涘缓琛ㄣ�佹彃鍏ユ暟鎹� - * - * @param connection - * @param tabName - * @param response - * @return - */ - private int LimitInsertData(Connection connection, String tabName, JSONObject response,String name,Integer page) { - 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; - log.info("璇锋眰杩斿洖鎬绘潯鏁� ->{},褰撳墠椤� ->{},鎬婚〉鏁� ->{}",totalCount,page,maxPage); - jsonArray.forEach(obj -> { - editDataBase(connection, tabName, (JSONObject) obj,name); - }); - return maxPage; - } - - /** - * 鎿嶄綔鏁版嵁搴� - * - * @param connection - * @param tabName - * @param obj - */ - private void editDataBase(Connection connection, String tabName, JSONObject obj,String name) { - try { - if (!tabIsExists(connection, tabName,name)) { - // 鍒涘缓琛� - creatTable(obj, tabName, connection); - } - } catch (SQLException throwables) { - log.error("鍒涘缓琛ㄥ紓甯�"); - log.error(throwables.getSQLState()); - log.error(throwables.getMessage()); - } - // 瀵规瘮瀛楁 骞舵彃鍏ユ暟鎹� - try { - operationTable(obj, tabName, connection); - } catch (SQLException e) { - log.error("瀵规瘮瀛楁鎻掑叆鏁版嵁寮傚父"); - log.error(e.getSQLState()); - log.error(e.getMessage()); - } - } - - /** - * 鎵цpost璇锋眰 - * - * @param params 璇锋眰鍙傛暟 渚嬪锛� param1=val1¶m2=val2 - * @return 璇锋眰杩斿洖鐨刯son杞崲鍚庣殑JSONObject瀵硅薄 - */ - private JSONObject execRequest(String params) { -// System.out.println(params); - URL url = null; - HttpURLConnection connection = null; - try { - url = new URL(BASE_API_URL); - connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("POST"); - connection.setRequestProperty("Accept", "application/json"); -// connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - 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(),StandardCharsets.UTF_8)); - StringBuilder builder = new StringBuilder(); - String str; - while ((str = reader.readLine()) != null) { - builder.append(str); - } - return JSONUtil.parseObj(builder.toString()); - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (connection != null) { - connection.disconnect(); - } - } - return null; - } - - private Connection getConnection(String user,String password,String url) { - try { - log.info("鏁版嵁搴撲俊鎭� ->{},{},{}",user,password,url); - return DriverManager.getConnection(url, user, password); - } catch (Exception throwables) { - log.error("鑾峰彇sql杩炴帴澶辫触"); - throwables.printStackTrace(); - } - return null; - } - - public Connection getConnection() { - try { - log.info("鏁版嵁搴撲俊鎭� ->{},{},{}",USER,PASSWORD,URL); - return DriverManager.getConnection(URL,USER,PASSWORD); - } catch (Exception throwables) { - log.error("鑾峰彇sql杩炴帴澶辫触"); - throwables.printStackTrace(); - } - return null; - } - - /** - * 琛ㄦ槸鍚﹀瓨鍦� - * - * @param connection - * @param tableName - * @return - * @throws SQLException - */ - private Boolean tabIsExists(Connection connection, String tableName,String name) throws SQLException { - String tabSql = "SELECT table_name FROM information_schema.tables WHERE table_schema = ? AND table_name = ?"; - PreparedStatement statement = connection.prepareStatement(tabSql); - statement.setString(1, name); - statement.setString(2, tableName); -// log.info("鍒ゆ柇琛ㄦ槸鍚﹀瓨鍦� sql-> {}", statement.toString()); - ResultSet resultSet = statement.executeQuery(); - boolean next = resultSet.next(); - statement.close(); - return next; - } - - /** - * 鎿嶄綔琛� - * - * @param tabName - * @param connection - * @throws SQLException - */ - private void operationTable(JSONObject jsonObject, String tabName, Connection connection) throws SQLException { - List<String> columns = getColumns(tabName, connection); -// log.info("褰撳墠琛ㄥ瓧娈典负 ->{}", columns); - ArrayList<String> responseColums = new ArrayList<>(); - for (Map.Entry<String, Object> entry : jsonObject.entrySet()) { - String key = entry.getKey().trim().toLowerCase(); - responseColums.add(key); - } -// log.info("璇锋眰杩斿洖鐨勫瓧娈典负 ->{}", responseColums); - responseColums.removeAll(columns); -// log.info("闇�瑕佸鍔犵殑瀛楁 ->{}",responseColums); - if (!responseColums.isEmpty()) { - // 闇�瑕佸鍔犲瓧娈� 骞舵彃鍏ユ暟鎹� - for (String colum : responseColums) { - String sql = "alter table " + tabName + " add column " + colum + " VARCHAR(200) null"; -// log.info("淇敼瀛楁 ->{}",sql.toString()); - Statement statement = connection.createStatement(); - statement.executeUpdate(sql); - statement.close(); - } - insertData(tabName, connection, jsonObject); - } else { - insertData(tabName, connection, jsonObject); - } - } - - /** - * 鎻掑叆鏁版嵁 - * - * @param tabName - * @param connection - * @param jsonObject - * @throws SQLException - */ - private void insertData(String tabName, Connection connection, JSONObject jsonObject) throws SQLException { - // 鎻掑叆鏁版嵁鍓� 鍏堟煡璇㈡暟鎹槸鍚﹀瓨鍦� -// StringBuilder selectSqlBuilder = new StringBuilder(); - StringBuilder insertSqlBuilder = new StringBuilder(); - StringBuilder valueBuilder = new StringBuilder(); - 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()) { - String defaultVal = entry.getValue().toString(); - String key = entry.getKey().trim().toLowerCase(); - if (StrUtil.isBlank(defaultVal) || defaultVal.equals("null")) - continue; - String val = defaultVal.trim().replaceAll("\\s+", "").replace("\\",""); - insertSqlBuilder.append(key).append(", "); - valueBuilder.append("'").append(val.replaceAll("'","鈥�")).append("', "); -// selectSqlBuilder.append(entry.getKey()).append(" = '").append(entry.getValue().toString().replaceAll("'","鈥�")).append("' and "); - } - insertSqlBuilder.append("insert_time, "); - String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); - valueBuilder.append("'").append(time).append("'").append(", "); - insertSqlBuilder.delete(insertSqlBuilder.length() - 2, insertSqlBuilder.length()); - valueBuilder.delete(valueBuilder.length() - 2, valueBuilder.length()); -// selectSqlBuilder.delete(selectSqlBuilder.length() - 5, selectSqlBuilder.length()); - insertSqlBuilder.append(") values (").append(valueBuilder).append(")"); -// log.info("鎻掑叆鍓嶆煡璇� sql ->{}", selectSqlBuilder.toString()); -// Statement statement = connection.prepareStatement(selectSqlBuilder.toString()); -// ResultSet resultSet = statement.executeQuery(selectSqlBuilder.toString()); -// resultSet.next(); -// String string = resultSet.getString("count"); -// statement.close(); - // 濡傛灉涓嶄负0 鍒欒繖鏉℃暟鎹瓨鍦� 涓嶈繘琛屾彃鍏� -// if (!"0".equals(string)) { -// log.info("鏁版嵁瀛樺湪涓嶉渶瑕佹彃鍏� {}", jsonObject); -// return; +//package com.example.utils; +// +//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.example.domain.HisSyncDict; +//import com.example.service.HisSyncDictService; +//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 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.Date; +//import java.util.*; +// +///** +// * @Company: 瑗垮畨璺嘲绉戞妧鏈夐檺鍏徃 +// * @Author: zhaowenxuan +// * @Date: 2024/5/21 16:41 +// */ +//@Slf4j +//@Component +//public class DictionaryUtilNew { +// @Autowired +// private HisSyncDictService hisSyncDictService; +// private static String CONFIG_PATH; +// private static String BASE_API_URL = ""; +// private static final int SIZE = 1000; +// private static String USER = ""; +// private static String PASSWORD = ""; +// private static String URL = ""; +// private static String NAME = ""; +// @Value("${config.path}") +// public void setConfigPath(String configPath) { +// CONFIG_PATH = configPath; +// FileInputStream inputStream = null; +// try { +// inputStream = new FileInputStream(CONFIG_PATH); +// Properties props = new Properties(); +// props.load(inputStream); +// NAME = props.getProperty("name"); +// URL = "jdbc:mysql://" + props.getProperty("ip") + ":" + props.getProperty("prot") + "/" + NAME + "" + +// "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8"; +// USER = props.getProperty("username"); +// 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"; +// } catch (IOException e) { +// System.out.println("鍒濆鍖栨暟鎹簱寮傚父 ->"+e.getMessage()); // } - // 鎻掑叆鏁版嵁 - Statement statement = connection.createStatement(); - log.info("鎻掑叆鏁版嵁 sql-> {}", insertSqlBuilder.toString()); - statement.execute(insertSqlBuilder.toString()); - statement.close(); - } - - /** - * 鑾峰彇琛ㄧ殑鍒� - * - * @param tabName - * @param connection - * @return - * @throws SQLException - */ - private List<String> getColumns(String tabName, Connection connection) throws SQLException { - DatabaseMetaData metaData = connection.getMetaData(); - ResultSet columns = metaData.getColumns(null, null, tabName, null); - ArrayList<String> tabColumns = new ArrayList<>(); - while (columns.next()) { - String columnName = columns.getString("column_name"); - tabColumns.add(columnName); - } - return tabColumns; - } - - /** - * 鍒涘缓琛� - * - * @param resultDataIndex1 杩斿洖鏁版嵁涓殑绗竴涓弬鏁� - * @param tabName - * @param connection - * @throws SQLException - */ - private void creatTable(JSONObject resultDataIndex1, String tabName, Connection connection) throws SQLException { - StringBuilder sql = new StringBuilder("CREATE TABLE " + tabName + " ("); - for (Map.Entry<String, Object> entry : resultDataIndex1.entrySet()) { - String key = entry.getKey().trim().toLowerCase(); - sql.append(key).append(" VARCHAR(200) null,"); - } - sql.append("insert_time").append(" VARCHAR(100) null,"); - sql = new StringBuilder(sql.substring(0, sql.length() - 1)); - sql.append(");"); - log.info("鍒涘缓琛ㄦ牸 -> {}",sql.toString()); - 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); - statement.close(); - } -} +// } +// +// +// /** +// * 鏆傛椂涓嶅仛 +// * 1.90 闂ㄨ瘖鏄庣粏璁¤垂鍙婄粍鍚堣璐归」鐩� MZJFZHMXXM +// * +// */ +// +//// 鍒嗛〉姣忔1000鏉� +// static { +// try { +// Class.forName("com.mysql.cj.jdbc.Driver"); +// } catch (Exception e) { +// System.out.println("闈欐�佷唬鐮佸潡寮傚父 ->"+e.getMessage()); +// } +// } +// +// public static void main(String[] args) { +// DictionaryUtilNew util = new DictionaryUtilNew(); +// util.exec1(); +// } +// +// /** +// * 澧炲姞榛樿鍙傛暟 +// * @param jsonObject +// * @return +// */ +// public JSONObject addInputVal(JSONObject jsonObject){ +// JSONObject obj = JSONUtil.createObj(); +// String method = jsonObject.getStr("method"); +// if (method.equals("MZJFZHMXXM") || method.equals("MXJFXMZD")){ +// obj.putOpt("mode","1"); +// } +// obj.putOpt("jgbm",""); +// obj.putOpt("bm",""); +// obj.putOpt("flbm",""); +// jsonObject.putOpt("input",obj); +// return jsonObject; +// } +// +// /** +// * 杩涜鍚屾 +// */ +// public void exec1(){ +// log.info("寮�濮嬫墽琛屽悓姝�"); +// Connection connection = getConnection(); +// if (connection == null) +// return; +// List<HisSyncDict> hisSyncDicts = hisSyncDictService.list(); +// for (HisSyncDict hisSyncDict : hisSyncDicts) { +// extracted(NAME, connection, hisSyncDict); +// } +// try { +// connection.close(); +// } catch (SQLException ignored) { } +// log.info("鎵ц鍚屾瀹屾瘯"); +// } +// +// /** +// * 閫氳繃鎸囧畾瀛楀吀杩涜鍚屾 +// */ +// public void execMethods(List<String > methods){ +// log.info("寮�濮嬫墽琛屽悓姝�"); +// Connection connection = getConnection(); +// if (connection == null) +// return; +// for (String method : methods) { +// LambdaQueryWrapper<HisSyncDict> wrapper = new LambdaQueryWrapper<>(); +// wrapper.eq(HisSyncDict::getDictName,method); +// HisSyncDict one = hisSyncDictService.getOne(wrapper); +// if (one == null){ +// log.error("{}瀛楀吀鍦ㄦ暟鎹簱涓笉瀛樺湪,璇锋鏌ユ暟鎹簱鎴栬姹傚弬鏁版槸鍚﹀~鍐欓敊璇�",method); +// continue; +// } +// extracted(NAME,connection,one); +// } +// try { +// connection.close(); +// } catch (SQLException ignored) { } +// log.info("鎵ц鍚屾瀹屾瘯"); +// } +// +// private void extracted(String name, Connection connection, HisSyncDict hisSyncDict) { +// String method = hisSyncDict.getDictName(); +// log.info("寮�濮嬭姹備唬鐮� ->{}", method); +// String tabName = "ltkj_" + method.toLowerCase(); +// boolean isLimit = false; +// int page = 1; +// int maxPage = 1; +// JSONObject object = JSONUtil.createObj(); +// object.putOpt("method", method); +// object = addInputVal(object); +// if (hisSyncDict.getIsLimit() == 1) { +// isLimit = true; +// JSONObject input = object.getJSONObject("input"); +// input.putOpt("pagecount", SIZE); +// input.putOpt("page", page); +// } +// log.info("璇锋眰鎺ュ彛 ->{}, 璇锋眰鍙傛暟 ->{}", BASE_API_URL, object.toString()); +// JSONObject entries = execRequest(object.toString()); +//// log.info("璇锋眰杩斿洖 ->{}", entries.toString()); +// 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); +// if (maxPage > 1) { +// for (page = 2; page <= maxPage; page++) { +// object.clear(); +// object.putOpt("method", method); +// object = addInputVal(object); +// JSONObject input = object.getJSONObject("input"); +// input.putOpt("pagecount", SIZE); +// input.putOpt("page", page); +// log.info("璇锋眰鎺ュ彛 ->{}, 璇锋眰鍙傛暟 ->{}", BASE_API_URL, object.toString()); +// entries = execRequest(object.toString()); +//// log.info("璇锋眰杩斿洖 ->{}", entries.toString()); +// response = entries.getJSONObject("Response"); +// if ("0".equals(response.getStr("ResultCode"))) { +// LimitInsertData(connection, tabName, response, name, page); +// } else { +// log.error("{} 璇锋眰澶辫触锛歿}", method, object.toString()); +// } +// } +// } +// } else { +// JSONArray resultData = response.getJSONArray("ResultData"); +// List<JSONObject> list = JSONUtil.toList(resultData, JSONObject.class); +// for (JSONObject jsonObject : list) { +// editDataBase(connection, tabName, jsonObject, name); +// } +// } +// } else { +// log.error("{}璇锋眰澶辫触 - 璇锋眰鐘舵�佺爜涓嶄负0, 璇锋眰鍙傛暟 ->{}, 璇锋眰杩斿洖 ->{}", method, object.toString(), response.toString()); +// } +// } +// +// /** +// * 閽堝浜庡垎椤垫帴鍙� 鍒涘缓琛ㄣ�佹彃鍏ユ暟鎹� +// * +// * @param connection +// * @param tabName +// * @param response +// * @return +// */ +// private int LimitInsertData(Connection connection, String tabName, JSONObject response,String name,Integer page) { +// 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; +// log.info("璇锋眰杩斿洖鎬绘潯鏁� ->{},褰撳墠椤� ->{},鎬婚〉鏁� ->{}",totalCount,page,maxPage); +// jsonArray.forEach(obj -> { +// editDataBase(connection, tabName, (JSONObject) obj,name); +// }); +// return maxPage; +// } +// +// /** +// * 鎿嶄綔鏁版嵁搴� +// * +// * @param connection +// * @param tabName +// * @param obj +// */ +// private void editDataBase(Connection connection, String tabName, JSONObject obj,String name) { +// try { +// if (!tabIsExists(connection, tabName,name)) { +// // 鍒涘缓琛� +// creatTable(obj, tabName, connection); +// } +// } catch (SQLException throwables) { +// log.error("鍒涘缓琛ㄥ紓甯�"); +// log.error(throwables.getSQLState()); +// log.error(throwables.getMessage()); +// } +// // 瀵规瘮瀛楁 骞舵彃鍏ユ暟鎹� +// try { +// operationTable(obj, tabName, connection); +// } catch (SQLException e) { +// log.error("瀵规瘮瀛楁鎻掑叆鏁版嵁寮傚父"); +// log.error(e.getSQLState()); +// log.error(e.getMessage()); +// } +// } +// +// /** +// * 鎵цpost璇锋眰 +// * +// * @param params 璇锋眰鍙傛暟 渚嬪锛� param1=val1¶m2=val2 +// * @return 璇锋眰杩斿洖鐨刯son杞崲鍚庣殑JSONObject瀵硅薄 +// */ +// private JSONObject execRequest(String params) { +//// System.out.println(params); +// URL url = null; +// HttpURLConnection connection = null; +// try { +// url = new URL(BASE_API_URL); +// connection = (HttpURLConnection) url.openConnection(); +// connection.setRequestMethod("POST"); +// connection.setRequestProperty("Accept", "application/json"); +//// connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); +// 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(),StandardCharsets.UTF_8)); +// StringBuilder builder = new StringBuilder(); +// String str; +// while ((str = reader.readLine()) != null) { +// builder.append(str); +// } +// return JSONUtil.parseObj(builder.toString()); +// } catch (IOException e) { +// e.printStackTrace(); +// } finally { +// if (connection != null) { +// connection.disconnect(); +// } +// } +// return null; +// } +// +// private Connection getConnection(String user,String password,String url) { +// try { +// log.info("鏁版嵁搴撲俊鎭� ->{},{},{}",user,password,url); +// return DriverManager.getConnection(url, user, password); +// } catch (Exception throwables) { +// log.error("鑾峰彇sql杩炴帴澶辫触"); +// throwables.printStackTrace(); +// } +// return null; +// } +// +// public Connection getConnection() { +// try { +// log.info("鏁版嵁搴撲俊鎭� ->{},{},{}",USER,PASSWORD,URL); +// return DriverManager.getConnection(URL,USER,PASSWORD); +// } catch (Exception throwables) { +// log.error("鑾峰彇sql杩炴帴澶辫触"); +// throwables.printStackTrace(); +// } +// return null; +// } +// +// /** +// * 琛ㄦ槸鍚﹀瓨鍦� +// * +// * @param connection +// * @param tableName +// * @return +// * @throws SQLException +// */ +// private Boolean tabIsExists(Connection connection, String tableName,String name) throws SQLException { +// String tabSql = "SELECT table_name FROM information_schema.tables WHERE table_schema = ? AND table_name = ?"; +// PreparedStatement statement = connection.prepareStatement(tabSql); +// statement.setString(1, name); +// statement.setString(2, tableName); +//// log.info("鍒ゆ柇琛ㄦ槸鍚﹀瓨鍦� sql-> {}", statement.toString()); +// ResultSet resultSet = statement.executeQuery(); +// boolean next = resultSet.next(); +// statement.close(); +// return next; +// } +// +// /** +// * 鎿嶄綔琛� +// * +// * @param tabName +// * @param connection +// * @throws SQLException +// */ +// private void operationTable(JSONObject jsonObject, String tabName, Connection connection) throws SQLException { +// List<String> columns = getColumns(tabName, connection); +//// log.info("褰撳墠琛ㄥ瓧娈典负 ->{}", columns); +// ArrayList<String> responseColums = new ArrayList<>(); +// for (Map.Entry<String, Object> entry : jsonObject.entrySet()) { +// String key = entry.getKey().trim().toLowerCase(); +// responseColums.add(key); +// } +//// log.info("璇锋眰杩斿洖鐨勫瓧娈典负 ->{}", responseColums); +// responseColums.removeAll(columns); +//// log.info("闇�瑕佸鍔犵殑瀛楁 ->{}",responseColums); +// if (!responseColums.isEmpty()) { +// // 闇�瑕佸鍔犲瓧娈� 骞舵彃鍏ユ暟鎹� +// for (String colum : responseColums) { +// String sql = "alter table " + tabName + " add column " + colum + " VARCHAR(200) null"; +//// log.info("淇敼瀛楁 ->{}",sql.toString()); +// Statement statement = connection.createStatement(); +// statement.executeUpdate(sql); +// statement.close(); +// } +// insertData(tabName, connection, jsonObject); +// } else { +// insertData(tabName, connection, jsonObject); +// } +// } +// +// /** +// * 鎻掑叆鏁版嵁 +// * +// * @param tabName +// * @param connection +// * @param jsonObject +// * @throws SQLException +// */ +// private void insertData(String tabName, Connection connection, JSONObject jsonObject) throws SQLException { +// // 鎻掑叆鏁版嵁鍓� 鍏堟煡璇㈡暟鎹槸鍚﹀瓨鍦� +//// StringBuilder selectSqlBuilder = new StringBuilder(); +// StringBuilder insertSqlBuilder = new StringBuilder(); +// StringBuilder valueBuilder = new StringBuilder(); +// 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()) { +// String defaultVal = entry.getValue().toString(); +// String key = entry.getKey().trim().toLowerCase(); +// if (StrUtil.isBlank(defaultVal) || defaultVal.equals("null")) +// continue; +// String val = defaultVal.trim().replaceAll("\\s+", "").replace("\\",""); +// insertSqlBuilder.append(key).append(", "); +// valueBuilder.append("'").append(val.replaceAll("'","鈥�")).append("', "); +//// selectSqlBuilder.append(entry.getKey()).append(" = '").append(entry.getValue().toString().replaceAll("'","鈥�")).append("' and "); +// } +// insertSqlBuilder.append("insert_time, "); +// String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); +// valueBuilder.append("'").append(time).append("'").append(", "); +// insertSqlBuilder.delete(insertSqlBuilder.length() - 2, insertSqlBuilder.length()); +// valueBuilder.delete(valueBuilder.length() - 2, valueBuilder.length()); +//// selectSqlBuilder.delete(selectSqlBuilder.length() - 5, selectSqlBuilder.length()); +// insertSqlBuilder.append(") values (").append(valueBuilder).append(")"); +//// log.info("鎻掑叆鍓嶆煡璇� sql ->{}", selectSqlBuilder.toString()); +//// Statement statement = connection.prepareStatement(selectSqlBuilder.toString()); +//// ResultSet resultSet = statement.executeQuery(selectSqlBuilder.toString()); +//// resultSet.next(); +//// String string = resultSet.getString("count"); +//// statement.close(); +// // 濡傛灉涓嶄负0 鍒欒繖鏉℃暟鎹瓨鍦� 涓嶈繘琛屾彃鍏� +//// if (!"0".equals(string)) { +//// log.info("鏁版嵁瀛樺湪涓嶉渶瑕佹彃鍏� {}", jsonObject); +//// return; +//// } +// // 鎻掑叆鏁版嵁 +// Statement statement = connection.createStatement(); +// log.info("鎻掑叆鏁版嵁 sql-> {}", insertSqlBuilder.toString()); +// statement.execute(insertSqlBuilder.toString()); +// statement.close(); +// } +// +// /** +// * 鑾峰彇琛ㄧ殑鍒� +// * +// * @param tabName +// * @param connection +// * @return +// * @throws SQLException +// */ +// private List<String> getColumns(String tabName, Connection connection) throws SQLException { +// DatabaseMetaData metaData = connection.getMetaData(); +// ResultSet columns = metaData.getColumns(null, null, tabName, null); +// ArrayList<String> tabColumns = new ArrayList<>(); +// while (columns.next()) { +// String columnName = columns.getString("column_name"); +// tabColumns.add(columnName); +// } +// return tabColumns; +// } +// +// /** +// * 鍒涘缓琛� +// * +// * @param resultDataIndex1 杩斿洖鏁版嵁涓殑绗竴涓弬鏁� +// * @param tabName +// * @param connection +// * @throws SQLException +// */ +// private void creatTable(JSONObject resultDataIndex1, String tabName, Connection connection) throws SQLException { +// StringBuilder sql = new StringBuilder("CREATE TABLE " + tabName + " ("); +// for (Map.Entry<String, Object> entry : resultDataIndex1.entrySet()) { +// String key = entry.getKey().trim().toLowerCase(); +// sql.append(key).append(" VARCHAR(200) null,"); +// } +// sql.append("insert_time").append(" VARCHAR(100) null,"); +// sql = new StringBuilder(sql.substring(0, sql.length() - 1)); +// sql.append(");"); +// log.info("鍒涘缓琛ㄦ牸 -> {}",sql.toString()); +// 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); +// statement.close(); +// } +//} diff --git a/src/main/java/com/example/utils/HttpClientUtils.java b/src/main/java/com/example/utils/HttpClientUtils.java index 1856869..509a9e5 100644 --- a/src/main/java/com/example/utils/HttpClientUtils.java +++ b/src/main/java/com/example/utils/HttpClientUtils.java @@ -186,6 +186,7 @@ BufferedReader reader = null; StringBuilder response = new StringBuilder(); try { + log.info("璇锋眰鍦板潃 ->{}",httpUrl); URL url = new URL(httpUrl); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); @@ -195,6 +196,7 @@ } connection.setDoOutput(true); StringBuilder postData = new StringBuilder(); + log.info("鍏ュ弬 ->{}", JSONUtil.toJsonStr(maps)); for (Map.Entry<String, Object> entry : maps.entrySet()) { if (postData.length() > 0) { postData.append("&"); @@ -211,6 +213,7 @@ while ((line = reader.readLine()) != null) { response.append(line); } + log.info("杩斿洖 ->{}",response); } catch (Exception e) { e.printStackTrace(); return null; @@ -236,6 +239,7 @@ String boundary = "----WebKitFormBoundary" + UUID.randomUUID().toString().replaceAll("-", ""); String CRLF = "\r\n"; try { + log.info("璇锋眰鍦板潃 ->{}",httpUrl); URL url = new URL(httpUrl); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); @@ -244,6 +248,7 @@ connection.setRequestProperty("Authorization", authorization); } connection.setDoOutput(true); + log.info("鍏ュ弬 ->{}",maps); outStream = new DataOutputStream(connection.getOutputStream()); for (Map.Entry<String, Object> entry : maps.entrySet()) { outStream.writeBytes("--" + boundary + CRLF); @@ -259,6 +264,7 @@ while ((line = reader.readLine()) != null) { response.append(line); } + log.info("杩斿洖 ->{}",response); } catch (Exception e) { e.printStackTrace(); return null; diff --git a/src/main/java/com/example/utils/synczd/DictionaryUtilShanXiXiAnMeiJiYy.java b/src/main/java/com/example/utils/synczd/DictionaryUtilShanXiXiAnMeiJiYy.java new file mode 100644 index 0000000..8c9e7fa --- /dev/null +++ b/src/main/java/com/example/utils/synczd/DictionaryUtilShanXiXiAnMeiJiYy.java @@ -0,0 +1,460 @@ +package com.example.utils.synczd; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.example.config.ConfigValue; +import com.example.domain.HisSyncDict; +import com.example.mapper.HisSyncDictMapper; +import com.example.service.HisSyncDictService; +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 java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.sql.*; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.*; + +/** + * 闄曡タ瑗垮畨鐓ゆ満鍖婚櫌瀛楀吀鍚屾绫� + * @Company: 瑗垮畨璺嘲绉戞妧鏈夐檺鍏徃 + * @Author: zhaowenxuan + * @Date: 2024/12/19 16:41 + */ +@Slf4j +@Component +public class DictionaryUtilShanXiXiAnMeiJiYy { + + @Autowired + private HisSyncDictService hisSyncDictService; + @Autowired + private ConfigValue configValue; + @Autowired + private HisSyncDictMapper hisSyncDictMapper; + + private static String CONFIG_PATH; + private static String BASE_API_URL = ""; + private static final int SIZE = 100; + private static String USER = ""; + private static String PASSWORD = ""; + private static String URL = ""; + private static String NAME = ""; + @Value("${config.path}") + public void setConfigPath(String configPath) { + CONFIG_PATH = configPath; + NAME = configValue.getConfigValue("name"); + URL = "jdbc:mysql://" + configValue.getConfigValue("ip") + ":" + configValue.getConfigValue("prot") + "/" + NAME + + "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8"; + USER = configValue.getConfigValue("username"); + PASSWORD = configValue.getConfigValue("password"); + String apiUrl = configValue.getConfigValue("ShanXi_Qin_XiAn_MeiJi.his_api_url"); + String apiPort = configValue.getConfigValue("ShanXi_Qin_XiAn_MeiJi.his_api_port"); + BASE_API_URL = apiUrl+":"+apiPort+configValue.getConfigValue("ShanXi_Qin_XiAn_MeiJi.hisapiappend"); + } + + + /** + * 鏆傛椂涓嶅仛 + * 1.90 闂ㄨ瘖鏄庣粏璁¤垂鍙婄粍鍚堣璐归」鐩� MZJFZHMXXM + * + */ + +// 鍒嗛〉姣忔1000鏉� + static { + try { + Class.forName("com.mysql.cj.jdbc.Driver"); + } catch (Exception e) { + System.out.println("闈欐�佷唬鐮佸潡寮傚父 ->"+e.getMessage()); + } + } + + /** + * 杩涜鍚屾 + */ + public void exec(List<HisSyncDict> hisSyncDicts,String token){ + log.info("寮�濮嬫墽琛屽悓姝�"); + Connection connection = getConnection(); + if (connection == null) + return; + for (HisSyncDict hisSyncDict : hisSyncDicts) { + boolean isFormatJson = false; + if (hisSyncDict.getDictName().equals("getKeShizd") || hisSyncDict.getDictName().equals("getKeShiByConditionszd")|| hisSyncDict.getDictName().equals("getShouFeiXmzd")) + isFormatJson = true; + hisSyncDict.setDictName(hisSyncDict.getHospId()+"_"+hisSyncDict.getDictName()); + extracted(NAME, connection, hisSyncDict,token,isFormatJson); + } + try { + connection.close(); + } catch (SQLException ignored) { } + hisSyncDictMapper.proSyncCommonDict(); + log.info("鎵ц鍚屾瀹屾瘯"); + } + + private void extracted(String name, Connection connection, HisSyncDict hisSyncDict,String token,Boolean isFormatJson) { + String method = hisSyncDict.getDictName(); + log.info("寮�濮嬭姹備唬鐮� ->{}", method); + String tabName = "ltkj_" + method.toLowerCase(); + boolean isLimit = false; + int page = 1; + int maxPage = 1; + String params = hisSyncDict.getParams(); + params = params.replace("${pageIndex}",String.valueOf(page)); + params = params.replace("${pageSize}",String.valueOf(SIZE)); + JSONObject object = JSONUtil.parseObj(params); + if (hisSyncDict.getIsLimit() == 1) { + isLimit = true; + } + log.info("璇锋眰鎺ュ彛 ->{}, 璇锋眰鍙傛暟 ->{}", BASE_API_URL+hisSyncDict.getUrl(), object); + JSONObject entries = execRequest(object.toString(),hisSyncDict,token); + log.info("璇锋眰杩斿洖 ->{}", entries.toString()); + if (isFormatJson){ + if (entries != null && "1".equals(entries.getStr("returnCode"))) { + JSONObject response = entries.getJSONObject("returnData"); + try { + dropTable(tabName, connection); + } catch (SQLException e) { + log.error("鍒犻櫎琛ㄥ紓甯� ->{}", e.getMessage()); + } + if (isLimit) { + maxPage = LimitInsertData(connection, tabName, response, name, page); + log.info("璁$畻椤电爜涓� ->{}", maxPage); + if (maxPage > 1) { + for (page = 2; page <= maxPage; page++) { + params = hisSyncDict.getParams(); + params = params.replace("${pageIndex}",String.valueOf(page)); + params = params.replace("${pageSize}",String.valueOf(SIZE)); + object = JSONUtil.parseObj(params); + log.info("璇锋眰鎺ュ彛 ->{}, 璇锋眰鍙傛暟 ->{}", BASE_API_URL+hisSyncDict.getUrl(), object.toString()); + entries = execRequest(object.toString(),hisSyncDict,token); + log.info("璇锋眰杩斿洖 ->{}", entries.toString()); + response = entries.getJSONObject("returnData"); + if ("1".equals(entries.getStr("returnCode"))) { + LimitInsertData(connection, tabName, response, name, page); + } else { + log.error("{} 璇锋眰澶辫触锛歿}", method, object.toString()); + } + } + } + } else { + JSONArray resultData = response.getJSONArray("list"); + List<JSONObject> list = JSONUtil.toList(resultData, JSONObject.class); + for (JSONObject jsonObject : list) { + editDataBase(connection, tabName, jsonObject, name); + } + } + } + }else { + if (entries != null && "1".equals(entries.getStr("returnCode"))) { + JSONArray response = entries.getJSONArray("returnData"); + try { + dropTable(tabName, connection); + List<JSONObject> list = JSONUtil.toList(response, JSONObject.class); + for (JSONObject jsonObject : list) { + editDataBase(connection, tabName, jsonObject, name); + } + } catch (SQLException e) { + log.error("鍒犻櫎琛ㄥ紓甯� ->{}", e.getMessage()); + } + if (isLimit) { + if (tabName.contains("_getjianchaxmzd")) maxPage = 10000; + log.info("璁$畻椤电爜涓� ->{}", maxPage); + if (maxPage > 1) { + for (page = 2; page <= maxPage; page++) { + params = hisSyncDict.getParams(); + params = params.replace("${pageIndex}",String.valueOf(page)); + params = params.replace("${pageSize}",String.valueOf(SIZE)); + object = JSONUtil.parseObj(params); + log.info("璇锋眰鎺ュ彛 ->{}, 璇锋眰鍙傛暟 ->{}", BASE_API_URL+hisSyncDict.getUrl(), object.toString()); + entries = execRequest(object.toString(),hisSyncDict,token); + log.info("璇锋眰杩斿洖 ->{}", entries.toString()); + response = entries.getJSONArray("returnData"); + if (response.isEmpty()) + break; + List<JSONObject> list = JSONUtil.toList(response, JSONObject.class); + for (JSONObject jsonObject : list) { + editDataBase(connection, tabName, jsonObject, name); + } + } + } + } else { + List<JSONObject> list = JSONUtil.toList(response, JSONObject.class); + for (JSONObject jsonObject : list) { + editDataBase(connection, tabName, jsonObject, name); + } + } + + + + + } + } + + } + + /** + * 閽堝浜庡垎椤垫帴鍙� 鍒涘缓琛ㄣ�佹彃鍏ユ暟鎹� + * + * @param connection + * @param tabName + * @param response + * @return + */ + private int LimitInsertData(Connection connection, String tabName, JSONObject response,String name,Integer page) { + JSONArray jsonArray = response.getJSONArray("list"); + JSONObject entries = (JSONObject) jsonArray.get(0); + int maxPage; + // 琛屾暟 鏁版嵁杩斿洖鐨勭鍑犺 + Integer rowNumber = response.getInt("RowNumber"); + // 鎬绘潯鏁� + Integer totalCount = response.getInt("totalRows"); + Integer pageCount = response.getInt("pageCount"); + maxPage = (totalCount + 100 - 1) / 100; + log.info("璇锋眰杩斿洖鎬绘潯鏁� ->{},褰撳墠椤� ->{},鎬婚〉鏁� ->{}",totalCount,page,maxPage); + jsonArray.forEach(obj -> { + editDataBase(connection, tabName, (JSONObject) obj,name); + }); + return pageCount; + } + + /** + * 鎿嶄綔鏁版嵁搴� + * + * @param connection + * @param tabName + * @param obj + */ + private void editDataBase(Connection connection, String tabName, JSONObject obj,String name) { + try { + if (!tabIsExists(connection, tabName,name)) { + // 鍒涘缓琛� + creatTable(obj, tabName, connection); + } + } catch (SQLException throwables) { + log.error("鍒涘缓琛ㄥ紓甯�"); + log.error(throwables.getSQLState()); + log.error(throwables.getMessage()); + } + // 瀵规瘮瀛楁 骞舵彃鍏ユ暟鎹� + try { + operationTable(obj, tabName, connection); + } catch (SQLException e) { + log.error("瀵规瘮瀛楁鎻掑叆鏁版嵁寮傚父"); + log.error(e.getSQLState()); + log.error(e.getMessage()); + } + } + + /** + * 鎵цpost璇锋眰 + * + * @param params 璇锋眰鍙傛暟 渚嬪锛� param1=val1¶m2=val2 + * @return 璇锋眰杩斿洖鐨刯son杞崲鍚庣殑JSONObject瀵硅薄 + */ + private JSONObject execRequest(String params,HisSyncDict hisSyncDict,String token) { + URL url = null; + HttpURLConnection connection = null; + OutputStreamWriter writer = null; + BufferedReader reader = null; + StringBuilder response = new StringBuilder(); + try { + url = new URL(BASE_API_URL+hisSyncDict.getUrl()); + connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + connection.setRequestProperty("Authorization", token); + if (hisSyncDict.getUrl().equals("/zhuShuJu/getListYiShengZd") || hisSyncDict.getUrl().equals("/zhuShuJu/getJianChaXm")){ + connection.setRequestProperty("dangQianYhId","DBA"); + if (hisSyncDict.getUrl().equals("/zhuShuJu/getJianChaXm")) + connection.setRequestProperty("yuanQuId","1"); + } + connection.setDoOutput(true); + StringBuilder postData = new StringBuilder(); + JSONObject jsonObject = JSONUtil.parseObj(params); + for (String key : jsonObject.keySet()) { + if (postData.length() > 0) { + postData.append("&"); + } + String encode = URLEncoder.encode(key, "UTF-8"); + String encode1 = URLEncoder.encode(String.valueOf(jsonObject.get(key)), "UTF-8"); + postData.append(encode).append("=").append(encode1); + } + + writer = new OutputStreamWriter(connection.getOutputStream()); + writer.write(postData.toString()); + writer.flush(); + reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + response.append(line); + } + return JSONUtil.parseObj(response); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (connection != null) { + connection.disconnect(); + } + } + return null; + } + + public Connection getConnection() { + try { + log.info("鏁版嵁搴撲俊鎭� ->{},{},{}",USER,PASSWORD,URL); + return DriverManager.getConnection(URL,USER,PASSWORD); + } catch (Exception throwables) { + log.error("鑾峰彇sql杩炴帴澶辫触"); + throwables.printStackTrace(); + } + return null; + } + + /** + * 琛ㄦ槸鍚﹀瓨鍦� + * + * @param connection + * @param tableName + * @return + * @throws SQLException + */ + private Boolean tabIsExists(Connection connection, String tableName,String name) throws SQLException { + String tabSql = "SELECT table_name FROM information_schema.tables WHERE table_schema = ? AND table_name = ?"; + PreparedStatement statement = connection.prepareStatement(tabSql); + statement.setString(1, name); + statement.setString(2, tableName); +// log.info("鍒ゆ柇琛ㄦ槸鍚﹀瓨鍦� sql-> {}", statement.toString()); + ResultSet resultSet = statement.executeQuery(); + boolean next = resultSet.next(); + statement.close(); + return next; + } + + /** + * 鎿嶄綔琛� + * + * @param tabName + * @param connection + * @throws SQLException + */ + private void operationTable(JSONObject jsonObject, String tabName, Connection connection) throws SQLException { + List<String> columns = getColumns(tabName, connection); +// log.info("褰撳墠琛ㄥ瓧娈典负 ->{}", columns); + ArrayList<String> responseColums = new ArrayList<>(); + for (Map.Entry<String, Object> entry : jsonObject.entrySet()) { + String key = entry.getKey().trim().toLowerCase(); + responseColums.add(key); + } +// log.info("璇锋眰杩斿洖鐨勫瓧娈典负 ->{}", responseColums); + responseColums.removeAll(columns); +// log.info("闇�瑕佸鍔犵殑瀛楁 ->{}",responseColums); + if (!responseColums.isEmpty()) { + // 闇�瑕佸鍔犲瓧娈� 骞舵彃鍏ユ暟鎹� + for (String colum : responseColums) { + String sql = "alter table " + tabName + " add column " + colum + " VARCHAR(200) null"; +// log.info("淇敼瀛楁 ->{}",sql.toString()); + Statement statement = connection.createStatement(); + statement.executeUpdate(sql); + statement.close(); + } + insertData(tabName, connection, jsonObject); + } else { + insertData(tabName, connection, jsonObject); + } + } + + /** + * 鎻掑叆鏁版嵁 + * + * @param tabName + * @param connection + * @param jsonObject + * @throws SQLException + */ + private void insertData(String tabName, Connection connection, JSONObject jsonObject) throws SQLException { + // 鎻掑叆鏁版嵁鍓� 鍏堟煡璇㈡暟鎹槸鍚﹀瓨鍦� + StringBuilder insertSqlBuilder = new StringBuilder(); + StringBuilder valueBuilder = new StringBuilder(); + insertSqlBuilder.append("insert into ").append(tabName).append(" ("); + for (Map.Entry<String, Object> entry : jsonObject.entrySet()) { + String defaultVal = entry.getValue().toString(); + String key = entry.getKey().trim().toLowerCase(); + if (StrUtil.isBlank(defaultVal) || defaultVal.equals("null")) + continue; + String val = defaultVal.trim().replaceAll("\\s+", "").replace("\\",""); + insertSqlBuilder.append(key).append(", "); + valueBuilder.append("'").append(val.replaceAll("'","鈥�")).append("', "); + } + insertSqlBuilder.append("insert_time, "); + String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + valueBuilder.append("'").append(time).append("'").append(", "); + insertSqlBuilder.delete(insertSqlBuilder.length() - 2, insertSqlBuilder.length()); + valueBuilder.delete(valueBuilder.length() - 2, valueBuilder.length()); + insertSqlBuilder.append(") values (").append(valueBuilder).append(")"); + // 鎻掑叆鏁版嵁 + Statement statement = connection.createStatement(); + log.info("鎻掑叆鏁版嵁 sql-> {}", insertSqlBuilder.toString()); + statement.execute(insertSqlBuilder.toString()); + statement.close(); + } + + /** + * 鑾峰彇琛ㄧ殑鍒� + * + * @param tabName + * @param connection + * @return + * @throws SQLException + */ + private List<String> getColumns(String tabName, Connection connection) throws SQLException { + DatabaseMetaData metaData = connection.getMetaData(); + ResultSet columns = metaData.getColumns(null, null, tabName, null); + ArrayList<String> tabColumns = new ArrayList<>(); + while (columns.next()) { + String columnName = columns.getString("column_name"); + tabColumns.add(columnName); + } + return tabColumns; + } + + /** + * 鍒涘缓琛� + * + * @param resultDataIndex1 杩斿洖鏁版嵁涓殑绗竴涓弬鏁� + * @param tabName + * @param connection + * @throws SQLException + */ + private void creatTable(JSONObject resultDataIndex1, String tabName, Connection connection) throws SQLException { + StringBuilder sql = new StringBuilder("CREATE TABLE " + tabName + " ("); + for (Map.Entry<String, Object> entry : resultDataIndex1.entrySet()) { + String key = entry.getKey().trim().toLowerCase(); + sql.append(key).append(" VARCHAR(200) null,"); + } + sql.append("insert_time").append(" VARCHAR(100) null,"); + sql = new StringBuilder(sql.substring(0, sql.length() - 1)); + sql.append(");"); + log.info("鍒涘缓琛ㄦ牸 -> {}",sql.toString()); + 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); + statement.close(); + } +} diff --git a/src/main/resources/mapper/HisSyncDictMapper.xml b/src/main/resources/mapper/HisSyncDictMapper.xml index 8b0cd28..04383d8 100644 --- a/src/main/resources/mapper/HisSyncDictMapper.xml +++ b/src/main/resources/mapper/HisSyncDictMapper.xml @@ -15,4 +15,9 @@ id,dict_name,is_limit, remark </sql> + <select id="proSyncCommonDict" statementType="CALLABLE"> + { + call pro_sync_common_zd() + } + </select> </mapper> diff --git a/src/main/resources/mapper/TjFlowingWaterHisMapper.xml b/src/main/resources/mapper/TjFlowingWaterHisMapper.xml new file mode 100644 index 0000000..23795f1 --- /dev/null +++ b/src/main/resources/mapper/TjFlowingWaterHisMapper.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.example.mapper.TjFlowingWaterHisMapper"> + + <resultMap id="BaseResultMap" type="com.example.domain.TjFlowingWaterHis"> + <id property="id" column="id" jdbcType="BIGINT"/> + <result property="parentId" column="parent_id" jdbcType="VARCHAR"/> + <result property="currentId" column="current_id" jdbcType="VARCHAR"/> + <result property="xmId" column="xm_id" jdbcType="VARCHAR"/> + </resultMap> + + <sql id="Base_Column_List"> + id,parent_id,current_id,xm_id + </sql> +</mapper> diff --git a/src/test/java/com/example/ImgCheckApplicationTests.java b/src/test/java/com/example/ImgCheckApplicationTests.java index bbce86d..1b1ae1b 100644 --- a/src/test/java/com/example/ImgCheckApplicationTests.java +++ b/src/test/java/com/example/ImgCheckApplicationTests.java @@ -1,7 +1,18 @@ package com.example; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; import org.junit.jupiter.api.Test;; import org.springframework.boot.test.context.SpringBootTest; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.util.Map; @SpringBootTest class ImgCheckApplicationTests { @@ -10,4 +21,41 @@ void contextLoads() { } + public static void main(String[] args) { + URL url = null; + HttpURLConnection connection = null; + OutputStreamWriter writer = null; + BufferedReader reader = null; + StringBuilder response = new StringBuilder(); + try { + url = new URL("http://oapi.xamjyy.com/OAPI/zhuShuJu/getShouFeiXm"); + connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + connection.setRequestProperty("Authorization", "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyI2MjY0MTYyNTk2MTY5OTczNzYiXSwiZXhwIjoxNzM0NzkyMzk2LCJqdGkiOiJhYjg0YWNjZi0xMDYyLTRjNDUtYjdhNy04OGVkYmQ4ZTdmYmMiLCJjbGllbnRfaWQiOiJYRlpaUUVmWFRaN2V4aGhpIn0.CothzTpZoz08Kvb8z3FIl0CtZQhc5p12H0oHmmdp1gQ"); + connection.setDoOutput(true); + StringBuilder postData = new StringBuilder(); + JSONObject jsonObject = JSONUtil.parseObj("{\"pageIndex\":1,\"pageSize\":10}"); + for (String key : jsonObject.keySet()) { + if (postData.length() > 0) { + postData.append("&"); + } + String encode = URLEncoder.encode(key, "UTF-8"); + String encode1 = URLEncoder.encode(String.valueOf(jsonObject.get(key)), "UTF-8"); + postData.append(encode).append("=").append(encode1); + } + writer = new OutputStreamWriter(connection.getOutputStream()); + System.out.println("postData = " + postData); + writer.write(postData.toString()); + writer.flush(); + reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + response.append(line); + } + System.out.println("response = " + response); + }catch (Exception e){ + + } + } } -- Gitblit v1.8.0