czt
2025-08-07 bc82af6e3664195bbcade1c769c8553457bfb09a
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
55
56
57
58
59
60
61
62
63
64
65
66
package com.fzzy.order.ordersx2023;
 
import com.fzzy.api.entity.ApiConfs;
import com.fzzy.api.view.pr.ApiConfsPR;
import com.fzzy.order.ordersx2023.data.OrderSxReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @Description 指令下发入口
 * @Author CZT
 * @Date 2024/4/23 11:36
 */
@Slf4j
@Component(OrderSxManager.BEAN_ID)
public class OrderSxManager implements ApplicationContextAware {
    public static final String BEAN_ID = "order.orderSxManager";
 
    private static Map<String, OrderSxService> serviceMap;
 
    @Autowired
    private ApiConfsPR apiConfsPR;
 
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, OrderSxService> map = applicationContext.getBeansOfType(OrderSxService.class);
        serviceMap = new HashMap<>();
        for (String key : map.keySet()) {
            serviceMap.put(map.get(key).getProtocol(), map.get(key));
        }
    }
 
    @Async
    public void execute(OrderSxReq req){
 
        try{
            //获取配置信息
            List<ApiConfs> apiConfList = apiConfsPR.listAll();
            if(null == apiConfList || apiConfList.isEmpty()){
                log.error("陕西省平台:收到指令,未获取到库区配置信息,不执行!");
                return;
            }
            //根据配置信息执行
            OrderSxService service;
            for (ApiConfs conf : apiConfList) {
                service = serviceMap.get(conf.getPushProtocol());
                if(null == service){
                    log.error("陕西省平台:收到指令,未获取到协议,不执行!");
                    continue;
                }
                service.execute(req, conf);
            }
        } catch (Exception e) {
            log.error("陕西省平台:指令执行失败,错误={}", e.getLocalizedMessage());
        }
    }
}