<?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.ghy.worker.mapper.WorkerBankMapper">

    <resultMap id="WorkerBankResult" type="com.ghy.worker.domain.WorkerBank">
        <result property="workerBankId" column="worker_bank_id"/>
        <result property="settleAccountId" column="settle_account_id"/>
        <result property="workerId" column="worker_id"/>
        <result property="name" column="name"/>
        <result property="certId" column="cert_id"/>
        <result property="bankName" column="bank_name"/>
        <result property="bankNum" column="bank_num"/>
        <result property="phone" column="phone"/>
        <result property="deptId" column="dept_id"/>
        <result property="adapayMemberId" column="adapay_member_id"/>
        <result property="settleAccount" column="settle_account"/>
        <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"/>
    </resultMap>

    <insert id="insertWorkerBank" parameterType="com.ghy.worker.domain.WorkerBank" useGeneratedKeys="true"
            keyProperty="workerBankId">
        INSERT INTO worker_bank( settle_account_id,
        <if test="workerId != null and workerId != 0">worker_id,</if>
        <if test="name != null and name != ''">name,</if>
        <if test="certId != null and certId != ''">cert_id,</if>
        <if test="bankName != null and bankName != ''">bank_name,</if>
        <if test="bankNum != null and bankNum != ''">bank_num,</if>
        <if test="phone != null and phone != ''">phone,</if>
        <if test="deptId != null and deptId != 0">dept_id,</if>
        <if test="adapayMemberId != null and adapayMemberId != ''">adapay_member_id,</if>
        <if test="settleAccount != null">settle_account,</if>
        <if test="createBy != null and createBy != ''">create_by,</if>
        <if test="remark != null and remark != ''">remark,</if>
        create_time
        )VALUES( #{settleAccountId},
        <if test="workerId != null and workerId != 0">#{workerId},</if>
        <if test="name != null and name != ''">#{name},</if>
        <if test="certId != null and certId != ''">#{certId},</if>
        <if test="bankName != null and bankName != ''">#{bankName},</if>
        <if test="bankNum != null and bankNum != ''">#{bankNum},</if>
        <if test="phone != null and phone != ''">#{phone},</if>
        <if test="deptId != null and deptId != 0">#{deptId},</if>
        <if test="adapayMemberId != null and adapayMemberId != ''">#{adapayMemberId},</if>
        <if test="settleAccount != null">#{settleAccount},</if>
        <if test="createBy != null and createBy != ''">#{createBy},</if>
        <if test="remark != null and remark != ''">#{remark},</if>
        sysdate()
        )
    </insert>

    <update id="updateByMemberId" parameterType="com.ghy.worker.domain.WorkerBank">
        UPDATE worker_bank
        <set>
            <if test="phone != null and phone != ''">phone = #{phone},</if>
            <if test="bankNum != null and bankNum != ''">bank_num = #{bankNum},</if>
            <if test="settleAccountId != null and settleAccountId != ''">settle_account_id = #{settleAccountId},</if>
            update_time = NOW()
        </set>
        WHERE adapay_member_id = #{adapayMemberId}
    </update>

    <select id="getByWorkerId" parameterType="Long" resultMap="WorkerBankResult">
        SELECT *
        FROM worker_bank
        <where>
            <if test="workerId != null and workerId != 0">
                and worker_id = #{workerId}
            </if>
        </where>
    </select>

    <select id="getByMemberId" parameterType="String" resultMap="WorkerBankResult">
        SELECT *
        FROM worker_bank
        WHERE adapay_member_id = #{adapayMemberId}
    </select>

    <select id="getByWorkerIds" resultMap="WorkerBankResult">
        SELECT *
        FROM worker_bank
        WHERE worker_id in (#{ids})
    </select>

    <select id="select" resultMap="WorkerBankResult">
        SELECT *
        FROM worker_bank
    </select>

</mapper>
