<?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="cn.com.countrygarden.bi.main.dao.domainname.DomainnameMapper">
    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.domainname.DomainName">
    </resultMap>
    <!--
      WARNING - @mbg.generated
    -->

    <select id="checkIsDomainAdmin" parameterType="java.lang.String" resultType="java.lang.Integer">
        SELECT count(id) AS c
        FROM user_roles
        WHERE user_code = #{userCode}
          AND role_code = 'domain_admin'
    </select>


    <!--序号	域名	域名券号	所有人	审核状态	域名申请日期	账户ID	操作-->
    <select id="getDomainnameList"
            resultMap="BaseResultMap">
        SELECT
        DISTINCT
        dm.`domain_id`,
        dm.`domain_name`,
        dm.`domain_coupon`,
        dm. `owner`,
        dm.`audit_status`,
        dm.`apply_date`,
        dm.`register_user`
        FROM
        domain_manager AS dm
        <where>
            1=1
        <!--choose-->
                <!--0-待审核 1-审核通过 2-审核未通过 3-草稿'-->
                <if test="userCode != null and userCode != ''">
                    <!--是管理员而非审核员
                管理员可查看：本人草稿状态的域名信息， 和有效状态的全部状态的域名信息。
            （usercode=登记人and audit_status=3  or (所有人的and audit_status！=3 )）-->
                    and ((dm.register_user = #{userCode}
                    and dm.audit_status=3) )or dm.audit_status!=3
                    <!--and dm.audit_status!=3-->
                 </if>
<!--                 <if test="userCode is null or userCode = ''">-->
<!--                     &lt;!&ndash;是审核员而非管理员,可查看所有已发布、待审核数据-->
<!--                         &ndash;&gt;-->
<!--                    and dm.audit_status in (0,1)-->
<!--                </if>-->
            <if test="userCode ==null or userCode=''">
                and dm.audit_status in (0,1)
            </if>
