|
@@ -0,0 +1,134 @@
|
|
|
|
+package org.springblade.repair.controller;
|
|
|
|
+
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
|
+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.repair.util.FileUtils;
|
|
|
|
+import org.springblade.resource.feign.NewIOSSClient;
|
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
+import org.springframework.mock.web.MockMultipartFile;
|
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
+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.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@RestController
|
|
|
|
+@AllArgsConstructor
|
|
|
|
+@RequestMapping("/checkAndRepair")
|
|
|
|
+@Api(value = "checkAndRepair", tags = "定时自动检测修复")
|
|
|
|
+public class CheckAndRepairController {
|
|
|
|
+ private final JdbcTemplate jdbcTemplate;
|
|
|
|
+ private final ExcelTabClient excelTabClient;
|
|
|
|
+ private final NewIOSSClient newIOSSClient;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 每天晚上1点检查excelHtml是否存在,如果不存在就下载excel表格然后重新上传
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping("/checkAndRepairExcelHtml")
|
|
|
|
+ @ApiOperation("定时检测修复ExcelHtml")
|
|
|
|
+ @Scheduled(cron = "0 15 16 * * ?")
|
|
|
|
+ public void checkAndRepairExcelHtml() {
|
|
|
|
+ StringBuilder result=new StringBuilder("");
|
|
|
|
+ StringBuilder result1=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\\";
|
|
|
|
+ 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) {
|
|
|
|
+ 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){
|
|
|
|
+ //先下载这个文件,再上传
|
|
|
|
+ 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();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ result.append(excelTab.getName() + "--" + tab.getName() + "--" + excelTab1.getName()+"\n");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }
|
|
|
|
+ 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 R putFileAttach(@RequestParam("file") MultipartFile file, Long nodeId) throws Exception {
|
|
|
|
+ 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");
|
|
|
|
+ // 上传excel文件
|
|
|
|
+ BladeFile bladeFile = newIOSSClient.uploadFile(file.getOriginalFilename(), exceUrl);
|
|
|
|
+ if (bladeFile == null || ObjectUtil.isEmpty(bladeFile)) {
|
|
|
|
+ return R.fail("oss上传失败,请校验oss配置是否正确");
|
|
|
|
+ }
|
|
|
|
+ // 解析原始excel
|
|
|
|
+ detail.setExtension(file.getOriginalFilename());
|
|
|
|
+ detail.setFileUrl(bladeFile.getLink());
|
|
|
|
+ detail.setFileType(3); // 表示为清表信息 1 表示祖节点 2 表示为节点信息 3 表示清表
|
|
|
|
+ detail.setHtmlUrl(thmlUrl);
|
|
|
|
+ excelTabClient.saveOrUpdate(detail);
|
|
|
|
+ // 解析html
|
|
|
|
+ excelTabClient.expailHtmlInfo(thmlUrl, detail.getId(), detail.getTabType() + "");
|
|
|
|
+ return R.success("上传成功");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 每周天晚上2点定时更新private和contract的html,通过is_private_type_id;
|
|
|
|
+ */
|
|
|
|
+ public void checkAndRepairPrivateAndContractHtml() {}
|
|
|
|
+}
|