# CarrierServiceImpl.java

    package com.mycim.server.carrier.service;

    import com.alipay.sofa.runtime.api.annotation.SofaService;
    import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding;
    import com.fa.sesa.exception.Assert;
    import com.fa.sesa.exception.Errors;
    import com.mycim.framework.jdbc.Page;
    import com.mycim.framework.utils.lang.StringUtils;
    import com.mycim.framework.utils.lang.math.NumberUtils;
    import com.mycim.server.base.manager.EventManager;
    import com.mycim.server.base.manager.NamedObjectManager;
    import com.mycim.server.carrier.manager.CarrierManager;
    import com.mycim.server.carrier.manager.DoorManager;
    import com.mycim.server.carrier.manager.PcdManager;
    import com.mycim.server.carrier.manager.PodManager;
    import com.mycim.server.status.manager.StatusManager;
    import com.mycim.server.system.manager.ReferenceFileManager;
    import com.mycim.valueobject.MessageIdList;
    import com.mycim.valueobject.consts.PcdStatus;
    import com.mycim.valueobject.ems.*;
    import com.mycim.valueobject.sorter.UnitBean;
    import com.mycim.valueobject.sys.ReferenceFileDetail;
    import com.mycim.valueobject.wip.Lot;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;

    import java.util.List;
    import java.util.Map;
    import java.util.stream.Collectors;

    @Service
    @SofaService(interfaceType = CarrierService.class, bindings = {@SofaServiceBinding(bindingType = "bolt")})
    public class CarrierServiceImpl implements CarrierService {

        @Autowired
        CarrierManager carrierManager;

        @Autowired
        PodManager podManager;

        @Autowired
        DoorManager doorManager;

        @Autowired
        NamedObjectManager objectManager;

        @Autowired
        ReferenceFileManager referenceFileManager;

        @Autowired
        EventManager eventManager;

        @Autowired
        PcdManager pcdManager;

        @Autowired
        StatusManager statusManager;

        @Override
        public Map<String, Object> qryCarrierListByPage(Map<String, Object> argMap) {
            return carrierManager.qryCarrierListByPage(argMap);
        }

        @Override
        public Map<String, Object> getEventInfoByPcdId(Long facilityRrn, String pcdId, String pcdType,
                                                       String targetStatus) {
            return pcdManager.getEventInfoByPcdId(facilityRrn, pcdId, pcdType, targetStatus);
        }

        @Override
        public Map<String, Object> getCarrierInfoDetailById(String carrierId, String namedSpace) {
            return carrierManager.getCarrierInfoDetailById(carrierId, namedSpace);
        }

        @Override
        public PcdClean getPcdCleanInfo(Long pcdRrn) {
            PcdClean cleanInfo = new PcdClean();
            if (pcdRrn != null && pcdRrn > 0) {
                cleanInfo = pcdManager.getPcdCleanInfo(pcdRrn);
            }
            return cleanInfo;
        }

        @Override
        public Map<String, Object> checkPcdChangeStatusButton(Long facilityRrn, Long pcdRrn, String currentStatus) {
            return pcdManager.checkPcdChangeStatusButton(facilityRrn, pcdRrn, currentStatus);
        }

        @Override
        public double getDefaultCleanCycle(String category, String type, Long facilityRrn) {
            return pcdManager.getDefaultCleanCycle(category, type, facilityRrn);
        }

        @Override
        public String generateCarrierId(String prefix) {
            return pcdManager.generateCarrierId(prefix);
        }

        @Override
        public String generateCarrierId(String prefix, int serialLength) {
            return pcdManager.generateCarrierId(prefix, serialLength);
        }

        @Override
        public Carrier getCarrier(long carrierRrn) {
            return carrierManager.getCarrier(carrierRrn);
        }

        @Override
        public Carrier getCarrier(Long facilityRrn, String carrierId) {
            return carrierManager.getCarrier(facilityRrn, carrierId);
        }

        @Override
        public void deleteCarrierEntity(String carrierId, Long facilityRrn, String user) {
            carrierManager.deleteCarrierEntity(carrierId, facilityRrn, user);
        }

        @Override
        public void addCarrierEntity(Map<String, Object> attrMap, Long facilityRrn, String user) {
            carrierManager.addCarrierEntity(attrMap, facilityRrn, user);
        }

        @Override
        public void updateCarrierEntity(Map<String, Object> attrMap, Long facilityRrn, String user) {
            carrierManager.updateCarrierEntity(attrMap, facilityRrn, user);
        }

        @Override
        public void changePcdStatusByLogEvent(Long facilityRrn, String user, String pcdId, String pcdType, String eventId,
                                              String comments, String targetStatus, String currentStatus,
                                              String cleanEqptId) {
            statusManager.changePcdStatusByLogEvent(facilityRrn, user, pcdId, pcdType, eventId, comments, targetStatus,
                                                    currentStatus, cleanEqptId);
        }

        @Override
        public PcdAssembly getPcdAssembly(Long carrierRrn, Long podRrn, Long doorRrn) {
            return pcdManager.getPcdAssembly(carrierRrn, podRrn, doorRrn);
        }

        @Override
        public POD getPod(long podRrn) {
            return podManager.getPod(podRrn);
        }

        @Override
        public Door getDoor(long doorRrn) {
            return doorManager.getDoor(doorRrn);
        }

        @Override
        public boolean checkPcdOverClean(long pcdRrn) {
            return pcdManager.checkPcdOverClean(pcdRrn);
        }

        @Override
        public void assemblyPcd(Long carrierRrn, Long podRrn, Long doorRrn, String user, Long facilityRrn) {
            pcdManager.assemblyPcd(carrierRrn, podRrn, doorRrn, user, facilityRrn);
        }

        @Override
        public void deAssemblyPcd(Long carrierRrn, Long podRrn, Long doorRrn, String user, Long facilityRrn) {
            pcdManager.deAssemblyPcd(carrierRrn, podRrn, doorRrn, user, facilityRrn);
        }

        @Override
        public Boolean isAssembledPCD(Long instanceRrn) {
            return pcdManager.isAssembledPCD(instanceRrn);
        }

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

        @Override
        public void holdCarrier(Map transInfo) {
            carrierManager.holdCarrier(transInfo);
        }

        @Override
        public void releaseCarrier(Map transInfo) {
            carrierManager.releaseCarrier(transInfo);
        }

        @Override
        public void holdPod(Map transInfo) {
            podManager.holdPod(transInfo);
        }

        @Override
        public void releasePod(Map transInfo) {
            podManager.releasePod(transInfo);
        }

        @Override
        public void holdDoor(Map transInfo) {
            doorManager.holdDoor(transInfo);
        }

        @Override
        public void releaseDoor(Map transInfo) {
            doorManager.releaseDoor(transInfo);
        }

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

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

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

        @Override
        public Map<String, Object> qryPodListByPage(Map<String, Object> argMap) {
            return podManager.qryPodListByPage(argMap);
        }

        @Override
        public void deletePodEntity(String podId, Long facilityRrn, String user) {
            podManager.deletePodEntity(podId, facilityRrn, user);
        }

        @Override
        public void updatePodEntity(Map<String, Object> attrMap, Long facilityRrn, String user) {
            podManager.updatePodEntity(attrMap, facilityRrn, user);
        }

        @Override
        public void addPodEntity(Map<String, Object> attrMap, Long facilityRrn, String user) {
            podManager.addPodEntity(attrMap, facilityRrn, user);
        }

        @Override
        public Map<String, Object> getPodInfoDetailById(String podId, String namedSpace) {
            return podManager.getPodInfoDetailById(podId, namedSpace);
        }

        @Override
        public Map<String, Object> getDoorInfoDetailById(String doorId, String namedSpace) {
            return doorManager.getDoorInfoDetailById(doorId, namedSpace);
        }

        @Override
        public Map<String, Object> qryDoorListByPage(Map<String, Object> argMap) {
            return doorManager.qryDoorListByPage(argMap);
        }

        @Override
        public void deleteDoorEntity(String doorId, Long facilityRrn, String user) {
            doorManager.deleteDoorEntity(doorId, facilityRrn, user);
        }

        @Override
        public void updateDoorEntity(Map<String, Object> attrMap, Long facilityRrn, String user) {
            doorManager.updateDoorEntity(attrMap, facilityRrn, user);
        }

        @Override
        public void addDoorEntity(Map<String, Object> attrMap, Long facilityRrn, String user) {
            doorManager.addDoorEntity(attrMap, facilityRrn, user);
        }

        @Override
        public Page queryCarrierHistory(Page page, Map<String, Object> query) {
            return carrierManager.queryCarrierHistory(page, query);
        }

        @Override
        public List<Map<String, Object>> getAllPcdCategory(Long facilityRrn) {
            return pcdManager.getAllPcdCategory(facilityRrn);
        }

        @Override
        public List<Map<String, Object>> getAllPcdType(Long facilityRrn) {
            return pcdManager.getAllPcdType(facilityRrn);
        }

        /**
         * 计算PCD的category加type组合总共有多少组
         */
        @Override
        public int getCategoryAndTypeCount(Long facilityRrn) {
            List<Map<String, Object>> categoryList = getAllPcdCategory(facilityRrn);
            List<Map<String, Object>> typeList = getAllPcdType(facilityRrn);
            return categoryList.size() * typeList.size();
        }

        @Override
        public void resetCleanCycle(List<Map<String, Object>> defaultCleanCycleList, Long facilityRrn, String user) {
            pcdManager.resetCleanCycle(defaultCleanCycleList, facilityRrn, user);
        }

        @Override
        public List<ReferenceFileDetail> getCleanEqptRefDetailInfo(String eqptId, Long facilityRrn) {
            return pcdManager.getCleanEqptRefDetailInfo(eqptId, facilityRrn);
        }

        @Override
        public String checkCleanEqptIsInUse(String eqptId, Long facilityRrn) {
            return pcdManager.checkCleanEqptIsInUse(eqptId, facilityRrn);
        }

        @Override
        public List<PcdClean> getCleaningPcdByEqpt(String eqptId, Long facilityRrn) {
            return pcdManager.getCleaningPcdByEqpt(eqptId, facilityRrn);
        }

        @Override
        public void batchOutClean(Long facilityRrn, String eqptId, String cstIds, String podIds, String doorIds,
                                  String user) {
            pcdManager.batchOutClean(facilityRrn, eqptId, cstIds, podIds, doorIds, user);
        }

        @Override
        public void batchInClean(Long facilityRrn, String eqptId, String cstIds, String podIds, String doorIds,
                                 String user) {
            pcdManager.batchInClean(facilityRrn, eqptId, cstIds, podIds, doorIds, user);
        }

        @Override
        public List<PcdClean> getPcdInfoByCleanEqpt(String eqptId, String entityNamedSpace) {
            return pcdManager.getPcdInfoByCleanEqpt(eqptId, entityNamedSpace);
        }

        @Override
        public void compareRealCarrierAndCheckAvailabile(Long facilityRrn, String sourceCarrierId, String targetCarrierId) {
            Carrier sourceCarrier = getCarrier(facilityRrn, sourceCarrierId);
            Carrier targetCarrier = getCarrier(facilityRrn, targetCarrierId);

            Assert.isTrue(StringUtils.equalsIgnoreCase(targetCarrier.getObjectSubtype(), sourceCarrier.getObjectSubtype()),
                          Errors.create().key(MessageIdList.CARRIER_TYPE_IS_NOT_CONSISTENT).content("晶舟类型不一致").build());

            Assert.isFalse(this.isAssseblyNeed(targetCarrier.getObjectSubtype()) &&
                                   !StringUtils.equals(targetCarrier.getCarrierStatus(), PcdStatus.ASSEMBLY_KEY),
                           Errors.create().key(MessageIdList.CARRIER_INVALID_CASSETTE_STATUS).content("晶舟当前状态不能交换!")
                                 .build());
            Assert.isTrue(this.isAssseblyNeed(targetCarrier.getObjectSubtype()) ||
                                  StringUtils.equals(targetCarrier.getCarrierStatus(), PcdStatus.FREE_KEY),
                          Errors.create().key(MessageIdList.CARRIER_INVALID_CASSETTE_STATUS).content("晶舟当前状态不能交换!")
                                .build());

            Assert.isTrue(StringUtils.equalsIgnoreCase(targetCarrier.getFlagType(), sourceCarrier.getFlagType()),
                          Errors.create().key(MessageIdList.CARRIER_CATEGORY_IS_NOT_CONSISTENT).content("晶舟类别不一致").build());

            checkPcdIsValid(targetCarrier.getInstanceRrn(), facilityRrn);
        }

        @Override
        public void checkPcdIsValid(Long carrierRrn, Long facilityRrn) {
            pcdManager.checkPcdIsValid(carrierRrn, facilityRrn);
        }

        @Override
        public List<String> getInUseCarrierLotIdList(Long carrierRrn) {
            return carrierManager.getInUseCarrierLotIdList(carrierRrn);
        }

        @Override
        public Long getNumberOfAvailableInCarrier(Long carrierRrn) {
            return carrierManager.getNumberOfAvailableInCarrier(carrierRrn);
        }

        @Override
        public Long getAvailableCarrierRrnById(Long facilityRrn, String carrierId) {
            return carrierManager.getAvailableCarrierRrnById(facilityRrn, carrierId);
        }

        @Override
        public void exchangeCarrierSpecial(Lot lot, long toCarrierRrn, List<Map> carrierMappings, Carrier toCarrier,
                                           Long facilityRrn, String userId) {
            carrierManager.exchangeCarrierSpecial(lot, toCarrierRrn, carrierMappings, toCarrier, facilityRrn, userId);
        }

        @Override
        public Boolean isAssseblyNeed(String carrierType) {
            return carrierManager.isAssseblyNeed(carrierType);
        }

        @Override
        public boolean isPcdCleaningTimeIsLessThan3Days(Long pcdRrn) {
            return pcdManager.isPcdCleaningTimeIsLessThan3Days(pcdRrn);
        }

        @Override
        public String getCarriertypeByProcessLocation(Lot lot) {
            return carrierManager.getCarriertypeByProcessLocation(lot);
        }

        @Override
        public Long getCarrierRrnForLot(Long facilityRrn, Lot lot, String carrierId) {
            return carrierManager.getCarrierRrnForLot(facilityRrn, lot, carrierId);
        }

        @Override
        public Long getCarrierRrnForLot(Long facilityRrn, Double lotQty, String carrierId) {
            return carrierManager.getCarrierRrnForLot(facilityRrn, lotQty, carrierId);
        }

        @Override
        public String getTargetCarrierTypeByStatus(Lot lot) {
            return carrierManager.getTargetCarrierTypeByStatus(lot);
        }

        @Override
        public void compareRealAndDummyCarrierAndCheckRealCarrierAvailabile(long facilityRrn, String dummyCarrierId,
                                                                            String realCarrierId) {
            Carrier dummyCarrier = getCarrier(facilityRrn, dummyCarrierId);
            Carrier realCarrier = getCarrier(facilityRrn, realCarrierId);

            Assert.isTrue(StringUtils.equalsIgnoreCase(realCarrier.getObjectSubtype(), dummyCarrier.getDmmType()),
                          Errors.create().key(MessageIdList.CARRIER_TYPE_IS_NOT_CONSISTENT).content("晶舟类型不一致").build());

            Assert.isFalse(this.isAssseblyNeed(realCarrier.getObjectSubtype()) &&
                                   !StringUtils.equals(realCarrier.getCarrierStatus(), PcdStatus.ASSEMBLY_KEY),
                           Errors.create().key(MessageIdList.CARRIER_INVALID_CASSETTE_STATUS).content("晶舟当前状态不能交换")
                                 .build());
            Assert.isTrue(this.isAssseblyNeed(realCarrier.getObjectSubtype()) ||
                                  StringUtils.equals(realCarrier.getCarrierStatus(), PcdStatus.FREE_KEY),
                          Errors.create().key(MessageIdList.CARRIER_INVALID_CASSETTE_STATUS).content("晶舟当前状态不能交换").build());

            Assert.isTrue(StringUtils.equalsIgnoreCase(realCarrier.getFlagType(), dummyCarrier.getFlagType()),
                          Errors.create().key(MessageIdList.CARRIER_CATEGORY_IS_NOT_CONSISTENT).content("晶舟类别不一致").build());

            checkPcdIsValid(realCarrier.getInstanceRrn(), facilityRrn);
        }

        @Override
        public String getTargetCarrierTypeByActionPoint(String actionPoint, Lot lot) {
            return carrierManager.getTargetCarrierTypeByActionPoint(actionPoint, lot);
        }

        @Override
        public boolean isThisCarrierPmNotMoveIn(long carrierRrn) {
            return carrierManager.isThisCarrierPmNotMoveIn(carrierRrn);
        }

        @Override
        public void exchangePCD(List<Map> transInfo) {
            pcdManager.exchangePCD(transInfo);
        }

        @Override
        public void checkPCDCleanTimeAndLogEvent(String waitCleanKey) {
            pcdManager.checkPCDCleanTimeAndLogEvent(waitCleanKey);
        }

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

        @Override
        public List<Long> getInUseCarrierLotRrnList(Long carrierRrn) {
            return carrierManager.getInUseCarrierLotRrnList(carrierRrn);
        }

        @Override
        public void checkPCDInfo(List<String> lotIdList, String actionPoint) {
            carrierManager.checkPCDInfo(lotIdList, actionPoint);
        }

        @Override
        public void checkPcdInfo(List<Lot> lotList, String actionPoint) {
            carrierManager.checkPcdInfo(lotList, actionPoint);
        }

        @Override
        public Boolean getCarrierRefreshInfo(Long carrierRrn) {
            return carrierManager.getCarrierRefreshInfo(carrierRrn);
        }

        @Override
        public void refreshCarrier(Long carrierRrn) {
            carrierManager.refreshCarrier(carrierRrn);
        }

        @Override
        public String generatePodId(String prefix, int width) {
            return podManager.generatePodId(prefix,width);
        }

        @Override
        public String generateCstIdByType(String prefix, int width) {
            return carrierManager.generateCstIdByType(prefix,width);
        }

        @Override
        public void autoExchangePCDType(Long carrierRrn) {
            pcdManager.autoExchangePCDType(carrierRrn);
        }

        @Override
        public void manualExchangePCDType(Carrier carrier) {
            pcdManager.manualExchangePCDType(carrier);
        }

        @Override
        public Boolean checkSwitchCarrierType(String targetCSTType) {
            return carrierManager.checkSwitchCarrierType(targetCSTType);
        }

        @Override
        public String generatePcdIdByPcdType(String pcdType, String prefix, String ignorePrefix, int length) {
            return carrierManager.generatePcdIdByPcdType(pcdType, prefix, ignorePrefix, length);
        }

    }