|
@@ -9,22 +9,31 @@ 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;
|
|
|
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.nio.file.Files;
|
|
|
+import java.time.chrono.JapaneseDate;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@RestController
|
|
@@ -41,10 +50,9 @@ public class CheckAndRepairController {
|
|
|
*/
|
|
|
@RequestMapping("/checkAndRepairExcelHtml")
|
|
|
@ApiOperation("定时检测修复ExcelHtml")
|
|
|
- @Scheduled(cron = "0 15 16 * * ?")
|
|
|
+ @Scheduled(cron = "00 00 00 * * ?")
|
|
|
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 +65,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){
|
|
|
+ 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();
|
|
|
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 +104,199 @@ 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("上传失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 定时更新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 initTable 通过excelID,保证一样
|
|
|
+ */
|
|
|
+ @GetMapping("/checkAndRepairPrivateInitTableAndExcelId")
|
|
|
+ @Scheduled(cron = "0 57 16 * * ?")
|
|
|
+ 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)";
|
|
|
+ List<WbsTreePrivate> list = jdbcTemplate.query(privateSql, new BeanPropertyRowMapper<>(WbsTreePrivate.class));
|
|
|
+ list = list.stream()
|
|
|
+ .filter(item ->
|
|
|
+ !ObjectUtil.isEmpty(item.getHtmlUrl()) ||
|
|
|
+ !ObjectUtil.isEmpty(item.getExcelId()) ||
|
|
|
+ !ObjectUtil.isEmpty(item.getInitTableName())
|
|
|
+ )
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ //excelId不为空 但是initTableName为空
|
|
|
+ List<WbsTreePrivate> list1 = list.stream()
|
|
|
+ .filter(item ->
|
|
|
+ !ObjectUtil.isEmpty(item.getExcelId()) &&
|
|
|
+ ObjectUtil.isEmpty(item.getInitTableName())
|
|
|
+ )
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ //excelId为空 但是initTableName不为空
|
|
|
+ List<WbsTreePrivate> list2 = list.stream()
|
|
|
+ .filter(item ->
|
|
|
+ ObjectUtil.isEmpty(item.getExcelId()) &&
|
|
|
+ !ObjectUtil.isEmpty(item.getInitTableName())
|
|
|
+ )
|
|
|
+ .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";
|
|
|
+ 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";
|
|
|
+ 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");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 每周天晚上2点定时更新private和contract的html,通过is_private_type_id;
|
|
|
+ * 定时更新contract initTable 通过excelID,保证一样
|
|
|
*/
|
|
|
- public void checkAndRepairPrivateAndContractHtml() {}
|
|
|
+ @GetMapping("/checkAndRepairContractInitTableAndExcelId")
|
|
|
+ @Scheduled(cron = "0 00 2 * * ?")
|
|
|
+ public void checkAndRepairContractInitTableAndExcelId() {
|
|
|
+ System.out.println("定时更新contract initTable和ExcelId");
|
|
|
+ String contractSql="select p_key_id,init_table_name,excel_id,html_url from m_wbs_tree_contract where type=2 AND is_deleted=0 AND (excel_id IS NULL OR init_table_name IS NULL OR html_url IS NULL)";
|
|
|
+ List<WbsTreeContract> list = jdbcTemplate.query(contractSql, new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
|
+ list = list.stream()
|
|
|
+ .filter(item ->
|
|
|
+ !ObjectUtil.isEmpty(item.getHtmlUrl()) ||
|
|
|
+ !ObjectUtil.isEmpty(item.getExcelId()) ||
|
|
|
+ !ObjectUtil.isEmpty(item.getInitTableName())
|
|
|
+ )
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ //excelId不为空 但是initTableName为空
|
|
|
+ List<WbsTreeContract> list1 = list.stream()
|
|
|
+ .filter(item ->
|
|
|
+ !ObjectUtil.isEmpty(item.getExcelId()) &&
|
|
|
+ ObjectUtil.isEmpty(item.getInitTableName())
|
|
|
+ )
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ //excelId为空 但是initTableName不为空
|
|
|
+ List<WbsTreeContract> list2 = list.stream()
|
|
|
+ .filter(item ->
|
|
|
+ ObjectUtil.isEmpty(item.getExcelId()) &&
|
|
|
+ !ObjectUtil.isEmpty(item.getInitTableName())
|
|
|
+ )
|
|
|
+ .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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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();
|
|
|
+ jdbcTemplate.update(update);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("更新完毕contract initTable和ExcelId");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|