# AutoMonitorMoveOutTaskManagerImpl.java

    package com.mycim.server.automonitor.manager.impl.job.task;

    import com.fa.sesa.exception.Assert;
    import com.fa.sesa.exception.Errors;
    import com.fa.sesa.threadlocal.LocalContext;
    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.framework.utils.lang.time.DateUtils;
    import com.mycim.server.automonitor.manager.job.task.AutoMonitorMoveInTaskManager;
    import com.mycim.server.base.manager.NamedObjectManager;
    import com.mycim.server.prp.manager.OperationManager;
    import com.mycim.server.rcp.manager.RecipeManager;
    import com.mycim.server.rcp.manager.RecipeVersionManager;
    import com.mycim.server.wip.manager.*;
    import com.mycim.utils.EmasUtil;
    import com.mycim.valueobject.ObjectList;
    import com.mycim.valueobject.SystemConstant;
    import com.mycim.valueobject.consts.SessionNames;
    import com.mycim.valueobject.consts.TransactionNames;
    import com.mycim.valueobject.prp.Operation;
    import com.mycim.valueobject.wip.*;
    import com.mycim.valueobject.wip.dto.LotInfoDto;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.sql.Timestamp;
    import java.util.*;

    @Service
    @Transactional
    public class AutoMonitorMoveOutTaskManagerImpl implements AutoMonitorMoveInTaskManager {

        @Autowired
        private JobQueryManager jobQueryManager;

        @Autowired
        private LotQueryManager lotQueryManager;

        @Autowired
        private OperationManager operationManager;

        @Autowired
        private JobManager jobManager;

        @Autowired
        private LotManager lotManager;

        @Autowired
        private EquipmentRunHistoryReqManager equipmentRunHistoryReqManager;

        public static boolean isCanDoTrackOutStatus(String lotStatus) {
            return LotStatus.isRunning(lotStatus) || LotStatus.isProcessed(lotStatus);
        }

        @Override
        public Map doExecute(Map parameters) {

            if (MapUtils.getBooleanValue(parameters, SystemConstant.Str.PAUSE_FLAG)) {
                return null;
            }

            long facilityRrn = MapUtils.getLongValue(parameters, "facilityRrn");
            long jobRrn = MapUtils.getLongValue(parameters, "jobRrn");

            Assert.state(jobRrn > 0, Errors.create().content("Parameters are not enough!").build());

            Job job = jobQueryManager.getJob(jobRrn);

            List<Lot> lotList = (List<Lot>) MapUtils.getObject(parameters, "lotList");
            Assert.state(CollectionUtils.isNotEmpty(lotList), Errors.create().content("Invalid lot size!").build());

            String[] moveOutQtyArray = new String[lotList.size()];
            int index = 0;
            for (Iterator iterator = lotList.iterator(); iterator.hasNext(); ) {
                Lot lot = (Lot) iterator.next();
                moveOutQtyArray[index] = String.valueOf(lot.getQty1());
                index++;
            }
            parameters.put("moveOutQty", moveOutQtyArray);

            moveOut(job, lotList, parameters);

            parameters.put(SessionNames.RUNSTEP_FLAG, "0");
            return parameters;
        }

        public void moveOut(Job job, List<Lot> lotList, Map parameters) {
            List<LotInfoDto> lotInfoDtos = (List<LotInfoDto>) MapUtils.getObject(parameters, "transData");
            Assert.state(CollectionUtils.isNotEmpty(lotInfoDtos),
                         Errors.create().content("Parameters are not enough!").build());
            LotInfoDto lotInfoDto = lotInfoDtos.iterator().next();

            jobManager.moveOutForSpecial(job,lotList);
        }

    }