1. 重构附件加密下载验证码获取流程
2. 新增简写命名字典功能
This commit is contained in:
@@ -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<FileRespVO> 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<FileRespVO> 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<String> 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<String> preDownloadEncrypt(@RequestParam("fileId") Long fileId) {
|
||||
public CommonResult<FileRespVO> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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<StdNmsDO> {
|
||||
|
||||
// 使用自定义 XML SQL 分页查询,word 不区分大小写
|
||||
List<StdNmsDO> selectPageCustom(StdNmsPageReqVO reqVO);
|
||||
|
||||
default PageResult<StdNmsDO> selectPage(StdNmsPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<StdNmsDO>()
|
||||
.eqIfPresent(StdNmsDO::getWord, reqVO.getWord())
|
||||
.eqIfPresent(StdNmsDO::getAbbr, reqVO.getAbbr())
|
||||
.eqIfPresent(StdNmsDO::getInfo, reqVO.getInfo())
|
||||
.betweenIfPresent(StdNmsDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(StdNmsDO::getId));
|
||||
List<StdNmsDO> records = selectPageCustom(reqVO);
|
||||
// 这里只做简单封装,如需 total 可自定义 count SQL
|
||||
return new PageResult<>(records, (long) records.size());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -84,7 +84,7 @@ rocketmq:
|
||||
|
||||
xxl:
|
||||
job:
|
||||
enabled: false # 是否开启调度中心,默认为 true 开启
|
||||
enabled: true # 是否开启调度中心,默认为 true 开启
|
||||
admin:
|
||||
addresses: http://172.16.46.63:30082/xxl-job-admin # 调度中心部署跟地址
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?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="cn.iocoder.yudao.module.system.dal.mysql.stdnms.StdNmsMapper">
|
||||
|
||||
<select id="selectPageCustom" resultType="cn.iocoder.yudao.module.system.dal.dataobject.stdnms.StdNmsDO">
|
||||
SELECT * FROM system_std_nms
|
||||
<where>
|
||||
<if test="word != null and word != ''">
|
||||
AND LOWER(word) LIKE CONCAT('%', LOWER(#{word}), '%')
|
||||
</if>
|
||||
<if test="abbr != null and abbr != ''">
|
||||
AND abbr = #{abbr}
|
||||
</if>
|
||||
<if test="info != null and info != ''">
|
||||
AND info = #{info}
|
||||
</if>
|
||||
<if test="createTime != null and createTime[0] != null and createTime[1] != null">
|
||||
AND create_time BETWEEN #{createTime[0]} AND #{createTime[1]}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY id DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user