package net.vtstar.zhongtong.avi.gateway.trial.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.trial.domain.HydrogenStationVocMachine;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 加氢站设备数据采集JOB
 */
@Slf4j
@Component
public class HydrogenStationVocMachineJob extends GatherJob {

    private static final String NAME = "HYDROGEN_STATIONVoc";

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

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

    public boolean handleObject(EquipmentData equipmentData) {
        HydrogenStationVocMachine data = (HydrogenStationVocMachine) equipmentData;
        Integer state = data.getStatus();
        if (state != null && state == 0) {
            return false;
        }
        equipmentData.setEquipStatus(EquipStatusEnum.RUN);
        return true;
    }

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

    @Override
    protected void postHandle(EquipmentData equipmentData) {
        ((HydrogenStationVocMachine)equipmentData).setCreateTime(new Date());
    }
}
