<?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="cn.iocoder.mall.admin.dao.RoleMapper">

    <sql id="FIELDS">
        id, name, create_time
    </sql>

    <insert id="insert" parameterType="RoleDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
        INSERT INTO role (
          name, create_time, deleted
        ) VALUES (
          #{name}, #{createTime}, #{deleted}
        )
    </insert>

    <update id="update" parameterType="RoleDO">
        UPDATE role
        <set>
            <if test="name != null">
                , name = #{name}
            </if>
            <if test="deleted != null">
                , deleted = #{deleted}
            </if>
        </set>
        WHERE id = #{id}
    </update>

    <select id="selectById" parameterType="Integer" resultType="RoleDO">
        SELECT
            <include refid="FIELDS"/>
        FROM role
        WHERE id = #{id}
        AND deleted = 0
    </select>

    <select id="selectListByNameLike" resultType="RoleDO">
        SELECT
            <include refid="FIELDS"/>
        FROM role
        <where>
            <if test="name != null">
                name LIKE "%"#{name}"%"
            </if>
            AND deleted = 0
        </where>
        LIMIT #{offset}, #{limit}
    </select>

    <select id="selectCountByNameLike" resultType="Integer">
        SELECT
          COUNT(1)
        FROM role
        <where>
            <if test="name != null">
                name LIKE "%"#{name}"%"
            </if>
            AND deleted = 0
        </where>
     </select>

    <select id="selectListByIds" resultType="RoleDO">
        SELECT
            <include refid="FIELDS"/>
        FROM role
        WHERE id IN
        <foreach item="id" collection="ids" separator="," open="(" close=")" index="">
            #{id}
        </foreach>
        AND deleted = 0
    </select>

    <select id="selectList" resultType="RoleDO">
        SELECT
            <include refid="FIELDS"/>
        FROM role
        WHERE deleted = 0
    </select>

</mapper>