mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 01:53:53 +08:00
fix:移除触发器,在DAO层添加了删除方法
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package xiaozhi.modules.knowledge.dao;
|
package xiaozhi.modules.knowledge.dao;
|
||||||
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import xiaozhi.common.dao.BaseDao;
|
import xiaozhi.common.dao.BaseDao;
|
||||||
import xiaozhi.modules.knowledge.entity.KnowledgeBaseEntity;
|
import xiaozhi.modules.knowledge.entity.KnowledgeBaseEntity;
|
||||||
@@ -11,4 +12,11 @@ import xiaozhi.modules.knowledge.entity.KnowledgeBaseEntity;
|
|||||||
@Mapper
|
@Mapper
|
||||||
public interface KnowledgeBaseDao extends BaseDao<KnowledgeBaseEntity> {
|
public interface KnowledgeBaseDao extends BaseDao<KnowledgeBaseEntity> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据知识库ID删除相关的插件映射记录
|
||||||
|
*
|
||||||
|
* @param knowledgeBaseId 知识库ID
|
||||||
|
*/
|
||||||
|
void deletePluginMappingByKnowledgeBaseId(@Param("knowledgeBaseId") String knowledgeBaseId);
|
||||||
|
|
||||||
}
|
}
|
||||||
+5
-1
@@ -314,7 +314,11 @@ public class KnowledgeBaseServiceImpl extends BaseServiceImpl<KnowledgeBaseDao,
|
|||||||
|
|
||||||
// API删除成功后再删除本地记录
|
// API删除成功后再删除本地记录
|
||||||
if (apiDeleteSuccess) {
|
if (apiDeleteSuccess) {
|
||||||
log.info("数据库触发器将自动清理ai_agent_plugin_mapping表中与知识库ID '{}' 相关的映射记录", entity.getId());
|
log.info("开始删除ai_agent_plugin_mapping表中与知识库ID '{}' 相关的映射记录", entity.getId());
|
||||||
|
|
||||||
|
// 先删除相关的插件映射记录
|
||||||
|
knowledgeBaseDao.deletePluginMappingByKnowledgeBaseId(entity.getId());
|
||||||
|
log.info("插件映射记录删除完成");
|
||||||
|
|
||||||
int deleteCount = knowledgeBaseDao.deleteById(entity.getId());
|
int deleteCount = knowledgeBaseDao.deleteById(entity.getId());
|
||||||
log.info("本地数据库删除结果: {}", deleteCount > 0 ? "成功" : "失败");
|
log.info("本地数据库删除结果: {}", deleteCount > 0 ? "成功" : "失败");
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
-- 当删除知识库记录时,自动删除相关的插件映射记录
|
|
||||||
|
|
||||||
-- 先删除可能存在的同名触发器(如果存在)
|
|
||||||
DROP TRIGGER IF EXISTS trigger_delete_plugin_mapping_on_knowledgebase_delete;
|
|
||||||
|
|
||||||
-- 创建新的触发器
|
|
||||||
CREATE TRIGGER trigger_delete_plugin_mapping_on_knowledgebase_delete
|
|
||||||
AFTER DELETE ON ai_rag_dataset
|
|
||||||
FOR EACH ROW
|
|
||||||
BEGIN
|
|
||||||
-- 删除与该知识库ID相关的插件映射记录
|
|
||||||
DELETE FROM ai_agent_plugin_mapping WHERE plugin_id = OLD.id;
|
|
||||||
END;
|
|
||||||
@@ -416,10 +416,3 @@ databaseChangeLog:
|
|||||||
- sqlFile:
|
- sqlFile:
|
||||||
encoding: utf8
|
encoding: utf8
|
||||||
path: classpath:db/changelog/202510251150.sql
|
path: classpath:db/changelog/202510251150.sql
|
||||||
- changeSet:
|
|
||||||
id: 202511131016
|
|
||||||
author: rainv123
|
|
||||||
changes:
|
|
||||||
- sqlFile:
|
|
||||||
encoding: utf8
|
|
||||||
path: classpath:db/changelog/202511131016.sql
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?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="xiaozhi.modules.knowledge.dao.KnowledgeBaseDao">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="xiaozhi.modules.knowledge.entity.KnowledgeBaseEntity">
|
||||||
|
<id property="id" column="id" jdbcType="VARCHAR"/>
|
||||||
|
<result property="datasetId" column="dataset_id" jdbcType="VARCHAR"/>
|
||||||
|
<result property="ragModelId" column="rag_model_id" jdbcType="VARCHAR"/>
|
||||||
|
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||||
|
<result property="description" column="description" jdbcType="VARCHAR"/>
|
||||||
|
<result property="status" column="status" jdbcType="TINYINT"/>
|
||||||
|
<result property="creator" column="creator" jdbcType="BIGINT"/>
|
||||||
|
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
||||||
|
<result property="updater" column="updater" jdbcType="BIGINT"/>
|
||||||
|
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<!-- 根据知识库ID删除相关的插件映射记录 -->
|
||||||
|
<delete id="deletePluginMappingByKnowledgeBaseId">
|
||||||
|
DELETE FROM ai_agent_plugin_mapping
|
||||||
|
WHERE plugin_id = #{knowledgeBaseId}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user