# LotMapper.java

    package com.mycim.server.wip.dao.mapper;

    import com.mycim.framework.jdbc.mapper.RowMapper;
    import com.mycim.framework.utils.lang.StringUtils;
    import com.mycim.valueobject.wip.Lot;
    import com.mycim.valueobject.wip.LotStatus;

    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.Objects;

    public class LotMapper implements RowMapper<Lot> {

        @Override
        public Lot mapRow(ResultSet rs, int rowNum) throws SQLException {
            Lot lot = new Lot();
            lot.setReworkTransRrn(new Long(rs.getLong("rework_trans_rrn")));
            lot.setFacilityRrn(new Long(rs.getLong("FACILITY_RRN")));
            lot.setLotId(rs.getString("LOT_ID"));
            lot.setBasedLotRrn(new Long(rs.getLong("BASED_LOT_RRN")));
            lot.setCreatedPlanLotRrn(new Long(rs.getLong("CREATED_PLAN_LOT_RRN")));
            lot.setHotFlag(rs.getString("HOT_FLAG"));
            lot.setPriority(new Integer(rs.getInt("PRIORITY")));
            lot.setStartedFlag(rs.getString("STARTED_FLAG"));
            lot.setStartedTimestamp(rs.getTimestamp("STARTED_TIMESTAMP"));
            lot.setCreateCategory(rs.getString("CREATE_CATEGORY"));
            lot.setCreatedTimestamp(rs.getTimestamp("CREATED_TIMESTAMP"));
            lot.setEndTimestamp(rs.getTimestamp("END_TIMESTAMP"));
            lot.setDueDate(rs.getTimestamp("DUE_DATE"));
            lot.setScheduleDueDate(rs.getTimestamp("SCHEDULE_DUE_DATE"));
            lot.setLastScheduleFlag(rs.getString("LATE_SCHEDULED_FLAG"));
            lot.setEstimatedRemainTime(new Long(rs.getLong("ESTIMATED_REMAIN_TIME")));
            lot.setDummyFlag(rs.getString("DUMMY_FLAG"));
            lot.setLotType(rs.getString("LOT_TYPE"));
            lot.setLotOwner(rs.getString("LOT_OWNER"));
            lot.setQty1(new Double(rs.getDouble("QTY1")));
            lot.setQty2(new Double(rs.getDouble("QTY2")));
            lot.setDummyQty1(new Integer(rs.getInt("DUMMY_QTY1")));
            lot.setInputQty1(new Double(rs.getDouble("INPUT_QTY1")));
            lot.setInputQty2(new Double(rs.getDouble("INPUT_QTY2")));
            lot.setSubcontractorRrn(new Long(rs.getLong("SUBCONTRACTOR_RRN")));
            lot.setLotComments(rs.getString("LOT_COMMENTS"));
            lot.setStepSequence(new Long(rs.getLong("STEP_SEQUENCE")));
            lot.setStepNumberInProcess(new Long(rs.getLong("STEP_NUMBER_IN_PROCESS")));
            lot.setHoldTimestamp(rs.getTimestamp("HOLD_TIMESTAMP"));
            lot.setReworkCategory(rs.getString("REWORK_CATEGORY"));
            lot.setCarrierRrn(new Long(rs.getLong("CARRIER_RRN")));

            lot.setBeforeStatus(rs.getString("BEFORE_STATUS"));
            lot.setLotStatus(rs.getString("LOT_STATUS"));
            lot.setProcessingStatus(rs.getString("PROCESSING_STATUS"));

            lot.setQueueTimestamp(rs.getTimestamp("QUEUE_TIMESTAMP"));
            if (Objects.nonNull(lot.getQueueTimestamp())) {
                long waitTime = (new java.util.Date().getTime() - lot.getQueueTimestamp().getTime()) / (60 * 1000);
                lot.setwaitTime(Long.toString(waitTime));
            }

            lot.setProductRrn(new Long(rs.getLong("PRODUCT_RRN")));
            lot.setProductVersion(rs.getInt("PRODUCT_VERSION"));
            lot.setReticleRrn(new Long(rs.getLong("RETICLE_RRN")));
            lot.setProductLayer(rs.getString("PRODUCT_LAYER"));
            lot.setOperationSeq(rs.getString("OPERATION_SEQ"));
            lot.setRouteSeq(rs.getString("ROUTE_SEQ"));
            lot.setRecipeLogicalRrn(new Long(rs.getLong("RECIPE_LOGICAL_RRN")));
            lot.setRecipePhysicalId(rs.getString("RECIPE_PHYSICAL_ID"));
            lot.setChamberType(rs.getString("CHAMBER_TYPE"));
            lot.setIsSapphire(rs.getString("IS_SAPPHIRE"));
            lot.setLotPlanType(rs.getString("LOT_PLAN_TYPE"));

            lot.setProcessRrn(new Long(rs.getLong("PROCESS_RRN")));

            lot.setProcessVersion(new Integer(rs.getInt("PROCESS_VERSION")));
            lot.setProcessStepVersion(rs.getString("PROCESS_STEP_VERSION"));
            lot.setProcessStepIdVersion(rs.getString("PROCESS_STEP_ID_VERSION"));
            lot.setWflStepPath(rs.getString("WFL_STEP_PATH"));
            lot.setOperationRrn(new Long(rs.getLong("OPERATION_RRN")));

            lot.setOperationVersion(new Integer(rs.getInt("OPERATION_VERSION")));
            lot.setNextStepVersion1(rs.getString("NEXT_STEP_VERSION1"));
            lot.setNextStepIdVersion1(rs.getString("NEXT_STEP_ID_VERSION1"));
            lot.setNextOperationRrn1(new Long(rs.getLong("NEXT_OPERATION_RRN1")));

            lot.setNextStepVersion2(rs.getString("NEXT_STEP_VERSION2"));
            lot.setNextStepIdVersion2(rs.getString("NEXT_STEP_ID_VERSION2"));
            lot.setNextOperationRrn2(new Long(rs.getLong("NEXT_OPERATION_RRN2")));
            lot.setStageId(rs.getString("STAGE_ID"));
            lot.setLayerId(rs.getString("LAYER_ID"));
            lot.setBorRrn(new Long(rs.getLong("BOR_RRN")));
            lot.setEqptRrn(new Long(rs.getLong("EQPT_RRN")));
            lot.setReticleRrn(new Long(rs.getLong("reticle_rrn")));

            lot.setRecipeString(rs.getString("RECIPE_STRING"));
            lot.setNextRecipeString1(rs.getString("NEXT_RECIPE_STRING1"));
            lot.setNextRecipeString2(rs.getString("NEXT_RECIPE_STRING2"));
            lot.setJobRrn(new Long(rs.getLong("JOB_RRN")));
            lot.setNextJobRrn1(new Long(rs.getLong("NEXT_JOB_RRN1")));
            lot.setNextJobRrn2(new Long(rs.getLong("NEXT_JOB_RRN2")));
            lot.setExecutionRrn(new Long(rs.getLong("EXECUTION_RRN")));
            lot.setLotRrn(rs.getLong("LOT_RRN"));
            lot.setShippedQty1(new Double(rs.getDouble("SHIPPED_QTY1")));
            lot.setShippedQty2(new Double(rs.getDouble("SHIPPED_QTY2")));
            lot.setRecipeLogicalRrn(new Long(rs.getLong("RECIPE_LOGICAL_RRN")));
            lot.setRecipePhysicalId(rs.getString("RECIPE_PHYSICAL_ID"));
            lot.setChamberType(rs.getString("CHAMBER_TYPE"));

            if (StringUtils.equalsIgnoreCase(LotStatus.BANKED, lot.getLotStatus()) ||
                    StringUtils.equalsIgnoreCase(LotStatus.OUTSOURCING, lot.getLotStatus())) {
                lot.setPrevOperationRrn(rs.getLong("PREV_OPERATION_RRN"));
            }
            lot.setFlowSeq(rs.getString("FLOW_SEQ"));
            lot.setOperationDesc(rs.getString("OPERATION_DESC"));
            lot.setProcessLocation(rs.getString("PROCESS_LOCATION"));
            lot.setqTime(StringUtils.toString(rs.getDouble("Q_TIME")));
            lot.setIsDummyLot(rs.getBoolean("IS_DUMMY_LOT"));
            return lot;
        }

    }