<?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.sundot.airport.system.mapper.SysAppMapper">

    <resultMap type="SysApp" id="SysAppResult">
        <result property="appId" column="app_id"/>
        <result property="appName" column="app_name"/>
        <result property="appUrl" column="app_url"/>
        <result property="appSort" column="app_sort"/>
        <result property="status" column="status"/>
        <result property="homePage" column="home_page"/>
        <result property="homePageIcon" column="home_page_icon"/>
        <result property="workbenchIcon" column="workbench_icon"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
        <result property="createByUserId" column="create_by_user_id"/>
        <result property="updateByUserId" column="update_by_user_id"/>
    </resultMap>

    <sql id="selectSysAppVo">
        select app_id,
               app_name,
               app_url,
               app_sort,
               status,
               home_page,
               home_page_icon,
               workbench_icon,
               create_by,
               create_time,
               update_by,
               update_time,
               remark,
               create_by_user_id,
               update_by_user_id
        from sys_app
    </sql>

    <select id="selectSysAppList" parameterType="SysApp" resultMap="SysAppResult">
        <include refid="selectSysAppVo"/>
        <where>
            <if test="appName != null  and appName != ''">and app_name like concat('%', #{appName}, '%')</if>
            <if test="appUrl != null  and appUrl != ''">and app_url = #{appUrl}</if>
            <if test="appSort != null ">and app_sort = #{appSort}</if>
            <if test="status != null  and status != ''">and status = #{status}</if>
            <if test="homePageIcon != null  and homePageIcon != ''">and home_page_icon = #{homePageIcon}</if>
            <if test="workbenchIcon != null  and workbenchIcon != ''">and workbench_icon = #{workbenchIcon}</if>
            <if test="createByUserId != null ">and create_by_user_id = #{createByUserId}</if>
            <if test="updateByUserId != null ">and update_by_user_id = #{updateByUserId}</if>
            <if test="createBy != null  and createBy != ''">and create_by like
                concat('%', #{createBy}, '%')
            </if>
            <if test="updateBy != null  and updateBy != ''">and update_by like
                concat('%', #{updateBy}, '%')
            </if>
        </where>
        order by app_sort asc
    </select>

    <select id="selectSysAppByAppId" parameterType="Long" resultMap="SysAppResult">
        <include refid="selectSysAppVo"/>
        where app_id = #{appId}
    </select>

    <insert id="insertSysApp" parameterType="SysApp" useGeneratedKeys="true" keyProperty="appId">
        insert into sys_app
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="appName != null and appName != ''">app_name,</if>
            <if test="appUrl != null and appUrl != ''">app_url,</if>
            <if test="appSort != null">app_sort,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="homePage != null and homePage != ''">home_page,</if>
            <if test="homePageIcon != null">home_page_icon,</if>
            <if test="workbenchIcon != null">workbench_icon,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="createByUserId != null">create_by_user_id,</if>
            <if test="updateByUserId != null">update_by_user_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="appName != null and appName != ''">#{appName},</if>
            <if test="appUrl != null and appUrl != ''">#{appUrl},</if>
            <if test="appSort != null">#{appSort},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="homePage != null and homePage != ''">#{homePage},</if>
            <if test="homePageIcon != null">#{homePageIcon},</if>
            <if test="workbenchIcon != null">#{workbenchIcon},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createByUserId != null">#{createByUserId},</if>
            <if test="updateByUserId != null">#{updateByUserId},</if>
        </trim>
    </insert>

    <update id="updateSysApp" parameterType="SysApp">
        update sys_app
        <trim prefix="SET" suffixOverrides=",">
            <if test="appName != null and appName != ''">app_name = #{appName},</if>
            <if test="appUrl != null and appUrl != ''">app_url = #{appUrl},</if>
            <if test="appSort != null">app_sort = #{appSort},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="homePage != null and homePage != ''">home_page = #{homePage},</if>
            <if test="homePageIcon != null">home_page_icon = #{homePageIcon},</if>
            <if test="workbenchIcon != null">workbench_icon = #{workbenchIcon},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createByUserId != null">create_by_user_id = #{createByUserId},</if>
            <if test="updateByUserId != null">update_by_user_id = #{updateByUserId},</if>
        </trim>
        where app_id = #{appId}
    </update>

    <delete id="deleteSysAppByAppId" parameterType="Long">
        delete
        from sys_app
        where app_id = #{appId}
    </delete>

    <delete id="deleteSysAppByAppIds" parameterType="String">
        delete from sys_app where app_id in
        <foreach item="appId" collection="array" open="(" separator="," close=")">
            #{appId}
        </foreach>
    </delete>
</mapper>