<?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.WxAppinfoMapper">
    <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxAppinfo">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <result column="app_id" jdbcType="VARCHAR" property="appId"/>
        <result column="parent_app_id" jdbcType="VARCHAR" property="parentAppId"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="secret" jdbcType="VARCHAR" property="secret"/>
        <result column="token" jdbcType="VARCHAR" property="token"/>
        <result column="aes_key" jdbcType="VARCHAR" property="aesKey"/>
        <result column="msg_data_format" jdbcType="VARCHAR" property="msgDataFormat"/>
        <result column="access_token" jdbcType="VARCHAR" property="accessToken"/>
        <result column="last_token_time" jdbcType="TIMESTAMP" property="lastTokenTime"/>
        <result column="expires_in" jdbcType="INTEGER" property="expiresIn"/>
        <result column="pay_id" jdbcType="BIGINT" property="payId"/>
        <result column="type" jdbcType="INTEGER" property="type"/>
        <result column="pay_bill_id" jdbcType="BIGINT" property="payBillId"/>

    </resultMap>

    <sql id="allColumns">
	    `id`,`tenant_id`,`app_id`,`parent_app_id`,`name`,
	    `secret`,`token`,`aes_key`,`msg_data_format`,`access_token`,`last_token_time`,`expires_in`,
	    `pay_id`,`type`,`pay_bill_id`
	</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 != appId ">
            and `app_id` =  #{appId}
        </if>
        <if test=" null != parentAppId ">
            and `parent_app_id` like concat('%', #{parentAppId},'%')
        </if>

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

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

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

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

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

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

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

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

        <if test=" null != payId ">
            and `pay_id` = #{payId}
        </if>
        <if test=" null != type ">
            and `type` = #{type}
        </if>
        <if test=" null != payBillId ">
            and `pay_bill_id` = #{payBillId}
        </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.WxAppinfo" resultMap="BaseResultMap">
        select
        <include refid="allColumns"/>
        from wx_appinfo
        <include refid="dynamicWhereConditions"/>
    </select>

    <select id="findByAppId" parameterType="java.lang.String" resultMap="BaseResultMap">
        SELECT *
        FROM wx_appinfo
        WHERE `app_id` = #{appId}
    </select>
</mapper>
