<?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.FranchiseFeeMapper">
    <update id="updateDataHandleServiceV25">
        update xfsg_franchise_fee
        set first_year_fee = "6000",
        first_year_manage_fee = "7200"
    </update>
    <update id="updateBill">
        <foreach collection="list" item="item" index="index" separator=";">
            update xfsg_franchise_fee
            <set>
                <if test="item.yearFranchiseFee !=null and item.yearFranchiseFee!=''">
                    year_franchise_fee = #{item.yearFranchiseFee},
                </if>
                <if test="item.firstYearManageFee !=null and item.firstYearManageFee!=''">
                    first_year_manage_fee = #{item.firstYearManageFee},
                </if>
                <if test="item.firstYearFee!=null and item.firstYearFee!=''">
                    first_year_fee= #{item.firstYearFee},
                </if>
                <if test="item.loanMargin !=null and item.loanMargin!=''">
                    loan_margin = #{item.loanMargin},
                </if>
                <if test="item.performanceBond !=null and item.performanceBond!=''">
                    performance_bond = #{item.performanceBond},
                </if>
                <if test="item.discountReason !=null and item.discountReason!=''">
                    discount_reason = #{item.discountReason},
                </if>
            </set>
            where shop_id = #{item.shopId}
        </foreach>
    </update>
    <update id="batchUpdateXgjCollectionStatus">
        update xfsg_franchise_fee
        set xgj_collection_status = #{collectionStatus}
        where shop_id in
        <foreach collection="shopIds" item="shopId" open="(" separator="," close=")">
            #{shopId}
        </foreach>
    </update>
    <update id="batchUpdateXgjCollectionStatusAndXgjFeesPaid">
        <foreach collection="list" separator=";" item="item">
            update xfsg_franchise_fee
            set xgj_collection_status = #{item.xgjCollectionStatus},
            xgj_fees_paid = #{item.xgjFeesPaid}
            where shop_id = #{item.shopId}
        </foreach>
    </update>

    <select id="selectByShopId" resultType="com.cool.store.entity.FranchiseFeeDO">
        select *
        from xfsg_franchise_fee
        where shop_id = #{shopId}
        order by create_time desc
        limit 1
    </select>
    <select id="getPayTimeByShopIds" resultType="com.cool.store.dto.FranchiseFeeDTO">
        select a.shop_id AS shopId ,
        b.pay_time as payTime,
        b.combined_field as combinedField,
        a.year_franchise_fee as yearFranchiseFee,
        a.first_year_manage_fee as firstYearManagementFee,
        a.loan_margin as loanMargin,
        a.first_year_start_time as firstYearStartTime,
        a.first_year_end_time as firstYearEndTime,
        a.first_year_fee as firstYearFee,
        a.performance_bond as performanceBond,
        b.pay_user_name as payUserName,
        a.discount_reason as discountReason
        from xfsg_franchise_fee a
        LEFT JOIN xfsg_line_pay b ON b.id = a.pay_id
        where a.shop_id in
        <foreach collection="shopIds" item="shopId" open="(" separator="," close=")">
            #{shopId}
        </foreach>
    </select>
    <select id="getFranchiseFeeByShopIds" resultType="com.cool.store.entity.FranchiseFeeDO">
        select *
        from xfsg_franchise_fee
        where shop_id in
        <foreach collection="shopIds" item="shopId" open="(" separator="," close=")">
            #{shopId}
        </foreach>
    </select>

</mapper>