<?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.WxCampaignMapper">
    <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCampaign">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
        <result column="cover_picture" jdbcType="VARCHAR" property="coverPicture"/>
        <result column="title" jdbcType="VARCHAR" property="title"/>
        <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
        <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
        <result column="discount_price" jdbcType="INTEGER" property="discountPrice"/>
        <result column="detail" jdbcType="VARCHAR" property="detail"/>
        <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
        <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
        <result column="img_detail" jdbcType="VARCHAR" property="imgDetail"/>
        <result column="type" jdbcType="INTEGER" property="type"/>
        <result column="coupon_ids" jdbcType="VARCHAR" property="couponIds"/>
        <result column="mechant_id" jdbcType="BIGINT" property="mechantId"/>
        <result column="sort_num" jdbcType="INTEGER" property="sortNum"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="html" jdbcType="VARCHAR" property="html"/>

        <result column="produce_type" jdbcType="INTEGER" property="produceType"/>
        <result column="produce_id" jdbcType="BIGINT" property="produceId"/>
        <result column="page_path" jdbcType="BIGINT" property="pagePath"/>
        <result column="page_scene" jdbcType="BIGINT" property="pageScene"/>
    </resultMap>
    
    <sql id="allColumns">
		`id`,`tenant_id`,`cover_img`,`cover_picture`,`detail_picture`,`title`,`sub_title`,`use_price`,`discount_price`,`detail`,`valid_start_date`,`valid_end_date`,`img_detail`,`type`,`coupon_ids`,
		`mechant_id`,`sort_num`,`status`,`create_time`,`update_time`,`html`,
		`produce_type`,`produce_id`,`page_path`,`page_scene`
	</sql>

    <sql id="allCHeadColumns">
		`id`,`tenant_id`,`cover_img`,`cover_picture`,`detail_picture`,`title`,`type`,`sort_num`,`page_path`
	</sql>

    <sql id="allAHeadColumns">
		`id`,`tenant_id`,`cover_img`,`cover_picture`,`detail_picture`,`title`,`sub_title`,`use_price`,`discount_price`,`detail`,`valid_start_date`,`valid_end_date`,`img_detail`,`type`,`coupon_ids`,
		`mechant_id`,`sort_num`,`status`,`create_time`,`update_time`,`page_path`
	</sql>

    <sql id="dynamicWhereConditions">
        where 1 = 1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        <if test=" null != updateTime ">
            and `update_time` = #{updateTime}
        </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.WxCampaign" resultMap="BaseResultMap">
        select
        <include refid="allAHeadColumns"/>
        from wx_campaign
        <include refid="dynamicWhereConditions"/>
    </select>

    <select id="findCList" parameterType="com.iformall.domain.po.WxCampaign" resultMap="BaseResultMap">
        select
        <include refid="allCHeadColumns"/>
        from wx_campaign
        <include refid="dynamicWhereConditions"/>
    </select>

    <select id="getMaxSortNum" parameterType="java.lang.String" resultType="java.lang.Integer">
		select max(sort_num) from wx_campaign where `tenant_id` = #{tenantId}
	</select>

</mapper>
