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

import lombok.extern.slf4j.Slf4j;
import net.vtstar.scada.base.gather.domain.EquipmentData;
import net.vtstar.scada.base.gather.job.GatherJob;
import net.vtstar.zhongtong.avi.gateway.painting.domain.DryingRoomTempMachine;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.stereotype.Component;

/**
 * 烘干室温度数据采集JOB
 */
@Slf4j
@Component
public class DryingRoomTempMachineJob extends GatherJob {

    private static final String NAME = "DRYING_ROOM_TEMP";

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

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

    @Override
    public boolean handleObject(EquipmentData equipmentData) {
        DryingRoomTempMachine data = (DryingRoomTempMachine) equipmentData;
        Integer state = data.getStatus();
        if (state != null && state == 0) {
            return false;
        }
        if (null == data.getTemperature()){
            return false;
        }
        return true;
    }

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

    @Override
    protected void postHandle(EquipmentData equipmentData) {

    }
}
