15个文件已修改
12个文件已添加
1个文件已删除
| | |
| | | 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) { |
| | | } |
| | | } |
| | | } |
| | |
| | | Properties properties = new Properties(); |
| | | // 这里是测试写法,具体的value可以通过请求参数传递过来 |
| | | 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); |
| | |
| | | public static final String CARD_ID = "cardId"; |
| | | |
| | | /** |
| | | * 体检号 |
| | | */ |
| | | public static final String Tj_NUM = "tjNum"; |
| | | |
| | | /** |
| | | * 病人姓名 |
| | | */ |
| | | public static final String CUS_NAME = "cusName"; |
| | |
| | | */ |
| | | public static final String CUS_ACCOUNT_ID = "cusAccountId"; |
| | | |
| | | public static final String YE_WU_LEIXING = "yeWuLx"; |
| | | |
| | | public static final String HOSPITAL = "hospital"; |
| | | |
| | | /** |
| | | * 公共查询key |
| | | */ |
New file |
| | |
| | | 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; |
| | | } |
| | |
| | | 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; |
| | |
| | | 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); |
| | | } |
| | | } |
New file |
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | 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为String集合 存储字典名 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为String集合 存储字典名 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(); |
| | | // } |
| | | //} |
| | |
| | | |
| | | private Integer isLimit; |
| | | |
| | | private String url; |
| | | |
| | | private String params; |
| | | |
| | | private String hospId; |
| | | |
| | | private String remark; |
| | | |
| | | private static final long serialVersionUID = 1L; |
New file |
| | |
| | | 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; |
| | | |
| | | /** |
| | | * 总开单id |
| | | */ |
| | | private String parentId; |
| | | |
| | | /** |
| | | * 当前项目订单id |
| | | */ |
| | | private String currentId; |
| | | |
| | | /** |
| | | * his项目id |
| | | */ |
| | | private String xmId; |
| | | |
| | | @TableField(exist = false) |
| | | private static final long serialVersionUID = 1L; |
| | | } |
| | |
| | | |
| | | 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; |
| | |
| | | */ |
| | | @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("配置文件中没有配置hosp_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的name |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | * @Entity com.example.domain.HisSyncDict |
| | | */ |
| | | public interface HisSyncDictMapper extends BaseMapper<HisSyncDict> { |
| | | |
| | | void proSyncCommonDict(); |
| | | } |
| | | |
| | | |
New file |
| | |
| | | package com.example.mapper; |
| | | |
| | | import com.example.domain.TjFlowingWaterHis; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | | /** |
| | | * @author 10845 |
| | | * @description 针对表【tj_flowing_water_his(his订单流水关联)】的数据库操作Mapper |
| | | * @createDate 2024-12-21 15:53:33 |
| | | * @Entity com.example.domain.TjFlowingWaterHis |
| | | */ |
| | | public interface TjFlowingWaterHisMapper extends BaseMapper<TjFlowingWaterHis> { |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | |
| | | 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(); |
| | | // } |
| | | //} |
New file |
| | |
| | | package com.example.scheudleds; |
| | | |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class DictSyncCommon { |
| | | |
| | | } |
| | |
| | | /** |
| | | * 收费/退费完成通知第三方 |
| | | */ |
| | | String pushZhiFuMsg(Map<String ,Object> map); |
| | | String pushZhiFuMsg(String hospName,Map<String ,Object> map); |
| | | |
| | | |
| | | /** |
| | |
| | | * 检验样本 |
| | | */ |
| | | String getJyYangBen(Map<String ,Object> map); |
| | | |
| | | |
| | | /** |
| | | * 同步字典 |
| | | */ |
| | | void syncDict(String hospName); |
| | | } |
New file |
| | |
| | | package com.example.service; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | public interface PacsService { |
| | | String orderAdd(String xml); |
| | | } |
New file |
| | |
| | | package com.example.service; |
| | | |
| | | import com.example.domain.TjFlowingWaterHis; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | |
| | | /** |
| | | * @author 10845 |
| | | * @description 针对表【tj_flowing_water_his(his订单流水关联)】的数据库操作Service |
| | | * @createDate 2024-12-21 15:53:33 |
| | | */ |
| | | public interface TjFlowingWaterHisService extends IService<TjFlowingWaterHis> { |
| | | |
| | | } |
New file |
| | |
| | | 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 针对表【tj_flowing_water_his(his订单流水关联)】的数据库操作Service实现 |
| | | * @createDate 2024-12-21 15:53:33 |
| | | */ |
| | | @Service |
| | | public class TjFlowingWaterHisServiceImpl extends ServiceImpl<TjFlowingWaterHisMapper, TjFlowingWaterHis> |
| | | implements TjFlowingWaterHisService{ |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | |
| | | 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; |
| | | |
| | |
| | | * @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 () { |
| | |
| | | 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){ |
| | |
| | | }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",""); |
| | |
| | | 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){ |
| | |
| | | } |
| | | 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 |
| | |
| | | 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 |
| | |
| | | }); |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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(); |
| | |
| | | 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(); |
| | |
| | | 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(); |
| | |
| | | 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(); |
| | |
| | | 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(); |
| | |
| | | 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(); |
| | |
| | | }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); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | 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"; |
| | | } |
| | | } |
New file |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | 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 请求返回的json转换后的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 请求返回的json转换后的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(); |
| | | // } |
| | | //} |
| | |
| | | BufferedReader reader = null; |
| | | StringBuilder response = new StringBuilder(); |
| | | try { |
| | | log.info("请求地址 ->{}",httpUrl); |
| | | URL url = new URL(httpUrl); |
| | | connection = (HttpURLConnection) url.openConnection(); |
| | | connection.setRequestMethod("POST"); |
| | |
| | | } |
| | | 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("&"); |
| | |
| | | while ((line = reader.readLine()) != null) { |
| | | response.append(line); |
| | | } |
| | | log.info("返回 ->{}",response); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | |
| | | 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"); |
| | |
| | | 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); |
| | |
| | | while ((line = reader.readLine()) != null) { |
| | | response.append(line); |
| | | } |
| | | log.info("返回 ->{}",response); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
New file |
| | |
| | | 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 请求返回的json转换后的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(); |
| | | } |
| | | } |
| | |
| | | id,dict_name,is_limit, |
| | | remark |
| | | </sql> |
| | | <select id="proSyncCommonDict" statementType="CALLABLE"> |
| | | { |
| | | call pro_sync_common_zd() |
| | | } |
| | | </select> |
| | | </mapper> |
New file |
| | |
| | | <?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> |
| | |
| | | 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 { |
| | |
| | | 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){ |
| | | |
| | | } |
| | | } |
| | | } |