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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.jeethink.bean.domain.ArchivesMaster;
import com.jeethink.save.service.IPutoutService;

/**
 * 档案出库Service业务层处理
 * 
 * @author sh
 * @date 2022-11-11
 */
@Service
public class PutoutServiceImpl implements IPutoutService
{
    @Autowired
    private ArchivesMapper archivesMapper;

    @Autowired
    private IFlowService flowService;

    /**
     * 查询档案出库列表
     *
     * @param archives 档案出库
     * @return 档案出库集合
     */
    @Override
    public List<ArchivesMaster> selectPutoutList(ArchivesMaster archives) {

        archives.setNowStatus(Constants.ARCHIVES_STATUS_DESTROY_WAIT);
        return archivesMapper.selectArchivesList(archives);
    }

    /**
     * 确认出库
     *
     * @param archivesId
     */
    @Override
    public void confirmPutout(String archivesId) {

        ArchivesMaster archives = archivesMapper.selectById(archivesId);
        if (!Constants.ARCHIVES_STATUS_DESTROY_WAIT.equals(archives.getNowStatus())) {
            throw new CustomException("该档案当前状态不能出库");
        }
        archivesMapper.changeNowStatus(archivesId, Constants.ARCHIVES_STATUS_DESTROY);
        flowService.finishFlow(archivesId, Constants.FLOW_TYPE_DESTROY);
    }
}
