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

	<resultMap type="RzlApplicantRankingInfo" id="RzlApplicantRankingInfoResult">
		<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="RzlApplicantRankingInfo" resultMap="RzlApplicantRankingInfoResult">
		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 rzl_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="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>
<!-- 
	<select id="selectForRank" parameterType="RzlApplicantRankingInfo" resultMap="RzlApplicantRankingInfoResult">
		select patentee_name,year,month,city_code,city_name,applicant_type,invent,utility_model,appearance_design,patent_type,
		 (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, status, del_flag,create_by,create_time,remark  from rzl_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="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>
		order by (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>)  desc 
	</select>
 -->

</mapper>

