<?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.iamberry.wechat.service.mapper.ProspectusMapper">
    <resultMap  id="BaseResultMap" type="Prospectus" >
        <result    column="prospectus_id"    property="prospectusId" />
        <result    column="prospectus_code"    property="prospectusCode" />
        <result    column="prospectus_name"    property="prospectusName" />
        <result    column="prospectus_img"    property="prospectusImg" />
        <result    column="prospectus_status"    property="prospectusStatus" />
        <result    column="prospectus_time"    property="prospectusTime" />
        <result    column="prospectus_create_time"    property="prospectusCreateTime" />
    </resultMap>
    <sql    id="Base_List" >
        t.prospectus_id,
        t.prospectus_code,
        t.prospectus_name,
        t.prospectus_img,
        t.prospectus_status,
        t.prospectus_time,
        t.prospectus_create_time
    </sql>
    <select id="getProspectusList" resultMap="BaseResultMap" parameterType="Prospectus" >
        select
        <include refid="Base_List" />
        from tb_iamberry_prospectus t
        <where>
            <if test="prospectusId != null ">
                AND t.prospectus_id = #{prospectusId}
            </if >
            <if test="prospectusCode != null and prospectusCode != ''">
                AND t.prospectus_code  like  CONCAT ('%',#{prospectusCode},'%')
            </if >
            <if test="prospectusName != null and prospectusName != ''">
                AND t.prospectus_name  like  CONCAT ('%',#{prospectusName},'%')
            </if >
            <if test="prospectusStatus != null ">
                AND t.prospectus_status = #{prospectusStatus}
            </if >
        </where>
    </select>

    <select id="selectProspectusPage" resultMap="BaseResultMap" parameterType="Prospectus" >
        select
        <include refid="Base_List" />
        from tb_iamberry_prospectus t
        <where>
            <if test="prospectusId != null ">
                AND t.prospectus_id = #{prospectusId}
            </if >
            <if test="prospectusCode != null and prospectusCode != ''">
                AND t.prospectus_code  like  CONCAT ('%',#{prospectusCode},'%')
            </if >
            <if test="prospectusName != null and prospectusName != ''">
                AND t.prospectus_name  like  CONCAT ('%',#{prospectusName},'%')
            </if >
            <if test="prospectusStatus != null ">
                AND t.prospectus_status = #{prospectusStatus}
            </if >
        </where>
        ORDER BY t.prospectus_id DESC
        LIMIT #{bean.minNum},#{bean.maxNum}
    </select>

    <select id="selectProspectusCount" resultType="Integer" parameterType="Prospectus" >
        select
          COUNT(t.prospectus_id)
        from tb_iamberry_prospectus t
        <where>
            <if test="prospectusId != null ">
                AND t.prospectus_id = #{prospectusId}
            </if >
            <if test="prospectusCode != null and prospectusCode != ''">
                AND t.prospectus_code  like  CONCAT ('%',#{prospectusCode},'%')
            </if >
            <if test="prospectusName != null and prospectusName != ''">
                AND t.prospectus_name  like  CONCAT ('%',#{prospectusName},'%')
            </if >
            <if test="prospectusStatus != null ">
                AND t.prospectus_status = #{prospectusStatus}
            </if >
        </where>
    </select>

    <select id="getProspectusById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_prospectus t
        where t.prospectus_id= #{prospectusId}
    </select>

    <select id="getProspectusByCode" resultMap="BaseResultMap" parameterType="String" >
        select
        <include refid="Base_List" />
        from tb_iamberry_prospectus t
        where t.prospectus_code = #{prospectusCode}
    </select>

    <insert id="save" parameterType="Prospectus" >
        insert into
        tb_iamberry_prospectus
        (
        prospectus_code,
        prospectus_name,
        prospectus_img,
        prospectus_status,
        prospectus_time
        )
        values
        (
        #{prospectusCode},
        #{prospectusName},
        #{prospectusImg},
        #{prospectusStatus},
        #{prospectusTime}
        )
    </insert>
    <update id="update" parameterType="Prospectus" >
        update
        tb_iamberry_prospectus
        <set >
            <if test="prospectusCode != null and prospectusCode != ''">
                prospectus_code = #{prospectusCode},
            </if >
            <if test="prospectusName != null and prospectusName != ''">
                prospectus_name = #{prospectusName},
            </if >
            <if test="prospectusImg != null and prospectusImg != ''">
                prospectus_img = #{prospectusImg},
            </if >
            <if test="prospectusStatus != null ">
                prospectus_status = #{prospectusStatus},
            </if >
            <if test="prospectusTime != null and prospectusTime != ''">
                prospectus_time = #{prospectusTime},
            </if >
        </set >
        where prospectus_id= #{prospectusId}
    </update>
    <delete id="delete" parameterType="Integer" >
        delete FROM
        tb_iamberry_prospectus
        where prospectus_id=#{prospectusId}
    </delete>
</mapper>