<?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.WxFloatingLayerMapper">
	<resultMap id="BaseResultMap" type="com.iformall.domain.po.WxFloatingLayer">
		<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="produce_id" jdbcType="BIGINT" property="produceId"/>
		<result column="page_path" jdbcType="VARCHAR" property="pagePath"/>
		<result column="status" jdbcType="INTEGER" property="status"/>
		<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
		<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
	
	</resultMap>
	
	<sql id="allColumns">
	     `id`,  `tenant_id` ,  `cover_img` ,  `produce_id`,  `page_path` ,  `status`,  `create_time`,  `update_time`
	</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 != status ">
			and `status` = #{status}
		</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>
	
	<sql id="allColumnsVO">
	     fl.`id` as id,  fl.`tenant_id` ,  fl.`cover_img` ,  fl.`produce_id`,
	     fl.`page_path` ,  fl.`status`,  fl.`create_time` as create_time,  fl.`update_time`,
	     cc.title
	</sql>
	
	<select id="findList" parameterType="com.iformall.domain.po.WxFloatingLayer" resultMap="BaseResultMap">
		select
		<include refid="allColumns"/>
		from wx_floating_layer
		<include refid="dynamicWhereConditions"/>
	</select>
	
	<resultMap id="resultListVO" type="com.iformall.domain.vo.WxFloatingLayerVO">
		<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="produce_id" jdbcType="BIGINT" property="produceId"/>
		<result column="page_path" jdbcType="VARCHAR" property="pagePath"/>
		<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="title" jdbcType="VARCHAR" property="title"/>
	</resultMap>
	
	<sql id="dynamicWhereConditionsVO">
		where 1=1
		<if test=" null != id ">
			and fl.`id` = #{id}
		</if>
		
		<if test=" null != tenantId ">
			and fl.`tenant_id` = #{tenantId}
		</if>
		
		<if test=" null != status ">
			and fl.`status` = #{status}
		</if>
		
		<if test=" null != ids ">
			and fl.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="findListVO" parameterType="com.iformall.domain.po.WxFloatingLayer" resultMap="resultListVO">
		select
		<include refid="allColumnsVO"/>
		from wx_floating_layer fl left join wx_coupon_channel cc on fl.produce_id=cc.id
		<include refid="dynamicWhereConditionsVO"/>
	</select>
	
	<update id="updateStatus">
		update wx_floating_layer set status=1 where produce_id=#{value}
	</update>

</mapper>
