mirror of
https://github.com/ccmjga/zhilu-admin
synced 2026-04-12 01:17:21 +00:00
fix ai reaction
This commit is contained in:
@@ -21,32 +21,30 @@ public class DepartmentOperatorTool {
|
|||||||
|
|
||||||
@Tool(value = "创建部门")
|
@Tool(value = "创建部门")
|
||||||
void createDepartment(
|
void createDepartment(
|
||||||
@P(value = "部门名称") String departmentName,
|
@P(value = "部门名称") String name, @P(value = "上级部门名称", required = false) String parentName) {
|
||||||
@P(value = "上级部门名称", required = false) String parentDepartmentName) {
|
Department exist = departmentRepository.fetchOneByName(name);
|
||||||
Department exist = departmentRepository.fetchOneByName(departmentName);
|
|
||||||
if (exist != null) {
|
if (exist != null) {
|
||||||
throw new BusinessException("当前部门已存在");
|
throw new BusinessException("当前部门已存在");
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(parentDepartmentName)) {
|
if (StringUtils.isNotEmpty(parentName)) {
|
||||||
Department parent = departmentRepository.fetchOneByName(parentDepartmentName);
|
Department parent = departmentRepository.fetchOneByName(parentName);
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
throw new BusinessException("上级部门不存在");
|
throw new BusinessException("上级部门不存在");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
departmentService.upsertDepartment(new Department(null, departmentName, null));
|
departmentService.upsertDepartment(new Department(null, name, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Tool(value = "更新部门/绑定上级部门/解绑上级部门")
|
@Tool(value = "更新部门/绑定上级部门/解绑上级部门")
|
||||||
void updateDepartment(
|
void updateDepartment(
|
||||||
@P(value = "部门名称") String departmentName,
|
@P(value = "部门名称") String name, @P(value = "上级部门名称", required = false) String parentName) {
|
||||||
@P(value = "上级部门名称", required = false) String parentDepartmentName) {
|
Department exist = departmentRepository.fetchOneByName(name);
|
||||||
Department exist = departmentRepository.fetchOneByName(departmentName);
|
|
||||||
if (exist == null) {
|
if (exist == null) {
|
||||||
throw new BusinessException("不存在的部门");
|
throw new BusinessException("不存在的部门");
|
||||||
}
|
}
|
||||||
Department department = new Department(null, departmentName, null);
|
Department department = new Department(null, name, null);
|
||||||
if (StringUtils.isNotEmpty(parentDepartmentName)) {
|
if (StringUtils.isNotEmpty(parentName)) {
|
||||||
Department parent = departmentRepository.fetchOneByName(parentDepartmentName);
|
Department parent = departmentRepository.fetchOneByName(parentName);
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
throw new BusinessException("上级部门不存在");
|
throw new BusinessException("上级部门不存在");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,17 +16,17 @@ public class PositionOperatorTool {
|
|||||||
private final PositionRepository positionRepository;
|
private final PositionRepository positionRepository;
|
||||||
|
|
||||||
@Tool(value = "创建岗位")
|
@Tool(value = "创建岗位")
|
||||||
void createPosition(@P("岗位名称") String positionName) {
|
void createPosition(@P("岗位名称") String name) {
|
||||||
Position position = positionRepository.fetchOneByName(positionName);
|
Position position = positionRepository.fetchOneByName(name);
|
||||||
if (position != null) {
|
if (position != null) {
|
||||||
throw new BusinessException("岗位已存在");
|
throw new BusinessException("岗位已存在");
|
||||||
}
|
}
|
||||||
positionRepository.merge(new Position(null, positionName));
|
positionRepository.merge(new Position(null, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Tool(value = "删除岗位")
|
@Tool(value = "删除岗位")
|
||||||
void deletePosition(@P("岗位名称") String positionName) {
|
void deletePosition(@P("岗位名称") String name) {
|
||||||
Position position = positionRepository.fetchOneByName(positionName);
|
Position position = positionRepository.fetchOneByName(name);
|
||||||
if (position == null) {
|
if (position == null) {
|
||||||
throw new BusinessException("岗位不存在");
|
throw new BusinessException("岗位不存在");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,12 +30,12 @@ public class UserRolePermissionOperatorTool {
|
|||||||
private final PositionRepository positionRepository;
|
private final PositionRepository positionRepository;
|
||||||
|
|
||||||
@Tool(value = {"创建用户", "入职申请", "开通账号"})
|
@Tool(value = {"创建用户", "入职申请", "开通账号"})
|
||||||
void createUser(@P(value = "用户名") String username) {
|
void createUser(@P(value = "用户名") String name) {
|
||||||
User user = userRepository.fetchOneByUsername(username);
|
User user = userRepository.fetchOneByUsername(name);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
throw new BusinessException("用户已存在");
|
throw new BusinessException("用户已存在");
|
||||||
}
|
}
|
||||||
identityAccessService.upsertUser(new UserUpsertDto(null, username, username, true));
|
identityAccessService.upsertUser(new UserUpsertDto(null, name, name, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Tool(value = "查询用户")
|
// @Tool(value = "查询用户")
|
||||||
@@ -50,15 +50,15 @@ public class UserRolePermissionOperatorTool {
|
|||||||
userRepository.deleteByUsername(username);
|
userRepository.deleteByUsername(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Tool(value = "编辑/更新/更改用户")
|
@Tool(value = {"编辑用户", "更新用户", "更改用户"})
|
||||||
void updateUser(
|
void updateUser(
|
||||||
@P(value = "用户名") String username,
|
@P(value = "用户名") String name,
|
||||||
@P(value = "密码", required = false) String password,
|
@P(value = "密码", required = false) String password,
|
||||||
@P(value = "是否开启", required = false) Boolean enable) {
|
@P(value = "是否开启", required = false) Boolean enable) {
|
||||||
identityAccessService.upsertUser(new UserUpsertDto(null, username, password, enable));
|
identityAccessService.upsertUser(new UserUpsertDto(null, name, password, enable));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Tool(value = "给用户绑定/分配角色")
|
@Tool(value = {"给用户绑定角色", "给用户分配角色"})
|
||||||
void bindRoleToUser(
|
void bindRoleToUser(
|
||||||
@P(value = "用户名") String username, @P(value = "角色名称") List<String> roleNames) {
|
@P(value = "用户名") String username, @P(value = "角色名称") List<String> roleNames) {
|
||||||
User user = checkUserExistBy(username);
|
User user = checkUserExistBy(username);
|
||||||
@@ -66,7 +66,7 @@ public class UserRolePermissionOperatorTool {
|
|||||||
identityAccessService.bindRoleToUser(user.getId(), bindRoleIds);
|
identityAccessService.bindRoleToUser(user.getId(), bindRoleIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Tool(value = "给用户解绑/撤销角色")
|
@Tool(value = {"给用户解绑角色", "给用户撤销角色"})
|
||||||
void unbindRoleToUser(
|
void unbindRoleToUser(
|
||||||
@P(value = "用户名") String username, @P(value = "角色名称") List<String> roleNames) {
|
@P(value = "用户名") String username, @P(value = "角色名称") List<String> roleNames) {
|
||||||
User user = checkUserExistBy(username);
|
User user = checkUserExistBy(username);
|
||||||
@@ -74,7 +74,7 @@ public class UserRolePermissionOperatorTool {
|
|||||||
identityAccessService.unBindRoleToUser(user.getId(), bindRoleIds);
|
identityAccessService.unBindRoleToUser(user.getId(), bindRoleIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Tool(value = "给用户绑定/分配部门")
|
@Tool(value = {"给用户绑定部门", "给用户分配部门"})
|
||||||
void bindDepartmentToUser(
|
void bindDepartmentToUser(
|
||||||
@P(value = "用户名") String username, @P(value = "部门名称列表") List<String> departmentNames) {
|
@P(value = "用户名") String username, @P(value = "部门名称列表") List<String> departmentNames) {
|
||||||
User user = checkUserExistBy(username);
|
User user = checkUserExistBy(username);
|
||||||
@@ -87,7 +87,7 @@ public class UserRolePermissionOperatorTool {
|
|||||||
new DepartmentBindDto(user.getId(), departments.stream().map(Department::getId).toList()));
|
new DepartmentBindDto(user.getId(), departments.stream().map(Department::getId).toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Tool(value = "给用户绑定/分配部门")
|
@Tool(value = {"给用户解绑部门", "给用户撤销部门"})
|
||||||
void unbindDepartmentToUser(
|
void unbindDepartmentToUser(
|
||||||
@P(value = "用户名") String username, @P(value = "部门名称列表") List<String> departmentNames) {
|
@P(value = "用户名") String username, @P(value = "部门名称列表") List<String> departmentNames) {
|
||||||
User user = checkUserExistBy(username);
|
User user = checkUserExistBy(username);
|
||||||
@@ -108,7 +108,7 @@ public class UserRolePermissionOperatorTool {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Tool(value = "给用户绑定/分配岗位")
|
@Tool(value = {"给用户绑定岗位", "给用户分配岗位"})
|
||||||
void bindPositionToUser(
|
void bindPositionToUser(
|
||||||
@P(value = "用户名") String username, @P(value = "岗位名称列表") List<String> positionNames) {
|
@P(value = "用户名") String username, @P(value = "岗位名称列表") List<String> positionNames) {
|
||||||
User user = checkUserExistBy(username);
|
User user = checkUserExistBy(username);
|
||||||
@@ -120,7 +120,7 @@ public class UserRolePermissionOperatorTool {
|
|||||||
new PositionBindDto(user.getId(), positions.stream().map(Position::getId).toList()));
|
new PositionBindDto(user.getId(), positions.stream().map(Position::getId).toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Tool(value = "给用户解绑/撤销岗位")
|
@Tool(value = {"给用户解绑岗位", "给用户撤销岗位"})
|
||||||
void unbindPositionToUser(
|
void unbindPositionToUser(
|
||||||
@P(value = "用户名") String username, @P(value = "岗位名称列表") List<String> positionNames) {
|
@P(value = "用户名") String username, @P(value = "岗位名称列表") List<String> positionNames) {
|
||||||
User user = checkUserExistBy(username);
|
User user = checkUserExistBy(username);
|
||||||
@@ -140,28 +140,26 @@ public class UserRolePermissionOperatorTool {
|
|||||||
return roles.stream().map(Role::getId).toList();
|
return roles.stream().map(Role::getId).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Tool(value = "创建角色")
|
@Tool(value = {"创建角色", "创建系统角色"})
|
||||||
void createRole(
|
void createRole(
|
||||||
@P(value = "角色名称") String roleName, @P(value = "角色编码", required = false) String roleCode) {
|
@P(value = "角色名称") String name, @P(value = "角色编码", required = false) String code) {
|
||||||
if (StringUtils.isEmpty(roleCode)) {
|
if (StringUtils.isEmpty(code)) {
|
||||||
roleCode = roleName;
|
code = name;
|
||||||
}
|
}
|
||||||
if (identityAccessService.isRoleDuplicate(roleCode, roleName)) {
|
if (identityAccessService.isRoleDuplicate(code, name)) {
|
||||||
throw new BusinessException("角色已存在");
|
throw new BusinessException("角色已存在");
|
||||||
}
|
}
|
||||||
identityAccessService.upsertRole(new RoleUpsertDto(null, roleName, roleCode));
|
identityAccessService.upsertRole(new RoleUpsertDto(null, name, code));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Tool(value = "更新角色")
|
@Tool(value = "更新角色")
|
||||||
void updateRole(@P(value = "角色名称") String roleName, @P(value = "角色编码") String roleCode) {
|
void updateRole(@P(value = "角色名称") String name, @P(value = "角色编码") String code) {
|
||||||
identityAccessService.upsertRole(new RoleUpsertDto(null, roleName, roleCode));
|
identityAccessService.upsertRole(new RoleUpsertDto(null, name, code));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Tool(value = "更新权限")
|
@Tool(value = "更新权限")
|
||||||
void updatePermission(
|
void updatePermission(@P(value = "权限名称") String name, @P(value = "权限编码") String code) {
|
||||||
@P(value = "权限名称") String permissionName, @P(value = "权限编码") String permissionCode) {
|
identityAccessService.upsertPermission(new PermissionUpsertDto(null, name, code));
|
||||||
identityAccessService.upsertPermission(
|
|
||||||
new PermissionUpsertDto(null, permissionName, permissionCode));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Tool(value = "删除角色")
|
@Tool(value = "删除角色")
|
||||||
@@ -182,7 +180,7 @@ public class UserRolePermissionOperatorTool {
|
|||||||
permissionRepository.deleteById(permission.getId());
|
permissionRepository.deleteById(permission.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Tool(value = "给角色绑定/分配权限")
|
@Tool(value = {"给角色绑定权限", "给用户分配权限"})
|
||||||
void bindPermissionToRole(
|
void bindPermissionToRole(
|
||||||
@P(value = "角色名称") String roleName, @P(value = "权限名称") List<String> permissionNames) {
|
@P(value = "角色名称") String roleName, @P(value = "权限名称") List<String> permissionNames) {
|
||||||
Role role = roleRepository.fetchOneByName(roleName);
|
Role role = roleRepository.fetchOneByName(roleName);
|
||||||
@@ -198,7 +196,7 @@ public class UserRolePermissionOperatorTool {
|
|||||||
role.getId(), permissions.stream().map(Permission::getId).toList());
|
role.getId(), permissions.stream().map(Permission::getId).toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Tool(value = "给角色解绑/撤销权限")
|
@Tool(value = {"给角色解绑权限", "给角色撤销权限"})
|
||||||
void unBindPermissionToRole(
|
void unBindPermissionToRole(
|
||||||
@P(value = "角色名称") String roleName, @P(value = "权限名称") List<String> permissionNames) {
|
@P(value = "角色名称") String roleName, @P(value = "权限名称") List<String> permissionNames) {
|
||||||
Role role = roleRepository.fetchOneByName(roleName);
|
Role role = roleRepository.fetchOneByName(roleName);
|
||||||
@@ -216,15 +214,13 @@ public class UserRolePermissionOperatorTool {
|
|||||||
|
|
||||||
@Tool(value = "创建权限")
|
@Tool(value = "创建权限")
|
||||||
void createPermission(
|
void createPermission(
|
||||||
@P(value = "权限名称") String permissionName,
|
@P(value = "权限名称") String name, @P(value = "权限编码", required = false) String code) {
|
||||||
@P(value = "权限编码", required = false) String permissionCode) {
|
if (StringUtils.isEmpty(code)) {
|
||||||
if (StringUtils.isEmpty(permissionCode)) {
|
code = name;
|
||||||
permissionCode = permissionName;
|
|
||||||
}
|
}
|
||||||
if (identityAccessService.isPermissionDuplicate(permissionName, permissionName)) {
|
if (identityAccessService.isPermissionDuplicate(name, name)) {
|
||||||
throw new BusinessException("权限已存在");
|
throw new BusinessException("权限已存在");
|
||||||
}
|
}
|
||||||
identityAccessService.upsertPermission(
|
identityAccessService.upsertPermission(new PermissionUpsertDto(null, name, code));
|
||||||
new PermissionUpsertDto(null, permissionName, permissionCode));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,17 +47,25 @@ public class AiController {
|
|||||||
Sinks.Many<String> sink = Sinks.many().unicast().onBackpressureBuffer();
|
Sinks.Many<String> sink = Sinks.many().unicast().onBackpressureBuffer();
|
||||||
TokenStream chat = aiChatService.actionExecuteWithZhiPu(principal.getName(), userMessage);
|
TokenStream chat = aiChatService.actionExecuteWithZhiPu(principal.getName(), userMessage);
|
||||||
chat.onPartialResponse(
|
chat.onPartialResponse(
|
||||||
text ->
|
(text) -> {
|
||||||
sink.tryEmitNext(
|
log.debug("ai action partialResponse: {}", text);
|
||||||
StringUtils.isNotEmpty(text) ? text.replace(" ", "␣").replace("\t", "⇥") : ""))
|
sink.tryEmitNext(
|
||||||
|
StringUtils.isNotEmpty(text) ? text.replace(" ", "␣").replace("\t", "⇥") : "");
|
||||||
|
})
|
||||||
.onToolExecuted(
|
.onToolExecuted(
|
||||||
toolExecution -> log.debug("当前请求 {} 成功执行函数调用: {}", userMessage, toolExecution))
|
toolExecution -> log.debug("当前请求 {} 成功执行函数调用: {}", userMessage, toolExecution))
|
||||||
.onCompleteResponse(
|
.onCompleteResponse(
|
||||||
r -> {
|
r -> {
|
||||||
|
log.debug("ai action completeResponse: {}", r);
|
||||||
|
sink.tryEmitComplete();
|
||||||
|
sink.emitComplete(Sinks.EmitFailureHandler.FAIL_FAST);
|
||||||
|
})
|
||||||
|
.onError(
|
||||||
|
(e) -> {
|
||||||
|
sink.tryEmitError(e);
|
||||||
sink.tryEmitComplete();
|
sink.tryEmitComplete();
|
||||||
sink.emitComplete(Sinks.EmitFailureHandler.FAIL_FAST);
|
sink.emitComplete(Sinks.EmitFailureHandler.FAIL_FAST);
|
||||||
})
|
})
|
||||||
.onError(sink::tryEmitError)
|
|
||||||
.start();
|
.start();
|
||||||
return sink.asFlux().timeout(Duration.ofSeconds(120));
|
return sink.asFlux().timeout(Duration.ofSeconds(120));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user