| | |
| | | |
| | | public static void main(String[] args) { |
| | | String projectPath = System.getProperty("user.dir"); // è·åé¡¹ç®æ ¹è·¯å¾ |
| | | String path = "basic-server"; // 模ååç§° |
| | | String table = "test"; // 表åï¼å¤ä¸ªè¡¨éå·éå¼ |
| | | String path = "ruoyi-common"; // 模ååç§° |
| | | String table = "storage_attachment"; // 表åï¼å¤ä¸ªè¡¨éå·éå¼ |
| | | |
| | | // 代ç è¾åºè·¯å¾é
ç½® |
| | | String outputBasePath = Paths.get(projectPath, path, "src", "main", "java").toString(); |
| | |
| | | // 代ç çææ ¸å¿é
ç½® |
| | | FastAutoGenerator.create(DB_URL, DB_USERNAME, DB_PASSWORD) |
| | | .globalConfig(builder -> { |
| | | builder.author("ruoyi") // ä½è
ä¿¡æ¯ |
| | | builder.author("chen") // ä½è
ä¿¡æ¯ |
| | | .outputDir(outputBasePath) // 代ç è¾åºç®å½ |
| | | .dateType(DateType.ONLY_DATE) // æ¥æç±»å |
| | | .commentDate("yyyy-MM-dd") // æ³¨éæ¥ææ ¼å¼ |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import com.ruoyi.basic.service.StorageBlobService; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import jakarta.servlet.http.HttpServletRequest; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import org.slf4j.Logger; |
| | |
| | | private ServerConfig serverConfig; |
| | | |
| | | private static final String FILE_DELIMETER = ","; |
| | | |
| | | @Autowired |
| | | private StorageBlobService storageBlobService; |
| | | |
| | | /** |
| | | * éç¨ä¸è½½è¯·æ± |
| | |
| | | } |
| | | |
| | | /** |
| | | * minioéç¨ä¸ä¼ 请æ±ï¼å¤ä¸ªï¼ |
| | | */ |
| | | @PostMapping("/minioUploads") |
| | | public R minioUploadFiles(List<MultipartFile> files, String bucketName) throws Exception |
| | | { |
| | | return R.ok(storageBlobService.updateStorageBlobs(files, bucketName)); |
| | | } |
| | | |
| | | /** |
| | | * æ¬å°èµæºéç¨ä¸è½½ |
| | | */ |
| | | @GetMapping("/download/resource") |
| | |
| | | minio: |
| | | endpoint: lunor.cn |
| | | port: 9000 |
| | | secure: false |
| | | accessKey: admin |
| | | secretKey: Admin123! |
| | | preview-expiry: 24 # é¢è§å°åé»è®¤24å°æ¶ |
| | | default-bucket: ruoyi # é»è®¤å卿¡¶ |
| | | |
| | | # 项ç®ç¸å
³é
ç½® |
| | | ruoyi: |
| | | # åç§° |
| | |
| | | component VARCHAR(255) DEFAULT NULL, |
| | | query VARCHAR(255) DEFAULT NULL, |
| | | route_name VARCHAR(50) DEFAULT '', |
| | | is_frame INTEGER DEFAULT 1, |
| | | is_cache INTEGER DEFAULT 0, |
| | | is_frame VARCHAR(10) DEFAULT 1, |
| | | is_cache VARCHAR(10) DEFAULT 0, |
| | | menu_type CHAR(1) DEFAULT '', |
| | | visible CHAR(1) DEFAULT '0', |
| | | status CHAR(1) DEFAULT '0', |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.basic.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.*; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.ruoyi.basic.entity.dto.StorageBlobDTO; |
| | | import lombok.Data; |
| | | import com.ruoyi.common.core.domain.BaseEntity; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * éç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯ å®ä½ç±» |
| | | * |
| | | * @author ruoyi |
| | | * @date 2025-05-29 |
| | | */ |
| | | @Data |
| | | @TableName("storage_attachment") |
| | | public class StorageAttachment implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Long id; |
| | | |
| | | /** å建æ¶é´ */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Date createTime; |
| | | |
| | | /** æ´æ°æ¶é´ */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private Date updateTime; |
| | | |
| | | /** |
| | | * é»è¾å é¤ |
| | | */ |
| | | @TableField(value = "deleted") |
| | | private Long deleted; |
| | | /** |
| | | * å
³èçè®°å½ç±»å |
| | | */ |
| | | @TableField(value = "record_type") |
| | | private Long recordType; |
| | | /** |
| | | * å
³èçè®°å½id |
| | | */ |
| | | @TableField(value = "record_id") |
| | | private Long recordId; |
| | | /** |
| | | * ç±»ååç§°, å¦: file, avatar (åºåå䏿¡è®°å½ä¸åç±»åçéä»¶) |
| | | */ |
| | | @TableField(value = "name") |
| | | private String name; |
| | | /** |
| | | * å
³èstorage_blobè®°å½id |
| | | */ |
| | | @TableField(value = "storage_blob_id") |
| | | private Long storageBlobId; |
| | | |
| | | private StorageBlobDTO storageBlobDTO; |
| | | |
| | | public StorageAttachment(String fileType, Long recordType, Long recordId) { |
| | | this.name = fileType; |
| | | this.recordType = recordType; |
| | | this.recordId = recordId; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.basic.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.*; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Data; |
| | | import com.ruoyi.common.core.domain.BaseEntity; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * éç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯ å®ä½ç±» |
| | | * |
| | | * @author ruoyi |
| | | * @date 2025-05-29 |
| | | */ |
| | | @Data |
| | | @TableName("storage_blob") |
| | | public class StorageBlob implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Long id; |
| | | |
| | | /** å建æ¶é´ */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | // @TableField(fill = FieldFill.INSERT) |
| | | private Date createTime; |
| | | |
| | | /** |
| | | * èµæºid |
| | | */ |
| | | @TableField(value = "key") |
| | | private String key; |
| | | /** |
| | | * èµæºç±»åï¼ä¾å¦JPGå¾ççèµæºç±»å为image/jpg |
| | | */ |
| | | @TableField(value = "content_type") |
| | | private String contentType; |
| | | /** |
| | | * åæä»¶å |
| | | */ |
| | | @TableField(value = "original_filename") |
| | | private String originalFilename; |
| | | |
| | | /** |
| | | * å卿¡¶ä¸ |
| | | */ |
| | | @TableField(value = "bucket_filename") |
| | | private String bucketFilename; |
| | | /** |
| | | * å卿¡¶å |
| | | */ |
| | | @TableField(value = "bucket_name") |
| | | private String bucketName; |
| | | /** |
| | | * èµæºå°ºå¯¸(åè) |
| | | */ |
| | | @TableField(value = "byte_size") |
| | | private Long byteSize; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.basic.entity.dto; |
| | | |
| | | import com.ruoyi.basic.entity.StorageBlob; |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class StorageBlobDTO extends StorageBlob { |
| | | private String url; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.basic.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.ruoyi.basic.entity.StorageAttachment; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * <p> |
| | | * éç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯ Mapper æ¥å£ |
| | | * </p> |
| | | * |
| | | * @author ruoyi |
| | | * @since 2025-05-29 |
| | | */ |
| | | @Mapper |
| | | public interface StorageAttachmentMapper extends BaseMapper<StorageAttachment> { |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.basic.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.ruoyi.basic.entity.StorageBlob; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * <p> |
| | | * éç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯ Mapper æ¥å£ |
| | | * </p> |
| | | * |
| | | * @author ruoyi |
| | | * @since 2025-05-29 |
| | | */ |
| | | @Mapper |
| | | public interface StorageBlobMapper extends BaseMapper<StorageBlob> { |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.basic.service; |
| | | |
| | | import com.ruoyi.basic.entity.StorageAttachment; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.ruoyi.common.constant.StorageAttachmentConstants; |
| | | import com.ruoyi.common.enums.StorageAttachmentRecordType; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | | * éç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯ æå¡ç±» |
| | | * </p> |
| | | * |
| | | * @author ruoyi |
| | | * @since 2025-05-29 |
| | | */ |
| | | public interface StorageAttachmentService extends IService<StorageAttachment> { |
| | | /** |
| | | * æ¥è¯¢éç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯ |
| | | * @param recordId å
³èè®°å½id |
| | | * @param recordType å
³èè®°å½ç±»å |
| | | * @param fileType æä»¶ç±»å |
| | | * @return æä»¶ä¿¡æ¯å表 |
| | | */ |
| | | List<StorageAttachment> selectStorageAttachments(Long recordId, StorageAttachmentRecordType recordType, StorageAttachmentConstants fileType); |
| | | |
| | | /** |
| | | * ä¿åéç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯ |
| | | * @param attachments æä»¶ä¿¡æ¯å表 |
| | | * @param recordId 管çè®°å½id |
| | | * @param recordType å
³èè®°å½ç±»å |
| | | * @param fileType æä»¶ç±»å |
| | | */ |
| | | public void saveStorageAttachment(List<StorageAttachment> attachments, Long recordId, StorageAttachmentRecordType recordType, StorageAttachmentConstants fileType); |
| | | |
| | | /** |
| | | * å é¤éç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯ |
| | | * @param storageAttachment æä»¶ä¿¡æ¯ |
| | | * @return å é¤ç»æ |
| | | */ |
| | | public int deleteStorageAttachment(StorageAttachment storageAttachment); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.basic.service; |
| | | |
| | | import com.ruoyi.basic.entity.StorageAttachment; |
| | | import com.ruoyi.basic.entity.StorageBlob; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.ruoyi.basic.entity.dto.StorageBlobDTO; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | | * éç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯ æå¡ç±» |
| | | * </p> |
| | | * |
| | | * @author ruoyi |
| | | * @since 2025-05-29 |
| | | */ |
| | | public interface StorageBlobService extends IService<StorageBlob> { |
| | | |
| | | /** |
| | | * æä»¶ä¸ä¼ æ¥å£ |
| | | * @param files æä»¶ä¿¡æ¯ |
| | | * @param bucketName å卿¡¶åç§° |
| | | * @return ä¸ä¼ ç»æ |
| | | */ |
| | | List<StorageBlobDTO> updateStorageBlobs(List<MultipartFile> files, String bucketName); |
| | | |
| | | /** |
| | | * æ¹éå 餿件 |
| | | * @param attachment |
| | | * @return |
| | | */ |
| | | public int deleteStorageBlobs(StorageAttachment attachment); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.basic.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.basic.entity.StorageAttachment; |
| | | import com.ruoyi.basic.entity.StorageBlob; |
| | | import com.ruoyi.basic.entity.dto.StorageBlobDTO; |
| | | import com.ruoyi.basic.mapper.StorageAttachmentMapper; |
| | | import com.ruoyi.basic.mapper.StorageBlobMapper; |
| | | import com.ruoyi.basic.service.StorageAttachmentService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.service.StorageBlobService; |
| | | import com.ruoyi.common.constant.StorageAttachmentConstants; |
| | | import com.ruoyi.common.enums.StorageAttachmentRecordType; |
| | | import com.ruoyi.common.utils.file.MinioUtils; |
| | | import io.minio.MinioClient; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import lombok.RequiredArgsConstructor; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | | * éç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯ æå¡å®ç°ç±» |
| | | * </p> |
| | | * |
| | | * @author ruoyi |
| | | * @since 2025-05-29 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class StorageAttachmentServiceImpl extends ServiceImpl<StorageAttachmentMapper, StorageAttachment> implements StorageAttachmentService { |
| | | @Autowired |
| | | private StorageBlobMapper storageBlobMapper; |
| | | |
| | | @Autowired |
| | | private StorageAttachmentMapper storageAttachmentMapper; |
| | | |
| | | @Autowired |
| | | private StorageBlobService storageBlobService; |
| | | |
| | | @Autowired |
| | | private MinioUtils minioUtils; |
| | | |
| | | @Override |
| | | public List<StorageAttachment> selectStorageAttachments(Long recordId, StorageAttachmentRecordType recordType, StorageAttachmentConstants fileType) { |
| | | List<StorageAttachment> storageAttachments = storageAttachmentMapper.selectList(new LambdaQueryWrapper<StorageAttachment>() |
| | | .eq(StorageAttachment::getRecordId, recordId) |
| | | .eq(StorageAttachment::getRecordType, recordType.ordinal()) |
| | | .eq(StorageAttachment::getName, fileType.toString())); |
| | | if (storageAttachments != null) { |
| | | for (StorageAttachment storageAttachment : storageAttachments) { |
| | | StorageBlob storageBlob = storageBlobMapper.selectById(storageAttachment.getStorageBlobId()); |
| | | StorageBlobDTO storageBlobDTO = new StorageBlobDTO(); |
| | | BeanUtils.copyProperties(storageBlob, storageBlobDTO); |
| | | storageBlobDTO.setUrl(minioUtils.getPreviewUrl(storageBlob.getBucketName(), storageBlob.getBucketName(), true)); |
| | | storageAttachment.setStorageBlobDTO(storageBlobDTO); |
| | | } |
| | | } |
| | | |
| | | return storageAttachments; |
| | | } |
| | | |
| | | @Override |
| | | public void saveStorageAttachment(List<StorageAttachment> attachments, Long recordId, StorageAttachmentRecordType recordType, StorageAttachmentConstants fileType) { |
| | | // å 餿§å¾ |
| | | deleteStorageAttachment(new StorageAttachment(fileType.toString(), (long) recordType.ordinal(), recordId)); |
| | | for (StorageAttachment attachment : attachments) { |
| | | // è·åå
³èè®°å½ |
| | | StorageBlob storageBlob = attachment.getStorageBlobDTO(); |
| | | attachment.setName(fileType.toString()); |
| | | attachment.setRecordType((long) recordType.ordinal()); |
| | | attachment.setRecordId(recordId); |
| | | attachment.setStorageBlobId(storageBlob.getId()); |
| | | storageAttachmentMapper.insert(attachment); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public int deleteStorageAttachment(StorageAttachment storageAttachment) { |
| | | // å
å 餿ç»è¡¨ |
| | | storageBlobService.deleteStorageBlobs(storageAttachment); |
| | | |
| | | |
| | | return storageAttachmentMapper.delete(new LambdaQueryWrapper<StorageAttachment>() |
| | | .eq(StorageAttachment::getRecordId, storageAttachment.getRecordId()) |
| | | .eq(StorageAttachment::getRecordType, storageAttachment.getRecordType()) |
| | | .eq(StorageAttachment::getName, storageAttachment.getName())); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.basic.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.basic.entity.StorageAttachment; |
| | | import com.ruoyi.basic.entity.StorageBlob; |
| | | import com.ruoyi.basic.entity.dto.StorageBlobDTO; |
| | | import com.ruoyi.basic.mapper.StorageAttachmentMapper; |
| | | import com.ruoyi.basic.mapper.StorageBlobMapper; |
| | | import com.ruoyi.basic.service.StorageBlobService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.config.MinioConfig; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.MinioResult; |
| | | import com.ruoyi.common.exception.file.InvalidExtensionException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.file.MinioUtils; |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | | * éç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯ æå¡å®ç°ç±» |
| | | * </p> |
| | | * |
| | | * @author ruoyi |
| | | * @since 2025-05-29 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class StorageBlobServiceImpl extends ServiceImpl<StorageBlobMapper, StorageBlob> implements StorageBlobService { |
| | | @Autowired |
| | | private StorageAttachmentMapper storageAttachmentMapper; |
| | | |
| | | @Autowired |
| | | private StorageBlobMapper storageBlobMapper; |
| | | |
| | | @Autowired |
| | | private MinioUtils minioUtils; |
| | | |
| | | @Override |
| | | public List<StorageBlobDTO> updateStorageBlobs(List<MultipartFile> files, String bucketName) { |
| | | |
| | | // è¥æ²¡ä¼ å
¥bucketNameï¼å使ç¨é»è®¤bucketName |
| | | if (StringUtils.isEmpty(bucketName)) { |
| | | bucketName = minioUtils.getDefaultBucket(); |
| | | } |
| | | |
| | | List<StorageBlobDTO> storageBlobDTOs = new ArrayList<>(); |
| | | for (MultipartFile file : files) { |
| | | try { |
| | | MinioResult res = minioUtils.upload(bucketName, file, false); |
| | | StorageBlobDTO dto = new StorageBlobDTO(); |
| | | dto.setContentType(file.getContentType()); |
| | | dto.setBucketFilename(res.getBucketFileName()); |
| | | dto.setOriginalFilename(res.getOriginalName()); |
| | | dto.setByteSize(file.getSize()); |
| | | dto.setKey(IdUtils.simpleUUID()); |
| | | dto.setBucketName(bucketName); |
| | | dto.setCreateTime(DateUtils.getNowDate()); |
| | | dto.setUrl(minioUtils.getPreviewUrl(res.getBucketFileName(), bucketName, false)); |
| | | // æå
¥æ°æ®åº |
| | | storageBlobMapper.insert(dto); |
| | | |
| | | storageBlobDTOs.add(dto); |
| | | } catch (InvalidExtensionException e) { |
| | | throw new RuntimeException("minioæä»¶ä¸ä¼ å¼å¸¸ï¼" + e); |
| | | } |
| | | } |
| | | |
| | | |
| | | return storageBlobDTOs; |
| | | } |
| | | |
| | | @Override |
| | | public int deleteStorageBlobs(StorageAttachment attachment) { |
| | | List<StorageAttachment> attachments = storageAttachmentMapper.selectList(new LambdaQueryWrapper<StorageAttachment>() |
| | | .eq(StorageAttachment::getRecordId, attachment.getRecordId()) |
| | | .eq(StorageAttachment::getRecordType, attachment.getRecordType()) |
| | | .eq(StorageAttachment::getName, attachment.getName())); |
| | | List<Long> ids = attachments.stream().map(StorageAttachment::getStorageBlobId).toList(); |
| | | List<StorageBlob> storageBlobs = storageBlobMapper.selectList(new LambdaQueryWrapper<StorageBlob>() |
| | | .in(StorageBlob::getId, ids)); |
| | | if (!storageBlobs.isEmpty()) { |
| | | for (StorageBlob storageBlob : storageBlobs) { |
| | | // ç§»é¤æ¡¶å
æä»¶ |
| | | minioUtils.removeObjectsResult(storageBlob.getBucketName(), storageBlob.getBucketName()); |
| | | } |
| | | } |
| | | |
| | | if (!ids.isEmpty()) { |
| | | return storageBlobMapper.delete(new QueryWrapper<StorageBlob>().lambda().in(StorageBlob::getId, ids)); |
| | | } |
| | | |
| | | return 0; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.constant; |
| | | |
| | | /** |
| | | * é件常é |
| | | */ |
| | | public class StorageAttachmentConstants { |
| | | |
| | | /** |
| | | * æä»¶ |
| | | */ |
| | | public static final String StorageAttachmentFile = "file"; |
| | | |
| | | /** |
| | | * å¾ç |
| | | */ |
| | | public static final String StorageAttachmentImage = "image"; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.handler; |
| | | |
| | | import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; |
| | | import org.apache.ibatis.reflection.MetaObject; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.time.LocalDateTime; |
| | | |
| | | /** |
| | | * @Author: zhangxy |
| | | * @Date: 2020-08-05 14:40 |
| | | */ |
| | | @Component |
| | | public class MyMetaObjectHandler implements MetaObjectHandler { |
| | | |
| | | |
| | | @Override |
| | | public void insertFill(MetaObject metaObject) { |
| | | this.setFieldValByName("createTime", LocalDateTime.now(), metaObject); |
| | | this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject); |
| | | // å¼çº¿ç¨ï¼åä¸å°user |
| | | try { |
| | | // SysUser currentUser = SecurityUtils.getLoginUser(); |
| | | // if (currentUser != null) { |
| | | // this.setFieldValByName("createUser", currentUser.getUsername(), metaObject); |
| | | // this.setFieldValByName("updateUser", currentUser.getUsername(), metaObject); |
| | | // } |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void updateFill(MetaObject metaObject) { |
| | | this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject); |
| | | try { |
| | | // ZttUser currentUser = SecurityUtils.getUser(); |
| | | // if (currentUser != null) { |
| | | // this.setFieldValByName("updateUser", currentUser.getUsername(), metaObject); |
| | | // } |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } |
| | |
| | | import io.minio.http.Method; |
| | | import io.minio.messages.DeleteError; |
| | | import io.minio.messages.DeleteObject; |
| | | import lombok.Getter; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | |
| | | @Value("${minio.preview-expiry}") |
| | | private Integer previewExpiry; |
| | | |
| | | /** |
| | | * -- GETTER -- |
| | | * è·åé»è®¤å卿¡¶åç§° |
| | | * |
| | | * @return |
| | | */ |
| | | @Getter |
| | | @Value("${minio.default-bucket}") |
| | | private String defaultBucket; |
| | | |
| | | /** |
| | | * 夿å卿¡¶æ¯å¦åå¨ï¼ä¸åå¨åå建 |
| | |
| | | .build() |
| | | ); |
| | | } catch (Exception e) { |
| | | throw new UtilException("MinioUtilsï¼ä¸ä¼ æä»¶å·¥å
·ç±»å¼å¸¸"); |
| | | throw new UtilException("MinioUtilsï¼ä¸ä¼ æä»¶å·¥å
·ç±»å¼å¸¸:" + e); |
| | | } |
| | | MinioResult minioResult = new MinioResult(); |
| | | minioResult.setBucketFileName(bucketFilePath); |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | CREATE TABLE storage_blob |
| | | ( |
| | | id bigserial PRIMARY KEY, |
| | | created_at timestamp default now() NOT NULL, |
| | | key varchar(150) DEFAULT '' NOT NULL, |
| | | content_type varchar(100) DEFAULT '' NOT NULL, |
| | | filename varchar(255) DEFAULT '' NOT NULL, |
| | | byte_size bigint DEFAULT 0 NOT NULL, |
| | | id bigserial PRIMARY KEY, |
| | | create_time timestamp default now() NOT NULL, |
| | | key varchar(150) DEFAULT '' NOT NULL, |
| | | content_type varchar(100) DEFAULT '' NOT NULL, |
| | | original_filename varchar(255) DEFAULT '' NOT NULL, |
| | | bucket_filename varchar(255) DEFAULT '' NOT NULL, |
| | | bucket_name varchar(255) DEFAULT '' NOT NULL, |
| | | byte_size bigint DEFAULT 0 NOT NULL, |
| | | UNIQUE (key) |
| | | ); |
| | | |
| | |
| | | |
| | | COMMENT ON COLUMN storage_blob.key IS 'èµæºid'; |
| | | COMMENT ON COLUMN storage_blob.content_type IS 'èµæºç±»åï¼ä¾å¦JPGå¾ççèµæºç±»å为image/jpg'; |
| | | COMMENT ON COLUMN storage_blob.filename IS 'æä»¶å'; |
| | | COMMENT ON COLUMN storage_blob.original_filename IS 'åæä»¶åç§°'; |
| | | COMMENT ON COLUMN storage_blob.bucket_filename IS 'å卿¡¶ä¸æä»¶å'; |
| | | COMMENT ON COLUMN storage_blob.bucket_name IS 'å卿¡¶å'; |
| | | COMMENT ON COLUMN storage_blob.byte_size IS 'èµæºå°ºå¯¸(åè)'; |
| | | |
| | |
| | | -- é件表 |
| | | -- ---------------------------- |
| | | drop table if exists storage_attachment; |
| | | CREATE TABLE storage_attachments |
| | | CREATE TABLE storage_attachment |
| | | ( |
| | | id bigserial PRIMARY KEY, |
| | | created_at timestamp default now() NOT NULL, |
| | | updated_at timestamp default now() NOT NULL, |
| | | deleted_at bigint DEFAULT 0 NOT NULL, |
| | | create_time timestamp default now() NOT NULL, |
| | | update_time timestamp default now() NOT NULL, |
| | | deleted bigint DEFAULT 0 NOT NULL, |
| | | record_type smallint DEFAULT 0 NOT NULL, |
| | | record_id bigint DEFAULT 0 NOT NULL, |
| | | name varchar(100) DEFAULT '' NOT NULL, |
| | | storage_blob_id bigint DEFAULT 0 NOT NULL |
| | | ); |
| | | |
| | | COMMENT ON TABLE storage_attachments IS 'éç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯'; |
| | | COMMENT ON TABLE storage_attachment IS 'éç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯'; |
| | | |
| | | COMMENT ON COLUMN storage_attachments.record_type IS 'å
³èçè®°å½ç±»å'; |
| | | COMMENT ON COLUMN storage_attachments.record_id IS 'å
³èçè®°å½id'; |
| | | COMMENT ON COLUMN storage_attachments.name IS 'åç§°, å¦: file, avatar (åºåå䏿¡è®°å½ä¸åç±»åçéä»¶)'; |
| | | COMMENT ON COLUMN storage_attachments.storage_blob_id IS 'å
³èstorage_blobè®°å½id'; |
| | | COMMENT ON COLUMN storage_attachment.record_type IS 'å
³èçè®°å½ç±»å'; |
| | | COMMENT ON COLUMN storage_attachment.record_id IS 'å
³èçè®°å½id'; |
| | | COMMENT ON COLUMN storage_attachment.name IS 'åç§°, å¦: file, avatar (åºåå䏿¡è®°å½ä¸åç±»åçéä»¶)'; |
| | | COMMENT ON COLUMN storage_attachment.storage_blob_id IS 'å
³èstorage_blobè®°å½id'; |
| | | |
| | | CREATE INDEX idx_storage_attachments_on_record |
| | | ON storage_attachments (record_type, record_id); |
| | | CREATE INDEX idx_storage_attachment_on_record |
| | | ON storage_attachment (record_type, record_id); |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.ruoyi.basic.mapper.StorageAttachmentMapper"> |
| | | |
| | | <!-- éç¨æ¥è¯¢æ å°ç»æ --> |
| | | <resultMap id="BaseResultMap" type="com.ruoyi.basic.entity.StorageAttachment"> |
| | | <id column="id" property="id" /> |
| | | <result column="create_time" property="createTime" /> |
| | | <result column="update_time" property="updateTime" /> |
| | | <result column="deleted" property="deleted" /> |
| | | <result column="record_type" property="recordType" /> |
| | | <result column="record_id" property="recordId" /> |
| | | <result column="name" property="name" /> |
| | | <result column="storage_blob_id" property="storageBlobId" /> |
| | | </resultMap> |
| | | |
| | | <!-- éç¨æ¥è¯¢ç»æå --> |
| | | <sql id="Base_Column_List"> |
| | | id, create_time, update_time, deleted, record_type, record_id, name, storage_blob_id |
| | | </sql> |
| | | |
| | | </mapper> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.ruoyi.basic.mapper.StorageBlobMapper"> |
| | | |
| | | <!-- éç¨æ¥è¯¢æ å°ç»æ --> |
| | | <resultMap id="BaseResultMap" type="com.ruoyi.basic.entity.StorageBlob"> |
| | | <id column="id" property="id" /> |
| | | <result column="create_time" property="createTime" /> |
| | | <result column="key" property="key" /> |
| | | <result column="content_type" property="contentType" /> |
| | | <result column="original_filename" property="originalFilename" /> |
| | | <result column="bucket_filename" property="bucketFilename" /> |
| | | <result column="bucket_name" property="bucketName" /> |
| | | <result column="byte_size" property="byteSize" /> |
| | | </resultMap> |
| | | |
| | | <!-- éç¨æ¥è¯¢ç»æå --> |
| | | <sql id="Base_Column_List"> |
| | | id, create_time, key, content_type, original_filename,bucket_filename,bucket_name, byte_size |
| | | </sql> |
| | | |
| | | </mapper> |
| | |
| | | </select> |
| | | |
| | | <select id="selectMenuTreeAll" resultMap="SysMenuResult"> |
| | | select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m."query", m.route_name, m.visible, m.status, COALESCE(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time |
| | | from sys_menu m where m.menu_type in ('M', 'C') and m.status = 0 |
| | | select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.query, m.route_name, m.visible, m.status, COALESCE(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time |
| | | from sys_menu m where m.menu_type in ('M', 'C') and m.status = '0' |
| | | order by m.parent_id, m.order_num |
| | | </select> |
| | | |
| | | <select id="selectMenuListByUserId" parameterType="SysMenu" resultMap="SysMenuResult"> |
| | | select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m."query", m.route_name, m.visible, m.status, COALESCE(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time |
| | | select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.query, m.route_name, m.visible, m.status, COALESCE(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time |
| | | from sys_menu m |
| | | left join sys_role_menu rm on m.menu_id = rm.menu_id |
| | | left join sys_user_role ur on rm.role_id = ur.role_id |
| | |
| | | </select> |
| | | |
| | | <select id="selectMenuTreeByUserId" parameterType="Long" resultMap="SysMenuResult"> |
| | | select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m."query", m.route_name, m.visible, m.status, COALESCE(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time |
| | | select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.query, m.route_name, m.visible, m.status, COALESCE(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time |
| | | from sys_menu m |
| | | left join sys_role_menu rm on m.menu_id = rm.menu_id |
| | | left join sys_user_role ur on rm.role_id = ur.role_id |
| | | left join sys_role ro on ur.role_id = ro.role_id |
| | | left join sys_user u on ur.user_id = u.user_id |
| | | where u.user_id = #{userId} and m.menu_type in ('M', 'C') and m.status = 0 AND ro.status = 0 |
| | | where u.user_id = #{userId} and m.menu_type in ('M', 'C') and m.status = '0' AND ro.status = '0' |
| | | order by m.parent_id, m.order_num |
| | | </select> |
| | | |