|
@@ -13,15 +13,28 @@ import org.springblade.archive.service.IArchivesAutoService;
|
|
|
import org.springblade.archive.utils.FileUtils;
|
|
|
import org.springblade.business.entity.ArchiveFile;
|
|
|
import org.springblade.business.feign.ArchiveFileClient;
|
|
|
+import org.springblade.common.utils.CommonUtil;
|
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
+import org.springblade.core.oss.model.BladeFile;
|
|
|
+import org.springblade.core.tool.utils.FileUtil;
|
|
|
+import org.springblade.core.tool.utils.IoUtil;
|
|
|
+import org.springblade.core.tool.utils.ResourceUtil;
|
|
|
import org.springblade.core.tool.utils.StringUtil;
|
|
|
+import org.springblade.manager.entity.ArchiveTreeContract;
|
|
|
+import org.springblade.manager.feign.ArchiveTreeClient;
|
|
|
+import org.springblade.manager.feign.ArchiveTreeContractClient;
|
|
|
+import org.springblade.resource.builder.oss.OssBuilder;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.*;
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.PreparedStatement;
|
|
|
+import java.sql.Statement;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -33,14 +46,146 @@ import java.util.List;
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class ArchiveOfflineVersionInfoServiceImpl extends BaseServiceImpl<ArchiveOfflineVersionInfoMapper, ArchiveOfflineVersionInfo> implements IArchiveOfflineVersionInfoService {
|
|
|
+ private final ArchiveOfflineVersionInfoMapper infoMapper;
|
|
|
private final sqliteConfig data;
|
|
|
private final ArchivesAutoMapper autoMapper;
|
|
|
private final ArchiveFileClient fileClient;
|
|
|
+ private final ArchiveTreeContractClient contractClient;
|
|
|
+ private final OssBuilder ossBuilder;
|
|
|
|
|
|
@Override
|
|
|
- public void packData(Long projectId) {
|
|
|
+ public void packData(Long projectId) throws Exception {
|
|
|
+ String localUrl = "/www/wwwroot/localClient/local_archives/alilib";
|
|
|
+ String packUrl = "/www/wwwroot/localClient";
|
|
|
+ String zipUrl = "/www/wwwroot/localClient.zip";
|
|
|
+ //清空url的文件夹
|
|
|
+ CommonUtil.deleteDir(localUrl);
|
|
|
+ //导入档案到sqlite
|
|
|
+ this.autoToSqlite(projectId);
|
|
|
+ //导入归档树到sqlite
|
|
|
+ this.contractToSqlite(projectId);
|
|
|
+ //导入档案文件
|
|
|
+ this.fileToSqlite(projectId);
|
|
|
+ //打包文件
|
|
|
+ CommonUtil.packageZip(packUrl);
|
|
|
+ //上传文件
|
|
|
+ File zipFile = ResourceUtil.getFile(zipUrl);
|
|
|
+ BladeFile bladeFile = ossBuilder.template().putFile("localClient.zip",new FileInputStream(zipFile));
|
|
|
+ ArchiveOfflineVersionInfo info = new ArchiveOfflineVersionInfo();
|
|
|
+ info.setId(SnowFlakeUtil.getId());
|
|
|
+ info.setFileUrl(bladeFile.getLink());
|
|
|
+ info.setFileName(bladeFile.getOriginalName());
|
|
|
+ info.setUploadDate(LocalDateTime.now());
|
|
|
+ info.setProjectId(projectId);
|
|
|
+ info.setFileSize(CommonUtil.getResourceLength(bladeFile.getLink())+"");
|
|
|
+ infoMapper.insert(info);
|
|
|
+
|
|
|
+ }
|
|
|
+ public void fileToSqlite(Long projectId) throws Exception {
|
|
|
+ List<ArchiveFile> list = fileClient.getListByProjectId(projectId);
|
|
|
+ String localUrl = "/www/wwwroot/localClient/local_archives/alilib/";
|
|
|
+ for (ArchiveFile file : list) {
|
|
|
+ if (StringUtil.isNotBlank(file.getFileUrl())) {
|
|
|
+ String fileUrl = file.getFileUrl();
|
|
|
+ String fileName = fileUrl.substring(fileUrl.lastIndexOf('/') + 1);
|
|
|
+ InputStream file_out = CommonUtil.getOSSInputStream(fileUrl);
|
|
|
+ CommonUtil.inputStreamToFile(file_out,new File(localUrl+fileName));
|
|
|
+ file.setFileUrl(fileName);
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(file.getPdfFileUrl())){
|
|
|
+ String pdfFileUrl = file.getPdfFileUrl();
|
|
|
+ String fileName = pdfFileUrl.substring(pdfFileUrl.lastIndexOf('/') + 1);
|
|
|
+ InputStream file_out = CommonUtil.getOSSInputStream(pdfFileUrl);
|
|
|
+ CommonUtil.inputStreamToFile(file_out,new File(localUrl+fileName));
|
|
|
+ file.setPdfFileUrl(fileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Connection conn = data.dataSource().getConnection();
|
|
|
+ //清空原有数据
|
|
|
+ Statement statement = conn.createStatement();
|
|
|
+ statement.execute("DELETE FROM u_archive_file");
|
|
|
+ statement.close();
|
|
|
+ //导入最新数据
|
|
|
+ String sql = "INSERT INTO u_archive_file (id, project_id, node_id, file_number, file_name, file_time, file_url, pdf_file_url, status, is_deleted, archive_id,create_time)" +
|
|
|
+ " VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
|
|
|
+ PreparedStatement pstm = conn.prepareStatement(sql);
|
|
|
+ //pstm 绑定数据
|
|
|
+ int i=0;
|
|
|
+ for (ArchiveFile file : list) {
|
|
|
+ i++;
|
|
|
+ pstm.setLong(1,file.getId());
|
|
|
+ pstm.setLong(2, Long.parseLong(file.getProjectId()));
|
|
|
+ pstm.setString(3,file.getNodeId()==null?"":file.getNodeId());
|
|
|
+ pstm.setString(4,file.getFileNumber()==null?"":file.getFileNumber());
|
|
|
+ pstm.setString(5,file.getFileName());
|
|
|
+ pstm.setString(6,file.getFileTime());
|
|
|
+ pstm.setString(7,file.getFileUrl()==null?"":file.getFileUrl());
|
|
|
+ pstm.setString(8,file.getPdfFileUrl()==null?"":file.getPdfFileUrl());
|
|
|
+ pstm.setInt(9,file.getStatus());
|
|
|
+ pstm.setInt(10,file.getIsDeleted());
|
|
|
+ pstm.setLong(11,file.getArchiveId()==null?-1:file.getArchiveId());
|
|
|
+ pstm.setString(12,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(file.getCreateTime()));
|
|
|
+ //添加批处理
|
|
|
+ pstm.addBatch();
|
|
|
+ if (i % 1000 == 0) {
|
|
|
+ pstm.executeBatch();
|
|
|
+ pstm.clearBatch();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //将批处理余下的语句执行完毕
|
|
|
+ pstm.executeBatch();
|
|
|
+ //释放资源
|
|
|
+ pstm.close();
|
|
|
+ conn.close();
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void contractToSqlite(Long projectId){
|
|
|
+ List<ArchiveTreeContract> list = contractClient.getListByProjectId(projectId);
|
|
|
+ try {
|
|
|
+ Connection conn = data.dataSource().getConnection();
|
|
|
+ Statement statement = conn.createStatement();
|
|
|
+ statement.execute("DELETE FROM m_archive_tree_contract");
|
|
|
+ statement.close();
|
|
|
+ //获取执行对象
|
|
|
+ String sql = "INSERT INTO m_archive_tree_contract(id, project_id, parent_id, ancestors, node_name,status,is_deleted,create_time)" +
|
|
|
+ "VALUES(?, ?, ?, ?, ?,?,?,?)";
|
|
|
+ PreparedStatement pstm = conn.prepareStatement(sql);
|
|
|
+ //pstm 绑定数据
|
|
|
+ int i=0;
|
|
|
+ for (ArchiveTreeContract contract : list) {
|
|
|
+ i++;
|
|
|
+ pstm.setLong(1,contract.getId());
|
|
|
+ pstm.setLong(2,contract.getProjectId());
|
|
|
+ pstm.setLong(3,contract.getParentId());
|
|
|
+ pstm.setString(4,contract.getAncestors());
|
|
|
+ pstm.setString(5,contract.getNodeName());
|
|
|
+ pstm.setInt(6,contract.getStatus());
|
|
|
+ pstm.setInt(7,contract.getIsDeleted());
|
|
|
+ pstm.setString(8, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(contract.getCreateTime()));
|
|
|
+ //添加批处理
|
|
|
+ pstm.addBatch();
|
|
|
+ if (i % 1000 == 0) {
|
|
|
+ pstm.executeBatch();
|
|
|
+ pstm.clearBatch();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //将批处理余下的语句执行完毕
|
|
|
+ pstm.executeBatch();
|
|
|
+ //释放资源
|
|
|
+ pstm.close();
|
|
|
+ conn.close();
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void autoToSqlite(Long projectId){
|
|
|
List<ArchivesAutoDTO> list = autoMapper.getListByProjectId(projectId);
|
|
|
- String localUrl = "D:\\develop\\aliyun\\";
|
|
|
+ String localUrl = "/www/wwwroot/localClient/local_archives/alilib/";
|
|
|
//拼接档案里文件的pdf设置allPdf
|
|
|
for (ArchivesAutoDTO dto : list) {
|
|
|
List<ArchiveFile> files = fileClient.getArchiveFileByArchivesId(dto.getId()+"","");
|
|
@@ -61,7 +206,11 @@ public class ArchiveOfflineVersionInfoServiceImpl extends BaseServiceImpl<Archiv
|
|
|
}
|
|
|
try {
|
|
|
Connection conn = data.dataSource().getConnection();
|
|
|
- //获取执行对象
|
|
|
+ //清空数据
|
|
|
+ Statement statement = conn.createStatement();
|
|
|
+ statement.execute("DELETE FROM u_archives_auto");
|
|
|
+ statement.close();
|
|
|
+ //导入数据
|
|
|
String sql = "INSERT INTO u_archives_auto (id, project_id, name, file_number, unit,storage_time, is_archive,node_id, status, is_deleted,create_time,all_file_pdf)" +
|
|
|
"VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
|
|
|
PreparedStatement pstm = conn.prepareStatement(sql);
|
|
@@ -98,4 +247,5 @@ public class ArchiveOfflineVersionInfoServiceImpl extends BaseServiceImpl<Archiv
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|