snowy-base/snowy-core/src/main/java/vip/xiaonuo/core/consts/MyConstant.java
@@ -1,7 +1,9 @@ package vip.xiaonuo.core.consts; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public interface MyConstant { Integer No = 0; @@ -33,6 +35,42 @@ /** * 文件类型 */ interface FileType { Integer fileTypeMarkDown_1 = 1; Integer fileTypeHtml_2 = 2; Integer fileTypeVideo_3 = 3; Integer fileTypeMp3_4 = 4; Integer fileTypeShort_5 = 5; Integer fileTypePhoto_9 = 9; } List<Integer> FileTypeList = new ArrayList(5) {{ add(FileType.fileTypeMarkDown_1); add(FileType.fileTypeHtml_2); add(FileType.fileTypeVideo_3); add(FileType.fileTypeMp3_4); add(FileType.fileTypeShort_5); add(FileType.fileTypePhoto_9); }}; //存储文件夹映射 String bucket_article = "article"; String bucket_video = "mp4"; String bucket_mp3 = "mp3"; String bucket_cover = "cover"; Map<Integer, String> uploadFileBucketMap = new HashMap(5) {{ put(FileType.fileTypeMarkDown_1, bucket_article); put(FileType.fileTypeHtml_2, bucket_article); put(FileType.fileTypeVideo_3, bucket_video); put(FileType.fileTypeMp3_4, bucket_mp3); put(FileType.fileTypePhoto_9, bucket_cover); }}; /** * 留言类型 1:留言板 2:日志评论 */ interface CommentType { snowy-base/snowy-system/src/main/java/vip/xiaonuo/sys/core/mybatis/fieldfill/CustomMetaObjectHandler.java
@@ -63,29 +63,43 @@ try { Object updateDate = metaObject.getValue(UPDATE_DATE); if(ObjectUtil.isNull(updateDate)) { if (ObjectUtil.isNull(updateDate)) { setFieldValByName(UPDATE_DATE, new Date(), metaObject); } Object createDate = metaObject.getValue(CREATE_DATE); if(ObjectUtil.isNull(createDate)) { if (ObjectUtil.isNull(createDate)) { setFieldValByName(CREATE_DATE, new Date(), metaObject); } //为空则设置createUser(BaseEntity) Object createUser = metaObject.getValue(CREATE_USER); if(ObjectUtil.isNull(createUser)) { if (ObjectUtil.isNull(createUser)) { setFieldValByName(CREATE_USER, this.getUserUniqueId(), metaObject); } //为空则设置createTime(BaseEntity) Object createTime = metaObject.getValue(CREATE_TIME); if(ObjectUtil.isNull(createTime)) { if (ObjectUtil.isNull(createTime)) { setFieldValByName(CREATE_TIME, new Date(), metaObject); } } catch (ReflectionException e) { log.warn(">>> CustomMetaObjectHandler处理过程中无相关字段,不做处理"); //二次设置 try { //为空则设置createTime(BaseEntity) Object createTime = metaObject.getValue(CREATE_TIME); if (ObjectUtil.isNull(createTime)) { setFieldValByName(CREATE_TIME, new Date(), metaObject); } //为空则设置createUser(BaseEntity) Object createUser = metaObject.getValue(CREATE_USER); if (ObjectUtil.isNull(createUser)) { setFieldValByName(CREATE_USER, this.getUserUniqueId(), metaObject); } } catch (ReflectionException ex) { log.warn(">>> CustomMetaObjectHandler处理过程中无相关字段,不做处理"); } } } @@ -110,7 +124,7 @@ private Long getUserUniqueId() { try { SysLoginUser sysLoginUser = LoginContextHolder.me().getSysLoginUserWithoutException(); if(ObjectUtil.isNotNull(sysLoginUser)) { if (ObjectUtil.isNotNull(sysLoginUser)) { return sysLoginUser.getId(); } else { return -1L; snowy-base/snowy-system/src/main/java/vip/xiaonuo/sys/modular/file/service/SysFileInfoService.java
@@ -110,6 +110,8 @@ */ Long uploadFile(MultipartFile file); Long uploadFileBlog(MultipartFile file, String bucket); /** * 获取文件信息结果集 * snowy-base/snowy-system/src/main/java/vip/xiaonuo/sys/modular/file/service/impl/SysFileInfoServiceImpl.java
@@ -57,8 +57,8 @@ import vip.xiaonuo.core.util.HttpServletUtil; import vip.xiaonuo.core.util.LibreOfficeUtil; import vip.xiaonuo.sys.modular.file.entity.SysFileInfo; import vip.xiaonuo.sys.modular.file.enums.SysFileLocationEnum; import vip.xiaonuo.sys.modular.file.enums.SysFileInfoExceptionEnum; import vip.xiaonuo.sys.modular.file.enums.SysFileLocationEnum; import vip.xiaonuo.sys.modular.file.mapper.SysFileInfoMapper; import vip.xiaonuo.sys.modular.file.param.SysFileInfoParam; import vip.xiaonuo.sys.modular.file.result.SysFileInfoResult; @@ -99,7 +99,7 @@ @Override public SysOnlineFileInfoResult onlineAddOrUpdate(SysFileInfoParam sysFileInfoParam) { if(fileOperator instanceof LocalFileOperator) { if (fileOperator instanceof LocalFileOperator) { //文件后缀 String fileSuffix = sysFileInfoParam.getFileSuffix(); //文件名称 @@ -107,7 +107,7 @@ //文件id Long id = sysFileInfoParam.getId(); //参数错误 if(ObjectUtil.isAllEmpty(fileSuffix, fileOriginName, id)) { if (ObjectUtil.isAllEmpty(fileSuffix, fileOriginName, id)) { throw new ServiceException(SysFileInfoExceptionEnum.ONLINE_EDIT_PARAM_ERROR); } //获取登录用户 @@ -115,19 +115,19 @@ SysFileInfo sysFileInfo; SysOnlineFileInfoResult sysOnlineFileInfoResult; //文件id不为空则表示编辑 if(ObjectUtil.isNotEmpty(id)) { if (ObjectUtil.isNotEmpty(id)) { sysFileInfo = this.getById(id); sysOnlineFileInfoResult= new SysOnlineFileInfoResult(Convert.toStr(sysFileInfo.getId()), sysFileInfo.getFileOriginName(), Convert.toStr(sysLoginUser.getId()), sysLoginUser.getName()); sysOnlineFileInfoResult = new SysOnlineFileInfoResult(Convert.toStr(sysFileInfo.getId()), sysFileInfo.getFileOriginName(), Convert.toStr(sysLoginUser.getId()), sysLoginUser.getName()); } else { //否则表示新增 Boolean sample = sysFileInfoParam.getSample(); sysFileInfo = createDemo(fileSuffix, fileOriginName, sample, Convert.toStr(sysLoginUser.getId()), sysLoginUser.getName()); sysOnlineFileInfoResult= new SysOnlineFileInfoResult(Convert.toStr(sysFileInfo.getId()), fileOriginName + SymbolConstant.PERIOD + fileSuffix, Convert.toStr(sysLoginUser.getId()), sysLoginUser.getName()); sysOnlineFileInfoResult = new SysOnlineFileInfoResult(Convert.toStr(sysFileInfo.getId()), fileOriginName + SymbolConstant.PERIOD + fileSuffix, Convert.toStr(sysLoginUser.getId()), sysLoginUser.getName()); } //设置history sysOnlineFileInfoResult.history = OnlineDocumentUtil.getHistory(sysOnlineFileInfoResult); if(ObjectUtil.isAllNotEmpty(sysFileInfoParam.getMode(), sysFileInfoParam.getType())) { if (ObjectUtil.isAllNotEmpty(sysFileInfoParam.getMode(), sysFileInfoParam.getType())) { sysOnlineFileInfoResult.changeType(sysFileInfoParam.getMode(), sysFileInfoParam.getType()); } return sysOnlineFileInfoResult; @@ -160,8 +160,8 @@ } // 根据后缀查询 if(ObjectUtil.isNotEmpty(sysFileInfoParam.getFileSuffix())) { if(sysFileInfoParam.getFileSuffix().contains(SymbolConstant.COMMA)) { if (ObjectUtil.isNotEmpty(sysFileInfoParam.getFileSuffix())) { if (sysFileInfoParam.getFileSuffix().contains(SymbolConstant.COMMA)) { queryWrapper.in(SysFileInfo::getFileSuffix, Arrays.asList(sysFileInfoParam.getFileSuffix().split(SymbolConstant.COMMA))); } else { queryWrapper.eq(SysFileInfo::getFileSuffix, sysFileInfoParam.getFileSuffix()); @@ -225,6 +225,11 @@ @Override public Long uploadFile(MultipartFile file) { return this.uploadFileBlog(file, DEFAULT_BUCKET); } @Override public Long uploadFileBlog(MultipartFile file, String bucket) { // 生成文件的唯一id Long fileId = IdWorker.getId(); @@ -245,7 +250,7 @@ byte[] bytes; try { bytes = file.getBytes(); fileOperator.storageFile(DEFAULT_BUCKET, finalName, bytes); fileOperator.storageFile(bucket, finalName, bytes); } catch (IOException e) { throw new ServiceException(SysFileInfoExceptionEnum.ERROR_FILE); } @@ -261,7 +266,7 @@ SysFileInfo sysFileInfo = new SysFileInfo(); sysFileInfo.setId(fileId); sysFileInfo.setFileLocation(SysFileLocationEnum.LOCAL.getCode()); sysFileInfo.setFileBucket(DEFAULT_BUCKET); sysFileInfo.setFileBucket(bucket); sysFileInfo.setFileObjectName(finalName); sysFileInfo.setFileOriginName(originalFilename); sysFileInfo.setFileSuffix(fileSuffix); @@ -418,7 +423,7 @@ } int status = (int) jsonObj.get("status"); String downloadUri = (String) jsonObj.get("url"); String downloadUri = (String) jsonObj.get("url"); String changesUri = (String) jsonObj.get("changesurl"); String key = (String) jsonObj.get("key"); @@ -427,7 +432,7 @@ //MustSave, Corrupted try { String histDir = OnlineDocumentUtil.getHistoryDir(OnlineDocumentUtil.getStoragePath(id)); String versionDir = OnlineDocumentUtil.getVersionDir(histDir, OnlineDocumentUtil.getFileVersion(histDir) + 1); String versionDir = OnlineDocumentUtil.getVersionDir(histDir, OnlineDocumentUtil.getFileVersion(histDir) + 1); File ver = new File(versionDir); File toSave = new File(storagePath); if (!ver.exists()) ver.mkdirs(); @@ -462,11 +467,11 @@ /** * 创建模板文件 * * @param fileSuffix 文件后缀 * @param fileSuffix 文件后缀 * @param originalFilename 文件原始名称 * @param sample 是否创建相同文件内容的模板文件 * @param userId 用户id * @param userName 用户名称 * @param sample 是否创建相同文件内容的模板文件 * @param userId 用户id * @param userName 用户名称 * @author xuyuxiang * @date 2021/3/24 11:01 */ @@ -509,8 +514,8 @@ /** * 创建元数据信息 * * @param fileId 文件id * @param userId 用户id * @param fileId 文件id * @param userId 用户id * @param userName 用户名称 * @author xuyuxiang * @date 2021/3/24 11:19 @@ -518,13 +523,13 @@ public void createMeta(String fileId, String userId, String userName) { // 仅限本地文件 Object localClient = fileOperator.getClient(); if(ObjectUtil.isNull(localClient)) { if (ObjectUtil.isNull(localClient)) { throw new ServiceException(SysFileInfoExceptionEnum.CLIENT_INIT_ERROR); } Dict localClientDict = (Dict) localClient; // 拼接获取文档历史路径 String histDir = localClientDict.getStr("currentSavePath") + File.separator + DEFAULT_BUCKET + File.separator + fileId + "-hist"; if(!FileUtil.exist(histDir)) { if (!FileUtil.exist(histDir)) { // 历史路径不存在则创建 File dir = new File(histDir); dir.mkdir(); snowy-main/src/main/java/vip/xiaonuo/modular/blogFile/BlogFileController.java
New file @@ -0,0 +1,92 @@ /* Copyright [2020] [https://www.xiaonuo.vip] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: 1.请不要删除和修改根目录下的LICENSE文件。 2.请不要删除和修改Snowy源码头部的版权声明。 3.请保留源码和相关描述文件的项目出处,作者声明等。 4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy 6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip */ package vip.xiaonuo.modular.blogFile; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import vip.xiaonuo.core.annotion.BusinessLog; import vip.xiaonuo.core.consts.MyConstant; import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum; import vip.xiaonuo.core.exception.BlogException; import vip.xiaonuo.core.pojo.response.ResponseData; import vip.xiaonuo.core.pojo.response.SuccessResponseData; import vip.xiaonuo.modular.blogarticle.service.BlogArticleService; import vip.xiaonuo.modular.blogarticletype.service.BlogArticleTypeService; import vip.xiaonuo.sys.modular.file.service.SysFileInfoService; import javax.annotation.Resource; import javax.validation.Valid; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import static vip.xiaonuo.sys.config.FileConfig.DEFAULT_BUCKET; /** * blog文件控制器 (提供给外部blog系统查询) * * @author inleft * @date 2022-08-19 15:18:00 */ @RestController @RequestMapping("/outside") @Valid public class BlogFileController { @Resource private BlogArticleService blogArticleService; @Resource private BlogArticleTypeService blogArticleTypeService; @Resource private SysFileInfoService fileInfoService; /** * 上传文件 * * @author yubaoshan * @date 2020/6/7 22:15 */ @PostMapping("/sysFileInfo/upload") @BusinessLog(title = "文件信息表_上传文件", opType = LogAnnotionOpTypeEnum.OTHER) public ResponseData upload(@RequestPart("file") MultipartFile file, @NotNull @RequestParam Integer fileType, @NotEmpty @RequestParam String authCode) { if (!MyConstant.FileTypeList.contains(fileType)) { throw new BlogException("错误文件类型"); } // if (StrUtil.isEmpty(authCode) || !authCode.equals(ConstantContextHolder.getAuthCode())) { // throw new BlogException("授权码错误"); // } String bucket = MyConstant.uploadFileBucketMap.getOrDefault(fileType, DEFAULT_BUCKET); Long fileId = fileInfoService.uploadFileBlog(file, bucket); return new SuccessResponseData(fileId); } } snowy-main/src/main/java/vip/xiaonuo/modular/blogarticle/controller/BlogArticleOutsideController.java
@@ -148,6 +148,7 @@ param.put("pageNo", PageUtil.getStart(queryDto.getPageNo() - 1, queryDto.getPageSize())); param.put("pageSize", queryDto.getPageSize()); param.put("typeId", queryDto.getTypeId()); param.put("fileType", queryDto.getFileType()); String blogSourcePrefix = ConstantContextHolder.getBlogSourcePrefix(); snowy-main/src/main/java/vip/xiaonuo/modular/blogarticle/mapper/mapping/BlogArticleMapper.xml
@@ -33,7 +33,14 @@ <trim prefix="WHERE" prefixOverrides="AND | OR"> a.is_enable=1 and a.editor_status=1 <choose> <when test="param.fileType != null"> and a.article_file_type = #{param.fileType} </when> <when test="param.fileType == null and param.typeId == null"> and a.article_file_type not in (3,4) </when> </choose> <choose> <when test="param.typeId != null"> AND a.article_type_id = #{param.typeId} @@ -82,7 +89,7 @@ <select id="searchMonthCount" resultType="vip.xiaonuo.modular.blogStatistics.vo.BlogArchiveDetailVo"> SELECT separate_month AS `month`, count(1) AS count count(1) AS `count` FROM blog_article WHERE snowy-main/src/main/java/vip/xiaonuo/modular/blogarticle/param/BlogArticleQueryDto.java
@@ -22,5 +22,7 @@ private Long typeId; private Long fileType; } snowy-main/src/main/java/vip/xiaonuo/modular/blogarticlecomment/entity/BlogCommentVo.java
@@ -43,4 +43,6 @@ private Integer commentType; private Integer isRead; }