# AutoMonitorItemReqManagerImpl.java

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

    import com.mycim.framework.utils.lang.StringUtils;
    import com.mycim.server.automonitor.dao.AutoMonitorItemReqDao;
    import com.mycim.server.automonitor.manager.AutoMonitorItemReqManager;
    import com.mycim.valueobject.automonitor.entity.AutoMonitorItem;
    import com.mycim.valueobject.automonitor.entity.AutoMonitorItemStep;
    import com.mycim.valueobject.automonitor.entity.AutoMonitorItemStepEdcInfo;
    import com.mycim.valueobject.automonitor.util.AutoMonitorOperationConstants;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.util.ArrayList;
    import java.util.List;

    /**
     * @author finatice.yang
     * @date 2021/9/2
     **/
    @Service
    @Transactional
    public class AutoMonitorItemReqManagerImpl implements AutoMonitorItemReqManager {

        @Autowired
        AutoMonitorItemReqDao itemDao;

        @Override
        public void insertAutoMonitorItem(AutoMonitorItem autoMonitorItem) {
            itemDao.insertAutoMonitorItem(autoMonitorItem);
        }

        @Override
        public void updateAutoMonitorItem(AutoMonitorItem autoMonitorItem) {
            itemDao.updateAutoMonitorItem(autoMonitorItem);
        }

        @Override
        public void deleteAutoMonitorItem(AutoMonitorItem autoMonitorItem) {
            itemDao.deleteAutoMonitorItem(autoMonitorItem);
        }

        @Override
        public void updateAutoMonitorItemSteps(Long workflowRrn, Integer workflowVersion,
                                               List<AutoMonitorItemStep> stepList) {
            deleteAutoMonitorItemSteps(workflowRrn, workflowVersion);

            List<AutoMonitorItemStepEdcInfo> edcInfoList = new ArrayList<>();
            for (AutoMonitorItemStep step : stepList) {
                step.setWorkflowRrn(workflowRrn);
                step.setWorkflowVersion(workflowVersion);

                if (StringUtils.equals(AutoMonitorOperationConstants.STEP_SLOT_TYPE_LOT, step.getNonRTSlotType())) {
                    AutoMonitorItemStepEdcInfo edcInfo = new AutoMonitorItemStepEdcInfo();
                    edcInfo.setWorkflowRrn(workflowRrn);
                    edcInfo.setWorkflowVersion(workflowVersion);
                    edcInfo.setWaferSlot(new Long(1));
                    edcInfo.setStepSequence(step.getStepSequence());
                    edcInfo.setNonRTJobIds(step.getNonRTJobIds());
                    edcInfo.setNonRTJobNames(step.getNonRTJobNames());
                    edcInfoList.add(edcInfo);
                } else if (StringUtils
                        .equals(AutoMonitorOperationConstants.STEP_SLOT_TYPE_WAFER, step.getNonRTSlotType())) {
                    for (int i = 0; i < step.getWaferNonRTJobIds().size(); i++) {
                        AutoMonitorItemStepEdcInfo edcInfo = new AutoMonitorItemStepEdcInfo();
                        edcInfo.setWorkflowRrn(workflowRrn);
                        edcInfo.setWorkflowVersion(workflowVersion);
                        edcInfo.setStepSequence(step.getStepSequence());
                        edcInfo.setWaferSlot(new Long(i + 1));
                        edcInfo.setNonRTJobIds(step.getWaferNonRTJobIds().get(i));
                        edcInfo.setNonRTJobNames(step.getWaferNonRTJobNames().get(i));
                        edcInfoList.add(edcInfo);
                    }
                }
            }
            itemDao.insertAutoMonitorItemSteps(stepList);
            if (edcInfoList.size() > 0) {
                itemDao.insertItemStepEdcInfo(edcInfoList);
            }
        }

        @Override
        public void deleteAutoMonitorItemSteps(Long workflowRrn, Integer workflowVersion) {
            itemDao.deleteAutoMonitorItemSteps(workflowRrn, workflowVersion);
            itemDao.deleteItemStepEdcInfo(workflowRrn, workflowVersion);
        }

        @Override
        public void updateAutoMonitorItemSysInActiveFlag(Long workflowRrn, Boolean sysInActiveFlag) {
            itemDao.updateAutoMonitorItemSysInActiveFlag(workflowRrn, sysInActiveFlag);
        }

    }