<?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.report.mapper.RzlClassStatisticsInfoMapper">


<!-- 
<select id="sumByReport" resultType="long">
select    ifnull(count(*),0) total_cnt
        from d_patent_effective_info
        where 1=1  and modify_patentee_type in (  '科研机构' , '企业' , '机关团体' , '个人' , '大专院校' )  
        and patent_type = '发明'
         and year_batch = #{year}
         and month_batch = #{month}  
</select>
 -->
 
 <select id="sumByReport" resultType="long">
select    ifnull(sum(total_cnt),0) total_cnt
        from rzl_class_statistics_info
        where 1=1  and modify_patentee_type in (  '科研机构' , '企业' , '机关团体' , '个人' , '大专院校' )  
        and patent_type = '发明'
         and year_batch = #{year}
         and month_batch = #{month}  
</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(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(total_cnt) total_cnt
        ,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 rzl_class_statistics_info
        where 1=1 
        <if test="createTimeBegin != null  and createTimeBegin != ''">and pub_date_pub >=#{createTimeBegin}</if>
        <if test="createTimeEnd != null  and createTimeEnd != ''">and pub_date_pub <![CDATA[<=]]>
            #{createTimeEnd}
        </if>
        <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>
        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
        ,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 ,count(*) total_cnt
        ,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_effective_info
        where 1=1 
        <if test="createTimeBegin != null  and createTimeBegin != ''">and pub_date_pub >=#{createTimeBegin}</if>
        <if test="createTimeEnd != null  and createTimeEnd != ''">and pub_date_pub <![CDATA[<=]]>
            #{createTimeEnd}
        </if>
        <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>
        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>
	 -->

</mapper>



