package net.vtstar.zhongtong.avi.gateway.parts.job;

import lombok.extern.slf4j.Slf4j;
import net.vtstar.scada.base.equipmgt.domain.Enum.EquipStatusEnum;
import net.vtstar.scada.base.gather.domain.EquipmentData;
import net.vtstar.scada.base.gather.job.GatherJob;
import net.vtstar.zhongtong.avi.gateway.parts.domain.DustingLineMachine;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.stereotype.Component;

/**
 * 喷粉线数据采集JOB
 */
@Slf4j
@Component
public class DustingLineMachineJob extends GatherJob {

    private static final String NAME = "DUSTING_LINE";

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {

        log.info("JobName: {}", context.getJobDetail().getKey().getName());
        super.gatherByModbus(NAME, DustingLineMachine.class);
    }

    protected boolean handleObject(EquipmentData equipmentData) {
        //0待机，1是喷粉
        DustingLineMachine data = (DustingLineMachine) equipmentData;
        Integer state = data.getState();
        if (state == null) {
            return false;
        }
        switch (state) {
            case 0:
                equipmentData.setEquipStatus(EquipStatusEnum.SHUTDOWN);
                break;
            case 1:
                equipmentData.setEquipStatus(EquipStatusEnum.RUN);
                break;
            case 2:
                equipmentData.setEquipStatus(EquipStatusEnum.ALARM);
                break;
            default:
                return false;
        }
        return true;
    }

    @Override
    protected Object handleValue(String fieldName, Object value) {
        return value;
    }
}
