diff --git a/diboot-file-starter/src/main/java/com/diboot/file/controller/BaseExcelFileController.java b/diboot-file-starter/src/main/java/com/diboot/file/controller/BaseExcelFileController.java index 52e4af9..e11e686 100644 --- a/diboot-file-starter/src/main/java/com/diboot/file/controller/BaseExcelFileController.java +++ b/diboot-file-starter/src/main/java/com/diboot/file/controller/BaseExcelFileController.java @@ -21,6 +21,7 @@ import com.diboot.core.util.S; import com.diboot.core.util.V; import com.diboot.core.vo.JsonResult; import com.diboot.core.vo.Status; +import com.diboot.file.dto.UploadFileFormDTO; import com.diboot.file.entity.UploadFile; import com.diboot.file.excel.listener.FixedHeadExcelListener; import com.diboot.file.util.ExcelHelper; @@ -28,13 +29,13 @@ import com.diboot.file.util.FileHelper; import lombok.extern.slf4j.Slf4j; import org.springframework.web.multipart.MultipartFile; -import javax.servlet.http.HttpServletRequest; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Excel导入基类Controller + * * @author Mazc@dibo.ltd * @version 2.0 * @date 2020/02/20 @@ -58,11 +59,23 @@ public abstract class BaseExcelFileController extends BaseFileController { * @throws Exception */ public JsonResult excelPreview(MultipartFile file) throws Exception { - Map dataMap = new HashMap(); + Map dataMap = new HashMap(16); savePreviewExcelFile(file, dataMap); return JsonResult.OK(dataMap); } + /*** + * excel数据预览 + * @param uploadFileFormDTO 带有其他配置的上传 + * @return + * @throws Exception + */ + public JsonResult excelPreview(UploadFileFormDTO uploadFileFormDTO) throws Exception { + Map dataMap = new HashMap(16); + savePreviewExcelFile(uploadFileFormDTO, dataMap); + return JsonResult.OK(dataMap); + } + /*** * 预览后提交保存 * @param @@ -70,22 +83,51 @@ public abstract class BaseExcelFileController extends BaseFileController { * @throws Exception */ public JsonResult excelPreviewSave(Class entityClass, String previewFileName, String originFileName) throws Exception { - if(V.isEmpty(previewFileName) || V.isEmpty(originFileName)){ + if (V.isEmpty(previewFileName) || V.isEmpty(originFileName)) { throw new BusinessException(Status.FAIL_INVALID_PARAM, "预览保存失败,参数 tempFileName 或 originFileName 未指定!"); } String fileUid = S.substringBefore(previewFileName, "."); String fullPath = FileHelper.getFullPath(previewFileName); + String accessUrl = FileHelper.getRelativePath(previewFileName); String ext = FileHelper.getFileExtByName(originFileName); // 描述 String description = getString("description"); // 保存文件上传记录 UploadFile uploadFile = new UploadFile().setUuid(fileUid) .setFileName(originFileName).setStoragePath(fullPath).setFileType(ext) + .setAccessUrl(accessUrl) .setRelObjType(entityClass.getSimpleName()).setDescription(description); super.createUploadFile(uploadFile); return JsonResult.OK(); } + /*** + * 预览后提交保存 + * @param uploadFileFormDTO + * @param previewFileName + * @param originFileName + * @return + * @throws Exception + */ + public JsonResult excelPreviewSave(UploadFileFormDTO uploadFileFormDTO, String previewFileName, String originFileName) throws Exception { + if (V.isEmpty(previewFileName) || V.isEmpty(originFileName)) { + throw new BusinessException(Status.FAIL_INVALID_PARAM, "预览保存失败,参数 tempFileName 或 originFileName 未指定!"); + } + String fileUid = S.substringBefore(previewFileName, "."); + String fullPath = FileHelper.getFullPath(previewFileName); + String accessUrl = FileHelper.getRelativePath(previewFileName); + String ext = FileHelper.getFileExtByName(originFileName); + // 保存文件上传记录 + UploadFile uploadFile = new UploadFile().setUuid(fileUid) + .setFileName(originFileName).setStoragePath(fullPath).setFileType(ext) + .setAccessUrl(accessUrl) + .setRelObjField(uploadFileFormDTO.getRelObjField()) + .setRelObjType(uploadFileFormDTO.getRelObjType()) + .setDescription(uploadFileFormDTO.getDescription()); + super.createUploadFile(uploadFile); + return JsonResult.OK(); + } + /*** * 直接上传excel * @param @@ -97,12 +139,24 @@ public abstract class BaseExcelFileController extends BaseFileController { return super.uploadFile(file, entityClass); } - /** - * 保存上传文件 + /*** + * 直接上传excel + * @param * @return * @throws Exception */ - private void savePreviewExcelFile(MultipartFile file, Map dataMap) throws Exception{ + public JsonResult uploadExcelFile(UploadFileFormDTO uploadFileFormDTO) throws Exception { + checkIsExcel(uploadFileFormDTO.getFile()); + return super.uploadFile(uploadFileFormDTO); + } + + /** + * 保存上传文件 + * + * @return + * @throws Exception + */ + private void savePreviewExcelFile(MultipartFile file, Map dataMap) throws Exception { checkIsExcel(file); // 保存文件到本地 UploadFile uploadFile = super.saveFile(file, getExcelDataListener().getExcelModelClass()); @@ -111,10 +165,9 @@ public abstract class BaseExcelFileController extends BaseFileController { listener.setRequestParams(super.getParamsMap()); try { ExcelHelper.previewReadExcel(uploadFile.getStoragePath(), listener); - } - catch (Exception e) { + } catch (Exception e) { log.warn("解析并校验excel文件失败", e); - if(V.notEmpty(e.getMessage())){ + if (V.notEmpty(e.getMessage())) { throw new Exception(e.getMessage()); } throw e; @@ -124,7 +177,41 @@ public abstract class BaseExcelFileController extends BaseFileController { dataMap.put(ORIGIN_FILE_NAME, file.getOriginalFilename()); dataMap.put(PREVIEW_FILE_NAME, FileHelper.getFileName(uploadFile.getStoragePath())); List dataList = listener.getDataList(); - if(V.notEmpty(dataList) && dataList.size() > BaseConfig.getPageSize()){ + if (V.notEmpty(dataList) && dataList.size() > BaseConfig.getPageSize()) { + dataList = dataList.subList(0, BaseConfig.getPageSize()); + } + //最多返回前端十条数据 + dataMap.put("dataList", dataList); + } + + /** + * 保存上传文件 + * + * @return + * @throws Exception + */ + private void savePreviewExcelFile(UploadFileFormDTO uploadFileFormDTO, Map dataMap) throws Exception { + checkIsExcel(uploadFileFormDTO.getFile()); + // 保存文件到本地 + UploadFile uploadFile = super.saveFile(uploadFileFormDTO); + // 预览 + FixedHeadExcelListener listener = getExcelDataListener(); + listener.setRequestParams(super.getParamsMap()); + try { + ExcelHelper.previewReadExcel(uploadFile.getStoragePath(), listener); + } catch (Exception e) { + log.warn("解析并校验excel文件失败", e); + if (V.notEmpty(e.getMessage())) { + throw new Exception(e.getMessage()); + } + throw e; + } + // 绑定属性到model + dataMap.put("header", listener.getFieldHeaders()); + dataMap.put(ORIGIN_FILE_NAME, uploadFileFormDTO.getFile().getOriginalFilename()); + dataMap.put(PREVIEW_FILE_NAME, FileHelper.getFileName(uploadFile.getStoragePath())); + List dataList = listener.getDataList(); + if (V.notEmpty(dataList) && dataList.size() > BaseConfig.getPageSize()) { dataList = dataList.subList(0, BaseConfig.getPageSize()); } //最多返回前端十条数据 @@ -135,17 +222,16 @@ public abstract class BaseExcelFileController extends BaseFileController { * 保存文件之后的处理逻辑,如解析excel */ @Override - protected int extractDataCount(String fileUuid, String fullPath) throws Exception{ + protected int extractDataCount(String fileUuid, String fullPath) throws Exception { FixedHeadExcelListener listener = getExcelDataListener(); listener.setUploadFileUuid(fileUuid); listener.setPreview(false); listener.setRequestParams(super.getParamsMap()); - try{ + try { ExcelHelper.readAndSaveExcel(fullPath, listener); - } - catch(Exception e){ - log.warn("上传数据错误: "+ e.getMessage(), e); - if(V.notEmpty(e.getMessage())){ + } catch (Exception e) { + log.warn("上传数据错误: " + e.getMessage(), e); + if (V.notEmpty(e.getMessage())) { throw new Exception(e.getMessage()); } throw e; @@ -155,11 +241,12 @@ public abstract class BaseExcelFileController extends BaseFileController { /** * 检查是否为合法的excel文件 + * * @param file * @throws Exception */ - private void checkIsExcel(MultipartFile file) throws Exception{ - if(V.isEmpty(file)) { + private void checkIsExcel(MultipartFile file) throws Exception { + if (V.isEmpty(file)) { throw new BusinessException(Status.FAIL_INVALID_PARAM, "未获取待处理的excel文件!"); } String fileName = file.getOriginalFilename(); diff --git a/diboot-file-starter/src/main/java/com/diboot/file/controller/BaseFileController.java b/diboot-file-starter/src/main/java/com/diboot/file/controller/BaseFileController.java index 688a5d7..eb543a8 100644 --- a/diboot-file-starter/src/main/java/com/diboot/file/controller/BaseFileController.java +++ b/diboot-file-starter/src/main/java/com/diboot/file/controller/BaseFileController.java @@ -16,6 +16,8 @@ package com.diboot.file.controller; import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.diboot.core.controller.BaseController; import com.diboot.core.exception.BusinessException; import com.diboot.core.util.S; @@ -23,14 +25,18 @@ import com.diboot.core.util.V; import com.diboot.core.vo.JsonResult; import com.diboot.core.vo.Pagination; import com.diboot.core.vo.Status; +import com.diboot.file.dto.UploadFileFormDTO; import com.diboot.file.entity.UploadFile; import com.diboot.file.service.UploadFileService; import com.diboot.file.util.FileHelper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; +import javax.validation.constraints.NotNull; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -81,10 +87,12 @@ public abstract class BaseFileController extends BaseController { // 保存上传记录 createUploadFile(uploadFile); // 返回结果 - Map dataMap = new HashMap<>(); - dataMap.put("uuid", uploadFile.getUuid()); - dataMap.put("accessUrl", uploadFile.getAccessUrl()); - return JsonResult.OK(dataMap); + // 返回结果 + return JsonResult.OK(new HashMap(16) {{ + put("uuid", uploadFile.getUuid()); + put("accessUrl", uploadFile.getAccessUrl()); + put("fileName", uploadFile.getFileName()); + }}); } /** @@ -114,6 +122,59 @@ public abstract class BaseFileController extends BaseController { return uploadFile; } + /*** + * 直接上传文件 + * @param uploadFileFormDTO + * @return + * @throws Exception + */ + public JsonResult uploadFile(UploadFileFormDTO uploadFileFormDTO) throws Exception { + if(uploadFileFormDTO == null || uploadFileFormDTO.getFile() == null) { + throw new BusinessException(Status.FAIL_INVALID_PARAM, "未获取待处理的文件!"); + } + String originFileName = uploadFileFormDTO.getFile().getOriginalFilename(); + if (V.isEmpty(originFileName) || !FileHelper.isValidFileExt(originFileName)) { + log.debug("非法的文件类型: " + originFileName); + throw new BusinessException(Status.FAIL_VALIDATION, "请上传合法的文件格式!"); + } + // 保存文件 + UploadFile uploadFile = saveFile(uploadFileFormDTO); + // 保存上传记录 + createUploadFile(uploadFile); + // 返回结果 + return JsonResult.OK(new HashMap(16) {{ + put("uuid", uploadFile.getUuid()); + put("accessUrl", uploadFile.getAccessUrl()); + put("fileName", uploadFile.getFileName()); + }}); + } + + /** + * 保存文件 + * @param uploadFileFormDTO + * @param + * @return + * @throws Exception + */ + protected UploadFile saveFile(UploadFileFormDTO uploadFileFormDTO) throws Exception{ + // 文件后缀 + String originFileName = uploadFileFormDTO.getFile().getOriginalFilename(); + String ext = FileHelper.getFileExtByName( uploadFileFormDTO.getFile().getOriginalFilename()); + // 先保存文件 + String fileUid = S.newUuid(); + String newFileName = fileUid + "." + ext; + String storageFullPath = FileHelper.saveFile( uploadFileFormDTO.getFile(), newFileName); + String accessUrl = FileHelper.getRelativePath(newFileName); + UploadFile uploadFile = new UploadFile(); + uploadFile.setUuid(fileUid).setFileName(originFileName).setFileType(ext); + uploadFile.setRelObjType(uploadFileFormDTO.getRelObjType()) + .setRelObjField(uploadFileFormDTO.getRelObjField()) + .setStoragePath(storageFullPath).setAccessUrl(accessUrl) + .setDescription(uploadFileFormDTO.getDescription()); + // 返回uploadFile对象 + return uploadFile; + } + /** * 保存上传文件信息 * @param uploadFile @@ -127,6 +188,29 @@ public abstract class BaseFileController extends BaseController { uploadFileService.createEntity(uploadFile); } + /** + *

获取文件通用接口

+ *

+ * 其中当relObjField不传递的时候,表示获取当前业务ID和业务类型下的所有文件
+ * 当传递relObjField的时候,获取指定类型的文件 + *

+ * + * @param relObjId 业务ID 必传字段 + * @param relObjType 业务类型 必传字段 + * @param relObjField 对应的具体类型 非必传字段(同一种业务下可能有多种文件) + * @return {@link List } 返回文件对象的集合 + * @throws Exception + */ + public List getUploadFileList(Long relObjId, String relObjType, String relObjField) throws Exception { + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery() + .eq(UploadFile::getRelObjId, relObjId) + .eq(UploadFile::getRelObjType, relObjType); + if (V.notEmpty(relObjField)) { + wrapper.eq(UploadFile::getRelObjField, relObjField); + } + return uploadFileService.getEntityList(wrapper); + } + /** * 保存文件之后的处理逻辑,如解析excel */ diff --git a/diboot-file-starter/src/main/java/com/diboot/file/dto/UploadFileFormDTO.java b/diboot-file-starter/src/main/java/com/diboot/file/dto/UploadFileFormDTO.java new file mode 100644 index 0000000..cea8b17 --- /dev/null +++ b/diboot-file-starter/src/main/java/com/diboot/file/dto/UploadFileFormDTO.java @@ -0,0 +1,47 @@ +package com.diboot.file.dto; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.springframework.web.multipart.MultipartFile; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + * 上传文件提交的form + * + * @author : uu + * @version : v1.0 + * @Date 2020-05-18 17:32 + */ +@Setter +@Getter +@ToString +public class UploadFileFormDTO implements Serializable { + + private static final long serialVersionUID = -3467553770266812902L; + + /** + * 上传的文件 + */ + @NotNull(message = "上传文件不能为空") + private MultipartFile file; + + /** + * 关联对象类 + */ + @NotNull(message = "关联对象类不能为空!") + private String relObjType; + + /** + * 关联对象属性 + */ + @NotNull(message = "关联对象属性不能为空!") + private String relObjField; + + /** + * 描述 + */ + private String description; +} diff --git a/diboot-file-starter/src/main/java/com/diboot/file/entity/UploadFile.java b/diboot-file-starter/src/main/java/com/diboot/file/entity/UploadFile.java index 2b123d3..fd2022f 100644 --- a/diboot-file-starter/src/main/java/com/diboot/file/entity/UploadFile.java +++ b/diboot-file-starter/src/main/java/com/diboot/file/entity/UploadFile.java @@ -51,6 +51,10 @@ public class UploadFile extends BaseEntity { @NotNull(message = "关联对象ID不能为空!") private Long relObjId; + @TableField + @NotNull(message = "关联对象属性不能为空!") + private String relObjField; + @TableField @NotNull(message = "文件名不能为空!") @Length(max = 100, message = "文件名长度超出了最大限制!") diff --git a/diboot-file-starter/src/main/java/com/diboot/file/service/UploadFileService.java b/diboot-file-starter/src/main/java/com/diboot/file/service/UploadFileService.java index 27ee405..7da0b0b 100644 --- a/diboot-file-starter/src/main/java/com/diboot/file/service/UploadFileService.java +++ b/diboot-file-starter/src/main/java/com/diboot/file/service/UploadFileService.java @@ -15,6 +15,7 @@ */ package com.diboot.file.service; +import com.diboot.core.entity.BaseEntity; import com.diboot.core.service.BaseService; import com.diboot.file.entity.UploadFile; @@ -22,6 +23,7 @@ import java.util.List; /** * 基础文件Service + * * @author Lishuaifei@dibo.ltd * @date 2019-07-18 */ @@ -29,10 +31,21 @@ public interface UploadFileService extends BaseService { /** * 获取指定对象记录关联的上传文件列表 + * * @param relObjClass * @param relObjId * @return */ List getUploadedFiles(String relObjClass, Long relObjId); + /** + * 绑定业务id + * + * @param relObjId + * @param relObjTypeClass + * @param fileUuidList + * @throws Exception + */ + void bindRelObjId(Long relObjId, Class relObjTypeClass, List fileUuidList) throws Exception; + } \ No newline at end of file diff --git a/diboot-file-starter/src/main/java/com/diboot/file/service/impl/UploadFileServiceImpl.java b/diboot-file-starter/src/main/java/com/diboot/file/service/impl/UploadFileServiceImpl.java index da8cac0..67335bc 100644 --- a/diboot-file-starter/src/main/java/com/diboot/file/service/impl/UploadFileServiceImpl.java +++ b/diboot-file-starter/src/main/java/com/diboot/file/service/impl/UploadFileServiceImpl.java @@ -17,11 +17,15 @@ package com.diboot.file.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.diboot.core.entity.BaseEntity; import com.diboot.core.service.impl.BaseServiceImpl; +import com.diboot.core.util.V; import com.diboot.file.entity.UploadFile; import com.diboot.file.mapper.UploadFileMapper; import com.diboot.file.service.UploadFileService; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -42,4 +46,34 @@ public class UploadFileServiceImpl extends BaseServiceImpl relObjTypeClass, List fileUuidList) throws Exception { + + //如果不存在需要绑定的么清除所有当前关联的所有文件 + if (V.isEmpty(fileUuidList)) { + this.update( + Wrappers.lambdaUpdate() + .set(true, UploadFile::isDeleted, true) + .eq(UploadFile::getRelObjId, relObjId) + .eq(UploadFile::getRelObjType, relObjTypeClass.getSimpleName()) + ); + return; + } + // 删除 relObjId + relObjType下的 并且不包含fileIdList的file。 + this.update( + Wrappers.lambdaUpdate() + .set(true, UploadFile::isDeleted, true) + .eq(UploadFile::getRelObjId, relObjId) + .eq(UploadFile::getRelObjType, relObjTypeClass.getSimpleName()) + .notIn(UploadFile::getUuid, fileUuidList) + ); + // 绑定绑定数据 + this.update( + Wrappers.lambdaUpdate() + .set(true, UploadFile::getRelObjId, relObjId) + .in(UploadFile::getUuid, fileUuidList) + ); + } + } diff --git a/diboot-file-starter/src/main/resources/META-INF/sql/init-file-mariadb.sql b/diboot-file-starter/src/main/resources/META-INF/sql/init-file-mariadb.sql index aaba9f5..4ab9137 100644 --- a/diboot-file-starter/src/main/resources/META-INF/sql/init-file-mariadb.sql +++ b/diboot-file-starter/src/main/resources/META-INF/sql/init-file-mariadb.sql @@ -3,6 +3,7 @@ CREATE TABLE upload_file ( uuid varchar(32) NOT NULL COMMENT '编号' primary key, rel_obj_type varchar(50) DEFAULT NULL COMMENT '关联对象类', rel_obj_id bigint DEFAULT NULL COMMENT '关联对象ID', + rel_obj_field varchar(50) DEFAULT NULL COMMENT '关联对象属性名称', file_name varchar(100) NOT NULL COMMENT '文件名', storage_path varchar(200) NOT NULL COMMENT '存储路径', file_type varchar(20) DEFAULT NULL COMMENT '文件类型', @@ -13,4 +14,4 @@ CREATE TABLE upload_file ( create_time timestamp default CURRENT_TIMESTAMP not null comment '创建时间' ) DEFAULT CHARSET=utf8 COMMENT='上传文件'; -- 索引 -create index idx_upload_file on upload_file (rel_obj_type, rel_obj_id); \ No newline at end of file +create index idx_upload_file on upload_file (rel_obj_type, rel_obj_id, rel_obj_field); \ No newline at end of file diff --git a/diboot-file-starter/src/main/resources/META-INF/sql/init-file-mysql.sql b/diboot-file-starter/src/main/resources/META-INF/sql/init-file-mysql.sql index 2ed066a..b557670 100644 --- a/diboot-file-starter/src/main/resources/META-INF/sql/init-file-mysql.sql +++ b/diboot-file-starter/src/main/resources/META-INF/sql/init-file-mysql.sql @@ -3,6 +3,7 @@ CREATE TABLE upload_file ( uuid varchar(32) NOT NULL COMMENT '编号' primary key, rel_obj_type varchar(50) DEFAULT NULL COMMENT '关联对象类', rel_obj_id bigint DEFAULT NULL COMMENT '关联对象ID', + rel_obj_field varchar(50) DEFAULT NULL COMMENT '关联对象属性名称', file_name varchar(100) NOT NULL COMMENT '文件名', storage_path varchar(200) NOT NULL COMMENT '存储路径', access_url varchar(200) NULL COMMENT '访问地址', @@ -13,4 +14,4 @@ CREATE TABLE upload_file ( create_time timestamp default CURRENT_TIMESTAMP not null comment '创建时间' ) DEFAULT CHARSET=utf8 COMMENT='上传文件'; -- 索引 -create index idx_upload_file on upload_file (rel_obj_type, rel_obj_id); \ No newline at end of file +create index idx_upload_file on upload_file (rel_obj_type, rel_obj_id, rel_obj_field); \ No newline at end of file diff --git a/diboot-file-starter/src/main/resources/META-INF/sql/init-file-oracle.sql b/diboot-file-starter/src/main/resources/META-INF/sql/init-file-oracle.sql index 31f0f11..4d411cd 100644 --- a/diboot-file-starter/src/main/resources/META-INF/sql/init-file-oracle.sql +++ b/diboot-file-starter/src/main/resources/META-INF/sql/init-file-oracle.sql @@ -3,6 +3,7 @@ CREATE TABLE ${SCHEMA}.upload_file ( uuid VARCHAR2(32) NOT NULL, rel_obj_type VARCHAR2(50), rel_obj_id NUMBER(20), + rel_obj_field VARCHAR2(50), file_name VARCHAR2(100) NOT NULL, storage_path VARCHAR2(200) NOT NULL, access_url VARCHAR2(200), @@ -17,6 +18,7 @@ CREATE TABLE ${SCHEMA}.upload_file ( comment on column ${SCHEMA}.upload_file.uuid is 'UUID'; comment on column ${SCHEMA}.upload_file.rel_obj_type is '关联对象类'; comment on column ${SCHEMA}.upload_file.rel_obj_id is '关联对象ID'; +comment on column ${SCHEMA}.upload_file.rel_obj_field is '关联对象属性名称'; comment on column ${SCHEMA}.upload_file.file_name is '文件名'; comment on column ${SCHEMA}.upload_file.storage_path is '存储路径'; comment on column ${SCHEMA}.upload_file.access_url is '访问地址'; @@ -27,4 +29,4 @@ comment on column ${SCHEMA}.upload_file.is_deleted is '删除标记'; comment on column ${SCHEMA}.upload_file.create_time is '创建时间'; comment on table ${SCHEMA}.upload_file is '上传文件'; -- 索引 -create index idx_upload_file on ${SCHEMA}.upload_file (rel_obj_type, rel_obj_id); \ No newline at end of file +create index idx_upload_file on ${SCHEMA}.upload_file (rel_obj_type, rel_obj_id, rel_obj_field); \ No newline at end of file diff --git a/diboot-file-starter/src/main/resources/META-INF/sql/init-file-postgresql.sql b/diboot-file-starter/src/main/resources/META-INF/sql/init-file-postgresql.sql index 779bc8b..76ed7e4 100644 --- a/diboot-file-starter/src/main/resources/META-INF/sql/init-file-postgresql.sql +++ b/diboot-file-starter/src/main/resources/META-INF/sql/init-file-postgresql.sql @@ -3,6 +3,7 @@ CREATE TABLE upload_file ( uuid varchar(32) NOT NULL, rel_obj_type varchar(50), rel_obj_id bigint, + rel_obj_field varchar(50), file_name varchar(100) NOT NULL, storage_path varchar(200) NOT NULL, access_url varchar(200), @@ -17,6 +18,7 @@ CREATE TABLE upload_file ( comment on column upload_file.uuid is 'UUID'; comment on column upload_file.rel_obj_type is '关联对象类'; comment on column upload_file.rel_obj_id is '关联对象ID'; +comment on column upload_file.rel_obj_field is '关联对象属性名称'; comment on column upload_file.file_name is '文件名'; comment on column upload_file.storage_path is '存储路径'; comment on column upload_file.access_url is '访问地址'; @@ -27,4 +29,4 @@ comment on column upload_file.is_deleted is '删除标记'; comment on column upload_file.create_time is '创建时间'; comment on table upload_file is '上传文件'; -- 索引 -create index idx_upload_file on upload_file (rel_obj_type, rel_obj_id); \ No newline at end of file +create index idx_upload_file on upload_file (rel_obj_type, rel_obj_id, rel_obj_field); \ No newline at end of file diff --git a/diboot-file-starter/src/main/resources/META-INF/sql/init-file-sqlserver.sql b/diboot-file-starter/src/main/resources/META-INF/sql/init-file-sqlserver.sql index 54544cd..54ce49b 100644 --- a/diboot-file-starter/src/main/resources/META-INF/sql/init-file-sqlserver.sql +++ b/diboot-file-starter/src/main/resources/META-INF/sql/init-file-sqlserver.sql @@ -3,6 +3,7 @@ CREATE TABLE ${SCHEMA}.upload_file ( uuid varchar(32) NOT NULL, rel_obj_type varchar(50), rel_obj_id bigint, + rel_obj_field varchar(50), file_name varchar(100) NOT NULL, storage_path varchar(200) NOT NULL, access_url varchar(200) NULL, @@ -17,6 +18,7 @@ CREATE TABLE ${SCHEMA}.upload_file ( execute sp_addextendedproperty 'MS_Description', N'UUID', 'SCHEMA', '${SCHEMA}', 'table', upload_file, 'column', 'uuid'; execute sp_addextendedproperty 'MS_Description', N'关联对象类', 'SCHEMA', '${SCHEMA}', 'table', upload_file, 'column', 'rel_obj_type'; execute sp_addextendedproperty 'MS_Description', N'关联对象ID', 'SCHEMA', '${SCHEMA}', 'table', upload_file, 'column', 'rel_obj_id'; +execute sp_addextendedproperty 'MS_Description', N'关联对象属性名称', 'SCHEMA', '${SCHEMA}', 'table', upload_file, 'column', 'rel_obj_field'; execute sp_addextendedproperty 'MS_Description', N'文件名', 'SCHEMA', '${SCHEMA}', 'table', upload_file, 'column', 'file_name'; execute sp_addextendedproperty 'MS_Description', N'存储路径', 'SCHEMA', '${SCHEMA}', 'table', upload_file, 'column', 'storage_path'; execute sp_addextendedproperty 'MS_Description', N'访问地址', 'SCHEMA', '${SCHEMA}', 'table', upload_file, 'column', 'access_url'; @@ -27,4 +29,4 @@ execute sp_addextendedproperty 'MS_Description', N'删除标记', 'SCHEMA', '${S execute sp_addextendedproperty 'MS_Description', N'创建时间', 'SCHEMA', '${SCHEMA}', 'table', upload_file, 'column', 'create_time'; execute sp_addextendedproperty 'MS_Description', N'上传文件', 'SCHEMA', '${SCHEMA}', 'table', upload_file, null, null; -- 索引 -create nonclustered index idx_upload_file on upload_file(rel_obj_type, rel_obj_id); +create nonclustered index idx_upload_file on upload_file(rel_obj_type, rel_obj_id, rel_obj_field);