<?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.ruoyi.platform.mapper.AssetIconDao">

    <resultMap type="com.ruoyi.platform.domain.AssetIcon" id="AssetIconMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="categoryId" column="category_id" jdbcType="INTEGER"/>
        <result property="path" column="path" jdbcType="VARCHAR"/>
        <result property="description" column="description" jdbcType="VARCHAR"/>
        <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="state" column="state" jdbcType="INTEGER"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="AssetIconMap">
        select
        id,name, category_id, path, description, create_by, create_time, update_by, update_time, state
        from asset_icon
        where id = #{id} and state = 1
    </select>

    <select id="queryByCategoryId" resultMap="AssetIconMap">
        select
        id,name, category_id, path, description, create_by, create_time, update_by, update_time, state
        from asset_icon
        where category_id = #{categoryId} and state = 1
    </select>

    <!--通过图标名字进行模糊查询-->
    <select id="queryByName" resultMap="AssetIconMap">
        select
        id,name,category_id, path, description, create_by, create_time, update_by, update_time, state
        from asset_icon
        <where>
            state = 1
            <if test="name != null and name != ''">
                and name like "%"#{name}"%"
            </if>
        </where>
    </select>

    <select id="queryByPath" resultMap="AssetIconMap" >
        select
        id, name,category_id, path, description, create_by, create_time, update_by, update_time, state
        from asset_icon
        where path = #{path} and state = 1
    </select>

    <select id="queryAllByLimit" resultMap="AssetIconMap">
        select
        id, name, category_id, path, description, create_by, create_time, update_by, update_time, state
        from asset_icon
        <where>
            state = 1
            <if test="assetIcon.id != null">
                and id = #{assetIcon.id}
            </if>
            <if test="assetIcon.name != null and assetIcon.name != ''">
                and name like "%"#{assetIcon.name}"%"
            </if>
            <if test="assetIcon.categoryId != null">
                and category_id = #{assetIcon.categoryId}
            </if>
            <if test="assetIcon.path != null and assetIcon.path != ''">
                and path = #{assetIcon.path}
            </if>
            <if test="assetIcon.description != null and assetIcon.description != ''">
                and description = #{assetIcon.description}
            </if>
            <if test="assetIcon.createBy != null and assetIcon.createBy != ''">
                and create_by = #{assetIcon.createBy}
            </if>
            <if test="assetIcon.createTime != null">
                and create_time = #{assetIcon.createTime}
            </if>
            <if test="assetIcon.updateBy != null and assetIcon.updateBy != ''">
                and update_by = #{assetIcon.updateBy}
            </if>
            <if test="assetIcon.updateTime != null">
                and update_time = #{assetIcon.updateTime}
            </if>
            <if test="assetIcon.state != null">
                and state = #{assetIcon.state}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>


    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from asset_icon
        <where>
            state = 1
            <if test="assetIcon.id != null">
                and id = #{assetIcon.id}
            </if>
            <if test="assetIcon.name != null and assetIcon.name != ''">
                and name like "%"#{assetIcon.name}"%"
            </if>
            <if test="assetIcon.categoryId != null">
                and category_id = #{assetIcon.categoryId}
            </if>
            <if test="assetIcon.path != null and assetIcon.path != ''">
                and path = #{assetIcon.path}
            </if>
            <if test="assetIcon.description != null and assetIcon.description != ''">
                and description = #{assetIcon.description}
            </if>
            <if test="assetIcon.createBy != null and assetIcon.createBy != ''">
                and create_by = #{assetIcon.createBy}
            </if>
            <if test="assetIcon.createTime != null">
                and create_time = #{assetIcon.createTime}
            </if>
            <if test="assetIcon.updateBy != null and assetIcon.updateBy != ''">
                and update_by = #{assetIcon.updateBy}
            </if>
            <if test="assetIcon.updateTime != null">
                and update_time = #{assetIcon.updateTime}
            </if>
            <if test="assetIcon.state != null">
                and state = #{assetIcon.state}
            </if>
        </where>
    </select>


    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into asset_icon(name, category_id, path, description, create_by, create_time, update_by, update_time, state)
        values (#{assetIcon.name}, #{assetIcon.categoryId}, #{assetIcon.path}, #{assetIcon.description}, #{assetIcon.createBy}, #{assetIcon.createTime}, #{assetIcon.updateBy}, #{assetIcon.updateTime}, #{assetIcon.state})
    </insert>


    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into asset_icon(name,category_id,path,description,create_by,create_time,update_by,update_time,state)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.name}#{entity.categoryId}#{entity.path}#{entity.description}#{entity.createBy}#{entity.createTime}#{entity.updateBy}#{entity.updateTime}#{entity.state})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into asset_icon(name,category_id,path,description,create_by,create_time,update_by,update_time,state)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}#{entity.categoryId}#{entity.path}#{entity.description}#{entity.createBy}#{entity.createTime}#{entity.updateBy}#{entity.updateTime}#{entity.state})
        </foreach>
        on duplicate key update
name = values(name)category_id = values(category_id)path = values(path)description = values(description)create_by = values(create_by)create_time = values(create_time)update_by = values(update_by)update_time = values(update_time)state = values(state)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update asset_icon
        <set>
            <if test="assetIcon.name != null and assetIcon.name != ''">
                name = #{assetIcon.name},
            </if>
            <if test="assetIcon.categoryId != null">
                category_id = #{assetIcon.categoryId},
            </if>
            <if test="assetIcon.path != null and assetIcon.path != ''">
                path = #{assetIcon.path},
            </if>
            <if test="assetIcon.description != null and assetIcon.description != ''">
                description = #{assetIcon.description},
            </if>
            <if test="assetIcon.createBy != null and assetIcon.createBy != ''">
                create_by = #{assetIcon.createBy},
            </if>
            <if test="assetIcon.createTime != null">
                create_time = #{assetIcon.createTime},
            </if>
            <if test="assetIcon.updateBy != null and assetIcon.updateBy != ''">
                update_by = #{assetIcon.updateBy},
            </if>
            <if test="assetIcon.updateTime != null">
                update_time = #{assetIcon.updateTime},
            </if>
            <if test="assetIcon.state != null">
                state = #{assetIcon.state},
            </if>
        </set>
        where id = #{assetIcon.id}
    </update>

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

</mapper>

