mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
Merge branch 'main' into update-tts-voice-data
This commit is contained in:
@@ -245,4 +245,9 @@ public interface ErrorCode {
|
||||
int DEVICE_NOT_EXIST = 10194; // 设备不存在
|
||||
int OTA_UPLOAD_COUNT_EXCEED = 10195; // OTA上传次数超过限制
|
||||
|
||||
// 智能体标签相关错误码
|
||||
int AGENT_TAG_NAME_DUPLICATE = 10196; // 标签名称已存在
|
||||
int AGENT_TAG_NAME_EMPTY = 10197; // 标签名称不能为空
|
||||
int AGENT_TAG_NOT_EXIST = 10198; // 标签不存在
|
||||
|
||||
}
|
||||
|
||||
+49
-1
@@ -42,6 +42,9 @@ import xiaozhi.modules.agent.dto.AgentMemoryDTO;
|
||||
import xiaozhi.modules.agent.dto.AgentUpdateDTO;
|
||||
import xiaozhi.modules.agent.entity.AgentEntity;
|
||||
import xiaozhi.modules.agent.entity.AgentTemplateEntity;
|
||||
import xiaozhi.modules.agent.dto.AgentTagDTO;
|
||||
import xiaozhi.modules.agent.entity.AgentTagEntity;
|
||||
import xiaozhi.modules.agent.service.AgentTagService;
|
||||
import xiaozhi.modules.agent.service.AgentChatAudioService;
|
||||
import xiaozhi.modules.agent.service.AgentChatHistoryService;
|
||||
import xiaozhi.modules.agent.service.AgentChatSummaryService;
|
||||
@@ -69,6 +72,7 @@ public class AgentController {
|
||||
private final AgentContextProviderService agentContextProviderService;
|
||||
private final AgentChatSummaryService agentChatSummaryService;
|
||||
private final RedisUtils redisUtils;
|
||||
private final AgentTagService agentTagService;
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获取用户智能体列表")
|
||||
@@ -77,7 +81,7 @@ public class AgentController {
|
||||
@RequestParam(value = "keyword", required = false) String keyword,
|
||||
@RequestParam(value = "searchType", defaultValue = "name") String searchType) {
|
||||
UserDetail user = SecurityUser.getUser();
|
||||
|
||||
|
||||
// 直接调用整合后的getUserAgents方法,无需再区分搜索和普通查询
|
||||
List<AgentDTO> agents = agentService.getUserAgents(user.getId(), keyword, searchType);
|
||||
return new Result<List<AgentDTO>>().ok(agents);
|
||||
@@ -275,6 +279,50 @@ public class AgentController {
|
||||
.body(audioData);
|
||||
}
|
||||
|
||||
@PostMapping("/tag")
|
||||
@Operation(summary = "创建标签")
|
||||
@RequiresPermissions("sys:role:normal")
|
||||
public Result<AgentTagEntity> createTag(@RequestBody Map<String, String> params) {
|
||||
String tagName = params.get("tagName");
|
||||
if (StringUtils.isBlank(tagName)) {
|
||||
return new Result<AgentTagEntity>().error("标签名称不能为空");
|
||||
}
|
||||
AgentTagEntity tag = agentTagService.saveTag(tagName);
|
||||
return new Result<AgentTagEntity>().ok(tag);
|
||||
}
|
||||
|
||||
@GetMapping("/tag/list")
|
||||
@Operation(summary = "获取所有标签列表")
|
||||
@RequiresPermissions("sys:role:normal")
|
||||
public Result<List<AgentTagDTO>> getAllTags() {
|
||||
List<AgentTagDTO> tags = agentTagService.getAllTags();
|
||||
return new Result<List<AgentTagDTO>>().ok(tags);
|
||||
}
|
||||
|
||||
@DeleteMapping("/tag/{id}")
|
||||
@Operation(summary = "删除标签")
|
||||
@RequiresPermissions("sys:role:normal")
|
||||
public Result<Void> deleteTag(@PathVariable String id) {
|
||||
agentTagService.deleteTag(id);
|
||||
return new Result<Void>().ok(null);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/tags")
|
||||
@Operation(summary = "获取智能体的标签")
|
||||
@RequiresPermissions("sys:role:normal")
|
||||
public Result<List<AgentTagDTO>> getAgentTags(@PathVariable String id) {
|
||||
List<AgentTagDTO> tags = agentTagService.getTagsByAgentId(id);
|
||||
return new Result<List<AgentTagDTO>>().ok(tags);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}/tags")
|
||||
@Operation(summary = "保存智能体的标签")
|
||||
@RequiresPermissions("sys:role:normal")
|
||||
public Result<Void> saveAgentTags(@PathVariable String id, @RequestBody Map<String, Object> params) {
|
||||
List<String> tagIds = (List<String>) params.get("tagIds");
|
||||
List<String> tagNames = (List<String>) params.get("tagNames");
|
||||
agentTagService.saveAgentTags(id, tagIds, tagNames);
|
||||
return new Result<Void>().ok(null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package xiaozhi.modules.agent.dao;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import xiaozhi.common.dao.BaseDao;
|
||||
import xiaozhi.modules.agent.entity.AgentTagEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface AgentTagDao extends BaseDao<AgentTagEntity> {
|
||||
|
||||
List<AgentTagEntity> selectByAgentId(@Param("agentId") String agentId);
|
||||
|
||||
List<AgentTagEntity> selectByAgentIds(@Param("agentIds") List<String> agentIds);
|
||||
|
||||
List<AgentTagEntity> selectAll();
|
||||
|
||||
List<String> selectAgentIdsByTagName(@Param("tagName") String tagName);
|
||||
|
||||
List<AgentTagEntity> selectByTagNames(@Param("tagNames") List<String> tagNames);
|
||||
|
||||
int batchInsert(@Param("list") List<AgentTagEntity> tagList);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package xiaozhi.modules.agent.dao;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import xiaozhi.common.dao.BaseDao;
|
||||
import xiaozhi.modules.agent.entity.AgentTagRelationEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface AgentTagRelationDao extends BaseDao<AgentTagRelationEntity> {
|
||||
|
||||
int deleteByAgentId(@Param("agentId") String agentId);
|
||||
|
||||
int insertRelation(AgentTagRelationEntity relation);
|
||||
|
||||
int batchInsertRelation(@Param("list") List<AgentTagRelationEntity> relations);
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import xiaozhi.modules.agent.dto.AgentTagDTO;
|
||||
|
||||
/**
|
||||
* 智能体数据传输对象
|
||||
@@ -46,4 +47,7 @@ public class AgentDTO {
|
||||
|
||||
@Schema(description = "设备数量", example = "10")
|
||||
private Integer deviceCount;
|
||||
|
||||
@Schema(description = "标签列表")
|
||||
private List<AgentTagDTO> tags;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package xiaozhi.modules.agent.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Schema(description = "智能体标签DTO")
|
||||
public class AgentTagDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "标签ID")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "标签名称")
|
||||
private String tagName;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package xiaozhi.modules.agent.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("ai_agent_tag")
|
||||
@Schema(description = "智能体标签")
|
||||
public class AgentTagEntity {
|
||||
|
||||
@TableId(type = IdType.ASSIGN_UUID)
|
||||
@Schema(description = "主键")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "标签名称")
|
||||
private String tagName;
|
||||
|
||||
@Schema(description = "排序")
|
||||
private Integer sort;
|
||||
|
||||
@Schema(description = "创建者")
|
||||
private Long creator;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private Date createdAt;
|
||||
|
||||
@Schema(description = "更新者")
|
||||
private Long updater;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private Date updatedAt;
|
||||
|
||||
@Schema(description = "删除标记")
|
||||
private Integer deleted;
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package xiaozhi.modules.agent.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("ai_agent_tag_relation")
|
||||
@Schema(description = "智能体标签关联")
|
||||
public class AgentTagRelationEntity {
|
||||
|
||||
@TableId(type = IdType.ASSIGN_UUID)
|
||||
@Schema(description = "主键")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "智能体ID")
|
||||
private String agentId;
|
||||
|
||||
@Schema(description = "标签ID")
|
||||
private String tagId;
|
||||
|
||||
@Schema(description = "创建者")
|
||||
private Long creator;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private Date createdAt;
|
||||
|
||||
@Schema(description = "更新者")
|
||||
private Long updater;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private Date updatedAt;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package xiaozhi.modules.agent.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import xiaozhi.modules.agent.dto.AgentTagDTO;
|
||||
import xiaozhi.modules.agent.entity.AgentTagEntity;
|
||||
|
||||
public interface AgentTagService {
|
||||
|
||||
AgentTagEntity saveTag(String tagName);
|
||||
|
||||
void deleteTag(String tagId);
|
||||
|
||||
List<AgentTagDTO> getTagsByAgentId(String agentId);
|
||||
|
||||
void saveAgentTags(String agentId, List<String> tagIds, List<String> tagNames);
|
||||
|
||||
void deleteAgentTags(String agentId);
|
||||
|
||||
List<AgentTagDTO> getTagsByAgentIds(List<String> agentIds);
|
||||
|
||||
List<AgentTagDTO> getAllTags();
|
||||
|
||||
List<String> getAgentIdsByTagName(String tagName);
|
||||
}
|
||||
+29
-2
@@ -31,17 +31,21 @@ import xiaozhi.common.utils.ConvertUtils;
|
||||
import xiaozhi.common.utils.JsonUtils;
|
||||
import xiaozhi.common.utils.ToolUtil;
|
||||
import xiaozhi.modules.agent.dao.AgentDao;
|
||||
import xiaozhi.modules.agent.dao.AgentTagDao;
|
||||
import xiaozhi.modules.agent.dto.AgentCreateDTO;
|
||||
import xiaozhi.modules.agent.dto.AgentDTO;
|
||||
import xiaozhi.modules.agent.dto.AgentTagDTO;
|
||||
import xiaozhi.modules.agent.dto.AgentUpdateDTO;
|
||||
import xiaozhi.modules.agent.entity.AgentContextProviderEntity;
|
||||
import xiaozhi.modules.agent.entity.AgentEntity;
|
||||
import xiaozhi.modules.agent.entity.AgentPluginMapping;
|
||||
import xiaozhi.modules.agent.entity.AgentTagEntity;
|
||||
import xiaozhi.modules.agent.entity.AgentTemplateEntity;
|
||||
import xiaozhi.modules.agent.service.AgentChatHistoryService;
|
||||
import xiaozhi.modules.agent.service.AgentContextProviderService;
|
||||
import xiaozhi.modules.agent.service.AgentPluginMappingService;
|
||||
import xiaozhi.modules.agent.service.AgentService;
|
||||
import xiaozhi.modules.agent.service.AgentTagService;
|
||||
import xiaozhi.modules.agent.service.AgentTemplateService;
|
||||
import xiaozhi.modules.agent.vo.AgentInfoVO;
|
||||
import xiaozhi.modules.device.entity.DeviceEntity;
|
||||
@@ -59,6 +63,7 @@ import xiaozhi.modules.timbre.service.TimbreService;
|
||||
@AllArgsConstructor
|
||||
public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> implements AgentService {
|
||||
private final AgentDao agentDao;
|
||||
private final AgentTagDao agentTagDao;
|
||||
private final TimbreService timbreModelService;
|
||||
private final ModelConfigService modelConfigService;
|
||||
private final RedisUtils redisUtils;
|
||||
@@ -68,6 +73,7 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
|
||||
private final AgentTemplateService agentTemplateService;
|
||||
private final ModelProviderService modelProviderService;
|
||||
private final AgentContextProviderService agentContextProviderService;
|
||||
private final AgentTagService agentTagService;
|
||||
|
||||
@Override
|
||||
public PageData<AgentEntity> adminAgentList(Map<String, Object> params) {
|
||||
@@ -151,8 +157,16 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
|
||||
return new ArrayList<>();
|
||||
}
|
||||
} else {
|
||||
// 按名称搜索
|
||||
queryWrapper.like("agent_name", keyword);
|
||||
// 按名称搜索(默认):同时搜索智能体名称和标签名
|
||||
List<String> tagAgentIds = agentTagService.getAgentIdsByTagName(keyword);
|
||||
if (ToolUtil.isNotEmpty(tagAgentIds)) {
|
||||
queryWrapper.and(wrapper -> wrapper
|
||||
.like("agent_name", keyword)
|
||||
.or()
|
||||
.in("id", tagAgentIds));
|
||||
} else {
|
||||
queryWrapper.like("agent_name", keyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,6 +207,19 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
|
||||
// 获取设备数量
|
||||
dto.setDeviceCount(getDeviceCountByAgentId(agent.getId()));
|
||||
|
||||
// 获取标签列表
|
||||
List<AgentTagEntity> tags = agentTagDao.selectByAgentId(agent.getId());
|
||||
if (ToolUtil.isNotEmpty(tags)) {
|
||||
dto.setTags(tags.stream().map(this::convertTagToDTO).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
private AgentTagDTO convertTagToDTO(AgentTagEntity entity) {
|
||||
AgentTagDTO dto = new AgentTagDTO();
|
||||
dto.setId(entity.getId());
|
||||
dto.setTagName(entity.getTagName());
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
package xiaozhi.modules.agent.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import xiaozhi.common.exception.ErrorCode;
|
||||
import xiaozhi.common.exception.RenException;
|
||||
import xiaozhi.common.service.impl.BaseServiceImpl;
|
||||
import xiaozhi.modules.agent.dao.AgentTagDao;
|
||||
import xiaozhi.modules.agent.dao.AgentTagRelationDao;
|
||||
import xiaozhi.modules.agent.dto.AgentTagDTO;
|
||||
import xiaozhi.modules.agent.entity.AgentTagEntity;
|
||||
import xiaozhi.modules.agent.entity.AgentTagRelationEntity;
|
||||
import xiaozhi.modules.agent.service.AgentTagService;
|
||||
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class AgentTagServiceImpl extends BaseServiceImpl<AgentTagDao, AgentTagEntity> implements AgentTagService {
|
||||
|
||||
private final AgentTagRelationDao agentTagRelationDao;
|
||||
|
||||
@Override
|
||||
public AgentTagEntity saveTag(String tagName) {
|
||||
if (tagName == null || tagName.trim().isEmpty()) {
|
||||
throw new RenException(ErrorCode.AGENT_TAG_NAME_EMPTY);
|
||||
}
|
||||
|
||||
QueryWrapper<AgentTagEntity> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("tag_name", tagName);
|
||||
wrapper.eq("deleted", 0);
|
||||
AgentTagEntity existTag = baseDao.selectOne(wrapper);
|
||||
if (existTag != null) {
|
||||
return existTag;
|
||||
}
|
||||
|
||||
AgentTagEntity tag = new AgentTagEntity();
|
||||
tag.setId(UUID.randomUUID().toString().replace("-", ""));
|
||||
tag.setTagName(tagName);
|
||||
tag.setSort(0);
|
||||
tag.setCreatedAt(new Date());
|
||||
tag.setUpdatedAt(new Date());
|
||||
tag.setDeleted(0);
|
||||
baseDao.insert(tag);
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTag(String tagId) {
|
||||
AgentTagEntity tag = baseDao.selectById(tagId);
|
||||
if (tag != null) {
|
||||
tag.setDeleted(1);
|
||||
tag.setUpdatedAt(new Date());
|
||||
baseDao.updateById(tag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AgentTagDTO> getTagsByAgentId(String agentId) {
|
||||
List<AgentTagEntity> tags = baseDao.selectByAgentId(agentId);
|
||||
return tags.stream().map(this::convertToDTO).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveAgentTags(String agentId, List<String> tagIds, List<String> tagNames) {
|
||||
agentTagRelationDao.deleteByAgentId(agentId);
|
||||
|
||||
List<AgentTagEntity> currentTags = baseDao.selectByAgentId(agentId);
|
||||
List<String> currentTagNames = currentTags.stream()
|
||||
.map(AgentTagEntity::getTagName)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<String> allTagIds = new ArrayList<>();
|
||||
List<String> newTagNames = new ArrayList<>();
|
||||
|
||||
if (tagNames != null && !tagNames.isEmpty()) {
|
||||
Set<String> addedTagNames = new HashSet<>();
|
||||
for (String tagName : tagNames) {
|
||||
if (tagName == null || tagName.trim().isEmpty()) {
|
||||
throw new RenException(ErrorCode.AGENT_TAG_NAME_EMPTY);
|
||||
}
|
||||
|
||||
if (currentTagNames.contains(tagName) || addedTagNames.contains(tagName)) {
|
||||
throw new RenException(ErrorCode.AGENT_TAG_NAME_DUPLICATE);
|
||||
}
|
||||
addedTagNames.add(tagName);
|
||||
newTagNames.add(tagName);
|
||||
}
|
||||
}
|
||||
|
||||
List<AgentTagEntity> existTags = new ArrayList<>();
|
||||
if (!newTagNames.isEmpty()) {
|
||||
existTags = baseDao.selectByTagNames(newTagNames);
|
||||
}
|
||||
|
||||
List<String> existTagNames = existTags.stream()
|
||||
.map(AgentTagEntity::getTagName)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<AgentTagEntity> tagsToInsert = new ArrayList<>();
|
||||
for (String tagName : newTagNames) {
|
||||
if (!existTagNames.contains(tagName)) {
|
||||
AgentTagEntity tag = new AgentTagEntity();
|
||||
tag.setId(UUID.randomUUID().toString().replace("-", ""));
|
||||
tag.setTagName(tagName);
|
||||
tag.setSort(0);
|
||||
tag.setDeleted(0);
|
||||
tag.setCreatedAt(new Date());
|
||||
tag.setUpdatedAt(new Date());
|
||||
tagsToInsert.add(tag);
|
||||
}
|
||||
}
|
||||
|
||||
if (!tagsToInsert.isEmpty()) {
|
||||
baseDao.batchInsert(tagsToInsert);
|
||||
for (AgentTagEntity tag : tagsToInsert) {
|
||||
allTagIds.add(tag.getId());
|
||||
}
|
||||
}
|
||||
|
||||
for (AgentTagEntity existTag : existTags) {
|
||||
if (!allTagIds.contains(existTag.getId())) {
|
||||
allTagIds.add(existTag.getId());
|
||||
}
|
||||
}
|
||||
|
||||
if (tagIds != null && !tagIds.isEmpty()) {
|
||||
List<AgentTagEntity> tagIdEntities = baseDao.selectBatchIds(tagIds);
|
||||
for (AgentTagEntity tag : tagIdEntities) {
|
||||
if (tag != null && (currentTagNames.contains(tag.getTagName()) ||
|
||||
newTagNames.contains(tag.getTagName()))) {
|
||||
throw new RenException(ErrorCode.AGENT_TAG_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
allTagIds.addAll(tagIds);
|
||||
}
|
||||
|
||||
if (allTagIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<AgentTagRelationEntity> relations = new ArrayList<>();
|
||||
Date now = new Date();
|
||||
for (String tagId : allTagIds) {
|
||||
AgentTagRelationEntity relation = new AgentTagRelationEntity();
|
||||
relation.setId(UUID.randomUUID().toString().replace("-", ""));
|
||||
relation.setAgentId(agentId);
|
||||
relation.setTagId(tagId);
|
||||
relation.setCreatedAt(now);
|
||||
relation.setUpdatedAt(now);
|
||||
relations.add(relation);
|
||||
}
|
||||
agentTagRelationDao.batchInsertRelation(relations);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteAgentTags(String agentId) {
|
||||
agentTagRelationDao.deleteByAgentId(agentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AgentTagDTO> getTagsByAgentIds(List<String> agentIds) {
|
||||
if (agentIds == null || agentIds.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
List<AgentTagEntity> tags = baseDao.selectByAgentIds(agentIds);
|
||||
return tags.stream().map(this::convertToDTO).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AgentTagDTO> getAllTags() {
|
||||
List<AgentTagEntity> tags = baseDao.selectAll();
|
||||
return tags.stream().map(this::convertToDTO).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAgentIdsByTagName(String tagName) {
|
||||
return baseDao.selectAgentIdsByTagName(tagName);
|
||||
}
|
||||
|
||||
private AgentTagDTO convertToDTO(AgentTagEntity entity) {
|
||||
AgentTagDTO dto = new AgentTagDTO();
|
||||
dto.setId(entity.getId());
|
||||
dto.setTagName(entity.getTagName());
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
-- 标签表
|
||||
CREATE TABLE IF NOT EXISTS ai_agent_tag (
|
||||
id VARCHAR(32) NOT NULL COMMENT '主键',
|
||||
tag_name VARCHAR(64) NOT NULL COMMENT '标签名称',
|
||||
sort INT UNSIGNED DEFAULT 0 COMMENT '排序',
|
||||
creator BIGINT COMMENT '创建者',
|
||||
created_at DATETIME COMMENT '创建时间',
|
||||
updater BIGINT COMMENT '更新者',
|
||||
updated_at DATETIME COMMENT '更新时间',
|
||||
deleted TINYINT DEFAULT 0 COMMENT '删除标记',
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_tag_name (tag_name),
|
||||
INDEX idx_sort (sort)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='智能体标签表';
|
||||
|
||||
-- 智能体标签关联表
|
||||
CREATE TABLE IF NOT EXISTS ai_agent_tag_relation (
|
||||
id VARCHAR(32) NOT NULL COMMENT '主键',
|
||||
agent_id VARCHAR(32) NOT NULL COMMENT '智能体ID',
|
||||
tag_id VARCHAR(32) NOT NULL COMMENT '标签ID',
|
||||
creator BIGINT COMMENT '创建者',
|
||||
created_at DATETIME COMMENT '创建时间',
|
||||
updater BIGINT COMMENT '更新者',
|
||||
updated_at DATETIME COMMENT '更新时间',
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_agent_tag (agent_id, tag_id),
|
||||
INDEX idx_agent_id (agent_id),
|
||||
INDEX idx_tag_id (tag_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='智能体标签关联表';
|
||||
@@ -543,3 +543,9 @@ databaseChangeLog:
|
||||
- sqlFile:
|
||||
encoding: utf8
|
||||
path: classpath:db/changelog/202602271137.sql
|
||||
id: 202602281000
|
||||
author: rainv123
|
||||
changes:
|
||||
- sqlFile:
|
||||
encoding: utf8
|
||||
path: classpath:db/changelog/202602281000.sql
|
||||
|
||||
@@ -201,4 +201,7 @@
|
||||
10192=\u9002\u914D\u5668\u7C7B\u578B\u672A\u627E\u5230
|
||||
10193=\u8BBE\u5907ID\u4E0D\u80FD\u4E3A\u7A7A
|
||||
10194=\u8BBE\u5907\u4E0D\u5B58\u5728\u6216\u4E0D\u5728\u7EBF
|
||||
10195=OTA\u4E0A\u4F20\u6B21\u6570\u8D85\u8FC7\u9650\u5236
|
||||
10195=OTA\u4E0A\u4F20\u6B21\u6570\u8D85\u8FC7\u9650\u5236
|
||||
10196=\u6807\u7B7E\u540D\u79F0\u5DF2\u5B58\u5728
|
||||
10197=\u6807\u7B7E\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A
|
||||
10198=\u6807\u7B7E\u4E0D\u5B58\u5728
|
||||
@@ -201,4 +201,7 @@
|
||||
10192=Adaptertyp nicht gefunden
|
||||
10193=Adapter-ID darf nicht leer sein
|
||||
10194=Adapter nicht gefunden oder nicht online
|
||||
10195=OTA-Upload-Anzahl \u00FCberschreitet das Limit
|
||||
10195=OTA-Upload-Anzahl \u00FCberschreitet das Limit
|
||||
10196=Tag-Name existiert bereits
|
||||
10197=Tag-Name darf nicht leer sein
|
||||
10198=Tag nicht gefunden
|
||||
@@ -201,4 +201,7 @@
|
||||
10192=Adapter type not found
|
||||
10193=Device ID cannot be empty
|
||||
10194=Device not found or not online
|
||||
10195=OTA upload times exceed the limit
|
||||
10195=OTA upload times exceed the limit
|
||||
10196=Tag name already exists
|
||||
10197=Tag name cannot be empty
|
||||
10198=Tag not found
|
||||
@@ -201,4 +201,7 @@
|
||||
10192=Kh\u00F4ng t\u00ECm th\u1EA5y lo\u1EA1i b\u1ED9 chuy\u1EC3n \u0111\u1ED5i
|
||||
10193=ID thi\u1EBFt b\u1ECB kh\u00F4ng th\u1EC3 tr\u1ED1ng
|
||||
10194=Kh\u00F4ng t\u00ECm th\u1EA5y thi\u1EBFt b\u1ECB ho\u1EB7c thi\u1EBFt b\u1ECB kh\u00F4ng tr\u1EF1c tuy\u1EBFn
|
||||
10195=S\u1ED1 l\u1EA7n t\u1EA3i l\u00EAn OTA v\u01B0\u1EE3t qu\u00E1 gi\u1EDBi h\u1EA1n
|
||||
10195=S\u1ED1 l\u1EA7n t\u1EA3i l\u00EAn OTA v\u01B0\u1EE3t qu\u00E1 gi\u1EDBi h\u1EA1n
|
||||
10196=T\u00EAn th\u1EB9� \u0111\u00E3 t\u1ED3n t\u1EA1i
|
||||
10197=T\u00EAn th\u1EB9� kh\u00F4ng th\u1EC3 \u0111\u1EC3 tr\u1ED1ng
|
||||
10198=Kh\u00F4ng t\u00ECm th\u1EA5y th\u1EB9�
|
||||
@@ -201,4 +201,7 @@
|
||||
10192=\u9002\u914D\u5668\u985E\u578B\u672A\u627E\u5230
|
||||
10193=\u8A2D\u5099ID\u4E0D\u80FD\u4E3A\u7A7A
|
||||
10194=\u8A2D\u5099\u4E0D\u5B58\u5728\u6216\u672A\u5728\u7DDA
|
||||
10195=OTA\u4E0A\u4F20\u6B21\u6578\u8D85\u904E\u9650\u5236
|
||||
10195=OTA\u4E0A\u4F20\u6B21\u6578\u8D85\u904E\u9650\u5236
|
||||
10196=\u6A19\u7C64\u540D\u7A31\u5DF2\u5B58\u5728
|
||||
10197=\u6A19\u7C64\u540D\u7A31\u4E0D\u80FD\u4E3A\u7A7A
|
||||
10198=\u6A19\u7C64\u4E0D\u5B58\u5728
|
||||
@@ -0,0 +1,56 @@
|
||||
<?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.agent.dao.AgentTagDao">
|
||||
|
||||
<select id="selectByAgentId" resultType="xiaozhi.modules.agent.entity.AgentTagEntity">
|
||||
SELECT t.id, t.tag_name AS tagName, t.sort
|
||||
FROM ai_agent_tag t
|
||||
INNER JOIN ai_agent_tag_relation r ON t.id = r.tag_id
|
||||
WHERE r.agent_id = #{agentId} AND t.deleted = 0
|
||||
ORDER BY t.sort ASC
|
||||
</select>
|
||||
|
||||
<select id="selectByAgentIds" resultType="xiaozhi.modules.agent.entity.AgentTagEntity">
|
||||
SELECT t.id, t.tag_name AS tagName, t.sort, r.agent_id AS agentId
|
||||
FROM ai_agent_tag t
|
||||
INNER JOIN ai_agent_tag_relation r ON t.id = r.tag_id
|
||||
WHERE r.agent_id IN
|
||||
<foreach collection="agentIds" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
AND t.deleted = 0
|
||||
ORDER BY t.sort ASC
|
||||
</select>
|
||||
|
||||
<select id="selectAll" resultType="xiaozhi.modules.agent.entity.AgentTagEntity">
|
||||
SELECT id, tag_name AS tagName, sort
|
||||
FROM ai_agent_tag
|
||||
WHERE deleted = 0
|
||||
ORDER BY sort ASC
|
||||
</select>
|
||||
|
||||
<select id="selectAgentIdsByTagName" resultType="java.lang.String">
|
||||
SELECT r.agent_id
|
||||
FROM ai_agent_tag_relation r
|
||||
INNER JOIN ai_agent_tag t ON r.tag_id = t.id
|
||||
WHERE t.tag_name LIKE CONCAT('%', #{tagName}, '%') AND t.deleted = 0
|
||||
</select>
|
||||
|
||||
<select id="selectByTagNames" resultType="xiaozhi.modules.agent.entity.AgentTagEntity">
|
||||
SELECT id, tag_name AS tagName, sort
|
||||
FROM ai_agent_tag
|
||||
WHERE deleted = 0 AND tag_name IN
|
||||
<foreach collection="tagNames" item="name" open="(" separator="," close=")">
|
||||
#{name}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<insert id="batchInsert" parameterType="java.util.List">
|
||||
INSERT INTO ai_agent_tag (id, tag_name, sort, deleted, creator, created_at, updater, updated_at)
|
||||
VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.id}, #{item.tagName}, #{item.sort}, #{item.deleted}, #{item.creator}, #{item.createdAt}, #{item.updater}, #{item.updatedAt})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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.agent.dao.AgentTagRelationDao">
|
||||
|
||||
<delete id="deleteByAgentId">
|
||||
DELETE FROM ai_agent_tag_relation WHERE agent_id = #{agentId}
|
||||
</delete>
|
||||
|
||||
<insert id="insertRelation" parameterType="xiaozhi.modules.agent.entity.AgentTagRelationEntity">
|
||||
INSERT INTO ai_agent_tag_relation (id, agent_id, tag_id, creator, created_at, updater, updated_at)
|
||||
VALUES (#{id}, #{agentId}, #{tagId}, #{creator}, #{createdAt}, #{updater}, #{updatedAt})
|
||||
</insert>
|
||||
|
||||
<insert id="batchInsertRelation" parameterType="java.util.List">
|
||||
INSERT INTO ai_agent_tag_relation (id, agent_id, tag_id, creator, created_at, updater, updated_at)
|
||||
VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.id}, #{item.agentId}, #{item.tagId}, #{item.creator}, #{item.createdAt}, #{item.updater}, #{item.updatedAt})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user