# CarrierInqDAOImpl.java

    package com.mycim.server.carrier.dao.impl;

    import com.fa.sesa.threadlocal.LocalContext;
    import com.mycim.framework.jdbc.JdbcTemplate;
    import com.mycim.server.carrier.dao.CarrierInqDAO;
    import com.mycim.server.carrier.dao.mapper.CarrierInqMapper;
    import com.mycim.valueobject.consts.DataBaseNames;
    import com.mycim.valueobject.ems.Carrier;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Repository;

    /**
     * @author finatice.yang
     * @date 2021/12/23
     **/
    @Repository
    public class CarrierInqDAOImpl implements CarrierInqDAO {

        @Autowired
        JdbcTemplate jdbcTemplate;

        @Override
        public String getCarrierId(Long carrierRrn) {
            StringBuilder sql = new StringBuilder("SELECT CARRIER_ID FROM ");
            sql.append(DataBaseNames.CARRIER);
            sql.append(" WHERE CARRIER_RRN = ?");
            return jdbcTemplate.queryForObjectWithNull(sql.toString(), String.class, carrierRrn);
        }

        @Override
        public Long getCarrierRrn(String carrierId) {
            StringBuilder sql = new StringBuilder("SELECT CARRIER_RRN FROM ");
            sql.append(DataBaseNames.CARRIER);
            sql.append(" WHERE CARRIER_ID = ? AND FACILITY_RRN = ?");
            Object[] args = new Object[]{carrierId, LocalContext.getFacilityRrn()};
            return jdbcTemplate.queryForObjectWithNull(sql.toString(), args, Long.class);
        }

        @Override
        public Carrier getCarrier(Long carrierRrn) {
            StringBuilder sql = new StringBuilder("SELECT ");
            sql.append(" A.CARRIER_RRN,A.CARRIER_ID,A.DESCRIPTION,A.Allowable_Events_Rrn,A.Obj_Subtype,");
            sql.append(" A.SLOT_COUNT,A.AVAILABLE_SLOT_COUNT, A.CARRIER_CODE, A.MCS_MOVE_STATUS, A.MCS_LAST_MOVE_TIME, ");
            sql.append(" A.MCS_LAST_OPERATOR_RRN, A.EQPT_RRN, A.JOB_RRN, A.RUN_RRN, A.CARRIER_MAP_RRN,");
            sql.append(" A.LOAD_POSITION,A.POLLUTION_LEVEL,C.CURRENT_STATUS,A.FLAG_TYPE, A.DMM_TYPE");
            sql.append(" FROM ");
            sql.append(DataBaseNames.CARRIER + " A ");
            sql.append(" LEFT JOIN ").append(DataBaseNames.CARRIER_STATUS + " C ");
            sql.append(" ON A.CARRIER_RRN = C.CARRIER_SYS_RRN WHERE A.CARRIER_RRN = ? ");
            return jdbcTemplate.queryForObjectWithNull(sql.toString(), new CarrierInqMapper(), carrierRrn);
        }

    }