<?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.cool.store.mapper.IntentAgreementMapper">
    <resultMap id="BaseResultMap" type="com.cool.store.entity.SigningBaseInfoDO">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="partner_id" jdbcType="VARCHAR" property="partnerId" />
        <result column="line_id" jdbcType="BIGINT" property="lineId" />
        <result column="sign_name" jdbcType="VARCHAR" property="signName" />
        <result column="mobile" jdbcType="VARCHAR" property="mobile" />
        <result column="sex" jdbcType="TINYINT" property="sex" />
        <result column="id_card_front" jdbcType="VARCHAR" property="idCardFront" />
        <result column="id_card_reverse" jdbcType="VARCHAR" property="idCardReverse" />
        <result column="id_card_no" jdbcType="VARCHAR" property="idCardNo" />
        <result column="id_card_address" jdbcType="VARCHAR" property="idCardAddress" />
        <result column="current_residence" jdbcType="VARCHAR" property="currentResidence" />
        <result column="address_detail" jdbcType="VARCHAR" property="addressDetail" />
        <result column="business_license" jdbcType="VARCHAR" property="businessLicense" />
        <result column="business_license_code" jdbcType="VARCHAR" property="businessLicenseCode" />
        <result column="business_license_address" jdbcType="VARCHAR" property="businessLicenseAddress" />
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
        <result column="deleted" jdbcType="TINYINT" property="deleted"/>
        <result column="audit_id" jdbcType="BIGINT" property="auditId"/>
    </resultMap>
    <sql id="Base_Column_List">
        id,
        partner_id,
        line_id,
        sign_name,
        mobile,
        sex,
        id_card_front,
        id_card_reverse,
        id_card_no,
        id_card_address,
        current_residence,
        address_detail,
        business_license,
        business_license_code,
        business_license_address,
        create_time,
        update_time,
        deleted,
        audit_id
  </sql>
    <insert id="insert" parameterType="com.cool.store.entity.SigningBaseInfoDO" useGeneratedKeys="true" keyProperty="id">
        insert into xfsg_signing_base_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="request.partnerId != null">partner_id,</if>
            <if test="request.lineId != null">line_id,</if>
            <if test="request.signName != null">sign_name,</if>
            <if test="request.mobile != null">mobile,</if>
            <if test="request.sex != null">sex,</if>
            <if test="request.idCardFront != null">id_card_front,</if>
            <if test="request.idCardReverse != null">id_card_reverse,</if>
            <if test="request.idCardNo != null">id_card_no,</if>
            <if test="request.idCardAddress != null">id_card_address,</if>
            <if test="request.currentResidence != null">current_residence,</if>
            <if test="request.addressDetail != null">address_detail,</if>
            <if test="request.businessLicense != null">business_license,</if>
            <if test="request.businessLicenseCode != null">business_license_code,</if>
            <if test="request.businessLicenseAddress != null">business_license_address,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="request.partnerId != null">#{request.partnerId},</if>
            <if test="request.lineId != null">#{request.lineId},</if>
            <if test="request.signName != null">#{request.signName},</if>
            <if test="request.mobile != null">#{request.mobile},</if>
            <if test="request.sex != null">#{request.sex},</if>
            <if test="request.idCardFront != null">#{request.idCardFront},</if>
            <if test="request.idCardReverse != null">#{request.idCardReverse},</if>
            <if test="request.idCardNo != null">#{request.idCardNo},</if>
            <if test="request.idCardAddress != null">#{request.idCardAddress},</if>
            <if test="request.currentResidence != null">#{request.currentResidence},</if>
            <if test="request.addressDetail != null">#{request.addressDetail},</if>
            <if test="request.businessLicense != null">#{request.businessLicense},</if>
            <if test="request.businessLicenseCode != null">#{request.businessLicenseCode},</if>
            <if test="request.businessLicenseAddress != null">#{request.businessLicenseAddress},</if>
        </trim>
        ON DUPLICATE KEY UPDATE
        <trim suffixOverrides=",">
            <if test="request.partnerId != null">partner_id = #{request.partnerId},</if>
            <if test="request.signName != null">sign_name = #{request.signName},</if>
            <if test="request.mobile != null">mobile = #{request.mobile},</if>
            <if test="request.sex != null">sex = #{request.sex},</if>
            <if test="request.idCardFront != null">id_card_front = #{request.idCardFront},</if>
            <if test="request.idCardReverse != null">id_card_reverse = #{request.idCardReverse},</if>
            <if test="request.idCardNo != null">id_card_no = #{request.idCardNo},</if>
            <if test="request.idCardAddress != null">id_card_address = #{request.idCardAddress},</if>
            <if test="request.currentResidence != null">current_residence = #{request.currentResidence},</if>
            <if test="request.addressDetail != null">address_detail = #{request.addressDetail},</if>
            <if test="request.businessLicense != null">business_license = #{request.businessLicense},</if>
            <if test="request.businessLicenseCode != null">business_license_code = #{request.businessLicenseCode},</if>
            <if test="request.businessLicenseAddress != null">business_license_address = #{request.businessLicenseAddress},</if>
        </trim>
    </insert>
    <update id="updateAuditId">
        update xfsg_signing_base_info
        set audit_id = #{auditId}
        where line_id = #{lineId}
    </update>
    <select id="selectByPartnerIdOrLineId" resultType="com.cool.store.entity.SigningBaseInfoDO">
        select
        <include refid="Base_Column_List"/>
        from xfsg_signing_base_info
        <where>
            deleted = 0
            <if test="partnerId != null and partnerId != ''">
                and partner_id = #{partnerId}
            </if>
            <if test="lineId != null">
                and line_id = #{lineId}
            </if>
        </where>
    </select>
    <select id="judge" resultType="com.cool.store.entity.SigningBaseInfoDO">
        SELECT
        <include refid="Base_Column_List"/>
        FROM xfsg_signing_base_info
        <where>
            deleted = 0
            <if test="request.idCardNo != null and request.idCardNo != ''">
                AND id_card_no = #{request.idCardNo}
            </if>
            <if test="request.businessLicenseCode != null and request.businessLicenseCode != ''">
                AND business_license_code = #{request.businessLicenseCode}
            </if>
        </where>
    </select>

    <select id="selectByLineIds" resultType="com.cool.store.entity.SigningBaseInfoDO">
        select
        <include refid="Base_Column_List"/>
        from xfsg_signing_base_info
        where deleted = 0
        <if test="lineIds !=null and lineIds.size>0">
            <foreach collection="lineIds" item="lineId" open="and line_id in (" close=")" separator=",">
                #{lineId}
            </foreach>
        </if>
    </select>

    <select id="selectByMobile" resultType="com.cool.store.entity.SigningBaseInfoDO">
        select
        <include refid="Base_Column_List"/>
        from xfsg_signing_base_info
        where deleted = 0
        <if test="mobile!=null and mobile!=''">
            and mobile = #{mobile}
        </if>
        <if test="idCard!=null and idCard!=''">
            and id_card_no = #{idCard}
        </if>
        limit 1
    </select>

</mapper>