DspEqptStatusContextValue.java

package com.mycim.valueobject.prp;

import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.math.NumberUtils;
import com.mycim.valueobject.consts.ContextNames;
import com.mycim.valueobject.consts.EquipmentStatus;
import com.mycim.valueobject.consts.EventName;
import com.mycim.valueobject.wip.LotStatus;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

/**
 * @author andy
 */
public class DspEqptStatusContextValue extends AbstractContextValue {

    public static final String SEPARATOR = ",";

    private static final long serialVersionUID = -2146954425912284966L;

    private String lotType;

    private String lotIdPrefix;

    private String eqptStatus;

    public DspEqptStatusContextValue() {
        this.setContextId(ContextNames.DSP_EQPT_STATUS_CONTEXT);
    }

    /**
     * @return the equipmentRrn
     */
    @java.lang.Override
    public Long getEquipmentRrn() {
        return NumberUtils.createLong(StringUtils.trimToNull(this.getContextKey5()));
    }

    /**
     * @param equipmentRrn the equipmentRrn to set
     */
    @java.lang.Override
    public void setEquipmentRrn(Long equipmentRrn) {
        if (equipmentRrn != null) {
            this.setContextKey5(equipmentRrn + "");
        }
    }

    /**
     * @return the lotRrn
     */
    @java.lang.Override
    public Long getLotRrn() {
        return NumberUtils.createLong(StringUtils.trimToNull(this.getContextKey6()));
    }

    /**
     * @param lotRrn the lotRrn to set
     */
    @java.lang.Override
    public void setLotRrn(Long lotRrn) {
        if (lotRrn != null) {
            this.setContextKey6(lotRrn + "");
        }
    }

    /**
     * @return the lotType
     */
    public String getLotType() {
        this.lotType = this.getContextKey7();
        return this.lotType;
    }

    /**
     * @param lotType the lotType to set
     */
    public void setLotType(String lotType) {
        this.lotType = StringUtils.trimToUpperCase(lotType);
        if (StringUtils.isNotEmpty(lotType)) {
            this.setContextKey7(lotType);
        }
    }

    /**
     * @return the lotIdPrefix
     */
    public String getLotIdPrefix() {
        this.lotIdPrefix = this.getContextKey8();
        return lotIdPrefix;
    }

    /**
     * @param lotIdPrefix the lotIdPrefix to set
     */
    public void setLotIdPrefix(String lotIdPrefix) {
        this.lotIdPrefix = StringUtils.trimToUpperCase(lotIdPrefix);
        if (StringUtils.isNotEmpty(lotIdPrefix)) {
            this.setContextKey8(lotIdPrefix);
        }
    }

    /**
     * @return the eqptStatus
     */
    public Collection getEqptStatus() {
        this.eqptStatus = this.getResultValue1();
        if (StringUtils.isEmpty(this.eqptStatus)) {
            return new ArrayList();
        } else {
            return StringUtils.splitAsList(this.eqptStatus, DspEqptStatusContextValue.SEPARATOR);
        }
    }

    /**
     * @param eqptStatus the eqptStatus to set
     */
    public void setEqptStatus(String eqptStatus) {
        this.eqptStatus = StringUtils.trimToUpperCase(eqptStatus);
        if (StringUtils.isNotEmpty(this.eqptStatus)) {
            this.setResultValue1(this.eqptStatus);
        }
    }

    /**
     * Check the equipment is available for dispatch lot.
     *
     * @param equipmenStatus
     * @return
     */
    public boolean isEqptStatusAvailable(String equipmenStatus, String lotStatus) {
        if (StringUtils.isEmpty(equipmenStatus)) {
            return false;
        }
        return (this.getEqptStatus().contains(equipmenStatus) || (EventName.IDLE).equalsIgnoreCase(equipmenStatus) ||
                (EventName.RUN).equalsIgnoreCase(equipmenStatus)|| Arrays.asList(EquipmentStatus.AVAILABLE_EQP_STATUS).contains(equipmenStatus)) ||
                ((StringUtils.equals(lotStatus, LotStatus.RUNNING) ||
                        StringUtils.equals(lotStatus, LotStatus.DISPATCH) ||
                        StringUtils.equals(lotStatus, LotStatus.PROCESSED)) &&
                        StringUtils.equalsIgnoreCase(equipmenStatus, EventName.DOWN));
    }

    /**
     * @param equipmenCurrentStatus
     * @return
     */
    public boolean isSkipLogEvent(String equipmenCurrentStatus) {
        return (this.getEqptStatus().contains(equipmenCurrentStatus) || equipmenCurrentStatus.equals(EventName.PT) ||
                StringUtils.equalsIgnoreCase(equipmenCurrentStatus, EventName.DOWN));
    }

}