<?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.reportrzs.mapper.RzsClassStatisticsInfoMapper">


<select id="sumByRank" resultType="long">
	SELECT
	ifnull(sum( total_cnt ) ,0) total_cnt
FROM
	rzs_class_statistics_info 
WHERE
	1 = 1 
	AND modify_patentee_type IN ( '大专院校', '科研机构', '企业', '机关团体', '个人' ) 
	AND patent_type ='发明'
	AND auth_inbound_date >=#{createTimeBegin} 
	AND auth_inbound_date <![CDATA[<=]]> #{createTimeEnd}
	</select>
<!-- 
	<select id="sumByRank" resultType="long">
	SELECT
	ifnull(count( * ) ,0) total_cnt
FROM
	d_patent_auth_info 
WHERE
	1 = 1 
	AND modify_patentee_type IN ( '大专院校', '科研机构', '企业', '机关团体', '个人' ) 
	AND patent_type ='发明'
	AND auth_inbound_date >=#{createTimeBegin} 
	AND auth_inbound_date <![CDATA[<=]]> #{createTimeEnd}
	</select>
	 -->
	<select id="listByReport" resultType="map">
        select
        <if test="cityCode != null  and cityCode != ''">modify_area_name area_name ,modify_area_code area_code ,</if>
        <if test="cityCode == null  or cityCode == ''">modify_city_name area_name ,modify_city_code area_code ,</if>patent_type,
        year_batch year,sum(total_cnt) total_cnt
        ,sum(case when modify_patentee_type='大专院校' then total_cnt else 0 end ) higher_school
        ,sum(case when modify_patentee_type='科研机构' then total_cnt else 0 end ) research_institute
        ,sum(case when modify_patentee_type='企业' then total_cnt else 0 end ) enterprise
        ,sum(case when modify_patentee_type='机关团体' then total_cnt else 0 end ) institutions
        ,sum(case when modify_patentee_type='个人' then total_cnt else 0 end ) individual
        from rzs_class_statistics_info
        where 1=1 
        <if test="applicantTypesList != null and applicantTypesList.size > 0">
            and modify_patentee_type in
            <foreach item="type" collection="applicantTypesList" open="(" separator="," close=")">#{type}</foreach>
        </if>
        <if test="patentTypesList != null and patentTypesList.size > 0">
            and patent_type in
            <foreach item="type" collection="patentTypesList" open="(" separator="," close=")">#{type}</foreach>
        </if>
        <if test="year != null  and year != ''">and year_batch = #{year}</if>
        <if test="month != null  and month != ''">and month_batch = #{month}</if>
        <if test="cityCode != null  and cityCode != ''">and modify_city_code = #{cityCode}</if>
        
        <if test="authInboundDate != null  and authInboundDate != ''">and auth_inbound_date = #{authInboundDate}</if>
        
        <if test="createTimeBegin != null  and createTimeBegin != ''">and auth_inbound_date>=#{createTimeBegin}</if>
        <if test="createTimeEnd != null  and createTimeEnd != ''">and auth_inbound_date <![CDATA[<=]]>
            #{createTimeEnd}
        </if>
        group by
        <if test="cityCode != null  and cityCode != ''">modify_area_name ,modify_area_code ,</if>
        <if test="cityCode == null  or cityCode == ''">modify_city_name ,modify_city_code ,</if>
        patent_type,year_batch
    </select>
    
    
	<!--
	<select id="listByReport" resultType="map">
        select
        <if test="cityCode != null  and cityCode != ''">modify_area_name area_name ,modify_area_code area_code ,</if>
        <if test="cityCode == null  or cityCode == ''">modify_city_name area_name ,modify_city_code area_code ,</if>patent_type,
        year_batch year,count(*) total_cnt
        ,sum(case when modify_patentee_type='大专院校' then 1 else 0 end ) higher_school
        ,sum(case when modify_patentee_type='科研机构' then 1 else 0 end ) research_institute
        ,sum(case when modify_patentee_type='企业' then 1 else 0 end ) enterprise
        ,sum(case when modify_patentee_type='机关团体' then 1 else 0 end ) institutions
        ,sum(case when modify_patentee_type='个人' then 1 else 0 end ) individual
        from d_patent_auth_info
        where 1=1 
        <if test="applicantTypesList != null and applicantTypesList.size > 0">
            and modify_patentee_type in
            <foreach item="type" collection="applicantTypesList" open="(" separator="," close=")">#{type}</foreach>
        </if>
        <if test="patentTypesList != null and patentTypesList.size > 0">
            and patent_type in
            <foreach item="type" collection="patentTypesList" open="(" separator="," close=")">#{type}</foreach>
        </if>
        <if test="year != null  and year != ''">and year_batch = #{year}</if>
        <if test="month != null  and month != ''">and month_batch = #{month}</if>
        <if test="cityCode != null  and cityCode != ''">and modify_city_code = #{cityCode}</if>
        
        <if test="authInboundDate != null  and authInboundDate != ''">and auth_inbound_date = #{authInboundDate}</if>
        
        <if test="createTimeBegin != null  and createTimeBegin != ''">and auth_inbound_date>=#{createTimeBegin}</if>
        <if test="createTimeEnd != null  and createTimeEnd != ''">and auth_inbound_date <![CDATA[<=]]>
            #{createTimeEnd}
        </if>
        group by
        <if test="cityCode != null  and cityCode != ''">modify_area_name ,modify_area_code ,</if>
        <if test="cityCode == null  or cityCode == ''">modify_city_name ,modify_city_code ,</if>
        patent_type,year_batch
    </select>
    
    <select id="listByReport" resultType="map">
        select
        <if test="cityCode != null  and cityCode != ''">area_name_pub area_name ,</if>
        <if test="cityCode == null  or cityCode == ''">city_name_pub area_name ,</if>patent_type,
        year_batch year,count(*) total_cnt
        ,sum(case when patentee_type='大专院校' then 1 else 0 end ) higher_school
        ,sum(case when patentee_type='科研机构' then 1 else 0 end ) research_institute
        ,sum(case when patentee_type='企业' then 1 else 0 end ) enterprise
        ,sum(case when patentee_type='机关团体' then 1 else 0 end ) institutions
        ,sum(case when patentee_type='个人' then 1 else 0 end ) individual
        from d_patent_auth_info
        where 1=1 and area_name_pub is not null
        <if test="applicantTypesList != null and applicantTypesList.size > 0">
            and patentee_type in
            <foreach item="type" collection="applicantTypesList" open="(" separator="," close=")">#{type}</foreach>
        </if>
        <if test="patentTypesList != null and patentTypesList.size > 0">
            and patent_type in
            <foreach item="type" collection="patentTypesList" open="(" separator="," close=")">#{type}</foreach>
        </if>
        <if test="year != null  and year != ''">and year_batch = #{year}</if>
        <if test="month != null  and month != ''">and month_batch = #{month}</if>
        <if test="cityCode != null  and cityCode != ''">and city_code_pub = #{cityCode}</if>
        
        <if test="authInboundDate != null  and authInboundDate != ''">and auth_inbound_date = #{authInboundDate}</if>
        
        <if test="createTimeBegin != null  and createTimeBegin != ''">and auth_inbound_date>=#{createTimeBegin}</if>
        <if test="createTimeEnd != null  and createTimeEnd != ''">and auth_inbound_date <![CDATA[<=]]>
            #{createTimeEnd}
        </if>
        group by
        <if test="cityCode != null  and cityCode != ''">area_name_pub ,</if>
        <if test="cityCode == null  or cityCode == ''">city_name_pub ,</if>
        patent_type,year_batch
    </select>
 	-->

</mapper>


