<?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.zcxk.dao.VerManageMapper">
    <resultMap type="VerManageEntity" id="VerManageResult">
        <result property="id"    column="id"    />
        <result property="verId"    column="ver_id"    />
        <result property="verUrl"    column="ver_url"    />
        <result property="isForcedUpgrade"    column="is_forced_upgrade"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="dateCreate"    column="date_create"    />
        <result property="updateBy"    column="update_by"    />
        <result property="dateUpdate"    column="date_update"    />
        <result property="mobileOS"    column="mobile_os"    />
        <result property="curAppVer"    column="cur_app_ver"    />
        <result property="productType"    column="product_type"    />
        <result property="forcedUpgradeVer"    column="forced_upgrade_ver"    />
        <result property="isNewestVer"    column="is_newest_ver"    />
        <result property="download"    column="download"    />
    </resultMap>

    <!--  实体  -->
    <sql id="verManageColumns">
         a.id as "id" ,
         a.ver_id as "verId" ,
         a.ver_url as "verUrl" ,
         a.is_forced_upgrade as "isForcedUpgrade" ,
         a.remark as "remark" ,
         a.date_create as "dateCreate" ,
         a.date_update as "dateUpdate" ,
         a.create_by as "createBy" ,
         a.update_by as "updateBy" ,
         a.mobile_os as "mobileOS" ,
         a.cur_app_ver as "curAppVer" ,
         a.product_type as "productType" ,
         a.forced_upgrade_ver as "forcedUpgradeVer" ,
         a.is_newest_ver as "isNewestVer" ,
         a.download as "download"
     </sql>

    <!--  根据主键获取实体   -->
    <select id="findVerManage" resultType="com.zcxk.entity.VerManageEntity">
        SELECT
        <include refid="verManageColumns"/>
        FROM uims_ver_manage a
        WHERE a.status=1
        <if test="verId != null">
            and a.cur_app_ver like concat(concat('%',#{verId}) ,'%')
        </if>
        <if test="productType != null and productType !=''">
            and a.product_type = #{productType}
        </if>
        order by  a.DATE_CREATE desc
    </select>

    <select id="getUpgradeVer" resultType="com.zcxk.entity.VerManageEntity">
        SELECT
        <include refid="verManageColumns"/>
        FROM uims_ver_manage a
        WHERE a.status=1
        and a.mobile_os='安卓'
        <if test="productType != null and productType !=''">
            and a.product_type = #{productType}
        </if>
        order by a.DATE_CREATE desc
        limit 1
    </select>

    <insert id="insertSelective" parameterType="com.zcxk.entity.VerManageEntity" >
        insert into uims_ver_manage
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="verId != null" >
                ver_id,
            </if>
            <if test="verUrl != null" >
                ver_url,
            </if>
            <if test="download != null" >
                download,
            </if>
            <if test="isForcedUpgrade != null" >
                is_forced_upgrade,
            </if>
            <if test="remark != null" >
                remark,
            </if>
            <if test="dateUpdate != null" >
                date_update,
            </if>
            <if test="createBy != null" >
                create_by,
            </if>
            <if test="updateBy != null" >
                update_by,
            </if>
            <if test="mobileOS != null" >
                mobile_os,
            </if>
            <if test="curAppVer != null" >
                cur_app_ver,
            </if>
            <if test="productType != null" >
                product_type,
            </if>
            <if test="forcedUpgradeVer != null" >
                forced_upgrade_ver,
            </if>
            <if test="isNewestVer != null" >
                is_newest_ver,
            </if>
            <if test="status != null" >
               status,
            </if>
            date_create,
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="verId != null" >
                #{verId,jdbcType=VARCHAR},
            </if>
            <if test="verUrl != null" >
                #{verUrl,jdbcType=VARCHAR},
            </if>
            <if test="download != null" >
                #{download,jdbcType=VARCHAR},
            </if>
            <if test="isForcedUpgrade != null" >
                #{isForcedUpgrade,jdbcType=INTEGER},
            </if>
            <if test="remark != null" >
                #{remark,jdbcType=VARCHAR},
            </if>
            <if test="dateUpdate != null" >
                #{dateUpdate,jdbcType=TIMESTAMP},
            </if>
            <if test="createBy != null" >
                #{createBy,jdbcType=VARCHAR},
            </if>
            <if test="updateBy != null" >
                #{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="mobileOS != null" >
                #{mobileOS,jdbcType=VARCHAR},
            </if>
            <if test="curAppVer != null" >
                #{curAppVer,jdbcType=VARCHAR},
            </if>
            <if test="productType != null" >
                #{productType,jdbcType=VARCHAR},
            </if>
            <if test="forcedUpgradeVer != null" >
                #{forcedUpgradeVer,jdbcType=VARCHAR},
            </if>
            <if test="isNewestVer != null" >
                #{isNewestVer,jdbcType=INTEGER},
            </if>
            <if test="status != null" >
                #{status,jdbcType=INTEGER},
            </if>
            SYSDATE(),
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective" parameterType="com.zcxk.entity.VerManageEntity" >
        update uims_ver_manage
        <set >
            <if test="verId != null" >
                ver_id = #{verId,jdbcType=VARCHAR},
            </if>
            <if test="verUrl != null" >
                ver_url = #{verUrl,jdbcType=VARCHAR},
            </if>
            <if test="download != null" >
                download = #{download,jdbcType=VARCHAR},
            </if>
            <if test="isForcedUpgrade != null" >
                is_forced_upgrade = #{isForcedUpgrade,jdbcType=INTEGER},
            </if>
            <if test="remark != null" >
                remark = #{remark,jdbcType=VARCHAR},
            </if>
            <if test="dateUpdate != null" >
                date_update = #{dateUpdate,jdbcType=TIMESTAMP},
            </if>
            <if test="updateBy != null" >
                create_by = #{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="mobileOS != null" >
                mobile_os = #{mobileOS,jdbcType=VARCHAR},
            </if>
            <if test="curAppVer != null" >
                cur_app_ver = #{curAppVer,jdbcType=VARCHAR},
            </if>
            <if test="productType != null" >
                product_type = #{productType,jdbcType=VARCHAR},
            </if>
            <if test="forcedUpgradeVer != null" >
                forced_upgrade_ver = #{forcedUpgradeVer,jdbcType=VARCHAR},
            </if>
            <if test="isNewestVer != null" >
                is_newest_ver = #{isNewestVer,jdbcType=INTEGER},
            </if>
            <if test="status != null" >
                status = #{status,jdbcType=INTEGER},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>

    <delete id="deleteSelective" parameterType="map">
        update uims_ver_manage
        set status = 0
        where id in
        <foreach collection="ids" item="item" open="(" close=")" separator=",">
            #{item,jdbcType=INTEGER}
        </foreach>
    </delete>

</mapper>