<?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.vctgo.system.mapper.SysReGardenBranchMapper">

    <resultMap type="com.vctgo.system.domain.SysReGardenBranch" id="SysReGardenBranchResult">
        <result property="id"    column="id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="deptType"    column="dept_type"    />
        <result property="isDeleted"    column="is_deleted"    />
        <result property="createById"    column="create_by_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateById"    column="update_by_id"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectSysReGardenBranchVo">
        select id, parent_id, dept_type, is_deleted, create_by_id, create_by, create_time, update_by_id, update_by, update_time from sys_re_garden_branch
    </sql>

    <sql id="selectAssociationGardenBranchVo">
        select li.id, li.parent_id, li.dept_type, li.is_deleted,
               li.create_by_id, li.create_by, li.create_time,
               li.update_by_id, li.update_by, li.update_time, t.tenant_name tenantName
        from
            (select id, parent_id, dept_type, is_deleted, create_by_id, create_by,
                    create_time, update_by_id, update_by, update_time
             from sys_re_garden_branch
             where id = #{query.id} and is_deleted=0
        <if test="query.deptType != null "> and dept_type = #{query.deptType}</if>
        <if test="query.isDeleted != null  and query.isDeleted != ''"> and is_deleted = #{query.isDeleted}</if>
             union
             select id, parent_id, dept_type, is_deleted, create_by_id, create_by,
                    create_time, update_by_id, update_by, update_time
             from sys_re_garden_branch
             where parent_id = #{query.id} and is_deleted=0
        <if test="query.deptType != null "> and dept_type = #{query.deptType}</if>
        <if test="query.isDeleted != null  and query.isDeleted != ''"> and is_deleted = #{query.isDeleted}</if>
             ) li
        inner join sys_tenant t on t.id= li.id
        where t.del_flag=0
    </sql>

    <sql id="defaultDeleteCondition">
        is_deleted = 0
    </sql>

    <select id="selectSysReGardenBranchList"   resultMap="SysReGardenBranchResult">
        <include refid="selectAssociationGardenBranchVo"/>
    </select>

    <update id="logicalDeleteSysReGardenBranchByIds" parameterType="String">
        update sys_re_garden_branch set is_deleted = #{query.isDeleted},
        update_by_id = #{query.updateById}, update_by = #{query.updateBy},
        update_time = #{query.updateTime} where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteSysReGardenBranchByIds" parameterType="String">
        delete from sys_re_garden_branch where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
