<?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.indica.mapper.CIndicationInfoMapper">


<delete id="clearData"    >
	truncate table c_indication_info  
	</delete>
	
	<!-- 
	select sum(case when (data_type='原产地地理标志' and pub_type='批准公告') then 1 else 0 end ) total_cnt2
	,sum(case when (data_type='农产品地理标志' and pub_type='登记公告') then 1 else 0 end ) total_cnt3
	,sum(case when (data_type='地理标志商标' and pub_type='已注册') then 1 else 0 end ) total_cnt1
	,modify_app_city modify_city,modify_app_city_code modify_city_code from c_indication_info 
	where modify_app_city is not null and modify_app_city <![CDATA[<>]]>'' 
	group by modify_app_city,modify_app_city_code
	 -->
<select id="listForLast" resultType="map">
	select sum(case when ( data_type='地理标志商标' and pub_type='已注册') then 1 else 0 end ) total_cnt2
	,sum(case when (data_type='原产地地理标志' and pub_type='批准公告') then 1 else 0 end ) total_cnt3
	,sum(case when (data_type='地理标志商标' and pub_type='已注册' and pub_year=DATE_FORMAT(SYSDATE(),'%Y') ) then 1 else 0 end ) total_cnt1
	,modify_app_city modify_city,modify_app_city_code modify_city_code from c_indication_info
	group by modify_app_city,modify_app_city_code
</select>

<select id="listReportGrowth" resultType="map">
	  	select  modify_city 
		,sum(total_cnt) total_cnt
		 ,sum(case when (data_type='原产地地理标志' and pub_type='批准公告') then total_cnt else 0 end ) total_cnt1
		 ,sum(case when (data_type='原产地地理标志' and pub_type='批准公告') then hzqy_counts else 0 end ) total_cnt2
		  ,sum(case when (data_type='农产品地理标志' and pub_type='登记公告') then total_cnt else 0 end ) total_cnt3
		 ,sum(case when (data_type='地理标志商标' and pub_type='已注册') then total_cnt else 0 end ) total_cnt4
		from (
		select 
		<if test="sumType == 'province'">'云南省' modify_city </if>
		<if test="sumType == 'city'">modify_app_city modify_city </if>
		<if test="sumType == 'area'">modify_app_county modify_city </if>
		 ,count(*) total_cnt ,sum(ifnull( hzqy_counts, 0 ) ) hzqy_counts,data_type,pub_type  from c_indication_info  where 1=1 
	<if test="sumType == 'city' and cityCode != '' and cityCode != 'null'">and modify_app_city_code=#{cityCode}</if>
	<if test="sumType == 'area' and cityCode != '' and cityCode != 'null' ">and modify_app_city_code=#{cityCode}</if>
		and modify_app_city is not null and modify_app_city !=''   
		and pub_date is not null and pub_date !=''   
		<if test="beginDate != null  and beginDate != '' and endDate != null  and endDate != ''">
				and pub_date <![CDATA[>=]]>#{beginDate} and pub_date <![CDATA[<=]]>#{endDate}
			</if>
			<if test="sumType == 'province'">group by data_type,pub_type </if>
			<if test="sumType == 'city'"> group by modify_app_city,data_type,pub_type </if>
			<if test="sumType == 'area'">group by modify_app_county,data_type,pub_type </if>
			 
		) ff group by modify_city
	</select>
	
	
	 <select id="listReportMark" resultType="map">
  select  
  <if test="cityCode != null  and cityCode != ''">
  		modify_app_county area_name,modify_app_county_code area_code,
  	</if>
  	<if test="cityCode == null  or cityCode == ''">
  		modify_app_city area_name,modify_app_city_code area_code ,
  	</if>
  count(*) total_cnt  from c_indication_info 
  where modify_app_city is not null and modify_app_city !='' 
  and pub_year is not null and pub_year!='' 
  and data_type='地理标志商标'   and pub_type='已注册' 
	
	<if test="sumYearDate != null  and sumYearDate != ''">
		and pub_date <![CDATA[<=]]>#{sumYearDate}
	</if>
	
	<if test="cityCode != null  and cityCode != ''">
  		and modify_app_city_code =#{cityCode}
  	</if>
  group by <if test="cityCode != null  and cityCode != ''">
  		modify_app_county  ,modify_app_county_code 
  	</if>
  	<if test="cityCode == null  or cityCode == ''">
  		modify_app_city,modify_app_city_code 
  	</if>
  
  </select>
  
  
