<?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.ResourceRecomManageDaoImpl">

    <resultMap type="com.pcloud.book.group.entity.ResourceRecomManage" id="ResourceRecomManageMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="serveId" column="serve_id" jdbcType="INTEGER"/>
        <result property="serveName" column="serve_name" jdbcType="VARCHAR"/>
        <result property="serveType" column="serve_type" jdbcType="VARCHAR"/>
        <result property="typeCode" column="type_code" jdbcType="VARCHAR"/>
        <result property="coverImg" column="cover_img" jdbcType="VARCHAR"/>
        <result property="sourceFrom" column="source_from" jdbcType="INTEGER"/>
        <result property="showState" column="show_state" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="createUser" column="create_user" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, serve_id, serve_name, serve_type, type_code, cover_img, source_from, show_state
    </sql>
    <!--查询单个-->
    <select id="getById" resultMap="ResourceRecomManageMap">
        select
          <include refid="Base_Column_List"/>
        from book.resource_recom_manage
        where id = #{id}
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into book.resource_recom_manage(serve_id, serve_name, serve_type, type_code, cover_img, source_from, show_state, create_time, create_user)
        values (#{serveId}, #{serveName}, #{serveType}, #{typeCode}, #{coverImg}, #{sourceFrom}, #{showState}, now(), #{createUser})
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update book.resource_recom_manage
        <set>
            <if test="serveId != null">
                serve_id = #{serveId},
            </if>
            <if test="serveName != null and serveName != ''">
                serve_name = #{serveName},
            </if>
            <if test="serveType != null and serveType != ''">
                serve_type = #{serveType},
            </if>
            <if test="typeCode != null and typeCode != ''">
                type_code = #{typeCode},
            </if>
            <if test="coverImg != null and coverImg != ''">
                cover_img = #{coverImg},
            </if>
            <if test="sourceFrom != null">
                source_from = #{sourceFrom},
            </if>
            <if test="showState != null">
                show_state = #{showState},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="createUser != null">
                create_user = #{createUser},
            </if>
        </set>
        where id = #{id}
    </update>

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

    <select id="deleteByServe" parameterType="map">
        DELETE
        from book.resource_recom_manage
        where serve_id = #{serveId}
        and source_from = #{sourceFrom}
        and serve_type = #{serveType}
    </select>

    <select id="mapResourceRecomManage" parameterType="map" resultMap="ResourceRecomManageMap">
        SELECT
	    <include refid="Base_Column_List"/>
        FROM
            resource_recom_manage
        WHERE
            serve_id IN
        <foreach collection="serveIds" index="index" separator="," item="item" close=")" open="(">
            #{item}
        </foreach>
        AND source_from = #{sourceFrom}
        AND serve_type = #{serveType}
    </select>
</mapper>