feat(user-call-log): 新增用户调用日志管理功能
新增用户调用日志模块,包含Controller、DO、Mapper、Service及VO等完整结构,支持记录用户每次调用的token、模型、耗时与成功率信息,并补充对应错误码常量。
This commit is contained in:
@@ -0,0 +1,104 @@
|
|||||||
|
package com.yolo.keyboard.controller.admin.usercalllog;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.*;
|
||||||
|
import jakarta.validation.*;
|
||||||
|
import jakarta.servlet.http.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||||
|
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||||
|
import com.yolo.keyboard.framework.common.pojo.CommonResult;
|
||||||
|
import com.yolo.keyboard.framework.common.util.object.BeanUtils;
|
||||||
|
import static com.yolo.keyboard.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
import com.yolo.keyboard.framework.excel.core.util.ExcelUtils;
|
||||||
|
|
||||||
|
import com.yolo.keyboard.framework.apilog.core.annotation.ApiAccessLog;
|
||||||
|
import static com.yolo.keyboard.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||||
|
|
||||||
|
import com.yolo.keyboard.controller.admin.usercalllog.vo.*;
|
||||||
|
import com.yolo.keyboard.dal.dataobject.usercalllog.KeyboardUserCallLogDO;
|
||||||
|
import com.yolo.keyboard.service.usercalllog.KeyboardUserCallLogService;
|
||||||
|
|
||||||
|
@Tag(name = "管理后台 - 用户每次调用日志(用于记录token、模型、耗时、成功率等)")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/keyboard/user-call-log")
|
||||||
|
@Validated
|
||||||
|
public class KeyboardUserCallLogController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private KeyboardUserCallLogService userCallLogService;
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@Operation(summary = "创建用户每次调用日志(用于记录token、模型、耗时、成功率等)")
|
||||||
|
@PreAuthorize("@ss.hasPermission('keyboard:user-call-log:create')")
|
||||||
|
public CommonResult<Long> createUserCallLog(@Valid @RequestBody KeyboardUserCallLogSaveReqVO createReqVO) {
|
||||||
|
return success(userCallLogService.createUserCallLog(createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update")
|
||||||
|
@Operation(summary = "更新用户每次调用日志(用于记录token、模型、耗时、成功率等)")
|
||||||
|
@PreAuthorize("@ss.hasPermission('keyboard:user-call-log:update')")
|
||||||
|
public CommonResult<Boolean> updateUserCallLog(@Valid @RequestBody KeyboardUserCallLogSaveReqVO updateReqVO) {
|
||||||
|
userCallLogService.updateUserCallLog(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
@Operation(summary = "删除用户每次调用日志(用于记录token、模型、耗时、成功率等)")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('keyboard:user-call-log:delete')")
|
||||||
|
public CommonResult<Boolean> deleteUserCallLog(@RequestParam("id") Long id) {
|
||||||
|
userCallLogService.deleteUserCallLog(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete-list")
|
||||||
|
@Parameter(name = "ids", description = "编号", required = true)
|
||||||
|
@Operation(summary = "批量删除用户每次调用日志(用于记录token、模型、耗时、成功率等)")
|
||||||
|
@PreAuthorize("@ss.hasPermission('keyboard:user-call-log:delete')")
|
||||||
|
public CommonResult<Boolean> deleteUserCallLogList(@RequestParam("ids") List<Long> ids) {
|
||||||
|
userCallLogService.deleteUserCallLogListByIds(ids);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get")
|
||||||
|
@Operation(summary = "获得用户每次调用日志(用于记录token、模型、耗时、成功率等)")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
@PreAuthorize("@ss.hasPermission('keyboard:user-call-log:query')")
|
||||||
|
public CommonResult<KeyboardUserCallLogRespVO> getUserCallLog(@RequestParam("id") Long id) {
|
||||||
|
KeyboardUserCallLogDO userCallLog = userCallLogService.getUserCallLog(id);
|
||||||
|
return success(BeanUtils.toBean(userCallLog, KeyboardUserCallLogRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "获得用户每次调用日志(用于记录token、模型、耗时、成功率等)分页")
|
||||||
|
@PreAuthorize("@ss.hasPermission('keyboard:user-call-log:query')")
|
||||||
|
public CommonResult<PageResult<KeyboardUserCallLogRespVO>> getUserCallLogPage(@Valid KeyboardUserCallLogPageReqVO pageReqVO) {
|
||||||
|
PageResult<KeyboardUserCallLogDO> pageResult = userCallLogService.getUserCallLogPage(pageReqVO);
|
||||||
|
return success(BeanUtils.toBean(pageResult, KeyboardUserCallLogRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/export-excel")
|
||||||
|
@Operation(summary = "导出用户每次调用日志(用于记录token、模型、耗时、成功率等) Excel")
|
||||||
|
@PreAuthorize("@ss.hasPermission('keyboard:user-call-log:export')")
|
||||||
|
@ApiAccessLog(operateType = EXPORT)
|
||||||
|
public void exportUserCallLogExcel(@Valid KeyboardUserCallLogPageReqVO pageReqVO,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||||
|
List<KeyboardUserCallLogDO> list = userCallLogService.getUserCallLogPage(pageReqVO).getList();
|
||||||
|
// 导出 Excel
|
||||||
|
ExcelUtils.write(response, "用户每次调用日志(用于记录token、模型、耗时、成功率等).xls", "数据", KeyboardUserCallLogRespVO.class,
|
||||||
|
BeanUtils.toBean(list, KeyboardUserCallLogRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.yolo.keyboard.controller.admin.usercalllog.vo;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static com.yolo.keyboard.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 用户每次调用日志(用于记录token、模型、耗时、成功率等)分页 Request VO")
|
||||||
|
@Data
|
||||||
|
public class KeyboardUserCallLogPageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@Schema(description = "用户ID", example = "22552")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Schema(description = "幂等请求ID,避免重试导致重复记录", example = "12645")
|
||||||
|
private String requestId;
|
||||||
|
|
||||||
|
@Schema(description = "调用功能来源")
|
||||||
|
private String feature;
|
||||||
|
|
||||||
|
@Schema(description = "调用的模型名称")
|
||||||
|
private String model;
|
||||||
|
|
||||||
|
@Schema(description = "输入token数")
|
||||||
|
private Integer inputTokens;
|
||||||
|
|
||||||
|
@Schema(description = "输出token数")
|
||||||
|
private Integer outputTokens;
|
||||||
|
|
||||||
|
@Schema(description = "总token数(input+output)")
|
||||||
|
private Integer totalTokens;
|
||||||
|
|
||||||
|
@Schema(description = "调用是否成功")
|
||||||
|
private Boolean success;
|
||||||
|
|
||||||
|
@Schema(description = "调用耗时(毫秒)")
|
||||||
|
private Integer latencyMs;
|
||||||
|
|
||||||
|
@Schema(description = "失败错误码(可空)")
|
||||||
|
private String errorCode;
|
||||||
|
|
||||||
|
@Schema(description = "调用记录创建时间")
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
@Schema(description = "生成 id", example = "2813")
|
||||||
|
private String genId;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package com.yolo.keyboard.controller.admin.usercalllog.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import cn.idev.excel.annotation.*;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 用户每次调用日志(用于记录token、模型、耗时、成功率等) Response VO")
|
||||||
|
@Data
|
||||||
|
@ExcelIgnoreUnannotated
|
||||||
|
public class KeyboardUserCallLogRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "主键 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "32537")
|
||||||
|
@ExcelProperty("主键 id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "22552")
|
||||||
|
@ExcelProperty("用户ID")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Schema(description = "幂等请求ID,避免重试导致重复记录", requiredMode = Schema.RequiredMode.REQUIRED, example = "12645")
|
||||||
|
@ExcelProperty("幂等请求ID,避免重试导致重复记录")
|
||||||
|
private String requestId;
|
||||||
|
|
||||||
|
@Schema(description = "调用功能来源", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("调用功能来源")
|
||||||
|
private String feature;
|
||||||
|
|
||||||
|
@Schema(description = "调用的模型名称")
|
||||||
|
@ExcelProperty("调用的模型名称")
|
||||||
|
private String model;
|
||||||
|
|
||||||
|
@Schema(description = "输入token数", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("输入token数")
|
||||||
|
private Integer inputTokens;
|
||||||
|
|
||||||
|
@Schema(description = "输出token数", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("输出token数")
|
||||||
|
private Integer outputTokens;
|
||||||
|
|
||||||
|
@Schema(description = "总token数(input+output)", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("总token数(input+output)")
|
||||||
|
private Integer totalTokens;
|
||||||
|
|
||||||
|
@Schema(description = "调用是否成功", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("调用是否成功")
|
||||||
|
private Boolean success;
|
||||||
|
|
||||||
|
@Schema(description = "调用耗时(毫秒)")
|
||||||
|
@ExcelProperty("调用耗时(毫秒)")
|
||||||
|
private Integer latencyMs;
|
||||||
|
|
||||||
|
@Schema(description = "失败错误码(可空)")
|
||||||
|
@ExcelProperty("失败错误码(可空)")
|
||||||
|
private String errorCode;
|
||||||
|
|
||||||
|
@Schema(description = "调用记录创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("调用记录创建时间")
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
@Schema(description = "生成 id", example = "2813")
|
||||||
|
@ExcelProperty("生成 id")
|
||||||
|
private String genId;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.yolo.keyboard.controller.admin.usercalllog.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import jakarta.validation.constraints.*;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 用户每次调用日志(用于记录token、模型、耗时、成功率等)新增/修改 Request VO")
|
||||||
|
@Data
|
||||||
|
public class KeyboardUserCallLogSaveReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "主键 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "32537")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "用户ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "22552")
|
||||||
|
@NotNull(message = "用户ID不能为空")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Schema(description = "幂等请求ID,避免重试导致重复记录", requiredMode = Schema.RequiredMode.REQUIRED, example = "12645")
|
||||||
|
@NotEmpty(message = "幂等请求ID,避免重试导致重复记录不能为空")
|
||||||
|
private String requestId;
|
||||||
|
|
||||||
|
@Schema(description = "调用功能来源", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotEmpty(message = "调用功能来源不能为空")
|
||||||
|
private String feature;
|
||||||
|
|
||||||
|
@Schema(description = "调用的模型名称")
|
||||||
|
private String model;
|
||||||
|
|
||||||
|
@Schema(description = "输入token数", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "输入token数不能为空")
|
||||||
|
private Integer inputTokens;
|
||||||
|
|
||||||
|
@Schema(description = "输出token数", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "输出token数不能为空")
|
||||||
|
private Integer outputTokens;
|
||||||
|
|
||||||
|
@Schema(description = "总token数(input+output)", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "总token数(input+output)不能为空")
|
||||||
|
private Integer totalTokens;
|
||||||
|
|
||||||
|
@Schema(description = "调用是否成功", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "调用是否成功不能为空")
|
||||||
|
private Boolean success;
|
||||||
|
|
||||||
|
@Schema(description = "调用耗时(毫秒)")
|
||||||
|
private Integer latencyMs;
|
||||||
|
|
||||||
|
@Schema(description = "失败错误码(可空)")
|
||||||
|
private String errorCode;
|
||||||
|
|
||||||
|
@Schema(description = "调用记录创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "调用记录创建时间不能为空")
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
@Schema(description = "生成 id", example = "2813")
|
||||||
|
private String genId;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package com.yolo.keyboard.dal.dataobject.usercalllog;
|
||||||
|
|
||||||
|
import com.yolo.keyboard.framework.tenant.core.aop.TenantIgnore;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import com.yolo.keyboard.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户每次调用日志(用于记录token、模型、耗时、成功率等) DO
|
||||||
|
*
|
||||||
|
* @author Ziin
|
||||||
|
*/
|
||||||
|
@TableName("keyboard_user_call_log")
|
||||||
|
@KeySequence("keyboard_user_call_log_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
|
@Data
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@TenantIgnore
|
||||||
|
public class KeyboardUserCallLogDO{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键 id
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 用户ID
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
/**
|
||||||
|
* 幂等请求ID,避免重试导致重复记录
|
||||||
|
*/
|
||||||
|
private String requestId;
|
||||||
|
/**
|
||||||
|
* 调用功能来源
|
||||||
|
*/
|
||||||
|
private String feature;
|
||||||
|
/**
|
||||||
|
* 调用的模型名称
|
||||||
|
*/
|
||||||
|
private String model;
|
||||||
|
/**
|
||||||
|
* 输入token数
|
||||||
|
*/
|
||||||
|
private Integer inputTokens;
|
||||||
|
/**
|
||||||
|
* 输出token数
|
||||||
|
*/
|
||||||
|
private Integer outputTokens;
|
||||||
|
/**
|
||||||
|
* 总token数(input+output)
|
||||||
|
*/
|
||||||
|
private Integer totalTokens;
|
||||||
|
/**
|
||||||
|
* 调用是否成功
|
||||||
|
*/
|
||||||
|
private Boolean success;
|
||||||
|
/**
|
||||||
|
* 调用耗时(毫秒)
|
||||||
|
*/
|
||||||
|
private Integer latencyMs;
|
||||||
|
/**
|
||||||
|
* 失败错误码(可空)
|
||||||
|
*/
|
||||||
|
private String errorCode;
|
||||||
|
/**
|
||||||
|
* 调用记录创建时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
/**
|
||||||
|
* 生成 id
|
||||||
|
*/
|
||||||
|
private String genId;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.yolo.keyboard.dal.mysql.usercalllog;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||||
|
import com.yolo.keyboard.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
|
import com.yolo.keyboard.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import com.yolo.keyboard.dal.dataobject.usercalllog.KeyboardUserCallLogDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import com.yolo.keyboard.controller.admin.usercalllog.vo.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户每次调用日志(用于记录token、模型、耗时、成功率等) Mapper
|
||||||
|
*
|
||||||
|
* @author Ziin
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface KeyboardUserCallLogMapper extends BaseMapperX<KeyboardUserCallLogDO> {
|
||||||
|
|
||||||
|
default PageResult<KeyboardUserCallLogDO> selectPage(KeyboardUserCallLogPageReqVO reqVO) {
|
||||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<KeyboardUserCallLogDO>()
|
||||||
|
.eqIfPresent(KeyboardUserCallLogDO::getUserId, reqVO.getUserId())
|
||||||
|
.eqIfPresent(KeyboardUserCallLogDO::getRequestId, reqVO.getRequestId())
|
||||||
|
.eqIfPresent(KeyboardUserCallLogDO::getFeature, reqVO.getFeature())
|
||||||
|
.eqIfPresent(KeyboardUserCallLogDO::getModel, reqVO.getModel())
|
||||||
|
.eqIfPresent(KeyboardUserCallLogDO::getInputTokens, reqVO.getInputTokens())
|
||||||
|
.eqIfPresent(KeyboardUserCallLogDO::getOutputTokens, reqVO.getOutputTokens())
|
||||||
|
.eqIfPresent(KeyboardUserCallLogDO::getTotalTokens, reqVO.getTotalTokens())
|
||||||
|
.eqIfPresent(KeyboardUserCallLogDO::getSuccess, reqVO.getSuccess())
|
||||||
|
.eqIfPresent(KeyboardUserCallLogDO::getLatencyMs, reqVO.getLatencyMs())
|
||||||
|
.eqIfPresent(KeyboardUserCallLogDO::getErrorCode, reqVO.getErrorCode())
|
||||||
|
.eqIfPresent(KeyboardUserCallLogDO::getCreatedAt, reqVO.getCreatedAt())
|
||||||
|
.eqIfPresent(KeyboardUserCallLogDO::getGenId, reqVO.getGenId())
|
||||||
|
.orderByDesc(KeyboardUserCallLogDO::getId));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package com.yolo.keyboard.service.usercalllog;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import jakarta.validation.*;
|
||||||
|
import com.yolo.keyboard.controller.admin.usercalllog.vo.*;
|
||||||
|
import com.yolo.keyboard.dal.dataobject.usercalllog.KeyboardUserCallLogDO;
|
||||||
|
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||||
|
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户每次调用日志(用于记录token、模型、耗时、成功率等) Service 接口
|
||||||
|
*
|
||||||
|
* @author Ziin
|
||||||
|
*/
|
||||||
|
public interface KeyboardUserCallLogService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建用户每次调用日志(用于记录token、模型、耗时、成功率等)
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
Long createUserCallLog(@Valid KeyboardUserCallLogSaveReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新用户每次调用日志(用于记录token、模型、耗时、成功率等)
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void updateUserCallLog(@Valid KeyboardUserCallLogSaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除用户每次调用日志(用于记录token、模型、耗时、成功率等)
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void deleteUserCallLog(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除用户每次调用日志(用于记录token、模型、耗时、成功率等)
|
||||||
|
*
|
||||||
|
* @param ids 编号
|
||||||
|
*/
|
||||||
|
void deleteUserCallLogListByIds(List<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得用户每次调用日志(用于记录token、模型、耗时、成功率等)
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return 用户每次调用日志(用于记录token、模型、耗时、成功率等)
|
||||||
|
*/
|
||||||
|
KeyboardUserCallLogDO getUserCallLog(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得用户每次调用日志(用于记录token、模型、耗时、成功率等)分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return 用户每次调用日志(用于记录token、模型、耗时、成功率等)分页
|
||||||
|
*/
|
||||||
|
PageResult<KeyboardUserCallLogDO> getUserCallLogPage(KeyboardUserCallLogPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package com.yolo.keyboard.service.usercalllog;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import com.yolo.keyboard.controller.admin.usercalllog.vo.*;
|
||||||
|
import com.yolo.keyboard.dal.dataobject.usercalllog.KeyboardUserCallLogDO;
|
||||||
|
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||||
|
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||||
|
import com.yolo.keyboard.framework.common.util.object.BeanUtils;
|
||||||
|
|
||||||
|
import com.yolo.keyboard.dal.mysql.usercalllog.KeyboardUserCallLogMapper;
|
||||||
|
|
||||||
|
import static com.yolo.keyboard.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static com.yolo.keyboard.framework.common.util.collection.CollectionUtils.convertList;
|
||||||
|
import static com.yolo.keyboard.framework.common.util.collection.CollectionUtils.diffList;
|
||||||
|
import static com.yolo.keyboard.module.infra.enums.ErrorCodeConstants.USER_CALL_LOG_NOT_EXISTS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户每次调用日志(用于记录token、模型、耗时、成功率等) Service 实现类
|
||||||
|
*
|
||||||
|
* @author Ziin
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class KeyboardUserCallLogServiceImpl implements KeyboardUserCallLogService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private KeyboardUserCallLogMapper userCallLogMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long createUserCallLog(KeyboardUserCallLogSaveReqVO createReqVO) {
|
||||||
|
// 插入
|
||||||
|
KeyboardUserCallLogDO userCallLog = BeanUtils.toBean(createReqVO, KeyboardUserCallLogDO.class);
|
||||||
|
userCallLogMapper.insert(userCallLog);
|
||||||
|
|
||||||
|
// 返回
|
||||||
|
return userCallLog.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateUserCallLog(KeyboardUserCallLogSaveReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
validateUserCallLogExists(updateReqVO.getId());
|
||||||
|
// 更新
|
||||||
|
KeyboardUserCallLogDO updateObj = BeanUtils.toBean(updateReqVO, KeyboardUserCallLogDO.class);
|
||||||
|
userCallLogMapper.updateById(updateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteUserCallLog(Long id) {
|
||||||
|
// 校验存在
|
||||||
|
validateUserCallLogExists(id);
|
||||||
|
// 删除
|
||||||
|
userCallLogMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteUserCallLogListByIds(List<Long> ids) {
|
||||||
|
// 删除
|
||||||
|
userCallLogMapper.deleteByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void validateUserCallLogExists(Long id) {
|
||||||
|
if (userCallLogMapper.selectById(id) == null) {
|
||||||
|
throw exception(USER_CALL_LOG_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyboardUserCallLogDO getUserCallLog(Long id) {
|
||||||
|
return userCallLogMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<KeyboardUserCallLogDO> getUserCallLogPage(KeyboardUserCallLogPageReqVO pageReqVO) {
|
||||||
|
return userCallLogMapper.selectPage(pageReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.yolo.keyboard.module.keyboard.dal.mysql.productitems.KeyboardProductItemsMapper">
|
<mapper namespace="com.yolo.keyboard.dal.mysql.productitems.KeyboardProductItemsMapper">
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?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="com.yolo.keyboard.dal.mysql.usercalllog.KeyboardUserCallLogMapper">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||||
|
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||||
|
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||||
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
|
-->
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.yolo.keyboard.module.keyboard.dal.mysql.userpurchaserecords.KeyboardUserPurchaseRecordsMapper">
|
<mapper namespace="com.yolo.keyboard.dal.mysql.userpurchaserecords.KeyboardUserPurchaseRecordsMapper">
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.yolo.keyboard.module.keyboard.dal.mysql.userwallet.KeyboardUserWalletMapper">
|
<mapper namespace="com.yolo.keyboard.dal.mysql.userwallet.KeyboardUserWalletMapper">
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ public interface ErrorCodeConstants {
|
|||||||
ErrorCode USER_WALLET_NOT_EXISTS = new ErrorCode(1_001_202_005, "用户钱包不存在");
|
ErrorCode USER_WALLET_NOT_EXISTS = new ErrorCode(1_001_202_005, "用户钱包不存在");
|
||||||
ErrorCode USER_PURCHASE_RECORDS_NOT_EXISTS = new ErrorCode(1_001_202_006, "用户内购记录不存在");
|
ErrorCode USER_PURCHASE_RECORDS_NOT_EXISTS = new ErrorCode(1_001_202_006, "用户内购记录不存在");
|
||||||
ErrorCode PRODUCT_ITEMS_NOT_EXISTS = new ErrorCode(1_001_202_007, "内购商品不存在");
|
ErrorCode PRODUCT_ITEMS_NOT_EXISTS = new ErrorCode(1_001_202_007, "内购商品不存在");
|
||||||
|
ErrorCode USER_CALL_LOG_NOT_EXISTS = new ErrorCode(1_001_202_008, "用户每次调用日志(用于记录token、模型、耗时、成功率等)不存在");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user