<?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.cku.oa.show.dao.ChampionLoginDao">
  	<sql id="championLoginColumns">
		a.id AS "id",
		a.running_number AS "runningNumber",
		a.login_type AS "loginType",
		a.login_code AS "loginCode",
		a.pedigree_certified AS "pedigreeCertified",
		a.create_date AS "createDate",
		a.print_time AS "printTime",
		a.payment_state AS "paymentState",
		case when (a.print_state !='1' or  a.print_state is null) and a.review_state = '1' and a.payment_state = '2' and login_type != '6' then '0'
		when a.print_state !='1' or  a.print_state is null then '0'
		else a.print_state end "printState",
		a.dog_breed AS "dogBreed",
		a.membership_code AS "membershipCode",
		a.cku_state AS "ckuState",
		a.price AS "price",
		a.payment_membership_code AS "paymentMembershipCode",
		a.post_type AS "postType",
		a.post_address AS "postAddress",
		a.operater AS "operater",
		a.review_state AS "reviewState",
		a.review_time AS "reviewTime",
		a.review_remarks AS "reviewRemarks",
		a.payment_time AS "paymentTime",
		a.proccess_time AS "proccessTime",
		a.proccess_state AS "proccessState",
		a.create_by AS "createBy.id",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		case when a.login_type = '1' then 'show_champion_login@com'
		when a.login_type = '2' then 'show_champion_login@tong'
		when a.login_type = '3' then 'show_champion_login@yin'
		when a.login_type = '4' then 'show_champion_login@jin'
		when a.login_type = '5' then 'show_champion_login@chaoji'
		when a.login_type = '6' then 'show_champion_login@shijie'
		when a.login_type = '7' then 'show_champion_login@qingnian'
		else '' end shortName,
		a.dog_img AS dogImg,
		a.sticker_flag AS stickerFlag
	</sql>

	<sql id="championLoginJoins">
	</sql>

    <select id="championLoginType" resultType="string">
		SELECT
			max(login_type)
		FROM
		show_champion_login
		WHERE
			pedigree_certified = #{pedigreeCertified}

    </select>

	<select id="get" resultType="ChampionLogin">
		SELECT
		    b.dog_owner "dog.dogOwner",
            b.member_code "dog.memberCode",
            b.identification_flag "dog.identificationFlag",
            b.name_en "dog.nameEn",
            b.gender "dog.gender",
			<include refid="championLoginColumns"/>
		FROM show_champion_login a
		left join dog b on a.pedigree_certified = b.pedigree_certified_code AND b.del_flag = '0'
		<include refid="championLoginJoins"/>
		WHERE a.id = #{id}
	</select>

	<!-- 验证是否完成普通登录 -->
	<select id="validateLoginType" resultType="ChampionLogin">
	   SELECT a.login_type AS "loginType" from show_champion_login a
	   where a.login_type = '1' and a.pedigree_certified = #{pedigreeCertified}
	       and a.payment_state = '2' and a.review_state = '1' and a.del_flag = '0'
	</select>

	<!-- 验证是否完重复申请 -->
    <select id="validateLogin" resultType="ChampionLogin">
       SELECT a.login_type AS "loginType" from show_champion_login a
       where a.login_type = #{loginType} and a.pedigree_certified = #{pedigreeCertified}
           and a.review_state !='3' and a.del_flag = '0'
    </select>

	<sql id="listWhere">
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			AND b.del_flag = #{DEL_FLAG_NORMAL}
			<if test="loginType != null and loginType != ''">
				AND a.login_type = #{loginType}
			</if>
			<if test="loginCode != null and loginCode != ''">
				AND a.login_code LIKE concat('%',#{loginCode},'%')
			</if>
			<if test="pedigreeCertified != null and pedigreeCertified != ''">
				AND a.pedigree_certified like '%${pedigreeCertified}%'
			</if>
			<if test="printState != null and printState != ''">
				AND a.print_state = #{printState}
			</if>
			<if test="reviewState != null and reviewState != ''">
				AND a.review_state = #{reviewState}
			</if>
			<if test="runningNumber != null and runningNumber != ''">
				AND a.running_number = #{runningNumber}
			</if>
			<if test="paymentState != null and paymentState != ''">
                AND a.payment_state = #{paymentState}
            </if>
			<if test="paymentMembershipCode != null and paymentMembershipCode != ''">
                AND a.payment_membership_code = #{paymentMembershipCode}
            </if>
			<if test="sqlMap.dogBreedMap != null and sqlMap.dogBreedMap != ''">
				AND b.dog_breed ${sqlMap.dogBreedMap}
			</if>
            <if test="memberCode != null and memberCode != ''">
                AND (b.member_code = #{memberCode} or b.dog_owner LIKE concat('%',#{memberCode},'%'))
            </if>

            <if test="id!=null and id !=''">
                AND a.id in (${id})
            </if>

			<if test="beginCreateDate != null and beginCreateDate != ''">
				AND date_format(a.create_date,'%Y-%m-%d') <![CDATA[>=]]> date_format(#{beginCreateDate},'%Y-%m-%d')
			</if>
			<if test="endCreateDate != null and endCreateDate != ''">
				AND date_format(a.create_date,'%Y-%m-%d') <![CDATA[<=]]> date_format(#{endCreateDate},'%Y-%m-%d')
			</if>

		</where>
	</sql>

	<select id="listCount" resultType="int">
		select count(1) FROM show_champion_login a left join dog b on a.pedigree_certified = b.pedigree_certified_code
		<include refid="championLoginJoins"/>
		<include refid="listWhere"/>
	</select>

	<select id="findList" resultType="ChampionLogin">
		SELECT
			b.dog_owner "dog.dogOwner",
			b.member_code "dog.memberCode",
			b.identification_flag "dog.identificationFlag",
			b.name_en "dog.nameEn",
			b.id "dog.id",
			case 
                   when a.login_type = '6' then 1
                   when a.login_type = '5' then 2
                   when a.login_type = '1' then 3
                   when a.login_type = '7' then 4
                 end    as loginTypeOrder,
			<include refid="championLoginColumns"/>
		FROM show_champion_login a left join dog b on a.pedigree_certified = b.pedigree_certified_code
        <if test="chargingItemId != null and chargingItemId != ''">
          LEFT JOIN  payment_order_detail od ON  od.business_ids =  a.id
        </if>
		<include refid="championLoginJoins"/>
		<include refid="listWhere"/>
		<if test="chargingItemId != null and chargingItemId != ''">
			AND od.charging_item_id = #{chargingItemId}
		</if>
		<if test="pedigreeCertified != null and pedigreeCertified != ''">
			AND a.pedigree_certified = #{pedigreeCertified}
		</if>
		<if test="paymentTimeLimit != null and paymentTimeLimit != ''">
			AND date_format(a.payment_time,'%Y-%m-%d') <![CDATA[<]]> date_format(#{paymentTimeLimit},'%Y-%m-%d')
		</if>
		<if test="loginTypes != null">
                and  a.login_type IN
                <foreach item="loginType" index="index" collection="loginTypes" open="(" separator="," close=")">
                    #{loginType}
                </foreach>
            </if>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>

	<select id="findAllList" resultType="ChampionLogin">
		SELECT
			<include refid="championLoginColumns"/>
		FROM show_champion_login a
		<include refid="championLoginJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>

	<insert id="insert">
		INSERT INTO show_champion_login(
			id,
			running_number,
			login_type,
			login_code,
			pedigree_certified,
			create_date,
			print_time,
			payment_state,
			print_state,
			dog_breed,
			membership_code,
			cku_state,
			price,
			payment_membership_code,
			post_type,
			post_address,
			operater,
		<if test="stickerFlag != null and stickerFlag != ''">
			sticker_flag,
		</if>
			review_state,
			review_time,
			review_remarks,
			payment_time,
			proccess_time,
			proccess_state,
			create_by,
			update_by,
			update_date,
			remarks,
			del_flag,
			dog_img
		) VALUES (
			#{id},
			#{runningNumber},
			#{loginType},
			#{loginCode},
			#{pedigreeCertified},
			#{createDate},
			#{printTime},
			#{paymentState},
			#{printState},
			#{dogBreed},
			#{membershipCode},
			#{ckuState},
			#{price},
			#{paymentMembershipCode},
			#{postType},
			#{postAddress},
			#{operater},
		<if test="stickerFlag != null and stickerFlag != ''">
			#{stickerFlag},
		</if>
			#{reviewState},
			#{reviewTime},
			#{reviewRemarks},
			#{paymentTime},
			#{proccessTime},
			#{proccessState},
			#{createBy.id},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{dogImg}
		)
	</insert>

	<update id="update">
		UPDATE show_champion_login SET
			login_code = #{loginCode},
			post_type = #{postType},
			post_address = #{postAddress},
			review_state = #{reviewState},
			review_time = #{reviewTime},
			review_remarks = #{reviewRemarks},
			remarks = #{remarks},
			dog_img = #{dogImg},
			print_state = #{printState}
		WHERE id = #{id}
	</update>

	<update id="delete">
		UPDATE show_champion_login SET
		remarks = concat(IFNULL(remarks,''),#{remarks}),
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	<update id="resetPrintState">
	    UPDATE show_champion_login SET
	        print_state = #{printState}
	    WHERE id = #{id}
	</update>
	<update id="print">
        UPDATE show_champion_login SET
            print_state = #{printState},
            print_time = #{printTime}
        WHERE id = #{id}
    </update>



	<select id="getCCMessage" resultType="int"> 
		SELECT
			count( 1 )  
		FROM
			show_results 
		WHERE
			pedigree_certified = #{pedigreeCertified}
			AND find_in_set( 'CC', REPLACE ( result_cc, '/', ',' ) ) > 0;
	</select>
	
	
	<select id="getJCCMessage" resultType="int"> 
		SELECT
			count( 1 )  
		FROM
			show_results 
		WHERE
			pedigree_certified = #{pedigreeCertified}
			AND find_in_set( 'JCC', REPLACE ( result_cc, '/', ',' ) ) > 0;
	</select>
	
	<select id="getDogMessage" resultType="Dog">
		SELECT
		a.pedigree_certified_code AS "pedigreeCertifiedCode",
		a.identification_flag identificationFlag,
		a.name_en nameEn,
		a.name_cn nameCn,
		a.gender gender,
		a.dog_owner dogOwner,
		a.member_code memberCode,
		a.birthdate birthdate,
		b.CC 'showResults.resultCc',
		b.JCC 'showResults.resultJcc',
		b.GCC 'showResults.resultGcc',
		b.RCC 'showResults.resultRcc',
		b.RJCC 'showResults.resultRjcc',
		b.BOB 'showResults.resultBob',
		b.BOS 'showResults.resultBos',
		b.BOW 'showResults.resultBow',
		b.BIG 'showResults.resultBig',
		b.BIS 'showResults.resultBis',
		b.CACIB 'showResults.resultCacib',
		concat(c.dog_breed_code,'-',c.breed_cn_name,'-',c.breed_en_name) dogBreed,
		concat(c.breed_cn_name,' ',c.breed_en_name) dogType
		FROM
		dog a
		LEFT JOIN (
		SELECT
		count(CC) CC,
		count(JCC) JCC,
		count(GCC)GCC,
		count(RCC) RCC,
		count(RJCC) RJCC,
		count(BOB) BOB,
		count(BOS) BOS,
		count(BOW) BOW,
		count(BIG) BIG,
		count(BIS) BIS,
		count(CACIB) CACIB,
		pedigree_certified
		FROM(
		SELECT
		'CC' = max(CASE WHEN result_cc='CC' THEN 'CC' ELSE null END) CC,
		'JCC' = max(CASE WHEN result_cc like'%JCC%' THEN 'JCC' ELSE null END) JCC,
		'GCC' = max(CASE WHEN result_cc like'%GCC%' THEN 'GCC' ELSE null END) GCC,
		'RCC' = max(CASE WHEN result_cc like '%RCC%' THEN 'RCC' ELSE null END) RCC,
		'RJCC' = max(CASE WHEN result_cc like '%RJCC%' THEN 'RJCC' ELSE null END) RJCC,
		'BOB' = max(CASE WHEN result_bob='BOB' THEN 'BOB' ELSE null END) BOB,
		'BOS' = max(CASE WHEN result_bob='BOS' THEN 'BOS' ELSE null END) BOS,
		'BOW' = max(CASE WHEN result_bow='BOW' THEN 'BOW' ELSE null END) BOW,
		max(CASE WHEN result_big like'BIG%' THEN result_big ELSE null END) BIG,
		max(CASE WHEN result_bis like'BIS%' THEN result_bis ELSE null END) BIS,
		'CACIB' = max(CASE WHEN result_cacib='CACIB' THEN 'CACIB' ELSE null END) CACIB,
		pedigree_certified,
		referee
		FROM
		show_results
		WHERE
		pedigree_certified = #{pedigreeCertified}
		GROUP BY
		referee
		) tab
		) b ON a.pedigree_certified_code = b.pedigree_certified left join dog_type c on a.dog_breed = c.dog_breed_code
		WHERE
		a.pedigree_certified_code = #{pedigreeCertified} AND a.del_flag  = '0'
	</select>

    <select id="getChampionLogin" resultType="com.cku.restful.v1.show.model.CkuChampionLogin">
		SELECT
			a.login_type AS loginType,
			a.login_code AS loginCode,
			a.pedigree_certified AS pedigreeCertified,
			b.dog_owner AS dogOwner,
			b.name_en AS nameEn,
			CASE WHEN d.dog_id IS NOT NULL THEN '1'
			ELSE (CASE WHEN e.pedigree_certified IS NOT NULL THEN '1' ELSE '0' END)
			END AS dnaPayState,
			c.breed_cn_name AS breedCnName,
			c.breed_en_name AS breedEnName
		FROM
		(
			SELECT
				a.login_type,
				a.login_code,
				a.pedigree_certified,
				a.create_date
			FROM
				show_champion_login a
			WHERE
				a.login_type = #{loginType}
				AND a.del_flag = '0'
				AND a.payment_state = '2'
				AND a.review_state = #{reviewState}
				<if test="pedigreeCertifiedCode != null and pedigreeCertifiedCode != ''">
					AND a.pedigree_certified = #{pedigreeCertifiedCode}
				</if>
				ORDER BY a.create_date DESC
				<if test="pageNo != null and pageSize != null">
					limit ${pageNo},${pageSize}
				</if>
		) a
		LEFT JOIN dog b ON a.pedigree_certified = b.pedigree_certified_code AND b.del_flag = '0'
		LEFT JOIN dog_type c ON b.dog_breed = c.dog_breed_code
		LEFT JOIN dog_dna d ON b.id = d.dog_id AND d.del_flag = '0'
		LEFT JOIN dog_dna_archive e ON e.pedigree_certified = a.pedigree_certified AND e.del_flag = '0' AND e.payment_state = '2'
		ORDER BY a.create_date DESC
		<if test="pageNo != null and pageSize != null">
			limit ${pageSize}
		</if>
    </select>
    <select id="getChampionLoginCount" resultType="long">
	    SELECT
		   COUNT(1)
		FROM
		   show_champion_login a
		LEFT JOIN dog b ON a.pedigree_certified = b.pedigree_certified_code
		LEFT JOIN dog_type c ON b.dog_breed = c.dog_breed_code
		WHERE
		   a.login_type = #{loginType}
		AND a.del_flag = '0'
		AND b.del_flag = '0'
		AND a.payment_state = '2'
		AND a.review_state = #{reviewState}
		<if test="pedigreeCertifiedCode != null and pedigreeCertifiedCode != ''">
		AND a.pedigree_certified = #{pedigreeCertifiedCode}
		</if>
    </select>
    <select id="championLogin" resultType="com.cku.restful.v1.show.model.CkuChampionLogin">
	    SELECT
	       a.login_type AS loginType,
		   a.login_code AS code,
		   a.pedigree_certified AS pedigreeCertified,
		   a.dog_img dogImg,
		   b.NAME AS memberName,
		   c.NAME AS kennelName
		FROM
		   show_champion_login a
		LEFT JOIN dog d ON a.pedigree_certified = d.pedigree_certified_code
		LEFT JOIN sys_member b ON d.member_code = b.member_code
		LEFT JOIN kennel c ON b.member_code = c.member_code
		WHERE
		   a.login_type = #{loginType}
		AND a.payment_state = '2'
		AND a.review_state = '1'
		AND a.del_flag = '0'
		AND b.del_flag = '0'
		AND a.pedigree_certified != 'CKU-'
		ORDER BY
		<if test='loginType=="6"'>
			substring(a.login_code, 8, 4) DESC
		</if>
		<if test='loginType!="6"'>
			right(login_code,4) DESC
		</if>
		LIMIT ${pageNo},${pageSize}
    </select>

	<select id="championLoginCount" resultType="long">
		SELECT
		   COUNT(1)
		FROM
		   show_champion_login a
		LEFT JOIN dog d ON a.pedigree_certified = d.pedigree_certified_code
		LEFT JOIN sys_member b ON d.member_code = b.member_code
		LEFT JOIN kennel c ON b.member_code = c.member_code
		WHERE
		   a.login_type = #{loginType}
		AND a.payment_state = '2'
		AND a.review_state = '1'
		AND a.del_flag = '0'
		AND a.pedigree_certified != 'CKU-'
		AND b.del_flag = '0'
	</select>
	<select id="countResult" resultType="com.cku.oa.show.entity.ShowResults"> 
    	SELECT
			pedigree_certified AS pedigreeCertified,
			result_cc AS resultCc
		FROM
			show_results 
		WHERE
			pedigree_certified = #{pedigreeCertified}
			AND del_flag = '0' UNION ALL
		SELECT
			pedigree_certified AS pedigreeCertified,
			result_cc AS resultCc
		FROM
			show_results_bov 
		WHERE
			pedigree_certified = #{pedigreeCertified}
			AND del_flag = '0';
    </select>
    <select id="countCC" resultType="int">
		SELECT a.C+b.C
		FROM (
				SELECT COUNT(1) C
				FROM show_results
				WHERE pedigree_certified = #{pedigreeCertified}
				AND result_cc = 'CC'
				AND del_flag = '0'
			) a,
			(
				SELECT COUNT(1) C
				FROM show_results_bov
				WHERE pedigree_certified = #{pedigreeCertified}
				AND result_cc = 'CC' 
				AND del_flag = '0'
			) b
    </select>
    <select id="countRCC" resultType="int">
		SELECT a.C+b.C
		FROM (
				SELECT COUNT(1) C
				FROM show_results
				WHERE pedigree_certified = #{pedigreeCertified}
				AND result_cc = 'RCC'
				AND del_flag = '0'
			) a,
			(
				SELECT COUNT(1) C
				FROM show_results_bov
				WHERE pedigree_certified = #{pedigreeCertified}
				AND result_cc = 'RCC'
				AND del_flag = '0'
			) b
    </select>
    <select id="countJCC" resultType="int">
		SELECT a.C+b.C
		FROM (
				SELECT COUNT(1) C
				FROM show_results
				WHERE pedigree_certified = #{pedigreeCertified}
				AND result_cc = 'JCC'
				AND del_flag = '0'
			) a,
			(
				SELECT COUNT(1) C
				FROM show_results_bov
				WHERE pedigree_certified = #{pedigreeCertified}
				AND result_cc = 'JCC'
				AND del_flag = '0'
			) b
    </select>
    <select id="countRJCC" resultType="int">
		SELECT a.C+b.C
		FROM (
				SELECT COUNT(1) C
				FROM show_results
				WHERE pedigree_certified = #{pedigreeCertified}
				AND result_cc = 'RJCC'
				AND del_flag = '0'
			) a,
			(
				SELECT COUNT(1) C
				FROM show_results_bov
				WHERE pedigree_certified = #{pedigreeCertified}
				AND result_cc = 'RJCC'
				AND del_flag = '0'
			) b
    </select>
    
    
    <select id="countBOB_BOS_BOW_BOJ_JBOS" resultType="int">
		SELECT a.C+b.C
		FROM (
				SELECT COUNT(1) C
				FROM show_results
				WHERE pedigree_certified = #{pedigreeCertified}
				AND (
						result_bob IN ('BOB','BOS') OR result_bow = 'BOW' OR result_boj IN ('BOJ','JBOS')
					)
				AND del_flag = '0'
			) a,
			(
				SELECT COUNT(1) C
				FROM show_results_bov
				WHERE pedigree_certified = #{pedigreeCertified}
				AND (
						result_bob IN ('BOB','BOS') OR result_bow = 'BOW'
					)
				AND del_flag = '0'
			) b
    </select>
    <select id="countBOB_BOS_BOW" resultType="int">
		SELECT a.C+b.C
		FROM (
				SELECT COUNT(1) C
				FROM show_results
				WHERE pedigree_certified = #{pedigreeCertified}
				AND (result_bob IN ('BOB','BOS') OR result_bow = 'BOW')
				AND del_flag = '0'
			) a,
			(
				SELECT COUNT(1) C
				FROM show_results_bov
				WHERE pedigree_certified = #{pedigreeCertified}
				AND (result_bob IN ('BOB','BOS') OR result_bow = 'BOW')
				AND del_flag = '0'
			) b
    </select>
    <select id="countBOB" resultType="int">
		SELECT a.C+b.C
		FROM (
				SELECT COUNT(DISTINCT(referee)) C
				FROM show_results
				WHERE pedigree_certified = #{pedigreeCertified}
				AND (result_bob IN ('BOB','BOS','BOV','BOW') OR result_bow = 'BOW')
				AND del_flag = '0'
			) a,
			(
				SELECT COUNT(DISTINCT(referee)) C
				FROM show_results_bov
				WHERE pedigree_certified = #{pedigreeCertified}
				AND (result_bob in ('BOS','BOV') OR result_bow = 'BOW' OR result_biss in ('BISS','BOSS'))
				AND del_flag = '0'
			) b
    </select>

    <select id="countBIG" resultType="int">
		SELECT COUNT(DISTINCT(referee))
		FROM show_results
		WHERE pedigree_certified = #{pedigreeCertified}
		AND LEFT(result_big,3) = 'BIG'
		AND del_flag = '0'
    </select>

	<select id="countBIGOne" resultType="int">
		SELECT COUNT(DISTINCT(referee))
		FROM show_results
		WHERE pedigree_certified = #{pedigreeCertified}
		AND (result_big = 'BIG1' OR result_big = 'BIG 1')
		AND del_flag = '0'
	</select>

    <select id="countBIS" resultType="int">
		SELECT COUNT(DISTINCT(referee))
		FROM show_results
		WHERE pedigree_certified = #{pedigreeCertified}
		AND LEFT(result_bis,3) = 'BIS'
		AND del_flag = '0'
    </select>

	<select id="countCACIB" resultType="int">
		SELECT COUNT(1)
		FROM show_results
		WHERE pedigree_certified = #{pedigreeCertified}
		AND result_cacib = 'CACIB'
		AND del_flag = '0'
    </select>

	<select id="countByPedigreeCertified" resultType="int">
		SELECT count(1)
		FROM show_champion_login a
		WHERE a.pedigree_certified = #{pedigreeCertified}
		AND a.del_flag = '0'
	</select>

	<select id="getLoginTypeByPedigreeCertified" resultType="string">
		SELECT a.login_type AS "loginType"
		FROM show_champion_login a
		WHERE a.pedigree_certified = #{pedigreeCertified}
		AND a.del_flag = '0'
		AND a.payment_state = '2'
		AND a.review_state = '1'
		ORDER BY a.login_type ASC
	</select>

	<select id="getChildLoginTypeCountMapByFdogPedigreeCertified" resultType="java.util.Map">
		SELECT
		login_type AS "loginType",
		COUNT(1) AS "count"
		FROM show_champion_login
		WHERE pedigree_certified IN (
				SELECT
					pedigree_certified
				FROM dog_birth_certificate
				WHERE fdog_pedigree_certified = #{fdogPedigreeCertified}
				AND review_state = '1'
				AND payment_state = '2'
				AND del_flag = '0'
		)
		AND review_state = '1'
		AND payment_state = '2'
		AND del_flag = '0'
		GROUP BY login_type
	</select>
	 <update id="refundShowChampionLogin" >
	  update
	  	show_champion_login
	  set
	  	review_state ='3' ,
		review_remarks=#{vo.reviewRemarks},
		update_date=#{vo.updateDate},
		update_by=#{vo.updateBy.id}
	  where  id in
	   	<foreach item="item" index="index" collection="ids" open="(" close=")" separator=",">
		     	#{item}
		    </foreach>
	</update>
	
	 <select id="getByPedigreeCertified" resultType="com.cku.oa.show.entity.ChampionLogin">
		SELECT * FROM show_champion_login  
		WHERE  del_flag = '0'  and payment_state ='2' and review_state='1'
		and pedigree_certified = #{pedigreeCertified}
    </select>

	<select id="countGCC" resultType="int">
		SELECT a.C+b.C
		FROM (
				SELECT COUNT(1) C
				FROM show_results
				WHERE pedigree_certified = #{pedigreeCertified}
				AND result_cc = 'GCC'
				AND del_flag = '0'
			) a,
			(
				SELECT COUNT(1) C
				FROM show_results_bov
				WHERE pedigree_certified = #{pedigreeCertified}
				AND result_cc = 'GCC'
				AND del_flag = '0'
			) b
    </select>
	<select id="countGCCGroup" resultType="int">
		SELECT a.C+b.C
		FROM (
				SELECT COUNT(1) C
				FROM show_results
				WHERE pedigree_certified = #{pedigreeCertified}
				AND result_cc = 'GCC'
				AND del_flag = '0'
				AND age_group  in ('12','13','14')
			) a,
			(
				SELECT COUNT(1) C
				FROM show_results_bov
				WHERE pedigree_certified = #{pedigreeCertified}
				AND result_cc = 'GCC'
				AND del_flag = '0'
				AND age_group  in ('12','13','14')
			) b
    </select>
</mapper>
