作者 dong

日志界面

  1 +package org.jeecg.modules.airag.app.controller;
  2 +
  3 +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4 +import com.baomidou.mybatisplus.core.metadata.IPage;
  5 +import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6 +import io.swagger.v3.oas.annotations.Operation;
  7 +import io.swagger.v3.oas.annotations.tags.Tag;
  8 +import lombok.extern.slf4j.Slf4j;
  9 +import org.apache.shiro.authz.annotation.RequiresPermissions;
  10 +import org.jeecg.common.api.vo.Result;
  11 +import org.jeecg.common.aspect.annotation.AutoLog;
  12 +import org.jeecg.common.system.base.controller.JeecgController;
  13 +import org.jeecg.common.system.query.QueryGenerator;
  14 +import org.jeecg.modules.airag.app.entity.AiragLog;
  15 +import org.jeecg.modules.airag.app.service.IAiragLogService;
  16 +import org.jeecg.modules.airag.llm.entity.AiragModel;
  17 +import org.jeecg.modules.airag.llm.service.IAiragModelService;
  18 +import org.springframework.beans.factory.annotation.Autowired;
  19 +import org.springframework.web.bind.annotation.*;
  20 +import org.springframework.web.servlet.ModelAndView;
  21 +
  22 +import javax.servlet.http.HttpServletRequest;
  23 +import javax.servlet.http.HttpServletResponse;
  24 +import java.util.Arrays;
  25 +import java.util.HashMap;
  26 +import java.util.List;
  27 +import java.util.Map;
  28 +
  29 +/**
  30 +* @Description: 日志管理
  31 +* @Author: jeecg-boot
  32 +* @Date: 2025-06-10
  33 +* @Version: V1.0
  34 +*/
  35 +@Tag(name="日志管理")
  36 +@RestController
  37 +@RequestMapping("/airaglog/airagLog")
  38 +@Slf4j
  39 +public class AiragLogController extends JeecgController<AiragLog, IAiragLogService> {
  40 + @Autowired
  41 + private IAiragLogService airagLogService;
  42 +
  43 + @Autowired
  44 + private IAiragModelService airagModelService;
  45 + /**
  46 + * 分页列表查询
  47 + *
  48 + * @param airagLog
  49 + * @param pageNo
  50 + * @param pageSize
  51 + * @param req
  52 + * @return
  53 + */
  54 + //@AutoLog(value = "日志管理-分页列表查询")
  55 + @Operation(summary="日志管理-分页列表查询")
  56 + @GetMapping(value = "/list")
  57 + public Result<IPage<AiragLog>> queryPageList(AiragLog airagLog,
  58 + @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
  59 + @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
  60 + HttpServletRequest req) {
  61 + QueryWrapper<AiragLog> queryWrapper = QueryGenerator.initQueryWrapper(airagLog, req.getParameterMap());
  62 + Page<AiragLog> page = new Page<AiragLog>(pageNo, pageSize);
  63 + IPage<AiragLog> pageList = airagLogService.page(page, queryWrapper);
  64 + List<AiragModel> list = airagModelService.list();
  65 + Map<String,String> nameMap = new HashMap<String,String>();
  66 + for(AiragModel airagModel : list){
  67 + nameMap.put(airagModel.getId(), airagModel.getName());
  68 + }
  69 + for (AiragLog log : pageList.getRecords()) {
  70 + String modelId = log.getModelId(); // 获取当前日志的 model_id
  71 + log.setName(nameMap.get(modelId)); // 从 nameMap 中匹配 name
  72 + }
  73 + return Result.OK(pageList);
  74 + }
  75 +
  76 + /**
  77 + * 添加
  78 + *
  79 + * @param airagLog
  80 + * @return
  81 + */
  82 + @AutoLog(value = "日志管理-添加")
  83 + @Operation(summary="日志管理-添加")
  84 + @RequiresPermissions("airaglog:airag_log:add")
  85 + @PostMapping(value = "/add")
  86 + public Result<String> add(@RequestBody AiragLog airagLog) {
  87 + airagLogService.save(airagLog);
  88 + return Result.OK("添加成功!");
  89 + }
  90 +
  91 +
  92 + /**
  93 + * 添加到知识库
  94 + *
  95 + * @param airagLog
  96 + * @return
  97 + */
  98 + @AutoLog(value = "日志管理-存入问题库")
  99 + @Operation(summary = "日志管理-存入问题库")
  100 + @RequiresPermissions("airaglog:airag_log:saveToQuestionLibrary")
  101 + @PostMapping(value = "/saveToQuestionLibrary")
  102 + public Result<String> saveToQuestionLibrary(@RequestBody AiragLog airagLog) {
  103 + airagLogService.saveToQuestionLibrary(airagLog);
  104 + return Result.OK("存入问题库成功!");
  105 + }
  106 +
  107 + /**
  108 + * 编辑
  109 + *
  110 + * @param airagLog
  111 + * @return
  112 + */
  113 + @AutoLog(value = "日志管理-编辑")
  114 + @Operation(summary="日志管理-编辑")
  115 + @RequiresPermissions("airaglog:airag_log:edit")
  116 + @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
  117 + public Result<String> edit(@RequestBody AiragLog airagLog) {
  118 + airagLogService.updateById(airagLog);
  119 + return Result.OK("编辑成功!");
  120 + }
  121 +
  122 + /**
  123 + * 通过id删除
  124 + *
  125 + * @param id
  126 + * @return
  127 + */
  128 + @AutoLog(value = "日志管理-通过id删除")
  129 + @Operation(summary="日志管理-通过id删除")
  130 + @RequiresPermissions("airaglog:airag_log:delete")
  131 + @DeleteMapping(value = "/delete")
  132 + public Result<String> delete(@RequestParam(name="id",required=true) String id) {
  133 + airagLogService.removeById(id);
  134 + return Result.OK("删除成功!");
  135 + }
  136 +
  137 + /**
  138 + * 批量删除
  139 + *
  140 + * @param ids
  141 + * @return
  142 + */
  143 + @AutoLog(value = "日志管理-批量删除")
  144 + @Operation(summary="日志管理-批量删除")
  145 + @RequiresPermissions("airaglog:airag_log:deleteBatch")
  146 + @DeleteMapping(value = "/deleteBatch")
  147 + public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
  148 + this.airagLogService.removeByIds(Arrays.asList(ids.split(",")));
  149 + return Result.OK("批量删除成功!");
  150 + }
  151 +
  152 + /**
  153 + * 通过id查询
  154 + *
  155 + * @param id
  156 + * @return
  157 + */
  158 + //@AutoLog(value = "日志管理-通过id查询")
  159 + @Operation(summary="日志管理-通过id查询")
  160 + @GetMapping(value = "/queryById")
  161 + public Result<AiragLog> queryById(@RequestParam(name="id",required=true) String id) {
  162 + AiragLog airagLog = airagLogService.getById(id);
  163 + if(airagLog==null) {
  164 + return Result.error("未找到对应数据");
  165 + }
  166 + return Result.OK(airagLog);
  167 + }
  168 +
  169 + /**
  170 + * 导出excel
  171 + *
  172 + * @param request
  173 + * @param airagLog
  174 + */
  175 + @RequiresPermissions("airaglog:airag_log:exportXls")
  176 + @RequestMapping(value = "/exportXls")
  177 + public ModelAndView exportXls(HttpServletRequest request, AiragLog airagLog) {
  178 + return super.exportXls(request, airagLog, AiragLog.class, "日志管理");
  179 + }
  180 +
  181 + /**
  182 + * 通过excel导入数据
  183 + *
  184 + * @param request
  185 + * @param response
  186 + * @return
  187 + */
  188 + @RequiresPermissions("airaglog:airag_log:importExcel")
  189 + @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
  190 + public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
  191 + return super.importExcel(request, response, AiragLog.class);
  192 + }
  193 +
  194 +}
  1 +package org.jeecg.modules.airag.app.entity;
  2 +
  3 +import com.baomidou.mybatisplus.annotation.IdType;
  4 +import com.baomidou.mybatisplus.annotation.TableField;
  5 +import com.baomidou.mybatisplus.annotation.TableId;
  6 +import com.baomidou.mybatisplus.annotation.TableName;
  7 +import com.fasterxml.jackson.annotation.JsonFormat;
  8 +import io.swagger.v3.oas.annotations.media.Schema;
  9 +import lombok.Data;
  10 +import lombok.EqualsAndHashCode;
  11 +import lombok.experimental.Accessors;
  12 +import org.jeecgframework.poi.excel.annotation.Excel;
  13 +import org.springframework.format.annotation.DateTimeFormat;
  14 +
  15 +import java.io.Serializable;
  16 +import java.util.Date;
  17 +
  18 +/**
  19 + * @Description: 日志管理
  20 + * @Author: jeecg-boot
  21 + * @Date: 2025-06-10
  22 + * @Version: V1.0
  23 + */
  24 +@Data
  25 +@TableName("airag_log")
  26 +@Accessors(chain = true)
  27 +@EqualsAndHashCode(callSuper = false)
  28 +@Schema(description="日志管理")
  29 +public class AiragLog implements Serializable {
  30 + private static final long serialVersionUID = 1L;
  31 +
  32 + /**
  33 + * 主键
  34 + */
  35 + @TableId(type = IdType.ASSIGN_ID)
  36 + @Schema(description = "主键")
  37 + private String id;
  38 + /**
  39 + * 创建人
  40 + */
  41 + @Schema(description = "创建人")
  42 + private String createBy;
  43 + /**
  44 + * 创建日期
  45 + */
  46 + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
  47 + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  48 + @Schema(description = "创建日期")
  49 + private Date createTime;
  50 + /**
  51 + * 更新人
  52 + */
  53 + @Schema(description = "更新人")
  54 + private String updateBy;
  55 + /**
  56 + * 更新日期
  57 + */
  58 + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
  59 + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  60 + @Schema(description = "更新日期")
  61 + private Date updateTime;
  62 + /**
  63 + * 问题
  64 + */
  65 + @Excel(name = "问题", width = 15)
  66 + @Schema(description = "问题")
  67 + private String question;
  68 + /**
  69 + * 回答
  70 + */
  71 + @Excel(name = "回答", width = 15)
  72 + @Schema(description = "回答")
  73 + private String answer;
  74 + /**
  75 + * 模型ID
  76 + */
  77 + @Excel(name = "模型ID", width = 15)
  78 + @Schema(description = "模型ID")
  79 + private String modelId;
  80 +
  81 + // 新增:临时字段(非数据库字段)
  82 + @TableField(exist = false) // MyBatis-Plus 标记该字段不存在于数据库表中
  83 + private String name;
  84 +}
  1 +package org.jeecg.modules.airag.app.mapper;
  2 +
  3 +import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  4 +import org.jeecg.modules.airag.app.entity.AiragLog;
  5 +
  6 +/**
  7 + * @Description: 日志管理
  8 + * @Author: jeecg-boot
  9 + * @Date: 2025-06-10
  10 + * @Version: V1.0
  11 + */
  12 +public interface AiragLogMapper extends BaseMapper<AiragLog> {
  13 +
  14 +}
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="org.jeecg.modules.airag.app.mapper.AiragLogMapper">
  4 +
  5 +</mapper>
  1 +package org.jeecg.modules.airag.app.service;
  2 +
  3 +import com.baomidou.mybatisplus.extension.service.IService;
  4 +import org.jeecg.modules.airag.app.entity.AiragLog;
  5 +
  6 +import java.util.List;
  7 +
  8 +/**
  9 + * @Description: 日志管理
  10 + * @Author: jeecg-boot
  11 + * @Date: 2025-06-10
  12 + * @Version: V1.0
  13 + */
  14 +public interface IAiragLogService extends IService<AiragLog> {
  15 +// List<AiragLog> getLogListWithModelName();
  16 + void saveToQuestionLibrary(AiragLog log);
  17 +}
  1 +package org.jeecg.modules.airag.app.service.impl;
  2 +
  3 +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4 +import org.jeecg.modules.airag.app.entity.AiragLog;
  5 +import org.jeecg.modules.airag.app.entity.QuestionEmbedding;
  6 +import org.jeecg.modules.airag.app.mapper.AiragLogMapper;
  7 +import org.jeecg.modules.airag.app.mapper.QuestionEmbeddingMapper;
  8 +import org.jeecg.modules.airag.app.service.IAiragLogService;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Service;
  11 +
  12 +import java.util.List;
  13 +
  14 +/**
  15 + * @Description: 日志管理
  16 + * @Author: jeecg-boot
  17 + * @Date: 2025-06-10
  18 + * @Version: V1.0
  19 + */
  20 +@Service
  21 +public class AiragLogServiceImpl extends ServiceImpl<AiragLogMapper, AiragLog> implements IAiragLogService {
  22 + @Autowired
  23 + private QuestionEmbeddingMapper questionEmbeddingMapper;
  24 +
  25 +// @Override
  26 +// public List<AiragLog> getLogListWithModelName() {
  27 +// List<AiragLog> logList = this.list();
  28 +// for (AiragLog log : logList) {
  29 +// AiragModel model = airagModelMapper.selectById(log.getModelId());
  30 +// if (model != null) {
  31 +// log.setModelName(model.getModelName());
  32 +// }
  33 +// }
  34 +// return logList;
  35 +// }
  36 +
  37 + @Override
  38 + public void saveToQuestionLibrary(AiragLog log) {
  39 + // 这里实现将问题和回答存入问题库数据表的逻辑
  40 + // 假设问题库数据表的实体类为 QuestionLibrary,Mapper 接口为 QuestionLibraryMapper
  41 + QuestionEmbedding questionEmbedding = new QuestionEmbedding();
  42 + questionEmbedding.setQuestion(log.getQuestion());
  43 + questionEmbedding.setAnswer(log.getAnswer());
  44 + questionEmbeddingMapper.insert(questionEmbedding);
  45 + }
  46 +}
  47 +