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

    <select id="list" resultType="com.gree.mall.manager.bean.policy.PolicyVo">
        SELECT
        ${ex.selected}
        FROM policy a
        ${ex.query}
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            ORDER BY a.create_time DESC
        </if>
        ${ex.orderBy}
    </select>
    <select id="listAgreement" resultType="com.gree.mall.manager.bean.policy.AgreementVo">
        SELECT
        ${ex.selected}
        FROM agreement a
        ${ex.query}
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            ORDER BY a.create_time DESC
        </if>
        ${ex.orderBy}
    </select>
    <select id="listMailBoxRecord" resultType="com.gree.mall.manager.bean.policy.MailBoxSendRecordVo">
        SELECT
        ${ex.selected}
        FROM mailbox_send_record a
        ${ex.query}
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            ORDER BY a.create_time DESC
        </if>
        ${ex.orderBy}
    </select>
    <select id="listPolicy" resultType="com.gree.mall.manager.bean.policy.MailboxSendRecordPolicyVo">
        SELECT
        ${ex.selected}
        FROM mailbox_send_record_policy a
        ${ex.query}
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            ORDER BY a.create_time DESC
        </if>
        ${ex.orderBy}
    </select>
    <select id="listPolicyOrder" resultType="com.gree.mall.manager.bean.policy.PolicyOrderVO">
        SELECT
        ${ex.selected}
        FROM policy_order a
        ${ex.query}
        and a.type = 'AC'
        and a.is_pay = 'YES'
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.adminWebsitIds != null and ex.adminWebsitIds.size > 0">
            AND a.websit_id IN
            <foreach item="item" index="index" collection="ex.adminWebsitIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            ORDER BY a.create_time DESC
        </if>
        ${ex.orderBy}
    </select>
    <select id="listEm" resultType="com.gree.mall.manager.bean.policy.PolicyOrderEmVO">
        SELECT
        ${ex.selected}
        FROM policy_order a
        ${ex.query}
        and a.type = 'EM'
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.adminWebsitIds != null and ex.adminWebsitIds.size > 0">
            AND a.websit_id IN
            <foreach item="item" index="index" collection="ex.adminWebsitIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            ORDER BY a.create_time DESC
        </if>
        ${ex.orderBy}
    </select>
    <select id="listIn" resultType="com.gree.mall.manager.bean.policy.PolicyOrderInVO">
        SELECT
        ${ex.selected}
        FROM policy_order a
        ${ex.query}
        and a.type = 'IN'
        <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.adminWebsitIds != null and ex.adminWebsitIds.size > 0">
            AND a.websit_id IN
            <foreach item="item" index="index" collection="ex.adminWebsitIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            ORDER BY a.create_time DESC
        </if>
        ${ex.orderBy}
    </select>
</mapper>