<?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.fjs.scenic.mapper.scenic.PicsMapper">
    <resultMap id="BaseResultMap" type="com.fjs.scenic.entity.scenic.Pics">
        <id column="id" jdbcType="INTEGER" property="id" />
		<result column="url" jdbcType="VARCHAR" property="url" />
		<result column="type" jdbcType="TINYINT" property="type" />
		<result column="fid" jdbcType="INTEGER" property="fid" />
    </resultMap>
    <sql id="Base_Column_List">
    id, url, type, fid
  </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from pics
        where id = #{id,jdbcType=INTEGER}
    </select>
    <select id="selectParam" resultMap="BaseResultMap" parameterType="java.util.Map">
        select
		<if test="field != null and field != ''"> ${field}</if>
		<if test="field == null or field == ''"> * </if>
		from pics
		<if test="param != null and param != ''">where ${param}</if>
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from pics
    where id = #{id,jdbcType=INTEGER}
  </delete>
    <insert id="insert" parameterType="com.fjs.scenic.entity.scenic.Pics">
    insert into pics (id, url, type, 
      fid)
    values (#{id,jdbcType=INTEGER}, #{url,jdbcType=VARCHAR}, #{type,jdbcType=TINYINT}, 
      #{fid,jdbcType=INTEGER})
  </insert>
    <insert id="insertSelective" parameterType="com.fjs.scenic.entity.scenic.Pics">
        insert into pics
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="url != null">
                url,
            </if>
            <if test="type != null">
                type,
            </if>
            <if test="fid != null">
                fid,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="url != null">
                #{url,jdbcType=VARCHAR},
            </if>
            <if test="type != null">
                #{type,jdbcType=TINYINT},
            </if>
            <if test="fid != null">
                #{fid,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.fjs.scenic.entity.scenic.Pics">
        update pics
        <set>
            <if test="url != null">
                url = #{url,jdbcType=VARCHAR},
            </if>
            <if test="type != null">
                type = #{type,jdbcType=TINYINT},
            </if>
            <if test="fid != null">
                fid = #{fid,jdbcType=INTEGER},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.fjs.scenic.entity.scenic.Pics">
    update pics
    set url = #{url,jdbcType=VARCHAR},
      type = #{type,jdbcType=TINYINT},
      fid = #{fid,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>

    <!--手动-->
    <update id="updateByFid" parameterType="com.fjs.scenic.entity.scenic.Pics">
        update pics
        <set>
            <if test="url != null">
                url = #{url,jdbcType=VARCHAR},
            </if>
            <if test="type != null">
                type = #{type,jdbcType=TINYINT},
            </if>
            <if test="fid != null">
                fid = #{fid,jdbcType=INTEGER},
            </if>
        </set>
        where fid = #{fid,jdbcType=INTEGER}
    </update>

    <select id="selectByFid" resultMap="BaseResultMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from pics
        where fid = #{fid,jdbcType=INTEGER}
    </select>

    <select id="getIndexPicAndCount" resultType="map" parameterType="java.lang.Integer">
  	SELECT COUNT(1) count,min(url) picUrl FROM pics WHERE fid=#{fid,jdbcType=INTEGER}
  </select>

    <delete id="deleteByFid" parameterType="java.lang.Integer">
    delete from pics
    where fid = #{fid,jdbcType=INTEGER}
  </delete>

    <insert id="adds" parameterType="java.util.List">
        insert into pics (id, url, type,
        fid) values
        <foreach collection="list" item="r" index="index" separator=",">
            (#{r.id,jdbcType=INTEGER}, #{r.url,jdbcType=VARCHAR}, #{r.type,jdbcType=TINYINT},
            #{r.fid,jdbcType=INTEGER})
        </foreach>
    </insert>

</mapper>