@Component @Slf4j public class ApplicationServicePlatformClientProxy { @Autowired private IApplicationServicePlatformClient applicationServicePlatformClient; @Value("${bsp.model-check.appid}") private String appId; public List<QueryAllProject> listUserProject() { QueryOut<Page<QueryAllProject>> result = null; try { String bspToken = RequestHeaderHolder.getBspToken(); String bspUserId = RequestHeaderHolder.getUserId(); String bspUserEnvId = RequestHeaderHolder.getCompanyId(); String bspUserTenant = RequestHeaderHolder.getCompanyId(); String companyId = RequestHeaderHolder.getCompanyId(); ProjectCondition queryProjectDto = new ProjectCondition(); queryProjectDto.setAppId(appId); queryProjectDto.setCompanyId(companyId); queryProjectDto.setDesignStatusList(Arrays.asList(2,3)); queryProjectDto.setPageSize(-1); queryProjectDto.setUserId(bspUserId); result = applicationServicePlatformClient.listUserProject(bspToken, bspUserId, bspUserEnvId, bspUserTenant, queryProjectDto); log.info("result={}", JSON.toJSONString(result)); } catch (Exception e) { log.error("调用IApplicationServicePlatformClient获取项目名称失败:", e); throw new BimdcException("调用IApplicationServicePlatformClient获取项目名称失败"); } if (result == null || result.getData() == null) { log.error("调用IApplicationServicePlatformClient获取项目名称失败:result={}", result); throw new BimdcException("调用IApplicationServicePlatformClient获取项目名称失败"); } return result.getData().getData(); } }

时间: 2024-04-27 07:20:13 浏览: 14
这段代码是一个 Java 类,命名为 ApplicationServicePlatformClientProxy,使用了 Spring 的 @Component 和 Lombok 的 @Slf4j 注解。它的主要作用是通过调用 applicationServicePlatformClient 中的 listUserProject 方法,获取用户参与的项目列表。其中,使用了 @Autowired 将 applicationServicePlatformClient 注入到类中,使用了 @Value("${bsp.model-check.appid}") 获取配置文件中的 appId 值。在方法中,通过调用 RequestHeaderHolder 中的方法获取用户的相关信息,并构造出 ProjectCondition 对象,最终调用 applicationServicePlatformClient.listUserProject 方法来获取用户参与的项目列表。如果调用失败或结果为空,会抛出 BimdcException 异常。
相关问题

@Component @Slf4j public class AppRouter { @Autowired private AppService appService;}

您的第一个问题是关于一个名为 AppRouter 的类的注解和依赖注入方法。@Component 表示该类是一个 Spring 组件,在 Spring 容器中可以被管理和调用。@Slf4j 表示该类使用了 Lombok 的日志库,在编译时会自动生成日志相关的代码,使得开发者在代码中可以方便地打印日志。@Autowired 表示该类中的 appService 属性是一个被 Spring 容器托管的服务,可以自动注入到该类中,从而方便该类中使用该服务的方法。

@Slf4j @Component public class FMSGCallBack implements HCNetSDK.FMSGCallBack_V31 { @Autowired private RedisService redisService; redisService 报空指针异常

这个问题可能是因为你没有将 RedisService 注入到 FMSGCallBack 类中。你可以检查一下 FMSGCallBack 类是否被正确地注入到 Spring 容器中,并且 RedisService 是否被正确地注入到 FMSGCallBack 类中。 另外,如果你要在非 Spring 管理的类中使用 Spring 管理的 Bean,你可以通过 ApplicationContext 的 getBean 方法获取 Bean 对象,而不是使用 @Autowired 注解注入。可以尝试一下这个方法: ``` @Slf4j @Component public class FMSGCallBack implements HCNetSDK.FMSGCallBack_V31 { private RedisService redisService; @Override public void invoke(NativeLong lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) { // 通过 ApplicationContext 获取 RedisService Bean ApplicationContext context = SpringContextUtil.getApplicationContext(); redisService = context.getBean(RedisService.class); // 使用 redisService 对象进行操作 redisService.xxx(); } } ``` 这里通过 SpringContextUtil 工具类获取了 ApplicationContext,然后通过 ApplicationContext 获取了 RedisService Bean 对象,最终使用这个对象进行操作。注意,这里需要将 RedisService 类型传入 getBean 方法中。

相关推荐

根据接口“”@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()) { 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; }

根据接口“”@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; }

