Browse Source

新增CSV文件转换节点-修改存储文件名称

Zhangvinjo 3 years ago
parent
commit
fab23fb794

+ 15 - 3
src/main/java/io/renren/modules/sys/controller/VisiWorkflowController.java

@@ -18,6 +18,7 @@ import io.renren.modules.sys.entity.VisiWorkflowEntity;
 import io.renren.modules.sys.service.VisiWorkflowService;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -47,6 +48,8 @@ public class VisiWorkflowController extends AbstractController {
     //20211108
     @Autowired
     private VisiWorkflowService visiWorkflowService;
+    @Value("${datasetLocation}")
+    String datasetLocation;
 
 
     /**
@@ -1533,14 +1536,21 @@ public class VisiWorkflowController extends AbstractController {
 
         //2.1 设置输出的文件路径
         //如果该目录下不存在该文件,则文件会被创建到指定目录下。如果该目录有同名文件,那么该文件将被覆盖。
-        File writeFile = new File("src/main/resources/"+"new"+filename.toString());
+//        File writeFile = new File("src/main/resources/"+"new"+filename.toString());
+        File writeFile = new File(datasetLocation+"/new"+filename.toString());
 
         try{
             //2.2 通过BufferedReader类创建一个使用默认大小输出缓冲区的缓冲字符输出流
             BufferedWriter writeText = new BufferedWriter(new FileWriter(writeFile));
             if(Integer.parseInt(rowminnum.toString())!=0){
                 //选中的行不包含表头,添加
-                writeText.write(StringUtils.join(headerinfo,","));
+                StringBuffer newheaderinfostr = new StringBuffer();
+                for (int j = Integer.parseInt(colminnum.toString()); j <= Integer.parseInt(colmaxnum.toString()); j++) {
+                    newheaderinfostr.append(headerinfo[j]).append(",");
+                }
+                String[] newheaderinfo = newheaderinfostr.toString().split(",");
+
+                writeText.write(StringUtils.join(newheaderinfo,","));
                 writeText.newLine();
             }
             //2.3 将文档的下一行数据赋值给lineData,并判断是否为空,若不为空则输出
@@ -1565,7 +1575,9 @@ public class VisiWorkflowController extends AbstractController {
         //上传新文件到minio
 //        MinIoUtils.uploadMultipartFile(file, "visiarguartifact", "argoworkflow" + "/" + file.getOriginalFilename());
 
-        MinIoUtils.uploadLocalFile("visiarguartifact","argoworkflow" + "/" + writeFile.getName(),writeFile.getPath(),null);
+        InputStream inputStream = new FileInputStream(writeFile);
+        MinIoUtils.uploadFileByInputStream(inputStream, (long) inputStream.available(),"visiarguartifact","argoworkflow" + "/" + writeFile.getName());
+//        MinIoUtils.uploadLocalFile("visiarguartifact","argoworkflow" + "/" + writeFile.getName(),writeFile.getPath(),null);
         String newfileurl = MinIoUtils.getFileUrl("visiarguartifact", "argoworkflow" + "/" + writeFile.getName());
         //上传成功后删除本地文件
         if(writeFile.exists()) {//判断路径是否存在