package com.zy.ai.controller;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.plugins.Page;
|
import com.core.annotations.ManagerAuth;
|
import com.core.common.R;
|
import com.zy.ai.entity.LlmCallLog;
|
import com.zy.ai.service.LlmCallLogService;
|
import com.zy.common.web.BaseController;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.web.bind.annotation.*;
|
|
@RestController
|
@RequestMapping("/ai/llm/log")
|
@RequiredArgsConstructor
|
public class LlmCallLogController extends BaseController {
|
|
private final LlmCallLogService llmCallLogService;
|
|
@GetMapping("/list/auth")
|
@ManagerAuth
|
public R list(@RequestParam(defaultValue = "1") Integer curr,
|
@RequestParam(defaultValue = "20") Integer limit,
|
@RequestParam(required = false) String scene,
|
@RequestParam(required = false) Integer success,
|
@RequestParam(required = false) Long routeId,
|
@RequestParam(required = false) String traceId) {
|
EntityWrapper<LlmCallLog> wrapper = new EntityWrapper<>();
|
if (!isBlank(scene)) {
|
wrapper.eq("scene", scene.trim());
|
}
|
if (success != null) {
|
wrapper.eq("success", success);
|
}
|
if (routeId != null) {
|
wrapper.eq("route_id", routeId);
|
}
|
if (!isBlank(traceId)) {
|
wrapper.eq("trace_id", traceId.trim());
|
}
|
wrapper.orderBy("id", false);
|
return R.ok(llmCallLogService.selectPage(new Page<>(curr, limit), wrapper));
|
}
|
|
@PostMapping("/delete/auth")
|
@ManagerAuth
|
public R delete(@RequestParam("id") Long id) {
|
if (id == null) {
|
return R.error("id不能为空");
|
}
|
llmCallLogService.deleteById(id);
|
return R.ok();
|
}
|
|
@PostMapping("/clear/auth")
|
@ManagerAuth
|
public R clear() {
|
llmCallLogService.delete(new EntityWrapper<LlmCallLog>());
|
return R.ok();
|
}
|
|
private boolean isBlank(String s) {
|
return s == null || s.trim().isEmpty();
|
}
|
}
|