Junjie
昨天 825813e2dd90cf8bdc48acbb6eee85159bc33b4d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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();
    }
}