package com.vincent.rsf.server.ai.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.vincent.rsf.framework.common.R; import com.vincent.rsf.server.ai.entity.AiCallLog; import com.vincent.rsf.server.ai.service.AiCallLogService; import com.vincent.rsf.server.common.domain.BaseParam; import com.vincent.rsf.server.common.domain.PageParam; import com.vincent.rsf.server.system.controller.BaseController; import lombok.RequiredArgsConstructor; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import java.util.Arrays; import java.util.Map; @RestController @RequiredArgsConstructor public class AiCallLogController extends BaseController { private final AiCallLogService aiCallLogService; @PreAuthorize("hasAuthority('system:aiCallLog:list')") @PostMapping("/aiCallLog/page") public R page(@RequestBody Map map) { BaseParam baseParam = buildParam(map, BaseParam.class); PageParam pageParam = new PageParam<>(baseParam, AiCallLog.class); return R.ok().add(aiCallLogService.page(pageParam, pageParam.buildWrapper(true) .eq("tenant_id", getTenantId()) .eq("deleted", 0))); } @PreAuthorize("hasAuthority('system:aiCallLog:list')") @PostMapping("/aiCallLog/list") public R list(@RequestBody Map map) { return R.ok().add(aiCallLogService.list(new LambdaQueryWrapper() .eq(AiCallLog::getTenantId, getTenantId()) .eq(AiCallLog::getDeleted, 0) .orderByDesc(AiCallLog::getId))); } @PreAuthorize("hasAuthority('system:aiCallLog:list')") @PostMapping({"/aiCallLog/many/{ids}", "/aiCallLogs/many/{ids}"}) public R many(@PathVariable Long[] ids) { return R.ok().add(aiCallLogService.list(new LambdaQueryWrapper() .eq(AiCallLog::getTenantId, getTenantId()) .eq(AiCallLog::getDeleted, 0) .in(AiCallLog::getId, Arrays.asList(ids)))); } @PreAuthorize("hasAuthority('system:aiCallLog:list')") @GetMapping("/aiCallLog/{id}") public R get(@PathVariable("id") Long id) { return R.ok().add(aiCallLogService.getOne(new LambdaQueryWrapper() .eq(AiCallLog::getId, id) .eq(AiCallLog::getTenantId, getTenantId()) .eq(AiCallLog::getDeleted, 0) .last("limit 1"))); } @PreAuthorize("hasAuthority('system:aiCallLog:list')") @GetMapping("/aiCallLog/stats") public R stats() { return R.ok().add(aiCallLogService.getObserveStats(getTenantId())); } @PreAuthorize("hasAuthority('system:aiCallLog:list')") @GetMapping("/aiCallLog/{id}/mcpLogs") public R listMcpLogs(@PathVariable("id") Long id) { return R.ok().add(aiCallLogService.listMcpLogs(id, getTenantId())); } }