| | |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.example.config.ConfigValue; |
| | | import com.example.domain.DictCommonHisConfig; |
| | | import com.example.domain.HisSyncDict; |
| | | import com.example.mapper.HisSyncDictMapper; |
| | | import com.example.service.DictCommonHisConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | @Component |
| | | public class DictionaryUtilShanXiWeiNanBjxjyy { |
| | | |
| | | @Autowired |
| | | private ConfigValue configValue; |
| | | // @Autowired |
| | | // private ConfigValue configValue; |
| | | @Autowired |
| | | private HisSyncDictMapper hisSyncDictMapper; |
| | | @Autowired |
| | | private DictCommonHisConfigService dictCommonHisConfigService; |
| | | |
| | | private static String CONFIG_PATH; |
| | | private static String BASE_API_URL = ""; |
| | | // 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("ShanXi_Qin_BaoJi_Bjxjyy.name"); |
| | | URL = "jdbc:mysql://" + configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.ip") + ":" + configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.prot") + "/" + NAME + |
| | | "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8"; |
| | | USER = configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.username"); |
| | | PASSWORD = configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.password"); |
| | | String apiUrl = configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.his_api_url"); |
| | | String apiPort = configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.his_api_port"); |
| | | BASE_API_URL = apiUrl+":"+apiPort+configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.hisapiappend"); |
| | | } |
| | | // 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("ShanXi_Qin_BaoJi_Bjxjyy.name"); |
| | | // URL = "jdbc:mysql://" + configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.ip") |
| | | // + ":" + configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.prot") + "/" + NAME + |
| | | // "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8"; |
| | | // USER = configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.username"); |
| | | // PASSWORD = configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.password"); |
| | | // String apiUrl = configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.his_api_url"); |
| | | // String apiPort = configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.his_api_port"); |
| | | // BASE_API_URL = apiUrl+":"+apiPort+configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.hisapiappend"); |
| | | // } |
| | | |
| | | |
| | | /** |
| | |
| | | * 进行同步 |
| | | */ |
| | | public void exec(List<HisSyncDict> hisSyncDicts, String token){ |
| | | DictCommonHisConfig config = dictCommonHisConfigService.getConfigByHospital("bjxjyy"); |
| | | log.info("开始执行同步"); |
| | | Connection connection = getConnection(); |
| | | Connection connection = getConnection(config); |
| | | if (connection == null) |
| | | return; |
| | | for (HisSyncDict hisSyncDict : hisSyncDicts) { |
| | |
| | | ) |
| | | isFormatJson = true; |
| | | hisSyncDict.setDictName(hisSyncDict.getHospId()+"_"+hisSyncDict.getDictName()); |
| | | extracted(NAME, connection, hisSyncDict,token,isFormatJson); |
| | | extracted(config.getDbName(), connection, hisSyncDict,token,isFormatJson,config); |
| | | } |
| | | try { |
| | | connection.close(); |
| | |
| | | log.info("执行同步完毕"); |
| | | } |
| | | |
| | | private void extracted(String name, Connection connection, HisSyncDict hisSyncDict,String token,Boolean isFormatJson) { |
| | | private void extracted(String name, Connection connection, HisSyncDict hisSyncDict,String token,Boolean isFormatJson,DictCommonHisConfig config) { |
| | | String method = hisSyncDict.getDictName(); |
| | | log.info("开始请求代码 ->{}", method); |
| | | String tabName = "ltkj_" + method.toLowerCase(); |
| | |
| | | if (hisSyncDict.getIsLimit() == 1) { |
| | | isLimit = true; |
| | | } |
| | | log.info("请求接口 ->{}, 请求参数 ->{}", BASE_API_URL+hisSyncDict.getUrl(), object); |
| | | JSONObject entries = execRequest(object.toString(),hisSyncDict,token); |
| | | log.info("请求接口 ->{}, 请求参数 ->{}", config.getHisUrl()+hisSyncDict.getUrl(), object); |
| | | JSONObject entries = execRequest(config,object.toString(),hisSyncDict,token); |
| | | log.info("请求返回 ->{}", entries.toString()); |
| | | if (isFormatJson){ |
| | | if ("1".equals(entries.getStr("returnCode"))) { |
| | |
| | | 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("请求接口 ->{}, 请求参数 ->{}", config.getHisUrl()+hisSyncDict.getUrl(), object.toString()); |
| | | entries = execRequest(config,object.toString(),hisSyncDict,token); |
| | | log.info("请求返回 ->{}", entries.toString()); |
| | | response = entries.getJSONObject("returnData"); |
| | | if ("1".equals(entries.getStr("returnCode"))) { |
| | |
| | | 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("请求接口 ->{}, 请求参数 ->{}", config.getHisUrl()+hisSyncDict.getUrl(), object.toString()); |
| | | entries = execRequest(config,object.toString(),hisSyncDict,token); |
| | | log.info("请求返回 ->{}", entries.toString()); |
| | | response = entries.getJSONArray("returnData"); |
| | | if (response.isEmpty()) |
| | |
| | | * @param params 请求参数 例如: param1=val1¶m2=val2 |
| | | * @return 请求返回的json转换后的JSONObject对象 |
| | | */ |
| | | private JSONObject execRequest(String params,HisSyncDict hisSyncDict,String token) { |
| | | private JSONObject execRequest(DictCommonHisConfig config,String params,HisSyncDict hisSyncDict,String token) { |
| | | java.net.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()); |
| | | url = new URL(config.getHisUrl()+hisSyncDict.getUrl()); |
| | | connection = (HttpURLConnection) url.openConnection(); |
| | | connection.setRequestMethod("POST"); |
| | | connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); |
| | |
| | | return null; |
| | | } |
| | | |
| | | public Connection getConnection() { |
| | | public Connection getConnection(DictCommonHisConfig config) { |
| | | // public void setConfigPath(String configPath) { |
| | | // CONFIG_PATH = configPath; |
| | | // NAME = configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.name"); |
| | | // URL = "jdbc:mysql://" + configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.ip") |
| | | // + ":" + configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.prot") + "/" + NAME + |
| | | // "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8"; |
| | | // USER = configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.username"); |
| | | // PASSWORD = configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.password"); |
| | | // String apiUrl = configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.his_api_url"); |
| | | // String apiPort = configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.his_api_port"); |
| | | // BASE_API_URL = apiUrl+":"+apiPort+configValue.getConfigValue("ShanXi_Qin_BaoJi_Bjxjyy.hisapiappend"); |
| | | // } |
| | | try { |
| | | log.info("数据库信息 ->{},{},{}",USER,PASSWORD,URL); |
| | | return DriverManager.getConnection(URL,USER,PASSWORD); |
| | | String url = "jdbc:mysql://" + config.getDbIp() |
| | | + ":" + config.getDbPort() + "/" + config.getDbName() + |
| | | "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8"; |
| | | log.info("数据库信息 ->{},{},{}",config.getDbUser(),config.getDbPassword(),url); |
| | | return DriverManager.getConnection(url,config.getDbUser(),config.getDbPassword()); |
| | | } catch (Exception throwables) { |
| | | log.error("获取sql连接失败"); |
| | | throwables.printStackTrace(); |