<?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.ym.mec.biz.dal.dao.HfMemberDao">
    <resultMap id="hfMember" type="com.ym.mec.biz.dal.entity.HfMember">
        <id column="id_" property="id"/>
        <result column="name_" property="name"/>
        <result column="member_id_" property="memberId"/>
        <result column="prov_code_" property="provCode"/>
        <result column="area_code_" property="areaCode"/>
        <result column="social_credit_code_" property="socialCreditCode"/>
        <result column="social_credit_code_expires_" property="socialCreditCodeExpires"/>
        <result column="business_scope_" property="businessScope"/>
        <result column="legal_person_" property="legalPerson"/>
        <result column="legal_cert_id_" property="legalCertId"/>
        <result column="legal_cert_id_expires_" property="legalCertIdExpires"/>
        <result column="legal_mp_" property="legalMp"/>
        <result column="address_" property="address"/>
        <result column="zip_code_" property="zipCode"/>
        <result column="card_no_" property="cardNo"/>
        <result column="bank_code_" property="bankCode"/>
        <result column="settle_account_id_" property="settleAccountId"/>
        <result column="status_" property="status"/>
        <result column="memo_" property="memo"/>
        <result column="month_max_receipt_" property="monthMaxReceipt"/>
        <result column="route_member_id_" property="routeMemberId"/>
        <result column="route_organ_id_" property="routeOrganId"/>
        <result column="create_time_" property="createTime"/>
        <result column="update_time_" property="updateTime"/>
        <result column="organ_id_" property="organId"/>
		<result column="tenant_id_" property="tenantId" />
		<result column="bank_acct_type_" property="bankAcctType" />
		<result column="card_name_" property="cardName" />
    </resultMap>
    <sql id="Base_Column_List">
        <!--@mbg.generated-->
        id_, name_, member_id_, prov_code_, area_code_, social_credit_code_, social_credit_code_expires_,
        business_scope_, legal_person_, legal_cert_id_, legal_cert_id_expires_, legal_mp_,
        address_, zip_code_, card_no_,
        bank_code_,settle_account_id_,status_,month_max_receipt_,route_member_id_,route_organ_id_, create_time_,
        update_time_,tenant_id_,organ_id_,bank_acct_type_,card_name_
    </sql>
    <select id="get" parameterType="java.lang.Integer" resultMap="hfMember">
        <!--@mbg.generated-->
        select
        <include refid="Base_Column_List"/>
        from hf_member
        where id_ = #{id,jdbcType=INTEGER}
    </select>
    <delete id="delete" parameterType="java.lang.Integer">
        <!--@mbg.generated-->
        delete from hf_member
        where id_ = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insert" keyColumn="id_" keyProperty="id" parameterType="com.ym.mec.biz.dal.entity.HfMember"
            useGeneratedKeys="true">
        <!--@mbg.generated-->
        insert into hf_member (name_, member_id_, prov_code_,
        area_code_, social_credit_code_, social_credit_code_expires_,
        business_scope_, legal_person_, legal_cert_id_,
        legal_cert_id_expires_, legal_mp_, address_,
        zip_code_, card_no_, bank_code_,status_,
        create_time_, update_time_,organ_id_,tenant_id_,bank_acct_type_,card_name_)
        values (#{name}, #{memberId}, #{provCode},
        #{areaCode}, #{socialCreditCode}, #{socialCreditCodeExpires},
        #{businessScope}, #{legalPerson}, #{legalCertId},
        #{legalCertIdExpires}, #{legalMp}, #{address},
        #{zipCode}, #{cardNo}, #{bankCode},#{status},
        #{createTime}, #{updateTime},#{organId},#{tenantId},#{bankAcctType},#{cardName})
    </insert>
    <update id="update" parameterType="com.ym.mec.biz.dal.entity.HfMember">
        <!--@mbg.generated-->
        update hf_member
        <set>
            <if test="name != null">
                name_ = #{name},
            </if>
            <if test="memberId != null">
                member_id_ = #{memberId},
            </if>
            <if test="provCode != null">
                prov_code_ = #{provCode},
            </if>
            <if test="areaCode != null">
                area_code_ = #{areaCode},
            </if>
            <if test="socialCreditCode != null">
                social_credit_code_ = #{socialCreditCode},
            </if>
            <if test="socialCreditCodeExpires != null">
                social_credit_code_expires_ = #{socialCreditCodeExpires},
            </if>
            <if test="businessScope != null">
                business_scope_ = #{businessScope},
            </if>
            <if test="legalPerson != null">
                legal_person_ = #{legalPerson},
            </if>
            <if test="legalCertId != null">
                legal_cert_id_ = #{legalCertId},
            </if>
            <if test="legalCertIdExpires != null">
                legal_cert_id_expires_ = #{legalCertIdExpires},
            </if>
            <if test="legalMp != null">
                legal_mp_ = #{legalMp},
            </if>
            <if test="address != null">
                address_ = #{address},
            </if>
            <if test="zipCode != null">
                zip_code_ = #{zipCode},
            </if>
            <if test="cardNo != null">
                card_no_ = #{cardNo},
            </if>
            <if test="bankAcctType != null">
                bank_acct_type_ = #{bankAcctType},
            </if>
            <if test="cardName != null">
                card_name_ = #{cardName},
            </if>
            <if test="bankCode != null">
                bank_code_ = #{bankCode},
            </if>
            <if test="settleAccountId != null">
                settle_account_id_ = #{settleAccountId},
            </if>
            <if test="memo != null">
                memo_ = #{memo},
            </if>
            <if test="status != null">
                status_ = #{status},
            </if>
            <if test="monthMaxReceipt != null">
                month_max_receipt_ = #{monthMaxReceipt},
            </if>
            <if test="routeMemberId != null">
                route_member_id_ = #{routeMemberId},
            </if>
            <if test="routeOrganId != null">
                route_organ_id_ = #{routeOrganId},
            </if>
            <if test="createTime != null">
                create_time_ = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time_ = #{updateTime},
            </if>
            <if test="organId != null">
                organ_id_ = #{organId},
            </if>
        </set>
        where id_ = #{id,jdbcType=INTEGER} and tenant_id_ = #{tenantId}
    </update>

    <!-- 分页查询 -->
    <select id="queryPage" resultMap="hfMember" parameterType="map">
        SELECT * FROM hf_member
        <include refid="queryPageSql"/>
        ORDER BY id_
        <include refid="global.limit"/>
    </select>

    <sql id="queryPageSql">
        <where>
        	tenant_id_ = #{tenantId}
            <if test="name != null">
                AND name_ LIKE CONCAT( '%', #{name}, '%' )
            </if>
            <if test="memberId != null">
                AND member_id_ = #{memberId}
            </if>
            <if test="status != null">
                AND status_ = #{status}
            </if>
            <if test="organId != null">
                AND organ_id_ = #{organId}
            </if>
        </where>
    </sql>

    <!-- 查询当前表的总记录数 -->
    <select id="queryCount" resultType="int">
        SELECT COUNT(*) FROM hf_member
        <include refid="queryPageSql"/>
    </select>

    <select id="getByMemberId" resultMap="hfMember">
        SELECT *
        FROM hf_member
        WHERE member_id_ = #{memberId}
        LIMIT 1
    </select>

    <select id="getByName" resultMap="hfMember">
        SELECT *
        FROM hf_member
        WHERE name_ = #{name}
        LIMIT 1
    </select>

</mapper>