<?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.ytpm.middle.dao.EnterpriseMapper">

    <insert id="insertOne" useGeneratedKeys="true" keyProperty="enterpriseId">
        insert into yt_middle_enterprise
            (
             user_id,
             enterprise_name,
             enterprise_type,
             credit_code,
             legal,
             legal_card,
             concat_phone,
             business_licence,
             registry_address,
             taku_public_key,
             has_fast,
             create_time,
             create_user_id,
             available
            )
            values
            (
             #{userId},
             #{enterpriseName},
             #{enterpriseType},
             #{creditCode},
             #{legal},
             #{legalCard},
             #{concatPhone},
             #{businessLicence},
             #{registryAddress},
             #{takuPublicKey},
             #{hasFast},
             #{createTime},
             #{createUserId},
             #{available}
            );
    </insert>
    <update id="updateById">
        update yt_middle_enterprise
        <set>
            <if test="enterpriseName != null">
                enterprise_name = #{enterpriseName},
            </if>
            <if test="enterpriseType != null">
                enterprise_type = #{enterpriseType},
            </if>
            <if test="creditCode != null">
                credit_code = #{creditCode},
            </if>
            <if test="legal != null">
                legal = #{legal},
            </if>
            <if test="legalCard != null">
                legal_card = #{legalCard},
            </if>
            <if test="concatPhone != null">
                concat_phone = #{concatPhone},
            </if>
            <if test="businessLicence != null">
                business_licence = #{businessLicence},
            </if>
            <if test="registryAddress != null">
                registry_address = #{registryAddress},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="updateUserId != null">
                update_user_id = #{updateUserId},
            </if>
            <if test="takuPublicKey != null">
                taku_public_key = #{takuPublicKey},
            </if>
            <if test="paymentDate != null">
                payment_date = #{paymentDate},
            </if>
            <if test="sharingRatio != null">
                sharing_ratio = #{sharingRatio},
            </if>
            <if test="available != null">
                available = #{available}
            </if>
        </set>
        where enterprise_id = #{enterpriseId}
    </update>

    <select id="getByCode" resultType="com.ytpm.middle.model.YtMiddleEnterprise">
        select
            enterprise_id,taku_public_key, user_id, enterprise_name,enterprise_type, credit_code, legal, legal_card, concat_phone, business_licence, registry_address, create_time, create_user_id, update_time, update_user_id, available
        from yt_middle_enterprise
        where credit_code = #{creditCode}
    </select>
    <select id="countEnterprise" resultType="java.lang.Integer">
        select
            count(credit_code)
        from yt_middle_enterprise
        where available = 1
    </select>
    <select id="selectPrimary" resultType="com.ytpm.middle.model.YtMiddleEnterprise">
        select
            enterprise_id, user_id, enterprise_name, enterprise_type, credit_code, legal, legal_card, concat_phone, business_licence, registry_address, logo, has_fast, sharing_ratio, payment_date, create_time, create_user_id, update_time, update_user_id, available, taku_public_key
        from yt_middle_enterprise
        where enterprise_id = #{enterpriseId}
    </select>
</mapper>