@Component
public class NetMeetingContext {
/**
* 注入的策略
*/
@Autowired
private Map<Integer, NetMeetingService> netMeetingServiceMap;
/**
* 创建网络会议
*
* @param meetingSource 对接类型
* @param netMeetingParam 创建网络会议入参
* @param userId 操作人
* @return 对接网络会议系统的返回
*/
public NetMeetingDTO<NetMeetingResponse> createNetMeeting(Integer meetingSource, NetMeetingParam netMeetingParam, Long userId) {
NetMeetingService netMeetingService = netMeetingServiceMap.get(meetingSource);
Assert.assertNotNull(netMeetingService);
return netMeetingService.createNetMeeting(netMeetingParam, userId);
}
}
对策略的map进行注入bean
@Configuration
public class NetMeetingServiceConfig {
@Resource
private NetMeetingService qsMeetingServiceImpl;
@Resource
private NetMeetingService xyMeetingServiceImpl;
/**
* 注入bean
*/
@Bean
public Map<Integer, NetMeetingService> netMeetingServiceMap() {
Map<Integer, NetMeetingService> dataMap = new HashMap<>();
dataMap.put(OnlineConstants.MEETING_SOURCE_QUANSHI, qsMeetingServiceImpl);
dataMap.put(OnlineConstants.MEETING_SOURCE_XIAOYU, xyMeetingServiceImpl);
return dataMap;
}
}