<?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.WxWeappCodeStatusMapper">
    <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxWeappCodeStatus">
        <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="type" jdbcType="INTEGER" property="type"/>
        <result column="user_version" jdbcType="VARCHAR" property="userVersion"/>
        <result column="version_desc" jdbcType="VARCHAR" property="versionDesc"/>
        <result column="code_status" jdbcType="INTEGER" property="codeStatus"/>
        <result column="code_err_code" jdbcType="VARCHAR" property="codeErrCode"/>
        <result column="code_time" jdbcType="TIMESTAMP" property="codeTime"/>
    </resultMap>

    <sql id="allColumns">
	    `id`,`tenant_id`,`app_id`,`type`,`user_version`,`version_desc`,`code_status`,`code_err_code`,`code_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 != 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 != codeStatus ">
            and `code_status` = #{codeStatus}
        </if>
        <if test=" null != codeTime ">
            and `code_time` = #{codeTime}
        </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.WxWeappCodeStatus" resultMap="BaseResultMap">
        select
        <include refid="allColumns"/>
        from wx_weapp_code_status
        <include refid="dynamicWhereConditions"/>
    </select>

    <update id="updateStatus" parameterType="com.iformall.domain.po.WxWeappCodeStatus">
        update wx_weapp_code_status
        set  `user_version` = #{userVersion}, `version_desc`= #{versionDesc},
          `code_status` = #{codeStatus}, `code_err_code` = #{codeErrCode}, `code_time` = #{codeTime}
        where `app_id` = #{appId} and `type` = #{type}
    </update>

    <select id="findUserVersions" resultType="hashmap">
        select user_version as version
        from wx_weapp_code_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.WxWeappCodeStatusVo">
        <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="type" jdbcType="INTEGER" property="type"/>
        <result column="user_version" jdbcType="VARCHAR" property="userVersion"/>
        <result column="version_desc" jdbcType="VARCHAR" property="versionDesc"/>
        <result column="code_status" jdbcType="INTEGER" property="codeStatus"/>
        <result column="code_err_code" jdbcType="VARCHAR" property="codeErrCode"/>
        <result column="code_time" jdbcType="TIMESTAMP" property="codeTime"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
    </resultMap>

    <sql id="allVoColumns">
	    c.`id`,c.`tenant_id`,c.`app_id`,c.`type`,c.`user_version`,c.`version_desc`,c.`code_status`,c.`code_err_code`,c.`code_time`, a.`name`
	</sql>

    <sql id="dynamicVoWhereConditions">
        where 1 = 1
        <if test=" null != id ">
            and c.`id` = #{id}
        </if>
        <if test=" null != tenantId ">
            and c.`tenant_id` = #{tenantId}
        </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 != codeStatus ">
            and c.`code_status` = #{codeStatus}
        </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.WxWeappCodeStatusVo" resultMap="VBaseResultMap">
        select
        <include refid="allVoColumns"/>
        from wx_weapp_code_status c
        left join wx_appinfo a on c.`app_id` = a.`app_id`
        <include refid="dynamicVoWhereConditions"/>
    </select>
</mapper>
