mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-01 22:53:29 +08:00
创建预授权URL后端日志记录
This commit is contained in:
@@ -349,6 +349,11 @@
|
||||
};
|
||||
xhr.onload = function (e) {
|
||||
console.log('上传成功', xhr.status, xhr.statusText);
|
||||
// 等待进度条走到 100% 否则小文件进度条还没有走完就提示上传完成会让人感觉有点奇怪
|
||||
setTimeout(function(){
|
||||
alert("上传成功!");
|
||||
window.location.reload();
|
||||
}, 300);
|
||||
};
|
||||
xhr.onerror = function (e) {
|
||||
console.log('上传出错', xhr.status, xhr.statusText);
|
||||
|
@@ -11,7 +11,7 @@
|
||||
Target Server Version : 50726
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 07/04/2022 11:32:50
|
||||
Date: 08/04/2022 18:21:08
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
@@ -112,6 +112,25 @@ INSERT INTO `category_info` VALUES (41, 'Java Web', '简介123', 1, 9, 3, 20);
|
||||
INSERT INTO `category_info` VALUES (42, 'Spring Cloud', '简介123', 1, 10, 3, 20);
|
||||
INSERT INTO `category_info` VALUES (43, '其他', '简介123', 1, 12, 1, 0);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for cos_presigned_url_generate_log
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `cos_presigned_url_generate_log`;
|
||||
CREATE TABLE `cos_presigned_url_generate_log` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增Id',
|
||||
`user_id` int(11) NOT NULL COMMENT '用户Id',
|
||||
`time` datetime NOT NULL COMMENT '链接生成时间',
|
||||
`expire_minute` int(255) NOT NULL COMMENT '链接有效期(单位:分钟)',
|
||||
`method` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '操作方法(上传请求用 PUT,下载请求用 GET,删除请求用 DELETE)',
|
||||
`file_path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '下载的文件链接',
|
||||
`url_guid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '链接生成时创建的全局唯一NanoID,便于出现异常下载记录与腾讯云下载日志做对应',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of cos_presigned_url_generate_log
|
||||
-- ----------------------------
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for file_info
|
||||
-- ----------------------------
|
||||
|
@@ -8,7 +8,9 @@ import com.qcloud.cos.auth.COSCredentials;
|
||||
import com.qcloud.cos.http.HttpMethodName;
|
||||
import com.qcloud.cos.http.HttpProtocol;
|
||||
import com.qcloud.cos.region.Region;
|
||||
import plus.bookshelf.Common.Error.BusinessException;
|
||||
import plus.bookshelf.Config.QCloudCosConfig;
|
||||
import plus.bookshelf.Service.Service.CosPresignedUrlGenerateLogService;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.net.URL;
|
||||
@@ -21,13 +23,17 @@ public class QCloudCosUtils {
|
||||
// 配置信息
|
||||
QCloudCosConfig qCloudCosConfig;
|
||||
|
||||
// 记录日志 Service
|
||||
CosPresignedUrlGenerateLogService cosPresignedUrlGenerateLogService;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @param qCloudCosConfig
|
||||
*/
|
||||
public QCloudCosUtils(QCloudCosConfig qCloudCosConfig) {
|
||||
public QCloudCosUtils(QCloudCosConfig qCloudCosConfig, CosPresignedUrlGenerateLogService cosPresignedUrlGenerateLogService) {
|
||||
this.qCloudCosConfig = qCloudCosConfig;
|
||||
this.cosPresignedUrlGenerateLogService = cosPresignedUrlGenerateLogService;
|
||||
}
|
||||
|
||||
private static COSClient _cosClient = null;
|
||||
@@ -93,7 +99,7 @@ public class QCloudCosUtils {
|
||||
* @param expireMinute 过期时间
|
||||
* @return
|
||||
*/
|
||||
public String generatePresignedUrl(String token, HttpMethodName httpMethodName, String objectKey, Integer expireMinute) {
|
||||
public String generatePresignedUrl(Integer userId, HttpMethodName httpMethodName, String objectKey, Integer expireMinute) throws BusinessException {
|
||||
// 调用 COS 接口之前必须保证本进程存在一个 COSClient 实例,如果没有则创建
|
||||
// 详细代码参见本页:简单操作 -> 创建 COSClient
|
||||
// COSClient cosClient = createCOSClient();
|
||||
@@ -110,10 +116,10 @@ public class QCloudCosUtils {
|
||||
|
||||
// 填写本次请求的参数,需与实际请求相同,能够防止用户篡改此签名的 HTTP 请求的参数
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("poweredBy", "bookshelf.plus");
|
||||
params.put("userToken", token);
|
||||
String downloadGUID = NanoIdUtils.randomNanoId();
|
||||
params.put("downloadGUID", downloadGUID); // 当次生成下载链接的全局唯一Id
|
||||
params.put("by", "书栖网 bookshelf.plus");
|
||||
params.put("userId", String.valueOf(userId));
|
||||
String urlGUID = NanoIdUtils.randomNanoId();
|
||||
params.put("guid", urlGUID); // 当次生成下载链接的全局唯一Id
|
||||
|
||||
// 填写本次请求的头部,需与实际请求相同,能够防止用户篡改此签名的 HTTP 请求的头部
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
@@ -125,6 +131,9 @@ public class QCloudCosUtils {
|
||||
URL url = cosClient.generatePresignedUrl(bucketName, key, expirationDate, method, headers, params);
|
||||
// System.out.println(url.toString());
|
||||
|
||||
// 记录用户操作日志
|
||||
cosPresignedUrlGenerateLogService.log(userId, expireMinute, httpMethodName.name(), key, urlGUID);
|
||||
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
|
@@ -13,6 +13,7 @@ import plus.bookshelf.Common.Response.CommonReturnType;
|
||||
import plus.bookshelf.Config.QCloudCosConfig;
|
||||
import plus.bookshelf.Service.Impl.UserServiceImpl;
|
||||
import plus.bookshelf.Service.Model.UserModel;
|
||||
import plus.bookshelf.Service.Service.CosPresignedUrlGenerateLogService;
|
||||
|
||||
@Api(tags = "文件管理")
|
||||
@Controller("file")
|
||||
@@ -25,6 +26,9 @@ public class FileController extends BaseController {
|
||||
@Autowired
|
||||
UserServiceImpl userService;
|
||||
|
||||
@Autowired
|
||||
CosPresignedUrlGenerateLogService cosPresignedUrlGenerateLogService;
|
||||
|
||||
/**
|
||||
* 创建文件操作预授权URL
|
||||
*
|
||||
@@ -61,7 +65,7 @@ public class FileController extends BaseController {
|
||||
throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "httpMethod 参数不合法");
|
||||
}
|
||||
|
||||
QCloudCosUtils qCloudCosUtils = new QCloudCosUtils(qCloudCosConfig);
|
||||
QCloudCosUtils qCloudCosUtils = new QCloudCosUtils(qCloudCosConfig, cosPresignedUrlGenerateLogService);
|
||||
|
||||
// 判断对象是否存在
|
||||
Boolean isExist = qCloudCosUtils.doesObjectExist(fileName);
|
||||
@@ -77,7 +81,7 @@ public class FileController extends BaseController {
|
||||
throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "httpMethod 参数暂不支持");
|
||||
}
|
||||
|
||||
String url = qCloudCosUtils.generatePresignedUrl(token, httpMethodName, fileName, 30);
|
||||
String url = qCloudCosUtils.generatePresignedUrl(userModel.getId(), httpMethodName, fileName, 30);
|
||||
|
||||
return CommonReturnType.create(url);
|
||||
}
|
||||
|
@@ -2,11 +2,11 @@ package plus.bookshelf.Dao.DO;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class FileOperationDO {
|
||||
public class CosPresignedUrlGenerateLogDO {
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_operation_log.id
|
||||
* This field corresponds to the database column cos_presigned_url_generate_log.id
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -15,7 +15,7 @@ public class FileOperationDO {
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_operation_log.user_id
|
||||
* This field corresponds to the database column cos_presigned_url_generate_log.user_id
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -24,7 +24,7 @@ public class FileOperationDO {
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_operation_log.time
|
||||
* This field corresponds to the database column cos_presigned_url_generate_log.time
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -33,16 +33,16 @@ public class FileOperationDO {
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_operation_log.expire_minute
|
||||
* This field corresponds to the database column cos_presigned_url_generate_log.expire_minute
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private String expireMinute;
|
||||
private Integer expireMinute;
|
||||
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_operation_log.method
|
||||
* This field corresponds to the database column cos_presigned_url_generate_log.method
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -51,7 +51,7 @@ public class FileOperationDO {
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_operation_log.file_path
|
||||
* This field corresponds to the database column cos_presigned_url_generate_log.file_path
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -60,7 +60,7 @@ public class FileOperationDO {
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_operation_log.url_guid
|
||||
* This field corresponds to the database column cos_presigned_url_generate_log.url_guid
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -68,9 +68,9 @@ public class FileOperationDO {
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_operation_log.id
|
||||
* This method returns the value of the database column cos_presigned_url_generate_log.id
|
||||
*
|
||||
* @return the value of file_operation_log.id
|
||||
* @return the value of cos_presigned_url_generate_log.id
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -80,9 +80,9 @@ public class FileOperationDO {
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_operation_log.id
|
||||
* This method sets the value of the database column cos_presigned_url_generate_log.id
|
||||
*
|
||||
* @param id the value for file_operation_log.id
|
||||
* @param id the value for cos_presigned_url_generate_log.id
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -92,9 +92,9 @@ public class FileOperationDO {
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_operation_log.user_id
|
||||
* This method returns the value of the database column cos_presigned_url_generate_log.user_id
|
||||
*
|
||||
* @return the value of file_operation_log.user_id
|
||||
* @return the value of cos_presigned_url_generate_log.user_id
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -104,9 +104,9 @@ public class FileOperationDO {
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_operation_log.user_id
|
||||
* This method sets the value of the database column cos_presigned_url_generate_log.user_id
|
||||
*
|
||||
* @param userId the value for file_operation_log.user_id
|
||||
* @param userId the value for cos_presigned_url_generate_log.user_id
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -116,9 +116,9 @@ public class FileOperationDO {
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_operation_log.time
|
||||
* This method returns the value of the database column cos_presigned_url_generate_log.time
|
||||
*
|
||||
* @return the value of file_operation_log.time
|
||||
* @return the value of cos_presigned_url_generate_log.time
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -128,9 +128,9 @@ public class FileOperationDO {
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_operation_log.time
|
||||
* This method sets the value of the database column cos_presigned_url_generate_log.time
|
||||
*
|
||||
* @param time the value for file_operation_log.time
|
||||
* @param time the value for cos_presigned_url_generate_log.time
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -140,33 +140,33 @@ public class FileOperationDO {
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_operation_log.expire_minute
|
||||
* This method returns the value of the database column cos_presigned_url_generate_log.expire_minute
|
||||
*
|
||||
* @return the value of file_operation_log.expire_minute
|
||||
* @return the value of cos_presigned_url_generate_log.expire_minute
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getExpireMinute() {
|
||||
public Integer getExpireMinute() {
|
||||
return expireMinute;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_operation_log.expire_minute
|
||||
* This method sets the value of the database column cos_presigned_url_generate_log.expire_minute
|
||||
*
|
||||
* @param expireMinute the value for file_operation_log.expire_minute
|
||||
* @param expireMinute the value for cos_presigned_url_generate_log.expire_minute
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setExpireMinute(String expireMinute) {
|
||||
this.expireMinute = expireMinute == null ? null : expireMinute.trim();
|
||||
public void setExpireMinute(Integer expireMinute) {
|
||||
this.expireMinute = expireMinute;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_operation_log.method
|
||||
* This method returns the value of the database column cos_presigned_url_generate_log.method
|
||||
*
|
||||
* @return the value of file_operation_log.method
|
||||
* @return the value of cos_presigned_url_generate_log.method
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -176,9 +176,9 @@ public class FileOperationDO {
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_operation_log.method
|
||||
* This method sets the value of the database column cos_presigned_url_generate_log.method
|
||||
*
|
||||
* @param method the value for file_operation_log.method
|
||||
* @param method the value for cos_presigned_url_generate_log.method
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -188,9 +188,9 @@ public class FileOperationDO {
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_operation_log.file_path
|
||||
* This method returns the value of the database column cos_presigned_url_generate_log.file_path
|
||||
*
|
||||
* @return the value of file_operation_log.file_path
|
||||
* @return the value of cos_presigned_url_generate_log.file_path
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -200,9 +200,9 @@ public class FileOperationDO {
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_operation_log.file_path
|
||||
* This method sets the value of the database column cos_presigned_url_generate_log.file_path
|
||||
*
|
||||
* @param filePath the value for file_operation_log.file_path
|
||||
* @param filePath the value for cos_presigned_url_generate_log.file_path
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -212,9 +212,9 @@ public class FileOperationDO {
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_operation_log.url_guid
|
||||
* This method returns the value of the database column cos_presigned_url_generate_log.url_guid
|
||||
*
|
||||
* @return the value of file_operation_log.url_guid
|
||||
* @return the value of cos_presigned_url_generate_log.url_guid
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
@@ -224,9 +224,9 @@ public class FileOperationDO {
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_operation_log.url_guid
|
||||
* This method sets the value of the database column cos_presigned_url_generate_log.url_guid
|
||||
*
|
||||
* @param urlGuid the value for file_operation_log.url_guid
|
||||
* @param urlGuid the value for cos_presigned_url_generate_log.url_guid
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
@@ -0,0 +1,55 @@
|
||||
package plus.bookshelf.Dao.Mapper;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
import plus.bookshelf.Dao.DO.CosPresignedUrlGenerateLogDO;
|
||||
|
||||
@Repository // 添加这个注解,Autowired的时候idea就不会报错了
|
||||
public interface CosPresignedUrlGenerateLogDOMapper {
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table cos_presigned_url_generate_log
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table cos_presigned_url_generate_log
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
int insert(CosPresignedUrlGenerateLogDO record);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table cos_presigned_url_generate_log
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
int insertSelective(CosPresignedUrlGenerateLogDO record);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table cos_presigned_url_generate_log
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
CosPresignedUrlGenerateLogDO selectByPrimaryKey(Integer id);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table cos_presigned_url_generate_log
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
int updateByPrimaryKeySelective(CosPresignedUrlGenerateLogDO record);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table cos_presigned_url_generate_log
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
int updateByPrimaryKey(CosPresignedUrlGenerateLogDO record);
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
package plus.bookshelf.Dao.Mapper;
|
||||
|
||||
import plus.bookshelf.Dao.DO.FileOperationDO;
|
||||
|
||||
public interface FileOperationDOMapper {
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table file_operation_log
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table file_operation_log
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
int insert(FileOperationDO record);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table file_operation_log
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
int insertSelective(FileOperationDO record);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table file_operation_log
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
FileOperationDO selectByPrimaryKey(Integer id);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table file_operation_log
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
int updateByPrimaryKeySelective(FileOperationDO record);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table file_operation_log
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
int updateByPrimaryKey(FileOperationDO record);
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
package plus.bookshelf.Service.Impl;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import plus.bookshelf.Common.Error.BusinessErrorCode;
|
||||
import plus.bookshelf.Common.Error.BusinessException;
|
||||
import plus.bookshelf.Dao.DO.CosPresignedUrlGenerateLogDO;
|
||||
import plus.bookshelf.Dao.Mapper.CosPresignedUrlGenerateLogDOMapper;
|
||||
import plus.bookshelf.Service.Service.CosPresignedUrlGenerateLogService;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
public class CosPresignedUrlGenerateLogServiceImpl implements CosPresignedUrlGenerateLogService {
|
||||
|
||||
@Autowired
|
||||
CosPresignedUrlGenerateLogDOMapper cosPresignedUrlGenerateLogDOMapper;
|
||||
|
||||
/**
|
||||
* 记录cos获取的预授权url日志
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param expireTime 过期时间(分钟)
|
||||
* @param method 请求方法
|
||||
* @param filePath 文件路径
|
||||
* @param urlGuid url唯一标识
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public void log(Integer userId, Integer expireTime, String method, String filePath, String urlGuid) throws BusinessException {
|
||||
CosPresignedUrlGenerateLogDO cosPresignedUrlGenerateLogDO = new CosPresignedUrlGenerateLogDO();
|
||||
cosPresignedUrlGenerateLogDO.setUserId(userId);
|
||||
cosPresignedUrlGenerateLogDO.setTime(new Date());
|
||||
cosPresignedUrlGenerateLogDO.setExpireMinute(expireTime);
|
||||
cosPresignedUrlGenerateLogDO.setMethod(method);
|
||||
cosPresignedUrlGenerateLogDO.setFilePath(filePath);
|
||||
cosPresignedUrlGenerateLogDO.setUrlGuid(urlGuid);
|
||||
|
||||
Integer affectRows = cosPresignedUrlGenerateLogDOMapper.insertSelective(cosPresignedUrlGenerateLogDO);
|
||||
if (affectRows == 0) {
|
||||
throw new BusinessException(BusinessErrorCode.UNKNOWN_ERROR, "日志记录失败");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package plus.bookshelf.Service.Service;
|
||||
|
||||
import plus.bookshelf.Common.Error.BusinessException;
|
||||
|
||||
public interface CosPresignedUrlGenerateLogService {
|
||||
/**
|
||||
* 记录cos获取的预授权url日志
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param expireTime 过期时间(分钟)
|
||||
* @param method 请求方法
|
||||
* @param filePath 文件路径
|
||||
* @param urlGuid url唯一标识
|
||||
* @return
|
||||
*/
|
||||
void log(Integer userId, Integer expireTime, String method, String filePath, String urlGuid) throws BusinessException;
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
<?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="plus.bookshelf.Dao.Mapper.FileOperationDOMapper">
|
||||
<resultMap id="BaseResultMap" type="plus.bookshelf.Dao.DO.FileOperationDO">
|
||||
<mapper namespace="plus.bookshelf.Dao.Mapper.CosPresignedUrlGenerateLogDOMapper">
|
||||
<resultMap id="BaseResultMap" type="plus.bookshelf.Dao.DO.CosPresignedUrlGenerateLogDO">
|
||||
<!--
|
||||
WARNING - @mbg.generated
|
||||
This element is automatically generated by MyBatis Generator, do not modify.
|
||||
@@ -9,7 +9,7 @@
|
||||
<id column="id" jdbcType="INTEGER" property="id" />
|
||||
<result column="user_id" jdbcType="INTEGER" property="userId" />
|
||||
<result column="time" jdbcType="TIMESTAMP" property="time" />
|
||||
<result column="expire_minute" jdbcType="VARCHAR" property="expireMinute" />
|
||||
<result column="expire_minute" jdbcType="INTEGER" property="expireMinute" />
|
||||
<result column="method" jdbcType="VARCHAR" property="method" />
|
||||
<result column="file_path" jdbcType="VARCHAR" property="filePath" />
|
||||
<result column="url_guid" jdbcType="VARCHAR" property="urlGuid" />
|
||||
@@ -28,7 +28,7 @@
|
||||
-->
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from file_operation_log
|
||||
from cos_presigned_url_generate_log
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
||||
@@ -36,27 +36,27 @@
|
||||
WARNING - @mbg.generated
|
||||
This element is automatically generated by MyBatis Generator, do not modify.
|
||||
-->
|
||||
delete from file_operation_log
|
||||
delete from cos_presigned_url_generate_log
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</delete>
|
||||
<insert id="insert" parameterType="plus.bookshelf.Dao.DO.FileOperationDO">
|
||||
<insert id="insert" parameterType="plus.bookshelf.Dao.DO.CosPresignedUrlGenerateLogDO">
|
||||
<!--
|
||||
WARNING - @mbg.generated
|
||||
This element is automatically generated by MyBatis Generator, do not modify.
|
||||
-->
|
||||
insert into file_operation_log (id, user_id, `time`,
|
||||
insert into cos_presigned_url_generate_log (id, user_id, `time`,
|
||||
expire_minute, `method`, file_path,
|
||||
url_guid)
|
||||
values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{time,jdbcType=TIMESTAMP},
|
||||
#{expireMinute,jdbcType=VARCHAR}, #{method,jdbcType=VARCHAR}, #{filePath,jdbcType=VARCHAR},
|
||||
#{expireMinute,jdbcType=INTEGER}, #{method,jdbcType=VARCHAR}, #{filePath,jdbcType=VARCHAR},
|
||||
#{urlGuid,jdbcType=VARCHAR})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="plus.bookshelf.Dao.DO.FileOperationDO">
|
||||
<insert id="insertSelective" parameterType="plus.bookshelf.Dao.DO.CosPresignedUrlGenerateLogDO">
|
||||
<!--
|
||||
WARNING - @mbg.generated
|
||||
This element is automatically generated by MyBatis Generator, do not modify.
|
||||
-->
|
||||
insert into file_operation_log
|
||||
insert into cos_presigned_url_generate_log
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">
|
||||
id,
|
||||
@@ -91,7 +91,7 @@
|
||||
#{time,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="expireMinute != null">
|
||||
#{expireMinute,jdbcType=VARCHAR},
|
||||
#{expireMinute,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="method != null">
|
||||
#{method,jdbcType=VARCHAR},
|
||||
@@ -104,12 +104,12 @@
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="plus.bookshelf.Dao.DO.FileOperationDO">
|
||||
<update id="updateByPrimaryKeySelective" parameterType="plus.bookshelf.Dao.DO.CosPresignedUrlGenerateLogDO">
|
||||
<!--
|
||||
WARNING - @mbg.generated
|
||||
This element is automatically generated by MyBatis Generator, do not modify.
|
||||
-->
|
||||
update file_operation_log
|
||||
update cos_presigned_url_generate_log
|
||||
<set>
|
||||
<if test="userId != null">
|
||||
user_id = #{userId,jdbcType=INTEGER},
|
||||
@@ -118,7 +118,7 @@
|
||||
`time` = #{time,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="expireMinute != null">
|
||||
expire_minute = #{expireMinute,jdbcType=VARCHAR},
|
||||
expire_minute = #{expireMinute,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="method != null">
|
||||
`method` = #{method,jdbcType=VARCHAR},
|
||||
@@ -132,15 +132,15 @@
|
||||
</set>
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="plus.bookshelf.Dao.DO.FileOperationDO">
|
||||
<update id="updateByPrimaryKey" parameterType="plus.bookshelf.Dao.DO.CosPresignedUrlGenerateLogDO">
|
||||
<!--
|
||||
WARNING - @mbg.generated
|
||||
This element is automatically generated by MyBatis Generator, do not modify.
|
||||
-->
|
||||
update file_operation_log
|
||||
update cos_presigned_url_generate_log
|
||||
set user_id = #{userId,jdbcType=INTEGER},
|
||||
`time` = #{time,jdbcType=TIMESTAMP},
|
||||
expire_minute = #{expireMinute,jdbcType=VARCHAR},
|
||||
expire_minute = #{expireMinute,jdbcType=INTEGER},
|
||||
`method` = #{method,jdbcType=VARCHAR},
|
||||
file_path = #{filePath,jdbcType=VARCHAR},
|
||||
url_guid = #{urlGuid,jdbcType=VARCHAR}
|
@@ -97,7 +97,7 @@
|
||||
<!--<table tableName="user_book_favorites_relation" domainObjectName="UserFavoritesDO" enableCountByExample="false"-->
|
||||
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"-->
|
||||
<!-- selectByExampleQueryId="false"></table>-->
|
||||
<!--<table tableName="file_operation_log" domainObjectName="FileOperationDO" enableCountByExample="false"-->
|
||||
<!--<table tableName="cos_presigned_url_generate_log" domainObjectName="CosPresignedUrlGenerateLogDO" enableCountByExample="false"-->
|
||||
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"-->
|
||||
<!-- selectByExampleQueryId="false"></table>-->
|
||||
</context>
|
||||
|
Reference in New Issue
Block a user