<?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.SignFranchiseMapper">
    <update id="updateAuditByShopId">
        update xfsg_sign_franchise
        <set>
            <if test="auditId!=null">
                audit_id = #{auditId},
            </if>
            <if test="dto!=null">
                <if test="dto.infoConsistencyFlag != null">
                    info_consistency_flag = #{dto.infoConsistencyFlag},
                </if>
                <if test="dto.reason != null and dto.reason != ''">
                    reason = #{dto.reason},
                </if>
            </if>
        </set>
        where shop_id = #{shopId}
    </update>
    <update id="dateHandle">
        update xfsg_sign_franchise
        set sign_type = 1
    </update>
    <update id="updateSpecific">
        <foreach collection="list" separator=";" item ="item" index="index">
            update xfsg_sign_franchise
            <set>
                <if test="item.contractCode != null">
                    contract_code = #{item.contractCode},
                </if>
                <if test="item.contractStartTime != null">
                    contract_start_time = #{item.contractStartTime},
                </if>
                <if test="item.contractEndTime != null">
                    contract_end_time = #{item.contractEndTime},
                </if>
                <if test="item.partnershipSignatorySecond != null and item.partnershipSignatorySecond != ''">
                    partnership_signatory_second = #{item.partnershipSignatorySecond},
                </if>
                <if test="item.partnershipSignatorySecondIdNumber != null and item.partnershipSignatorySecondIdNumber!=''">
                    partnership_signatory_second_id_number = #{item.partnershipSignatorySecondIdNumber},
                </if>
                <if test="item.partnershipSignatorySecondMobile !=null and item.partnershipSignatorySecondMobile != '' ">
                    partnership_signatory_second_mobile = #{item.partnershipSignatorySecondMobile},
                </if>
                <if test="item.introductionAward !=null and item.introductionAward !=''">
                    introduction_award = #{item.introductionAward},
                </if>
                <if test="item.introduceStore !=null and item.introduceStore!=''">
                    introduce_store = #{item.introduceStore},
                </if>
                <if test="item.introducer!=null and item.introducer!=''">
                    introducer = #{item.introducer},
                </if>
                <if test="item.protectiveDistance!=null">
                    protective_distance = #{item.protectiveDistance},
                </if>
            </set>
            where shop_id = #{item.shopId}
        </foreach>
    </update>
    <select id="selectByShopId" resultType="com.cool.store.entity.SignFranchiseDO">
        select *
        from xfsg_sign_franchise
        where shop_id = #{shopId}
         order by create_time desc
        limit 1
    </select>
    <select id="selectByShopIds" resultType="com.cool.store.entity.SignFranchiseDO">
        select contract_code,shop_id,sign_type,contract_start_time,contract_end_time,contract_amount,create_time,
        partnership_signatory_first,partnership_signatory_second ,partnership_signatory_second_id_number,partnership_signatory_second_mobile,
        introduction_award,introduce_store,introducer,protective_distance,partnership_signatory_first_which_store
        from xfsg_sign_franchise
        where 1=1
        <if test="list !=null and list.size >0">
        and shop_id in
            <foreach collection="list" open="(" separator="," close=")" item="item" index="index">
             #{item}
            </foreach>
        </if>
    </select>
    <select id="selectAllByShopIds" resultType="com.cool.store.entity.SignFranchiseDO">
        select * from xfsg_sign_franchise
        where shop_id in
        <foreach collection="list" open="(" separator="," close=")" item="item" index="index">
            #{item}
        </foreach>
    </select>
    <select id="getSignType" resultType="com.cool.store.entity.SignFranchiseDO">
        select shop_id as shopId, sign_type as signType,partnership_signatory_second as partnershipSignatorySecond from xfsg_sign_franchise
        where
        shop_id in
        <foreach collection="list" separator="," item="item" index="index" open="(" close=")">
            #{item}
        </foreach>
    </select>
</mapper>