添加业务类型的附件上传,更新实例ID,删除方法
This commit is contained in:
parent
8c7031c0f6
commit
eb9fcf94c7
@ -8,11 +8,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.BpmFileUploadReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileRespVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileUploadReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.*;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.BpmFileDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.BusinessFileDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
|
||||
import cn.iocoder.yudao.module.infra.service.file.FileService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@ -117,4 +115,29 @@ public class FileController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
//add by yj 2024 04-11 Begin
|
||||
@PostMapping("/businessUpload")
|
||||
@Operation(summary = "上传业务类型附件【如:工作日/周报附件】")
|
||||
@OperateLog(logArgs = false) // 上传文件,没有记录操作日志的必要
|
||||
public CommonResult<BusinessFileDO> businessUpload(@RequestParam("uploadFiles") MultipartFile file,@RequestParam("businessType")Long businessType) throws Exception {
|
||||
return success(fileService.createBusinessReturnFile(file,businessType));
|
||||
}
|
||||
|
||||
@DeleteMapping("/deleteBusinessFile")
|
||||
@Operation(summary = "删除业务流附件【如:工作日/周报附件】")
|
||||
@Parameter(name = "url", description = "附件URL地址", required = true)
|
||||
public CommonResult<Boolean> deleteBusinessFile(@RequestParam("url") String url) throws Exception {
|
||||
fileService.deleteBusinessFile(url);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/uploadBusinessFileProcessInstanceId")
|
||||
@Operation(summary = "更新文件的实例ID【如:工作日/周报附件】")
|
||||
@OperateLog(logArgs = false) // 上传文件,没有记录操作日志的必要
|
||||
public String uploadBusinessFileProcessInstanceId(@Valid @RequestBody BusinessFileUploadReqVO reqVO) throws Exception {
|
||||
fileService.uploadBusinessFileProcessInstanceId(reqVO);
|
||||
return "success" ;
|
||||
}
|
||||
//add by yj 2024 04-11 End
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.file.vo.file;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 上传业务文件 Request VO")
|
||||
@Data
|
||||
public class BusinessFileUploadReqVO {
|
||||
|
||||
@Schema(description = "附件地址", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "附件地址不能为空")
|
||||
private List<String> urls;
|
||||
|
||||
@Schema(description = "流程实例编号", example = "7c45f44f-b775-11ee-aba7-5ea7f9635f60")
|
||||
@NotNull(message = "流程实例编号不能为空")
|
||||
private String businessInstanceId;
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.dataobject.file;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* 文件表
|
||||
* 每次文件上传,都会记录一条记录到该表中
|
||||
*
|
||||
|
||||
*/
|
||||
@TableName("business_file")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BusinessFileDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号,数据库自增
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 业务类型 1:日志 2.暂定 3.暂定 4...
|
||||
*/
|
||||
private Long businessType;
|
||||
/**
|
||||
* 配置编号
|
||||
*
|
||||
* 关联 {@link FileConfigDO#getId()}
|
||||
*/
|
||||
private Long configId;
|
||||
/**
|
||||
* 原文件名
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 路径,即文件名
|
||||
*/
|
||||
private String path;
|
||||
/**
|
||||
* 访问地址
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 文件的 MIME 类型,例如 "application/octet-stream"
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* 文件大小
|
||||
*/
|
||||
private Integer size;
|
||||
|
||||
/**
|
||||
* 上传人ID
|
||||
*/
|
||||
private Long uploadUserId ;
|
||||
|
||||
/**
|
||||
* 流程实例编号
|
||||
*/
|
||||
private String businessInstanceId ;
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.mysql.file;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.BpmFileDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.BusinessFileDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* business文件操作 Mapper
|
||||
*
|
||||
|
||||
*/
|
||||
@Mapper
|
||||
public interface BusinessFileMapper extends BaseMapperX<BusinessFileDO> {
|
||||
|
||||
default PageResult<BusinessFileDO> selectPage(FilePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<BusinessFileDO>()
|
||||
.likeIfPresent(BusinessFileDO::getPath, reqVO.getPath())
|
||||
.likeIfPresent(BusinessFileDO::getType, reqVO.getType())
|
||||
.betweenIfPresent(BusinessFileDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(BusinessFileDO::getId));
|
||||
}
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
package cn.iocoder.yudao.module.infra.service.file;
|
||||
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.BpmFileUploadReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.BusinessFileUploadReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.BpmFileDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.BusinessFileDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@ -77,4 +79,28 @@ public interface FileService {
|
||||
* @throws Exception
|
||||
*/
|
||||
void uploadBpmFileProcessInstanceId(BpmFileUploadReqVO reqVO) throws Exception ;
|
||||
|
||||
/**
|
||||
* 保存业务类型文件,并返回文件对象
|
||||
*
|
||||
* @param file 上传文件对象
|
||||
* @param businessType 业务类型
|
||||
* @return 文件路径
|
||||
*/
|
||||
BusinessFileDO createBusinessReturnFile(MultipartFile file, Long businessType);
|
||||
|
||||
/**
|
||||
* 删除bpm文件
|
||||
* @param url
|
||||
* @throws Exception
|
||||
*/
|
||||
void deleteBusinessFile(String url) throws Exception;
|
||||
|
||||
/**
|
||||
* 更新文件的流程实例ID
|
||||
* @param reqVO
|
||||
* @throws Exception
|
||||
*/
|
||||
void uploadBusinessFileProcessInstanceId(BusinessFileUploadReqVO reqVO) throws Exception ;
|
||||
|
||||
}
|
||||
|
@ -10,10 +10,13 @@ import cn.iocoder.yudao.framework.file.core.client.FileClient;
|
||||
import cn.iocoder.yudao.framework.file.core.utils.FileTypeUtils;
|
||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.BpmFileUploadReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.BusinessFileUploadReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.BpmFileDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.BusinessFileDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.file.BpmFileMapper;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.file.BusinessFileMapper;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.file.FileMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import lombok.SneakyThrows;
|
||||
@ -40,12 +43,14 @@ public class FileServiceImpl implements FileService {
|
||||
@Resource
|
||||
private BpmFileMapper bpmFileMapper;
|
||||
|
||||
@Resource
|
||||
private BusinessFileMapper businessFileMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<FileDO> getFilePage(FilePageReqVO pageReqVO) {
|
||||
return fileMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public BpmFileDO createReturnFile(MultipartFile file) {
|
||||
@ -206,4 +211,94 @@ public class FileServiceImpl implements FileService {
|
||||
// 调用 MyBatis Plus 的 update 方法执行批量更新
|
||||
bpmFileMapper.update(null, lambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public BusinessFileDO createBusinessReturnFile(MultipartFile file, Long businessType) {
|
||||
Long userId = SecurityFrameworkUtils.getLoginUserId();
|
||||
long timestamp = System.currentTimeMillis();
|
||||
|
||||
String[] fileInfo = new String[4];
|
||||
String name = file.getOriginalFilename();
|
||||
String path = null;
|
||||
byte[] content = IoUtil.readBytes(file.getInputStream());
|
||||
|
||||
// 计算默认的 path 名
|
||||
String type = FileTypeUtils.getMineType(content, name);
|
||||
|
||||
StrUtil.isEmpty(path);//path = FileUtils.generatePath(content, name);
|
||||
path = userId + "_" + timestamp;
|
||||
String beginPath = name.replace(".", "_");
|
||||
path = beginPath + "_" + path + "." + FileNameUtil.extName(name);
|
||||
// 如果 name 为空,则使用 path 填充
|
||||
if (StrUtil.isEmpty(name)) {
|
||||
name = path;
|
||||
}
|
||||
|
||||
// 上传到文件存储器
|
||||
FileClient client = fileConfigService.getMasterFileClient();
|
||||
Assert.notNull(client, "客户端(master) 不能为空");
|
||||
String url = client.upload(content, path, type);
|
||||
|
||||
// 保存到数据库
|
||||
BusinessFileDO fileDo = new BusinessFileDO();
|
||||
fileDo.setConfigId(client.getId());
|
||||
fileDo.setName(name);
|
||||
fileDo.setPath(path);
|
||||
fileDo.setUrl(url);
|
||||
fileDo.setType(type);
|
||||
fileDo.setSize(content.length);
|
||||
fileDo.setUploadUserId(userId);
|
||||
fileDo.setBusinessType(businessType) ;
|
||||
businessFileMapper.insert(fileDo);
|
||||
|
||||
fileInfo[0] = name;
|
||||
fileInfo[1] = fileDo.getUrl();
|
||||
fileInfo[2] = fileDo.getType();
|
||||
return fileDo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除bpm文件
|
||||
* @param url
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void deleteBusinessFile(String url) {
|
||||
String path = url.substring(url.lastIndexOf("/") + 1);
|
||||
PageResult<BusinessFileDO> fileDOPageResult = businessFileMapper.selectPage(new FilePageReqVO().setPath(path));
|
||||
BusinessFileDO file = null;
|
||||
if (fileDOPageResult != null && fileDOPageResult.getTotal() > 0) {
|
||||
file = fileDOPageResult.getList().get(0);
|
||||
}
|
||||
if (file == null) {
|
||||
throw exception(FILE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 从文件存储器中删除
|
||||
FileClient client = fileConfigService.getFileClient(file.getConfigId());
|
||||
Assert.notNull(client, "客户端({}) 不能为空", file.getConfigId());
|
||||
client.delete(file.getPath());
|
||||
|
||||
// 删除记录
|
||||
businessFileMapper.deleteById(file.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文件的流程实例ID
|
||||
* @param reqVO
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void uploadBusinessFileProcessInstanceId(BusinessFileUploadReqVO reqVO) {
|
||||
String businessInstanceId = reqVO.getBusinessInstanceId();
|
||||
List<String> urls = reqVO.getUrls();
|
||||
LambdaUpdateWrapper<BusinessFileDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
lambdaUpdateWrapper.in(BusinessFileDO::getUrl, urls);
|
||||
lambdaUpdateWrapper.set(BusinessFileDO::getBusinessInstanceId, businessInstanceId); // 假设 bid 是要更新的 bid 值
|
||||
// 调用 MyBatis Plus 的 update 方法执行批量更新
|
||||
businessFileMapper.update(null, lambdaUpdateWrapper);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user