<?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.hzs.system.config.mapper.BdVertexMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.vertex.BdVertex">
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="PK_ID" property="pkId"/>
        <result column="PK_MEMBER" property="pkMember"/>
        <result column="VERTEX_NAME" property="vertexName"/>
    </resultMap>
    <update id="updateBdVertexById">
        update cu_member set pk_vertex =#{pkVertex} where pk_id in(
            SELECT  pk_id
            FROM  cu_member  t
            WHERE  t.del_flag  =  0
        START  WITH  t.pk_id = #{pkMember}
        CONNECT  BY  PRIOR  t.pk_id  =  t.pk_parent)
    </update>
    <update id="updateBdVertexNullById">
        update cu_member set pk_vertex = null where pk_vertex = #{pkVertex}
    </update>

    <select id="selectByList" resultType="com.hzs.system.config.vo.VertexVo">
        select bv.*,cm.MEMBER_CODE memberCode from BD_VERTEX bv
        left join CU_MEMBER cm on cm.PK_ID = bv.PK_MEMBER
        where 1 = 1 and bv.DEL_FLAG = '0'
        <if test="createStartDate != null">
            and bv.CREATION_TIME &gt;= #{createStartDate}
        </if>
        <if test="createEndDate != null">
            and bv.CREATION_TIME &lt;= #{createEndDate}
        </if>
        <if test="pkCountry != null">
            and bv.PK_COUNTRY = #{pkCountry}
        </if>
        <if test="vertexName != null and vertexName !=''">
            and bv.VERTEX_NAME like #{vertexName} || '%'
        </if>
        <if test="memberCode != null and memberCode !=''">
            and cm.MEMBER_CODE like #{memberCode} || '%'
        </if>
    </select>

    <!-- 根据管理员ID查询体系列表 -->
    <select id="queryListByUserId" resultMap="BaseResultMap">
        select bv.pk_id, bv.vertex_name
        from sys_user_vertex suv
                 left join BD_VERTEX bv
                           on bv.pk_id = suv.pk_vertex
                               and bv.del_flag = 0
        where suv.user_id = #{userId}
        order by bv.creation_time
    </select>

</mapper>
