<?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.ApplyLicenseMapper">


    <sql id="baseColumn">
        id,
        shop_id,
        business_license,
        license_type,
        license_legal_person,
        credit_code,
        credit_url,
        license_address,
        issueTime,
        validity,
        id_card_positive_credit_url,
        id_card_negative_credit_url,
        food_business_license_code,
        main_business,
        operator,
        food_license_legal_person,
        business_project,
        food_license_address,
        food_business_start_time,
        food_business_end_time,
        food_business_license_url,
        remark,
        remark_url,
        submit_status,
        create_time,
        update_time,
        deleted
    </sql>
    <update id="updateByShopId">
        update xfsg_license_transact
        set submit_status = #{entity.submitStatus}
        where shop_id = #{entity.shopId}
    </update>


    <select id="licenseList" resultType="com.cool.store.response.LicenseListResponse">
        select
        o.shop_id as shopId,
        s.shop_name as storeName,
        s.store_num as storeNum,
        s.shop_manager_user_id as shopManagerUserId,
        l.username as franchiseeName,
        l.mobile as franchiseeMobile,
        l.region_id AS fightRegionId,
        l.investment_manager AS investmentManager,
        s.supervisor_user_id AS supervisorUserId,
        o.create_time as submitTime,
        o.submit_status as status
        FROM
        xfsg_license_transact o
        LEFT JOIN xfsg_shop_info s ON o.shop_id = s.id
        LEFT JOIN xfsg_line_info l ON l.id = s.line_id
        <where>
        o.deleted = 0
            <if test="userId != null and userId != ''">
                and s.supervisor_user_id = #{userId}
            </if>
            <if test="fightRegions != null">
                and l.region_id in
                <foreach item="regionId" collection="fightRegions" open="(" separator="," close=")">
                    #{regionId}
                </foreach>
            </if>
            <if test="request.storeName != null and request.storeName != ''">
                AND s.shop_name like concat('%',#{request.storeName},'%')
            </if>
            <if test="request.submitStartTime != null and request.submitEndTime">
                AND
                o.create_time BETWEEN
                FROM_UNIXTIME(#{request.submitStartTime} / 1000)
                AND FROM_UNIXTIME(#{request.submitEndTime} / 1000)

            </if>
            <if test="request.regionId != null and request.regionId != ''">
                AND l.region_id = #{request.regionId}
            </if>
            <if test="request.status != null">
                AND o.submit_status = #{request.status}
            </if>
        </where>


  </select>
    <select id="selectByShopId" resultType="com.cool.store.entity.LicenseTransactDO">
        select <include refid="baseColumn"/>
        from xfsg_license_transact
        where shop_id = #{shopId}
        and deleted = 0
    </select>
</mapper>