|
@@ -1,7 +1,11 @@
|
|
package com.kexun.controller;
|
|
package com.kexun.controller;
|
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
|
|
|
//import ch.qos.logback.core.rolling.helper.FileStoreUtil;
|
|
//import ch.qos.logback.core.rolling.helper.FileStoreUtil;
|
|
//import ch.qos.logback.core.util.FileUtil;
|
|
//import ch.qos.logback.core.util.FileUtil;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.kexun.common.FileUploadUtil;
|
|
import com.kexun.common.FileUploadUtil;
|
|
import com.kexun.common.utils.Result;
|
|
import com.kexun.common.utils.Result;
|
|
import com.kexun.entity.SysUser;
|
|
import com.kexun.entity.SysUser;
|
|
@@ -49,27 +53,79 @@ public class FileUploadController {
|
|
@Value("${config.fileupload.warpath}")
|
|
@Value("${config.fileupload.warpath}")
|
|
private String warPath;
|
|
private String warPath;
|
|
|
|
|
|
|
|
+ @PostMapping("/filechange")
|
|
|
|
+ public Result filechange(@RequestParam Integer index, @RequestParam MultipartFile chunk, @RequestParam String name, @RequestParam Integer chunksLength, @RequestParam String uid
|
|
|
|
+ , @RequestParam String output_list, SysUser sysUser, @RequestParam long id
|
|
|
|
+ ) throws IOException {
|
|
|
|
+ String filename = name.split("\\.")[0];
|
|
|
|
+ String filefmt = name.split("\\.")[1];
|
|
|
|
+ String fullFileName = String.join("-", new String[]{filename, uid, index + "", "." + filefmt});
|
|
|
|
+ String filePath=fileuploadPath + "/" + sysUser.getUserName() + "/" +filename+"."+filefmt;
|
|
|
|
+ log.info("filename:" + fullFileName);
|
|
|
|
+ File dir = new File(fileuploadPath + "/" + sysUser.getUserName() + "/");
|
|
|
|
+
|
|
|
|
+ if (!dir.exists())
|
|
|
|
+ dir.mkdirs();
|
|
|
|
+
|
|
|
|
+ File file = new File(fileuploadPath + "/" + sysUser.getUserName() + "/" + fullFileName);
|
|
|
|
+ FileCopyUtils.copy(chunk.getInputStream(), new FileOutputStream(file));
|
|
|
|
+ FileUploadUtil.put(uid, index, chunksLength, fullFileName, fileuploadPath + "/" + sysUser.getUserName() + "/");
|
|
|
|
+ // 检测所有文件是否上传完成
|
|
|
|
+ boolean isAllChunksUploaded = FileUploadUtil.isAllChunksUploaded(uid);
|
|
|
|
+ //当前步骤这一步一定完成
|
|
|
|
+ try {
|
|
|
|
+ if (isAllChunksUploaded) {
|
|
|
|
+ FileUploadUtil.mergeChunks(name, uid);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ throw new RuntimeException(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ UserModel model=userModelService.findByID(id);
|
|
|
|
+ String oldFilePath=model.getFilePath();
|
|
|
|
+ File oldFile = new File(oldFilePath);
|
|
|
|
+
|
|
|
|
+ if (oldFile.exists()) {
|
|
|
|
+ try {
|
|
|
|
+ FileUtils.forceDelete(oldFile);
|
|
|
|
+ System.out.println("file delete success");
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ System.out.println("file delete fail: " + e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ System.out.println("file not exist");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ model.setFilePath(filePath);
|
|
|
|
+ userModelService.updateById(model);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return Result.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
//上传用户模型及审批结果
|
|
//上传用户模型及审批结果
|
|
@PostMapping("/fileupload")
|
|
@PostMapping("/fileupload")
|
|
@ResponseBody
|
|
@ResponseBody
|
|
public Result upload2(@RequestParam Integer index, @RequestParam MultipartFile chunk, @RequestParam String name, @RequestParam Integer chunksLength, @RequestParam String uid
|
|
public Result upload2(@RequestParam Integer index, @RequestParam MultipartFile chunk, @RequestParam String name, @RequestParam Integer chunksLength, @RequestParam String uid
|
|
, @RequestParam String model_name, @RequestParam String model_type, @RequestParam String output_list, SysUser sysUser
|
|
, @RequestParam String model_name, @RequestParam String model_type, @RequestParam String output_list, SysUser sysUser
|
|
) throws IOException {
|
|
) throws IOException {
|
|
- int type=Integer.parseInt(model_type);
|
|
|
|
- if(type==1 || type==2)
|
|
|
|
- {
|
|
|
|
|
|
+ int type = Integer.parseInt(model_type);
|
|
|
|
+ if (type == 1 || type == 2) {
|
|
String filename = name.split("\\.")[0];
|
|
String filename = name.split("\\.")[0];
|
|
String filefmt = name.split("\\.")[1];
|
|
String filefmt = name.split("\\.")[1];
|
|
- String fullFileName = String.join("-", new String[] {filename, uid, index + "", "." + filefmt});
|
|
|
|
|
|
+ String fullFileName = String.join("-", new String[]{filename, uid, index + "", "." + filefmt});
|
|
|
|
+ String filePath=fileuploadPath + "/" + sysUser.getUserName() + "/" +filename+"."+filefmt;
|
|
log.info("filename:" + fullFileName);
|
|
log.info("filename:" + fullFileName);
|
|
- File dir = new File(fileuploadPath+ "/" +sysUser.getUserName()+"/");
|
|
|
|
|
|
+ File dir = new File(fileuploadPath + "/" + sysUser.getUserName() + "/");
|
|
|
|
|
|
if (!dir.exists())
|
|
if (!dir.exists())
|
|
dir.mkdirs();
|
|
dir.mkdirs();
|
|
|
|
|
|
- File file = new File(fileuploadPath + "/" +sysUser.getUserName()+"/"+ fullFileName);
|
|
|
|
|
|
+ File file = new File(fileuploadPath + "/" + sysUser.getUserName() + "/" + fullFileName);
|
|
FileCopyUtils.copy(chunk.getInputStream(), new FileOutputStream(file));
|
|
FileCopyUtils.copy(chunk.getInputStream(), new FileOutputStream(file));
|
|
- FileUploadUtil.put(uid, index, chunksLength, fullFileName, fileuploadPath+ "/" +sysUser.getUserName()+"/");
|
|
|
|
|
|
+ FileUploadUtil.put(uid, index, chunksLength, fullFileName, fileuploadPath + "/" + sysUser.getUserName() + "/");
|
|
// 检测所有文件是否上传完成
|
|
// 检测所有文件是否上传完成
|
|
boolean isAllChunksUploaded = FileUploadUtil.isAllChunksUploaded(uid);
|
|
boolean isAllChunksUploaded = FileUploadUtil.isAllChunksUploaded(uid);
|
|
//当前步骤这一步一定完成
|
|
//当前步骤这一步一定完成
|
|
@@ -91,24 +147,22 @@ public class FileUploadController {
|
|
|
|
|
|
|
|
|
|
//model 数据库连接接口
|
|
//model 数据库连接接口
|
|
- String userName=sysUser.getUserName();
|
|
|
|
- UserModel new_model=new UserModel();
|
|
|
|
|
|
+ String userName = sysUser.getUserName();
|
|
|
|
+ UserModel new_model = new UserModel();
|
|
new_model.setCreateBy(userName);
|
|
new_model.setCreateBy(userName);
|
|
new_model.setModelName(model_name);
|
|
new_model.setModelName(model_name);
|
|
new_model.setModelType(type);
|
|
new_model.setModelType(type);
|
|
new_model.setStatus("暂停使用");
|
|
new_model.setStatus("暂停使用");
|
|
// new_model.setOtherData(name);
|
|
// new_model.setOtherData(name);
|
|
// new_model.setOutputList(output_list);
|
|
// new_model.setOutputList(output_list);
|
|
- new_model.setFilePath(fileuploadPath + "/" +sysUser.getUserName()+"/"+ fullFileName);
|
|
|
|
|
|
+ new_model.setFilePath(filePath);
|
|
userModelService.save(new_model);
|
|
userModelService.save(new_model);
|
|
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
|
|
+ } else {
|
|
// http请求
|
|
// http请求
|
|
String filename = name.split("\\.")[0];
|
|
String filename = name.split("\\.")[0];
|
|
String filefmt = name.split("\\.")[1];
|
|
String filefmt = name.split("\\.")[1];
|
|
- String fullFileName = String.join("-", new String[] {filename, uid, index + "", "." + filefmt});
|
|
|
|
|
|
+ String fullFileName = String.join("-", new String[]{filename, uid, index + "", "." + filefmt});
|
|
log.info("filename:" + fullFileName);
|
|
log.info("filename:" + fullFileName);
|
|
File dir = new File(warPath);
|
|
File dir = new File(warPath);
|
|
if (!dir.exists())
|
|
if (!dir.exists())
|
|
@@ -129,22 +183,20 @@ public class FileUploadController {
|
|
}
|
|
}
|
|
|
|
|
|
//审批
|
|
//审批
|
|
- UserApproval approval=new UserApproval();
|
|
|
|
|
|
+ UserApproval approval = new UserApproval();
|
|
approval.setUserName(sysUser.getUserName());
|
|
approval.setUserName(sysUser.getUserName());
|
|
approval.setApprovalId((long) 1);
|
|
approval.setApprovalId((long) 1);
|
|
|
|
|
|
|
|
|
|
approval.setData(model_name.split(";")[0]);
|
|
approval.setData(model_name.split(";")[0]);
|
|
|
|
|
|
- String url_address=model_name.split(";")[1];
|
|
|
|
|
|
+ String url_address = model_name.split(";")[1];
|
|
|
|
|
|
userApprovalService.save(approval);
|
|
userApprovalService.save(approval);
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- String userName=sysUser.getUserName();
|
|
|
|
- UserModel new_model=new UserModel();
|
|
|
|
|
|
+ String userName = sysUser.getUserName();
|
|
|
|
+ UserModel new_model = new UserModel();
|
|
new_model.setCreateBy(userName);
|
|
new_model.setCreateBy(userName);
|
|
new_model.setModelName(model_name);
|
|
new_model.setModelName(model_name);
|
|
new_model.setModelType(type);
|
|
new_model.setModelType(type);
|
|
@@ -154,7 +206,7 @@ public class FileUploadController {
|
|
new_model.setFilePath(warPath + "/" + fullFileName);
|
|
new_model.setFilePath(warPath + "/" + fullFileName);
|
|
userModelService.save(new_model);
|
|
userModelService.save(new_model);
|
|
}
|
|
}
|
|
- return Result.success();
|
|
|
|
|
|
+ return Result.success();
|
|
}
|
|
}
|
|
|
|
|
|
@GetMapping("/get")
|
|
@GetMapping("/get")
|