package com.qmth.distributed.print.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qmth.distributed.print.business.bean.dto.approvalForm.ApprovalInfo;
import com.qmth.distributed.print.business.bean.result.TFFlowLogResult;
import com.qmth.distributed.print.business.entity.TFFlowLog;
import com.qmth.distributed.print.business.mapper.TFFlowLogMapper;
import com.qmth.distributed.print.business.service.TFFlowLogService;
import com.qmth.teachcloud.common.enums.FlowApproveOperationEnum;
import com.qmth.teachcloud.common.service.SysOrgService;
import com.qmth.teachcloud.common.service.SysUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 流程流水表 服务实现类
 * </p>
 *
 * @author wangliang
 * @since 2021-08-02
 */
@Service
public class TFFlowLogServiceImpl extends ServiceImpl<TFFlowLogMapper, TFFlowLog> implements TFFlowLogService {

    @Resource
    TFFlowLogMapper tfFlowLogMapper;
    @Resource
    SysUserService sysUserService;
    @Resource
    SysOrgService sysOrgService;

    /**
     * 根据流程id查询流程状态
     *
     * @param flowId
     * @param schoolId
     * @return
     */
    @Override
    public List<TFFlowLog> findByFlowId(Long flowId, Long schoolId) {
        return tfFlowLogMapper.findByFlowId(flowId, schoolId);
    }

    /**
     * 根据实体id查询
     *
     * @param objectId
     * @return
     */
    @Override
    public List<TFFlowLogResult> findByObjectId(Long objectId) {
        return tfFlowLogMapper.findByObjectId(objectId);
    }

    /**
     * 查找最后一条审批记录
     *
     * @param flowId
     * @param schoolId
     * @param flowApproveOperationEnum
     * @return
     */
    @Override
    public TFFlowLog findByLast(Long flowId, Long schoolId, FlowApproveOperationEnum flowApproveOperationEnum) {
        return tfFlowLogMapper.findByLast(flowId, schoolId, Objects.nonNull(flowApproveOperationEnum) ? flowApproveOperationEnum.name() : null);
    }

    @Override
    public List<ApprovalInfo> findApprovalInfoByFlowId(Long flowId) {
        return this.baseMapper.findApprovalInfoByFlowId(flowId);
    }
}
