# CheckListManagerImpl.java

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

    import com.mycim.server.base.manager.NamedObjectManager;
    import com.mycim.server.base.manager.TransactionLogManager;
    import com.mycim.server.pms.dao.CheckListDao;
    import com.mycim.server.pms.manager.CheckListManager;
    import com.mycim.valueobject.bas.NamedObject;
    import com.mycim.valueobject.bas.TransactionLog;
    import com.mycim.valueobject.consts.TransactionNames;
    import com.mycim.valueobject.ems.Checklist;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    /**
     * CheckList ManagerImpl
     *
     * @author pinyan.song
     * @version 6.0.0
     * @date 2019-11-5
     **/
    @Service
    @Transactional
    public class CheckListManagerImpl implements CheckListManager {

        @Autowired
        CheckListDao checkListDao;

        @Autowired
        NamedObjectManager namedObjectManager;

        @Autowired
        TransactionLogManager transactionLogManager;

        @Override
        public Checklist getCheckList(Checklist checkList) {
            NamedObject namedObject = namedObjectManager.getNamedObject(checkList);

            if (namedObject == null) {
                return null;
            }
            checkList.copyNamedObject(namedObject);
            checkList = checkListDao.getChecklist(checkList);
            checkList.setStartEventId(namedObjectManager.getInstanceId(checkList.getStartEventRrn()));
            checkList.setEndEventId(namedObjectManager.getInstanceId(checkList.getEndEventRrn()));
            return checkList;
        }

        @Override
        public long insertChecklist(Checklist checkList) {
            long instanceRrn = 0;
            TransactionLog transactionLog = transactionLogManager
                    .startTransactionLog(checkList.getTransPerformedby(), TransactionNames.CREATE_KEY);
            instanceRrn = namedObjectManager.insertNamedObject(checkList, transactionLog.getTransRrn());
            checkList.setInstanceRrn(instanceRrn);
            checkListDao.insertCheckList(checkList);
            checkListDao.insertCheckListHis(instanceRrn, transactionLog);
            transactionLogManager.markTransactionLog(transactionLog);

            return instanceRrn;
        }

        @Override
        public void deleteChecklist(Checklist checkList) {
            TransactionLog transactionLog = transactionLogManager
                    .startTransactionLog(checkList.getTransPerformedby(), TransactionNames.DELETE_KEY);
            namedObjectManager.deleteNamedObject(checkList, transactionLog.getTransRrn());
            checkListDao.insertCheckListHis(checkList.getInstanceRrn(), transactionLog);
            checkListDao.deleteCheckList(checkList);
            transactionLogManager.markTransactionLog(transactionLog);
        }

        @Override
        public void updateChecklist(Checklist checkList) {
            TransactionLog transactionLog = transactionLogManager
                    .startTransactionLog(checkList.getTransPerformedby(), TransactionNames.MODIFY_KEY);
            namedObjectManager.updateNamedObject(checkList, transactionLog.getTransRrn());
            checkListDao.updateCheckList(checkList);
            checkListDao.insertCheckListHis(checkList.getInstanceRrn(), transactionLog);
            transactionLogManager.markTransactionLog(transactionLog);
        }

    }