|
@@ -9,6 +9,9 @@ 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;
|
|
|
+import org.springblade.manager.entity.WbsTreePrivate;
|
|
|
+import org.springblade.repair.util.ExcelInfoUtils;
|
|
|
import org.springblade.repair.util.FileUtils;
|
|
|
import org.springblade.resource.feign.NewIOSSClient;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
@@ -21,6 +24,7 @@ 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.nio.file.Files;
|
|
@@ -41,10 +45,9 @@ public class CheckAndRepairController {
|
|
|
*/
|
|
|
@RequestMapping("/checkAndRepairExcelHtml")
|
|
|
@ApiOperation("定时检测修复ExcelHtml")
|
|
|
- @Scheduled(cron = "0 15 16 * * ?")
|
|
|
+ @Scheduled(cron = "00 22 10 * * ?")
|
|
|
public void checkAndRepairExcelHtml() {
|
|
|
- StringBuilder result=new StringBuilder("");
|
|
|
- StringBuilder result1=new StringBuilder("");
|
|
|
+ StringBuilder result=new StringBuilder("清表损坏:");
|
|
|
String sql = "Select * from m_excel_tab where parent_id=0 and is_deleted=0";
|
|
|
List<ExcelTab> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(ExcelTab.class));
|
|
|
//String excelPath="E:\\excel\\";
|
|
@@ -57,27 +60,37 @@ public class CheckAndRepairController {
|
|
|
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) {
|
|
|
+ if(excelTab1.getId()==1800344270830305280L){
|
|
|
+ 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.getResourceLength(excelTab1.getFileUrl());
|
|
|
- if(resourceLength>=500){
|
|
|
+ long resourceLength = CommonUtil.getFileContentLength(excelTab1.getFileUrl());
|
|
|
+ System.out.println("文件大小:"+resourceLength);
|
|
|
+ if(resourceLength!=415L&&resourceLength!=0L&&resourceLength!=234L){
|
|
|
//先下载这个文件,再上传
|
|
|
String fileUrl = excelTab1.getFileUrl();
|
|
|
String localPath=excelPath+excelTab1.getId()+".xlsx";
|
|
|
- InputStream inputStreamByUrl = FileUtils.getInputStreamByUrl(fileUrl);
|
|
|
- FileUtils.saveFile(inputStreamByUrl,localPath);
|
|
|
- File htmlFile = new File(localPath);
|
|
|
- if(htmlFile.exists()){
|
|
|
- try {
|
|
|
- MultipartFile file = convert(htmlFile, excelTab1);
|
|
|
- this.putFileAttach(file, excelTab1.getId());
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
+ System.out.println("开始下载:"+fileUrl);
|
|
|
+ try {
|
|
|
+ InputStream inputStreamByUrl = FileUtils.getInputStreamByUrl(fileUrl);
|
|
|
+ if(inputStreamByUrl!=null){
|
|
|
+ FileUtils.saveFile(inputStreamByUrl,localPath);
|
|
|
+ File htmlFile = new File(localPath);
|
|
|
+ if(htmlFile.exists()){
|
|
|
+ this.putFileAttach(new FileInputStream(htmlFile), excelTab1.getId(),excelTab1.getExtension());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ System.out.println("下载失败:"+fileUrl);
|
|
|
+ if(resourceLength<500){
|
|
|
+ deletedExcel(excelTab1.getId());
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
|
+ deletedExcel(excelTab1.getId());
|
|
|
result.append(excelTab.getName() + "--" + tab.getName() + "--" + excelTab1.getName()+"\n");
|
|
|
}
|
|
|
}
|
|
@@ -86,49 +99,82 @@ public class CheckAndRepairController {
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
System.out.println("完成");
|
|
|
System.out.println(result);
|
|
|
- System.out.println(result1);
|
|
|
}
|
|
|
|
|
|
- public static MultipartFile convert(File file,ExcelTab e) throws IOException {
|
|
|
- String contentType = Files.probeContentType(file.toPath());
|
|
|
- byte[] content = Files.readAllBytes(file.toPath());
|
|
|
- return new MockMultipartFile(
|
|
|
- "file",
|
|
|
- e.getName(),
|
|
|
- contentType,
|
|
|
- content
|
|
|
- );
|
|
|
+ public void deletedExcel(Long id){
|
|
|
+ String sql="update m_excel_tab set is_deleted=3 where id="+id;
|
|
|
+ jdbcTemplate.execute(sql);
|
|
|
+ System.out.println("删除成功:"+id);
|
|
|
}
|
|
|
- public R putFileAttach(@RequestParam("file") MultipartFile file, Long nodeId) throws Exception {
|
|
|
+
|
|
|
+ public void putFileAttach(InputStream inputStream, Long nodeId,String name) throws Exception {
|
|
|
+ System.out.println("开始上传");
|
|
|
String file_path = FileUtils.getSysLocalFileUrl();
|
|
|
String sql="Select * from m_excel_tab where id="+nodeId+" and is_deleted=0";
|
|
|
ExcelTab detail = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(ExcelTab.class));
|
|
|
String filecode = SnowFlakeUtil.getId() + "";
|
|
|
String thmlUrl = file_path + filecode + ".html";
|
|
|
String exceUrl = file_path + filecode + "123.xlsx";
|
|
|
- excelTabClient.excelInfo(file.getInputStream(), exceUrl, thmlUrl, "1");
|
|
|
+ ExcelInfoUtils.excelInfo(inputStream, exceUrl, thmlUrl, "1");
|
|
|
// 上传excel文件
|
|
|
- BladeFile bladeFile = newIOSSClient.uploadFile(file.getOriginalFilename(), exceUrl);
|
|
|
- if (bladeFile == null || ObjectUtil.isEmpty(bladeFile)) {
|
|
|
- return R.fail("oss上传失败,请校验oss配置是否正确");
|
|
|
- }
|
|
|
+ BladeFile bladeFile = newIOSSClient.uploadFile(name, exceUrl);
|
|
|
// 解析原始excel
|
|
|
- detail.setExtension(file.getOriginalFilename());
|
|
|
+ detail.setExtension(name);
|
|
|
detail.setFileUrl(bladeFile.getLink());
|
|
|
detail.setFileType(3); // 表示为清表信息 1 表示祖节点 2 表示为节点信息 3 表示清表
|
|
|
detail.setHtmlUrl(thmlUrl);
|
|
|
- excelTabClient.saveOrUpdate(detail);
|
|
|
+ String update="update m_excel_tab set file_url ="+"'"+bladeFile.getLink()+"' , html_url="+"'"+thmlUrl+"' where id="+nodeId;
|
|
|
+ System.out.println(update);
|
|
|
+ int i = jdbcTemplate.update(update);
|
|
|
// 解析html
|
|
|
excelTabClient.expailHtmlInfo(thmlUrl, detail.getId(), detail.getTabType() + "");
|
|
|
- return R.success("上传成功");
|
|
|
+ if(i==1){
|
|
|
+ System.out.println("上传成功");
|
|
|
+ }else {
|
|
|
+ System.out.println("上传失败");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 每周天晚上2点定时更新private和contract的html,通过is_private_type_id;
|
|
|
+ * 定时更新private的htmUrl 保证url格式为 /mnt/sdc/Users/hongchuangyanfa/Desktop/privateUrlCopy/
|
|
|
*/
|
|
|
- public void checkAndRepairPrivateAndContractHtml() {}
|
|
|
+ private void checkAndRepairPrivateAndContractPrivateCopyUrl() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 定时更新private和contract的html,通过is_private_type_id;保证一样
|
|
|
+ */
|
|
|
+ @Scheduled(cron = "0 0 1 * * ?")
|
|
|
+ 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";
|
|
|
+ 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();
|
|
|
+ int i = jdbcTemplate.update(update);
|
|
|
+ if(i!=1){
|
|
|
+ result.append(wbsTreeContract.getPKeyId()+"\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println("更新完毕private和contract的html");
|
|
|
+ System.out.println(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 定时更新private和contract的initTable 通过excelID,保证一样
|
|
|
+ */
|
|
|
+ public void checkAndRepairPrivateAndContractInitTable() {}
|
|
|
+
|
|
|
+
|
|
|
}
|