# UnitQueryManagerImpl.java

    package com.mycim.server.wip.manager.impl;

    import com.mycim.framework.utils.lang.collections.CollectionUtils;
    import com.mycim.framework.utils.lang.collections.MapUtils;
    import com.mycim.server.wip.dao.UnitQueryDAO;
    import com.mycim.server.wip.manager.UnitQueryManager;
    import com.mycim.valueobject.prp.UnitRecycledInfo;
    import com.mycim.valueobject.wip.BoxForDie;
    import com.mycim.valueobject.wip.Lot;
    import com.mycim.valueobject.wip.Unit;
    import com.mycim.valueobject.wip.UnitTimelimitStatus;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
    import java.util.Map;

    /**
     * @author yanbing.chen
     * @date 2019/9/4
     * @since 1.8
     **/
    @Service
    @Transactional
    public class UnitQueryManagerImpl implements UnitQueryManager {

        @Autowired
        UnitQueryDAO unitQueryDAO;

        @Override
        public Unit getUnit(long unitRrn) {
            return unitQueryDAO.getUnit(unitRrn);
        }

        @Override
        public List<Unit> getUnitList(Long lotRrn) {
            return unitQueryDAO.getUnitList(lotRrn);
        }

        @Override
        public List<Map> getUnits(Long lotRrn) {
            return unitQueryDAO.getUnits(lotRrn);
        }

        @Override
        public List<Map> getUnitsByParentLotRrn(long lotRrn) {
            return unitQueryDAO.getUnitsByParentLotRrn(lotRrn);
        }

        @Override
        public List<Map> getUnitListByLot(long lotRrn) {
            return unitQueryDAO.getUnitListByLot(lotRrn, true);
        }

        @Override
        public Unit getUnit(long facilityRrn, String unitId) {
            return unitQueryDAO.getUnit(facilityRrn, unitId);
        }

        @Override
        public List<Map<String, Object>> getUsefulUnits(long lotRrn) {
            return unitQueryDAO.getUsefulUnits(lotRrn);
        }

        @Override
        public int getLotWafeCount(long lotRrn) {
            return unitQueryDAO.getLotWafeCount(lotRrn);
        }

        @Override
        public List<Map<String,Long>> getLotRrnFromUnitStepRangeHistory(String unitId) {
            return unitQueryDAO.getLotRrnFromUnitStepRangeHistory(unitId);
        }

        @Override
        public List<Map> getUnitListByCarrier(long carrierRrn) {
            return unitQueryDAO.getUnitListByCarrier(carrierRrn);
        }

        @Override
        public Long getNumberOfUnitInCarrier(Long carrierRrn) {
            return unitQueryDAO.getNumberOfUnitInCarrier(carrierRrn);
        }

        @Override
        public List<Map<String, Object>> getLotUnitsAndBoxsInfos(Long lotRrn) {
            // 批次下所有unit
            List<Map<String, Object>> usefulUnits = unitQueryDAO.getUsefulUnits(lotRrn);
            // 批次下所有box
            List<BoxForDie> boxsByLotRrn = unitQueryDAO.getBoxsByLotRrn(lotRrn);
            for (Map<String, Object> map : usefulUnits) {
                Long unitRrn = MapUtils.getLong(map, "UNIT_RRN");
                List<BoxForDie> unitBoxs = new ArrayList<BoxForDie>();
                // 循环匹配unit下面的box
                for (BoxForDie boxForDie : boxsByLotRrn) {
                    Long unitRrnForbox = boxForDie.getUnitRrn();
                    if (unitRrn.equals(unitRrnForbox)) {
                        unitBoxs.add(boxForDie);
                    }
                }
                // 将boxs放入unit信息中
                map.put("unitBoxs", unitBoxs);
            }
            return usefulUnits;
        }

        @Override
        public List<BoxForDie> getDieBoxsByLotRrn(Long lotRrn) {
            return unitQueryDAO.getBoxsByLotRrn(lotRrn);
        }

        @Override
        public List<Map<String, Object>> getUnitsByLot(Lot lot) {
            return unitQueryDAO.getUnitsByLot(lot);
        }

        @Override
        public List<Map> getUnitListByLot(long lotRrn, Boolean filterStatus) {
            return unitQueryDAO.getUnitListByLot(lotRrn, filterStatus);
        }

        @Override
        public List<Map> getUnitListHistory(long transRrn) {
            return unitQueryDAO.getUnitListHistory(transRrn);
        }

        @Override
        public List<Map<String, Long>> getReworkUnitSeq(Long lotRrn, String processStepVersion) {
            return unitQueryDAO.getReworkUnitSeq(lotRrn, processStepVersion);
        }

        @Override
        public List<Unit> getUnitListByT7Code(String t7Code) {
            return unitQueryDAO.getUnitListByT7Code(t7Code);
        }

        @Override
        public Unit getUnit4Alias1(Long unitRrn, String unitId) {
            return unitQueryDAO.getUnit4Alias(unitRrn, unitId, "UNIT_ALIAS_1");
        }

        @Override
        public Unit getUnit4Alias2(Long unitRrn, String unitId) {
            return unitQueryDAO.getUnit4Alias(unitRrn, unitId, "UNIT_ALIAS_2");
        }

        @Override
        public List<UnitTimelimitStatus> getUnitTimeLimitStatusByLotRrn(Long lotRrn, String targetStatus) {
            return unitQueryDAO.getUnitTimeLimitStatusByLotRrn(lotRrn, targetStatus);
        }

        @Override
        public List<UnitTimelimitStatus> getUnitTimeLimitStatusForNormal() {
            return unitQueryDAO.getUnitTimeLimitStatusForNormal();
        }

        @Override
        public List<Map<String, Object>> getUnitListFromCarrierMapping(Long lotRrn) {
            return unitQueryDAO.getUnitListFromCarrierMapping(lotRrn);
        }

        @Override
        public List<UnitRecycledInfo> getUnitRecycledInfoByLotRrn(Long lotRrn) {
            List<UnitRecycledInfo> results = unitQueryDAO.getUnitRecycledInfoByLotRrn(lotRrn);
            if (CollectionUtils.isEmpty(results)) {
                results = Collections.emptyList();
            }
            return results;
        }

        @Override
        public List<Unit> getAllUnits(Long lotRrn) {
            return unitQueryDAO.getAllUnits(lotRrn);
        }

        @Override
        public List<Map> getUnitListLot(Long lotRrn) {
            return unitQueryDAO.getUnitListLot(lotRrn);
        }

        @Override
        public String getUnitIdByRrn(Long unitRrn) {
            return unitQueryDAO.getUnitIdByRrn(unitRrn);
        }

        @Override
        public String getUnitIdBySlot(long lotRrn, long carrierRrn, Integer slot) {
            return unitQueryDAO.getUnitIdBySlotandLotRrnandCsdRrn(lotRrn, carrierRrn, slot);
        }

        @Override
        public List<Map<String, Object>> getUnitListByCarrierMapRrn(Long carrierMapRrn) {
            return unitQueryDAO.getUnitListByCarrierMapRrn(carrierMapRrn);
        }

        @Override
        public List<Map> getUnpackUnitListByLot(long lotRrn) {
            return unitQueryDAO.getUnpackUnitListByLot(lotRrn);
        }

        @Override
        public List<Unit> getUnitList(List<Long> lotRrnList) {
            return unitQueryDAO.getUnitList(lotRrnList);
        }

        @Override
        public Long getMaxReworkCountByUnit(Long lotRrn, String processStepVersion) {
            return unitQueryDAO.getMaxReworkCountByUnit(lotRrn, processStepVersion);
        }

        @Override
        public Long getMaxReworkCountByUnit(Long transRrn) {
            return unitQueryDAO.getMaxReworkCountByUnit(transRrn);
        }

        @Override
        public List<Unit> getUnitHistoryListByCarrierMapRrn(long oldCarrierMapRrn) {
            return unitQueryDAO.getUnitHistoryListByCarrierMapRrn(oldCarrierMapRrn);
        }

        @Override
        public List<Unit> getUnitListByCustomerT7Code(String customerT7code) {
            return unitQueryDAO.getUnitListByCustomerT7Code(customerT7code);
        }

        @Override
        public List<Unit> getUnitListByMaterialId(String materialId) {
            return unitQueryDAO.getUnitListByMaterialId(materialId);
        }

    }