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.TFCustomFlow;
import com.qmth.sop.business.mapper.TFCustomFlowMapper;
import com.qmth.sop.business.service.TFCustomFlowService;
import com.qmth.sop.common.enums.TFCustomTypeEnum;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 自定义流程表 服务实现类
 * </p>
 *
 * @author wangliang
 * @since 2023-07-17
 */
@Service
public class TFCustomFlowServiceImpl extends ServiceImpl<TFCustomFlowMapper, TFCustomFlow> implements TFCustomFlowService {

    /**
     * 查询版本号
     *
     * @param orgId
     * @param flowName
     * @param type
     * @return
     */
    @Override
    public TFCustomFlow findMaxVersion(Long orgId, String flowName, TFCustomTypeEnum type) {
        return this.baseMapper.findMaxVersion(orgId, flowName, Objects.nonNull(type) ? type.name() : null);
    }

    /**
     * 查询流程部署信息
     *
     * @return
     */
    @Override
    public List<TFCustomFlow> findFlowDeploymentList() {
        return this.baseMapper.findFlowDeploymentList();
    }

    /**
     * 获取流程版本信息
     *
     * @param type
     * @return
     */
    @Override
    public List<TFCustomFlow> findFlowVersion(TFCustomTypeEnum type) {
        return this.list(new QueryWrapper<TFCustomFlow>().lambda().eq(TFCustomFlow::getType, type).orderByDesc(TFCustomFlow::getVersion));
    }
}
