package com.jeethink.save.service.impl;

import java.util.List;

import com.jeethink.common.constant.Constants;
import com.jeethink.common.exception.CustomException;
import com.jeethink.flow.service.IFlowService;
import com.jeethink.receive.mapper.ArchivesMapper;
import com.jeethink.receive.service.IArchivesService;
import com.jeethink.receive.vo.ArchivesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.jeethink.bean.domain.ArchivesMaster;
import com.jeethink.save.service.IPutinService;

/**
 * 档案入库Service业务层处理
 * 
 * @author sh
 * @date 2022-11-11
 */
@Service
public class PutinServiceImpl implements IPutinService
{
    @Autowired
    private IArchivesService archivesService;
    @Autowired
    private IFlowService flowService;

    @Override
    public List<ArchivesMaster> selectPutinList(ArchivesMaster archives) {

        archives.setNowStatus(Constants.ARCHIVES_STATUS_RECEIVE_WAIT);
        return archivesService.selectArchivesList(archives);
    }

    @Override
    public void confirmPutin(String archivesId) {

        ArchivesMaster archives = archivesService.selectById(archivesId);
        if (!Constants.ARCHIVES_STATUS_RECEIVE_WAIT.equals(archives.getNowStatus())) {
            throw new CustomException("该档案当前状态不能入库");
        }
        archivesService.changeNowStatus(archivesId, Constants.ARCHIVES_STATUS_RK);
        flowService.finishFlow(archivesId, Constants.FLOW_TYPE_RECEIVE);
    }

    @Override
    public ArchivesVO selectArchivesById(String archivesId) {

        return archivesService.selectArchivesById(archivesId);
    }
}
