package com.docus.server.common;

import com.docus.server.entity.scheduling.management.SchTerminator;
import com.docus.server.enums.BusyStateEnum;
import com.docus.server.enums.OnlineStateEnum;
import com.docus.server.service.ISchTerminatorService;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 重启置空
 */
@Component
public class TerminatorListener implements ApplicationListener<ContextRefreshedEvent> {
    @Resource
    private ISchTerminatorService iSchTerminatorService;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        List<SchTerminator> terminators = iSchTerminatorService.findAll();
        terminators.forEach(p -> {
            p.setBusyState(BusyStateEnum.IDLE);
            p.setOnlineState(OnlineStateEnum.OFFLINE);
        });
        iSchTerminatorService.batchUpdate(terminators);
    }
}
