ソースを参照

定时检查private的html是否存在

chenr 2 ヶ月 前
コミット
64acae5730

+ 3 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/feign/ExcelTabClient.java

@@ -84,4 +84,7 @@ public interface ExcelTabClient {
 
     @PostMapping(API_PREFIX + "/excelInfo")
     void excelInfo(@RequestPart("file") MultipartFile file, @RequestParam String exceUrl, @RequestParam String thmlUrl, @RequestParam String number) throws IOException;
+
+    @PostMapping(API_PREFIX + "/saveLinkTab")
+    void saveLinkTab(@RequestParam Long excelId,@RequestParam Long pKeyId) throws IOException;
 }

+ 4 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/feign/ExcelTabClientFallBack.java

@@ -91,6 +91,10 @@ public class ExcelTabClientFallBack implements ExcelTabClient {
 
     }
 
+    @Override
+    public void saveLinkTab(Long excelId, Long pKeyId) throws IOException {
+
+    }
 
 
 }

+ 19 - 3
blade-service/blade-manager/src/main/java/org/springblade/manager/feign/ExcelTabClientImpl.java

@@ -142,10 +142,20 @@ public class ExcelTabClientImpl implements ExcelTabClient {
                             BladeFile bladeFile = newIOSSClient.uploadFile(id + "2.pdf", pdfPath);
                             if (bladeFile != null) {
                                 List<InformationQuery> query2 = jdbcTemplate.query("select id from u_information_query where classify ='" + type + "' and wbs_id ='" + id + "' and contract_id ='" + contractId + "'", new BeanPropertyRowMapper<>(InformationQuery.class));
+                                StringBuilder names=new StringBuilder("");
+                                if(StringUtils.isNotEmpty(dto.getReportNo())){
+                                    names.append("[");
+                                    names.append(dto.getReportNo());
+                                    names.append("]");
+                                }
+                                if(StringUtils.isNotEmpty(dto.getTrialProjectName())){
+                                    names.append(dto.getTrialProjectName());
+                                }
+                                names.append("试验检测报告及附件");
                                 if (query2.size() > 0) {
-                                    jdbcTemplate.execute("update u_information_query set pdf_url ='" + bladeFile.getLink() + "', name ='" + (StringUtils.isNotEmpty(dto.getTrialProjectName()) ? dto.getTrialProjectName() : "") + "'  where classify='" + type + "' and  wbs_id='" + id + "' and contract_id ='" + contractId + "'");
+                                    jdbcTemplate.execute("update u_information_query set pdf_url ='" + bladeFile.getLink() + "', name ='" + names + "'  where classify='" + type + "' and  wbs_id='" + id + "' and contract_id ='" + contractId + "'");
                                 } else {
-                                    informationQueryClient.saveData(id.toString(), projectId, contractId, type.toString(), bladeFile.getLink(), (StringUtils.isNotEmpty(dto.getTrialProjectName()) ? dto.getTrialProjectName() : ""));
+                                    informationQueryClient.saveData(id.toString(), projectId, contractId, type.toString(), bladeFile.getLink(), names.toString());
                                 }
                             }
                         }
