# PmsPmScheduleRowMapper.java

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

    import com.mycim.framework.jdbc.mapper.RowMapper;
    import com.mycim.framework.utils.lang.StringUtils;
    import com.mycim.framework.utils.lang.time.DateUtils;
    import com.mycim.valueobject.ems.*;

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

    public class PmsPmScheduleRowMapper implements RowMapper<PmsSchedule> {

        @Override
        public PmsSchedule mapRow(ResultSet rs, int rowNum) throws SQLException {
            String type = rs.getString("CONTROL_TYPE");
            PmsSchedule schedule = PmsScheduleSimplyFactory.create().find(type);

            schedule.setPmRrn(rs.getLong("PM_RRN"));
            schedule.setPmId(rs.getString("PM_ID"));
            schedule.setObjectRrn(rs.getLong("OBJECT_RRN"));
            schedule.setObjectType(rs.getString("OBJECT_TYPE"));
            schedule.setObjectId(rs.getString("OBJECT_ID"));
            schedule.setChamberId("#".equals(rs.getString("CHAMBER_ID")) ? "" : rs.getString("CHAMBER_ID"));
            schedule.setPmType(rs.getString("PM_TYPE"));
            schedule.setPmItemDesc(rs.getString("PM_ITEM_DESC"));
            schedule.setCycleTime(rs.getDouble("CYCLE_TIME"));
            schedule.setDurationTime(rs.getDouble("DURATION_TIME"));
            schedule.setNextPmTime(rs.getTimestamp("NEXT_PM_TIME"));
            schedule.setToleranceTime(rs.getDouble("TOLERANCE_TIME"));
            schedule.setCycleCount(rs.getInt("CYCLE_COUNT"));
            schedule.setDurationCount(rs.getInt("DURATION_COUNT"));
            schedule.setCurrentPmCount(rs.getInt("CURRENT_PM_COUNT"));
            schedule.setToleranceCount(rs.getInt("TOLERANCE_COUNT"));
            schedule.setCycleOther(rs.getString("CYCLE_OTHER"));
            schedule.setDurationOther(rs.getString("DURATION_OTHER"));
            schedule.setCurrentPmOther(rs.getString("CURRENT_PM_OTHER"));
            schedule.setToleranceOther(rs.getString("TOLERANCE_OTHER"));
            schedule.setItemStatus(rs.getString("ITEM_STATUS"));
            schedule.setAutoEqpStatus(rs.getString("AUTO_EQP_STATUS"));
            schedule.setCreateUserRrn(rs.getLong("CREATE_USER_RRN"));
            schedule.setCreateUserId(rs.getString("PM_CREATE_USER"));
            //schedule.setCreateDate(rs.getDate("CREATE_DATE")); //数据库Date类型，直接拿是拿不到时分秒的
            schedule.setCreateDate(new Date(rs.getTimestamp("CREATE_DATE").getTime()));
            schedule.setAttributeData1(rs.getString("ATTRIBUTE_DATA_1"));
            schedule.setAttributeData2(rs.getString("ATTRIBUTE_DATA_2"));
            schedule.setAttributeData3(rs.getString("ATTRIBUTE_DATA_3"));
            schedule.setAttributeData4(rs.getString("ATTRIBUTE_DATA_4"));
            schedule.setAttributeData5(rs.getString("ATTRIBUTE_DATA_5"));
            schedule.setObjectStatus(rs.getString("OBJECT_STATUS"));
            schedule.setChamberStatus(rs.getString("CHAMBER_STATUS"));
            schedule.setChamberRrn(rs.getLong("CHAMBER_RRN"));
            schedule.setControlType(type);
            schedule.setAlarmCount(rs.getInt("ALARM_COUNT"));
            schedule.setTotalCount(rs.getInt("TOTAL_COUNT"));
            schedule.setChecklistRrn(rs.getLong("CHECKLIST_RRN"));
            schedule.setChecklistId(rs.getString("CHECKLIST_ID"));
            schedule.setEqptStatus(rs.getString("EQPT_STATUS"));
            schedule.setEquipmentLocation(rs.getString("EQUIPMENT_LOCATION"));
            schedule.setTransId(rs.getString("trans_id"));
            String userLocation = rs.getString("USER_LOCATION");
            if (StringUtils.isNotBlank(userLocation) &&
                    userLocation.contains("#" + schedule.getEquipmentLocation() + "#")) {
                schedule.setInUserLocation(1);
            } else {
                schedule.setInUserLocation(0);
            }

            String[] pmDateStr = DateUtils.formatDate(schedule.getNextPmTime()).split(" ");
            schedule.setNextPmTimeStr(pmDateStr[0]);
            schedule.setSubNextPmTimeStr(pmDateStr[1].substring(0, 5));
            schedule.setStation(rs.getString("STATION_IDS"));
            schedule.setPmTimeType(rs.getString("PM_TIME_TYPE"));
            schedule.setPmLinks(rs.getString("PM_LINKS"));
            schedule.setTriggerCode(rs.getString("TRIGGER_CODE"));
            schedule.setTriggerCodeSpec(rs.getString("TRIGGER_CODE_SPEC"));
            schedule.setTriggerReading(rs.getString("TRIGGER_READING"));
            return schedule;
        }

    }