<?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.bonus.material.basic.mapper.BmNoticeInfoMapper">
    <resultMap type="com.bonus.material.basic.domain.BmNoticeInfo" id="BmNoticeInfoResult">
        <result property="id"    column="id"    />
        <result property="taskId"    column="task_id"    />
        <result property="content"    column="content"    />
        <result property="noticeUser"    column="notice_user"    />
        <result property="phone"    column="phone"    />
        <result property="modelName"    column="model_name"    />
        <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="remark"    column="remark"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>

    <sql id="selectBmNoticeInfoVo">
        select id, task_id, content, notice_user, phone, model_name, create_by, create_time, update_by, update_time, remark, company_id from bm_notice_info
    </sql>

    <select id="selectBmNoticeInfoList" parameterType="com.bonus.material.basic.domain.BmNoticeInfo" resultMap="BmNoticeInfoResult">
        <include refid="selectBmNoticeInfoVo"/>
        <where>  
            <if test="taskId != null "> and task_id = #{taskId}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="noticeUser != null "> and notice_user = #{noticeUser}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="modelName != null  and modelName != ''"> and model_name like concat('%', #{modelName}, '%')</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectBmNoticeInfoById" parameterType="Long" resultMap="BmNoticeInfoResult">
        <include refid="selectBmNoticeInfoVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBmNoticeInfo" parameterType="com.bonus.material.basic.domain.BmNoticeInfo" useGeneratedKeys="true" keyProperty="id">
        insert into bm_notice_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="content != null and content != ''">content,</if>
            <if test="noticeUser != null">notice_user,</if>
            <if test="phone != null">phone,</if>
            <if test="modelName != null">model_name,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="companyId != null">company_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null">#{taskId},</if>
            <if test="content != null and content != ''">#{content},</if>
            <if test="noticeUser != null">#{noticeUser},</if>
            <if test="phone != null">#{phone},</if>
            <if test="modelName != null">#{modelName},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="companyId != null">#{companyId},</if>
         </trim>
    </insert>

    <update id="updateBmNoticeInfo" parameterType="com.bonus.material.basic.domain.BmNoticeInfo">
        update bm_notice_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="content != null and content != ''">content = #{content},</if>
            <if test="noticeUser != null">notice_user = #{noticeUser},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="modelName != null">model_name = #{modelName},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBmNoticeInfoById" parameterType="Long">
        delete from bm_notice_info where id = #{id}
    </delete>

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