更新本地js
This commit is contained in:
@@ -82,7 +82,7 @@ public class BizFiles implements Serializable {
|
||||
* 是否删除(0-未删除,1-已删除)
|
||||
*/
|
||||
@TableField("is_deleted")
|
||||
private Byte isDeleted;
|
||||
private Integer isDeleted;
|
||||
|
||||
/**
|
||||
* 文件版本号(用于版本控制)
|
||||
|
||||
@@ -13,6 +13,7 @@ import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -152,8 +153,13 @@ public class viewController {
|
||||
*/
|
||||
|
||||
@GetMapping("/biz/dataDoc")
|
||||
public String getDataDox(Model model) {
|
||||
List<BizFiles> files = filesService.list();
|
||||
public String getDataDox(Model model, String folderId) {
|
||||
QueryWrapper<BizFiles> fileWrapper = new QueryWrapper<>();
|
||||
fileWrapper.eq("is_deleted", "0");
|
||||
if (StringUtils.hasText(folderId)) {
|
||||
fileWrapper.eq("folder_id", folderId);
|
||||
}
|
||||
List<BizFiles> files = filesService.list(fileWrapper);
|
||||
List<FolderTree> folderTrees = new ArrayList<>();
|
||||
QueryWrapper<BizFileFolders> parentWrapper = new QueryWrapper<>();
|
||||
parentWrapper.eq("parent_id", "0");
|
||||
@@ -164,7 +170,14 @@ public class viewController {
|
||||
List<BizFileFolders> childFolders = foldersService.list(childWrapper);
|
||||
folderTrees.add(new FolderTree(fileFolder, childFolders));
|
||||
}
|
||||
|
||||
QueryWrapper<BizFileFolders> uploadWrapper = new QueryWrapper<>();
|
||||
uploadWrapper.ne("parent_id", 0);
|
||||
List<BizFileFolders> uploadFolder = foldersService.list(uploadWrapper);
|
||||
|
||||
|
||||
model.addAttribute("files", files);
|
||||
model.addAttribute("uploadFolder", uploadFolder);
|
||||
model.addAttribute("folderTrees", folderTrees);
|
||||
return "file";
|
||||
}
|
||||
|
||||
@@ -1,16 +1,27 @@
|
||||
package com.mini.capi.biz;
|
||||
|
||||
import com.mini.capi.biz.domain.BizFileFolders;
|
||||
import com.mini.capi.biz.domain.BizFiles;
|
||||
import com.mini.capi.biz.domain.BizSubTask;
|
||||
import com.mini.capi.biz.service.BizFileFoldersService;
|
||||
import com.mini.capi.biz.service.BizFilesService;
|
||||
import com.mini.capi.biz.service.BizSubTaskService;
|
||||
import com.mini.capi.model.ApiResult;
|
||||
import com.mini.capi.model.CreateFolder;
|
||||
import com.mini.capi.model.info.TodoHandleDTO;
|
||||
import com.mini.capi.utils.FileUtils;
|
||||
import com.mini.capi.utils.vId;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/biz")
|
||||
@@ -20,6 +31,14 @@ public class workController {
|
||||
@Resource
|
||||
private BizSubTaskService bizSubTaskService;
|
||||
|
||||
@Resource
|
||||
private BizFileFoldersService bizFileFoldersService;
|
||||
|
||||
@Resource
|
||||
private BizFilesService bizFilesService;
|
||||
|
||||
private static String UPLOAD_PATH = "/ogsapp/files/";
|
||||
|
||||
|
||||
/**
|
||||
* 完成待办
|
||||
@@ -45,4 +64,72 @@ public class workController {
|
||||
return ResponseEntity.status(500).build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建文件夹
|
||||
*/
|
||||
@PostMapping("/CreateFolder")
|
||||
public ApiResult<?> CreateFolder(@Validated @RequestBody CreateFolder request) {
|
||||
try {
|
||||
String dirId = vId.getCid();
|
||||
BizFileFolders folders = new BizFileFolders();
|
||||
folders.setFolderId(dirId);
|
||||
folders.setFolderName(request.getName());
|
||||
folders.setParentId(request.getParentId());
|
||||
bizFileFoldersService.save(folders);
|
||||
FileUtils.checkDirExists(UPLOAD_PATH + dirId);
|
||||
return ApiResult.success();
|
||||
} catch (Exception e) {
|
||||
// 异常捕获,返回失败响应
|
||||
return ApiResult.error(101, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("uploadFiles")
|
||||
public ResponseEntity<Map<String, Object>> uploadFiles(
|
||||
@RequestParam(value = "folderId") String folderId,
|
||||
@RequestParam("files") MultipartFile[] files) {
|
||||
// 响应结果集
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Path basePath = Paths.get(UPLOAD_PATH + folderId);
|
||||
FileUtils.checkDirExists(basePath.toString());
|
||||
// 统计成功/失败数量
|
||||
int successCount = 0;
|
||||
int failCount = 0;
|
||||
// 遍历上传的文件
|
||||
for (MultipartFile file : files) {
|
||||
BizFiles bizFiles = new BizFiles();
|
||||
try {
|
||||
// 1. 获取原始文件名和后缀
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String fileSuffix = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
// 2. 生成唯一文件名(避免文件名冲突)
|
||||
String uniqueFileName = vId.getCid() + fileSuffix;
|
||||
// 3. 构建文件存储路径
|
||||
Path filePath = basePath.resolve(uniqueFileName);
|
||||
// 4. 保存文件到本地磁盘
|
||||
file.transferTo(filePath.toFile());
|
||||
bizFiles.setFileName(originalFilename);
|
||||
bizFiles.setFolderId(folderId);
|
||||
bizFiles.setFileSize(file.getSize());
|
||||
bizFiles.setFileType(fileSuffix);
|
||||
bizFiles.setFilePath(filePath.toString());
|
||||
bizFiles.setCreatorId(0);
|
||||
bizFiles.setIsDeleted(0);
|
||||
bizFilesService.save(bizFiles);
|
||||
successCount++;
|
||||
} catch (Exception e) {
|
||||
System.err.print(e.getMessage());
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
// 构建响应结果
|
||||
result.put("success", true);
|
||||
result.put("message", "上传成功");
|
||||
result.put("successCount", successCount);
|
||||
result.put("failCount", failCount);
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
}
|
||||
|
||||
13
src/main/java/com/mini/capi/model/CreateFolder.java
Normal file
13
src/main/java/com/mini/capi/model/CreateFolder.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.mini.capi.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class CreateFolder implements Serializable {
|
||||
|
||||
private String name;
|
||||
|
||||
private String parentId;
|
||||
}
|
||||
@@ -19,7 +19,6 @@ public class LoggerUtils {
|
||||
// 单例实例
|
||||
private static volatile LoggerUtils instance;
|
||||
|
||||
// 日志文件根路径(默认:/ogsapp/logs/cApi)
|
||||
private String baseLogPath;
|
||||
|
||||
// 日期格式(文件名:yyyyMMdd,日志内容时间戳:yyyy-MM-dd HH:mm:ss.SSS)
|
||||
|
||||
@@ -24,4 +24,12 @@ public class vId {
|
||||
return tm + String.format("%015d", rand);
|
||||
}
|
||||
|
||||
|
||||
public static String getCid() {
|
||||
// 17 位时间
|
||||
String tm = LocalDateTime.now().format(DF);
|
||||
// 25 位随机数字(高位补零)
|
||||
long rand = Math.abs(RAND.nextLong()) % (long) Math.pow(3, 6);
|
||||
return tm + String.format("%04d", rand);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user