<?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.WxOrderPressMapper">
	<resultMap id="BaseResultMap" type="com.iformall.domain.po.WxOrderPress">
		<id column="id" jdbcType="BIGINT" property="id" />
        <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
		<result column="order_id" jdbcType="BIGINT" property="orderId" />
		<result column="user_id" jdbcType="BIGINT" property="userId" />
		<result column="press_value" jdbcType="INTEGER" property="pressValue" />
		<result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
        <result column="first" jdbcType="SMALLINT" property="first" />
	</resultMap>
	
	<sql id="allColumns">
	    `id`,`order_id`,`user_id`,`press_value`,`create_date`,`first`
	</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 != orderId ">
		    and `order_id` = #{orderId}
		</if>    
		<if test=" null != userId ">
		    and `user_id` = #{userId}
		</if>    
		<if test=" null != pressValue ">
		    and `press_value` = #{pressValue}
		</if>    
		<if test=" null != createDate ">
		    and `create_date` = #{createDate}
		</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.WxOrderPress" resultMap="BaseResultMap">
		select <include refid="allColumns" /> from wx_order_press
		<include refid="dynamicWhereConditions" />
	</select>

    <resultMap id="VoBaseResultMap" type="com.iformall.domain.vo.WxOrderPressVo">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
        <result column="order_id" jdbcType="BIGINT" property="orderId" />
        <result column="user_id" jdbcType="BIGINT" property="userId" />
        <result column="press_value" jdbcType="INTEGER" property="pressValue" />
        <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
        <result column="first" jdbcType="SMALLINT" property="first" />

        <result column="nick_name" jdbcType="VARCHAR" property="nickName"/>
        <result column="avatar_url" jdbcType="VARCHAR" property="avatarUrl"/>
    </resultMap>

    <sql id="allVoColumns">
	    op.`id`,op.`order_id`,op.`user_id`,op.`press_value`,op.`create_date`,op.`first`,
	    cu.`nick_name`, cu.`avatar_url`
	</sql>

    <select id="findPressList" parameterType="com.iformall.domain.vo.WxOrderPressVo" resultMap="VoBaseResultMap">
        select <include refid="allVoColumns" />
        from wx_order_press op
        left join wx_c_user cu on cu.id = op.user_id
        where op.`order_id` = #{orderId}
        order by op.`create_date` desc
    </select>
	
	
	
	
	
	
</mapper>
