<?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.CompanyProfitMapper">
    
    <resultMap type="CompanyProfit" id="CompanyProfitResult">
        <result property="profitId"    column="profit_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="bankName"    column="bank_name"    />
        <result property="bankBranchName"    column="bank_branch_name"    />
        <result property="bankCardNo"    column="bank_card_no"    />
        <result property="bankUserName"    column="bank_user_name"    />
        <result property="money"    column="money"    />
        <result property="balances"    column="balances"    />
        <result property="profitStatus"    column="profit_status"    />
        <result property="profitType"    column="profit_type"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="imgUrl"    column="img_url"    />
    </resultMap>

    <sql id="selectCompanyProfitVo">
        select profit_id, company_id, bank_name, bank_branch_name, bank_card_no, bank_user_name, money, balances, profit_status, profit_type, remark, create_time, update_time,img_url from company_profit
    </sql>

    <select id="selectCompanyProfitList" parameterType="CompanyProfit" resultMap="CompanyProfitResult">
        <include refid="selectCompanyProfitVo"/>
        <where>  
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="bankName != null  and bankName != ''"> and bank_name like concat('%', #{bankName}, '%')</if>
            <if test="bankBranchName != null  and bankBranchName != ''"> and bank_branch_name like concat('%', #{bankBranchName}, '%')</if>
            <if test="bankCardNo != null  and bankCardNo != ''"> and bank_card_no = #{bankCardNo}</if>
            <if test="bankUserName != null  and bankUserName != ''"> and bank_user_name like concat('%', #{bankUserName}, '%')</if>
            <if test="money != null "> and money = #{money}</if>
            <if test="balances != null "> and balances = #{balances}</if>
            <if test="profitStatus != null "> and profit_status = #{profitStatus}</if>
            <if test="profitType != null "> and profit_type = #{profitType}</if>
        </where>
    </select>
    
    <select id="selectCompanyProfitById" parameterType="Long" resultMap="CompanyProfitResult">
        <include refid="selectCompanyProfitVo"/>
        where profit_id = #{profitId}
    </select>
        
    <insert id="insertCompanyProfit" parameterType="CompanyProfit" useGeneratedKeys="true" keyProperty="profitId">
        insert into company_profit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="bankName != null">bank_name,</if>
            <if test="bankBranchName != null">bank_branch_name,</if>
            <if test="bankCardNo != null">bank_card_no,</if>
            <if test="bankUserName != null">bank_user_name,</if>
            <if test="money != null">money,</if>
            <if test="balances != null">balances,</if>
            <if test="profitStatus != null">profit_status,</if>
            <if test="profitType != null">profit_type,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="imgUrl != null">img_url,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="bankName != null">#{bankName},</if>
            <if test="bankBranchName != null">#{bankBranchName},</if>
            <if test="bankCardNo != null">#{bankCardNo},</if>
            <if test="bankUserName != null">#{bankUserName},</if>
            <if test="money != null">#{money},</if>
            <if test="balances != null">#{balances},</if>
            <if test="profitStatus != null">#{profitStatus},</if>
            <if test="profitType != null">#{profitType},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="imgUrl != null">#{imgUrl},</if>
         </trim>
    </insert>

    <update id="updateCompanyProfit" parameterType="CompanyProfit">
        update company_profit
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="bankName != null">bank_name = #{bankName},</if>
            <if test="bankBranchName != null">bank_branch_name = #{bankBranchName},</if>
            <if test="bankCardNo != null">bank_card_no = #{bankCardNo},</if>
            <if test="bankUserName != null">bank_user_name = #{bankUserName},</if>
            <if test="money != null">money = #{money},</if>
            <if test="balances != null">balances = #{balances},</if>
            <if test="profitStatus != null">profit_status = #{profitStatus},</if>
            <if test="profitType != null">profit_type = #{profitType},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="imgUrl != null">img_url = #{imgUrl},</if>
        </trim>
        where profit_id = #{profitId}
    </update>

    <delete id="deleteCompanyProfitById" parameterType="Long">
        delete from company_profit where profit_id = #{profitId}
    </delete>

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