CZT
2023-11-27 c206acfaedc69c390fb67daa81bc686f58a212ef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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);
    }
}