Selaa lähdekoodia

脱机工具,取消固定项目

qianxb 2 vuotta sitten
vanhempi
commit
fad5505e8f

+ 2 - 2
blade-service/blade-archive/src/main/java/org/springblade/archive/controller/ArchiveOfflineVersionInfoController.java

@@ -38,7 +38,7 @@ public class ArchiveOfflineVersionInfoController {
     @GetMapping("/packData")
     public R<String> packData(Long projectId) throws Exception {
         //异步调用自动打包上传,完成后修改数据库信息
-        offlineVersionInfoService.packData(1578599210897772545L);
+        offlineVersionInfoService.packData(projectId);
         return R.data("最新数据后台自动打包中,打包完成后会更新打包日期");
     }
     /**
@@ -47,7 +47,7 @@ public class ArchiveOfflineVersionInfoController {
     @ApiOperation(value = "脱机载体工具")
     @GetMapping("/getVersionInfo")
     public R<ArchiveOfflineVersionInfo> getVersionInfo(Long projectId){
-        ArchiveOfflineVersionInfo versionInfo = mapper.selectVersionInfo(1578599210897772545L);
+        ArchiveOfflineVersionInfo versionInfo = mapper.selectVersionInfo(projectId);
         String size = this.formatSize(Long.parseLong(versionInfo.getFileSize()));
         versionInfo.setFileSize(size);
         return R.data(versionInfo);

+ 147 - 141
blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchiveOfflineVersionInfoServiceImpl.java

@@ -81,168 +81,174 @@ public class ArchiveOfflineVersionInfoServiceImpl extends BaseServiceImpl<Archiv
     }
     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;
+        if (list != null && list.size() > 0) {
+            String localUrl = "/www/wwwroot/localClient/local_archives/alilib/";
             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();
+                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();
             }
-            //将批处理余下的语句执行完毕
-            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();
+        if (list != null && list.size() > 0) {
+            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();
             }
-            //将批处理余下的语句执行完毕
-            pstm.executeBatch();
-            //释放资源
-            pstm.close();
-            conn.close();
-        }catch (Exception e){
-            e.printStackTrace();
         }
     }
 
     public void autoToSqlite(Long projectId){
         List<ArchivesAutoDTO> list = autoMapper.getListByProjectId(projectId);
-        String localUrl = "/www/wwwroot/localClient/local_archives/alilib/";
-        //拼接档案里文件的pdf设置allPdf
-        for (ArchivesAutoDTO dto : list) {
-            List<ArchiveFile> files = fileClient.getArchiveFileByArchivesId(dto.getId()+"","");
-            if (files != null && files.size() >0){
-                List<String> urlList = new ArrayList<>();
-                for (ArchiveFile file : files) {
-                    if (StringUtil.isNotBlank(file.getPdfFileUrl())){
-                        urlList.add(file.getPdfFileUrl());
+        if (list != null && list.size() > 0) {
+            String localUrl = "/www/wwwroot/localClient/local_archives/alilib/";
+            //拼接档案里文件的pdf设置allPdf
+            for (ArchivesAutoDTO dto : list) {
+                List<ArchiveFile> files = fileClient.getArchiveFileByArchivesId(dto.getId() + "", "");
+                if (files != null && files.size() > 0) {
+                    List<String> urlList = new ArrayList<>();
+                    for (ArchiveFile file : files) {
+                        if (StringUtil.isNotBlank(file.getPdfFileUrl())) {
+                            urlList.add(file.getPdfFileUrl());
+                        }
+                    }
+                    if (urlList.size() > 0) {
+                        Long id = SnowFlakeUtil.getId();
+                        FileUtils.mergePdfPublicMethods(urlList, localUrl + id + ".pdf");
+                        dto.setAllFilePdf(id + ".pdf");
                     }
                 }
-                if (urlList.size() > 0){
-                    Long id = SnowFlakeUtil.getId();
-                    FileUtils.mergePdfPublicMethods(urlList,localUrl+id+".pdf");
-                    dto.setAllFilePdf(id+".pdf");
-                }
-            }
 
-        }
-        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);
-            //pstm 绑定数据
-            int i=0;
-            for (ArchivesAutoDTO auto : list) {
-                i++;
-                pstm.setLong(1,auto.getId());
-                pstm.setLong(2,auto.getProjectId());
-                pstm.setString(3,auto.getName());
-                pstm.setString(4,auto.getFileNumber());
-                pstm.setString(5,auto.getUnit());
-                pstm.setString(6,auto.getStorageTime());
-                pstm.setInt(7,auto.getIsArchive()==null?0:1);
-                pstm.setLong(8,auto.getNodeId());
-                pstm.setInt(9,auto.getStatus());
-                pstm.setInt(10,auto.getIsDeleted());
-                pstm.setString(11,  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(auto.getCreateTime()));
-                pstm.setString(12,auto.getAllFilePdf()==null?"":auto.getAllFilePdf());
+            }
+            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);
+                //pstm 绑定数据
+                int i = 0;
+                for (ArchivesAutoDTO auto : list) {
+                    i++;
+                    pstm.setLong(1, auto.getId());
+                    pstm.setLong(2, auto.getProjectId());
+                    pstm.setString(3, auto.getName());
+                    pstm.setString(4, auto.getFileNumber());
+                    pstm.setString(5, auto.getUnit());
+                    pstm.setString(6, auto.getStorageTime());
+                    pstm.setInt(7, auto.getIsArchive() == null ? 0 : 1);
+                    pstm.setLong(8, auto.getNodeId());
+                    pstm.setInt(9, auto.getStatus());
+                    pstm.setInt(10, auto.getIsDeleted());
+                    pstm.setString(11, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(auto.getCreateTime()));
+                    pstm.setString(12, auto.getAllFilePdf() == null ? "" : auto.getAllFilePdf());
 
-                //添加批处理
-                pstm.addBatch();
-                if (i % 1000 == 0) {
-                    pstm.executeBatch();
-                    pstm.clearBatch();
+                    //添加批处理
+                    pstm.addBatch();
+                    if (i % 1000 == 0) {
+                        pstm.executeBatch();
+                        pstm.clearBatch();
+                    }
                 }
+                //将批处理余下的语句执行完毕
+                pstm.executeBatch();
+                //释放资源
+                pstm.close();
+                conn.close();
+            } catch (Exception e) {
+                e.printStackTrace();
             }
-            //将批处理余下的语句执行完毕
-            pstm.executeBatch();
-            //释放资源
-            pstm.close();
-            conn.close();
-        }catch (Exception e){
-            e.printStackTrace();
         }
     }