<?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.WxMallMapper">
    <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxMall">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="group" jdbcType="VARCHAR" property="group"/>
        <result column="country" jdbcType="VARCHAR" property="country"/>
        <result column="province" jdbcType="VARCHAR" property="province"/>
        <result column="city" jdbcType="VARCHAR" property="city"/>
        <result column="addr" jdbcType="VARCHAR" property="addr"/>
        <result column="total_area" jdbcType="DECIMAL" property="totalArea"/>
        <result column="operating_area" jdbcType="DECIMAL" property="operatingArea"/>
        <result column="park_area" jdbcType="DECIMAL" property="parkArea"/>
        <result column="park_place_number" jdbcType="INTEGER" property="parkPlaceNumber"/>
        <result column="service_phone" jdbcType="VARCHAR" property="servicePhone"/>
        <result column="img_url" jdbcType="VARCHAR" property="imgUrl"/>
        <result column="img_url_h" jdbcType="VARCHAR" property="imgUrlH"/>
        <result column="weap_note" jdbcType="VARCHAR" property="weapNote"/>
        <result column="img_qrcode_weapp" jdbcType="VARCHAR" property="imgQrcodeWeapp"/>
        <result column="img_qrcode_wemp" jdbcType="VARCHAR" property="imgQrcodeWemp"/>
    </resultMap>

    <sql id="allColumns">
	    `id`,`tenant_id`,`name`,`group`,`country`,`province`,`city`,`addr`,
	    `total_area`,`operating_area`,`park_area`,`park_place_number`,`service_phone`,
	    `img_url`,`img_url_h`, `weap_note`, `img_qrcode_weapp`, `img_qrcode_wemp`
	</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 != name ">
            and `name` like concat('%', #{name},'%')
        </if>

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

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

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

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

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

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

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

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

        <if test=" null != parkPlaceNumber ">
            and `park_place_number` = #{parkPlaceNumber}
        </if>
        <if test=" null != servicePhone ">
            and `service_phone` = #{servicePhone}
        </if>
        <if test=" null != imgUrl ">
            and `img_url` = #{imgUrl}
        </if>
        <if test=" null != imgUrlH ">
            and `img_ur_h` = #{imgUrlH}
        </if>

        <if test=" null != imgQrcodeWeapp ">
            and `img_qrcode_weapp` = #{imgQrcodeWeapp}
        </if>
        <if test=" null != imgQrcodeWemp ">
            and `img_qrcode_wemp` = #{imgQrcodeWemp}
        </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.WxMall" resultMap="BaseResultMap">
        select
        <include refid="allColumns"/>
        from wx_mall
        <include refid="dynamicWhereConditions"/>
    </select>

    <update id="updateToken" parameterType="com.iformall.domain.po.WxMall">
		update wx_mall set token=#{token},expired_time=#{expiredTime} where id=#{id}
	</update>


</mapper>
