package com.ld.igds.wms.manager;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.ld.igds.wms.constant.WmsCodeEnum;
|
import com.ld.igds.wms.data.WmsRequest;
|
import com.ld.igds.wms.data.WmsResponse;
|
import com.ld.igds.wms.service.WmsService;
|
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 czt
|
*/
|
@Component
|
public class WmsManager implements ApplicationContextAware {
|
|
private static Map<String, WmsService> serviceMap;
|
|
@Override
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
Map<String, WmsService> map = applicationContext.getBeansOfType(WmsService.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 WmsResponse execute(WmsRequest<JSONObject> req) throws Exception{
|
|
WmsService service = serviceMap.get(req.getInterfaceId());
|
|
if(null == service){
|
//通讯失败
|
return new WmsResponse(WmsCodeEnum.WMS_CODE_1004.getCode(), WmsCodeEnum.WMS_CODE_1004.getMsg());
|
}
|
|
return service.execute(req);
|
}
|
}
|