package com.prolog.eis.init;

import com.prolog.eis.constants.cache.EisCache;
import com.prolog.eis.constants.cache.EisCache;
import com.prolog.eis.model.config.OutboundStrategyConfig;
import com.prolog.eis.service.config.OutboundStrategyConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author wk
 */
@Component
@RequiredArgsConstructor
public class OutboundDispatchStrategy implements CommandLineRunner {

    private final OutboundStrategyConfigService outboundStrategyConfigService;

    @Override
    public void run(String... args) throws Exception {
        List<OutboundStrategyConfig> outboundStrategyConfigList = outboundStrategyConfigService.findAllConfig();
        for (OutboundStrategyConfig outboundStrategyConfig : outboundStrategyConfigList) {
            EisCache.OUTBOUND_DISPATCH_STRATEGY_MAP.put(outboundStrategyConfig.getBillType() + "&" + outboundStrategyConfig.getWarehouseArea(), outboundStrategyConfig.getStrategyName());
            EisCache.OUTBOUND_STORE_STRATEGY_MAP.put(outboundStrategyConfig.getStrategyName(), outboundStrategyConfig.getRelateStoreStrategyName());
        }
    }
}
