<?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.ruoyi.reportpub.mapper.RzgApplicantRankingInfoMapper">


	<resultMap type="RzgApplicantRankingInfo" id="RzgApplicantRankingInfoResult">
		<id property="id" column="id" />
		<result property="patenteeName" column="patentee_name" />
		<result property="cityCode" column="city_code" />
		<result property="cityName" column="city_name" />
		<result property="year" column="year" />
		<result property="month" column="month" />
		<result property="applicantType" column="applicant_type" />
		<result property="invent" column="invent" />
		<result property="utilityModel" column="utility_model" />
		<result property="appearanceDesign" column="appearance_design" />
		<result property="patentType" column="patent_type" />
		<result property="patentsTotalNumber" column="patents_total_number" />
		<result property="pubDate" column="pub_Date" />
		<result property="status" column="status" />
		<result property="delFlag" column="del_flag" />
		<result property="loginIp" column="login_ip" />
		<result property="loginDate" column="login_date" />
		<result property="createBy" column="create_by" />
		<result property="createTime" column="create_time" />
		<result property="updateBy" column="update_by" />
		<result property="updateTime" column="update_time" />
		<result property="remark" column="remark" />
	</resultMap>


<!-- 
<select id="selectForRank" parameterType="RzgApplicantRankingInfo" resultMap="RzgApplicantRankingInfoResult">
select patentee_name,(0<if test="inventQ != null and inventQ == '1'.toString()"> + invent </if>
<if test="utilityModelQ != null and utilityModelQ == '1'.toString()">  + utility_model </if>
<if test="appearanceDesignQ != null and appearanceDesignQ == '1'.toString()"> + appearance_design</if>) as patents_total_number,
(case  applicant_type when 'IME' then '企业' when 'OT' then '机关团体' when 'PE' then '个人' 
when 'SRI' then '科研机构' when 'UC' then '大专院校' else 0 end ) applicant_type,
invent,utility_model,appearance_design from (
select  appli patentee_name,count(*) patents_total_number ,
modify_appli_type applicant_type
,sum(case  when patent_type='1' then 1 else 0 end ) invent  
,sum(case  when patent_type='2' then 1 else 0 end ) utility_model 
,sum(case  when patent_type='3' then 1 else 0 end ) appearance_design
from d_patent_pub_info 
where 1=1 
<if test="createTimeBegin != null and createTimeBegin != ''"> AND pub_date >= #{createTimeBegin}</if>
<if test="createTimeEnd != null and createTimeEnd != ''"> AND pub_date  <![CDATA[<=]]> #{createTimeEnd}</if>
<if test="cityCode != null and cityCode != ''"> AND modify_appli_city_code = #{cityCode}</if>
<if test="patenteeName != null and patenteeName != ''"> AND appli = #{patenteeName}</if>
<if test="applicantType != null and applicantType != ''"> AND modify_appli_type = #{applicantType}</if>
<if test="applicantTypesList != null and applicantTypesList.size > 0">
    and modify_appli_type in <foreach item="type" collection="applicantTypesList" open="(" separator="," close=")">#{type}</foreach>
</if>
group by appli,modify_appli_type ,modify_appli_city_code,modify_appli_city 
) ff 
</select>
 -->
<!-- -->
	<select id="selectForRank" parameterType="RzgApplicantRankingInfo" resultMap="RzgApplicantRankingInfoResult">
		select patentee_name,applicant_type,
		sum(ifnull(invent,0)) invent,sum(ifnull(utility_model,0)) utility_model,sum(ifnull(appearance_design,0)) appearance_design,
		sum(0<if test="inventQ != null and inventQ == '1'.toString()"> + ifnull(invent,0) </if>
		 <if test="utilityModelQ != null and utilityModelQ == '1'.toString()">  + ifnull(utility_model,0) </if>
		 <if test="appearanceDesignQ != null and appearanceDesignQ == '1'.toString()"> + ifnull(appearance_design,0)
		 </if>) as patents_total_number from rzg_applicant_ranking_info where 1=1 
		<if test="year != null and year != ''">
			AND `year` = #{year}
		</if>
		<if test="month != null and month != ''">
			AND `month` = #{month}
		</if>
		<if test="createTimeBegin != null and createTimeBegin != ''">
			AND `imp_batch` >= #{createTimeBegin}
		</if>
		<if test="createTimeEnd != null and createTimeEnd != ''">
			AND `imp_batch` <![CDATA[<=]]> #{createTimeEnd}
		</if>
		<if test="cityCode != null and cityCode != ''">
			AND `city_code` = #{cityCode}
		</if>
		<if test="patenteeName != null and patenteeName != ''">
			AND `patentee_name` = #{patenteeName}
		</if>
		<if test="applicantType != null and applicantType != ''">
			AND `applicant_type` = #{applicantType}
		</if>
		<if test="applicantTypesList != null and applicantTypesList.size > 0">
            and applicant_type in
            <foreach item="type" collection="applicantTypesList" open="(" separator="," close=")">#{type}</foreach>
        </if>
		group by patentee_name,applicant_type 
		order by sum(0<if test="inventQ != null and inventQ == '1'.toString()"> + ifnull(invent,0) </if>
		 <if test="utilityModelQ != null and utilityModelQ == '1'.toString()">  + ifnull(utility_model,0) </if>
		 <if test="appearanceDesignQ != null and appearanceDesignQ == '1'.toString()"> + ifnull(appearance_design,0)
		 </if>)   desc 
	</select>
 	

</mapper>