<?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.WxWeappReleaseStatusMapper">
	<resultMap id="BaseResultMap" type="com.iformall.domain.po.WxWeappReleaseStatus">
		<id column="id" jdbcType="BIGINT" property="id" />
		<result column="app_id" jdbcType="VARCHAR" property="appId" />
		<result column="type" jdbcType="INTEGER" property="type" />
		<result column="user_version" jdbcType="VARCHAR" property="userVersion" />
        <result column="version_desc" jdbcType="VARCHAR" property="versionDesc" />
        <result column="release_status" jdbcType="VARCHAR" property="releaseStatus" />
        <result column="release_err_code" jdbcType="INTEGER" property="releaseErrCode" />
        <result column="release_time" jdbcType="TIMESTAMP" property="releaseTime" />
	</resultMap>
	
	<sql id="allColumns">
	    `id`,`app_id`,`type`,`user_version`,`version_desc`,`release_status`,`release_err_code`,`release_time`
	</sql>

	<sql id="dynamicWhereConditions">
	        where 1 = 1
		<if test=" null != id ">
		    and `id` = #{id}
		</if>    
		<if test=" null != appId ">
		    and `app_id` = #{appId}
		</if>    
		<if test=" null != type ">
		    and `type` = #{type}
		</if>
        <if test=" null != userVersion ">
            and `user_version` = #{userVersion}
        </if>
        <if test=" null != releaseStatus ">
            and `release_status` = #{releaseStatus}
        </if>
		<if test=" null != releaseTime ">
		    and `release_time` = #{releaseTime}
		</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.WxWeappReleaseStatus" resultMap="BaseResultMap">
		select <include refid="allColumns" /> from wx_weapp_release_status
		<include refid="dynamicWhereConditions" />
	</select>

    <update id="updateStatus" parameterType="com.iformall.domain.po.WxWeappReleaseStatus" >
        update wx_weapp_release_status
        set  `user_version` = #{userVersion}, `version_desc` = #{versionDesc},
          `release_status` = #{releaseStatus}, `release_err_code` = #{releaseErrCode}, `release_time` = #{releaseTime}
        where `app_id` = #{appId} and `type` = #{type}
    </update>

    <select id="findUserVersions" resultType="hashmap" >
        select user_version as version
        from wx_weapp_release_status
        where 1 = 1
        <if test=" null != type ">
            and `type` = #{type}
        </if>
        group by user_version
    </select>

    <resultMap id="VBaseResultMap" type="com.iformall.domain.vo.WxWeappReleaseStatusVo">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="app_id" jdbcType="VARCHAR" property="appId" />
        <result column="type" jdbcType="INTEGER" property="type" />
        <result column="user_version" jdbcType="VARCHAR" property="userVersion" />
        <result column="version_desc" jdbcType="VARCHAR" property="versionDesc" />
        <result column="release_status" jdbcType="INTEGER" property="releaseStatus" />
        <result column="release_err_code" jdbcType="VARCHAR" property="releaseErrCode" />
        <result column="release_time" jdbcType="TIMESTAMP" property="releaseTime" />
        <result column="name" jdbcType="TIMESTAMP" property="name" />
    </resultMap>

    <sql id="allVoColumns">
	    c.`id`,c.`app_id`,c.`type`,c.`user_version`,c.`version_desc`,
	    c.`release_status`,c.`release_err_code`,c.`release_time`,
	    a.`name`
	</sql>

    <sql id="dynamicVoWhereConditions">
        where 1 = 1
        <if test=" null != id ">
            and c.`id` = #{id}
        </if>
        <if test=" null != appId ">
            and c.`app_id` = #{appId}
        </if>
        <if test=" null != type ">
            and c.`type` = #{type}
        </if>
        <if test=" null != userVersion ">
            and c.`user_version` = #{userVersion}
        </if>
        <if test=" null != releaseStatus ">
            and c.`release_status` = #{releaseStatus}
        </if>
        <if test=" null != releaseTime ">
            and c.`release_time` = #{releaseTime}
        </if>
        <if test=" null != name ">
            and a.`name` like concat('%', #{name},'%')
        </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="findVoList" parameterType="com.iformall.domain.vo.WxWeappReleaseStatusVo" resultMap="VBaseResultMap">
        select <include refid="allVoColumns" />
        from wx_weapp_release_status c
        left join wx_appinfo a on c.`app_id` = a.`app_id`
        <include refid="dynamicVoWhereConditions" />
    </select>
	
</mapper>
