package com.fdkankan.ucenter.pay.strategy; import com.fdkankan.ucenter.vo.response.OrderItemVo; import com.fdkankan.ucenter.common.SpringUtil; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Log4j2 @Component public class OrderStrategyFactory implements InitializingBean { @Autowired private SpringUtil applicationContextHelper; private Map orderHandleMap = new ConcurrentHashMap<>(); private Map orderItemHandleMap = new ConcurrentHashMap<>(); @Override public void afterPropertiesSet() throws Exception { Map orderItemHandles = applicationContextHelper.getBeansOfType(OrderItemStrategy.class); for (Map.Entry orderHandle : orderItemHandles.entrySet()) { String type = orderHandle.getValue().getType(); String[] types = type.split(","); if (types.length > 1){ for (String str : types){ orderItemHandleMap .put(str, orderHandle.getValue()); } } else{ orderItemHandleMap .put(orderHandle.getValue().getType(), orderHandle.getValue()); } } Map orderHandles = applicationContextHelper.getBeansOfType(OrderStrategy.class); for (Map.Entry orderHandle : orderHandles.entrySet()) { orderHandleMap.put(orderHandle.getValue().getType(), orderHandle.getValue()); } } public void doHandler(Long userId, OrderItemVo t) throws Exception{ log.warn("sku:"+t.getSkuSn()); orderItemHandleMap.get(t.getSkuSn()).handleOrderItem(userId, t); } public void doHandler(String orderSn, String tradeNo, String openId, String type, int paymentTypeName) throws Exception{ Long spaceId = null; log.info("进入doHandler"); if(orderSn.split("_").length == 2){ spaceId = Long.valueOf(orderSn.split("_")[1]); orderSn = orderSn.split("_")[0]; } if(type.matches("^-?[0-9]+")){ type = "expansion"; } log.info("type:" + type); log.info("orderSn:" + orderSn); orderHandleMap.get(type).handleOrder(orderSn, tradeNo, openId, paymentTypeName, spaceId); } }