<?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.kxs.system.biz.mapper.KxsCampBonusLogMapper">

    <resultMap type="com.kxs.system.api.model.KxsCampBonusLog" id="KxsCampBonusLogMap">
        <result column="id" property="id" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
        <result column="del_flag" property="delFlag" />
        <result column="version" property="version" />
        <result column="source_num" property="sourceNum" />
        <result column="kind" property="kind" />
        <result column="remark" property="remark" />
        <result column="camp_id" property="campId" />
        <result column="create_by" property="createBy" />
        <result column="source_id" property="sourceId" />
        <result column="username" property="username" />
        <result column="user_code" property="userCode" />
        <result column="source_type" property="sourceType" />
        <result column="camp_user_id" property="campUserId" />
        <result column="group_id" property="groupId" />

    </resultMap>
    <select id="getSysPage" resultType="com.kxs.system.api.vo.admin.camp.CampBonusLogVO">
        SELECT cbl.id, cbl.source_num, cbl.username as sourceName, cbl.source_id, cbl.user_code as sourceCode, cbl.source_type, cbl.remark, cbl.create_time, cbl.group_id, cbl.kind,
               cu.username, cu.user_code, cg.group_name,
               c.title
        FROM  kxs_camp_bonus_log cbl
        LEFT JOIN kxs_camp_user cu ON cbl.camp_user_id = cu.user_id AND cu.camp_id = #{param.campId}
        LEFT JOIN kxs_camp c ON cbl.camp_id = c.id
        left join kxs_camp_group cg on cg.group_id = cbl.group_id
        <where>
            AND cbl.del_flag = 0
            <if test="param.campId != null">
                AND cbl.camp_id = #{param.campId}
            </if>
            <if test="param.userCode != null">
                AND cu.user_code = #{param.userCode}
            </if>
            <if test="param.sourceType != null">
                AND cbl.source_type = #{param.sourceType}
            </if>
            <if test="param.groupId != null">
                AND cbl.group_id = #{param.groupId}
            </if>
            <if test="param.createTime != null and  param.createTime.length == 2">
                AND cbl.create_time between #{param.createTime[0]} and #{param.createTime[1]}
            </if>
        </where>
        order by cbl.create_time desc
    </select>
    <select id="exportLog" resultType="com.kxs.system.api.vo.admin.camp.CampBonusLogVO">
        SELECT cbl.id, cbl.source_num, cbl.username as sourceName, cbl.source_id, cbl.user_code as sourceCode, cbl.source_type, cbl.remark, cbl.create_time, cbl.group_id, cbl.kind,
        cu.username, cu.user_code, cg.group_name,
        c.title
        FROM  kxs_camp_bonus_log cbl
        LEFT JOIN kxs_camp_user cu ON cbl.camp_user_id = cu.user_id AND cu.camp_id = #{param.campId}
        LEFT JOIN kxs_camp c ON cbl.camp_id = c.id
        left join kxs_camp_group cg on cg.group_id = cbl.group_id
        <where>
            AND cbl.del_flag = 0
            <if test="param.campId != null">
                AND cbl.camp_id = #{param.campId}
            </if>
            <if test="param.userCode != null">
                AND cu.user_code = #{param.userCode}
            </if>
            <if test="param.sourceType != null">
                AND cbl.source_type = #{param.sourceType}
            </if>
            <if test="param.groupId != null">
                AND cbl.group_id = #{param.groupId}
            </if>
            <if test="param.createTime != null and  param.createTime.length == 2">
                AND cbl.create_time between #{param.createTime[0]} and #{param.createTime[1]}
            </if>
        </where>
    </select>

</mapper>
