<?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.dgtly.notice.mapper.NoticeDemandMapper">
    
    <resultMap type="NoticeDemand" id="NoticeDemandResult">
        <result property="id"    column="id"    />
        <result property="memberId"    column="member_id"    />
        <result property="purchaseTitle"    column="purchase_title"    />
        <result property="summaryOfNeeds"    column="summary_of_needs"    />
        <result property="demandDetails"    column="demand_details"    />
        <result property="contacts"    column="contacts"    />
        <result property="contactNumber"    column="contact_number"    />
        <result property="releaseTime"    column="release_time"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectNoticeDemandVo">
        select id, member_id, purchase_title, summary_of_needs, demand_details, contacts, contact_number, release_time, status, create_by, create_time, update_by, update_time, del_flag, remark from notice_demand
    </sql>

    <select id="selectNoticeDemandList" parameterType="NoticeDemand" resultMap="NoticeDemandResult">
        <include refid="selectNoticeDemandVo"/>
        <where>  
            <if test="memberId != null "> and member_id = #{memberId}</if>
            <if test="purchaseTitle != null  and purchaseTitle != ''"> and purchase_title = #{purchaseTitle}</if>
            <if test="summaryOfNeeds != null  and summaryOfNeeds != ''"> and summary_of_needs = #{summaryOfNeeds}</if>
            <if test="demandDetails != null  and demandDetails != ''"> and demand_details = #{demandDetails}</if>
            <if test="contacts != null  and contacts != ''"> and contacts = #{contacts}</if>
            <if test="contactNumber != null  and contactNumber != ''"> and contact_number = #{contactNumber}</if>
            <if test="releaseTime != null "> and release_time = #{releaseTime}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectNoticeDemandById" parameterType="Long" resultMap="NoticeDemandResult">
        <include refid="selectNoticeDemandVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertNoticeDemand" parameterType="NoticeDemand" useGeneratedKeys="true" keyProperty="id">
        insert into notice_demand
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="memberId != null ">member_id,</if>
            <if test="purchaseTitle != null  and purchaseTitle != ''">purchase_title,</if>
            <if test="summaryOfNeeds != null  and summaryOfNeeds != ''">summary_of_needs,</if>
            <if test="demandDetails != null  and demandDetails != ''">demand_details,</if>
            <if test="contacts != null  and contacts != ''">contacts,</if>
            <if test="contactNumber != null  and contactNumber != ''">contact_number,</if>
            <if test="releaseTime != null ">release_time,</if>
            <if test="status != null  and status != ''">status,</if>
            <if test="createBy != null  and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="updateBy != null  and updateBy != ''">update_by,</if>
            <if test="updateTime != null ">update_time,</if>
            <if test="delFlag != null  and delFlag != ''">del_flag,</if>
            <if test="remark != null  and remark != ''">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="memberId != null ">#{memberId},</if>
            <if test="purchaseTitle != null  and purchaseTitle != ''">#{purchaseTitle},</if>
            <if test="summaryOfNeeds != null  and summaryOfNeeds != ''">#{summaryOfNeeds},</if>
            <if test="demandDetails != null  and demandDetails != ''">#{demandDetails},</if>
            <if test="contacts != null  and contacts != ''">#{contacts},</if>
            <if test="contactNumber != null  and contactNumber != ''">#{contactNumber},</if>
            <if test="releaseTime != null ">#{releaseTime},</if>
            <if test="status != null  and status != ''">#{status},</if>
            <if test="createBy != null  and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null ">#{updateTime},</if>
            <if test="delFlag != null  and delFlag != ''">#{delFlag},</if>
            <if test="remark != null  and remark != ''">#{remark},</if>
         </trim>
    </insert>

    <update id="updateNoticeDemand" parameterType="NoticeDemand">
        update notice_demand
        <trim prefix="SET" suffixOverrides=",">
            <if test="memberId != null ">member_id = #{memberId},</if>
            <if test="purchaseTitle != null  and purchaseTitle != ''">purchase_title = #{purchaseTitle},</if>
            <if test="summaryOfNeeds != null  and summaryOfNeeds != ''">summary_of_needs = #{summaryOfNeeds},</if>
            <if test="demandDetails != null  and demandDetails != ''">demand_details = #{demandDetails},</if>
            <if test="contacts != null  and contacts != ''">contacts = #{contacts},</if>
            <if test="contactNumber != null  and contactNumber != ''">contact_number = #{contactNumber},</if>
            <if test="releaseTime != null ">release_time = #{releaseTime},</if>
            <if test="status != null  and status != ''">status = #{status},</if>
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
            <if test="delFlag != null  and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="remark != null  and remark != ''">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNoticeDemandById" parameterType="Long">
        delete from notice_demand where id = #{id}
    </delete>

    <delete id="deleteNoticeDemandByIds" parameterType="String">
        delete from notice_demand where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
    
    <select id="getDemandInfoTenList" resultMap="NoticeDemandResult">
        select id, member_id, purchase_title,release_time from notice_demand
        order by release_time desc limit 0,10

    </select>
    
</mapper>