帮我解读一下这段代码:if (CollectionUtils.isEmpty(labelIds) || userId == null) { return new ArrayList<>(); } LambdaQueryWrapper<LabelInfoPO> labelQueryWrapper = new LambdaQueryWrapper<>(); labelQueryWrapper.eq(LabelInfoPO::getBusiness, LabelBusinessEnum.NEW_USER_INTEREST_LABEL.getCode()) .orderByAsc(LabelInfoPO::getWeight) ; List<LabelInfoPO> list = labelInfoMapper.selectList(labelQueryWrapper); if (CollectionUtils.isEmpty(list)) { return new ArrayList<>(); } Map<Long, LabelInfoPO> labelMap = list.stream().collect(Collectors.toMap(LabelInfoPO::getId, labelInfoPO -> labelInfoPO)); // 如果是选择标签然后提交的,需要保存用户选择记录 if (isSubmit) { for (Long labelId : labelIds) { if (!labelMap.containsKey(labelId)) { continue; } LabelRelPO labelRelPO = new LabelRelPO(); labelRelPO.setBusiness(LabelBusinessEnum.NEW_USER_LABEL_USER.getCode()); labelRelPO.setLabelId(labelId); labelRelPO.setRelId(userId); labelRelPO.setWeight(1); labelRelMapper.insert(labelRelPO); } } Set<Long> labelIdSet = list.stream().map(LabelInfoPO::getId).collect(Collectors.toSet()); LambdaQueryWrapper<LabelRelPO> queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(LabelRelPO::getBusiness, LabelBusinessEnum.NEW_USER_LABEL_BOT.getCode()) .in(LabelRelPO::getLabelId, labelIdSet) ; List<LabelRelPO> labelRelList = labelRelMapper.selectList(queryWrapper); if (CollectionUtils.isEmpty(labelRelList)) { return new ArrayList<>(); } Set<Long> botIds = labelRelList.stream().map(LabelRelPO::getRelId).collect(Collectors.toSet()); List<BotInfoVO> botInfoList = botInfoService.selectByIds(botIds); if (CollectionUtils.isEmpty(botInfoList)) { return new ArrayList<>(); } Map<Long, BotInfoVO> botInfoMap = botInfoList.stream().collect(Collectors.toMap(BotInfoVO::getId, botInfoVO -> botInfoVO)); List<BotInfoVO> resultList = new ArrayList<>(); // 开始排序 按照两个order之和进行排序,不是用户选择的对order按照系数进行膨胀,这个系数可以根据实际情况再调整,目前来说这个是够了的 labelRelList.stream() .sorted(Comparator.comparingInt(e -> (labelMap.get(e.getLabelId()).getWeight() + e.getWeight()) * (labelIds.contains(e.getLabelId()) ? 1 : 10000))) .forEach(e -> { if (resultList.size() < 20 && botInfoMap.containsKey(e.getRelId())) { resultList.add(botInfoMap.get(e.getRelId())); } }); return resultList;

时间: 2024-04-19 07:26:25 浏览: 20
这段代码主要是根据一些条件查询并排序标签和机器人信息,并返回结果列表。 首先,代码检查了 `labelIds` 是否为空或者 `userId` 是否为空,如果是,则直接返回一个空列表 `new ArrayList<>()`。 接下来,使用 `LambdaQueryWrapper` 创建了一个查询条件 `labelQueryWrapper`,并设置了业务类型为 `NEW_USER_INTEREST_LABEL`,并按照权重进行升序排序。 然后,通过 `labelInfoMapper` 执行查询操作,将查询结果保存在 `list` 中。如果查询结果为空,则同样返回一个空列表。 接着,将 `list` 转换为一个 `Map` 对象 `labelMap`,以标签的 ID 作为键,标签对象 `LabelInfoPO` 作为值。 如果 `isSubmit` 为真,则进入一个循环遍历 `labelIds`。如果 `labelMap` 中包含当前遍历的标签 ID,则创建一个 `LabelRelPO` 对象,并设置相关属性,最后将其插入到数据库中。 然后,创建一个空的 `labelIdSet` 集合,并将 `list` 中的标签 ID 添加到集合中。 再使用 `LambdaQueryWrapper` 创建一个查询条件 `queryWrapper`,设置业务类型为 `NEW_USER_LABEL_BOT`,并且标签 ID 在 `labelIdSet` 集合中。 通过 `labelRelMapper` 执行查询操作,将查询结果保存在 `labelRelList` 中。如果查询结果为空,则同样返回一个空列表。 接着,从 `labelRelList` 中提取机器人 ID,并保存在 `botIds` 集合中。 使用 `botInfoService` 根据机器人 ID 进行批量查询,将查询结果保存在 `botInfoList` 中。如果查询结果为空,则同样返回一个空列表。 将 `botInfoList` 转换为一个 `Map` 对象 `botInfoMap`,以机器人的 ID 作为键,机器人对象 `BotInfoVO` 作为值。 创建一个空的 `resultList` 列表,然后对 `labelRelList` 进行排序。排序规则是根据标签的权重和关联权重的和进行排序,并且如果标签 ID 在 `labelIds` 中存在,则乘以一个较大的系数(1 * 10000),以便放置用户选择的标签更靠前。 最后,遍历排序后的 `labelRelList`,将对应的机器人对象添加到 `resultList` 中,直到 `resultList` 的大小达到 20 或遍历完所有的标签关联记录。 最终,返回排序后的机器人列表 `resultList`。

