|
@ -1,18 +1,13 @@
|
|
package com.yihu.ehr.service.standard;
|
|
package com.yihu.ehr.service.standard;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import com.yihu.ehr.common.config.SysConfig;
|
|
import com.yihu.ehr.common.config.SysConfig;
|
|
import com.yihu.ehr.common.constants.Constants;
|
|
import com.yihu.ehr.common.constants.Constants;
|
|
import com.yihu.ehr.dbhelper.jdbc.DBHelper;
|
|
|
|
import com.yihu.ehr.util.compress.Zipper;
|
|
import com.yihu.ehr.util.compress.Zipper;
|
|
import com.yihu.ehr.util.encode.Base64;
|
|
|
|
import com.yihu.ehr.util.encrypt.RSA;
|
|
import com.yihu.ehr.util.encrypt.RSA;
|
|
import com.yihu.ehr.util.file.FileUtil;
|
|
|
|
import com.yihu.ehr.util.httpclient.EsbHttp;
|
|
import com.yihu.ehr.util.httpclient.EsbHttp;
|
|
|
|
import com.yihu.ehr.util.httpclient.HttpClientUtil;
|
|
import com.yihu.ehr.util.httpclient.Response;
|
|
import com.yihu.ehr.util.httpclient.Response;
|
|
import com.yihu.ehr.util.log.LogUtil;
|
|
import com.yihu.ehr.util.log.LogUtil;
|
|
import com.yihu.ehr.util.operator.CollectionUtil;
|
|
|
|
import com.yihu.ehr.util.operator.SqlCreate;
|
|
import com.yihu.ehr.util.operator.SqlCreate;
|
|
import com.yihu.ehr.util.operator.StringUtil;
|
|
import com.yihu.ehr.util.operator.StringUtil;
|
|
import org.dom4j.Document;
|
|
import org.dom4j.Document;
|
|
@ -28,15 +23,12 @@ public class StandardManager {
|
|
public static String versionMethod;
|
|
public static String versionMethod;
|
|
public static String downMethod;
|
|
public static String downMethod;
|
|
private static volatile StandardManager instance;
|
|
private static volatile StandardManager instance;
|
|
private DBHelper db;
|
|
|
|
private SysConfig sysConfig;
|
|
private SysConfig sysConfig;
|
|
private File[] zipFiles;
|
|
private File[] zipFiles;
|
|
private String localVersion;
|
|
private String localVersion;
|
|
|
|
|
|
|
|
|
|
public StandardManager(){
|
|
public StandardManager(){
|
|
if (db == null) {
|
|
|
|
db = new DBHelper();
|
|
|
|
}
|
|
|
|
sysConfig = SysConfig.getInstance();
|
|
sysConfig = SysConfig.getInstance();
|
|
}
|
|
}
|
|
|
|
|
|
@ -75,7 +67,7 @@ public class StandardManager {
|
|
LogUtil.warn("总支撑平台尚无可用版本进行标准升级");
|
|
LogUtil.warn("总支撑平台尚无可用版本进行标准升级");
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
localVersion = getCurrentVersion();
|
|
|
|
|
|
String localVersion = getCurrentVersion();
|
|
if (StringUtil.isEmpty(localVersion)) {
|
|
if (StringUtil.isEmpty(localVersion)) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@ -105,6 +97,7 @@ public class StandardManager {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
versionUpdate(encryptPwd);
|
|
versionUpdate(encryptPwd);
|
|
|
|
localVersion = remoteVersion;
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@ -115,14 +108,9 @@ public class StandardManager {
|
|
* @return String
|
|
* @return String
|
|
*/
|
|
*/
|
|
public synchronized String getCurrentVersion() {
|
|
public synchronized String getCurrentVersion() {
|
|
if (!StringUtil.isEmpty(localVersion)){
|
|
|
|
return localVersion;
|
|
|
|
}
|
|
|
|
List<JSONObject> list = db.query("select code from std_inner_version order by code desc");
|
|
|
|
if (!CollectionUtil.isEmpty(list)) {
|
|
|
|
localVersion = list.get(0).getString("code");
|
|
|
|
|
|
if (StringUtil.isEmpty(localVersion)){
|
|
|
|
localVersion = new StandardService().getCurrentVersion();
|
|
}
|
|
}
|
|
|
|
|
|
return localVersion;
|
|
return localVersion;
|
|
}
|
|
}
|
|
|
|
|
|
@ -148,7 +136,7 @@ public class StandardManager {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
result = genData();
|
|
|
|
|
|
result = new StandardService().genData(zipFiles);
|
|
if (!result) {
|
|
if (!result) {
|
|
LogUtil.fatal("生成标准数据失败.");
|
|
LogUtil.fatal("生成标准数据失败.");
|
|
return false;
|
|
return false;
|
|
@ -165,17 +153,14 @@ public class StandardManager {
|
|
if (re.has("password")&&re.has("url")) {
|
|
if (re.has("password")&&re.has("url")) {
|
|
String encryptPwd = re.getString("password");
|
|
String encryptPwd = re.getString("password");
|
|
String zipContent = re.getString("url");
|
|
String zipContent = re.getString("url");
|
|
byte[] decode = Base64.decode(zipContent);
|
|
|
|
String downloadFilePath = SysConfig.getInstance().getTempFile() + "/" + Constants.STANDARD_ZIP;
|
|
String downloadFilePath = SysConfig.getInstance().getTempFile() + "/" + Constants.STANDARD_ZIP;
|
|
boolean writeFile = FileUtil.writeFile(downloadFilePath, decode, "UTF-8");
|
|
|
|
if (!writeFile) {
|
|
|
|
LogUtil.fatal("下载标准包失败,生成本地临时文件错误.");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
//boolean writeFile = FileUtil.writeFile(downloadFilePath, zipContent, "UTF-8");
|
|
|
|
HttpClientUtil.downLoadFile(downloadFilePath,zipContent,"","");
|
|
|
|
|
|
return encryptPwd;
|
|
return encryptPwd;
|
|
}
|
|
}
|
|
else{
|
|
else{
|
|
LogUtil.fatal("下载标准包失败");
|
|
|
|
|
|
LogUtil.fatal("获取标准包失败");
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@ -192,7 +177,13 @@ public class StandardManager {
|
|
|
|
|
|
private boolean unpack(String encryptPwd) {
|
|
private boolean unpack(String encryptPwd) {
|
|
try {
|
|
try {
|
|
Key key = RSA.genPublicKey(sysConfig.getPublicKey());
|
|
|
|
|
|
String publicKey = sysConfig.getPublicKey();
|
|
|
|
if(publicKey==null ||publicKey.length()==0)
|
|
|
|
{
|
|
|
|
publicKey = EsbHttp.getPublicKey();
|
|
|
|
sysConfig.setPublicKey(publicKey);
|
|
|
|
}
|
|
|
|
Key key = RSA.genPublicKey(publicKey);
|
|
if (key == null) {
|
|
if (key == null) {
|
|
LogUtil.fatal("解压文件错误,获取公钥错误.");
|
|
LogUtil.fatal("解压文件错误,获取公钥错误.");
|
|
return false;
|
|
return false;
|
|
@ -227,42 +218,6 @@ public class StandardManager {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
private boolean genData() {
|
|
|
|
List<String> sqlList = new ArrayList<>();
|
|
|
|
List<String> fileNameList = new ArrayList<>();
|
|
|
|
List<String> deleteDataList = new ArrayList<>();
|
|
|
|
for (File file : zipFiles) {
|
|
|
|
if (!file.getName().contains("_cda")) {
|
|
|
|
if (file.getName().contains("org_")||file.getName().contains("adapter_")
|
|
|
|
||file.getName().contains("std_")) {
|
|
|
|
fileNameList.add(StringUtil.substring(file.getName(), 0, file.getName().indexOf(Constants.DOT)));
|
|
|
|
}
|
|
|
|
if (!file.getParentFile().getName().equals(Constants.CDA_FILE)) {
|
|
|
|
createData(file, sqlList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SqlCreate sqlCreate = new SqlCreate();
|
|
|
|
for (String fileName : fileNameList) {
|
|
|
|
sqlCreate.setTableName(fileName);
|
|
|
|
deleteDataList.add(sqlCreate.deleteData());
|
|
|
|
}
|
|
|
|
String[] deleteArray = new String[deleteDataList.size()];
|
|
|
|
deleteDataList.toArray(deleteArray);
|
|
|
|
String[] sqlArray = new String[sqlList.size()];
|
|
|
|
sqlList.toArray(sqlArray);
|
|
|
|
try {
|
|
|
|
db.executeBatch(deleteArray);
|
|
|
|
db = new DBHelper();
|
|
|
|
db.executeBatch(sqlArray);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createData(File file, List<String> sqlList) {
|
|
private void createData(File file, List<String> sqlList) {
|
|
try {
|
|
try {
|
|
SAXReader reader = new SAXReader();
|
|
SAXReader reader = new SAXReader();
|