<?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.system.mapper.UrPatentValidMapper">
    
    <resultMap type="com.ruoyi.system.domain.UrPatentValid" id="UrPatentValidResult">
        <result property="an"    column="an"    />
        <result property="databaseDate"    column="database_date"    />
        <result property="ad"    column="ad"    />
        <result property="patentName"    column="patent_name"    />
        <result property="agentOrgCode"    column="agent_org_code"    />
        <result property="agentOrgName"    column="agent_org_name"    />
        <result property="ipc"    column="ipc"    />
        <result property="peopleName"    column="people_name"    />
        <result property="zipCode"    column="zip_code"    />
        <result property="address"    column="address"    />
        <result property="pts"    column="pts"    />
        <result property="ppType"    column="pp_type"    />
        <result property="provinceName"    column="province_name"    />
        <result property="cityName"    column="city_name"    />
        <result property="districtName"    column="district_name"    />
    </resultMap>

    <sql id="selectUrPatentValidVo">
        select an, database_date, ad, patent_name, agent_org_code, agent_org_name, ipc, people_name, zip_code, address, pts, pp_type, province_name, city_name, district_name from ur_patent_valid_all
    </sql>

    <select id="selectUrPatentValidList" parameterType="com.ruoyi.system.domain.UrPatentValid" resultMap="UrPatentValidResult">
        <include refid="selectUrPatentValidVo"/>
        <where>
            <if test="an != null  and an != ''"> and an = #{an}</if>
            <if test="databaseDate != null  and databaseDate != ''"> and database_date = #{databaseDate}</if>
            <if test="ad != null  and ad != ''"> and ad = #{ad}</if>
            <if test="patentName != null  and patentName != ''"> and patent_name like concat('%', #{patentName}, '%')</if>
            <if test="agentOrgCode != null  and agentOrgCode != ''"> and agent_org_code = #{agentOrgCode}</if>
            <if test="agentOrgName != null  and agentOrgName != ''"> and agent_org_name like concat('%', #{agentOrgName}, '%')</if>
            <if test="ipc != null  and ipc != ''"> and ipc = #{ipc}</if>
            <if test="peopleName != null  and peopleName != ''"> and people_name like concat('%', #{peopleName}, '%')</if>
            <if test="zipCode != null  and zipCode != ''"> and zip_code = #{zipCode}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="pts != null  and pts != ''"> and pts = #{pts}</if>
            <if test="ppType != null  and ppType != ''"> and pp_type = #{ppType}</if>
            <if test="provinceName != null  and provinceName != ''"> and province_name like concat('%', #{provinceName}, '%')</if>
            <if test="cityName != null  and cityName != ''"> and city_name like concat('%', #{cityName}, '%')</if>
            <if test="districtName != null  and districtName != ''"> and district_name like concat('%', #{districtName}, '%')</if>
        </where>
    </select>

    <select id="selectHeaderList" parameterType="com.ruoyi.system.domain.vo.UrPatentValidVo" resultMap="UrPatentValidResult">
        select header.subject as patent_name from (
        select
            year,
            year as subject,
                1 as sort
        from (select year(database_date) as year from ur_patent_valid_all where year(database_date) >= #{startDate} and year(database_date) &lt;= #{endDate} GROUP BY year(database_date) ORDER BY database_date asc) a
        union
        select
            year,
            '大专院校' as subject,
                2 as sort
        from (select year(database_date) as year from ur_patent_valid_all where year(database_date) >= #{startDate} and year(database_date) &lt;= #{endDate} GROUP BY year(database_date) ORDER BY database_date asc) b
        union
        select
            year,
            '科研机构' as subject,
                3 as sort
        from (select year(database_date) as year from ur_patent_valid_all where year(database_date) >= #{startDate} and year(database_date) &lt;= #{endDate} GROUP BY year(database_date) ORDER BY database_date asc) c
        union
        select
            year,
            '企业' as subject,
                4 as sort
        from (select year(database_date) as year from ur_patent_valid_all where year(database_date) >= #{startDate} and year(database_date) &lt;= #{endDate} GROUP BY year(database_date) ORDER BY database_date asc) d
        union
        select
            year,
            '机关团体' as subject,
                5 as sort
        from (select year(database_date) as year from ur_patent_valid_all where year(database_date) >= #{startDate} and year(database_date) &lt;= #{endDate} GROUP BY year(database_date) ORDER BY database_date asc) e
        union
        select
            year,
            '个人' as subject,
                6 as sort
        from (select year(database_date) as year from ur_patent_valid_all where year(database_date) >= #{startDate} and year(database_date) &lt;= #{endDate} GROUP BY year(database_date) ORDER BY database_date asc) e
        )  header order by header.year,header.sort asc
    </select>


    <select id="selectGroupDistrictName" resultMap="UrPatentValidResult">
        select DISTINCT district_short_name as district_name from blade_region where district_short_name is not null GROUP BY district_short_name
    </select>

    <update id="setDistrictName" parameterType="java.lang.String">
        update ur_patent_valid2 set district_name=#{districtName} where address like concat('%', #{districtName}, '%')
    </update>
</mapper>