<?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.iformall.mapper.WxGameMapper">
	<resultMap id="BaseResultMap" type="com.iformall.domain.po.WxGame">
		<id column="id" jdbcType="BIGINT" property="id" />
		<result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
		<result column="game_id" jdbcType="INTEGER" property="gameId" />
		<result column="status" jdbcType="INTEGER" property="status" />
		<result column="coupon_ids" jdbcType="VARCHAR" property="couponIds" />
		<result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate" />
		<result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate" />
		<result column="triggle_action" jdbcType="INTEGER" property="triggleAction" />
		<result column="play_limit" jdbcType="INTEGER" property="playLimit" />
		<result column="award_limit" jdbcType="INTEGER" property="awardLimit" />
	</resultMap>
	
	<sql id="allColumns">
	    `id`,`tenant_id`,`game_id`,`status`,`coupon_ids`,`valid_start_date`,`valid_end_date`,`triggle_action`,`play_limit`,`award_limit`
	</sql>

	<sql id="dynamicWhereConditions">
	        where 1 = 1
		<if test=" null != id ">
		    and `id` = #{id}
		</if>

		<if test=" null != tenantId ">
		    and `tenant_id`  like concat('%', #{tenantId},'%')
		</if>

		<if test=" null != gameId ">
		    and `game_id` = #{gameId}
		</if>

		<if test=" null != status ">
		    and `status` = #{status}
		</if>

		<if test=" null != validStartDate ">
		    and `valid_start_date` = #{validStartDate}
		</if>

		<if test=" null != validEndDate ">
		    and `valid_end_date` = #{validEndDate}
		</if>

		<if test=" null != triggleAction ">
		    and `triggle_action` = #{triggleAction}
		</if>

		<if test=" null != playLimit ">
			and `play_limit` = #{playLimit}
		</if>

		<if test=" null != awardLimit ">
			and `award_limit` = #{awardLimit}
		</if>

		<if test=" null != ids ">
		 	and id in  
			<foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
			#{idItem}
			</foreach>
		</if>		
		<if test=" null != sortColumns"> order by ${sortColumns} </if>
	</sql>
	
	<select id="findList" parameterType="com.iformall.domain.po.WxGame" resultMap="BaseResultMap">
		select <include refid="allColumns" /> from wx_game
		<include refid="dynamicWhereConditions" />
	</select>

	
</mapper>
