package com.fastbee.ggroup.mapper;


import com.fastbee.ggroup.domain.GGroups;
import com.fastbee.ggroup.domain.vo.GGroupSiteVo;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 组Mapper接口
 *
 * @author kerwincui
 * &#064;date  2024-09-27
 */
@Mapper
public interface GGroupsMapper extends MPJBaseMapper<GGroups>
{
    /**
     * 查询组
     *
     * @param id 组主键
     * @return 组
     */
    GGroups selectGGroupsById(Long id);

    /**
     * 查询组列表
     *
     * @param gGroups 组
     * @return 组集合
     */
    List<GGroups> selectGGroupsList(GGroups gGroups);


    @Select({
            "<script>",
            "select gsg.id, gsg.parent_id as parent_id, gg.name as parent_name, gsg.site_id as siteId," +
                    "gs.name as name, gs.icon, gs.type, gs.space,gs.space_value",
            "from g_site_groups gsg",
            "left join g_groups gg on gsg.parent_id = gg.id",
            "left join g_sites gs on gsg.site_id = gs.id",
            "where 1=1",
            "<if test='projectId != null'>",
            "and gsg.project_id = #{projectId}",
            "</if>",
            "<if test='parentId != null'>",
            "and gsg.parent_id = #{parentId}",
            "</if>",
            "<if test='searchValue != null'>",
            "and gs.name like CONCAT('%', #{searchValue}, '%')",  // 使用 CONCAT 将 % 和参数拼接
            "</if>",
            "</script>"
    })
    List<GGroupSiteVo> selectGGroupsSiteList(GGroups gGroups);


    /**
     * 新增组
     *
     * @param gGroups 组
     * @return 结果
     */
    int insertGGroups(GGroups gGroups);

    /**
     * 修改组
     *
     * @param gGroups 组
     * @return 结果
     */
    int updateGGroups(GGroups gGroups);

    /**
     * 删除组
     *
     * @param id 组主键
     * @return 结果
     */
    int deleteGGroupsById(Long id);

    /**
     * 批量删除组
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    int deleteGGroupsByIds(Long[] ids);
}
