package org.jeecg.modules.workFlow.flowplus.workflow.mapper;

import org.jeecg.modules.workFlow.flowplus.workflow.dto.TemplateGroupDto;
import org.jeecg.modules.workFlow.flowplus.workflow.entity.WflowTemplateGroup;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 流程模版分组关联 Mapper
 *

 */
//@Mapper
public interface WflowTemplateGroupMapper extends BaseMapper<WflowTemplateGroup> {

    /**
     * 查询所有模版及分组 分组内没有元素不显示分组
     */
//    @Select("SELECT fg.group_id, tg.id, fg.group_name, pt.template_id, pt.template_key, pt.template_version, pt.remark, pt.status, pt.update_time, pt.template_name, " +
//            "pt.logo FROM wflow_process_templates pt LEFT JOIN wflow_template_group tg ON pt.template_id = tg.template_id " +
//            "RIGHT JOIN wflow_process_groups fg ON tg.group_id = fg.group_id " +
//            "WHERE (pt.template_key, pt.template_version) in (select template_key, MAX(template_version) from wflow_process_templates group by template_key)" +
//            "ORDER BY fg.sort_num ASC, tg.sort_num ASC")
//    List<TemplateGroupDto> getAllFormAndGroups();

    /**
     * 查询所有模版及分组 分组没有元素也显示分组
     */
    @Select("SELECT fg.group_id, tg.id, fg.group_name, pt.template_id, pt.template_key, pt.template_version, pt.remark, pt.status, pt.update_time, pt.template_name, " +
            "pt.logo FROM wflow_process_groups fg " +
            "LEFT JOIN wflow_template_group tg ON fg.group_id = tg.group_id " +
            "LEFT JOIN wflow_process_templates pt ON tg.template_id = pt.template_id AND (pt.template_key, pt.template_version) IN (SELECT template_key, MAX(template_version) FROM wflow_process_templates GROUP BY template_key) " +
            "ORDER BY fg.sort_num ASC, tg.sort_num ASC")
    List<TemplateGroupDto> getAllFormAndGroups();
}
