Merge branch 'master' of http://114.132.189.42:9002/r/zd-after into li
| | |
| | | <postgresql.version>42.7.3</postgresql.version> |
| | | <mybatis-plus.version>3.5.12</mybatis-plus.version> |
| | | <freemarker.version>2.3.30</freemarker.version> |
| | | <minio.version>8.4.3</minio.version> |
| | | <okhttp.version>4.9.0</okhttp.version> |
| | | </properties> |
| | | |
| | | <!-- ä¾èµå£°æ --> |
| | |
| | | <artifactId>pagehelper-spring-boot-starter</artifactId> |
| | | <version>${pagehelper.boot.version}</version> |
| | | </dependency> |
| | | |
| | | |
| | | <dependency> |
| | | <groupId>com.mysql</groupId> |
| | | <artifactId>mysql-connector-j</artifactId> |
| | |
| | | <version>${postgresql.version}</version> |
| | | </dependency> |
| | | |
| | | <!-- minio --> |
| | | <dependency> |
| | | <groupId>io.minio</groupId> |
| | | <artifactId>minio</artifactId> |
| | | <version>${minio.version}</version> |
| | | <exclusions> |
| | | <exclusion> |
| | | <groupId>com.squareup.okhttp3</groupId> |
| | | <artifactId>okhttp</artifactId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | |
| | | <!-- minioä¾èµokhttp ä¸ç¶æ¥é --> |
| | | <dependency> |
| | | <groupId>com.squareup.okhttp3</groupId> |
| | | <artifactId>okhttp</artifactId> |
| | | <version>${okhttp.version}</version> |
| | | </dependency> |
| | | |
| | | <!--åºç¡æ¨¡å--> |
| | | <dependency> |
| | | <groupId>com.ruoyi</groupId> |
| | |
| | | <version>2.3</version> |
| | | </dependency> |
| | | |
| | | <!-- minioä¾èµokhttp ä¸ç¶æ¥é --> |
| | | <dependency> |
| | | <groupId>com.squareup.okhttp3</groupId> |
| | | <artifactId>okhttp</artifactId> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | |
| | | 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 INTEGER DEFAULT 0, |
| | |
| | | <version>3.5.12</version> |
| | | </dependency> |
| | | |
| | | <!-- minio --> |
| | | <dependency> |
| | | <groupId>io.minio</groupId> |
| | | <artifactId>minio</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- minioä¾èµokhttp ä¸ç¶æ¥é --> |
| | | <dependency> |
| | | <groupId>com.squareup.okhttp3</groupId> |
| | | <artifactId>okhttp</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.projectlombok</groupId> |
| | | <artifactId>lombok</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-web</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.projectlombok</groupId> |
| | | <artifactId>lombok</artifactId> |
| | | </dependency> |
| | | |
| | | |
| | | </dependencies> |
| | | |
| | | </project> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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.config; |
| | | |
| | | import io.minio.MinioClient; |
| | | import lombok.Data; |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | @Configuration |
| | | @Component |
| | | @ConfigurationProperties(prefix = "minio") |
| | | @Data |
| | | public class MinioConfig { |
| | | private String endpoint; |
| | | private int port; |
| | | private String accessKey; |
| | | private String secretKey; |
| | | private Boolean secure; |
| | | |
| | | @Bean |
| | | public MinioClient getMinioClient() { |
| | | return MinioClient.builder().endpoint(endpoint, port, secure) |
| | | .credentials(accessKey, secretKey) |
| | | .build(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.constant; |
| | | |
| | | /** |
| | | * é件常é |
| | | */ |
| | | public class StorageAttachmentConstants { |
| | | |
| | | /** |
| | | * æä»¶ |
| | | */ |
| | | public static final String StorageAttachmentFile = "file"; |
| | | |
| | | /** |
| | | * å¾ç |
| | | */ |
| | | public static final String StorageAttachmentImage = "image"; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.core.domain; |
| | | |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class MinioResult { |
| | | // minioä¸çæä»¶åç§° |
| | | private String bucketFileName; |
| | | |
| | | // æºæä»¶åç§° |
| | | private String originalName; |
| | | |
| | | // é¢è§è·¯å¾ |
| | | private String previewExpiry; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.enums; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | |
| | | /** |
| | | * éä»¶è®°å½ç±»åæä¸¾ |
| | | * |
| | | */ |
| | | @AllArgsConstructor |
| | | public enum StorageAttachmentRecordType { |
| | | // ä¾å å®é
å¼å请å é¤ |
| | | Template("Template","èä¾"); |
| | | |
| | | |
| | | private final String code; |
| | | private final String info; |
| | | |
| | | public String getCode() { |
| | | return code; |
| | | } |
| | | |
| | | public String getInfo() { |
| | | return info; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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) { |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.utils.file; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.ruoyi.common.core.domain.MinioResult; |
| | | import com.ruoyi.common.exception.UtilException; |
| | | import com.ruoyi.common.exception.file.InvalidExtensionException; |
| | | import io.minio.*; |
| | | 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; |
| | | import org.springframework.util.FastByteArrayOutputStream; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import jakarta.servlet.ServletOutputStream; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import java.io.InputStream; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Component |
| | | public class MinioUtils { |
| | | @Autowired |
| | | private MinioClient minioClient; |
| | | |
| | | @Value("${minio.preview-expiry}") |
| | | private Integer previewExpiry; |
| | | |
| | | /** |
| | | * -- GETTER -- |
| | | * è·åé»è®¤å卿¡¶åç§° |
| | | * |
| | | * @return |
| | | */ |
| | | @Getter |
| | | @Value("${minio.default-bucket}") |
| | | private String defaultBucket; |
| | | |
| | | /** |
| | | * 夿å卿¡¶æ¯å¦åå¨ï¼ä¸åå¨åå建 |
| | | * |
| | | * @param bucketName å卿¡¶åç§° |
| | | */ |
| | | public void existBucket(String bucketName) { |
| | | try { |
| | | boolean exists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build()); |
| | | if (!exists) { |
| | | minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build()); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å建å卿¡¶ |
| | | * |
| | | * @param bucketName å卿¡¶åç§° |
| | | * @return æ¯å¦å建æå |
| | | */ |
| | | public Boolean makeBucket(String bucketName) { |
| | | try { |
| | | minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * å é¤å卿¡¶ |
| | | * |
| | | * @param bucketName å卿¡¶åç§° |
| | | * @return æ¯å¦å 餿å |
| | | */ |
| | | public Boolean removeBucket(String bucketName) { |
| | | try { |
| | | minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * å¤æå¯¹è±¡æ¯å¦åå¨ |
| | | * |
| | | * @param bucketName å卿¡¶åç§° |
| | | * @param originalFileName MinIOä¸åå¨å¯¹è±¡å
¨è·¯å¾ |
| | | * @return 对象æ¯å¦åå¨ |
| | | */ |
| | | public boolean existObject(String bucketName, String originalFileName) { |
| | | try { |
| | | minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(originalFileName).build()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * æä»¶ä¸ä¼ |
| | | * |
| | | * @param bucketName å卿¡¶åç§° |
| | | * @param file æä»¶ |
| | | * @return æ¡¶ä¸ä½ç½® |
| | | */ |
| | | public MinioResult upload(String bucketName, MultipartFile file, Boolean isPreviewExpiry) throws InvalidExtensionException { |
| | | MultipartFile[] fileArr = {file}; |
| | | List<MinioResult> fileNames = upload(bucketName, fileArr, isPreviewExpiry); |
| | | return fileNames.isEmpty() ? null : fileNames.get(0); |
| | | } |
| | | |
| | | /** |
| | | * ä¸ä¼ æä»¶ |
| | | * |
| | | * @param bucketName å卿¡¶åç§° |
| | | * @param fileList æä»¶å表 |
| | | * @return æ¡¶ä¸ä½ç½®å表 |
| | | */ |
| | | public List<MinioResult> upload(String bucketName, List<MultipartFile> fileList, Boolean isPreviewExpiry) throws InvalidExtensionException { |
| | | MultipartFile[] fileArr = fileList.toArray(new MultipartFile[0]); |
| | | return upload(bucketName, fileArr, isPreviewExpiry); |
| | | } |
| | | |
| | | /** |
| | | * description: ä¸ä¼ æä»¶ |
| | | * |
| | | * @param bucketName å卿¡¶åç§° |
| | | * @param fileArr æä»¶å表 |
| | | * @return æ¡¶ä¸ä½ç½®å表 |
| | | */ |
| | | public List<MinioResult> upload(String bucketName, MultipartFile[] fileArr, Boolean isPreviewExpiry) throws InvalidExtensionException { |
| | | for (MultipartFile file : fileArr) { |
| | | FileUploadUtils.assertAllowed(file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); |
| | | } |
| | | // ä¿è¯æ¡¶ä¸å®åå¨ |
| | | existBucket(bucketName); |
| | | // æ§è¡æ£å¸¸æä½ |
| | | List<MinioResult> bucketFileNames = new ArrayList<>(fileArr.length); |
| | | for (MultipartFile file : fileArr) { |
| | | // è·ååå§æä»¶åç§° |
| | | String originalFileName = file.getOriginalFilename(); |
| | | // è·åå½åæ¥æï¼æ ¼å¼ä¾å¦ï¼2020-11 |
| | | String datePath = new SimpleDateFormat("yyyy-MM").format(new Date()); |
| | | // æä»¶åç§° |
| | | String uuid = IdWorker.get32UUID(); |
| | | // è·åæä»¶åç¼ |
| | | String suffix = originalFileName.substring(originalFileName.lastIndexOf(".")); |
| | | String bucketFilePath = datePath + "/" + uuid + suffix; |
| | | |
| | | // æ¨éæä»¶å°MinIO |
| | | try (InputStream in = file.getInputStream()) { |
| | | minioClient.putObject(PutObjectArgs.builder() |
| | | .bucket(bucketName) |
| | | .object(bucketFilePath) |
| | | .stream(in, in.available(), -1) |
| | | .contentType(file.getContentType()) |
| | | .build() |
| | | ); |
| | | } catch (Exception e) { |
| | | throw new UtilException("MinioUtilsï¼ä¸ä¼ æä»¶å·¥å
·ç±»å¼å¸¸:" + e); |
| | | } |
| | | MinioResult minioResult = new MinioResult(); |
| | | minioResult.setBucketFileName(bucketFilePath); |
| | | // è¿åæ°¸ä¹
é¢è§å°å |
| | | if (isPreviewExpiry) { |
| | | String previewUrl = getPreviewUrl(bucketFilePath, bucketName, isPreviewExpiry); |
| | | minioResult.setPreviewExpiry(previewUrl); |
| | | } |
| | | minioResult.setOriginalName(originalFileName); |
| | | bucketFileNames.add(minioResult); |
| | | } |
| | | return bucketFileNames; |
| | | } |
| | | |
| | | /** |
| | | * æä»¶ä¸è½½ |
| | | * |
| | | * @param bucketName å卿¡¶åç§° |
| | | * @param bucketFileName æ¡¶ä¸æä»¶åç§° |
| | | * @param originalFileName åå§æä»¶åç§° |
| | | * @param response response对象 |
| | | */ |
| | | public void download(String bucketName, String bucketFileName, String originalFileName, HttpServletResponse response) { |
| | | GetObjectArgs objectArgs = GetObjectArgs.builder().bucket(bucketName).object(bucketFileName).build(); |
| | | try (GetObjectResponse objResponse = minioClient.getObject(objectArgs)) { |
| | | byte[] buf = new byte[1024]; |
| | | int len; |
| | | try (FastByteArrayOutputStream os = new FastByteArrayOutputStream()) { |
| | | while ((len = objResponse.read(buf)) != -1) { |
| | | os.write(buf, 0, len); |
| | | } |
| | | os.flush(); |
| | | byte[] bytes = os.toByteArray(); |
| | | response.setCharacterEncoding("utf-8"); |
| | | //设置强å¶ä¸è½½ä¸æå¼ |
| | | response.setContentType("application/force-download"); |
| | | // 设置éä»¶åç§°ç¼ç |
| | | originalFileName = new String(originalFileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1); |
| | | // 设置éä»¶åç§° |
| | | response.addHeader("Content-Disposition", "attachment;fileName=" + originalFileName); |
| | | // åå
¥æä»¶ |
| | | try (ServletOutputStream stream = response.getOutputStream()) { |
| | | stream.write(bytes); |
| | | stream.flush(); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | throw new UtilException("MinioUtilsï¼ä¸ä¼ æä»¶å·¥å
·ç±»å¼å¸¸"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åå·²ä¸ä¼ 对象çæä»¶æµï¼å端å 为ä¸å¡éè¦è·åæä»¶æµå¯ä»¥è°ç¨è¯¥æ¹æ³ï¼ |
| | | * |
| | | * @param bucketName å卿¡¶åç§° |
| | | * @param bucketFileName æ¡¶ä¸æä»¶åç§° |
| | | * @return æä»¶æµ |
| | | */ |
| | | public InputStream getFileStream(String bucketName, String bucketFileName) throws Exception { |
| | | GetObjectArgs objectArgs = GetObjectArgs.builder().bucket(bucketName).object(bucketFileName).build(); |
| | | return minioClient.getObject(objectArgs); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤æä»¶å¯¹è±¡ç»æ |
| | | * |
| | | * @param bucketName å卿¡¶åç§° |
| | | * @param bucketFileName æ¡¶ä¸æä»¶åç§° |
| | | * @return å é¤ç»æ |
| | | */ |
| | | public DeleteError removeObjectsResult(String bucketName, String bucketFileName) { |
| | | List<DeleteError> results = removeObjectsResult(bucketName, Collections.singletonList(bucketFileName)); |
| | | return !results.isEmpty() ? results.get(0) : null; |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤æä»¶å¯¹è±¡ç»æ |
| | | * |
| | | * @param bucketName å卿¡¶åç§° |
| | | * @param bucketFileNames æ¡¶ä¸æä»¶åç§°éå |
| | | * @return å é¤ç»æ |
| | | */ |
| | | public List<DeleteError> removeObjectsResult(String bucketName, List<String> bucketFileNames) { |
| | | Iterable<Result<DeleteError>> results = removeObjects(bucketName, bucketFileNames); |
| | | List<DeleteError> res = new ArrayList<>(); |
| | | for (Result<DeleteError> result : results) { |
| | | try { |
| | | res.add(result.get()); |
| | | } catch (Exception e) { |
| | | throw new UtilException("MinioUtilsï¼ä¸ä¼ æä»¶å·¥å
·ç±»å¼å¸¸"); |
| | | } |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤æä»¶å¯¹è±¡ |
| | | * |
| | | * @param bucketName å卿¡¶åç§° |
| | | * @param bucketFileNames æ¡¶ä¸æä»¶åç§°éå |
| | | */ |
| | | private Iterable<Result<DeleteError>> removeObjects(String bucketName, List<String> bucketFileNames) { |
| | | List<DeleteObject> dos = bucketFileNames.stream().map(DeleteObject::new).collect(Collectors.toList()); |
| | | return minioClient.removeObjects(RemoveObjectsArgs.builder().bucket(bucketName).objects(dos).build()); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢é¢è§url |
| | | * @param bucketFileName minioæä»¶åç§° |
| | | * @param bucketName å卿¡¶åç§° |
| | | * @param isPreviewExpiry æ¯å¦éè¦è¿ææ¶é´ é»è®¤24å°æ¶ |
| | | * @return |
| | | */ |
| | | public String getPreviewUrl(String bucketFileName, String bucketName, Boolean isPreviewExpiry) { |
| | | if (StringUtils.isNotBlank(bucketFileName)) { |
| | | try { |
| | | minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(bucketFileName).build()); |
| | | // 为falseåªçæ24å°æ¶æææ¶é¿çurl龿¥ï¼å¯ä»¥è®¿é®è¯¥æä»¶ |
| | | if (isPreviewExpiry){ |
| | | return minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder().method(Method.GET).bucket(bucketName).object(bucketFileName).build()); |
| | | }else { |
| | | return minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder().method(Method.GET).bucket(bucketName).object(bucketFileName).expiry(previewExpiry, TimeUnit.HOURS).build()); |
| | | } |
| | | } catch (Exception e) { |
| | | throw new UtilException("MinioUtilsï¼ä¸ä¼ æä»¶å·¥å
·ç±»å¼å¸¸"); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | DROP TABLE IF EXISTS storage_blob; |
| | | |
| | | CREATE TABLE storage_blob |
| | | ( |
| | | 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 TABLE storage_blob IS 'éç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯'; |
| | | |
| | | COMMENT ON COLUMN storage_blob.key IS 'èµæºid'; |
| | | COMMENT ON COLUMN storage_blob.content_type IS 'èµæºç±»åï¼ä¾å¦JPGå¾ççèµæºç±»å为image/jpg'; |
| | | 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_attachment |
| | | ( |
| | | id bigserial PRIMARY KEY, |
| | | 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_attachment IS 'éç¨æä»¶ä¸ä¼ çéä»¶ä¿¡æ¯'; |
| | | |
| | | 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_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="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 |