package com.njzscloud.dispose.config;

import com.njzscloud.common.security.util.SecurityUtil;
import com.njzscloud.dispose.wh.service.PurchaseOrderService;
import com.njzscloud.dispose.wh.service.SalesOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.List;

import static com.njzscloud.dispose.event.SysMittEvent.*;

/**
 * @author lzq
 */
@Component
@RequiredArgsConstructor
public class SpringReady {
    // 采购单
    private final PurchaseOrderService purchaseOrderService;

    // 销售单
    private final SalesOrderService salesOrderService;

    @EventListener(ApplicationReadyEvent.class)
    public void onApplicationReady() {
        COERCE_LOGOUT.on((List<Long> ids) -> ids.forEach(SecurityUtil::removeToken));

        PURCHASE_ORDER.on(purchaseOrderService::add);

        SALES_ORDER.on(salesOrderService::add);

    }
}