相关推荐

优化代码:@Override public List projectCount(String beginTime, String endTime, Integer forceType, String projectId) { List<TaskTask> taskTaskList = this.listStatisticsTask(beginTime, endTime, forceType, projectId); if(CollectionUtil.isEmpty(taskTaskList)){ return Collections.emptyList(); } List result = new ArrayList<>(); Map<String, List<TaskTask>> projectTaskMap = taskTaskList.stream().collect(Collectors.groupingBy(TaskTask::getProjectId)); for (Map.Entry<String, List<TaskTask>> projectTaskEntry : projectTaskMap.entrySet()) { String currentProjectId = projectTaskEntry.getKey(); ProjectCountVO projectCountVO = new ProjectCountVO(); projectCountVO.setId(currentProjectId); // 查询项目名称 ProjectCondition queryProjectDto = new ProjectCondition(); queryProjectDto.setCompanyId(companyId); queryProjectDto.setDesignStatusList(designStatusList); queryProjectDto.setPageSize(pageSize); queryProjectDto.setUserId(userId); ResultWrapper<QueryAllProject> queryAllProjectResult = applicationServicePlatformClient.listUserProject(bspToken, bspUserId, bspUserEnvId, bspUserTenant, queryProjectDto); QueryAllProject queryAllProject = queryAllProjectResult.getData(); projectCountVO.setName(queryAllProject.getProjectName()); List<TaskTask> taskList = projectTaskEntry.getValue(); projectCountVO.setTaskCount(taskList.size()); Integer problemCount = CollectionUtil.isEmpty(taskList) ? 0 : taskList.stream().collect(Collectors.summingInt(task-> Optional.ofNullable(task.getProblemNum()).orElse(0))); projectCountVO.setProblemCount(problemCount); result.add(projectCountVO); } return result; }

根据接口“”@FeignClient(name = "UserUgsApi", url = "${newbim.login-domain}") public interface IApplicationServicePlatformClient {@PostMapping("/ums/v1/feign/omp/project/search") ResultWrapper<QueryAllProject> listUserProject(@RequestHeader("BSP_TOKEN") String bspToken, @RequestHeader("BSP_USER_ID") String bspUserId, @RequestHeader("BSP_USER_ENV_ID") String bspUserEnvId, @RequestHeader("BSP_USER_TENANT") String bspUserTenant, @RequestBody ProjectCondition queryProjectDto);和代码“@Component @Slf4j public class ApplicationServicePlatformClientProxy { @Autowired private IApplicationServicePlatformClient applicationServicePlatformClient; public QueryAllProject listUserProject(String appId, String companyId, String designStatusList, String pageSize, ProjectCondition userId) { ResultWrapper<QueryAllProject> result = null; return result.getData(); } }”,修改下面代码:@Override public List projectCount(String beginTime, String endTime, Integer forceType, String projectId) { List<TaskTask> taskTaskList = this.listStatisticsTask(beginTime, endTime, forceType, projectId); if(CollectionUtil.isEmpty(taskTaskList)){ return Collections.emptyList(); } List result = new ArrayList<>(); Map<String, List<TaskTask>> projectTaskMap = taskTaskList.stream().collect(Collectors.groupingBy(TaskTask::getProjectId)); for (Map.Entry<String, List<TaskTask>> projectTaskEntry : projectTaskMap.entrySet()) { String currentProjectId = projectTaskEntry.getKey(); ProjectCountVO projectCountVO = new ProjectCountVO(); projectCountVO.setId(currentProjectId); // 查询项目名称 QueryAllProject queryAllProject = applicationServicePlatformClient.listUserProject(); projectCountVO.setName(projectName); List<TaskTask> taskList = projectTaskEntry.getValue(); projectCountVO.setTaskCount(taskList.size()); Integer problemCount = CollectionUtil.isEmpty(taskList) ? 0 : taskList.stream().collect(Collectors.summingInt(task-> Optional.ofNullable(task.getProblemNum()).orElse(0))); projectCountVO.setProblemCount(problemCount); result.add(projectCountVO); } return result; }

根据接口“”@FeignClient(name = "UserUgsApi", url = "${newbim.login-domain}") public interface IApplicationServicePlatformClient {@PostMapping("/ums/v1/feign/omp/project/search") ResultWrapper<QueryAllProject> listUserProject(@RequestHeader("BSP_TOKEN") String bspToken, @RequestHeader("BSP_USER_ID") String bspUserId, @RequestHeader("BSP_USER_ENV_ID") String bspUserEnvId, @RequestHeader("BSP_USER_TENANT") String bspUserTenant, @RequestBody ProjectCondition queryProjectDto);和代码“@Component @Slf4j public class ApplicationServicePlatformClientProxy { @Autowired private IApplicationServicePlatformClient applicationServicePlatformClient; public QueryAllProject listUserProject(String appId, String companyId, String designStatusList, String pageSize, ProjectCondition userId) { ResultWrapper<QueryAllProject> result = null; return result.getData(); } }”,修改下面内容:public List projectCount(String beginTime, String endTime, Integer forceType, String projectId) { List<TaskTask> taskTaskList = this.listStatisticsTask(beginTime, endTime, forceType, projectId); if (CollectionUtil.isEmpty(taskTaskList)) { return Collections.emptyList(); } List result = new ArrayList<>(); Map<String, List<TaskTask>> projectTaskMap = taskTaskList.stream().collect(Collectors.groupingBy(TaskTask::getProjectId)); for (Map.Entry<String, List<TaskTask>> projectTaskEntry : projectTaskMap.entrySet()) { projectId = projectTaskEntry.getKey(); ProjectCountVO projectCountVO = new ProjectCountVO(); projectCountVO.setId(projectId); //查询项目名称 ResultWrapper<QueryAllProject> projectResult = applicationServicePlatformClient.listUserProject( "token", "userId", "userEnvId", "userTenant", new ProjectCondition()); QueryAllProject queryAllProject = projectResult.getData(); String projectName = queryAllProject.getBtpProjectId(); projectCountVO.setName(projectName); List<TaskTask> taskList = projectTaskEntry.getValue(); projectCountVO.setTaskCount(taskList.size()); Integer problemCount = CollectionUtil.isEmpty(taskList) ? 0 : taskList.stream().collect(Collectors.summingInt(task -> Optional.ofNullable(task.getProblemNum()).orElse(0))); projectCountVO.setProblemCount(problemCount); result.add(projectCountVO); } return result; }

根据接口“”@FeignClient(name = "UserUgsApi", url = "${newbim.login-domain}") public interface IApplicationServicePlatformClient {@PostMapping("/ums/v1/feign/omp/project/search") ResultWrapper<QueryAllProject> listUserProject(@RequestHeader("BSP_TOKEN") String bspToken, @RequestHeader("BSP_USER_ID") String bspUserId, @RequestHeader("BSP_USER_ENV_ID") String bspUserEnvId, @RequestHeader("BSP_USER_TENANT") String bspUserTenant, @RequestBody ProjectCondition queryProjectDto);和代码”@Component @Slf4j public class ApplicationServicePlatformClientProxy { @Autowired private IApplicationServicePlatformClient applicationServicePlatformClient; public QueryAllProject listUserProject(String appId, String companyId, String designStatusList, String pageSize, ProjectCondition userId) { ResultWrapper<QueryAllProject> result = null; return result.getData(); } }“检查并修改下面代码:@Override public List projectCount(String beginTime, String endTime, Integer forceType, String projectId) { // 查询任务列表 List<TaskTask> taskTaskList = this.listStatisticsTask(beginTime, endTime, forceType, projectId); if (CollectionUtil.isEmpty(taskTaskList)) { return Collections.emptyList(); } List result = new ArrayList<>(); // 将任务按照项目ID分组 Map<String, List<TaskTask>> projectTaskMap = taskTaskList.stream().collect(Collectors.groupingBy(TaskTask::getProjectId)); // 遍历项目及对应的任务列表 for (Map.Entry<String, List<TaskTask>> projectTaskEntry : projectTaskMap.entrySet()) { projectId = projectTaskEntry.getKey(); ProjectCountVO projectCountVO = new ProjectCountVO(); projectCountVO.setId(projectId); //查询项目名称 QueryAllProject queryAllProject = applicationServicePlatformClientProxy.listUserProject( "token", "userId", "userEnvId", "userTenant", new ProjectCondition()); String projectName = queryAllProject.getBtpProjectId(); projectCountVO.setName(projectName); List<TaskTask> taskList = projectTaskEntry.getValue(); projectCountVO.setTaskCount(taskList.size()); Integer problemCount = CollectionUtil.isEmpty(taskList) ? 0 : taskList.stream().collect(Collectors.summingInt(task -> Optional.ofNullable(task.getProblemNum()).orElse(0))); projectCountVO.setProblemCount(problemCount); result.add(projectCountVO); } return result; }

/** * 根据formBean修改指定参数 / public static boolean updateData(Long id, String tableName, Map<String, Object> fields) throws BusinessException, SQLException { StringBuilder fieldNames = new StringBuilder(""); Iterator<Entry<String, Object>> iter = fields.entrySet().iterator(); if (fields.isEmpty()) { log.error("更新字段为空"); return true; } else { int count = 0; List<Object> fieldValues = new ArrayList<>(); while (iter.hasNext()) { ++count; Entry<String, Object> entry = iter.next(); String fieldName = (String) entry.getKey(); Object fieldValue = entry.getValue(); String splitStr = count == fields.size() ? "" : ","; / 这段代码是一个Java中的三目运算符,它的作用是根据一个条件来决定一个字符串变量的值。 具体来说,这行代码的意思是:如果 count 等于 fields.size(),那么 splitStr 的值为一个空字符串 "",否则 splitStr 的值为逗号 ","。 通常情况下,这行代码用于在生成一个字符串时,根据某些条件来决定是否需要添加分隔符。如果这些条件不满足,就不需要添加分隔符,否则需要添加一个逗号分隔符。*/ fieldNames.append(fieldName + "=?" + splitStr); fieldValues.add(fieldValue); } JDBCAgent jdbc = null; String sql = "update " + tableName + " set " + fieldNames.toString() + " where id =?"; fieldValues.add(id); boolean isUpdate; try { jdbc = new JDBCAgent(); isUpdate = jdbc.execute(sql, fieldValues) > 0; } catch (Exception var15) { log.error(sql); log.error(fieldValues); log.error(var15.getMessage(), var15); throw var15; } finally { if (null != jdbc) { jdbc.close(); } } return isUpdate; } }以这样的形式写一个在java代码中,修改数据库表名为smsserver_out的字段status,条件是如果第一:数据库中字段status的值为U或者Q,第二:user_id等于前端传过来的值,需要考虑的情况为考虑user_id可能是一个也有可能是多个,也有可能为空,为防止sql注入,要采用预编译的方式

最新推荐

recommend-type

grpcio-1.47.0-cp310-cp310-linux_armv7l.whl

Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
recommend-type

小程序项目源码-美容预约小程序.zip

小程序项目源码-美容预约小程序小程序项目源码-美容预约小程序小程序项目源码-美容预约小程序小程序项目源码-美容预约小程序小程序项目源码-美容预约小程序小程序项目源码-美容预约小程序小程序项目源码-美容预约小程序小程序项目源码-美容预约小程序v
recommend-type

MobaXterm 工具

MobaXterm 工具
recommend-type

grpcio-1.48.0-cp37-cp37m-linux_armv7l.whl

Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
recommend-type

扁平风格PPT可修改ppt下载(11).zip

扁平风格PPT可修改ppt下载(11).zip
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

【实战演练】MATLAB用遗传算法改进粒子群GA-PSO算法

![MATLAB智能算法合集](https://static.fuxi.netease.com/fuxi-official/web/20221101/83f465753fd49c41536a5640367d4340.jpg) # 2.1 遗传算法的原理和实现 遗传算法(GA)是一种受生物进化过程启发的优化算法。它通过模拟自然选择和遗传机制来搜索最优解。 **2.1.1 遗传算法的编码和解码** 编码是将问题空间中的解表示为二进制字符串或其他数据结构的过程。解码是将编码的解转换为问题空间中的实际解的过程。常见的编码方法包括二进制编码、实数编码和树形编码。 **2.1.2 遗传算法的交叉和
recommend-type

openstack的20种接口有哪些

以下是OpenStack的20种API接口: 1. Identity (Keystone) API 2. Compute (Nova) API 3. Networking (Neutron) API 4. Block Storage (Cinder) API 5. Object Storage (Swift) API 6. Image (Glance) API 7. Telemetry (Ceilometer) API 8. Orchestration (Heat) API 9. Database (Trove) API 10. Bare Metal (Ironic) API 11. DNS
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。