LotQueryInfoMapper.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.LotConstants;
import com.mycim.valueobject.wip.LotStatus;
import com.mycim.valueobject.wip.LotStepStatSpeedTime;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class LotQueryInfoMapper implements RowMapper<Map<String, Object>> {

    private final int countLot;

    private final int countQty;

    public LotQueryInfoMapper(int countLot, int countQty) {
        this.countLot = countLot;
        this.countQty = countQty;
    }


    @Override
    public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        String priority = StringUtils.EMPTY;
        if(StringUtils.isNotBlank(rs.getString("PRIORITY"))){
            priority = rs.getString("PRIORITY");
        }

        dataMap.put("lotCount", countLot);
        dataMap.put("qtyCount", countQty);

        dataMap.put("processStepIdVersion", rs.getString("process_step_id_version"));
        dataMap.put("processStepVersion", rs.getString("process_step_version"));
        dataMap.put("lotID", rs.getString("LOT_ID"));
        dataMap.put("lotRRN", rs.getLong("LOT_RRN"));
        dataMap.put("eqpRrn", rs.getLong("eqpt_rrn"));
        dataMap.put("lotStatus", rs.getString("LOT_STATUS"));
        dataMap.put("statusFlag", rs.getString("LOT_STATUS"));
        dataMap.put("lotType", rs.getString("LOT_TYPE"));
        dataMap.put("lotOwer", rs.getString("lot_owner"));
        dataMap.put("lotPiority", rs.getString("hot_flag") + "-" + priority); // 已拼接
        dataMap.put("qty1", rs.getInt("QTY1")); // 数量
        dataMap.put("carrierRrn", rs.getString("CARRIER_RRN"));
        dataMap.put("productRrn", rs.getLong("PRODUCT_RRN"));
        dataMap.put("routeSeq", rs.getString("ROUTE_SEQ"));
        dataMap.put("stepSeq", rs.getString("operation_seq"));
        dataMap.put("Step_Sequence", rs.getString("Step_Sequence"));
        dataMap.put("processRrn", rs.getLong("PROCESS_RRN"));
        dataMap.put("stepRrn", rs.getLong("operation_rrn"));
        dataMap.put("lotCategory", rs.getString("CREATE_CATEGORY"));

        LocalDateTime queueTime = rs.getTimestamp("QUEUE_TIMESTAMP").toLocalDateTime();
        Duration queueTimeDuration = Duration.between(queueTime, LocalDateTime.now());
        long spent = queueTimeDuration.toMinutes();

        String waitTimeHr = (new java.text.DecimalFormat("#0.00")).format(spent / 60f);
        dataMap.put("queueTime", waitTimeHr); // 小时 new Long(spent / 60 / 60)

        if (LotConstants.QTIME_DEFUALT_VALUE != rs.getDouble("Q_TIME")){
            dataMap.put("timeLimit", rs.getDouble("Q_TIME"));
        }

        if (StringUtils.equalsIgnoreCase(LotStatus.HOLD, rs.getString("LOT_STATUS")) ||
                StringUtils.equalsIgnoreCase(LotStatus.RUNNINGHOLD, rs.getString("LOT_STATUS"))) {
            if (rs.getTimestamp("HOLD_TIMESTAMP") != null) {
                LocalDateTime holdTime = rs.getTimestamp("HOLD_TIMESTAMP").toLocalDateTime();
                Duration holdTimeDuration = Duration.between(holdTime, LocalDateTime.now());
                long holdSpent = holdTimeDuration.toMinutes();

                String holdTimeHr = (new java.text.DecimalFormat("#0.00")).format(holdSpent / 60f);
                dataMap.put("holdTime", holdTimeHr);
            }
        }

        dataMap.put("stageID", rs.getString("STAGE_ID"));
        dataMap.put("pollutionLevel", rs.getString("POLLUTION_LEVEL"));
        dataMap.put("recipePara", rs.getString("RECIPE_STRING"));// 工艺规格
        dataMap.put("isRework", rs.getString("REWORK_CATEGORY"));
        //		dataMap.put("lotCategory", rs.getString("CREATE_CATEGORY"));
        dataMap.put("processVersion", rs.getString("PROCESS_VERSION"));
        dataMap.put("shippingCode", rs.getString("SHIPPING_CODE"));
        dataMap.put("customerId", rs.getString("CUSTOMER_ID"));
        dataMap.put("outerOrderNO", rs.getString("OUTER_ORDER_NO"));
        dataMap.put("outOrderType", rs.getString("OUT_ORDER_TYPE"));
        dataMap.put("workOrderId", rs.getString("INNER_ORDER_NO"));
        dataMap.put("customerLotId", rs.getString("CUSTOMER_LOT_ID"));
        dataMap.put("wflSeq", rs.getString("FLOW_SEQ"));
        dataMap.put("locationRrn", rs.getLong("LOCATION"));
        dataMap.put("pLocationRrn", rs.getLong("PLOCATION"));
        //		dataMap.put("recipeRrn", rs.getLong("RECIPE_RRN"));
        //		dataMap.put("routeRrn", rs.getLong("ROUTE_RRN"));
        dataMap.put("lotPurpose", rs.getString("lot_comments"));
        dataMap.put("materialLotId", rs.getString("unit_alias_2"));
        dataMap.put("processLocation", rs.getString("process_location"));
        dataMap.put("jobRrn", rs.getLong("JOB_RRN"));
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date(rs.getTimestamp("due_date").getTime());
        dataMap.put("dueDate", format.format(date));
        byte[] dataStruct=  rs.getBytes("CURRENT_STEP_TIME_STRUCT");
        LotStepStatSpeedTime lotStepStatSpeedTime= new LotStepStatSpeedTime(dataStruct);
        dataMap.putAll(lotStepStatSpeedTime.resolveDataStruct());
        return dataMap;
    }

}