From 7fdd613f3dbc75cc2fcb10db70bb615abe57a726 Mon Sep 17 00:00:00 2001 From: jack ning Date: Sun, 27 Apr 2025 22:59:27 +0800 Subject: [PATCH] update --- .../config/properties/BytedeskProperties.java | 6 +- .../com/bytedesk/core/utils/ConvertUtils.java | 93 +++++++++++-------- 2 files changed, 57 insertions(+), 42 deletions(-) diff --git a/modules/core/src/main/java/com/bytedesk/core/config/properties/BytedeskProperties.java b/modules/core/src/main/java/com/bytedesk/core/config/properties/BytedeskProperties.java index 38205fd7d4..326df2dd55 100644 --- a/modules/core/src/main/java/com/bytedesk/core/config/properties/BytedeskProperties.java +++ b/modules/core/src/main/java/com/bytedesk/core/config/properties/BytedeskProperties.java @@ -2,7 +2,7 @@ * @Author: jackning 270580156@qq.com * @Date: 2024-01-30 09:14:39 * @LastEditors: jackning 270580156@qq.com - * @LastEditTime: 2025-04-23 17:44:36 + * @LastEditTime: 2025-04-27 22:42:53 * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk * Please be aware of the BSL license restrictions before installing Bytedesk IM – * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. @@ -165,8 +165,8 @@ public class BytedeskProperties { private WechatPay wechatPay = new WechatPay(); public static enum Edition { - COMMUNITY, // 社区版-免费, 功能受限,人数不限 - ENTERPRISE, // 企业版-200人,付费,功能不限 + COMMUNITY, // 社区版-不限人,免费, 功能受限 + ENTERPRISE, // 企业版-不限人,付费,功能不限 PLATFORM // 平台版-不限人数,付费,功能不限 } diff --git a/modules/core/src/main/java/com/bytedesk/core/utils/ConvertUtils.java b/modules/core/src/main/java/com/bytedesk/core/utils/ConvertUtils.java index 728cf644a6..bb5f0938c9 100644 --- a/modules/core/src/main/java/com/bytedesk/core/utils/ConvertUtils.java +++ b/modules/core/src/main/java/com/bytedesk/core/utils/ConvertUtils.java @@ -2,7 +2,7 @@ * @Author: jackning 270580156@qq.com * @Date: 2024-03-01 17:20:46 * @LastEditors: jackning 270580156@qq.com - * @LastEditTime: 2025-04-27 13:27:46 + * @LastEditTime: 2025-04-27 22:46:45 * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk * Please be aware of the BSL license restrictions before installing Bytedesk IM – * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. @@ -44,7 +44,8 @@ public class ConvertUtils { private static final ModelMapper modelMapper = new ModelMapper(); // 添加静态ModelMapper实例 - private ConvertUtils() {} + private ConvertUtils() { + } public static UserResponse convertToUserResponse(UserDetailsImpl userDetails) { // 无需进行authorities转换,因为UserDetailsImpl中已经包含了authorities @@ -68,7 +69,8 @@ public class ConvertUtils { .collect(Collectors.toSet()); // log.info("authorities only: {}", authorities); - // 添加用户的角色,使用方式,在Controller或Service方法配置注解:@PreAuthorize("hasAnyRole('ADMIN', 'SUPER', 'CS')"), + // 添加用户的角色,使用方式,在Controller或Service方法配置注解:@PreAuthorize("hasAnyRole('ADMIN', + // 'SUPER', 'CS')"), // 无需加角色前缀ROLE_,因为已经在RoleEntity的name中配置了 authorities.addAll(user.getUserOrganizationRoles().stream() .filter(uor -> uor.getOrganization().equals(user.getCurrentOrganization())) // 过滤步骤 @@ -76,7 +78,7 @@ public class ConvertUtils { .map(role -> new SimpleGrantedAuthority(role.getName()))) .collect(Collectors.toSet())); // log.info("authorities with roles: {}", authorities); - + return authorities; } @@ -103,69 +105,76 @@ public class ConvertUtils { public static ThreadResponse convertToThreadResponse(ThreadEntity thread) { ThreadResponse threadResponse = modelMapper.map(thread, ThreadResponse.class); - // 用于更新robot-agent-llm配置,不能修改为UserProtobuf, + // 用于更新robot-agent-llm配置,不能修改为UserProtobuf, // 否则会内容缺失,因为可能为RobotProtobuf类型, 其中含有llm字段 // if (thread.getAgent() != null) { - // UserProtobuf agent = JSON.parseObject(thread.getAgent(), UserProtobuf.class); - // threadResponse.setAgent(agent); + // UserProtobuf agent = JSON.parseObject(thread.getAgent(), UserProtobuf.class); + // threadResponse.setAgent(agent); // } // agent if (thread.getAgent() != null) { - UserProtobuf agent = UserProtobuf.fromJson(thread.getAgent()); //JSON.parseObject(thread.getAgent(), UserProtobuf.class); + UserProtobuf agent = UserProtobuf.fromJson(thread.getAgent()); // JSON.parseObject(thread.getAgent(), + // UserProtobuf.class); threadResponse.setAgentProtobuf(agent); } if (thread.getUser() != null) { - UserProtobuf user = UserProtobuf.fromJson(thread.getUser()); //JSON.parseObject(thread.getUser(), UserProtobuf.class); + UserProtobuf user = UserProtobuf.fromJson(thread.getUser()); // JSON.parseObject(thread.getUser(), + // UserProtobuf.class); threadResponse.setUser(user); } // robot if (thread.getRobot() != null) { - UserProtobuf robot = UserProtobuf.fromJson(thread.getRobot()); //JSON.parseObject(thread.getRobot(), UserProtobuf.class); + UserProtobuf robot = UserProtobuf.fromJson(thread.getRobot()); // JSON.parseObject(thread.getRobot(), + // UserProtobuf.class); threadResponse.setRobot(robot); } if (thread.getWorkgroup() != null) { - UserProtobuf workgroup = UserProtobuf.fromJson(thread.getWorkgroup()); //JSON.parseObject(thread.getWorkgroup(), UserProtobuf.class); + UserProtobuf workgroup = UserProtobuf.fromJson(thread.getWorkgroup()); // JSON.parseObject(thread.getWorkgroup(), + // UserProtobuf.class); threadResponse.setWorkgroup(workgroup); } if (thread.getInvites() != null) { // 将string[]为UserProtobuf[],并存入threadResponse.setInvites()中 for (String invite : thread.getInvites()) { - UserProtobuf inviteUser = UserProtobuf.fromJson(invite); //JSON.parseObject(invite, UserProtobuf.class); + UserProtobuf inviteUser = UserProtobuf.fromJson(invite); // JSON.parseObject(invite, + // UserProtobuf.class); threadResponse.getInvites().add(inviteUser); } } if (thread.getMonitors() != null) { for (String monitor : thread.getMonitors()) { - UserProtobuf monitorUser = UserProtobuf.fromJson(monitor); //JSON.parseObject(monitor, UserProtobuf.class); + UserProtobuf monitorUser = UserProtobuf.fromJson(monitor); // JSON.parseObject(monitor, + // UserProtobuf.class); threadResponse.getMonitors().add(monitorUser); } } if (thread.getAssistants() != null) { for (String assistant : thread.getAssistants()) { - UserProtobuf assistantUser = UserProtobuf.fromJson(assistant); //JSON.parseObject(assistant, UserProtobuf.class); + UserProtobuf assistantUser = UserProtobuf.fromJson(assistant); // JSON.parseObject(assistant, + // UserProtobuf.class); threadResponse.getAssistants().add(assistantUser); } } - // + // return threadResponse; } public static RoleResponse convertToRoleResponse(RoleEntity entity) { // return modelMapper.map(role, RoleResponse.class); RoleResponse roleResponse = modelMapper.map(entity, RoleResponse.class); - // 将Set authorities转换为Set authorities - roleResponse.setAuthorities( - entity.getAuthorities().stream() - .map(authorityEntity -> ConvertUtils - .convertToAuthorityResponse(authorityEntity)) - .collect(Collectors.toSet())); - return roleResponse; + // 将Set authorities转换为Set authorities + roleResponse.setAuthorities( + entity.getAuthorities().stream() + .map(authorityEntity -> ConvertUtils + .convertToAuthorityResponse(authorityEntity)) + .collect(Collectors.toSet())); + return roleResponse; } public static MessageResponse convertToMessageResponse(MessageEntity message) { MessageResponse messageResponse = modelMapper.map(message, MessageResponse.class); - // + // if (message.getUser() != null) { // UserProtobuf user = JSON.parseObject(message.getUser(), UserProtobuf.class); UserProtobuf user = UserProtobuf.fromJson(message.getUser()); @@ -178,14 +187,15 @@ public class ConvertUtils { // extra格式不固定,前端需要根据type字段来解析,所以此处不能使用MessageExtra // extra // if (message.getExtra() != null) { - // // MessageExtra extra = JSON.parseObject(message.getExtra(), MessageExtra.class); - // MessageExtra extra = MessageExtra.fromJson(message.getExtra()); - // if (extra.getFeedback() == null) { - // extra.setFeedback(BytedeskConsts.EMPTY_JSON_STRING); - // } - // messageResponse.setExtra(extra); + // // MessageExtra extra = JSON.parseObject(message.getExtra(), + // MessageExtra.class); + // MessageExtra extra = MessageExtra.fromJson(message.getExtra()); + // if (extra.getFeedback() == null) { + // extra.setFeedback(BytedeskConsts.EMPTY_JSON_STRING); // } - + // messageResponse.setExtra(extra); + // } + // thread if (message.getThread() != null) { ThreadResponse thread = convertToThreadResponse(message.getThread()); @@ -195,21 +205,26 @@ public class ConvertUtils { return messageResponse; } - - public static AuthorityResponse convertToAuthorityResponse(AuthorityEntity authorityEntity) { return modelMapper.map(authorityEntity, AuthorityResponse.class); } - public static BytedeskPropertiesResponse convertToBytedeskPropertiesResponse(BytedeskProperties bytedeskProperties) { - return modelMapper.map(bytedeskProperties, BytedeskPropertiesResponse.class); + public static BytedeskPropertiesResponse convertToBytedeskPropertiesResponse( + BytedeskProperties bytedeskProperties) { + // return modelMapper.map(bytedeskProperties, BytedeskPropertiesResponse.class); + BytedeskPropertiesResponse response = modelMapper.map(bytedeskProperties, BytedeskPropertiesResponse.class); + // 明确设置showRightCornerChat的值,确保从配置中获取 + if (bytedeskProperties.getCustom() != null) { + response.getCustom().setShowRightCornerChat(bytedeskProperties.getCustom().getShowRightCornerChat()); + } + return response; } public static UploadResponse convertToUploadResponse(UploadEntity entity) { - UploadResponse uploadResponse = modelMapper.map(entity, UploadResponse.class); - // 上一行没有自动初始化isLlm字段,所以这里需要手动设置 - // uploadResponse.setIsLlm(entity.isLlm()); - return uploadResponse; - } + UploadResponse uploadResponse = modelMapper.map(entity, UploadResponse.class); + // 上一行没有自动初始化isLlm字段,所以这里需要手动设置 + // uploadResponse.setIsLlm(entity.isLlm()); + return uploadResponse; + } }