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


<!-- 
<select id="listByReport" resultType="map">
    	select <if test="cityCode != null  and cityCode != ''"> area_name ,</if>
    	<if test="cityCode == null  or cityCode == ''">city_name area_name ,</if>
    	patent_type,year,sum(higher_school) higher_school,sum(research_institute) research_institute,sum(total_cnt) total_cnt,
		sum(enterprise) enterprise,sum(institutions) institutions,sum(individual) individual
		  from rzg_class_statistics_info
		  where 1=1 
     <if test="cityCode != null  and cityCode != ''">and city_code = #{cityCode}</if>
		   group by city_name,patent_type,year 
		   </select>
 <select id="sumByRank" resultType="long">
 SELECT ifnull(count(*),0) total
FROM
	d_patent_pub_info 
WHERE yunnan_modify_appli_city_code IS NOT NULL 
	AND yunnan_modify_appli_city_code != '' 
	AND pub_date >=#{createTimeBegin}
	AND pub_date <![CDATA[<=]]>  #{createTimeEnd}
	AND modify_appli_type IN ( 'UC','SRI', 'IME', 'OT', 'PE' ) 
	AND patent_type = '1' 
 </select>
  -->
  
   <select id="sumByRank" resultType="long">
 SELECT ifnull(sum(total_cnt),0) total
FROM
	d_patent_pub_info 
WHERE yunnan_modify_appli_city_code IS NOT NULL 
	AND yunnan_modify_appli_city_code != '' 
	AND pub_date >=#{createTimeBegin}
	AND pub_date <![CDATA[<=]]>  #{createTimeEnd}
	AND modify_appli_type IN ( 'UC','SRI', 'IME', 'OT', 'PE' ) 
	AND patent_type = '1' 
 </select>
 
 
 <select id="listByReport" resultType="map">
select yunnan_modify_appli_province,
<if test="cityCode != null  and cityCode != ''">yunnan_modify_appli_county area_name ,yunnan_modify_appli_county_code area_code</if>
<if test="cityCode == null  or cityCode == ''">yunnan_modify_appli_city area_name, yunnan_modify_appli_city_code area_code</if>
,year_batch,  month_batch, patent_type
,sum(case  when modify_appli_type='UC' then total_cnt else 0 end ) higher_school  
,sum(case  when modify_appli_type='SRI' then total_cnt else 0 end ) research_institute 
,sum(case  when modify_appli_type='IME' then total_cnt else 0 end ) enterprise 
,sum(case  when modify_appli_type='OT' then total_cnt else 0 end ) institutions 
,sum(case  when modify_appli_type='PE' then total_cnt else 0 end ) individual 
from rzg_class_statistics_info where patent_type in ('发明','实用新型','外观设计') and yunnan_modify_appli_city_code is not null and yunnan_modify_appli_city_code !='' 
 <if test="cityCode != null  and cityCode != ''">and yunnan_modify_appli_city_code = #{cityCode}</if>
 <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="applicantTypesList != null and applicantTypesList.size > 0">
            and modify_appli_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>
group by yunnan_modify_appli_province,modify_appli_type,
<if test="cityCode != null  and cityCode != ''">yunnan_modify_appli_city,yunnan_modify_appli_county, yunnan_modify_appli_county_code,</if>
<if test="cityCode == null  or cityCode == ''">yunnan_modify_appli_city,yunnan_modify_appli_city_code,</if>
year_batch,  month_batch ,patent_type 
    </select>
    
 <!-- 
<select id="listByReport" resultType="map">
select 
<if test="cityCode != null  and cityCode != ''">yunnan_modify_appli_county area_name ,yunnan_modify_appli_county_code area_code</if>
<if test="cityCode == null  or cityCode == ''">yunnan_modify_appli_city area_name, yunnan_modify_appli_city_code area_code</if>
,SUBSTRING(pub_date,1,4) year_batch,SUBSTRING(pub_date,5,2) month_batch
,(case  when patent_type='1' then '发明' when patent_type='2' then '实用新型' when patent_type='3' then '外观设计'  else '' end )  patent_type
,sum(case  when modify_appli_type='UC' then 1 else 0 end ) higher_school  
,sum(case  when modify_appli_type='SRI' then 1 else 0 end ) research_institute 
,sum(case  when modify_appli_type='IME' then 1 else 0 end ) enterprise 
,sum(case  when modify_appli_type='OT' then 1 else 0 end ) institutions 
,sum(case  when modify_appli_type='PE' then 1 else 0 end ) individual 
from d_patent_pub_info where patent_type in ('1','2','3') and yunnan_modify_appli_city_code is not null and yunnan_modify_appli_city_code !='' 
 <if test="cityCode != null  and cityCode != ''">and yunnan_modify_appli_city_code = #{cityCode}</if>
 <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="applicantTypesList != null and applicantTypesList.size > 0">
            and modify_appli_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>
group by yunnan_modify_appli_province,
<if test="cityCode != null  and cityCode != ''">yunnan_modify_appli_city,yunnan_modify_appli_county, yunnan_modify_appli_county_code,</if>
<if test="cityCode == null  or cityCode == ''">yunnan_modify_appli_city,yunnan_modify_appli_city_code,</if>
SUBSTRING(pub_date,1,4),SUBSTRING(pub_date,5,2) ,patent_type 
    </select>
     -->

</mapper>