<!--                <otherwise>-->
<!--                </otherwise>-->
<!--          </choose>-->
            <!--域名（模糊匹配）	域名券号（模糊匹配） 所有人（模糊匹配）	审核状态（下拉)  域名申请日期（区间）-->

            <if test="domainName.domain_name != null and domainName.domain_name != ''">
                and dm.domain_name like CONCAT('%',#{domainName.domain_name},'%')
            </if>
            <if test="domainName.domain_coupon != null and domainName.domain_coupon != ''">
                and dm.domain_coupon like CONCAT('%',#{domainName.domain_coupon},'%')
            </if>
            <if test="domainName.owner  != null and domainName.owner != ''">
                and dm.owner like CONCAT('%',#{domainName.owner},'%')
            </if>
            <if test="domainName.audit_status != null and domainName.audit_status != ''">
                and dm.audit_status = #{domainName.audit_status}
            </if>
            <if test="timeMap.beginDate!=null and timeMap.beginDate!= ''">
                <![CDATA[
                   and dm.apply_date >= #{timeMap.beginDate}
                ]]>
            </if>
            <if test="timeMap.endDate!=null and timeMap.endDate!= ''">
                <![CDATA[
                  and dm.apply_date <= #{timeMap.endDate}
                ]]>
            </if>
        </where>
        ORDER BY
        dm.audit_status,
        dm.apply_date DESC
    </select>


<!--    <select id="getDomainnameListCankao" parameterType="cn.com.countrygarden.bi.main.model.domainname.DomainName"-->
<!--            resultMap="BaseResultMap">-->
<!--        SELECT-->
<!--        DISTINCT-->
<!--        sr.`id`,-->
<!--        sr.`code`,-->
<!--        sr.`name`,-->
<!--        sr.`enable`,-->
<!--        sr.created_date-->
<!--        FROM-->
<!--        sys_role AS sr-->
<!--        LEFT JOIN user_roles AS ur ON sr.`code` = ur.role_code-->
<!--        <where>-->
<!--            1=1-->
<!--            <if test="userCode != null and userCode != ''">-->
<!--                and ur.user_code = #{userCode}-->
<!--            </if>-->
<!--            <if test="role.code != null and role.code != ''">-->
<!--                and sr.code like CONCAT('%',#{role.code},'%')-->
<!--            </if>-->
<!--            <if test="role.name != null and role.name != ''">-->
<!--                and sr.name like CONCAT('%',#{role.name},'%')-->
<!--            </if>-->
<!--        </where>-->
<!--        ORDER BY sr.created_date,-->
<!--        sr.code,-->
<!--        sr.name,-->
<!--        sr.enable DESC-->
<!--    </select>-->


<!--    <sql id="selectAllRole">-->
<!--    <![CDATA[-->
<!--        SELECT r.id,-->
<!--               r.code,-->
<!--               r.name,-->
<!--               r.enable,-->
<!--               r.created_date,-->
<!--               r.created_by,-->
<!--               r.updated_date,-->
<!--               r.updated_by-->
<!--        FROM sys_role AS r-->
<!--        ]]>-->
<!--  </sql>-->

<!--    <select id="getUserWhiteUrlByRoleCode" parameterType="java.lang.String"-->
<!--            resultType="cn.com.countrygarden.bi.main.model.sys.UserWhiteUrl">-->
<!--        SELECT DISTINCT rm.role_code AS roleCode,-->
<!--                        sm.white_url AS whiteUrl-->
<!--        FROM role_menus AS rm-->
<!--                 INNER JOIN sys_menu AS sm ON rm.menu_code = sm.`code`-->
<!--        WHERE rm.role_code = #{roleCode}-->
<!--    </select>-->

<!--    <select id="findByUserCode" parameterType="string" resultMap="BaseResultMap">-->
<!--        <include refid="selectAllRole"></include>-->
<!--        <![CDATA[-->
<!--            INNER JOIN  user_roles us ON us.role_code = r.code-->
<!--            WHERE us.role_code = r.code AND us.user_code=#{userCode}-->
<!--            ]]>-->
<!--    </select>-->

<!--    <select id="selectDataByPrimaryKey" resultMap="BaseResultMap">-->
<!--     <![CDATA[-->
<!--        SELECT r.id, r.code, r.name, r.enable, r.role_type-->
<!--        FROM sys_role AS r-->
<!--        WHERE r.id = #{id}-->
<!--        ]]>-->
<!--  </select>-->

<!--    <select id="getUserRoleList" parameterType="cn.com.countrygarden.bi.main.model.sys.Role" resultMap="BaseResultMap">-->
<!--        SELECT-->
<!--        DISTINCT-->
<!--        sr.`id`,-->
<!--        sr.`code`,-->
<!--        sr.`name`,-->
<!--        sr.`enable`,-->
<!--        sr.created_date-->
<!--        FROM-->
<!--        sys_role AS sr-->
<!--        LEFT JOIN user_roles AS ur ON sr.`code` = ur.role_code-->
<!--        <where>-->
<!--            1=1-->
<!--            <if test="userCode != null and userCode != ''">-->
<!--                and ur.user_code = #{userCode}-->
<!--            </if>-->
<!--            <if test="role.code != null and role.code != ''">-->
<!--                and sr.code like CONCAT('%',#{role.code},'%')-->
<!--            </if>-->
<!--            <if test="role.name != null and role.name != ''">-->
<!--                and sr.name like CONCAT('%',#{role.name},'%')-->
<!--            </if>-->
<!--        </where>-->
<!--        ORDER BY sr.created_date,-->
<!--        sr.code,-->
<!--        sr.name,-->
<!--        sr.enable DESC-->
<!--    </select>-->

<!--    <select id="checkIsAdmin" parameterType="java.lang.String" resultType="java.lang.Integer">-->
<!--        SELECT count(id) AS c-->
<!--        FROM user_roles-->
<!--        WHERE user_code = #{userCode}-->
<!--          AND role_code = 'admin'-->
<!--    </select>-->

<!--    <select id="checkIsConsoleAdmin" parameterType="java.lang.String" resultType="java.lang.Integer">-->
<!--        SELECT COUNT(*) AS c-->
<!--        FROM user_roles AS ur-->
<!--                 INNER JOIN sys_role AS sr ON ur.role_code = sr.`code`-->
<!--        WHERE ur.user_code = #{userCode}-->
<!--          AND sr.role_type = 2-->
<!--    </select>-->
</mapper>