|
@ -0,0 +1,167 @@
|
|
|
package com.yihu.hos.rest.services.crawler;
|
|
|
|
|
|
import com.yihu.hos.core.compress.Zipper;
|
|
|
import com.yihu.hos.core.datatype.DateUtil;
|
|
|
import com.yihu.hos.core.encrypt.RSA;
|
|
|
import com.yihu.hos.core.file.FileUtil;
|
|
|
import com.yihu.hos.core.log.Logger;
|
|
|
import com.yihu.hos.core.log.LoggerFactory;
|
|
|
import com.yihu.hos.rest.models.crawler.config.SysConfig;
|
|
|
import com.yihu.hos.rest.models.crawler.patient.Patient;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.security.Key;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* 质控包上传
|
|
|
*
|
|
|
* @author Air
|
|
|
* @version 1.0
|
|
|
* @created 2015.07.06 15:58
|
|
|
*/
|
|
|
public class QCDataUpload {
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(QCDataUpload.class);
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 上传质控 日报包
|
|
|
* @param patient
|
|
|
* @param type 质控包类型 1 质控包, 2 日报包
|
|
|
* @param currentString 文件夹随机码
|
|
|
* @return
|
|
|
*/
|
|
|
public Boolean uploadQcDailyZip(Patient patient, String type,String currentString) {
|
|
|
ZipFile zipFile = zip(patient,type,currentString);
|
|
|
try {
|
|
|
if (zipFile == null || zipFile.file == null) {
|
|
|
logger.info("压缩质控日报数据失败,质控日报数据未生成,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
boolean result = uploadQc(patient, zipFile, type);
|
|
|
if (!result) {
|
|
|
logger.info("上传质控日报数据失败,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
|
|
|
result = FileUtil.deleteDirectory(new File(zipFile.directory));
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
logger.trace(zipFile.directory);
|
|
|
result = FileUtil.deleteDirectory(new File(zipFile.directory));
|
|
|
if (!result) {
|
|
|
logger.info("删除质控日报临时文件失败,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
|
|
|
return result;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.error("质控服务-日报包上传异常",e);
|
|
|
FileUtil.deleteDirectory(new File(zipFile.directory));
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 上传自控数据档案包
|
|
|
* @param patient 病人信息
|
|
|
* @param type 文件包类型 1 质控包, 2 日报包
|
|
|
* @return
|
|
|
*/
|
|
|
public Boolean uploadQc(Patient patient, String type) {
|
|
|
ZipFile zipFile = zip(patient,type, DateUtil.getCurrentString(DateUtil.DEFAULT_NOW_STRING_FORMAT));
|
|
|
try {
|
|
|
if (zipFile == null || zipFile.file == null) {
|
|
|
logger.info("压缩质控数据失败,质控数据未生成,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
boolean result = uploadQc(patient, zipFile, type);
|
|
|
if (!result) {
|
|
|
logger.info("上传质控数据失败,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
|
|
|
result = FileUtil.deleteDirectory(new File(zipFile.directory));
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
logger.trace(zipFile.directory);
|
|
|
result = FileUtil.deleteDirectory(new File(zipFile.directory));
|
|
|
if (!result) {
|
|
|
logger.info("删除质控临时文件失败,patient_id:" + patient.getPatientId() + ",event_no:" + patient.getEventNo());
|
|
|
return result;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
FileUtil.deleteDirectory(new File(zipFile.directory));
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param patient
|
|
|
* @return
|
|
|
* @modify 从质控数据目录生成zip数据
|
|
|
*/
|
|
|
public ZipFile zip(Patient patient,String type,String currentString) {
|
|
|
try {
|
|
|
QCDataIndex qcDataIndex = new QCDataIndex(patient, currentString);
|
|
|
String dataDirectory = null;
|
|
|
String filePath = null;
|
|
|
String directory = null;
|
|
|
if (QCDataIndex.IndexType.QC_TYPE_DATASET.equals(type)){
|
|
|
dataDirectory = qcDataIndex.getDataDirectory();
|
|
|
directory = qcDataIndex.getDirectory();
|
|
|
filePath = qcDataIndex.createIndex(PatientCDAIndex.IndexType.ZIP, PatientCDAIndex.FileType.ZIP);
|
|
|
}else if (QCDataIndex.IndexType.QC_TYPE_DAILY.equals(type)){
|
|
|
dataDirectory = qcDataIndex.getDataDailyDir();
|
|
|
directory = qcDataIndex.getDailyDir();
|
|
|
filePath = qcDataIndex.createQcDailyIndex(PatientCDAIndex.IndexType.ZIP, PatientCDAIndex.FileType.ZIP);
|
|
|
}
|
|
|
UUID uuidPwd = UUID.randomUUID();
|
|
|
String pwd = uuidPwd.toString();
|
|
|
String publicKey = SysConfig.getInstance().getPublicKeyMap().get(patient.getOrgCode());
|
|
|
if(publicKey== null || publicKey.length() == 0) {
|
|
|
publicKey = EsbHttp.getPublicKey(patient.getOrgCode());
|
|
|
SysConfig.getInstance().getPublicKeyMap().put(patient.getOrgCode(), publicKey);
|
|
|
}
|
|
|
|
|
|
Key key = RSA.genPublicKey(publicKey);
|
|
|
if (key == null) {
|
|
|
logger.info("压缩质控文件错误,获取公钥错误.");
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
ZipFile zipFile = new ZipFile();
|
|
|
zipFile.encryptPwd = RSA.encrypt(pwd, key);
|
|
|
|
|
|
Zipper zipper = new Zipper();
|
|
|
zipFile.file = zipper.zipFileForAll(new File(dataDirectory), filePath, pwd);
|
|
|
zipFile.dataDirectory = dataDirectory;
|
|
|
zipFile.directory = directory;
|
|
|
|
|
|
return zipFile;
|
|
|
} catch (Exception e) {
|
|
|
logger.error("从质控目录生成zip数据时,压缩文件异常");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 上传质控包/日报包
|
|
|
* @param patient
|
|
|
* @param zipFile
|
|
|
* @param type 文件类型 :1-质控包,2-日报包
|
|
|
* @return
|
|
|
*/
|
|
|
private boolean uploadQc(Patient patient, ZipFile zipFile, String type) {
|
|
|
return EsbHttp.uploadQC(patient, zipFile.file, zipFile.encryptPwd, type);
|
|
|
}
|
|
|
|
|
|
private class ZipFile {
|
|
|
public File file;
|
|
|
public String encryptPwd;
|
|
|
public String directory;
|
|
|
public String dataDirectory;
|
|
|
}
|
|
|
|
|
|
}
|