<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fuyuanshen.equipment.mapper.DeviceGroupMapper">

    <!-- 查询顶级分组 -->
    <select id="selectRootGroups" resultType="DeviceGroup">
        SELECT * FROM device_group
        WHERE parent_id IS NULL
        <if test="bo.groupName != null and bo.groupName != ''">
            AND group_name LIKE CONCAT('%', #{bo.groupName}, '%')
        </if>
        <if test="bo.status != null">
            AND status = #{bo.status}
        </if>
        ORDER BY create_time DESC
    </select>

    <!-- 根据父ID查询子分组 -->
    <select id="selectByParentId" resultType="DeviceGroup">
        SELECT *
        FROM device_group
        WHERE parent_id = #{parentId}
        ORDER BY create_time DESC
    </select>

</mapper>
