|
|
|
@ -2420,23 +2420,38 @@ public class CollectServiceImpl implements CollectService { |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public String saveFileToCatalogUpload(String mountFileId,String fileExtension, String fileDpi, String path, String fileName, long fileSize, String archivesInfo, Map<String, Object> fileCategory,String filePath) { |
|
|
|
public String saveFileToCatalogUpload(Integer fondsNo,String mountFileId,String fileExtension, String fileDpi, String path, String fileName, long fileSize, String archivesInfo, Map<String, Object> fileCategory,String filePath) { |
|
|
|
String returnString = ""; |
|
|
|
Map<String, Object> singCategory = categoryArchivesRepository.findCategoryByPid(fileCategory.get("pid")+"",3); |
|
|
|
String archiveNo = archivesInfo.split("_")[0]; |
|
|
|
String archiveIdSql = "select id,collect_formal,maintitle,archive_no from "+singCategory.get("en_name")+" where archive_no = '"+archiveNo+"' limit 0,1"; |
|
|
|
String archiveIdSql = "select id,collect_formal,maintitle,archive_no from "+singCategory.get("en_name")+" where archive_no = '"+archiveNo+"' " + |
|
|
|
"and fonds_affiliation = '"+fondsNo+"' limit 0,1"; |
|
|
|
List<Object[]> list = entityManager.createNativeQuery(archiveIdSql).getResultList(); |
|
|
|
if(list.size() == 0){ |
|
|
|
returnString = archiveNo + "搜索失败"; |
|
|
|
MountFileDetails details = new MountFileDetails(); |
|
|
|
details.setMountId(mountFileId); |
|
|
|
details.setFileName(fileName); |
|
|
|
details.setMountResult(2); |
|
|
|
details.setReason(returnString); |
|
|
|
details.setArchivesId(null); |
|
|
|
details.setArchivesNo(archiveNo); |
|
|
|
details.setMaintitle(null); |
|
|
|
mountFileDetailsRepository.saveAndFlush(details); |
|
|
|
return returnString; |
|
|
|
} |
|
|
|
Object[] objects = list.get(0); |
|
|
|
String archivesId = objects[0]+""; |
|
|
|
Integer collectFormal = objects[1] == null ? 0 : Integer.parseInt(objects[1]+""); |
|
|
|
String returnString = ""; |
|
|
|
|
|
|
|
//当该文件归档时 |
|
|
|
if(collectFormal == 2){ |
|
|
|
returnString = objects[2]+"("+objects[3]+")"; |
|
|
|
returnString = objects[3]+"正在归档"; |
|
|
|
MountFileDetails details = new MountFileDetails(); |
|
|
|
details.setMountId(mountFileId); |
|
|
|
details.setFileName(fileName); |
|
|
|
details.setMountResult(2); |
|
|
|
details.setReason("该档案正在归档,无法添加电子原文"); |
|
|
|
details.setReason(objects[2]+"("+objects[3]+")正在归档,无法添加电子原文"); |
|
|
|
details.setArchivesId(archivesId); |
|
|
|
details.setArchivesNo(objects[3]+""); |
|
|
|
details.setMaintitle(objects[2]+""); |
|
|
|
@ -2627,137 +2642,140 @@ public class CollectServiceImpl implements CollectService { |
|
|
|
sysFileList.setTotalSize(fileChunkRequest.getTotalSize()); |
|
|
|
sysFileListService.save(sysFileList); |
|
|
|
|
|
|
|
//添加电子原文JSON |
|
|
|
JSONArray jsons = new JSONArray(fileChunkRequest.getFileJsonString()); |
|
|
|
JSONObject json = (JSONObject) jsons.get(0); |
|
|
|
json.put("file_path",repath); |
|
|
|
json.put("archive_id",fileChunkRequest.getArchivesId()); |
|
|
|
json.put("last_modified",mergeFile.lastModified()); |
|
|
|
json.put("is_analysis",-1); |
|
|
|
json.put("is_mark",0); |
|
|
|
|
|
|
|
try{ |
|
|
|
//获取电子原文表门类信息 |
|
|
|
Map<String,Object> pcategory = categoryArchivesRepository.findCategoryByPid(categoryId,3); |
|
|
|
Set<String> keys = new HashSet<>(json.keySet()); |
|
|
|
keys.add("digital_summary"); |
|
|
|
keys.add("public_key"); |
|
|
|
keys.add("private_key"); |
|
|
|
|
|
|
|
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); |
|
|
|
keyPairGenerator.initialize(2048); |
|
|
|
KeyPair keyPair = keyPairGenerator.generateKeyPair(); |
|
|
|
String publicKey = org.apache.commons.codec.binary.Base64.encodeBase64String(keyPair.getPublic().getEncoded()); |
|
|
|
String privateKey = Base64.encodeBase64String(keyPair.getPrivate().getEncoded()); |
|
|
|
String digitalSummary = null; |
|
|
|
if(!StringUtils.isEmpty(fileChunkRequest.getArchivesId())){ |
|
|
|
|
|
|
|
String insertKey = "id,"; |
|
|
|
String insertValue = "'"+insertId+"',"; |
|
|
|
for(String key:keys){ |
|
|
|
insertKey += key+","; |
|
|
|
//添加电子原文JSON |
|
|
|
JSONArray jsons = new JSONArray(fileChunkRequest.getFileJsonString()); |
|
|
|
JSONObject json = (JSONObject) jsons.get(0); |
|
|
|
json.put("file_path",repath); |
|
|
|
json.put("archive_id",fileChunkRequest.getArchivesId()); |
|
|
|
json.put("last_modified",mergeFile.lastModified()); |
|
|
|
json.put("is_analysis",-1); |
|
|
|
json.put("is_mark",0); |
|
|
|
|
|
|
|
if("digital_summary".equals(key)){ |
|
|
|
digitalSummary = FourFileUtils.getDigitalSummary(new File(location+json.get("file_path"))); |
|
|
|
insertValue += StringUtils.isEmpty(digitalSummary) ? "null," : "'"+digitalSummary+"',"; |
|
|
|
}else if("public_key".equals(key)) { |
|
|
|
insertValue += StringUtils.isEmpty(publicKey) ? "null," : "'"+publicKey+"',"; |
|
|
|
}else if("private_key".equals(key)) { |
|
|
|
insertValue += StringUtils.isEmpty(privateKey) ? "null," : "'"+privateKey+"',"; |
|
|
|
}else{ |
|
|
|
insertValue += json.get(key) == null ? null +",":"'"+json.get(key)+"',"; |
|
|
|
try{ |
|
|
|
//获取电子原文表门类信息 |
|
|
|
Map<String,Object> pcategory = categoryArchivesRepository.findCategoryByPid(categoryId,3); |
|
|
|
Set<String> keys = new HashSet<>(json.keySet()); |
|
|
|
keys.add("digital_summary"); |
|
|
|
keys.add("public_key"); |
|
|
|
keys.add("private_key"); |
|
|
|
|
|
|
|
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); |
|
|
|
keyPairGenerator.initialize(2048); |
|
|
|
KeyPair keyPair = keyPairGenerator.generateKeyPair(); |
|
|
|
String publicKey = org.apache.commons.codec.binary.Base64.encodeBase64String(keyPair.getPublic().getEncoded()); |
|
|
|
String privateKey = Base64.encodeBase64String(keyPair.getPrivate().getEncoded()); |
|
|
|
String digitalSummary = null; |
|
|
|
|
|
|
|
String insertKey = "id,"; |
|
|
|
String insertValue = "'"+insertId+"',"; |
|
|
|
for(String key:keys){ |
|
|
|
insertKey += key+","; |
|
|
|
|
|
|
|
if("digital_summary".equals(key)){ |
|
|
|
digitalSummary = FourFileUtils.getDigitalSummary(new File(location+json.get("file_path"))); |
|
|
|
insertValue += StringUtils.isEmpty(digitalSummary) ? "null," : "'"+digitalSummary+"',"; |
|
|
|
}else if("public_key".equals(key)) { |
|
|
|
insertValue += StringUtils.isEmpty(publicKey) ? "null," : "'"+publicKey+"',"; |
|
|
|
}else if("private_key".equals(key)) { |
|
|
|
insertValue += StringUtils.isEmpty(privateKey) ? "null," : "'"+privateKey+"',"; |
|
|
|
}else{ |
|
|
|
insertValue += json.get(key) == null ? null +",":"'"+json.get(key)+"',"; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
insertKey = insertKey.substring(0,insertKey.length()-1); |
|
|
|
insertValue = insertValue.substring(0,insertValue.length()-1); |
|
|
|
String sql = "insert into " + toCategory.get("en_name") + "("+insertKey+") values ("+insertValue+")"; |
|
|
|
int result = entityManager.createNativeQuery(sql).executeUpdate(); |
|
|
|
insertKey = insertKey.substring(0,insertKey.length()-1); |
|
|
|
insertValue = insertValue.substring(0,insertValue.length()-1); |
|
|
|
String sql = "insert into " + toCategory.get("en_name") + "("+insertKey+") values ("+insertValue+")"; |
|
|
|
int result = entityManager.createNativeQuery(sql).executeUpdate(); |
|
|
|
|
|
|
|
//添加总表 |
|
|
|
ArchivesSummaryFile asFile = new ArchivesSummaryFile(); |
|
|
|
asFile.setFileId(insertId); |
|
|
|
asFile.setArchiveId(json.get("archive_id") == null ? null : json.get("archive_id")+""); |
|
|
|
asFile.setFileType(json.get("file_type") == null ? null : json.get("file_type")+""); |
|
|
|
asFile.setFileDpi(json.get("file_dpi") == null ? null : json.get("file_dpi")+""); |
|
|
|
asFile.setFilePath(json.get("file_path") == null ? null : json.get("file_path")+""); |
|
|
|
asFile.setFileName(json.get("file_name") == null ? null : json.get("file_name")+""); |
|
|
|
asFile.setFileSize(json.get("file_size") == null ? null : Integer.parseInt(json.get("file_size")+"")); |
|
|
|
asFile.setLastModified(json.get("last_modified")==null ?null:json.get("last_modified")+""); |
|
|
|
asFile.setDigitalSummary(StringUtils.isEmpty(digitalSummary) ? null : digitalSummary); |
|
|
|
asFile.setPublicKey(StringUtils.isEmpty(publicKey) ? null : publicKey); |
|
|
|
asFile.setPrivateKey(StringUtils.isEmpty(privateKey) ? null : privateKey); |
|
|
|
asFile.setCategoryId(toCategory.get("id")+""); |
|
|
|
asFile.setCategoryPid(toCategory.get("pid")+""); |
|
|
|
asFile.setCreateTime(new Timestamp(System.currentTimeMillis())); |
|
|
|
asFile.setIsAnalysis(-1); |
|
|
|
asFile.setIsMark(0); |
|
|
|
//添加总表 |
|
|
|
ArchivesSummaryFile asFile = new ArchivesSummaryFile(); |
|
|
|
asFile.setFileId(insertId); |
|
|
|
asFile.setArchiveId(json.get("archive_id") == null ? null : json.get("archive_id")+""); |
|
|
|
asFile.setFileType(json.get("file_type") == null ? null : json.get("file_type")+""); |
|
|
|
asFile.setFileDpi(json.get("file_dpi") == null ? null : json.get("file_dpi")+""); |
|
|
|
asFile.setFilePath(json.get("file_path") == null ? null : json.get("file_path")+""); |
|
|
|
asFile.setFileName(json.get("file_name") == null ? null : json.get("file_name")+""); |
|
|
|
asFile.setFileSize(json.get("file_size") == null ? null : Integer.parseInt(json.get("file_size")+"")); |
|
|
|
asFile.setLastModified(json.get("last_modified")==null ?null:json.get("last_modified")+""); |
|
|
|
asFile.setDigitalSummary(StringUtils.isEmpty(digitalSummary) ? null : digitalSummary); |
|
|
|
asFile.setPublicKey(StringUtils.isEmpty(publicKey) ? null : publicKey); |
|
|
|
asFile.setPrivateKey(StringUtils.isEmpty(privateKey) ? null : privateKey); |
|
|
|
asFile.setCategoryId(toCategory.get("id")+""); |
|
|
|
asFile.setCategoryPid(toCategory.get("pid")+""); |
|
|
|
asFile.setCreateTime(new Timestamp(System.currentTimeMillis())); |
|
|
|
asFile.setIsAnalysis(-1); |
|
|
|
asFile.setIsMark(0); |
|
|
|
|
|
|
|
//解析电子原文 |
|
|
|
String fondsCode = this.findFondsCodeByUsername(username); |
|
|
|
JSONObject josnPOST = new JSONObject(); |
|
|
|
josnPOST.put("id",insertId); |
|
|
|
josnPOST.put("code",fondsCode); |
|
|
|
josnPOST.put("type","uploadFile"); |
|
|
|
josnPOST.put("keywords",""); |
|
|
|
String savePath = asFile.getFilePath(); |
|
|
|
savePath = savePath.substring(0,savePath.lastIndexOf("/")); |
|
|
|
savePath = savePath.replaceAll("category","file_analysis"); |
|
|
|
josnPOST.put("save_path",prefixPath + savePath); |
|
|
|
List<String> passPath = new ArrayList<>(); |
|
|
|
passPath.add(prefixPath + asFile.getFilePath()); |
|
|
|
josnPOST.put("path",passPath.toArray()); |
|
|
|
//解析电子原文 |
|
|
|
String fondsCode = this.findFondsCodeByUsername(username); |
|
|
|
JSONObject josnPOST = new JSONObject(); |
|
|
|
josnPOST.put("id",insertId); |
|
|
|
josnPOST.put("code",fondsCode); |
|
|
|
josnPOST.put("type","uploadFile"); |
|
|
|
josnPOST.put("keywords",""); |
|
|
|
String savePath = asFile.getFilePath(); |
|
|
|
savePath = savePath.substring(0,savePath.lastIndexOf("/")); |
|
|
|
savePath = savePath.replaceAll("category","file_analysis"); |
|
|
|
josnPOST.put("save_path",prefixPath + savePath); |
|
|
|
List<String> passPath = new ArrayList<>(); |
|
|
|
passPath.add(prefixPath + asFile.getFilePath()); |
|
|
|
josnPOST.put("path",passPath.toArray()); |
|
|
|
|
|
|
|
try { |
|
|
|
URL requestURL = new URL(pythonURL+":5051/file_upload"); |
|
|
|
HttpURLConnection conn = (HttpURLConnection) requestURL.openConnection(); |
|
|
|
conn.setRequestMethod("POST"); |
|
|
|
conn.setDoOutput(true); |
|
|
|
try { |
|
|
|
URL requestURL = new URL(pythonURL+":5051/file_upload"); |
|
|
|
HttpURLConnection conn = (HttpURLConnection) requestURL.openConnection(); |
|
|
|
conn.setRequestMethod("POST"); |
|
|
|
conn.setDoOutput(true); |
|
|
|
|
|
|
|
// 设置请求头,指定内容类型和长度 |
|
|
|
conn.setRequestProperty("Content-Type", "application/json"); |
|
|
|
String jsonInputString = josnPOST.toString(); |
|
|
|
byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8); |
|
|
|
conn.setRequestProperty("Content-Length", Integer.toString(input.length)); |
|
|
|
// 设置请求头,指定内容类型和长度 |
|
|
|
conn.setRequestProperty("Content-Type", "application/json"); |
|
|
|
String jsonInputString = josnPOST.toString(); |
|
|
|
byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8); |
|
|
|
conn.setRequestProperty("Content-Length", Integer.toString(input.length)); |
|
|
|
|
|
|
|
// 发送请求参数 |
|
|
|
try(OutputStream os = conn.getOutputStream()) { |
|
|
|
os.write(input); |
|
|
|
} |
|
|
|
// 发送请求参数 |
|
|
|
try(OutputStream os = conn.getOutputStream()) { |
|
|
|
os.write(input); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取服务器响应代码 |
|
|
|
int responseCode = conn.getResponseCode(); |
|
|
|
// 获取服务器响应代码 |
|
|
|
int responseCode = conn.getResponseCode(); |
|
|
|
|
|
|
|
// 读取服务器响应内容(如果有的话) |
|
|
|
if (responseCode == HttpURLConnection.HTTP_OK) { |
|
|
|
java.util.Scanner s = new java.util.Scanner(conn.getInputStream()).useDelimiter("\\A"); |
|
|
|
String response = s.hasNext() ? s.next() : ""; |
|
|
|
JSONObject returnJSON = new JSONObject(response); |
|
|
|
String returnStatus = returnJSON.getStr("status"); |
|
|
|
if("200".equals(returnStatus)){ |
|
|
|
String updateSql = "update " + toCategory.get("en_name") + " set is_analysis = 0 where id = '"+insertId+"'"; |
|
|
|
entityManager.createNativeQuery(updateSql).executeUpdate(); |
|
|
|
asFile.setIsAnalysis(0); |
|
|
|
// 读取服务器响应内容(如果有的话) |
|
|
|
if (responseCode == HttpURLConnection.HTTP_OK) { |
|
|
|
java.util.Scanner s = new java.util.Scanner(conn.getInputStream()).useDelimiter("\\A"); |
|
|
|
String response = s.hasNext() ? s.next() : ""; |
|
|
|
JSONObject returnJSON = new JSONObject(response); |
|
|
|
String returnStatus = returnJSON.getStr("status"); |
|
|
|
if("200".equals(returnStatus)){ |
|
|
|
String updateSql = "update " + toCategory.get("en_name") + " set is_analysis = 0 where id = '"+insertId+"'"; |
|
|
|
entityManager.createNativeQuery(updateSql).executeUpdate(); |
|
|
|
asFile.setIsAnalysis(0); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
//盘点服务器连接超时 |
|
|
|
} |
|
|
|
}else{ |
|
|
|
//盘点服务器连接超时 |
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
asFile = archivesSummaryFileRepository.save(asFile); |
|
|
|
asFile = archivesSummaryFileRepository.save(asFile); |
|
|
|
|
|
|
|
//档案操作日志 |
|
|
|
ArchivesOperateLog log = new ArchivesOperateLog(); |
|
|
|
log.setArchivesId(asFile.getArchiveId()); |
|
|
|
log.setOperateType(17); |
|
|
|
log.setRemarks("大文件上传【"+asFile.getFileName()+"】"); |
|
|
|
archivesOperateLogRepository.save(log); |
|
|
|
//档案操作日志 |
|
|
|
ArchivesOperateLog log = new ArchivesOperateLog(); |
|
|
|
log.setArchivesId(asFile.getArchiveId()); |
|
|
|
log.setOperateType(17); |
|
|
|
log.setRemarks("大文件上传【"+asFile.getFileName()+"】"); |
|
|
|
archivesOperateLogRepository.save(log); |
|
|
|
|
|
|
|
if(null != json.get("archive_id")){ |
|
|
|
this.arrangePatentChild(toCategory,pcategory,json.get("archive_id")+""); |
|
|
|
if(null != json.get("archive_id")){ |
|
|
|
this.arrangePatentChild(toCategory,pcategory,json.get("archive_id")+""); |
|
|
|
} |
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
return repath; |
|
|
|
@ -4045,6 +4063,16 @@ public class CollectServiceImpl implements CollectService { |
|
|
|
return archivesSummaryRepository.getMaxItemNoByParentId(archivesId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean isPowerByFondsIdAndCategoryId(Integer fondsId, String categoryId) { |
|
|
|
boolean isok = false; |
|
|
|
Integer count = archivesSummaryRepository.countByFondsIdAndCategoryId(fondsId,categoryId); |
|
|
|
if(count>0){ |
|
|
|
isok = true; |
|
|
|
} |
|
|
|
return isok; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public void lingshi(String tableName) { |
|
|
|
|