12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 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<String, OrderStrategy> orderHandleMap = new ConcurrentHashMap<>();
- private Map<String, OrderItemStrategy> orderItemHandleMap = new ConcurrentHashMap<>();
- @Override
- public void afterPropertiesSet() throws Exception {
- Map<String, OrderItemStrategy> orderItemHandles = applicationContextHelper.getBeansOfType(OrderItemStrategy.class);
- for (Map.Entry<String, OrderItemStrategy> 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<String, OrderStrategy> orderHandles = applicationContextHelper.getBeansOfType(OrderStrategy.class);
- for (Map.Entry<String, OrderStrategy> 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);
- }
- }
|