<?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.github.tangyi.user.mapper.RouteMapper">
    <resultMap id="routeResultMap" type="com.github.tangyi.common.core.model.Route">
        <id column="id" property="id"/>
        <result column="route_id" property="routeId" />
        <result column="route_name" property="routeName" />
        <result column="predicates" property="predicates" />
        <result column="filters" property="filters" />
        <result column="uri" property="uri" />
        <result column="sort" property="sort" />
        <result column="status" property="status" />
        <result column="creator" property="creator" />
        <result column="create_date" property="createDate" />
        <result column="modifier" property="modifier" />
        <result column="modify_date" property="modifyDate" />
        <result column="del_flag" property="delFlag" />
        <result column="application_code" property="applicationCode" />
    </resultMap>

    <sql id="routeColumns">
        a.id,
        a.route_id,
        a.route_name,
        a.predicates,
        a.filters,
        a.uri,
        a.sort,
        a.status,
        a.creator,
        a.create_date,
        a.modifier,
        a.modify_date,
        a.del_flag,
        a.application_code
    </sql>

    <!-- where 条件 -->
    <sql id="whereColumnList">
        <if test="routeId != null and routeId != ''">
            and a.route_id like CONCAT('%', #{routeId},'%')
        </if>
        <if test="routeName != null and routeName != ''">
            and a.route_name like CONCAT('%', #{routeName},'%')
        </if>
        <if test="status != null and status != ''">
            and a.status = #{status}
        </if>
    </sql>

    <select id="get" resultMap="routeResultMap">
        SELECT
        <include refid="routeColumns"/>
        FROM sys_route a
        WHERE a.id = #{id} and a.del_flag = 0
    </select>

    <select id="findList" resultMap="routeResultMap">
        SELECT
        <include refid="routeColumns"/>
        FROM sys_route  a
        WHERE a.del_flag = 0
        <include refid="whereColumnList"/>
    </select>

    <select id="findListById" resultMap="routeResultMap">
        SELECT
        <include refid="routeColumns"/>
        FROM sys_route  a
        WHERE a.id IN
        <foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <insert id="insert">
        INSERT INTO sys_route (
        id,
        route_id,
        route_name,
        predicates,
        filters,
        uri,
        sort,
        status,
        creator,
        create_date,
        modifier,
        modify_date,
        del_flag,
        application_code
        ) VALUES (
        #{id},
        #{routeId},
        #{routeName},
        #{predicates},
        #{filters},
        #{uri},
        #{sort},
        #{status},
        #{creator},
        #{createDate},
        #{modifier},
        #{modifyDate},
        #{delFlag},
        #{applicationCode}
        )
    </insert>

    <update id="update">
        UPDATE sys_route  SET
        <if test="routeId != null">
            route_id = #{routeId},
        </if>
        <if test="routeName != null">
            route_name = #{routeName},
        </if>
        <if test="predicates != null">
            predicates = #{predicates},
        </if>
        <if test="filters != null">
            filters = #{filters},
        </if>
        <if test="uri != null">
            uri = #{uri},
        </if>
        <if test="sort != null">
            sort = #{sort},
        </if>
        <if test="status != null">
            status = #{status},
        </if>
        modifier = #{modifier},
        modify_date = #{modifyDate}
        WHERE
        <if test="id != null">
            id = #{id}
        </if>
    </update>

    <delete id="delete">
        UPDATE sys_route SET
        del_flag = 1
        WHERE id = #{id}
    </delete>

    <delete id="deleteAll">
        UPDATE sys_route SET
        del_flag = 1
        WHERE id in
        <foreach item="item" index="index" collection="array" open="("
                 separator="," close=")"> #{item}
        </foreach>
    </delete>
</mapper>
