通过id或者name既查人、又查部门
@Component
public class ServiceLocator {
private static Map<String, ISearchService> serviceMap;
@Autowired
ApplicationContext applicationContext;
@PostConstruct
public void init() {
serviceMap = applicationContext.getBeansOfType(ISearchService.class);
}
public Map<String, ISearchService> getServiceImplMap() {
return serviceMap;
}
}
使用时注进来
@Resource
private ServiceLocator serviceLocator;
@PostMapping("/searches")
public WebResponse<SearchesVO> searches(@RequestBody SearchesRequest searchRequest) {
if (null == searchRequest.getHrStatusCode()) {
searchRequest.setHrStatusCode("A");
}
SearchesVO searchesVO = new SearchesVO();
Map<String, ISearchService> iSearchServiceMap = serviceLocator.getServiceImplMap();
iSearchServiceMap.forEach((key, value) -> value.search(searchRequest, searchesVO));
}
返回类
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SearchesVO {
private List<Emp> empList;
private List<Dept> deptList;
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Dept {
private String deptId;
private String deptIdPath;
private String deptName;
private String deptNamePath;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Emp {
private String avatarUrl;
private String empId;
private String mis;
private String name;
private String uid;
}
}
|