<?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.CompanyDeductMapper">
    
    <resultMap type="CompanyDeduct" id="CompanyDeductResult">
        <result property="deductId"    column="deduct_id"    />
        <result property="deductNo"    column="deduct_no"    />
        <result property="companyId"    column="company_id"    />
        <result property="money"    column="money"    />
        <result property="balance"    column="balance"    />
        <result property="createTime"    column="create_time"    />
        <result property="createUserId"    column="create_user_id"    />
        <result property="isAudit"    column="is_audit"    />
        <result property="auditUserId"    column="audit_user_id"    />
        <result property="auditTime"    column="audit_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCompanyDeductVo">
        select deduct_id, deduct_no, company_id, money, balance, create_time, create_user_id, is_audit, audit_user_id, audit_time,remark from company_deduct
    </sql>

    <select id="selectCompanyDeductList" parameterType="CompanyDeduct" resultMap="CompanyDeductResult">
        <include refid="selectCompanyDeductVo"/>
        <where>  
            <if test="deductNo != null  and deductNo != ''"> and deduct_no = #{deductNo}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="money != null "> and money = #{money}</if>
            <if test="balance != null "> and balance = #{balance}</if>
            <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
            <if test="isAudit != null "> and is_audit = #{isAudit}</if>
            <if test="auditUserId != null "> and audit_user_id = #{auditUserId}</if>
            <if test="auditTime != null "> and audit_time = #{auditTime}</if>
        </where>
    </select>
    
    <select id="selectCompanyDeductById" parameterType="Long" resultMap="CompanyDeductResult">
        <include refid="selectCompanyDeductVo"/>
        where deduct_id = #{deductId}
    </select>
        
    <insert id="insertCompanyDeduct" parameterType="CompanyDeduct" useGeneratedKeys="true" keyProperty="deductId">
        insert into company_deduct
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deductNo != null">deduct_no,</if>
            <if test="companyId != null">company_id,</if>
            <if test="money != null">money,</if>
            <if test="balance != null">balance,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createUserId != null">create_user_id,</if>
            <if test="isAudit != null">is_audit,</if>
            <if test="auditUserId != null">audit_user_id,</if>
            <if test="auditTime != null">audit_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deductNo != null">#{deductNo},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="money != null">#{money},</if>
            <if test="balance != null">#{balance},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createUserId != null">#{createUserId},</if>
            <if test="isAudit != null">#{isAudit},</if>
            <if test="auditUserId != null">#{auditUserId},</if>
            <if test="auditTime != null">#{auditTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCompanyDeduct" parameterType="CompanyDeduct">
        update company_deduct
        <trim prefix="SET" suffixOverrides=",">
            <if test="deductNo != null">deduct_no = #{deductNo},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="money != null">money = #{money},</if>
            <if test="balance != null">balance = #{balance},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createUserId != null">create_user_id = #{createUserId},</if>
            <if test="isAudit != null">is_audit = #{isAudit},</if>
            <if test="auditUserId != null">audit_user_id = #{auditUserId},</if>
            <if test="auditTime != null">audit_time = #{auditTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where deduct_id = #{deductId}
    </update>

    <delete id="deleteCompanyDeductById" parameterType="Long">
        delete from company_deduct where deduct_id = #{deductId}
    </delete>

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