| | |
| | | import io.swagger.annotations.Api; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | | import org.springblade.common.utils.ImageUtils; |
| | | import org.springblade.core.launch.constant.AppConstant; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.core.oss.model.OssFile; |
| | |
| | | import org.springblade.core.tool.constant.RoleConstant; |
| | | import org.springblade.core.tool.utils.FileUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.ImageUtil; |
| | | import org.springblade.modules.resource.builder.oss.OssBuilder; |
| | | import org.springblade.modules.resource.entity.Attach; |
| | | import org.springblade.modules.resource.entity.AttachData; |
| | | import org.springblade.modules.resource.service.IAttachDataService; |
| | | import org.springblade.modules.resource.service.IAttachService; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | * 附件表服务 |
| | | */ |
| | | private final IAttachService attachService; |
| | | |
| | | /** |
| | | * 附件数据表服务 |
| | | */ |
| | | private final IAttachDataService attachDataService; |
| | | |
| | | /** |
| | | * 创建存储桶 |
| | |
| | | String fileName = file.getOriginalFilename(); |
| | | BladeFile bladeFile = ossBuilder.templateByPrefixPath(prefixPath).putFile(file.getOriginalFilename(), file.getInputStream()); |
| | | Long attachId = buildAttach(fileName, file.getSize(), bladeFile); |
| | | buildAttachData(attachId,fileName, file.getSize(), bladeFile,file); |
| | | bladeFile.setAttachId(attachId); |
| | | // 修改link |
| | | changeLink(bladeFile); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 构建附件数据表 |
| | | * |
| | | * @param attachId 附件id |
| | | * @param fileName 文件名 |
| | | * @param fileSize 文件大小 |
| | | * @param bladeFile 对象存储文件 |
| | | * @return attachId |
| | | */ |
| | | private Long buildAttachData(Long attachId,String fileName, Long fileSize, BladeFile bladeFile,MultipartFile file) { |
| | | String fileExtension = FileUtil.getFileExtension(fileName); |
| | | AttachData attach = new AttachData(); |
| | | attach.setAttachId(attachId); |
| | | attach.setName(bladeFile.getName()); |
| | | attach.setOriginalName(bladeFile.getOriginalName()); |
| | | attach.setSize(fileSize); |
| | | attach.setExtension(fileExtension); |
| | | attach.setData(ImageUtils.mulToBase64(file)); |
| | | attachDataService.save(attach); |
| | | return attach.getId(); |
| | | } |
| | | |
| | | /** |
| | | * 删除文件 |
| | | * |
| | | * @param fileName 存储桶对象名称 |