<?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.gree.mall.manager.commonmapper.WebsitMapper">

    <select id="queryWebsitIds" resultType="com.gree.mall.manager.plus.entity.WebsitZone">
        select wz.* from
            admin_user_zone auz
                right join websit_zone wz on wz.admin_zone_id =auz.admin_zone_id
        where auz.admin_user_id = #{adminUserId}
    </select>

    <select id="queryWebsitNumbers" resultType="java.lang.String">
        select wz.websit_id from
            admin_user_zone auz
                right join websit_zone wz on wz.admin_zone_id =auz.admin_zone_id
        where auz.admin_user_id = #{adminUserId}
    </select>
    <select id="querySignStatus" resultType="com.gree.mall.manager.plus.entity.WebsitContractSignRecord">
        SELECT
            id, status, parent_id, websit_id, create_time, sign_over_time
        FROM
            websit_contract_sign_record
        WHERE
            id IN (
                SELECT
                    MAX(c.id) AS id
                FROM
                   contract_template a
                       JOIN websit_contract_sign_item b ON a.contract_template_id = b.contract_template_id
                       JOIN websit_contract_sign_record c ON b.websit_contract_sign_record_id = c.id
                WHERE
                    a.contract_type = 'MAIN'
                    AND a.contract_template_id = #{contractTemplateId}
                    <if test="subWebsitIds != null and subWebsitIds.size > 0">
                        AND c.websit_id IN
                        <foreach item="item" index="index" collection="subWebsitIds" open="(" separator="," close=")">
                            #{item}
                        </foreach>
                    </if>
                GROUP BY
                   c.contract_template_id, c.parent_id, c.websit_id
                )
        ORDER BY id DESC, create_time DESC
    </select>


</mapper>