# WipQueryServiceImpl.java

    package com.mycim.server.wip.service;

    import com.alipay.sofa.runtime.api.annotation.SofaService;
    import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding;
    import com.mycim.framework.jdbc.Page;
    import com.mycim.framework.utils.lang.StringUtils;
    import com.mycim.framework.utils.lang.collections.CollectionUtils;
    import com.mycim.framework.utils.lang.collections.MapUtils;
    import com.mycim.server.base.manager.NamedObjectManager;
    import com.mycim.server.constrain.manager.LotConstrainManager;
    import com.mycim.server.prp.manager.OperationManager;
    import com.mycim.server.security.manager.RoleManager;
    import com.mycim.server.security.service.SecurityService;
    import com.mycim.server.spec.manager.AttributeConvertManager;
    import com.mycim.server.wip.manager.*;
    import com.mycim.valueobject.alm.EenAction;
    import com.mycim.valueobject.automonitor.entity.LotAutoMonitorInfo;
    import com.mycim.valueobject.bas.ErrorMsg;
    import com.mycim.valueobject.bas.Relation;
    import com.mycim.valueobject.consts.EDCConst;
    import com.mycim.valueobject.consts.OcapTypeEnum;
    import com.mycim.valueobject.consts.VersionStatus;
    import com.mycim.valueobject.edcspc.Parameter;
    import com.mycim.valueobject.edcspc.rule.CollectionRule;
    import com.mycim.valueobject.ems.Equipment;
    import com.mycim.valueobject.ems.pilot.PiLotRcpGrp;
    import com.mycim.valueobject.ems.pilot.PiLotSetup;
    import com.mycim.valueobject.ems.pilot.PiLotView;
    import com.mycim.valueobject.ems.pilot.dto.PiLotRcpGrpQueryDTO;
    import com.mycim.valueobject.ems.pilot.dto.PiLotSetupQueryDTO;
    import com.mycim.valueobject.ems.pilot.dto.PiLotViewQueryDTO;
    import com.mycim.valueobject.ocap.OcapCard;
    import com.mycim.valueobject.ocap.dto.OcapCardDTO;
    import com.mycim.valueobject.ocap.dto.OcapChartInfoDTO;
    import com.mycim.valueobject.ocap.dto.OcapQueryConditionDTO;
    import com.mycim.valueobject.prp.ContextValue;
    import com.mycim.valueobject.security.Station;
    import com.mycim.valueobject.wip.*;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.util.ObjectUtils;

    import java.util.*;

    /**
     * lot相关的单独处理
     *
     * @author Johnson Wang
     **/
    @Service
    @SofaService(interfaceType = WipQueryService.class, bindings = {@SofaServiceBinding(bindingType = "bolt")})
    public class WipQueryServiceImpl implements WipQueryService {

        private static final String FUTURE_KEY = "future";

        private static final String FUTURE_STEP_SEQ_KEY = "futureStepSeq";

        @Autowired
        private LotQueryManager lotQueryManager;

        @Autowired
        private OperationPanelQueryManager operationPanelQueryManager;

        @Autowired
        private RoleManager roleManager;

        @Autowired
        private SecurityService securityService;

        @Autowired
        private NamedObjectManager objectManager;

        @Autowired
        private UnitQueryManager unitQueryManager;

        @Autowired
        private JobQueryManager jobQueryManager;

        @Autowired
        private EquipmentQueryManager equipmentQueryManager;

        @Autowired
        private ReticleQueryManager reticleQueryManager;

        @Autowired
        private EdcQueryManager edcQueryManager;

        @Autowired
        private EenActionQueryManager eenActionQueryManager;

        @Autowired
        private WipWorkflowQueryManager wipWorkflowQueryManager;

        @Autowired
        private OcapQueryManager ocapQueryManager;

        @Autowired
        private OperationManager operationManager;

        @Autowired
        private LotConstrainManager lotConstrainManager;

        @Autowired
        private PiLotInqManager piLotInqManager;

        @Autowired
        AttributeConvertManager attributeConvertManager;

        @Autowired
        private EquipmentRunHistoryReqManager equipmentRunHistoryReqManager;

        @Override
        public Run getRun(Long runRrn) {
            return jobQueryManager.getRun(runRrn);
        }

        @Override
        public Run getRunByJob(long jobRrn) {
            return jobQueryManager.getRunByJob(jobRrn);
        }

        @Override
        public Page queryRunHistory(Page page, Long runRrn) {
            return jobQueryManager.queryRunHistory(page, runRrn);
        }

        @Override
        public String getParamCon(Long lotRrn, String stepSequence) {
            return lotQueryManager.getParamCon(lotRrn, stepSequence);
        }

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

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

        @Override
        public String getHotflagSplicingPriority(Integer hotFlag, Integer priority, Long facilityRrn) {
            return lotQueryManager.getHotflagSplicingPriority(hotFlag, priority, facilityRrn);
        }

        @Override
        public String getConsumedMaterial(Long lotRrn) {
            return lotQueryManager.getConsumedMaterial(lotRrn);
        }

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

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

        @Override
        public List<Map> getReleaseReasonCodes(String releaseReasonGroupID, List<Object> releaseRoles,
                                               String referenceFileId) {
            return lotQueryManager.getReleaseReasonCodes(releaseReasonGroupID, releaseRoles, referenceFileId);
        }

        @Override
        public List<Map> getHoldReasonCodes(String holdReasonGroupID, List<String> holdRoles, String referenceFileId) {
            return lotQueryManager.getHoldReasonCodes(holdReasonGroupID, holdRoles, referenceFileId);
        }

        @Override
        public List<Map> getHoldReasonCodes4HoldCodeGroupAll(String referenceFileId) {
            return lotQueryManager.getHoldReasonCodes4HoldCodeGroupAll(referenceFileId);
        }

        @Override
        public List<Map> getReleaseGroup(String holdCode, String classTableValue) {
            return lotQueryManager.getReleaseGroup(holdCode, classTableValue);
        }

        @Override
        public Boolean hasChangeOrReleaseHoldPermissionForBatch(Long facilityRrn, Long userRrn,
                                                                List<Map<String, Object>> holdReasons) {
            boolean hasPermission = true;
            if (CollectionUtils.isEmpty(holdReasons) || roleManager.isAdminRole(facilityRrn, userRrn)) {
                return hasPermission;
            }

            for (Map<String, Object> holdReason : holdReasons) {
                long holdByRrn = MapUtils.getLongValue(holdReason, "holdByRrn");
                String holdCode = MapUtils.getString(holdReason, "reasonCode");
                List<Map> releaseGroups = getReleaseGroup(holdCode, "$HOLD_CODE");
                String releaseGroup = "";
                if (CollectionUtils.isNotEmpty(releaseGroups)) {
                    releaseGroup = (String) releaseGroups.get(0).get("releaseGroup");
                }
                boolean isSystemHold = holdByRrn == 0;
                if (!(isSystemHold || StringUtils.equalsIgnoreCase(releaseGroup, "ALL") ||
                        securityService.checkUserExistedUserGroups(userRrn, releaseGroup))) {
                    hasPermission = false;
                    break;
                }
            }

            return hasPermission;
        }

        @Override
        public Boolean hasChangeOrReleaseHoldPermission(Long facilityRrn, Long userRrn, Long holdByRrn, String holdCode) {
            boolean isSystemHold = holdByRrn != null && holdByRrn == 0;
            if (isSystemHold || roleManager.isAdminRole(facilityRrn, userRrn) ||
                    roleManager.isSpecificRole(facilityRrn, userRrn)) {
                return true;
            }

            List<Map> releaseGroups = getReleaseGroup(holdCode, "$HOLD_CODE");
            String releaseGroup = "";
            if (CollectionUtils.isNotEmpty(releaseGroups)) {
                releaseGroup = (String) releaseGroups.get(0).get("releaseGroup");
            }
            return StringUtils.equalsIgnoreCase(releaseGroup, "ALL") ||
                    securityService.checkUserExistedUserGroups(userRrn, releaseGroup);
        }

        @Override
        public int countPilotLotInfo(long lotRrn) {
            return lotQueryManager.countPilotLotInfo(lotRrn);
        }

        @Override
        public PilotLotInfo getPilotLotInfo(long lotRrn) {
            return lotQueryManager.getPilotLotInfo(lotRrn);
        }

        @Override
        public Lot getLotPlan(String lotId) {
            return lotQueryManager.getLotPlan(lotId);
        }

        @Override
        public Map getLotPlanMap(String lotId) {
            return lotQueryManager.getLotPlanMap(lotId);
        }

        @Override
        public List queryLotPlanHistory(Map map, int current, int pageSize) {
            return lotQueryManager.queryLotPlanHistory(map, current, pageSize);
        }

        @Override
        public boolean checkLotStatus(Long recipeRrn, long entityRrn) {
            return lotQueryManager.checkLotStatus(recipeRrn, entityRrn);
        }

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

        @Override
        public Job getJob(long jobRrn) {
            return jobQueryManager.getJob(jobRrn);
        }

        @Override
        public int countLotForOperatorPanel(Map criterion) {
            return operationPanelQueryManager.countLotForOperatorPanel(criterion);
        }

        @Override
        public List<Map<String, Object>> listLotForOperatorPanel(Map criterion) {
            return operationPanelQueryManager.listLotForOperatorPanel(criterion);
        }

        @Override
        public List<Map<String, Object>> listLotForOperatorPanelByRuncard(Map criterion) {
            return operationPanelQueryManager.listLotForOperatorPanelByRuncard(criterion);
        }

        @Override
        public List qryLotCreateHistory(long lotRrn, int current, int pageSize) {
            return lotQueryManager.qryLotCreateHistory(lotRrn, current, pageSize);
        }

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

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

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

        @Override
        public long getJobRrn(long lotRrn) {
            return jobQueryManager.getJobRrn(lotRrn);
        }

        @Override
        public List<Station> getEntities4ExtByUser(long userRrn, String namedSpace, String filter) {
            return equipmentQueryManager.getEntities4ExtByUser(userRrn, namedSpace, filter);
        }

        @Override
        public Map<String, Integer> countLotByStausForEntity(String lotStatus) {
            return equipmentQueryManager.countLotByStausForEntity(lotStatus);
        }

        @Override
        public List<String> getLotsStatusEntity(Long entityRrn) {
            return equipmentQueryManager.getLotsStatusEntity(entityRrn);
        }

        @Override
        public List<Equipment> getEquipment4Ext(long equipmentRrn, long stationRrn) {
            return equipmentQueryManager.getEquipment4Ext(equipmentRrn, stationRrn);
        }

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

        @Override
        public List<Map> getJobList(long instanceRrn, String type) {
            return jobQueryManager.getJobList(instanceRrn, type);
        }

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

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

        @Override
        public List<Relation> getAvailableReticlesForTrackIn(Lot lot, Long equipmentRrn) {
            return reticleQueryManager.getAvailableReticlesForTrackIn(lot, equipmentRrn);
        }

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

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

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

        @Override
        public double getParamValByCondition(long lotRrn, long operationRrn, long productRrn, long processRrn,
                                             long parameterRrn, String puType) {
            return edcQueryManager.getParamValByCondition(lotRrn, operationRrn, productRrn, processRrn, parameterRrn,
                                                          puType);
        }

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

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

        @Override
        public List<EenAction> getFutureActions(ContextValue contextValue, long facilityRrn) {
            return eenActionQueryManager.getFutureActions(contextValue, facilityRrn);
        }

        @Override
        public Unit getUnit4Alias2(Long unitRrn, String unitId) {
            return unitQueryManager.getUnit4Alias2(unitRrn, unitId);
        }

        @Override
        public Unit getUnit4Alias1(Long unitRrn, String unitId) {
            return unitQueryManager.getUnit4Alias1(unitRrn, unitId);
        }

        @Override
        public CollectionRule getAvailableDataCollectionRule(List<Unit> unitList, Long parameterRrn) {
            return edcQueryManager.getAvailableDataCollectionRule(unitList, parameterRrn);
        }

        @Override
        public CollectionRule getAvailableDataCollectionRule(Lot lot, List<Unit> unitList, Long parameterRrn) {
            Map<String, Object> matchMap = new HashMap<String, Object>();
            matchMap.put(EDCConst.CollectionRuleMatchKey.FACILITY_RRN.getMatchKey(), lot.getFacilityRrn());
            matchMap.put(EDCConst.CollectionRuleMatchKey.EQPT_RRN.getMatchKey(), lot.getEqptRrn());
            matchMap.put(EDCConst.CollectionRuleMatchKey.PRODUCT_RRN.getMatchKey(), lot.getProductRrn());

            Long matcRecipeRrn = lot.getRecipeRrn();
            if (matcRecipeRrn == null || matcRecipeRrn.longValue() <= 0) {
                matcRecipeRrn = lot.getRecipeLogicalRrn();
            }
            matchMap.put(EDCConst.CollectionRuleMatchKey.RECIPE_RRN.getMatchKey(), matcRecipeRrn);

            return edcQueryManager.getAvailableDataCollectionRule(lot.getFacilityRrn(), lot.getLotRrn(), matchMap, unitList,
                                                                  parameterRrn);
        }

        @Override
        public String getSemiAutoParamsInExection(long exectionRrn) {
            return jobQueryManager.getSemiAutoParamsInExection(exectionRrn);
        }

        @Override
        public List<Map> equipmentFutureLotCache(Long equipmentRrn, String operationStep, Map conditionInfo,
                                                 Long facilityRrn) {
            List<Map> operationMap = operationManager.getOperationMap(equipmentRrn);

            Map<String, Object> tempEquipLot = new HashMap<>(4);
            Map equipLot = new HashMap();
            List equipLots = new ArrayList();

            for (int i = 1; i <= 10; i++) {
                tempEquipLot.put(FUTURE_KEY + i, Integer.toString(0));
            }

            Equipment equipment = new Equipment();
            equipment.setInstanceRrn(equipmentRrn);
            List<Map> equipmentLots = lotQueryManager.getLotsByEquipment4Ext(equipmentRrn, operationStep, operationMap);
            equipmentLots = checkCondition(conditionInfo, equipmentLots);

            List<Map> lots = new ArrayList<>();
            for (Object equipmentLot : equipmentLots) {
                Map lot = (HashMap) equipmentLot;
                if (MapUtils.isNotEmpty(lot)) {
                    boolean addFlag = true;
                    for (Map map : lots) {
                        if (map.get("lotId").equals(lot.get("lotId"))) {
                            if (MapUtils.getLongValue((HashMap) map, FUTURE_STEP_SEQ_KEY) <
                                    MapUtils.getLongValue(lot, FUTURE_STEP_SEQ_KEY)) {
                                addFlag = false;
                            } else {
                                lots.remove((HashMap) map);
                            }
                            break;
                        }
                    }
                    if (addFlag) {
                        lots.add(lot);
                    }
                }
            }

            // 对比限制
            for (Map map : lots) {
                long futureStep = MapUtils.getLongValue(map, FUTURE_STEP_SEQ_KEY);
                ErrorMsg errorMsg = checkLotConstrain(equipment, map);
                if (!errorMsg.getError()) {
                    if (tempEquipLot.containsKey(FUTURE_KEY + futureStep)) {
                        int tempfutureStep = MapUtils.getIntValue(tempEquipLot, FUTURE_KEY + futureStep);
                        tempEquipLot.put(FUTURE_KEY + futureStep, Integer.toString(tempfutureStep + 1));
                    } else {
                        tempEquipLot.put(FUTURE_KEY + futureStep, Integer.toString(1));
                    }
                }
            }

            for (int i = 1; i <= 10; i++) {
                int countLot = 0;
                for (int k = 1; k <= i; k++) {
                    countLot += Integer.parseInt(tempEquipLot.get(FUTURE_KEY + k) + "");
                }
                equipLot.put(FUTURE_KEY + i, Integer.toString(countLot));
            }

            equipLot.put("equipRrn", Long.toString(equipmentRrn));
            equipLot.put("equipId", objectManager.getInstanceId(equipment.getInstanceRrn()));
            equipLot.put("operationStep", conditionInfo.get("oeprationstep"));
            equipLot.put("lotId", conditionInfo.get("lotId"));
            equipLot.put("productId", conditionInfo.get("productId"));
            equipLot.put("processId", conditionInfo.get("processId"));
            equipLot.put("routeId", conditionInfo.get("routeId"));
            equipLot.put("operationId", conditionInfo.get("operationId"));
            equipLots.add(equipLot);
            return equipLots;
        }

        @Override
        public List<Map> equipmentFutureLotDetailCache(Long equipmentRrn, String operationStep, Long facilityRrn,
                                                       Map conditionInfo) {
            List<Map> operationMap = operationManager.getOperationMap(equipmentRrn);

            List<Map> equipmentLots = lotQueryManager.queryFutureLotDetail4Extjs(equipmentRrn, operationStep, operationMap);
            equipmentLots = removeRepeatLotInfo(equipmentLots);
            equipmentLots = checkCondition(conditionInfo, equipmentLots);
            List eqLots = new ArrayList();
            Equipment equipment = new Equipment();
            equipment.setInstanceRrn(equipmentRrn);
            Map lot = new TreeMap();
            for (Map equipmentLot : equipmentLots) {
                lot = (TreeMap) equipmentLot;
                long tLotRrn = MapUtils.getLongValue(lot, "lotRrn");
                String operationRrn = MapUtils.getString(lot, "operationprrn");
                String productRrn = MapUtils.getString(lot, "productrrn");
                String processRrn = MapUtils.getString(lot, "processrrn");

                Lot sLot = lotQueryManager.getLot(tLotRrn);
                sLot.setOperationRrn(Long.valueOf(operationRrn));
                sLot.setProcessRrn(Long.valueOf(processRrn));
                sLot.setProductRrn(Long.valueOf(productRrn));
                ErrorMsg errorMsg = lotConstrainManager.checkLotConstrain(equipment, sLot);
                if (!errorMsg.getError()) {
                    long routeRrn = MapUtils.getLongValue(lot, "routeRrn");
                    String routeDesc = objectManager.getNamedObjectDesc(routeRrn);
                    lot.put("routeDesc", routeDesc);
                    eqLots.add(lot);
                }
            }

            eqLots.sort(new Comparator() {
                @Override
                public int compare(Object a, Object b) {
                    Map mapA = (Map) a;
                    Map mapB = (Map) b;
                    Long idA = (Long) mapA.get(FUTURE_STEP_SEQ_KEY);
                    Long idB = (Long) mapB.get(FUTURE_STEP_SEQ_KEY);
                    return idA.compareTo(idB);
                }
            });
            return eqLots;
        }

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

        @Override
        public CollectionRule getDataCollectionRule(List<Unit> unitList, Long parameterSetRrn, Integer parameterSetVersion,
                                                    Long parameterRrn) {
            return edcQueryManager.getDataCollectionRule(unitList, parameterSetRrn, parameterSetVersion, parameterRrn);
        }

        @Override
        public List<Lot> getLotsByEqpt(String whereSql, long eqptRrn) {
            return lotQueryManager.getLotsByEqpt(whereSql, eqptRrn);
        }

        @Override
        public Map getLotTransInfo(String lotrrn) {
            return lotQueryManager.getLotTransInfo(lotrrn);
        }

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

        @Override
        public Map getNodeInfoByWflTree(Lot lot, long operationRrn, boolean beforeFirst) {
            return wipWorkflowQueryManager.getNodeInfoByWflTree(lot, operationRrn, beforeFirst);
        }

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

        @Override
        public List<Relation> getReticlesForMovein(Long reticleGroupRrn, long eqptRrn, boolean statusFLag) {
            return reticleQueryManager.getReticlesForMovein(reticleGroupRrn, eqptRrn, statusFLag);
        }

        @Override
        public Page getOcapCardPage(OcapQueryConditionDTO queryConditionDTO) {
            List<String> endAreaIds = new ArrayList<>();
            // 查询时同时兼容workArea desc 与 code
            Map<String, String> workAreaKeyMap = attributeConvertManager.getWorkAreaKeyMap();
            List<String> areaIds = queryConditionDTO.getAreaIds();
            endAreaIds.addAll(areaIds);
            for (String areaId : areaIds) {
                if (StringUtils.isNotBlank(areaId)) {
                    String workAreaDesc= MapUtils.getString(workAreaKeyMap, areaId, StringUtils.EMPTY);
                    if (!StringUtils.equalsIgnoreCase(areaId, workAreaDesc)) {
                        endAreaIds.add(workAreaDesc);
                    }
                }
            }
            queryConditionDTO.setAreaIds(endAreaIds);
            return ocapQueryManager.getOcapCardPage(queryConditionDTO);
        }

        @Override
        public Map<Long, String> getParamSetMapByLotRrn(Long lotRrn) {
            Map<Long, String> paramSetMap = new HashMap<>(16);
            lotQueryManager.getParamSetMapByLotRrn(lotRrn, paramSetMap);
            return paramSetMap;
        }

        @Override
        public void checkActiveOfflineOcapId(Long facilityRrn, String equipmentId, String chartName) {
            ocapQueryManager.checkActiveOfflineOcapId(facilityRrn, equipmentId, chartName);
        }

        @Override
        public void checkActiveOfflineOcapId(Long eqptRrn) {
            ocapQueryManager.checkActiveOfflineOcapId(eqptRrn);
        }

        @Override
        public Boolean checkActiveOfflineOcapId(Long eqptRrn, String eventId) {
            return ocapQueryManager.checkLogEventActiveOfflineOcap(eqptRrn, eventId);
        }

        @Override
        public OcapCard getOcapCardByUniqueKey(Long facilityRrn, String ocapId, String lotId) {
            return ocapQueryManager.getOcapCardByUniqueKey(facilityRrn, ocapId, lotId);
        }

        @Override
        public List<String> getActiveOfflineOcapIds(Long eqptRrn) {
            return ocapQueryManager.getActiveOfflineOcapIds(eqptRrn);
        }

        @Override
        public List<String> getActiveOfflineOcapListByLot(Long lotRrn) {
            List<String> ocapIds = ocapQueryManager.getActiveOfflineOcapListByLot(lotRrn);
            return ocapIds;
        }

        @Override
        public List<OcapChartInfoDTO> queryOcapChartInfoList(OcapChartInfoDTO dto) {
            return ocapQueryManager.queryOcapChartInfoList(dto);
        }

        @Override
        public String getActiveInlineOcapIdByLot(long lotRrn) {
            return ocapQueryManager.getActiveInlineOcapId(lotRrn);
        }

        @Override
        public void checkActiveInlineOcapId(long lotRrn) {
            ocapQueryManager.checkActiveInlineOcapId(lotRrn);
        }

        @Override
        public boolean isValidOcapHold(Long lotRrn, String oldReason) {
            return ocapQueryManager.isValidOcapHold(lotRrn, oldReason);
        }

        @Override
        public String getAvailableReticleIdsStr(Lot lot, Long equipmentRrn) {
            return reticleQueryManager.getAvailableReticleIdsStr(lot, equipmentRrn);
        }

        @Override
        public String getAvailableReticleIdsByAutoMonitor(LotAutoMonitorInfo monitorInfo, Long equipmentRrn) {
            if (StringUtils.isNotBlank(monitorInfo.getReticleId())) {
                return monitorInfo.getReticleId();
            } else if (StringUtils.isNotBlank(monitorInfo.getReticleGroupId())) {
                Long reticleGroupRrn = monitorInfo.getReticleGroupRrn();
                return reticleQueryManager.getAvailableReticleIdsStr(reticleGroupRrn, equipmentRrn, Boolean.TRUE);
            } else {
                return StringUtils.EMPTY;
            }
        }

        @Override
        public long getReticleFamilyRrnByLot(Lot lot) {
            return reticleQueryManager.getReticleFamilyRrnByLot(lot);
        }

        @Override
        public List<Parameter> getLotEdcInfoList(Lot lot, Equipment equipment) {
            return edcQueryManager.getLotEdcInfoList(lot, equipment);
        }

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

        @Override
        public OcapCard getOcapCardByPrimaryKey(Long ocapRrn) {
            return ocapQueryManager.getOcapCardByPrimaryKey(ocapRrn);
        }

        @Override
        public List<OcapCard> getOcapCardsByBatchId(long facilityRrn, String ocapBatchId) {
            return ocapQueryManager.getOcapCardsByBatchId(facilityRrn, ocapBatchId);
        }

        @Override
        public OcapCardDTO getOcapInfo(long facilityRrn, String ocapId, String lotId) {
            return ocapQueryManager.getOcapInfo(facilityRrn, ocapId, lotId);
        }

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

        @Override
        public String getMixedEqptGroupIds(Lot lot, long equipmentRrn) {
            return equipmentQueryManager.getMixedEqptGroupIds(lot, equipmentRrn);
        }

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

        @Override
        public Page getPiLotSetups(PiLotSetupQueryDTO queryDTO) {
            return piLotInqManager.getPiLotSetups(queryDTO);
        }

        @Override
        public PiLotSetup getPiLotSetup(Long piLotSetupRrn) {
            return piLotInqManager.getBasePilotSetup(piLotSetupRrn);
        }

        @Override
        public Page getPiLotViews(PiLotViewQueryDTO queryDTO) {
            return piLotInqManager.getPiLotViews(queryDTO);
        }

        @Override
        public PiLotView getPiLotViewByViewRrn(Long piLotViewRrn) {
            return piLotInqManager.getPiLotViewByRrn(piLotViewRrn);
        }

        @Override
        public PiLotView getPiLotViewIdByLotRrn(Long lotRrn, Long baseLotRrn) {
            PiLotView pilotView = piLotInqManager.getPiLotViewByLotRrn(lotRrn);
            if (Objects.nonNull(pilotView)) {
                return pilotView;
            }
            if (lotRrn.longValue() == baseLotRrn.longValue()) {
                // 母批
                return piLotInqManager.getPiLotViewByLotRrn(baseLotRrn);
            } else {
                // 子批
                return piLotInqManager.getPiLotViewByChildLotRrn(lotRrn);
            }
        }

        @Override
        public Page queryRcpGrpList(PiLotRcpGrpQueryDTO queryDTO) {
            return piLotInqManager.getPiLotRcpGrps(queryDTO);
        }

        @Override
        public PiLotRcpGrp getPiLotRcpGrp(Long rcpGrpRrn) {
            return piLotInqManager.getPiLotRcpGrpByRrn(rcpGrpRrn);
        }

        @Override
        public Page queryRcpList(PiLotRcpGrpQueryDTO queryDTO) {
            return piLotInqManager.getPiLotRcps(queryDTO);
        }

        @Override
        public PiLotView getPiLotViewByLotRrn(Long lotRrn) {
            return piLotInqManager.getPiLotViewByLotRrn(lotRrn);
        }

        @Override
        public PiLotView getPiLotViewByChildLotRrn(Long lotRrn) {
            return piLotInqManager.getPiLotViewByChildLotRrn(lotRrn);
        }

        @Override
        public Page querySetupHistorys(PiLotSetupQueryDTO queryDTO) {
            return piLotInqManager.querySetupHistorys(queryDTO);
        }

        @Override
        public Page queryViewHistorys(PiLotViewQueryDTO queryDTO) {
            return piLotInqManager.queryViewHistorys(queryDTO);
        }

        @Override
        public PiLotSetup getPiLotSetupByTypeAndEqptId(String type, String eqptId) {
            return piLotInqManager.getPiLotSetupByTypeAndEqptId(type, eqptId);
        }

        @Override
        public PiLotSetup getPiLotSetupByView(String piLotViewId, String lotId) {
            return null;
        }

        @Override
        public PiLotSetup getPiLotSetupByRrn(Long piLotRrn) {
            return piLotInqManager.getPiLotSetupByRrn(piLotRrn);
        }

        private ErrorMsg checkLotConstrain(Equipment equipment, Map lot) {
            long tLotRrn = MapUtils.getLongValue(lot, "lotRrn");

            Lot sLot = new Lot();
            sLot.setLotRrn(tLotRrn);
            sLot = lotQueryManager.getLot(tLotRrn);

            ErrorMsg errorMsg = lotConstrainManager.checkLotConstrain(equipment, sLot);
            return errorMsg;
        }

        /**
         * 用户条件查询判断<br> 根据判断生成相对应的需要显示的数据
         *
         * @return
         */
        private List<Map> checkCondition(Map conditionInfo, List<Map> lots) {
            if (conditionInfo.size() != 0) {
                List<Map> newLots = new ArrayList();
                for (Map object : lots) {
                    if (isMatchCondition(conditionInfo, object)) {
                        newLots.add(object);
                    }
                }
                return newLots;
            }
            return lots;
        }

        /**
         * 匹配条件
         *
         * @param conditionInfo
         * @param object
         * @return
         */
        private boolean isMatchCondition(Map conditionInfo, Map object) {
            Set entrySet = conditionInfo.entrySet();
            int i = 0;
            for (Iterator iterator2 = entrySet.iterator(); iterator2.hasNext(); ) {
                Map.Entry entry = (Map.Entry) iterator2.next();
                String key = ObjectUtils.getDisplayString(entry.getKey());
                String value = ObjectUtils.getDisplayString(entry.getValue());
                if (object.containsKey(key) && object.containsValue(value)) {
                    i++;
                }
                if (i == conditionInfo.size()) {
                    return true;
                }
            }
            return false;
        }

        /**
         * 去除重复lot,取futureStepSeq小的
         *
         * @param equipmentLots Collection
         * @return lots Collection
         */
        private List<Map> removeRepeatLotInfo(List<Map> equipmentLots) {
            List<Map> lots = new ArrayList();
            for (Map equipmentLot : equipmentLots) {
                if (MapUtils.isNotEmpty(equipmentLot)) {
                    Map lot = (TreeMap) equipmentLot;
                    boolean addFlag = true;
                    for (Map map : lots) {
                        Map tempLot = (TreeMap) map;
                        if (tempLot.get("lotId").equals(lot.get("lotId"))) {
                            if (MapUtils.getLongValue(tempLot, FUTURE_STEP_SEQ_KEY) <
                                    MapUtils.getLongValue(lot, FUTURE_STEP_SEQ_KEY)) {
                                addFlag = false;
                            } else {
                                lots.remove(tempLot);
                            }
                            break;
                        }
                    }
                    if (addFlag) {
                        lots.add(lot);
                    }
                }
            }
            return lots;
        }

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

        @Override
        public String getLatestRunModeOfMoveIn(String equipmentId, String lotId, Long lotRrn, Long stepSequence) {
            return equipmentRunHistoryReqManager.getLatestRunModeOfMoveIn(equipmentId, lotId, lotRrn, stepSequence);
        }

    }