From 9f1fad0096757989556576adeca16c7ff11ad70e Mon Sep 17 00:00:00 2001 From: chenbowen Date: Thu, 24 Jul 2025 14:03:52 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E9=87=8D=E6=9E=84=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E5=8A=A0=E5=AF=86=E4=B8=8B=E8=BD=BD=E9=AA=8C=E8=AF=81=E7=A0=81?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=B5=81=E7=A8=8B=202.=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=AE=80=E5=86=99=E5=91=BD=E5=90=8D=E5=AD=97=E5=85=B8=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/file/FileController.java | 54 ++++++++++++++----- .../dal/dataobject/stdnms/StdNmsDO.java | 15 +++--- .../system/dal/mysql/stdnms/StdNmsMapper.java | 25 +++++---- .../src/main/resources/application-local.yaml | 2 +- .../resources/mapper/stdnms/StdNmsMapper.xml | 24 +++++++++ 5 files changed, 87 insertions(+), 33 deletions(-) create mode 100644 yudao-module-system/yudao-module-system-server/src/main/resources/mapper/stdnms/StdNmsMapper.xml diff --git a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java index dcb81546..2711f784 100644 --- a/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java +++ b/yudao-module-infra/yudao-module-infra-server/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java @@ -31,6 +31,7 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.util.Base64; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @@ -51,6 +52,38 @@ public class FileController { @Value("${yudao.kkfile:}") private String onlinePreview; + @GetMapping("/download-url") + @Operation(summary = "获取文件下载地址", description = "根据 fileId 返回文件下载 url") + public CommonResult getDownloadUrl(@RequestParam("fileId") Long fileId) { + FileDO fileDO = fileService.getActiveFileById(fileId); + if (fileDO == null) { + return CommonResult.error(HttpStatus.NOT_FOUND.value(), "文件不存在"); + } + // FileDO 转换为 FileRespVO + FileRespVO fileRespVO = BeanUtils.toBean(fileDO, FileRespVO.class); + if (StrUtil.isEmpty(onlinePreview) || StrUtil.isEmpty(fileRespVO.getUrl())) { + return CommonResult.error(HttpStatus.BAD_REQUEST.value(), "文件 URL 为空"); + } + return success(fileRespVO); + } + + @GetMapping("/preview-url") + @Operation(summary = "获取文件预览地址", description = "根据 fileId 返回文件预览 url(kkfile)") + public CommonResult getPreviewUrl(@RequestParam("fileId") Long fileId) { + FileDO fileDO = fileService.getActiveFileById(fileId); + if (fileDO == null) { + return CommonResult.error(HttpStatus.NOT_FOUND.value(), "文件不存在"); + } + // FileDO 转换为 FileRespVO + FileRespVO fileRespVO = BeanUtils.toBean(fileDO, FileRespVO.class); + if (StrUtil.isEmpty(onlinePreview) || StrUtil.isEmpty(fileRespVO.getUrl())) { + return CommonResult.error(HttpStatus.BAD_REQUEST.value(), "在线预览地址未配置或文件 URL 为空"); + } + String previewUrl = onlinePreview + URLEncoder.encode(Base64.getEncoder().encodeToString(fileRespVO.getUrl().getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); + fileRespVO.setPreviewUrl(previewUrl); + return success(fileRespVO); + } + @PostMapping("/upload") @Operation(summary = "上传文件", description = "模式一:后端上传文件") @@ -135,14 +168,6 @@ public class FileController { return success(BeanUtils.toBean(pageResult, FileRespVO.class)); } - @GetMapping("/verification-code") - @Operation(summary = "获取加密文件下载验证码 ") - public CommonResult getVerificationCode(@RequestParam("fileId") Long fileId) { - Long userId = getLoginUserId(); - String code = fileService.generateFileVerificationCode(fileId, userId); - return success(code); - } - @GetMapping("/verify-and-download") @Operation(summary = "校验验证码并下载解密文件") public void verifyAndDownload(@Valid @RequestParam Long fileId, @RequestParam String code, HttpServletResponse response) throws Exception { @@ -157,15 +182,18 @@ public class FileController { } @GetMapping("/generate-download-code") @Operation(summary = "获取下载验证码") - public CommonResult preDownloadEncrypt(@RequestParam("fileId") Long fileId) { + public CommonResult preDownloadEncrypt(@RequestParam("fileId") Long fileId) { Long userId = getLoginUserId(); - FileDO activeFileById = new FileDO(); + FileDO activeFileById = fileService.getActiveFileById(fileId); + if (activeFileById == null) { + return CommonResult.error(HttpStatus.NOT_FOUND.value(), "文件不存在"); + } + FileRespVO fileRespVO = BeanUtils.toBean(activeFileById, FileRespVO.class); try { - activeFileById = fileService.getActiveFileById(fileId); fileService.generateFileVerificationCode(fileId, userId); - return CommonResult.customize(activeFileById.getName(), HttpStatus.OK.value(), "验证码已生成,请使用验证码下载文件"); + return CommonResult.customize(fileRespVO, HttpStatus.OK.value(), "验证码已生成,请使用验证码下载文件"); } catch (ServiceException e) { - return CommonResult.customize(activeFileById.getName(), HttpStatus.BAD_REQUEST.value(), e.getMessage()); + return CommonResult.customize(fileRespVO, HttpStatus.OK.value(), e.getMessage()); } } } diff --git a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/stdnms/StdNmsDO.java b/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/stdnms/StdNmsDO.java index e1ef563a..71832e93 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/stdnms/StdNmsDO.java +++ b/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/stdnms/StdNmsDO.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.module.system.dal.dataobject.stdnms; -import lombok.*; -import java.util.*; -import java.time.LocalDateTime; -import java.time.LocalDateTime; -import com.baomidou.mybatisplus.annotation.*; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; /** * 数据命名与简写标准 DO * @@ -42,6 +42,9 @@ public class StdNmsDO extends BaseDO { * 中文意思 */ private String info; - + /** + * 是否删除(取消逻辑删除) + */ + private Boolean deleted; } \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/stdnms/StdNmsMapper.java b/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/stdnms/StdNmsMapper.java index 5bd448ed..e21cb124 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/stdnms/StdNmsMapper.java +++ b/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/stdnms/StdNmsMapper.java @@ -1,13 +1,12 @@ package cn.iocoder.yudao.module.system.dal.mysql.stdnms; -import java.util.*; - import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.system.controller.admin.stdnms.vo.StdNmsPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.stdnms.StdNmsDO; import org.apache.ibatis.annotations.Mapper; -import cn.iocoder.yudao.module.system.controller.admin.stdnms.vo.*; + +import java.util.List; /** * 数据命名与简写标准 Mapper @@ -17,13 +16,13 @@ import cn.iocoder.yudao.module.system.controller.admin.stdnms.vo.*; @Mapper public interface StdNmsMapper extends BaseMapperX { - default PageResult selectPage(StdNmsPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(StdNmsDO::getWord, reqVO.getWord()) - .eqIfPresent(StdNmsDO::getAbbr, reqVO.getAbbr()) - .eqIfPresent(StdNmsDO::getInfo, reqVO.getInfo()) - .betweenIfPresent(StdNmsDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(StdNmsDO::getId)); - } + // 使用自定义 XML SQL 分页查询,word 不区分大小写 + List selectPageCustom(StdNmsPageReqVO reqVO); + + default PageResult selectPage(StdNmsPageReqVO reqVO) { + List records = selectPageCustom(reqVO); + // 这里只做简单封装,如需 total 可自定义 count SQL + return new PageResult<>(records, (long) records.size()); + } +} -} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-server/src/main/resources/application-local.yaml b/yudao-module-system/yudao-module-system-server/src/main/resources/application-local.yaml index 689136b3..0c4a6a4c 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/resources/application-local.yaml +++ b/yudao-module-system/yudao-module-system-server/src/main/resources/application-local.yaml @@ -84,7 +84,7 @@ rocketmq: xxl: job: - enabled: false # 是否开启调度中心,默认为 true 开启 + enabled: true # 是否开启调度中心,默认为 true 开启 admin: addresses: http://172.16.46.63:30082/xxl-job-admin # 调度中心部署跟地址 diff --git a/yudao-module-system/yudao-module-system-server/src/main/resources/mapper/stdnms/StdNmsMapper.xml b/yudao-module-system/yudao-module-system-server/src/main/resources/mapper/stdnms/StdNmsMapper.xml new file mode 100644 index 00000000..cd8d25ab --- /dev/null +++ b/yudao-module-system/yudao-module-system-server/src/main/resources/mapper/stdnms/StdNmsMapper.xml @@ -0,0 +1,24 @@ + + + + + + +