package com.qmth.sop.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qmth.sop.business.entity.TFFlowApprove;
import com.qmth.sop.business.mapper.TFFlowApproveMapper;
import com.qmth.sop.business.service.TFFlowApproveService;
import com.qmth.sop.common.enums.ExceptionResultEnum;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * <p>
 * 流程审核表 服务实现类
 * </p>
 *
 * @author wangliang
 * @since 2023-07-17
 */
@Service
public class TFFlowApproveServiceImpl extends ServiceImpl<TFFlowApproveMapper, TFFlowApprove>
        implements TFFlowApproveService {

    /**
     * 根据crmNo查询flowId
     *
     * @param crmNo
     * @return
     */
    @Override
    public List<Long> findFlowIdByCrmNo(String crmNo) {
        return this.baseMapper.findFlowIdByCrmNo(crmNo);
    }

    /**
     * 根据crmNo查找sop在途的流程数
     *
     * @param crmNo
     * @return
     */
    @Override
    public int findFlowPassageSopByCrmNo(String crmNo) {
        return this.baseMapper.findFlowPassageSopByCrmNo(crmNo);
    }

    /**
     * 根据流程id查询数据
     *
     * @param flowId
     * @return
     */
    @Override
    public TFFlowApprove findByFlowId(Long flowId) {
        TFFlowApprove tfFlowApprove = this.getOne(
                new QueryWrapper<TFFlowApprove>().lambda().eq(TFFlowApprove::getFlowId, flowId));
        Optional.ofNullable(tfFlowApprove).orElseThrow(() -> ExceptionResultEnum.FLOW_APPROVE_NO_DATA.exception());
        return tfFlowApprove;
    }
}
