# AutoMonitorProcessSwitchTaskManagerImpl.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.exception.SystemIllegalArgumentException;
    import com.fa.sesa.i18n.I18nUtils;
    import com.fa.sesa.threadlocal.LocalContext;
    import com.mycim.framework.utils.lang.BooleanUtils;
    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.math.NumberUtils;
    import com.mycim.server.automonitor.manager.job.task.AutoMonitorProcessSwitchTaskManager;
    import com.mycim.server.base.manager.NamedObjectManager;
    import com.mycim.server.carrier.manager.CarrierManager;
    import com.mycim.server.carrier.manager.PcdManager;
    import com.mycim.server.ctx.exec.manager.BORContextValueManager;
    import com.mycim.server.ctx.exec.manager.ChangeFlowContextValueManager;
    import com.mycim.server.ctx.exec.manager.RecipeContextManager;
    import com.mycim.server.ctx.exec.manager.ReworkRouteContextValueManager;
    import com.mycim.server.npw.manager.EqpMonitorLotManager;
    import com.mycim.server.prp.manager.OperationManager;
    import com.mycim.server.prp.manager.ProductManager;
    import com.mycim.server.prp.manager.WorkflowManager;
    import com.mycim.server.rcp.manager.RecipeManager;
    import com.mycim.server.rcp.manager.RecipeVersionManager;
    import com.mycim.server.security.manager.UserManager;
    import com.mycim.server.status.manager.StatusManager;
    import com.mycim.server.system.manager.ReferenceFileManager;
    import com.mycim.server.wip.manager.*;
    import com.mycim.server.wip.manager.job.TimeLimitCheckManager;
    import com.mycim.utils.WipUtils;
    import com.mycim.valueobject.MessageIdList;
    import com.mycim.valueobject.SystemConstant;
    import com.mycim.valueobject.alm.EenAction;
    import com.mycim.valueobject.automonitor.entity.LotAutoMonitorInfo;
    import com.mycim.valueobject.automonitor.util.AutoMonitorOperationConstants;
    import com.mycim.valueobject.automonitor.util.MonitorJobStatusConts;
    import com.mycim.valueobject.consts.*;
    import com.mycim.valueobject.edcspc.EdcRuleCheckResult;
    import com.mycim.valueobject.prp.ContextValue;
    import com.mycim.valueobject.prp.EqpMonitorLotBeforeInfo;
    import com.mycim.valueobject.prp.Operation;
    import com.mycim.valueobject.prp.ReworkRouteContextValue;
    import com.mycim.valueobject.wip.*;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.util.*;
    import java.util.stream.Collectors;

    @Service
    @Transactional
    public class AutoMonitorProcessSwitchTaskManagerImpl implements AutoMonitorProcessSwitchTaskManager {

        @Autowired
        private LotQueryManager lotQueryManager;

        @Autowired
        private ProcessSwitchSpecialManager processSwitchSpecialManager;

        @Override
        public Map doExecute(Map parameters) {

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

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

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

            processSwitchSpecialManager.moveNext(jobRrn, null, parameters);

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

            return parameters;
        }

    }