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());
|
}
|
}
|
}
|