<?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.member.base.mapper.CuMemberRetailDetailMapper">

    <select id="getChildList" resultType="com.hzs.member.structure.controller.vo.ChildCodeVO">
        SELECT
        cud.CHILD_NODE
        FROM
        CU_MEMBER cu LEFT JOIN
        ${ settleTableName } cud ON cu.PK_ID = cud.PK_MEMBER
        WHERE
        cu.MEMBER_CODE = #{ memberCode }
        AND cud.STAGE = #{ stage }
        <if test="stageStatus != null">
            and cud.STAGE_STATUS = #{stageStatus}
        </if>
        ORDER BY CHILD_NODE ASC
    </select>

    <select id="getFindCumemberRetailDetail" resultType="java.lang.Integer">
        select 1
        from user_tables
        where table_name = upper(#{settleTableName})
    </select>
    <select id="getCuMemberRetailDetailByUserId"
            resultType="com.hzs.common.domain.member.achieve.CuMemberRetailDetail">
        SELECT
        cud.*
        FROM
        ${ settleTableName } cud
        WHERE
        cud.PK_MEMBER = #{userId}
        AND CHILD_NODE = #{childNode}
        AND STAGE = #{stage}
        <if test="stageStatus != null">
            and cud.STAGE_STATUS = #{stageStatus}
        </if>
    </select>
    <select id="getChildListByUserId" resultType="com.hzs.member.structure.controller.vo.ChildCodeVO">
        SELECT
        cud.CHILD_NODE
        FROM
        ${ settleTableName } cud
        WHERE
        cud.PK_MEMBER = #{ userId }
        AND cud.STAGE = #{ stage }
        <if test="stageStatus != null">
            and cud.STAGE_STATUS = #{stageStatus}
        </if>
        ORDER BY CHILD_NODE ASC
    </select>
    <select id="getCuMemberRetailDetailDTOList"
            resultType="com.hzs.member.structure.controller.vo.CuMemberThreeFrameworkVO">
        SELECT
        curd.*
        FROM
        ${settleTableName} curd
        LEFT JOIN CU_MEMBER cu ON curd.PK_MEMBER = cu.PK_ID
        WHERE
        cu.MEMBER_CODE = #{memberCode}
        AND curd.STAGE = #{stage}
        <if test="stageStatus != null">
            and curd.STAGE_STATUS = #{stageStatus}
        </if>
        ORDER BY
        curd.STAGE_SORT
    </select>
    <select id="getPointDetailByUserId"
            resultType="com.hzs.member.structure.controller.dto.CuMemberPointDTO">
        SELECT cur.CREATION_TIME
        FROM ${settleTableName} cur
        WHERE cur.PK_MEMBER = #{ userId }
          AND cur.CHILD_NODE = #{ point }
          AND cur.STAGE = #{stage}
    </select>
    <select id="getPointDetailListByPoints"
            resultType="com.hzs.member.structure.controller.dto.CuMemberPointDTO">
        SELECT
        cur.PK_MEMBER,
        cur.STAGE_SORT,
        cur.CHILD_NODE,
        cur.CREATION_TIME,
        cur.STAGE
        FROM
        ${settleTableName} cur
        WHERE
        <foreach collection="pairList" item="pair" separator=" OR ">
            (cur.PK_MEMBER = #{pair.pkMember} AND cur.CHILD_NODE = #{pair.childNode}) AND cur.STAGE = #{ stage }
        </foreach>
    </select>
</mapper>
