作者 dong

日志界面

package org.jeecg.modules.airag.app.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.airag.app.entity.AiragLog;
import org.jeecg.modules.airag.app.service.IAiragLogService;
import org.jeecg.modules.airag.llm.entity.AiragModel;
import org.jeecg.modules.airag.llm.service.IAiragModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Description: 日志管理
* @Author: jeecg-boot
* @Date: 2025-06-10
* @Version: V1.0
*/
@Tag(name="日志管理")
@RestController
@RequestMapping("/airaglog/airagLog")
@Slf4j
public class AiragLogController extends JeecgController<AiragLog, IAiragLogService> {
@Autowired
private IAiragLogService airagLogService;
@Autowired
private IAiragModelService airagModelService;
/**
* 分页列表查询
*
* @param airagLog
* @param pageNo
* @param pageSize
* @param req
* @return
*/
//@AutoLog(value = "日志管理-分页列表查询")
@Operation(summary="日志管理-分页列表查询")
@GetMapping(value = "/list")
public Result<IPage<AiragLog>> queryPageList(AiragLog airagLog,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) {
QueryWrapper<AiragLog> queryWrapper = QueryGenerator.initQueryWrapper(airagLog, req.getParameterMap());
Page<AiragLog> page = new Page<AiragLog>(pageNo, pageSize);
IPage<AiragLog> pageList = airagLogService.page(page, queryWrapper);
List<AiragModel> list = airagModelService.list();
Map<String,String> nameMap = new HashMap<String,String>();
for(AiragModel airagModel : list){
nameMap.put(airagModel.getId(), airagModel.getName());
}
for (AiragLog log : pageList.getRecords()) {
String modelId = log.getModelId(); // 获取当前日志的 model_id
log.setName(nameMap.get(modelId)); // 从 nameMap 中匹配 name
}
return Result.OK(pageList);
}
/**
* 添加
*
* @param airagLog
* @return
*/
@AutoLog(value = "日志管理-添加")
@Operation(summary="日志管理-添加")
@RequiresPermissions("airaglog:airag_log:add")
@PostMapping(value = "/add")
public Result<String> add(@RequestBody AiragLog airagLog) {
airagLogService.save(airagLog);
return Result.OK("添加成功!");
}
/**
* 添加到知识库
*
* @param airagLog
* @return
*/
@AutoLog(value = "日志管理-存入问题库")
@Operation(summary = "日志管理-存入问题库")
@RequiresPermissions("airaglog:airag_log:saveToQuestionLibrary")
@PostMapping(value = "/saveToQuestionLibrary")
public Result<String> saveToQuestionLibrary(@RequestBody AiragLog airagLog) {
airagLogService.saveToQuestionLibrary(airagLog);
return Result.OK("存入问题库成功!");
}
/**
* 编辑
*
* @param airagLog
* @return
*/
@AutoLog(value = "日志管理-编辑")
@Operation(summary="日志管理-编辑")
@RequiresPermissions("airaglog:airag_log:edit")
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
public Result<String> edit(@RequestBody AiragLog airagLog) {
airagLogService.updateById(airagLog);
return Result.OK("编辑成功!");
}
/**
* 通过id删除
*
* @param id
* @return
*/
@AutoLog(value = "日志管理-通过id删除")
@Operation(summary="日志管理-通过id删除")
@RequiresPermissions("airaglog:airag_log:delete")
@DeleteMapping(value = "/delete")
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
airagLogService.removeById(id);
return Result.OK("删除成功!");
}
/**
* 批量删除
*
* @param ids
* @return
*/
@AutoLog(value = "日志管理-批量删除")
@Operation(summary="日志管理-批量删除")
@RequiresPermissions("airaglog:airag_log:deleteBatch")
@DeleteMapping(value = "/deleteBatch")
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
this.airagLogService.removeByIds(Arrays.asList(ids.split(",")));
return Result.OK("批量删除成功!");
}
/**
* 通过id查询
*
* @param id
* @return
*/
//@AutoLog(value = "日志管理-通过id查询")
@Operation(summary="日志管理-通过id查询")
@GetMapping(value = "/queryById")
public Result<AiragLog> queryById(@RequestParam(name="id",required=true) String id) {
AiragLog airagLog = airagLogService.getById(id);
if(airagLog==null) {
return Result.error("未找到对应数据");
}
return Result.OK(airagLog);
}
/**
* 导出excel
*
* @param request
* @param airagLog
*/
@RequiresPermissions("airaglog:airag_log:exportXls")
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(HttpServletRequest request, AiragLog airagLog) {
return super.exportXls(request, airagLog, AiragLog.class, "日志管理");
}
/**
* 通过excel导入数据
*
* @param request
* @param response
* @return
*/
@RequiresPermissions("airaglog:airag_log:importExcel")
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
return super.importExcel(request, response, AiragLog.class);
}
}
... ...
package org.jeecg.modules.airag.app.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* @Description: 日志管理
* @Author: jeecg-boot
* @Date: 2025-06-10
* @Version: V1.0
*/
@Data
@TableName("airag_log")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@Schema(description="日志管理")
public class AiragLog implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "主键")
private String id;
/**
* 创建人
*/
@Schema(description = "创建人")
private String createBy;
/**
* 创建日期
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Schema(description = "创建日期")
private Date createTime;
/**
* 更新人
*/
@Schema(description = "更新人")
private String updateBy;
/**
* 更新日期
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Schema(description = "更新日期")
private Date updateTime;
/**
* 问题
*/
@Excel(name = "问题", width = 15)
@Schema(description = "问题")
private String question;
/**
* 回答
*/
@Excel(name = "回答", width = 15)
@Schema(description = "回答")
private String answer;
/**
* 模型ID
*/
@Excel(name = "模型ID", width = 15)
@Schema(description = "模型ID")
private String modelId;
// 新增:临时字段(非数据库字段)
@TableField(exist = false) // MyBatis-Plus 标记该字段不存在于数据库表中
private String name;
}
... ...
package org.jeecg.modules.airag.app.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.airag.app.entity.AiragLog;
/**
* @Description: 日志管理
* @Author: jeecg-boot
* @Date: 2025-06-10
* @Version: V1.0
*/
public interface AiragLogMapper extends BaseMapper<AiragLog> {
}
... ...
<?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="org.jeecg.modules.airag.app.mapper.AiragLogMapper">
</mapper>
\ No newline at end of file
... ...
package org.jeecg.modules.airag.app.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.airag.app.entity.AiragLog;
import java.util.List;
/**
* @Description: 日志管理
* @Author: jeecg-boot
* @Date: 2025-06-10
* @Version: V1.0
*/
public interface IAiragLogService extends IService<AiragLog> {
// List<AiragLog> getLogListWithModelName();
void saveToQuestionLibrary(AiragLog log);
}
... ...
package org.jeecg.modules.airag.app.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.airag.app.entity.AiragLog;
import org.jeecg.modules.airag.app.entity.QuestionEmbedding;
import org.jeecg.modules.airag.app.mapper.AiragLogMapper;
import org.jeecg.modules.airag.app.mapper.QuestionEmbeddingMapper;
import org.jeecg.modules.airag.app.service.IAiragLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Description: 日志管理
* @Author: jeecg-boot
* @Date: 2025-06-10
* @Version: V1.0
*/
@Service
public class AiragLogServiceImpl extends ServiceImpl<AiragLogMapper, AiragLog> implements IAiragLogService {
@Autowired
private QuestionEmbeddingMapper questionEmbeddingMapper;
// @Override
// public List<AiragLog> getLogListWithModelName() {
// List<AiragLog> logList = this.list();
// for (AiragLog log : logList) {
// AiragModel model = airagModelMapper.selectById(log.getModelId());
// if (model != null) {
// log.setModelName(model.getModelName());
// }
// }
// return logList;
// }
@Override
public void saveToQuestionLibrary(AiragLog log) {
// 这里实现将问题和回答存入问题库数据表的逻辑
// 假设问题库数据表的实体类为 QuestionLibrary,Mapper 接口为 QuestionLibraryMapper
QuestionEmbedding questionEmbedding = new QuestionEmbedding();
questionEmbedding.setQuestion(log.getQuestion());
questionEmbedding.setAnswer(log.getAnswer());
questionEmbeddingMapper.insert(questionEmbedding);
}
}
... ...