<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
        "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="com.house365.beans.entity.VersionEntity">
    <typeAlias alias="versionEntity" type="com.house365.beans.entity.VersionEntity" />

    <resultMap id="version" class="com.house365.beans.entity.VersionEntity">
        <result property="id" column="id" />
        <result property="name" column="name" />
        <result property="version" column="version" />
        <result property="updateUrl" column="updateUrl" />
        <result property="description" column="description" />
        <result property="forceUpdate" column="forceUpdate" />
        <result property="versionCode" column="versionCode" />
        <result property="channel" column="type" />

    </resultMap>
    <!-- 新增记录 -->
    <insert id="save" parameterClass="versionEntity">
        <![CDATA[
	        INSERT INTO app_version (
	        	id,
	        	name,
	        	version,
	        	updateUrl,
	        	description,
	        	forceUpdate,
	        	versionCode,
	        	type
	        ) VALUES (
	        	#id#,
	        	#name#,
	        	#version#,
	        	#updateUrl#,
	        	#description#,
	        	#forceUpdate#,
	        	#versionCode#,
	        	#channel#
	        )
	    ]]>
    </insert>

    <!-- 为分页查询符合条件的记录数 -->
    <select id="queryByPage_count" resultClass="int">
        SELECT count(*) FROM app_version
    </select>

    <select id="queryByPage" resultMap="version">
        SELECT
        id,name,version,updateUrl,description,forceUpdate,type,versionCode
        <![CDATA[
	        FROM app_version u
	    ]]>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
    </select>

    <select id="getLastVersion" resultClass="versionEntity" parameterClass="versionEntity">
        SELECT
        id,name,version,updateUrl,description,forceUpdate,versionCode
        <![CDATA[
	        FROM app_version u
	    ]]>
	    where type =#channel#
        order by id desc
        LIMIT 1
    </select>

    <delete id="deleteVersionById">
        delete from app_version where id =#id#
    </delete>

</sqlMap>
