package com.ld.igds.three.manager;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.ld.igds.three.ThreeCodeEnum;
|
import com.ld.igds.three.data.ThreeResponse;
|
import com.ld.igds.three.param.ThreeRequest;
|
import com.ld.igds.three.service.ThreeService;
|
import com.ld.igds.three.util.ThreeRespUtil;
|
import org.springframework.beans.BeansException;
|
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.stereotype.Component;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* 接口业务分发
|
* @author chen
|
*/
|
@Component
|
public class ThreeManager implements ApplicationContextAware {
|
|
private static Map<String, ThreeService> serviceMap;
|
|
@Override
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
Map<String, ThreeService> map = applicationContext
|
.getBeansOfType(ThreeService.class);
|
serviceMap = new HashMap<>();
|
for (String key : map.keySet()) {
|
serviceMap.put(map.get(key).getInterfaceId(), map.get(key));
|
}
|
}
|
|
/**
|
* 业务执行入口
|
* @param req
|
* @return
|
* @throws Exception
|
*/
|
@SuppressWarnings("unchecked")
|
public ThreeResponse<Object> execute(ThreeRequest<JSONObject> req) throws Exception{
|
|
ThreeService service = serviceMap.get(req.getInterfaceId());
|
if(null == service){
|
return ThreeRespUtil.error(ThreeCodeEnum.CODE_1111, "当前接口没有找到实现类,无法执行处理!", req);
|
}
|
|
return service.execute(req);
|
}
|
}
|