<?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.NoticeSupplyMapper">
    
    <resultMap type="NoticeSupply" id="NoticeSupplyResult">
        <result property="id"    column="id"    />
        <result property="typeId"    column="type_id"    />
        <result property="typeName"    column="name"    />
        <result property="merchantId"    column="merchant_id"    />
        <result property="supplyTitle"    column="supply_title"    />
        <result property="supplyDetails"    column="supply_details"    />
        <result property="manufacturer"    column="manufacturer"    />
        <result property="contacts"    column="contacts"    />
        <result property="telephone"    column="telephone"    />
        <result property="releaseTime"    column="release_time"    />
        <result property="picture"    column="picture"    />
        <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="selectNoticeSupplyVo">
SELECT
  n.id,
  type_id,
  t.`name`,
  merchant_id,
  supply_title,
  supply_details,
  manufacturer,
  contacts,
  telephone,
  release_time,
  picture,
  `status`,
  n.create_by,
  n.create_time,
  n.update_by,
  n.update_time,
  n.del_flag,
  n.remark
FROM
  notice_supply AS n
  LEFT JOIN goods_type AS t ON n.`type_id` = t.`id`
  </sql>

    <select id="selectNoticeSupplyList" parameterType="NoticeSupply" resultMap="NoticeSupplyResult">
        <include refid="selectNoticeSupplyVo"/>
        <where>  
            <if test="typeId != null "> and type_id = #{typeId}</if>
            <if test="merchantId != null "> and merchant_id = #{merchantId}</if>
            <if test="supplyTitle != null  and supplyTitle != ''"> and supply_title = #{supplyTitle}</if>
            <if test="supplyDetails != null  and supplyDetails != ''"> and supply_details = #{supplyDetails}</if>
            <if test="manufacturer != null  and manufacturer != ''"> and manufacturer = #{manufacturer}</if>
            <if test="contacts != null  and contacts != ''"> and contacts = #{contacts}</if>
            <if test="telephone != null  and telephone != ''"> and telephone = #{telephone}</if>
            <if test="releaseTime != null "> and release_time = #{releaseTime}</if>
            <if test="picture != null  and picture != ''"> and picture = #{picture}</if>
            <if test="status != null  and status != ''"> and n.status = #{status}</if>
        </where>
    </select>
    
    <select id="selectNoticeSupplyById" parameterType="Long" resultMap="NoticeSupplyResult">
        <include refid="selectNoticeSupplyVo"/>
        where n.id = #{id}
    </select>
        
    <insert id="insertNoticeSupply" parameterType="NoticeSupply" useGeneratedKeys="true" keyProperty="id">
        insert into notice_supply
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="typeId != null ">type_id,</if>
            <if test="merchantId != null ">merchant_id,</if>
            <if test="supplyTitle != null  and supplyTitle != ''">supply_title,</if>
            <if test="supplyDetails != null  and supplyDetails != ''">supply_details,</if>
            <if test="manufacturer != null  and manufacturer != ''">manufacturer,</if>
            <if test="contacts != null  and contacts != ''">contacts,</if>
            <if test="telephone != null  and telephone != ''">telephone,</if>
            <if test="releaseTime != null ">release_time,</if>
            <if test="picture != null  and picture != ''">picture,</if>
            <if test="status != null  and status != ''">status,</if>
            <if test="createBy != null  and createBy != ''">create_by,</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="typeId != null ">#{typeId},</if>
            <if test="merchantId != null ">#{merchantId},</if>
            <if test="supplyTitle != null  and supplyTitle != ''">#{supplyTitle},</if>
            <if test="supplyDetails != null  and supplyDetails != ''">#{supplyDetails},</if>
            <if test="manufacturer != null  and manufacturer != ''">#{manufacturer},</if>
            <if test="contacts != null  and contacts != ''">#{contacts},</if>
            <if test="telephone != null  and telephone != ''">#{telephone},</if>
            <if test="releaseTime != null ">#{releaseTime},</if>
            <if test="picture != null  and picture != ''">#{picture},</if>
            <if test="status != null  and status != ''">#{status},</if>
            <if test="createBy != null  and createBy != ''">#{createBy},</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="updateNoticeSupply" parameterType="NoticeSupply">
        update notice_supply
        <trim prefix="SET" suffixOverrides=",">
            <if test="typeId != null ">type_id = #{typeId},</if>
            <if test="merchantId != null ">merchant_id = #{merchantId},</if>
            <if test="supplyTitle != null  and supplyTitle != ''">supply_title = #{supplyTitle},</if>
            <if test="supplyDetails != null  and supplyDetails != ''">supply_details = #{supplyDetails},</if>
            <if test="manufacturer != null  and manufacturer != ''">manufacturer = #{manufacturer},</if>
            <if test="contacts != null  and contacts != ''">contacts = #{contacts},</if>
            <if test="telephone != null  and telephone != ''">telephone = #{telephone},</if>
            <if test="releaseTime != null ">release_time = #{releaseTime},</if>
            <if test="picture != null  and picture != ''">picture = #{picture},</if>
            <if test="status != null  and status != ''">status = #{status},</if>
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</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="deleteNoticeSupplyById" parameterType="Long">
        delete from notice_supply where id = #{id}
    </delete>

    <delete id="deleteNoticeSupplyByIds" parameterType="String">
        delete from notice_supply where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>


    <select id="getSupplyInfoTenList" resultMap="NoticeSupplyResult">
        select id,
        type_id,
        supply_title,
        release_time
        from notice_supply
        order by release_time desc limit 0,10

    </select>
    
</mapper>