mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-21 22:53:56 +08:00
refactor(manager-api): consolidate mybatis-plus 3.5.17 integration
This commit is contained in:
@@ -20,10 +20,7 @@
|
|||||||
<java.version>21</java.version>
|
<java.version>21</java.version>
|
||||||
<junit.version>5.10.1</junit.version>
|
<junit.version>5.10.1</junit.version>
|
||||||
<druid.version>1.2.20</druid.version>
|
<druid.version>1.2.20</druid.version>
|
||||||
<mybatisplus.version>3.5.5</mybatisplus.version>
|
<mybatisplus.version>3.5.17</mybatisplus.version>
|
||||||
<mybatisplus.starter.artifactId>mybatis-plus-boot-starter</mybatisplus.starter.artifactId>
|
|
||||||
<mybatis-spring.version>3.0.3</mybatis-spring.version>
|
|
||||||
<mybatisplus.compat.source>src/mybatis-plus-legacy/java</mybatisplus.compat.source>
|
|
||||||
<hutool.version>5.8.24</hutool.version>
|
<hutool.version>5.8.24</hutool.version>
|
||||||
<jsoup.version>1.19.1</jsoup.version>
|
<jsoup.version>1.19.1</jsoup.version>
|
||||||
<knife4j.version>4.6.0</knife4j.version>
|
<knife4j.version>4.6.0</knife4j.version>
|
||||||
@@ -179,13 +176,13 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.baomidou</groupId>
|
<groupId>com.baomidou</groupId>
|
||||||
<artifactId>${mybatisplus.starter.artifactId}</artifactId>
|
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||||
<version>${mybatisplus.version}</version>
|
<version>${mybatisplus.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mybatis</groupId>
|
<groupId>com.baomidou</groupId>
|
||||||
<artifactId>mybatis-spring</artifactId>
|
<artifactId>mybatis-plus-jsqlparser-4.9</artifactId>
|
||||||
<version>${mybatis-spring.version}</version>
|
<version>${mybatisplus.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.hutool</groupId>
|
<groupId>cn.hutool</groupId>
|
||||||
@@ -268,54 +265,9 @@
|
|||||||
</snapshots>
|
</snapshots>
|
||||||
</pluginRepository>
|
</pluginRepository>
|
||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
<profiles>
|
|
||||||
<!-- Use -Pmybatis-plus-3.5.6 or -Pmybatis-plus-3.5.17 with clean; adapters share class names. -->
|
|
||||||
<profile>
|
|
||||||
<id>mybatis-plus-3.5.6</id>
|
|
||||||
<properties>
|
|
||||||
<mybatisplus.version>3.5.6</mybatisplus.version>
|
|
||||||
</properties>
|
|
||||||
</profile>
|
|
||||||
<!-- MyBatis-Plus 3.5.17 moved Spring services and split out JSqlParser support. -->
|
|
||||||
<profile>
|
|
||||||
<id>mybatis-plus-3.5.17</id>
|
|
||||||
<properties>
|
|
||||||
<mybatisplus.version>3.5.17</mybatisplus.version>
|
|
||||||
<mybatisplus.starter.artifactId>mybatis-plus-spring-boot3-starter</mybatisplus.starter.artifactId>
|
|
||||||
<mybatis-spring.version>3.0.5</mybatis-spring.version>
|
|
||||||
<mybatisplus.compat.source>src/mybatis-plus-modern/java</mybatisplus.compat.source>
|
|
||||||
</properties>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.baomidou</groupId>
|
|
||||||
<artifactId>mybatis-plus-jsqlparser-4.9</artifactId>
|
|
||||||
<version>${mybatisplus.version}</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</profile>
|
|
||||||
</profiles>
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>build-helper-maven-plugin</artifactId>
|
|
||||||
<version>3.6.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>add-mybatis-plus-compatibility-sources</id>
|
|
||||||
<phase>generate-sources</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>add-source</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<sources>
|
|
||||||
<source>${project.basedir}/${mybatisplus.compat.source}</source>
|
|
||||||
</sources>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
import org.apache.ibatis.binding.MapperMethod;
|
import org.apache.ibatis.binding.MapperMethod;
|
||||||
import org.apache.ibatis.logging.Log;
|
import org.apache.ibatis.logging.Log;
|
||||||
@@ -27,7 +27,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
||||||
|
|
||||||
import xiaozhi.common.constant.Constant;
|
import xiaozhi.common.constant.Constant;
|
||||||
import xiaozhi.common.mybatisplus.MybatisPlusBatchHelper;
|
|
||||||
import xiaozhi.common.page.PageData;
|
import xiaozhi.common.page.PageData;
|
||||||
import xiaozhi.common.service.BaseService;
|
import xiaozhi.common.service.BaseService;
|
||||||
import xiaozhi.common.utils.ConvertUtils;
|
import xiaozhi.common.utils.ConvertUtils;
|
||||||
@@ -182,9 +181,9 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T> implements Bas
|
|||||||
* 执行批量操作
|
* 执行批量操作
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
protected <E> boolean executeBatch(Collection<E> list, int batchSize, BiConsumer<SqlSession, E> operation) {
|
protected <E> boolean executeBatch(Collection<E> list, int batchSize, BiFunction<SqlSession, E, Integer> operation) {
|
||||||
return MybatisPlusBatchHelper.executeBatch(SqlHelper.sqlSessionFactory(this.currentModelClass()), this.log,
|
return SqlHelper.executeBatch(SqlHelper.sqlSessionFactory(this.currentModelClass()), this.log, list, batchSize,
|
||||||
list, batchSize, operation);
|
operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -211,7 +210,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T> implements Bas
|
|||||||
return executeBatch(entityList, batchSize, (sqlSession, entity) -> {
|
return executeBatch(entityList, batchSize, (sqlSession, entity) -> {
|
||||||
MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>();
|
MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>();
|
||||||
param.put(Constants.ENTITY, entity);
|
param.put(Constants.ENTITY, entity);
|
||||||
sqlSession.update(sqlStatement, param);
|
return sqlSession.update(sqlStatement, param);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -1,6 +1,7 @@
|
|||||||
package xiaozhi.modules.agent.service;
|
package xiaozhi.modules.agent.service;
|
||||||
|
|
||||||
import xiaozhi.common.mybatisplus.MpService;
|
import com.baomidou.mybatisplus.extension.repository.IRepository;
|
||||||
|
|
||||||
import xiaozhi.modules.agent.entity.AgentChatAudioEntity;
|
import xiaozhi.modules.agent.entity.AgentChatAudioEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,7 +11,7 @@ import xiaozhi.modules.agent.entity.AgentChatAudioEntity;
|
|||||||
* @version 1.0, 2025/5/8
|
* @version 1.0, 2025/5/8
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public interface AgentChatAudioService extends MpService<AgentChatAudioEntity> {
|
public interface AgentChatAudioService extends IRepository<AgentChatAudioEntity> {
|
||||||
/**
|
/**
|
||||||
* 保存音频数据
|
* 保存音频数据
|
||||||
*
|
*
|
||||||
|
|||||||
+3
-2
@@ -3,8 +3,9 @@ package xiaozhi.modules.agent.service;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.repository.IRepository;
|
||||||
|
|
||||||
import xiaozhi.common.page.PageData;
|
import xiaozhi.common.page.PageData;
|
||||||
import xiaozhi.common.mybatisplus.MpService;
|
|
||||||
import xiaozhi.modules.agent.dto.AgentChatHistoryDTO;
|
import xiaozhi.modules.agent.dto.AgentChatHistoryDTO;
|
||||||
import xiaozhi.modules.agent.dto.AgentChatSessionDTO;
|
import xiaozhi.modules.agent.dto.AgentChatSessionDTO;
|
||||||
import xiaozhi.modules.agent.entity.AgentChatHistoryEntity;
|
import xiaozhi.modules.agent.entity.AgentChatHistoryEntity;
|
||||||
@@ -17,7 +18,7 @@ import xiaozhi.modules.agent.vo.AgentChatHistoryUserVO;
|
|||||||
* @version 1.0, 2025/4/30
|
* @version 1.0, 2025/4/30
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public interface AgentChatHistoryService extends MpService<AgentChatHistoryEntity> {
|
public interface AgentChatHistoryService extends IRepository<AgentChatHistoryEntity> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据智能体ID获取会话列表
|
* 根据智能体ID获取会话列表
|
||||||
|
|||||||
+3
-2
@@ -2,14 +2,15 @@ package xiaozhi.modules.agent.service;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import xiaozhi.common.mybatisplus.MpService;
|
import com.baomidou.mybatisplus.extension.repository.IRepository;
|
||||||
|
|
||||||
import xiaozhi.modules.agent.entity.AgentPluginMapping;
|
import xiaozhi.modules.agent.entity.AgentPluginMapping;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 针对表【ai_agent_plugin_mapping(Agent与插件的唯一映射表)】的数据库操作Service
|
* @description 针对表【ai_agent_plugin_mapping(Agent与插件的唯一映射表)】的数据库操作Service
|
||||||
* @createDate 2025-05-25 22:33:17
|
* @createDate 2025-05-25 22:33:17
|
||||||
*/
|
*/
|
||||||
public interface AgentPluginMappingService extends MpService<AgentPluginMapping> {
|
public interface AgentPluginMappingService extends IRepository<AgentPluginMapping> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据智能体id获取插件参数
|
* 根据智能体id获取插件参数
|
||||||
|
|||||||
+3
-2
@@ -1,6 +1,7 @@
|
|||||||
package xiaozhi.modules.agent.service;
|
package xiaozhi.modules.agent.service;
|
||||||
|
|
||||||
import xiaozhi.common.mybatisplus.MpService;
|
import com.baomidou.mybatisplus.extension.repository.IRepository;
|
||||||
|
|
||||||
import xiaozhi.modules.agent.entity.AgentTemplateEntity;
|
import xiaozhi.modules.agent.entity.AgentTemplateEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8,7 +9,7 @@ import xiaozhi.modules.agent.entity.AgentTemplateEntity;
|
|||||||
* @description 针对表【ai_agent_template(智能体配置模板表)】的数据库操作Service
|
* @description 针对表【ai_agent_template(智能体配置模板表)】的数据库操作Service
|
||||||
* @createDate 2025-03-22 11:48:18
|
* @createDate 2025-03-22 11:48:18
|
||||||
*/
|
*/
|
||||||
public interface AgentTemplateService extends MpService<AgentTemplateEntity> {
|
public interface AgentTemplateService extends IRepository<AgentTemplateEntity> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取默认模板
|
* 获取默认模板
|
||||||
|
|||||||
+3
-2
@@ -2,7 +2,8 @@ package xiaozhi.modules.agent.service.impl;
|
|||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import xiaozhi.common.mybatisplus.MpServiceImpl;
|
import com.baomidou.mybatisplus.spring.repository.CrudRepository;
|
||||||
|
|
||||||
import xiaozhi.modules.agent.dao.AiAgentChatAudioDao;
|
import xiaozhi.modules.agent.dao.AiAgentChatAudioDao;
|
||||||
import xiaozhi.modules.agent.entity.AgentChatAudioEntity;
|
import xiaozhi.modules.agent.entity.AgentChatAudioEntity;
|
||||||
import xiaozhi.modules.agent.service.AgentChatAudioService;
|
import xiaozhi.modules.agent.service.AgentChatAudioService;
|
||||||
@@ -15,7 +16,7 @@ import xiaozhi.modules.agent.service.AgentChatAudioService;
|
|||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class AgentChatAudioServiceImpl extends MpServiceImpl<AiAgentChatAudioDao, AgentChatAudioEntity>
|
public class AgentChatAudioServiceImpl extends CrudRepository<AiAgentChatAudioDao, AgentChatAudioEntity>
|
||||||
implements AgentChatAudioService {
|
implements AgentChatAudioService {
|
||||||
@Override
|
@Override
|
||||||
public String saveAudio(byte[] audioData) {
|
public String saveAudio(byte[] audioData) {
|
||||||
|
|||||||
+3
-2
@@ -14,8 +14,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.spring.repository.CrudRepository;
|
||||||
|
|
||||||
import xiaozhi.common.constant.Constant;
|
import xiaozhi.common.constant.Constant;
|
||||||
import xiaozhi.common.mybatisplus.MpServiceImpl;
|
|
||||||
import xiaozhi.common.page.PageData;
|
import xiaozhi.common.page.PageData;
|
||||||
import xiaozhi.common.utils.ConvertUtils;
|
import xiaozhi.common.utils.ConvertUtils;
|
||||||
import xiaozhi.common.utils.JsonUtils;
|
import xiaozhi.common.utils.JsonUtils;
|
||||||
@@ -38,7 +39,7 @@ import xiaozhi.modules.agent.vo.AgentChatHistoryUserVO;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class AgentChatHistoryServiceImpl extends MpServiceImpl<AiAgentChatHistoryDao, AgentChatHistoryEntity>
|
public class AgentChatHistoryServiceImpl extends CrudRepository<AiAgentChatHistoryDao, AgentChatHistoryEntity>
|
||||||
implements AgentChatHistoryService {
|
implements AgentChatHistoryService {
|
||||||
|
|
||||||
private final AgentChatTitleService agentChatTitleService;
|
private final AgentChatTitleService agentChatTitleService;
|
||||||
|
|||||||
+3
-2
@@ -9,10 +9,11 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
|
import com.baomidou.mybatisplus.spring.repository.CrudRepository;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import xiaozhi.common.utils.JsonUtils;
|
import xiaozhi.common.utils.JsonUtils;
|
||||||
import xiaozhi.common.mybatisplus.MpServiceImpl;
|
|
||||||
import xiaozhi.modules.agent.dao.AgentPluginMappingMapper;
|
import xiaozhi.modules.agent.dao.AgentPluginMappingMapper;
|
||||||
import xiaozhi.modules.agent.entity.AgentPluginMapping;
|
import xiaozhi.modules.agent.entity.AgentPluginMapping;
|
||||||
import xiaozhi.modules.agent.service.AgentPluginMappingService;
|
import xiaozhi.modules.agent.service.AgentPluginMappingService;
|
||||||
@@ -28,7 +29,7 @@ import xiaozhi.modules.model.service.ModelConfigService;
|
|||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AgentPluginMappingServiceImpl extends MpServiceImpl<AgentPluginMappingMapper, AgentPluginMapping>
|
public class AgentPluginMappingServiceImpl extends CrudRepository<AgentPluginMappingMapper, AgentPluginMapping>
|
||||||
implements AgentPluginMappingService {
|
implements AgentPluginMappingService {
|
||||||
private final AgentPluginMappingMapper agentPluginMappingMapper;
|
private final AgentPluginMappingMapper agentPluginMappingMapper;
|
||||||
private final KnowledgeBaseService knowledgeBaseService;
|
private final KnowledgeBaseService knowledgeBaseService;
|
||||||
|
|||||||
+5
-4
@@ -16,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.repository.IRepository;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import xiaozhi.common.constant.Constant;
|
import xiaozhi.common.constant.Constant;
|
||||||
@@ -482,10 +483,10 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
|
|||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
if (!toUpdate.isEmpty()) {
|
if (!toUpdate.isEmpty()) {
|
||||||
agentPluginMappingService.updateBatchById(toUpdate);
|
agentPluginMappingService.updateBatchById(toUpdate, IRepository.DEFAULT_BATCH_SIZE);
|
||||||
}
|
}
|
||||||
if (!toInsert.isEmpty()) {
|
if (!toInsert.isEmpty()) {
|
||||||
agentPluginMappingService.saveBatch(toInsert);
|
agentPluginMappingService.saveBatch(toInsert, IRepository.DEFAULT_BATCH_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. 删除本次不在提交列表里的插件映射
|
// 5. 删除本次不在提交列表里的插件映射
|
||||||
@@ -494,7 +495,7 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
|
|||||||
.map(AgentPluginMapping::getId)
|
.map(AgentPluginMapping::getId)
|
||||||
.toList();
|
.toList();
|
||||||
if (!toDelete.isEmpty()) {
|
if (!toDelete.isEmpty()) {
|
||||||
agentPluginMappingService.removeBatchByIds(toDelete);
|
agentPluginMappingService.removeByIds(toDelete);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -687,7 +688,7 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
|
|||||||
toInsert.add(mapping);
|
toInsert.add(mapping);
|
||||||
}
|
}
|
||||||
// 保存默认插件
|
// 保存默认插件
|
||||||
agentPluginMappingService.saveBatch(toInsert);
|
agentPluginMappingService.saveBatch(toInsert, IRepository.DEFAULT_BATCH_SIZE);
|
||||||
agentSnapshotService.createSnapshot(entity.getId(), "initial");
|
agentSnapshotService.createSnapshot(entity.getId(), "initial");
|
||||||
return entity.getId();
|
return entity.getId();
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -26,6 +26,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.repository.IRepository;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@@ -612,7 +613,7 @@ public class AgentSnapshotServiceImpl extends BaseServiceImpl<AgentSnapshotDao,
|
|||||||
mapping.setParamInfo(JsonUtils.toJsonString(info.getParamInfo()));
|
mapping.setParamInfo(JsonUtils.toJsonString(info.getParamInfo()));
|
||||||
return mapping;
|
return mapping;
|
||||||
}).toList();
|
}).toList();
|
||||||
agentPluginMappingService.saveBatch(mappings);
|
agentPluginMappingService.saveBatch(mappings, IRepository.DEFAULT_BATCH_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restoreContextProviders(String agentId,
|
private void restoreContextProviders(String agentId,
|
||||||
|
|||||||
+3
-2
@@ -4,7 +4,8 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import xiaozhi.common.mybatisplus.MpServiceImpl;
|
import com.baomidou.mybatisplus.spring.repository.CrudRepository;
|
||||||
|
|
||||||
import xiaozhi.modules.agent.dao.AgentTemplateDao;
|
import xiaozhi.modules.agent.dao.AgentTemplateDao;
|
||||||
import xiaozhi.modules.agent.entity.AgentTemplateEntity;
|
import xiaozhi.modules.agent.entity.AgentTemplateEntity;
|
||||||
import xiaozhi.modules.agent.service.AgentTemplateService;
|
import xiaozhi.modules.agent.service.AgentTemplateService;
|
||||||
@@ -20,7 +21,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
* @createDate 2025-03-22 11:48:18
|
* @createDate 2025-03-22 11:48:18
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class AgentTemplateServiceImpl extends MpServiceImpl<AgentTemplateDao, AgentTemplateEntity>
|
public class AgentTemplateServiceImpl extends CrudRepository<AgentTemplateDao, AgentTemplateEntity>
|
||||||
implements AgentTemplateService {
|
implements AgentTemplateService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+3
-2
@@ -22,11 +22,12 @@ import org.springframework.util.MultiValueMap;
|
|||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.spring.repository.CrudRepository;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import xiaozhi.common.constant.Constant;
|
import xiaozhi.common.constant.Constant;
|
||||||
import xiaozhi.common.exception.ErrorCode;
|
import xiaozhi.common.exception.ErrorCode;
|
||||||
import xiaozhi.common.exception.RenException;
|
import xiaozhi.common.exception.RenException;
|
||||||
import xiaozhi.common.mybatisplus.MpServiceImpl;
|
|
||||||
import xiaozhi.common.utils.ConvertUtils;
|
import xiaozhi.common.utils.ConvertUtils;
|
||||||
import xiaozhi.common.utils.JsonUtils;
|
import xiaozhi.common.utils.JsonUtils;
|
||||||
import xiaozhi.modules.agent.dao.AgentVoicePrintDao;
|
import xiaozhi.modules.agent.dao.AgentVoicePrintDao;
|
||||||
@@ -45,7 +46,7 @@ import xiaozhi.modules.sys.service.SysParamsService;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AgentVoicePrintServiceImpl extends MpServiceImpl<AgentVoicePrintDao, AgentVoicePrintEntity>
|
public class AgentVoicePrintServiceImpl extends CrudRepository<AgentVoicePrintDao, AgentVoicePrintEntity>
|
||||||
implements AgentVoicePrintService {
|
implements AgentVoicePrintService {
|
||||||
private final AgentChatAudioService agentChatAudioService;
|
private final AgentChatAudioService agentChatAudioService;
|
||||||
private final RestTemplate restTemplate;
|
private final RestTemplate restTemplate;
|
||||||
|
|||||||
-7
@@ -1,7 +0,0 @@
|
|||||||
package xiaozhi.common.mybatisplus;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stable project-level alias for the MyBatis-Plus service contract used by 3.5.5 and 3.5.6.
|
|
||||||
*/
|
|
||||||
public interface MpService<T> extends com.baomidou.mybatisplus.extension.service.IService<T> {
|
|
||||||
}
|
|
||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
package xiaozhi.common.mybatisplus;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stable project-level base class for the MyBatis-Plus 3.5.5/3.5.6 service implementation.
|
|
||||||
*/
|
|
||||||
public class MpServiceImpl<M extends BaseMapper<T>, T>
|
|
||||||
extends com.baomidou.mybatisplus.extension.service.impl.ServiceImpl<M, T> implements MpService<T> {
|
|
||||||
}
|
|
||||||
-24
@@ -1,24 +0,0 @@
|
|||||||
package xiaozhi.common.mybatisplus;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
|
|
||||||
import org.apache.ibatis.logging.Log;
|
|
||||||
import org.apache.ibatis.session.SqlSession;
|
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type-safe access to the MyBatis-Plus 3.5.5/3.5.6 batch callback API.
|
|
||||||
*/
|
|
||||||
public final class MybatisPlusBatchHelper {
|
|
||||||
private MybatisPlusBatchHelper() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static <E> boolean executeBatch(SqlSessionFactory sqlSessionFactory, Log log, Collection<E> entities,
|
|
||||||
int batchSize, BiConsumer<SqlSession, E> operation) {
|
|
||||||
return SqlHelper.executeBatch(sqlSessionFactory, log, entities, batchSize, operation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-7
@@ -1,7 +0,0 @@
|
|||||||
package xiaozhi.common.mybatisplus;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stable project-level alias for the MyBatis-Plus 3.5.17 Spring service contract.
|
|
||||||
*/
|
|
||||||
public interface MpService<T> extends com.baomidou.mybatisplus.spring.service.IService<T> {
|
|
||||||
}
|
|
||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
package xiaozhi.common.mybatisplus;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stable project-level base class for the MyBatis-Plus 3.5.17 Spring service implementation.
|
|
||||||
*/
|
|
||||||
public class MpServiceImpl<M extends BaseMapper<T>, T>
|
|
||||||
extends com.baomidou.mybatisplus.spring.service.impl.ServiceImpl<M, T> implements MpService<T> {
|
|
||||||
}
|
|
||||||
-27
@@ -1,27 +0,0 @@
|
|||||||
package xiaozhi.common.mybatisplus;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
|
|
||||||
import org.apache.ibatis.logging.Log;
|
|
||||||
import org.apache.ibatis.session.SqlSession;
|
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type-safe access to the MyBatis-Plus 3.5.17 batch callback API.
|
|
||||||
*/
|
|
||||||
public final class MybatisPlusBatchHelper {
|
|
||||||
private MybatisPlusBatchHelper() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static <E> boolean executeBatch(SqlSessionFactory sqlSessionFactory, Log log, Collection<E> entities,
|
|
||||||
int batchSize, BiConsumer<SqlSession, E> operation) {
|
|
||||||
return SqlHelper.executeBatch(sqlSessionFactory, log, entities, batchSize, (sqlSession, entity) -> {
|
|
||||||
operation.accept(sqlSession, entity);
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-47
@@ -1,47 +0,0 @@
|
|||||||
package xiaozhi.common.mybatisplus;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.ibatis.executor.BatchResult;
|
|
||||||
import org.apache.ibatis.logging.Log;
|
|
||||||
import org.apache.ibatis.mapping.MappedStatement;
|
|
||||||
import org.apache.ibatis.session.ExecutorType;
|
|
||||||
import org.apache.ibatis.session.SqlSession;
|
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
class MybatisPlusBatchHelperTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void executesBatchThroughSelectedVersionAdapter() {
|
|
||||||
SqlSessionFactory sqlSessionFactory = mock(SqlSessionFactory.class);
|
|
||||||
SqlSession sqlSession = mock(SqlSession.class);
|
|
||||||
Log log = mock(Log.class);
|
|
||||||
when(sqlSessionFactory.openSession(ExecutorType.BATCH)).thenReturn(sqlSession);
|
|
||||||
|
|
||||||
BatchResult batchResult = new BatchResult(mock(MappedStatement.class), "INSERT");
|
|
||||||
batchResult.setUpdateCounts(new int[] { 1, 1 });
|
|
||||||
when(sqlSession.flushStatements()).thenReturn(List.of(batchResult));
|
|
||||||
|
|
||||||
List<String> processed = new ArrayList<>();
|
|
||||||
boolean result = MybatisPlusBatchHelper.executeBatch(sqlSessionFactory, log, List.of("first", "second"), 2,
|
|
||||||
(session, entity) -> {
|
|
||||||
assertSame(sqlSession, session);
|
|
||||||
processed.add(entity);
|
|
||||||
});
|
|
||||||
|
|
||||||
assertTrue(result);
|
|
||||||
assertEquals(List.of("first", "second"), processed);
|
|
||||||
verify(sqlSession).flushStatements();
|
|
||||||
verify(sqlSession).commit(true);
|
|
||||||
verify(sqlSession).close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,200 @@
|
|||||||
|
package xiaozhi.common.service.impl;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.CALLS_REAL_METHODS;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.mockStatic;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoInteractions;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
import org.apache.ibatis.binding.MapperMethod;
|
||||||
|
import org.apache.ibatis.executor.BatchResult;
|
||||||
|
import org.apache.ibatis.mapping.MappedStatement;
|
||||||
|
import org.apache.ibatis.session.ExecutorType;
|
||||||
|
import org.apache.ibatis.session.SqlSession;
|
||||||
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.MockedStatic;
|
||||||
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.enums.SqlMethod;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||||
|
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
||||||
|
|
||||||
|
class BaseServiceImplTest {
|
||||||
|
private static final String INSERT_STATEMENT = TestMapper.class.getName() + ".insert";
|
||||||
|
private static final String UPDATE_STATEMENT = TestMapper.class.getName() + ".updateById";
|
||||||
|
|
||||||
|
private final TestService service = new TestService();
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void clearTransactionSynchronization() {
|
||||||
|
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||||
|
TransactionSynchronizationManager.clearSynchronization();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void insertBatchFlushesAtTheRequestedBatchSizeAndCommitsWithoutATransaction() {
|
||||||
|
SqlSessionFactory sqlSessionFactory = mock(SqlSessionFactory.class);
|
||||||
|
SqlSession sqlSession = mock(SqlSession.class);
|
||||||
|
when(sqlSessionFactory.openSession(ExecutorType.BATCH)).thenReturn(sqlSession);
|
||||||
|
when(sqlSession.insert(eq(INSERT_STATEMENT), any(TestEntity.class))).thenReturn(1);
|
||||||
|
when(sqlSession.flushStatements())
|
||||||
|
.thenReturn(List.of(batchResult(1, 1)), List.of(batchResult(1)));
|
||||||
|
|
||||||
|
TestEntity first = new TestEntity(1L);
|
||||||
|
TestEntity second = new TestEntity(2L);
|
||||||
|
TestEntity third = new TestEntity(3L);
|
||||||
|
|
||||||
|
try (MockedStatic<SqlHelper> sqlHelper = sqlHelperUsing(sqlSessionFactory)) {
|
||||||
|
assertTrue(service.insertBatch(List.of(first, second, third), 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
verify(sqlSession).insert(INSERT_STATEMENT, first);
|
||||||
|
verify(sqlSession).insert(INSERT_STATEMENT, second);
|
||||||
|
verify(sqlSession).insert(INSERT_STATEMENT, third);
|
||||||
|
verify(sqlSession, times(2)).flushStatements();
|
||||||
|
verify(sqlSession).commit(true);
|
||||||
|
verify(sqlSession).close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updateBatchByIdPassesEachEntityAndReturnsSuccessfulFlushResult() {
|
||||||
|
SqlSessionFactory sqlSessionFactory = mock(SqlSessionFactory.class);
|
||||||
|
SqlSession sqlSession = mock(SqlSession.class);
|
||||||
|
when(sqlSessionFactory.openSession(ExecutorType.BATCH)).thenReturn(sqlSession);
|
||||||
|
when(sqlSession.update(eq(UPDATE_STATEMENT), any())).thenReturn(1);
|
||||||
|
when(sqlSession.flushStatements()).thenReturn(List.of(batchResult(1, 1)));
|
||||||
|
|
||||||
|
TestEntity first = new TestEntity(1L);
|
||||||
|
TestEntity second = new TestEntity(2L);
|
||||||
|
|
||||||
|
try (MockedStatic<SqlHelper> sqlHelper = sqlHelperUsing(sqlSessionFactory)) {
|
||||||
|
assertTrue(service.updateBatchById(List.of(first, second), 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
ArgumentCaptor<Object> params = ArgumentCaptor.forClass(Object.class);
|
||||||
|
verify(sqlSession, times(2)).update(eq(UPDATE_STATEMENT), params.capture());
|
||||||
|
assertSame(first, entityFrom(params.getAllValues().get(0)));
|
||||||
|
assertSame(second, entityFrom(params.getAllValues().get(1)));
|
||||||
|
verify(sqlSession).flushStatements();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void batchCallbacksReturnActualAffectedRowCounts() {
|
||||||
|
SqlSession sqlSession = mock(SqlSession.class);
|
||||||
|
when(sqlSession.insert(eq(INSERT_STATEMENT), any(TestEntity.class))).thenReturn(3);
|
||||||
|
when(sqlSession.update(eq(UPDATE_STATEMENT), any())).thenReturn(2);
|
||||||
|
CallbackCapturingTestService capturingService = new CallbackCapturingTestService(sqlSession);
|
||||||
|
TestEntity entity = new TestEntity(1L);
|
||||||
|
|
||||||
|
assertTrue(capturingService.insertBatch(List.of(entity), 7));
|
||||||
|
assertEquals(7, capturingService.batchSize);
|
||||||
|
assertEquals(List.of(3), capturingService.affectedRows);
|
||||||
|
|
||||||
|
assertTrue(capturingService.updateBatchById(List.of(entity), 9));
|
||||||
|
assertEquals(9, capturingService.batchSize);
|
||||||
|
assertEquals(List.of(2), capturingService.affectedRows);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void emptyBatchesReturnFalseWithoutOpeningABatchSession() {
|
||||||
|
SqlSessionFactory sqlSessionFactory = mock(SqlSessionFactory.class);
|
||||||
|
|
||||||
|
try (MockedStatic<SqlHelper> sqlHelper = sqlHelperUsing(sqlSessionFactory)) {
|
||||||
|
assertFalse(service.insertBatch(List.of(), 10));
|
||||||
|
assertFalse(service.updateBatchById(List.of(), 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
verifyNoInteractions(sqlSessionFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void activeTransactionSynchronizationUsesTransactionAwareCommitAndLifecycle() {
|
||||||
|
SqlSessionFactory sqlSessionFactory = mock(SqlSessionFactory.class);
|
||||||
|
SqlSession sqlSession = mock(SqlSession.class);
|
||||||
|
when(sqlSessionFactory.openSession(ExecutorType.BATCH)).thenReturn(sqlSession);
|
||||||
|
when(sqlSession.insert(eq(INSERT_STATEMENT), any(TestEntity.class))).thenReturn(1);
|
||||||
|
when(sqlSession.flushStatements()).thenReturn(List.of(batchResult(1)));
|
||||||
|
TransactionSynchronizationManager.initSynchronization();
|
||||||
|
|
||||||
|
try (MockedStatic<SqlHelper> sqlHelper = sqlHelperUsing(sqlSessionFactory)) {
|
||||||
|
assertTrue(service.insertBatch(List.of(new TestEntity(1L)), 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
verify(sqlSession).flushStatements();
|
||||||
|
verify(sqlSession).commit(false);
|
||||||
|
verify(sqlSession, never()).commit(true);
|
||||||
|
verify(sqlSession, never()).close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private static MockedStatic<SqlHelper> sqlHelperUsing(SqlSessionFactory sqlSessionFactory) {
|
||||||
|
MockedStatic<SqlHelper> sqlHelper = mockStatic(SqlHelper.class, CALLS_REAL_METHODS);
|
||||||
|
sqlHelper.when(() -> SqlHelper.sqlSessionFactory(TestEntity.class)).thenReturn(sqlSessionFactory);
|
||||||
|
return sqlHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BatchResult batchResult(int... updateCounts) {
|
||||||
|
BatchResult result = new BatchResult(mock(MappedStatement.class), "batch");
|
||||||
|
result.setUpdateCounts(updateCounts);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object entityFrom(Object parameter) {
|
||||||
|
assertTrue(parameter instanceof MapperMethod.ParamMap<?>);
|
||||||
|
return ((Map<?, ?>) parameter).get(Constants.ENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface TestMapper extends BaseMapper<TestEntity> {
|
||||||
|
}
|
||||||
|
|
||||||
|
private record TestEntity(Long id) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TestService extends BaseServiceImpl<TestMapper, TestEntity> {
|
||||||
|
@Override
|
||||||
|
protected String getSqlStatement(SqlMethod sqlMethod) {
|
||||||
|
return switch (sqlMethod) {
|
||||||
|
case INSERT_ONE -> INSERT_STATEMENT;
|
||||||
|
case UPDATE_BY_ID -> UPDATE_STATEMENT;
|
||||||
|
default -> throw new IllegalArgumentException("Unexpected SQL method: " + sqlMethod);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class CallbackCapturingTestService extends TestService {
|
||||||
|
private final SqlSession sqlSession;
|
||||||
|
private int batchSize;
|
||||||
|
private List<Integer> affectedRows;
|
||||||
|
|
||||||
|
private CallbackCapturingTestService(SqlSession sqlSession) {
|
||||||
|
this.sqlSession = sqlSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected <E> boolean executeBatch(Collection<E> list, int batchSize,
|
||||||
|
BiFunction<SqlSession, E, Integer> operation) {
|
||||||
|
this.batchSize = batchSize;
|
||||||
|
this.affectedRows = list.stream().map(entity -> operation.apply(sqlSession, entity)).toList();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-2
@@ -19,6 +19,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.repository.IRepository;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@@ -1172,7 +1173,7 @@ class AgentSnapshotServiceImplTest {
|
|||||||
&& "普通话".equals(agent.getTtsLanguage())
|
&& "普通话".equals(agent.getTtsLanguage())
|
||||||
&& "".equals(agent.getSummaryMemory())
|
&& "".equals(agent.getSummaryMemory())
|
||||||
&& Integer.valueOf(0).equals(agent.getChatHistoryConf())));
|
&& Integer.valueOf(0).equals(agent.getChatHistoryConf())));
|
||||||
inOrder.verify(pluginMappingService).saveBatch(any());
|
inOrder.verify(pluginMappingService).saveBatch(any(), eq(IRepository.DEFAULT_BATCH_SIZE));
|
||||||
inOrder.verify(snapshotService).createSnapshot(agentId, "initial");
|
inOrder.verify(snapshotService).createSnapshot(agentId, "initial");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1407,7 +1408,7 @@ class AgentSnapshotServiceImplTest {
|
|||||||
return mapping != null
|
return mapping != null
|
||||||
&& "plugin".equals(mapping.getPluginId())
|
&& "plugin".equals(mapping.getPluginId())
|
||||||
&& mapping.getParamInfo().contains("target");
|
&& mapping.getParamInfo().contains("target");
|
||||||
}));
|
}), eq(IRepository.DEFAULT_BATCH_SIZE));
|
||||||
verify(snapshotDao).insertWithNextVersion(argThat(snapshot -> "restore".equals(snapshot.getSource())));
|
verify(snapshotDao).insertWithNextVersion(argThat(snapshot -> "restore".equals(snapshot.getSource())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user