2025-03-28 17:38:34 +08:00
|
|
|
|
package com.celnet.datadump.controller;
|
|
|
|
|
|
2025-06-26 14:22:44 +08:00
|
|
|
|
import com.alibaba.fastjson.JSON;
|
2025-03-28 17:38:34 +08:00
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
2025-06-26 14:22:44 +08:00
|
|
|
|
import com.celnet.datadump.entity.DataObject;
|
2025-03-28 17:38:34 +08:00
|
|
|
|
import com.celnet.datadump.entity.OrgConfig;
|
|
|
|
|
import com.celnet.datadump.global.Result;
|
2025-06-26 14:22:44 +08:00
|
|
|
|
import com.celnet.datadump.param.DumpFileParam;
|
|
|
|
|
import com.celnet.datadump.service.DataObjectService;
|
2025-03-28 17:38:34 +08:00
|
|
|
|
import com.celnet.datadump.service.FileManagerService;
|
2025-06-26 14:22:44 +08:00
|
|
|
|
import com.celnet.datadump.service.FileService;
|
|
|
|
|
import com.celnet.datadump.util.DataUtil;
|
|
|
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
|
|
import com.xxl.job.core.log.XxlJobLogger;
|
2025-03-28 17:38:34 +08:00
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
2025-06-26 14:22:44 +08:00
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2025-03-28 17:38:34 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2025-06-26 14:22:44 +08:00
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
2025-03-28 17:38:34 +08:00
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@Api(value = "fileManager", tags = "文件管理")
|
|
|
|
|
@RequestMapping("/fileManager")
|
2025-06-26 14:22:44 +08:00
|
|
|
|
@Slf4j
|
2025-03-28 17:38:34 +08:00
|
|
|
|
public class FileManagerController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private FileManagerService fileManagerService;
|
2025-06-26 14:22:44 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
private FileService fileService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private DataObjectService dataObjectService;
|
2025-03-28 17:38:34 +08:00
|
|
|
|
|
|
|
|
|
@GetMapping("/documentPage")
|
|
|
|
|
@ApiOperation("document page")
|
|
|
|
|
public Result documentPage(@RequestParam("isDump") Integer isDump, @RequestParam("isUpload")Integer isUpload,
|
|
|
|
|
@RequestParam(value = "Name", required = false)String Name, @RequestParam("current")Integer page,
|
|
|
|
|
@RequestParam("size")Integer pageSize) {
|
|
|
|
|
return Result.success(fileManagerService.getDocFileList(isDump, isUpload, Name, page, pageSize));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/attachmentPage")
|
|
|
|
|
@ApiOperation("attachment page")
|
|
|
|
|
public Result attachmentPage(@RequestParam("isDump") Integer isDump, @RequestParam("isUpload")Integer isUpload,
|
|
|
|
|
@RequestParam(value = "Name", required = false)String Name, @RequestParam("current")Integer page,
|
|
|
|
|
@RequestParam("size")Integer pageSize) {
|
|
|
|
|
return Result.success(fileManagerService.getAttachmentFileList(isDump, isUpload, Name, page, pageSize));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/dumpImg")
|
|
|
|
|
public Result dumpImg(@RequestParam("token") String token) {
|
|
|
|
|
return Result.success(fileManagerService.dumpImg(token));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/uploadImg")
|
|
|
|
|
public Result uploadImg(@RequestParam("token") String token) {
|
|
|
|
|
return Result.success(fileManagerService.uploadImg(token));
|
|
|
|
|
}
|
2025-06-26 14:22:44 +08:00
|
|
|
|
|
|
|
|
|
@PostMapping("/dumpFileLocal")
|
|
|
|
|
@ApiOperation("附件下载")
|
|
|
|
|
public ReturnT<String> dumpFileLocal(String paramStr) throws Exception {
|
|
|
|
|
log.info("dumpFileLocal execute start ..................");
|
|
|
|
|
DumpFileParam param = new DumpFileParam();
|
|
|
|
|
try {
|
|
|
|
|
if (StringUtils.isNotBlank(paramStr)) {
|
|
|
|
|
param = JSON.parseObject(paramStr, DumpFileParam.class);
|
|
|
|
|
}
|
|
|
|
|
} catch (Throwable throwable) {
|
|
|
|
|
return new ReturnT<>(500, "参数解析失败!");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isBlank(param.getApi())) {
|
|
|
|
|
return new ReturnT<>(500, "api参数缺失!");
|
|
|
|
|
}
|
|
|
|
|
for (String api : DataUtil.toIdList(param.getApi())) {
|
|
|
|
|
DataObject dataObject = dataObjectService.getById(api);
|
|
|
|
|
String blobField = dataObject.getBlobField();
|
|
|
|
|
if (StringUtils.isBlank(blobField)) {
|
|
|
|
|
log.error("api:{} does not have blob field", api);
|
|
|
|
|
XxlJobLogger.log("api:{} does not have blob field", api);
|
|
|
|
|
}
|
|
|
|
|
fileService.dumpFile(api, blobField, param.getSingleThread());
|
|
|
|
|
}
|
|
|
|
|
return ReturnT.SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/uploadFileLocal")
|
|
|
|
|
@ApiOperation("附件上传")
|
|
|
|
|
public ReturnT<String> uploadFileLocal(String paramStr) throws Exception {
|
|
|
|
|
log.info("uploadFileJob execute start ..................");
|
|
|
|
|
DumpFileParam param = new DumpFileParam();
|
|
|
|
|
try {
|
|
|
|
|
if (StringUtils.isNotBlank(paramStr)) {
|
|
|
|
|
param = JSON.parseObject(paramStr, DumpFileParam.class);
|
|
|
|
|
}
|
|
|
|
|
} catch (Throwable throwable) {
|
|
|
|
|
return new ReturnT<>(500, "参数解析失败!");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isBlank(param.getApi())) {
|
|
|
|
|
return new ReturnT<>(500, "api参数缺失!");
|
|
|
|
|
}
|
|
|
|
|
for (String api : DataUtil.toIdList(param.getApi())) {
|
|
|
|
|
DataObject dataObject = dataObjectService.getById(api);
|
|
|
|
|
String blobField = dataObject.getBlobField();
|
|
|
|
|
if (StringUtils.isBlank(blobField)) {
|
|
|
|
|
log.error("api:{} does not have blob field", api);
|
|
|
|
|
XxlJobLogger.log("api:{} does not have blob field", api);
|
|
|
|
|
}
|
|
|
|
|
if ("Attachment".equals(api)){
|
|
|
|
|
fileService.uploadFileToAttachment(api, blobField, param.getSingleThread());
|
|
|
|
|
}else {
|
|
|
|
|
fileService.uploadFile(api, blobField, param.getSingleThread());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ReturnT.SUCCESS;
|
|
|
|
|
}
|
2025-03-28 17:38:34 +08:00
|
|
|
|
}
|