<!-- 
  <select id="listReportMark" resultType="map">
  select  
  <if test="cityCode != null  and cityCode != ''">
  		modify_app_county area_name,modify_app_county_code area_code,
  	</if>
  	<if test="cityCode == null  or cityCode == ''">
  		modify_app_city area_name,modify_app_city_code area_code ,
  	</if>
  count(*) total_cnt,pub_year  from c_indication_info 
  where modify_app_city is not null and modify_app_city !='' 
  and pub_year is not null and pub_year!='' 
  and data_type='地理标志商标'   and pub_type='已注册' 
  <if test="queryDate != null  and queryDate != ''">
		and pub_date <![CDATA[<=]]>#{queryDate}
	</if>
	<if test="beginDate != null  and beginDate != ''">
		and pub_date <![CDATA[>=]]>#{beginDate}
	</if>
	
	<if test="endDate != null  and endDate != ''">
		and pub_date <![CDATA[<=]]>#{endDate}
	</if>
	<if test="pubYears != null ">
		and pub_year  in 
            <foreach  item="item" index="index" collection="pubYears" open="(" separator="," close=" )">
                 #{item}
        	</foreach>
	</if>
	
	
	<if test="cityCode != null  and cityCode != ''">
  		and modify_app_city_code =#{cityCode}
  	</if>
  group by <if test="cityCode != null  and cityCode != ''">
  		modify_app_county  ,modify_app_county_code,
  	</if>
  	<if test="cityCode == null  or cityCode == ''">
  		modify_app_city,modify_app_city_code ,
  	</if>pub_year
  
  </select>
  
   -->
  
  
  <select id="listReportHzqy" resultType="map">
  select <if test="cityCode != null  and cityCode != ''">
  		modify_app_county area_name,modify_app_county_code area_code,
  	</if>
  	<if test="cityCode == null  or cityCode == ''">
  		modify_app_city area_name,modify_app_city_code area_code,
  	</if>count(*) total_cnt,sum(hzqy_counts) hzqy_counts  from c_indication_info 
  where modify_app_city is not null and modify_app_city !='' 
  and data_type='原产地地理标志'   and pub_type='批准公告'
	<if test="endDate != null  and endDate != ''">
		and pub_date <![CDATA[<=]]>#{endDate}
	</if>
	<if test="cityCode != null  and cityCode != ''">
  		and modify_app_city_code =#{cityCode}
  	</if>
  group by <if test="cityCode != null  and cityCode != ''">
  		modify_app_county  ,modify_app_county_code
  	</if>
  	<if test="cityCode == null  or cityCode == ''">
  		modify_app_city,modify_app_city_code
  	</if>
  
  </select>
  <!-- 
   <select id="listReportHzqy" resultType="map">
  select <if test="cityCode != null  and cityCode != ''">
  		modify_app_county area_name,modify_app_county_code area_code,
  	</if>
  	<if test="cityCode == null  or cityCode == ''">
  		modify_app_city area_name,modify_app_city_code area_code,
  	</if>count(*) total_cnt,pub_year,sum(hzqy_counts) hzqy_counts  from c_indication_info 
  where modify_app_city is not null and modify_app_city !='' 
  and pub_year is not null and pub_year!='' 
  and data_type='原产地地理标志'   and pub_type='批准公告'
  <if test="queryDate != null  and queryDate != ''">
		and pub_date <![CDATA[<=]]>#{queryDate}
	</if>
	<if test="beginDate != null  and beginDate != ''">
		and pub_date <![CDATA[>=]]>#{beginDate}
	</if>
	<if test="endDate != null  and endDate != ''">
		and pub_date <![CDATA[<=]]>#{endDate}
	</if>
	<if test="cityCode != null  and cityCode != ''">
  		and modify_app_city_code =#{cityCode}
  	</if>
  group by <if test="cityCode != null  and cityCode != ''">
  		modify_app_county  ,modify_app_county_code,
  	</if>
  	<if test="cityCode == null  or cityCode == ''">
  		modify_app_city,modify_app_city_code,
  	</if>pub_year
  </select> -->
  
  
  <select id="listReportFarm" resultType="map">
  select <if test="cityCode != null  and cityCode != ''">
  		modify_app_county area_name,modify_app_county_code area_code,
  	</if>
  	<if test="cityCode == null  or cityCode == ''">
  		modify_app_city area_name,modify_app_city_code area_code,
  	</if>count(*) total_cnt  from c_indication_info 
  where modify_app_city is not null and modify_app_city !='' 
  and data_type='农产品地理标志'  and pub_type='登记公告'

	<if test="endDate != null  and endDate != ''">
		and pub_date <![CDATA[<=]]>#{endDate}
	</if>
	<if test="cityCode != null  and cityCode != ''">
  		and modify_app_city_code =#{cityCode}
  	</if>
  group by <if test="cityCode != null  and cityCode != ''">
  		modify_app_county  ,modify_app_county_code
  	</if>
  	<if test="cityCode == null  or cityCode == ''">
  		modify_app_city,modify_app_city_code
  	</if>
  
  </select>
  
 
  
  
</mapper>