<?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.fs.company.mapper.CompanyProfitLogsMapper">
    
    <resultMap type="CompanyProfitLogs" id="CompanyProfitLogsResult">
        <result property="logsId"    column="logs_id"    />
        <result property="profitId"    column="profit_id"    />
        <result property="title"    column="title"    />
        <result property="reason"    column="reason"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectCompanyProfitLogsVo">
        select logs_id, profit_id, title, reason, create_time from company_profit_logs
    </sql>

    <select id="selectCompanyProfitLogsList" parameterType="CompanyProfitLogs" resultMap="CompanyProfitLogsResult">
        <include refid="selectCompanyProfitLogsVo"/>
        <where>  
            <if test="profitId != null "> and profit_id = #{profitId}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="reason != null  and reason != ''"> and reason = #{reason}</if>
        </where>
        order by logs_id desc
    </select>
    
    <select id="selectCompanyProfitLogsById" parameterType="Long" resultMap="CompanyProfitLogsResult">
        <include refid="selectCompanyProfitLogsVo"/>
        where logs_id = #{logsId}
    </select>
        
    <insert id="insertCompanyProfitLogs" parameterType="CompanyProfitLogs" useGeneratedKeys="true" keyProperty="logsId">
        insert into company_profit_logs
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="profitId != null">profit_id,</if>
            <if test="title != null">title,</if>
            <if test="reason != null">reason,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="profitId != null">#{profitId},</if>
            <if test="title != null">#{title},</if>
            <if test="reason != null">#{reason},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateCompanyProfitLogs" parameterType="CompanyProfitLogs">
        update company_profit_logs
        <trim prefix="SET" suffixOverrides=",">
            <if test="profitId != null">profit_id = #{profitId},</if>
            <if test="title != null">title = #{title},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where logs_id = #{logsId}
    </update>

    <delete id="deleteCompanyProfitLogsById" parameterType="Long">
        delete from company_profit_logs where logs_id = #{logsId}
    </delete>

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