如何将代码1“String bspToken = RequestHeaderHolder.getBspToken(); String bspUserId = RequestHeaderHolder.getUserId(); String bspUserEnvId = RequestHeaderHolder.getCompanyId(); String bspUserTenant = RequestHeaderHolder.getCompanyId(); String companyId = RequestHeaderHolder.getCompanyId(); ProjectCondition queryProjectDto = new ProjectCondition(); queryProjectDto.setAppId(queryProjectDto.getAppId()); queryProjectDto.setCompanyId(companyId); queryProjectDto.setDesignStatusList(Arrays.asList(2,3)); queryProjectDto.setPageSize(-1); queryProjectDto.setUserId(bspUserId); List<QueryAllProject> queryAllProject = applicationServicePlatformClientProxy.listUserProject(bspToken, bspUserId, bspUserEnvId, bspUserTenant, queryProjectDto);”,合并到代码2“@Component @Slf4j public class ApplicationServicePlatformClientProxy { @Autowired private IApplicationServicePlatformClient applicationServicePlatformClient; public List<QueryAllProject> listUserProject(String bspToken, String bspUserId, String bspUserEnvId, String bspUserTenant, ProjectCondition queryProjectDto) { QueryOut> result = null; try { result = applicationServicePlatformClient.listUserProject(bspToken, bspUserId, bspUserEnvId, bspUserTenant, queryProjectDto); log.info("result={}", JSON.toJSONString(result)); } catch (Exception e) { log.error("调用IApplicationServicePlatformClient获取项目名称失败:", e); throw new BimdcException("调用IApplicationServicePlatformClient获取项目名称失败"); } if (result == null || result.getData() == null) { log.error("调用IApplicationServicePlatformClient获取项目名称失败:result={}", result); throw new BimdcException("调用IApplicationServicePlatformClient获取项目名称失败"); } return result.getData().getData(); } }”

根据代码1“@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);” 代码2"@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; try { result = applicationServicePlatformClient.listUserProject(appId, companyId, designStatusList, pageSize, userId); } catch (Exception e) { log.error("调用IApplicationServicePlatformClient获取项目名称失败:", e); throw new BimdcException("调用IApplicationServicePlatformClient获取项目名称失败"); } if (result == null || result.getData() == null) { log.error("调用IApplicationServicePlatformClient获取项目名称失败:result={}", result); throw new BimdcException("调用IApplicationServicePlatformClient获取项目名称失败"); } 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()) { projectId = projectTaskEntry.getKey(); ProjectCountVO projectCountVO = new ProjectCountVO();

最新推荐

recommend-type

logback-slf4j日志配置文件-下载即可使用

logback+slf4j 异步日志输出到不同级别的文件-配置文件,下载即可使用。结合lombok【@slf4j】即可方便愉快的输出日志了 666
recommend-type

Springboot项目使用Slf4j将日志保存到本地目录的实现代码

主要介绍了Springboot项目使用Slf4j将日志保存到本地目录的实现方法,本文通过示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
recommend-type

电影票房.csv

电影票房
recommend-type

ASP.NET技术在网站开发设计中的研究与开发(论文+源代码+开题报告)【ASP】.zip

ASP.NET技术在网站开发设计中的研究与开发(论文+源代码+开题报告)【ASP】
recommend-type

WebShell-Password.txt

WebShell-Password
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结构体与对象编程:构建面向对象的应用程序,提升代码可维护性和可扩展性

![MATLAB结构体与对象编程:构建面向对象的应用程序,提升代码可维护性和可扩展性](https://picx.zhimg.com/80/v2-8132d9acfebe1c248865e24dc5445720_1440w.webp?source=1def8aca) # 1. MATLAB结构体基础** MATLAB结构体是一种数据结构,用于存储和组织相关数据。它由一系列域组成,每个域都有一个名称和一个值。结构体提供了对数据的灵活访问和管理,使其成为组织和处理复杂数据集的理想选择。 MATLAB中创建结构体非常简单,使用struct函数即可。例如: ```matlab myStruct
recommend-type

详细描述一下STM32F103C8T6怎么与DHT11连接

STM32F103C8T6可以通过单总线协议与DHT11连接。连接步骤如下: 1. 将DHT11的VCC引脚连接到STM32F103C8T6的5V电源引脚; 2. 将DHT11的GND引脚连接到STM32F103C8T6的GND引脚; 3. 将DHT11的DATA引脚连接到STM32F103C8T6的GPIO引脚,可以选择任一GPIO引脚,需要在程序中配置; 4. 在程序中初始化GPIO引脚,将其设为输出模式,并输出高电平,持续至少18ms,以激活DHT11; 5. 将GPIO引脚设为输入模式,等待DHT11响应,DHT11会先输出一个80us的低电平,然后输出一个80us的高电平,
recommend-type

JSBSim Reference Manual

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