OperationPanelLotMapper.java

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

import com.mycim.framework.jdbc.mapper.RowMapper;
import com.mycim.framework.utils.MiscUtils;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.collections.MapUtils;
import com.mycim.framework.utils.lang.time.DateUtils;
import com.mycim.utils.WipUtils;
import com.mycim.valueobject.LotConstants;
import com.mycim.valueobject.wip.LotStatus;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Johnson.Wang
 * @version 6.0.0
 * @date 2019/9/20
 **/
public class OperationPanelLotMapper implements RowMapper<Map<String, Object>> {
    @Override
    public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
        Map<String, Object> lot = new HashMap<String, Object>(rs.getMetaData().getColumnCount());
        lot.put("lotRrn", rs.getLong("LOT_RRN"));
        lot.put("lotId", rs.getString("LOT_ID"));
        lot.put("lotStatus", rs.getString("LOT_STATUS"));
        lot.put("lotType", rs.getString("LOT_TYPE"));
        lot.put("hotFlag", "1".equals(rs.getString("HOT_FLAG")) ? "Y" : "N");
        lot.put("hotFlagCode", rs.getString("HOT_FLAG"));
        lot.put("priority", rs.getString("PRIORITY"));
        lot.put("hotFalg_priority", rs.getString("HOTFLAG_PRIORITY"));
        lot.put("layerId", rs.getString("LAYER_ID"));
        lot.put("carrierId", rs.getString("CARRIER_ID"));
        lot.put("carrierRrn", rs.getLong("CARRIER_RRN"));
        lot.put("qty1", rs.getString("QTY1"));
        lot.put("qty2", rs.getString("QTY2"));
        lot.put("dummyQty1", rs.getInt("dummy_qty1"));
        lot.put("dummyFlag", rs.getString("DUMMY_FLAG"));
        if (rs.getString("EQPT_RRN") == null) {
            lot.put("equipmentRrn", "");
            lot.put("equipmentId", "");
        } else {
            lot.put("equipmentRrn", rs.getLong("EQPT_RRN"));
            lot.put("equipmentId", rs.getString("EQPT_ID"));
        }
        lot.put("operationRrn", rs.getLong("OPERATION_RRN"));
        lot.put("operationVersion", rs.getString("OPERATION_VERSION"));
        lot.put("operationId", rs.getString("OPERATION_ID"));
        lot.put("operationDesc", rs.getString("context_step_desc"));
        lot.put("contextOperationDesc", rs.getString("context_step_desc"));
        lot.put("reticleRrn", rs.getLong("reticle_rrn"));
        lot.put("reticleId", rs.getString("RETICLE_ID"));

        lot.put("routeRrn", Long.toString((WipUtils.getRouteRrnByProcessStep(rs.getString("PROCESS_STEP_VERSION")))));
        lot.put("routeId", WipUtils.getRouteIdByProcessStep(rs.getString("PROCESS_STEP_ID_VERSION")));

        lot.put("productId", rs.getString("PRODUCT_ID"));
        lot.put("productRrn", rs.getLong("PRODUCT_RRN"));
        lot.put("processRrn", rs.getLong("PROCESS_RRN"));
        lot.put("processId", rs.getString("PROCESS_ID"));
        lot.put("facilityRrn", rs.getLong("FACILITY_RRN"));

        long spent = DateUtils.getDistanceTime4Now(rs.getTimestamp("QUEUE_TIMESTAMP"));
        lot.put("queueTimestamp", spent / 60);
        lot.put("jobRrn", rs.getLong("JOB_RRN"));
        lot.put("createdTimestamp",
                (rs.getTimestamp("CREATED_TIMESTAMP") == null) ? 0 : rs.getTimestamp("CREATED_TIMESTAMP").getTime());
        lot.put("dueDate", (rs.getTimestamp("DUE_DATE") == null) ? 0 : rs.getTimestamp("DUE_DATE").getTime());
        lot.put("estimatedRemainTime", rs.getLong("ESTIMATED_REMAIN_TIME"));
        // 污染等级
        lot.put("pollutionLevel", rs.getString("ATTRIBUTE_DATA1"));


        if (LotConstants.QTIME_DEFUALT_VALUE != rs.getDouble("Q_TIME")){
            lot.put("qTime", rs.getString("Q_TIME"));
        }
        lot.put("timeLimit", rs.getString("TIME_REMAINING") == null ? "" : rs.getString("TIME_REMAINING"));
        lot.put("productLayer", rs.getString("product_layer"));
        lot.put("routeSeq", rs.getString("route_seq"));
        lot.put("operationSeq", rs.getString("operation_seq"));
        lot.put("processVersion", rs.getInt("PROCESS_VERSION"));
        lot.put("processStepVersion", rs.getString("PROCESS_STEP_VERSION"));
        lot.put("recipeLogicalRrn", rs.getLong("RECIPE_LOGICAL_RRN"));
        lot.put("recipePhysicalId", rs.getString("RECIPE_PHYSICAL_ID"));
        lot.put("contextRecipeId", rs.getString("contxt_recipe_id"));

        String recipeId = "";
        if (StringUtils.isNotBlank(MapUtils.getString(lot, "recipePhysicalId"))) {
            recipeId = MapUtils.getString(lot, "recipePhysicalId");
        } else if (MapUtils.getLongValue(lot, "recipeLogicalRrn") == 0 ||
                StringUtils.equalsIgnoreCase(MapUtils.getString(lot, "lotStatus"), LotStatus.HOLD) ||
                StringUtils.equalsIgnoreCase(MapUtils.getString(lot, "lotStatus"), LotStatus.WAITING)) {
            recipeId = rs.getString("contxt_recipe_id");
        } else {
            recipeId = rs.getString("LOGICAL_RECIPE_ID");
        }

        lot.put("recipeId", recipeId);
        lot.put("recipeRrn", rs.getLong("contxt_recipe_rrn"));

        lot.put("recipeParam", rs.getString("RECIPE_STRING"));
        lot.put("lotPlanType", rs.getString("LOT_PLAN_TYPE"));
        lot.put("batchId", rs.getString("BATCH_ID"));
        lot.put("contextStageId", rs.getString("context_stage_id"));
        lot.put("contextOperationDesc", rs.getString("context_step_desc"));
        lot.put("contextFlowSeq", rs.getString("context_flow_seq"));
        lot.put("operationMaxQueueTime", rs.getString("MAX_QUEUE_TIME"));
        lot.put("routeDesc", rs.getString("ROUTE_DESC"));
        lot.put("operationWorkArea", rs.getString("operation_work_area"));
        lot.put("piLot", rs.getString("PI_LOT"));
        lot.put("wflStepPath", rs.getString("WFL_STEP_PATH"));
        lot.put("recipeDocFile", rs.getString("RECIPE_DOC_FILE"));
        lot.put("recipeDocFileCompulsorydisplay", MiscUtils.changeCheckBox(rs.getString("RECIPE_DOC_COMMENTS")));
        lot.put("customerId", rs.getString("CUSTOMER_ID"));
        lot.put("createCategory", rs.getString("CREATE_CATEGORY"));
        lot.put("executionRrn", rs.getLong("EXECUTION_RRN"));
        lot.put("prevOperationRrn", rs.getLong("PREV_OPERATION_RRN"));

        return lot;
    }

}