# LotStatusCheckServiceImpl.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.utils.lang.StringUtils;
    import com.mycim.framework.utils.lang.collections.MapUtils;
    import com.mycim.server.base.manager.NamedObjectManager;
    import com.mycim.server.wip.manager.LotQueryManager;
    import com.mycim.server.wip.manager.RunCardQueryManager;
    import com.mycim.valueobject.wip.Lot;
    import com.mycim.valueobject.wip.LotRunCard;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;

    import java.util.Collection;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;

    /**
     * @author finatice.yang
     * @date 2021/5/14
     **/
    @Service
    @SofaService(interfaceType = LotStatusCheckService.class, bindings = {@SofaServiceBinding(bindingType = "bolt")})
    public class LotStatusCheckServiceImpl implements LotStatusCheckService {

        @Autowired
        RunCardQueryManager runCardQueryManager;

        @Autowired
        LotQueryManager lotQueryManager;

        @Autowired
        NamedObjectManager namedObjectManager;

        @Override
        public boolean isValidRcHold(Lot lot, String reason) {

            List<LotRunCard> runcardList = runCardQueryManager.getEffectiveLotRuncardByLot(lot.getLotRrn());
            for (LotRunCard runcard : runcardList) {
                String lotFlowSeq = lotQueryManager.getFlowSeqByLot(lot);
                boolean isValidRcHold = StringUtils.equals(lotFlowSeq, runcard.getSplitFlowSeq()) &&
                        StringUtils.contains(reason, namedObjectManager.getInstanceId(runcard.getRunCardRrn()));
                if (isValidRcHold) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public boolean hasValidRcHold(Lot lot) {

            List<Map> holdReasons = lotQueryManager.getHoldReasons(lot.getLotRrn());

            List<LotRunCard> runcardList = runCardQueryManager.getEffectiveLotRuncardByLot(lot.getLotRrn());
            for (LotRunCard runcard : runcardList) {
                String lotFlowSeq = lotQueryManager.getFlowSeqByLot(lot);
                String runcardId = namedObjectManager.getInstanceId(runcard.getRunCardRrn());

                for (Map holdReason : holdReasons) {
                    String reason = MapUtils.getString(holdReason, "reason");

                    boolean isValidRcHold = StringUtils.equals(lotFlowSeq, runcard.getSplitFlowSeq()) &&
                            StringUtils.contains(reason, runcardId);
                    if (isValidRcHold) {
                        return true;
                    }
                }
            }

            return false;
        }

    }