@@ -205,6 +215,7 @@ public class ExcelTabClientImpl implements ExcelTabClient {
         String groupId = table.getString("groupId");
         String contractId = table.getString("contractId");
         String pkeyId = table.getString("pkeyId");
+        String entrustInfoName = table.getString("entrustInfoName");
         JSONArray dataArray = new JSONArray();
         dataArray.add(table);
 
@@ -220,7 +231,7 @@ public class ExcelTabClientImpl implements ExcelTabClient {
             //------试验填报数据保存,当前记录id作为groupId------
             this.excelTabService.saveOrUpdateInfoTrial(tableInfoList, Func.toLong(groupId));
 
-            pdfUrl = this.excelTabService.getEntrustPDFTrial(Func.toLong(pkeyId), contractId, Func.toLong(groupId));
+            pdfUrl = this.excelTabService.getEntrustPDFTrial(Func.toLong(pkeyId), contractId, Func.toLong(groupId),entrustInfoName);
 
         } catch (Exception e) {
             e.printStackTrace();
@@ -495,6 +506,11 @@ public class ExcelTabClientImpl implements ExcelTabClient {
         ExcelInfoUtils.excelInfo(file.getInputStream(), exceUrl, thmlUrl, number);
     }
 
+    @Override
+    public void saveLinkTab(Long excelId, Long pKeyId) throws IOException {
+        excelTabController.saveLinkeTab(excelId,pKeyId);
+    }
+
 
     private String getHtmlString(String pkeyId) throws Exception {
         WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.selectOne(Wrappers.<WbsTreePrivate>query().lambda()

+ 162 - 61
blade-service/blade-repair/src/main/java/org/springblade/repair/controller/CheckAndRepairController.java

@@ -1,12 +1,14 @@
 package org.springblade.repair.controller;
 
+import cn.hutool.system.SystemUtil;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
+import org.apache.commons.lang.SystemUtils;
 import org.springblade.common.utils.CommonUtil;
 import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.oss.model.BladeFile;
-import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.ObjectUtil;
 import org.springblade.manager.entity.ExcelTab;
 import org.springblade.manager.entity.WbsTreeContract;
@@ -16,26 +18,25 @@ import org.springblade.repair.util.FileUtils;
 import org.springblade.resource.feign.NewIOSSClient;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.SingleColumnRowMapper;
-import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springblade.manager.feign.ExcelTabClient;
-import org.springframework.web.multipart.MultipartFile;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+
+import java.io.*;
 import java.nio.file.Files;
-import java.time.chrono.JapaneseDate;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 
+
+
 @RestController
 @AllArgsConstructor
 @RequestMapping("/checkAndRepair")
@@ -46,34 +47,29 @@ public class CheckAndRepairController {
     private final NewIOSSClient newIOSSClient;
 
     /**
-     * 每天晚上1点检查excelHtml是否存在,如果不存在就下载excel表格然后重新上传
+     * 检查清表的excelHtml是否存在,如果不存在就下载excel表格然后重新上传
      */
     @RequestMapping("/checkAndRepairExcelHtml")
     @ApiOperation("定时检测修复ExcelHtml")
     @Scheduled(cron = "00 00 00 * * ?")
     public void checkAndRepairExcelHtml() {
-        StringBuilder result=new StringBuilder("清表损坏:");
-        String sql = "Select * from m_excel_tab where parent_id=0 and is_deleted=0";
+        StringBuilder result=new StringBuilder("");
+        String sql = "Select * from m_excel_tab where  is_deleted=0 and file_url is  not null";
         List<ExcelTab> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(ExcelTab.class));
         //String excelPath="E:\\excel\\";
         String excelPath="/mnt/sdc/Users/hongchuangyanfa/Desktop/excel/";
         try {
-            for (ExcelTab excelTab : query) {
-                String sql1 = "Select * from m_excel_tab where parent_id=" + excelTab.getId() + " and is_deleted=0";
-                List<ExcelTab> query1 = jdbcTemplate.query(sql1, new BeanPropertyRowMapper<>(ExcelTab.class));
-                for (ExcelTab tab : query1) {
-                    String sql2 = "Select * from m_excel_tab where parent_id=" + tab.getId() + " and is_deleted=0 and file_url is not null ";
-                    List<ExcelTab> query2 = jdbcTemplate.query(sql2, new BeanPropertyRowMapper<>(ExcelTab.class));
-                    for (ExcelTab excelTab1 : query2) {
+                    for (ExcelTab excelTab1 : query) {
                         if(excelTab1.getId()==1800344270830305280L){
                             continue;
                         }
+                        if(StringUtils.isBlank(excelTab1.getHtmlUrl())||StringUtils.isBlank(excelTab1.getFileUrl())){
+                            continue;
+                        }
                         File html = new File(excelTab1.getHtmlUrl());
                         if(!html.exists()){
-                            System.out.println(excelTab.getName() + "--" + tab.getName() + "--" + excelTab1.getName()+"html不存在 id:"+excelTab1.getId());
                             if(excelTab1.getFileUrl() != null&&(excelTab1.getFileUrl().endsWith(".xlsx") || excelTab1.getFileUrl().endsWith(".xls"))){
                                 long resourceLength = CommonUtil.getFileContentLength(excelTab1.getFileUrl());
-                                System.out.println("文件大小:"+resourceLength);
                                 if(resourceLength!=415L&&resourceLength!=0L&&resourceLength!=234L){
                                     //先下载这个文件,再上传
                                     String fileUrl = excelTab1.getFileUrl();
@@ -86,6 +82,7 @@ public class CheckAndRepairController {
                                             File htmlFile = new File(localPath);
                                             if(htmlFile.exists()){
                                                 this.putFileAttach(new FileInputStream(htmlFile), excelTab1.getId(),excelTab1.getExtension());
+                                                result.append("上传成功:"+excelTab1.getId()+excelTab1.getName()+"\n");
                                             }
                                         }
                                     }catch (Exception e){
@@ -96,13 +93,10 @@ public class CheckAndRepairController {
                                     }
                                 }else {
                                     deletedExcel(excelTab1.getId());
-                                    result.append(excelTab.getName() + "--" + tab.getName() + "--" + excelTab1.getName()+"\n");
                                 }
                             }
                         }
                     }
-                }
-            }
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -142,19 +136,18 @@ public class CheckAndRepairController {
         }else {
             System.out.println("上传失败");
         }
-
     }
 
 
     /**
      * 定时更新private和contract的html,通过is_private_type_id;保证一样
      */
-    @Scheduled(cron = "0 0  1 * * ?")
+    @Scheduled(cron = "0 0  3 * * ?")
     public void checkAndRepairPrivateAndContractHtml() {
         System.out.println("开始扫描private和contract的html");
         StringBuilder result=new StringBuilder("");
         try {
-            String sql="SELECT a.p_key_id,a.is_type_private_pid FROM m_wbs_tree_contract a,m_wbs_tree_private b WHERE a.html_url != b.html_url AND a.is_type_private_pid=b.p_key_id AND a.type=2 AND a.is_deleted=0 AND b.type=2 AND b.html_url is not NULL";
+            String sql="SELECT a.p_key_id,a.is_type_private_pid FROM m_wbs_tree_contract a,m_wbs_tree_private b WHERE a.html_url != b.html_url AND a.is_type_private_pid=b.p_key_id AND a.type=2 AND a.is_deleted=0 AND b.type=2 AND b.html_url is not NULL AND a.project_id=b.project_id";
             List<WbsTreeContract> contractListlist = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(WbsTreeContract.class));
             for (WbsTreeContract wbsTreeContract : contractListlist) {
                 String update=" update m_wbs_tree_contract set html_url=(select html_url from m_wbs_tree_private where p_key_id="+wbsTreeContract.getIsTypePrivatePid()+") where p_key_id="+wbsTreeContract.getPKeyId();
@@ -171,10 +164,10 @@ public class CheckAndRepairController {
     }
 
     /**
-     * 定时更新private initTable 通过excelID,保证一样
+     * 定时更新private initTable或者excelID,保证一样
      */
     @GetMapping("/checkAndRepairPrivateInitTableAndExcelId")
-    @Scheduled(cron = "0 57  16 * * ?")
+    @Scheduled(cron = "0 30  1 * * ?")
     public void checkAndRepairPrivateInitTableAndExcelId() {
         System.out.println("开始扫描private initTable和ExcelId");
         String privateSql="select p_key_id,init_table_name,excel_id,html_url from m_wbs_tree_private where type=2 AND is_deleted=0 AND (excel_id IS NULL OR init_table_name IS NULL OR html_url IS NULL)";
@@ -203,39 +196,29 @@ public class CheckAndRepairController {
             .collect(Collectors.toList());
         if(!list1.isEmpty()){
             for (WbsTreePrivate w : list1) {
-                String sql="select a.tab_en_name,b.html_url from m_table_info a left join m_excel_tab b on a.id=b.tab_id where b.id="+w.getExcelId()+" and a.is_deleted=0 and b.is_deleted=0";
+                String sql="select a.tab_en_name from m_table_info a left join m_excel_tab b on a.id=b.tab_id where b.id="+w.getExcelId()+" and a.is_deleted=0 and b.is_deleted=0";
                 Map<String, Object> map = jdbcTemplate.queryForMap(sql);
                 if(map.get("tab_en_name")!=null){
                     String update="update m_wbs_tree_private set init_table_name="+map.get("tab_en_name")+" where p_key_id="+w.getPKeyId();
                     jdbcTemplate.update(update);
                 }
-                if(w.getHtmlUrl()==null){
-                    String update="update m_wbs_tree_private set html_url="+map.get("html_url")+" where p_key_id="+w.getPKeyId();
-                    jdbcTemplate.update(update);
-                }
             }
         }
         if(!list2.isEmpty()){
             for (WbsTreePrivate w : list2) {
-                String sql=" select a.id,a.html_url from m_excel_tab a left join m_table_info b on b.id=a.tab_id where b.tab_en_name= '"+w.getInitTableName()+"' and a.is_deleted=0 and b.is_deleted=0";
+                String sql=" select a.id from m_excel_tab a left join m_table_info b on b.id=a.tab_id where b.tab_en_name= '"+w.getInitTableName()+"' and a.is_deleted=0 and b.is_deleted=0";
                 Map<String, Object> map = jdbcTemplate.queryForMap(sql);
                 if(map.get("id")!=null){
                     String update="update m_wbs_tree_private set excel_id="+map.get("id")+" where p_key_id="+w.getPKeyId();
                     jdbcTemplate.update(update);
                 }
-                if(w.getHtmlUrl()==null){
-                    if(map.get("html_url")!=null){
-                        String update="update m_wbs_tree_private set html_url='"+map.get("html_url")+"' where p_key_id ="+w.getPKeyId();
-                        jdbcTemplate.update(update);
-                    }
-                }
             }
         }
         System.out.println("更新完毕private initTable和ExcelId");
     }
 
     /**
-     * 定时更新contract initTable 通过excelID,保证一样
+     * 定时更新contract initTable或者excelID,保证一样
      */
     @GetMapping("/checkAndRepairContractInitTableAndExcelId")
     @Scheduled(cron = "0  00  2 * * ?")
@@ -267,36 +250,154 @@ public class CheckAndRepairController {
             .collect(Collectors.toList());
         if(!list1.isEmpty()){
             for (WbsTreeContract w : list1) {
-                String sql="select a.tab_en_name,b.html_url from m_table_info a left join m_excel_tab b on a.id=b.tab_id where b.id="+w.getExcelId()+" and a.is_deleted=0 and b.is_deleted=0";
-                Map<String, Object> map = jdbcTemplate.queryForMap(sql);
-                if(map.get("tab_en_name")!=null){
-                    String update="update m_wbs_tree_contract set init_table_name="+map.get("tab_en_name")+" where p_key_id="+w.getPKeyId();
-                    jdbcTemplate.update(update);
-                }
-                if(w.getHtmlUrl()==null){
-                    String update="update m_wbs_tree_contract set html_url="+map.get("html_url")+" where p_key_id="+w.getPKeyId();
-                    jdbcTemplate.update(update);
+                String sql="select a.tab_en_name from m_table_info a left join m_excel_tab b on a.id=b.tab_id where b.id="+w.getExcelId()+" and a.is_deleted=0 and b.is_deleted=0";
+                List<Map<String, Object>> result = jdbcTemplate.queryForList(sql);
+                if (!result.isEmpty()) {
+                    Map<String, Object> map = result.get(0);
+                    if(map.get("tab_en_name")!=null){
+                        String update="update m_wbs_tree_contract set init_table_name="+map.get("tab_en_name")+" where p_key_id="+w.getPKeyId();
+                        jdbcTemplate.update(update);
+                    }
+                    // 继续处理
+                } else {
+                    System.out.println("contract p_key_id"+w.getPKeyId()+" excelId:"+w.getExcelId());
                 }
+
             }
         }
         if(!list2.isEmpty()){
             for (WbsTreeContract w : list2) {
-                String sql=" select a.id,a.html_url from m_excel_tab a left join m_table_info b on b.id=a.tab_id where b.tab_en_name= '"+w.getInitTableName()+"' and a.is_deleted=0 and b.is_deleted=0";
-                Map<String, Object> map = jdbcTemplate.queryForMap(sql);
-                if(map.get("id")!=null){
-                    String update="update m_wbs_tree_contract set excel_id="+map.get("id")+" where p_key_id="+w.getPKeyId();
-                    jdbcTemplate.update(update);
-                }
-                if(w.getHtmlUrl()==null){
-                    if(map.get("html_url")!=null){
-                        String update="update m_wbs_tree_contract set html_url='"+map.get("html_url")+"' where p_key_id ="+w.getPKeyId();
+                String sql=" select a.id from m_excel_tab a left join m_table_info b on b.id=a.tab_id where b.tab_en_name= '"+w.getInitTableName()+"' and a.is_deleted=0 and b.is_deleted=0";
+                List<Map<String, Object>> result = jdbcTemplate.queryForList(sql);
+                if (!result.isEmpty()){
+                    Map<String, Object> map = result.get(0);
+                    if(map.get("id")!=null){
+                        String update="update m_wbs_tree_contract set excel_id="+map.get("id")+" where p_key_id="+w.getPKeyId();
                         jdbcTemplate.update(update);
                     }
+                }else {
+                    System.out.println("contract p_key_id"+w.getPKeyId()+" initTableName:"+w.getInitTableName());
                 }
             }
         }
         System.out.println("更新完毕contract initTable和ExcelId");
     }
 
+    /**
+     * 定时检测excel文件后缀名
+     */
+    @GetMapping("/checkExcelExtension")
+    @Scheduled(cron = "0 00  12 * * ?")
+    public void checkExcelExtension(){
+        String sql="select id,name,extension from m_excel_tab where is_deleted=0";
+        List<ExcelTab> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(ExcelTab.class));
+        for (ExcelTab tab : list) {
+            if(StringUtils.isNotEmpty(tab.getExtension())){
+                String extension = tab.getExtension();
+                String[] extensions = extension.split("\\.");
+                if(extensions.length>=2){
+                    String extension1 = extensions[1];
+                    if(extension1.equals("xlsx")||extension1.equals("xls")){
+                        if((extensions[0] != null && extensions[0].matches("\\d+"))){
+                            extension=tab.getName()+"."+extension1;
+                            String update="update m_excel_tab set extension='"+extension+"' where id="+tab.getId();
+                            jdbcTemplate.update(update);
+                        }
+                    }
+                }
+            }
+        }
+        System.out.println("更新完毕excel文件后缀名");
+    }
+
+    /**
+     * 定时检测private html是否包含privateUrlCopy 但是不包括独立表单
+     */
+    @GetMapping("/checkPrivateHtmlIsCopy")
+    @Scheduled(cron = "0 30 23 * * ?")
+    public void checkPrivateHtmlIsCopy(){
+        String sql="select p_key_id,project_id,html_url from m_wbs_tree_private where is_deleted=0 and html_url  NOT LIKE '%privateUrlCopy%' AND type=2";
+        List<WbsTreePrivate> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(WbsTreePrivate.class));
+        for (WbsTreePrivate wbsTreePrivate : list) {
+            if(StringUtils.isNotEmpty(wbsTreePrivate.getHtmlUrl())){
+                String url=wbsTreePrivate.getHtmlUrl();
+                File html = new File(wbsTreePrivate.getHtmlUrl());
+                if(html.exists()){
+                    String project = "/mnt/sdc/Users/hongchuangyanfa/Desktop/privateUrlCopy/"+wbsTreePrivate.getProjectId()+"/";
+                    File projectFile = new File(project);
+                    if(!projectFile.exists()){
+                        projectFile.mkdir();
+                    }
+                    int lastIndex = url.lastIndexOf("/");
+                    if (lastIndex != -1) {
+                        String result = project+url.substring(lastIndex + 1);
+                        File  file = new File(result);
+                        if(!file.exists()){
+                            try (InputStream in = new FileInputStream(url);
+                                 OutputStream out = new FileOutputStream(result)) {
+                                byte[] buffer = new byte[1024];
+                                int length;
+                                while ((length = in.read(buffer)) > 0) {
+                                    out.write(buffer, 0, length);
+                                }
+                                System.out.println("文件复制成功!");
+                                String update="update m_wbs_tree_private set html_url='"+result+"' where p_key_id="+wbsTreePrivate.getPKeyId();
+                                System.out.println(update);
+                                jdbcTemplate.update(update);
+                            } catch (IOException e) {
+                                System.err.println("复制文件时发生错误:" + e.getMessage()+wbsTreePrivate.getPKeyId()+": "+wbsTreePrivate.getHtmlUrl());
+                            }
+                        }
+
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * 检查private html文件是否存在
+     */
+    @GetMapping("/checkPrivateHtmlIsExist")
+    @Scheduled(cron = "0  30  1 * * ?")
+    public void checkPrivateHtmlIsExist() throws Exception {
+        String sql="select p_key_id, excel_id,html_url from m_wbs_tree_private where html_url IS NOT NULL  and is_deleted=0";
+        List<WbsTreePrivate> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(WbsTreePrivate.class));
+        int i=0;
+        int n=list.size();
+        for (WbsTreePrivate wbsTreePrivate : list) {
+            String htmlUrl = wbsTreePrivate.getHtmlUrl();
+            File  html = new File(htmlUrl);
+            boolean flag=true;
+            //判断文件是否存在
+            if(!html.exists()){
+                Path sourcePath = Paths.get(htmlUrl);
+                String sql1="select * from m_wbs_tree_private where excel_id="+wbsTreePrivate.getExcelId()+" and is_deleted=0";
+                List<WbsTreePrivate> list1 = jdbcTemplate.query(sql1, new BeanPropertyRowMapper<>(WbsTreePrivate.class));
+                Set<String> htmlSets = list1.stream().map(WbsTreePrivate::getHtmlUrl).collect(Collectors.toSet());
+                //通过excel_id  找寻其他项目级下路径,判断是否存在,如果存在则拿去覆盖
+                for (String htmlUrlSet : htmlSets) {
+                    File htmlSet = new File(htmlUrlSet);
+                    if(htmlSet.exists()){
+                        Path targetPath = Paths.get(htmlUrlSet);
+                        Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
+                        System.out.println("文件复制成功!"+wbsTreePrivate.getPKeyId());
+                        flag=false;
+                        break;
+                    }
+                }
+                //不存在则通过excel_id和p_key_id 调用关联表单的接口
+                if(flag){
+                    excelTabClient.saveLinkTab(wbsTreePrivate.getExcelId(),wbsTreePrivate.getPKeyId());
+                    System.out.println("关联成功!"+wbsTreePrivate.getPKeyId());
+                }
+
+                i++;
+            }
+            n--;
+            System.out.println("已检查了"+n+"条记录");
+        }
+        System.out.println("检查完毕,更新了"+i+"条记录");
+    }
 
 }