<?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.AppMapper">
    <!-- 结果集 -->
    <resultMap type="com.zcxk.entity.App" id="AppMap">
        <result property="id" column="ID" jdbcType="INTEGER"/>
        <result property="appName" column="APP_NAME" jdbcType="VARCHAR"/>
        <result property="appId" column="APP_ID" jdbcType="VARCHAR"/>
        <result property="appSecretKey" column="APP_SECRET_KEY" jdbcType="VARCHAR"/>
        <result property="appWebUrl" column="APP_WEB_URL" jdbcType="VARCHAR"/>
        <result property="status" column="STATUS" jdbcType="INTEGER"/>
        <result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
        <result property="dateCreate" column="DATE_CREATE" jdbcType="TIMESTAMP"/>
        <result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
        <result property="dateUpdate" column="DATE_UPDATE" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!-- 基本字段 -->
    <sql id="Base_Column_List">
        ID, APP_NAME, APP_ID, APP_SECRET_KEY, APP_WEB_URL, STATUS, CREATE_BY, DATE_CREATE, UPDATE_BY, DATE_UPDATE    </sql>

    <!-- 查询单个 -->
    <select id="selectById" resultMap="AppMap">
        select
        <include refid="Base_Column_List"/>
        from uims_app
        where ID = #{id}
    </select>


    <!-- 查询全部 -->
    <select id="selectAll" resultMap="AppMap">
        select
        <include refid="Base_Column_List"/>
        from uims_app
    </select>

    <!--通过实体作为筛选条件查询-->
    <select id="selectList" resultMap="AppMap">
        select
        <include refid="Base_Column_List"/>
        from uims_app
        <where>
            <if test="id != null">
                and ID = #{id}
            </if>
            <if test="appName != null and appName != ''">
                and APP_NAME = #{appName}
            </if>
            <if test="appId != null and appId != ''">
                and APP_ID = #{appId}
            </if>
            <if test="appSecretKey != null and appSecretKey != ''">
                and APP_SECRET_KEY = #{appSecretKey}
            </if>
            <if test="appWebUrl != null and appWebUrl != ''">
                and APP_WEB_URL = #{appWebUrl}
            </if>
            <if test="status != null">
                and STATUS = #{status}
            </if>
            <if test="createBy != null and createBy != ''">
                and CREATE_BY = #{createBy}
            </if>
            <if test="dateCreate != null">
                and DATE_CREATE = #{dateCreate}
            </if>
            <if test="updateBy != null and updateBy != ''">
                and UPDATE_BY = #{updateBy}
            </if>
            <if test="dateUpdate != null">
                and DATE_UPDATE = #{dateUpdate}
            </if>
        </where>
    </select>

    <!-- 新增所有列 -->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into uims_app(ID, APP_NAME, APP_ID, APP_SECRET_KEY, APP_WEB_URL, STATUS, CREATE_BY, DATE_CREATE, UPDATE_BY, DATE_UPDATE)
        values ( #{id}, #{appName}, #{appId}, #{appSecretKey}, #{appWebUrl}, #{status}, #{createBy}, #{dateCreate}, #{updateBy}, #{dateUpdate})
    </insert>

    <!-- 批量新增 -->
    <insert id="batchInsert">
        insert into uims_app(ID, APP_NAME, APP_ID, APP_SECRET_KEY, APP_WEB_URL, STATUS, CREATE_BY, DATE_CREATE,
        UPDATE_BY, DATE_UPDATE)
        values
        <foreach collection="apps" item="item" index="index" separator=",">
            (
            #{item.id}, #{item.appName}, #{item.appId}, #{item.appSecretKey}, #{item.appWebUrl}, #{item.status},
            #{item.createBy}, #{item.dateCreate}, #{item.updateBy}, #{item.dateUpdate} )
        </foreach>
    </insert>

    <!-- 通过主键修改数据 -->
    <update id="update">
        update uims.uims_app
        <set>
            <if test="appName != null and appName != ''">
                APP_NAME = #{appName},
            </if>
            <if test="appId != null and appId != ''">
                APP_ID = #{appId},
            </if>
            <if test="appSecretKey != null and appSecretKey != ''">
                APP_SECRET_KEY = #{appSecretKey},
            </if>
            <if test="appWebUrl != null and appWebUrl != ''">
                APP_WEB_URL = #{appWebUrl},
            </if>
            <if test="status != null">
                STATUS = #{status},
            </if>
            <if test="createBy != null and createBy != ''">
                CREATE_BY = #{createBy},
            </if>
            <if test="dateCreate != null">
                DATE_CREATE = #{dateCreate},
            </if>
            <if test="updateBy != null and updateBy != ''">
                UPDATE_BY = #{updateBy},
            </if>
            <if test="dateUpdate != null">
                DATE_UPDATE = #{dateUpdate},
            </if>
        </set>
        where ID = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from uims_app where ID = #{id}
    </delete>

    <!-- 总数 -->
    <select id="count" resultType="int">
        select count(*) from uims_app
    </select>
    <select id="selectPage" resultMap="AppMap">
        select
        <include refid="Base_Column_List"/>
        from uims_app
        <where>
            <if test="app.id != null">
                and ID = #{app.id}
            </if>
            <if test="app.appName != null and app.appName != ''">
                and APP_NAME = #{app.appName}
            </if>
            <if test="app.appId != null and app.appId != ''">
                and APP_ID = #{app.appId}
            </if>
            <if test="app.appSecretKey != null and app.appSecretKey != ''">
                and APP_SECRET_KEY = #{app.appSecretKey}
            </if>
            <if test="app.appWebUrl != null and app.appWebUrl != ''">
                and APP_WEB_URL = #{app.appWebUrl}
            </if>
            <if test="app.status != null">
                and STATUS = #{app.status}
            </if>
            <if test="app.createBy != null and app.createBy != ''">
                and CREATE_BY = #{app.createBy}
            </if>
            <if test="app.dateCreate != null">
                and DATE_CREATE = #{app.dateCreate}
            </if>
            <if test="app.updateBy != null and app.updateBy != ''">
                and UPDATE_BY = #{app.updateBy}
            </if>
            <if test="app.dateUpdate != null">
                and DATE_UPDATE = #{app.dateUpdate}
            </if>
        </where>
    </select>
</mapper>