<?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.pcloud.book.group.dao.impl.ResourcePageModelDaoImpl">

    <resultMap type="com.pcloud.book.group.entity.ResourcePageModel" id="ResourcePageModelMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="resourcePageId" column="resource_page_id" jdbcType="INTEGER"/>
        <result property="serveTitle" column="serve_title" jdbcType="VARCHAR"/>
        <result property="serveIcon" column="serve_icon" jdbcType="VARCHAR"/>
        <result property="serveId" column="serve_id" jdbcType="INTEGER"/>
        <result property="serveType" column="serve_type" jdbcType="VARCHAR"/>
        <result property="linkUrl" column="link_url" jdbcType="VARCHAR"/>
        <result property="typeCode" column="type_code" jdbcType="VARCHAR"/>
        <result property="createUser" column="create_user" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="selfSet" column="self_set" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_columnss">
        id, resource_page_id, serve_title, serve_icon, serve_id, serve_type, link_url, type_code, create_user, create_time,self_set
    </sql>

    <!--查询单个-->
    <select id="getById" resultMap="ResourcePageModelMap">
        select
        <include refid="Base_columnss"/>
        from resource_page_model
        where id = #{id}
    </select>


    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into resource_page_model(resource_page_id, serve_title, serve_icon, serve_id, serve_type, link_url, type_code, create_user, create_time, update_time,self_set)
        values (#{resourcePageId}, #{serveTitle}, #{serveIcon}, #{serveId}, #{serveType}, #{linkUrl}, #{typeCode}, #{createUser}, now(), now(),ifnull(#{selfSet},0))
    </insert>

    <insert id="batchInsert" keyProperty="id" useGeneratedKeys="true">
        insert into resource_page_model(resource_page_id, serve_title, serve_icon, serve_id, serve_type, link_url, type_code, create_user, create_time, update_time,self_set)
        values
        <foreach collection="list" item="entity" separator=",">
        (#{entity.resourcePageId}, #{entity.serveTitle}, #{entity.serveIcon}, #{entity.serveId}, #{entity.serveType}, #{entity.linkUrl}, #{entity.typeCode}, #{entity.createUser}, now(), now(),ifnull(#{entity.selfSet},0))
        </foreach>
    </insert>


    <!--通过主键修改数据-->
    <update id="update">
        update resource_page_model
        <set>
            <if test="resourcePageId != null">
                resource_page_id = #{resourcePageId},
            </if>
            <if test="serveTitle != null and serveTitle != ''">
                serve_title = #{serveTitle},
            </if>
            <if test="serveIcon != null and serveIcon != ''">
                serve_icon = #{serveIcon},
            </if>
            <if test="serveId != null">
                serve_id = #{serveId},
            </if>
            <if test="serveType != null and serveType != ''">
                serve_type = #{serveType},
            </if>
            <if test="linkUrl != null and linkUrl != ''">
                link_url = #{linkUrl},
            </if>
            <if test="typeCode != null and typeCode != ''">
                type_code = #{typeCode},
            </if>
                update_time = now(),
        </set>
        where id = #{id}
    </update>

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

    <select id="getByPaegId"  parameterType="long" resultMap="ResourcePageModelMap">
        select
        <include refid="Base_columnss"/>
        from resource_page_model
        where resource_page_id = #{resourcePageId}
    </select>

    <delete id="deleteByPageId">
        delete from resource_page_model where resource_page_id = #{resourcePageId}
    </delete>

    <delete id="deleteByPageIdAndTypeCode" parameterType="map">
        delete from resource_page_model
        where resource_page_id = #{resourcePageId}
        and type_code in
        <foreach collection="typeCodes" separator="," item="item" index="index" open="(" close=")">
            #{item}
        </foreach>
    </delete>

    <delete id="deleteByPageIdExcludeTypeCode" parameterType="map">
        delete from resource_page_model
        where resource_page_id = #{resourcePageId}
        and type_code not in
        <foreach collection="typeCodes" separator="," item="item" index="index" open="(" close=")">
            #{item}
        </foreach>
    </delete>

</mapper>

