# PiLotReqManagerImpl.java

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

    import com.fa.sesa.i18n.I18nUtils;
    import com.fa.sesa.threadlocal.LocalContext;
    import com.mycim.framework.oid.IDGenerators;
    import com.mycim.framework.oid.type.IDNames;
    import com.mycim.framework.oid.type.SequenceNames;
    import com.mycim.framework.utils.beans.BeanUtils;
    import com.mycim.framework.utils.lang.ObjectUtils;
    import com.mycim.framework.utils.lang.StringUtils;
    import com.mycim.framework.utils.lang.time.DateUtils;
    import com.mycim.server.base.manager.TransactionLogManager;
    import com.mycim.server.ems.manager.EquipmentManager;
    import com.mycim.server.pilot.dao.PiLotReqDAO;
    import com.mycim.server.pilot.manager.PiLotCheckManager;
    import com.mycim.server.pilot.manager.PiLotReqManager;
    import com.mycim.server.wip.manager.*;
    import com.mycim.valueobject.MessageIdList;
    import com.mycim.valueobject.bas.TransactionLog;
    import com.mycim.valueobject.consts.PiLotStatusEnum;
    import com.mycim.valueobject.consts.PiLotTypeEnum;
    import com.mycim.valueobject.consts.TransactionNames;
    import com.mycim.valueobject.ems.Equipment;
    import com.mycim.valueobject.ems.pilot.*;
    import com.mycim.valueobject.wip.Lot;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.util.Date;
    import java.util.List;
    import java.util.Objects;

    /**
     * @author songpy
     * @version 1.0.0
     * @date 2021/8/26
     **/
    @Service
    @Transactional
    public class PiLotReqManagerImpl implements PiLotReqManager {
        @Autowired
        PiLotInqManager piLotInqManager;

        @Autowired
        private TransactionLogManager transactionLogManager;

        @Autowired
        private EquipmentManager equipmentManager;

        @Autowired
        private PiLotCheckManager piLotCheckManager;

        @Autowired
        private PiLotReqDAO dao;

        @Autowired
        private EenActionManager eenActionManager;

        @Autowired
        private LotTransHistoryReqManager lotTransHistoryReqManager;

        @Autowired
        private LotInqManager lotInqManager;

        @Override
        public void addPiLotSetup(PiLotSetup piLotSetup, TransactionLog transactionLog) {
            piLotSetup.setPiLotRrn(
                    Long.valueOf(IDGenerators.get(IDNames.SEQUENCE).generateId(SequenceNames.MODULE_SEQ_OBJECT_RRN)));
            piLotSetup.setCreateUserRrn(LocalContext.getUserRrn());
            piLotSetup.setCreateTime(transactionLog.getTransStartTimestamp());
            piLotSetup.setUpdateUserRrn(LocalContext.getUserRrn());
            piLotSetup.setUpdateTime(transactionLog.getTransStartTimestamp());
            piLotSetup.setPiLotId(initPiLotId(piLotSetup));
            piLotSetup.setStatus(PiLotStatusEnum.CREATED.toString());
            dao.insertPiLotSetup(piLotSetup);

            if (Objects.nonNull(piLotSetup.getIdle())) {
                dao.insertPiLotSetupIdle(piLotSetup, piLotSetup.getIdle());
                insertPiLotSetupIdleHistory(piLotSetup, piLotSetup.getIdle(), transactionLog);
            } else if (Objects.nonNull(piLotSetup.getPm())) {
                dao.insertPiLotSetupPM(piLotSetup, piLotSetup.getPm());
                insertPiLotSetupPMHistory(piLotSetup, piLotSetup.getPm(), transactionLog);
            } else if (Objects.nonNull(piLotSetup.getCount())) {
                dao.insertPiLotSetupCount(piLotSetup, piLotSetup.getCount());
                insertPiLotSetupCountHistory(piLotSetup, piLotSetup.getCount(), transactionLog);
            } else if (Objects.nonNull(piLotSetup.getRcpGrp())) {
                dao.insertPiLotSetupRcpGrp(piLotSetup, piLotSetup.getRcpGrp());
                insertPiLotSetupRcpGrpHistory(piLotSetup, piLotSetup.getRcpGrp(), transactionLog);
            }

            piLotSetup = piLotInqManager.getPiLotSetupByRrn(piLotSetup.getPiLotRrn());
            insertPiLotSetupHistory(piLotSetup, transactionLog);
        }

        @Override
        public void updatePiLotSetup(PiLotSetup piLotSetup, TransactionLog transactionLog) {
            piLotSetup.setUpdateUserRrn(LocalContext.getUserRrn());
            piLotSetup.setUpdateTime(transactionLog.getTransStartTimestamp());
            dao.updatePiLotSetup(piLotSetup);
            if (Objects.nonNull(piLotSetup.getIdle())) {
                dao.updatePiLotSetupIdle(piLotSetup, piLotSetup.getIdle());
                insertPiLotSetupIdleHistory(piLotSetup, piLotSetup.getIdle(), transactionLog);
            } else if (Objects.nonNull(piLotSetup.getPm())) {
                dao.updatePiLotSetupPM(piLotSetup, piLotSetup.getPm());
                insertPiLotSetupPMHistory(piLotSetup, piLotSetup.getPm(), transactionLog);
            } else if (Objects.nonNull(piLotSetup.getCount())) {
                dao.updatePiLotSetupCount(piLotSetup, piLotSetup.getCount());
                insertPiLotSetupCountHistory(piLotSetup, piLotSetup.getCount(), transactionLog);
            } else if (Objects.nonNull(piLotSetup.getRcpGrp())) {
                dao.updatePiLotSetupRcpGrp(piLotSetup, piLotSetup.getRcpGrp());
                insertPiLotSetupRcpGrpHistory(piLotSetup, piLotSetup.getRcpGrp(), transactionLog);
            }

            piLotSetup = piLotInqManager.getPiLotSetupByRrn(piLotSetup.getPiLotRrn());
            insertPiLotSetupHistory(piLotSetup, transactionLog);
        }

        @Override
        public void deletePiLotSetup(Long piLotSetupRrn, TransactionLog transactionLog) {
            insertPiLotSetupHistory(piLotInqManager.getPiLotSetupByRrn(piLotSetupRrn), transactionLog);
            dao.deletePiLotSetup(piLotSetupRrn);
        }

        @Override
        public void createPiLotView(PiLotSetup piLotSetup) {
            TransactionLog transactionLog = transactionLogManager.startTransactionLog(LocalContext.getUserId(),
                                                                                      TransactionNames.CREATE_KEY +
                                                                                              " VIEW");
            createPiLotView(piLotSetup, transactionLog);
            piLotSetup.setStatus(PiLotStatusEnum.ONGOING.toString());
            updatePiLotSetup(piLotSetup, transactionLog);
        }

        @Override
        public void savePiLotView(PiLotView piLotView, TransactionLog transactionLog) {
            String comments = piLotView.getComments();
            piLotView.setUpdateUserRrn(LocalContext.getUserRrn());
            piLotView.setUpdateTime(transactionLog.getTransStartTimestamp());
            dao.updatePiLotView(piLotView);

            piLotView = piLotInqManager.getPiLotViewByRrn(piLotView.getViewRrn());
            piLotView.setComments(comments);
            insertPiLotViewHistory(piLotView, transactionLog);
        }

        @Override
        public void updateRcpGrp(PiLotRcpGrp piLotRcpGrp, TransactionLog transactionLog) {
            piLotRcpGrp.setUpdateUserRrn(LocalContext.getUserRrn());
            piLotRcpGrp.setUpdateTime(transactionLog.getTransStartTimestamp());
            dao.updatePiLotRcpGrp(piLotRcpGrp);
            piLotRcpGrp = piLotInqManager.getPiLotRcpGrpByRrn(piLotRcpGrp.getRcpGrpRrn());
            insertPiLotRcpGrpHistory(piLotRcpGrp, transactionLog);
        }

        @Override
        public void addRcpGrp(PiLotRcpGrp piLotRcpGrp, TransactionLog transactionLog) {
            piLotRcpGrp.setRcpGrpRrn(
                    Long.valueOf(IDGenerators.get(IDNames.SEQUENCE).generateId(SequenceNames.MODULE_SEQ_OBJECT_RRN)));
            piLotRcpGrp.setCreateUserRrn(LocalContext.getUserRrn());
            piLotRcpGrp.setCreateTime(transactionLog.getTransStartTimestamp());
            piLotRcpGrp.setUpdateUserRrn(LocalContext.getUserRrn());
            piLotRcpGrp.setUpdateTime(transactionLog.getTransStartTimestamp());
            dao.insertPiLotRcpGrp(piLotRcpGrp);

            piLotRcpGrp = piLotInqManager.getPiLotRcpGrpByRrn(piLotRcpGrp.getRcpGrpRrn());
            insertPiLotRcpGrpHistory(piLotRcpGrp, transactionLog);
        }

        @Override
        public void addRcpToGrp(PiLotRcpMaping piLotRcpMaping, TransactionLog transactionLog) {
            dao.insertPiLotRcpMapping(piLotRcpMaping);
            insertPiLotRcpMappingHistory(piLotRcpMaping, transactionLog);
        }

        @Override
        public void deleteRcpFromGrp(PiLotRcpMaping piLotRcpMaping, TransactionLog transactionLog) {
            insertPiLotRcpMappingHistory(piLotRcpMaping, transactionLog);
            dao.deletePiLotRcpMapping(piLotRcpMaping);
        }

        @Override
        public void completePiLotFlow(Long lotRrn) {
            TransactionLog transactionLog = transactionLogManager.startTransactionLog(LocalContext.getUserId(),
                                                                                      TransactionNames.PI_LOT_COMPLETE_FLOW);
            PiLotView view = piLotInqManager.getPiLotViewByLotRrn(lotRrn);
            view.setComplete(true);
            savePiLotView(view, transactionLog);
            createPilotFlowLotTransHistory(null, view);
        }

        @Override
        public void updatePiLotStatusBySplit(Lot lot, Lot childLot) {
            TransactionLog transactionLog = transactionLogManager.startTransactionLog(LocalContext.getUserId(),
                                                                                      TransactionNames.SPLIT_KEY);

            PiLotView view = piLotInqManager.getPiLotViewByLotRrn(lot.getLotRrn());
            PiLotSetup setup = piLotInqManager.getPiLotSetupByRrn(view.getPiLotRrn());

            view.setStatus(PiLotStatusEnum.WAITMERGE.toString());
            view.setCanSplit(false);
            view.setChildLotRrn(childLot.getLotRrn());
            view.setChildLotId(childLot.getLotId());
            savePiLotView(view, transactionLog);

            setup.setStatus(PiLotStatusEnum.WAITMERGE.toString());
            updatePiLotSetup(setup, transactionLog);
            createPilotFlowLotTransHistory(null, view);
        }

        @Override
        public void meregePiLot(Long basedLotRrn, TransactionLog transactionLog) {
            PiLotView view = piLotInqManager.getPiLotViewByLotRrn(basedLotRrn);
            view.setStatus(PiLotStatusEnum.CLOSE.toString());
            savePiLotView(view, transactionLog);

            PiLotSetup setup = piLotInqManager.getPiLotSetupByRrn(view.getPiLotRrn());
            setup.setStatus(PiLotStatusEnum.CREATED.toString());
            updatePiLotSetup(setup, transactionLog);
        }

        private void insertPiLotSetupRcpGrpHistory(PiLotSetup piLotSetup, RcpGrpType rcpGrp,
                                                   TransactionLog transactionLog) {
            RcpGrpTypeH rcpGrpTypeH = new RcpGrpTypeH();
            BeanUtils.copyProperties(rcpGrp, rcpGrpTypeH);
            rcpGrpTypeH.setTransRrn(transactionLog.getTransRrn());
            rcpGrpTypeH.setTransId(transactionLog.getTransId());
            rcpGrpTypeH.setTransTime(transactionLog.getTransStartTimestamp());
            rcpGrpTypeH.setTransUserRrn(LocalContext.getUserRrn());
            rcpGrpTypeH.setTransUserId(LocalContext.getUserId());
            dao.insertPiLotSetupRcpGrpHistory(rcpGrpTypeH, piLotSetup);
        }

        private void insertPiLotSetupCountHistory(PiLotSetup piLotSetup, CountType count, TransactionLog transactionLog) {
            CountTypeH countTypeH = new CountTypeH();
            BeanUtils.copyProperties(count, countTypeH);
            countTypeH.setTransRrn(transactionLog.getTransRrn());
            countTypeH.setTransId(transactionLog.getTransId());
            countTypeH.setTransTime(transactionLog.getTransStartTimestamp());
            countTypeH.setTransUserRrn(LocalContext.getUserRrn());
            countTypeH.setTransUserId(LocalContext.getUserId());
            dao.insertPiLotSetupCountHistory(countTypeH, piLotSetup);
        }

        private void insertPiLotSetupPMHistory(PiLotSetup piLotSetup, PmType pm, TransactionLog transactionLog) {
            PmTypeH pmTypeH = new PmTypeH();
            BeanUtils.copyProperties(pm, pmTypeH);
            pmTypeH.setTransRrn(transactionLog.getTransRrn());
            pmTypeH.setTransId(transactionLog.getTransId());
            pmTypeH.setTransTime(transactionLog.getTransStartTimestamp());
            pmTypeH.setTransUserRrn(LocalContext.getUserRrn());
            pmTypeH.setTransUserId(LocalContext.getUserId());
            dao.insertPiLotSetupPMHistory(pmTypeH, piLotSetup);
        }

        private void insertPiLotSetupIdleHistory(PiLotSetup piLotSetup, IdleType idle, TransactionLog transactionLog) {
            IdleTypeH idleTypeH = new IdleTypeH();
            BeanUtils.copyProperties(idle, idleTypeH);
            idleTypeH.setTransRrn(transactionLog.getTransRrn());
            idleTypeH.setTransId(transactionLog.getTransId());
            idleTypeH.setTransTime(transactionLog.getTransStartTimestamp());
            idleTypeH.setTransUserRrn(LocalContext.getUserRrn());
            idleTypeH.setTransUserId(LocalContext.getUserId());
            dao.insertPiLotSetupIdleHistory(idleTypeH, piLotSetup);
        }

        private void insertPiLotRcpMappingHistory(PiLotRcpMaping piLotRcpMaping, TransactionLog transactionLog) {
            PiLotRcpMapingH mapingH = new PiLotRcpMapingH();
            BeanUtils.copyProperties(piLotRcpMaping, mapingH);
            mapingH.setTransRrn(transactionLog.getTransRrn());
            mapingH.setTransId(transactionLog.getTransId());
            mapingH.setTransTime(transactionLog.getTransStartTimestamp());
            mapingH.setTransUserRrn(LocalContext.getUserRrn());
            mapingH.setTransUserId(LocalContext.getUserId());
            dao.insertPiLotRcpMappingH(mapingH);
        }

        private void insertPiLotRcpGrpHistory(PiLotRcpGrp piLotRcpGrp, TransactionLog transactionLog) {
            PiLotRcpGrpH rcpGrpH = new PiLotRcpGrpH();
            BeanUtils.copyProperties(piLotRcpGrp, rcpGrpH);
            rcpGrpH.setTransRrn(transactionLog.getTransRrn());
            rcpGrpH.setTransId(transactionLog.getTransId());
            rcpGrpH.setTransTime(transactionLog.getTransStartTimestamp());
            rcpGrpH.setTransUserRrn(LocalContext.getUserRrn());
            rcpGrpH.setTransUserId(LocalContext.getUserId());
            dao.insertPiLotRcpGrpH(rcpGrpH);
        }

        private void createPiLotView(PiLotSetup piLotSetup, TransactionLog transactionLog) {
            PiLotView piLotView = new PiLotView();
            BeanUtils.copyProperties(piLotSetup, piLotView);

            piLotView.setViewRrn(
                    Long.valueOf(IDGenerators.get(IDNames.SEQUENCE).generateId(SequenceNames.MODULE_SEQ_OBJECT_RRN)));
            piLotView.setViewId(generateViewId(piLotSetup));
            piLotView.setStatus(PiLotStatusEnum.ONGOING.toString());

            piLotView.setCreateUserRrn(LocalContext.getUserRrn());
            piLotView.setCreateTime(transactionLog.getTransStartTimestamp());
            piLotView.setUpdateUserRrn(LocalContext.getUserRrn());
            piLotView.setUpdateTime(transactionLog.getTransStartTimestamp());

            dao.insertPiLotView(piLotView);

            piLotView = piLotInqManager.getPiLotViewByRrn(piLotView.getViewRrn());
            insertPiLotViewHistory(piLotView, transactionLog);
        }

        private String generateViewId(PiLotSetup piLotSetup) {
            int count = piLotInqManager.getCountPiLotViewBySetupRrn(piLotSetup.getPiLotRrn());
            count++;
            return piLotSetup.getPiLotId() + "." + String.format("%04d", count);
        }

        private void insertPiLotViewHistory(PiLotView piLotView, TransactionLog transactionLog) {
            PiLotViewH piLotViewH = new PiLotViewH();
            BeanUtils.copyProperties(piLotView, piLotViewH);
            piLotViewH.setTransRrn(transactionLog.getTransRrn());
            piLotViewH.setTransId(transactionLog.getTransId());
            piLotViewH.setTransTime(transactionLog.getTransStartTimestamp());
            piLotViewH.setTransUserRrn(LocalContext.getUserRrn());
            piLotViewH.setTransUserId(LocalContext.getUserId());
            dao.insertPiLotViewH(piLotViewH);
        }

        private String initPiLotId(PiLotSetup piLotSetup) {
            StringBuilder piLotId = new StringBuilder("PILOT");
            piLotId.append(DateUtils.formatDate(new Date(), DateUtils.DATE_FORMAT4NOSPLICING));
            return piLotId.toString();
        }

        private void insertPiLotSetupHistory(PiLotSetup piLotSetup, TransactionLog transactionLog) {
            PiLotSetupH piLotSetupH = new PiLotSetupH();
            BeanUtils.copyProperties(piLotSetup, piLotSetupH);
            piLotSetupH.setTransRrn(transactionLog.getTransRrn());
            piLotSetupH.setTransId(transactionLog.getTransId());
            piLotSetupH.setTransTime(transactionLog.getTransStartTimestamp());
            piLotSetupH.setTransUserRrn(LocalContext.getUserRrn());
            piLotSetupH.setTransUserId(LocalContext.getUserId());
            dao.insertPiLotSetupHistory(piLotSetupH);
        }

        @Override
        public void setSingleLotFutureHold(PiLotView view, PiLotSetup oldSetup) {
            eenActionManager.setPilotSingleLotFutureHold(view, oldSetup);
        }

        @Override
        public void closeSingleLotPilot(Long basedLotRrn) {
            TransactionLog transactionLog =transactionLogManager.startTransactionLog(LocalContext.getUserId(),
                                                                                     TransactionNames.PI_LOT_COMPLETE_FLOW);
            PiLotView view = piLotInqManager.getPiLotViewByLotRrn(basedLotRrn);
            view.setStatus(PiLotStatusEnum.CLOSE.toString());
            savePiLotView(view, transactionLog);

            PiLotSetup setup = piLotInqManager.getPiLotSetupByRrn(view.getPiLotRrn());
            setup.setStatus(PiLotStatusEnum.CREATED.toString());
            updatePiLotSetup(setup, transactionLog);

            transactionLog.setTransId(TransactionNames.PI_LOT_END);
            String transComments = "Pilot End! (Single lot 量测结束) Pilot Number:" + view.getViewId() +"! Equipment ID: " + view.getEqptId() + "!";
            lotTransHistoryReqManager.createLotTransHistory(transactionLog, lotInqManager.getLot(view.getBoundLotRrn()), transComments);
            transactionLogManager.markTransactionLog(transactionLog);
        }

        @Override
        public void deletePilotSingleLotFutureHold(PiLotView view) {
            eenActionManager.deletePilotSingleLotFutureHold(view);
        }

        @Override
        public void handPilotByTime() {
            // 查询出所有idletime并且状态为CREATED的pilot
            List<PiLotSetup> pilotSetupIdles = piLotInqManager.getPilotSetupIdle();
            for (PiLotSetup piLotSetup : pilotSetupIdles) {
                Boolean needPiLot = false;
                Equipment equipment = equipmentManager.getEquipment(piLotSetup.getEqptRrn());
                //判断是否满足触发条件
                needPiLot = piLotCheckManager.checkNeedPilotByTime(piLotSetup, equipment, needPiLot);
                if (Boolean.TRUE.equals(needPiLot)) {
                    createPiLotView(piLotSetup);
                }
            }
        }

        @Override
        public void createPilotFlowLotTransHistory(PiLotSetup oldSetup, PiLotView view) {
            if (ObjectUtils.isEmpty(view)) {
                return;
            }
            TransactionLog transactionLog = transactionLogManager.startTransactionLog(LocalContext.getUserId(), StringUtils.EMPTY);

            switch (PiLotStatusEnum.valueOf(view.getStatus())) {
                case WAITSPLIT:
                case WAITCOMPLETE:
                    buildLotTransByWaitSplitOrWaitComplete(oldSetup, view, transactionLog);
                    break;
                case WAITMERGE:
                    buildLotTransByWaitMerge(view, transactionLog);
                    break;
                case CLOSE:
                    buildLotTransByClose(view, transactionLog);
                    break;
                default:
                    break;
            }

            transactionLogManager.markTransactionLog(transactionLog);
        }

        /**
         * 子母批Assign Lot时两种情况  和 单批Assign Lot和Retry
         * @param oldSetup
         * @param view
         * @param transactionLog
         */
        private void buildLotTransByWaitSplitOrWaitComplete(PiLotSetup oldSetup, PiLotView view, TransactionLog transactionLog) {
            String transComments = StringUtils.EMPTY;
            //不存在旧Assign lot 需将新lot记录PILOT_START
            transactionLog.setTransId(TransactionNames.PI_LOT_START);
            transComments = "Pilot Start! (Assign lot) Pilot Number:" + view.getViewId() +"! Equipment ID: " + view.getEqptId() + "!";
            lotTransHistoryReqManager.createLotTransHistory(transactionLog, lotInqManager.getLot(view.getBoundLotRrn()), transComments.toString());
            //存在旧Assign lot 需将旧lot记录PILOT_WITHDRAW
            if (StringUtils.isNotEmpty(oldSetup.getBoundLotId())) {
                transactionLog.setTransId(TransactionNames.PI_LOT_WITHDRAW);
                if (StringUtils.equalsIgnoreCase(view.getSingleLot(), PiLotStatusEnum.YES.toString())) {
                    transComments = "Pilot Withdraw! (单批Pilot Retry) Pilot Number:" + view.getViewId() +"! Equipment ID: " + view.getEqptId() + "!";
                }
                if (StringUtils.equalsIgnoreCase(view.getSingleLot(), PiLotStatusEnum.NO.toString())) {
                    transComments = "Pilot Withdraw! (Assign lot) Pilot Number:" + view.getViewId() +"! Equipment ID: " + view.getEqptId() + "!";
                }
                lotTransHistoryReqManager.createLotTransHistory(transactionLog, lotInqManager.getLot(oldSetup.getBoundLotRrn()), transComments);
            }
        }

        /**
         * 子母批分批、retry、子母量测结束
         * @param view
         * @param transactionLog
         */
        private void buildLotTransByWaitMerge(PiLotView view, TransactionLog transactionLog) {
            String transComments = StringUtils.EMPTY;
            // WaitMerge状态  retry、split都是子批记录历史 默认为为子批记录历史
            Lot childLot = lotInqManager.getLot(view.getChildLotRrn());
            Lot parentLot = lotInqManager.getLot(view.getBoundLotRrn());
            //判断是否可以进行分批  能分批为retry操作 不能分批为split操作或已经分批走流程
            if (view.getCanSplit()) {
                transactionLog.setTransId(TransactionNames.PI_LOT_WITHDRAW);
                transComments = "Pilot Withdraw!(子母批Pilot retry) Pilot Number:" + view.getViewId() +"! Equipment ID: " + view.getEqptId() + "!";
            } else {
                transactionLog.setTransId(TransactionNames.PI_LOT_START);
                transComments = "Pilot Start! (Pilot Split) Pilot Number:" + view.getViewId() +"! Equipment ID: " + view.getEqptId() + "!";
                // 子批走完流程量测结束
                if (view.getComplete()) {
                    transactionLog.setTransId(TransactionNames.PI_LOT_END);
                    transComments = "Pilot End! (Child lot 量测结束) Pilot Number:" + view.getViewId() +"! Equipment ID: " + view.getEqptId() + "!";
                    //子批走完流程 母批也走完流程量测结束
                    if (StringUtils.equalsIgnoreCase(childLot.getFlowSeq(), parentLot.getFlowSeq())) {
                        childLot = parentLot;
                        transComments = "Pilot End! (Parent lot 量测结束) Pilot Number:" + view.getViewId() +"! Equipment ID: " + view.getEqptId() + "!";
                    }
                }
            }
            lotTransHistoryReqManager.createLotTransHistory(transactionLog, childLot, transComments);
        }

        /**
         * 手动close
         * @param view
         * @param transactionLog
         */
        private void buildLotTransByClose(PiLotView view, TransactionLog transactionLog) {

           String transComments = StringUtils.EMPTY;
           transactionLog.setTransId(TransactionNames.PI_LOT_END);
           transComments = "Pilot End!(Special Close) Pilot Number:" + view.getViewId() +"! Equipment ID: " + view.getEqptId() + "!";
           if (StringUtils.isNotEmpty(view.getBoundLotId())) {
               lotTransHistoryReqManager.createLotTransHistory(transactionLog, lotInqManager.getLot(view.getBoundLotRrn()), transComments);
           }

           // 存在子批也需要 记录end lot trans
           if (StringUtils.isNotEmpty(view.getChildLotId())) {
               lotTransHistoryReqManager.createLotTransHistory(transactionLog, lotInqManager.getLot(view.getChildLotRrn()), transComments);
           }
        }

    }