<?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.web.modules.prosperity.mapper.BizCommonProsperityAchievementMapper">

    <resultMap type="com.ruoyi.web.modules.prosperity.domain.BizCommonProsperityAchievement" id="BizCommonProsperityAchievementResult">
        <id     property="id"                              column="id"/>
        <result property="statPeriod"                      column="stat_period"/>
        <result property="collectiveEconomyIncome"         column="collective_economy_income"/>
        <result property="employmentDrivenCount"           column="employment_driven_count"/>
        <result property="newJobPositions"                   column="new_job_positions"/>
        <result property="envProjectCount"                   column="env_project_count"/>
        <result property="newGreenArea"                      column="new_green_area"/>
        <result property="culturalHeritageCount"           column="cultural_heritage_count"/>
        <result property="ethnicIntegrationProjectCount"   column="ethnic_integration_project_count"/>
        <result property="ethnicUnityActivityCount"        column="ethnic_unity_activity_count"/>
        <result property="digitalPlatformUsageRate"        column="digital_platform_usage_rate"/>
        <result property="regionalPublicBrandCount"        column="regional_public_brand_count"/>
        <result property="brandPremiumRate"                column="brand_premium_rate"/>
        <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>

    <sql id="selectVo">
        select id, stat_period, collective_economy_income, employment_driven_count, new_job_positions,
               env_project_count, new_green_area, cultural_heritage_count,
               ethnic_integration_project_count, ethnic_unity_activity_count,
               digital_platform_usage_rate, regional_public_brand_count, brand_premium_rate,
               create_by, create_time, update_by, update_time, remark
        from biz_common_prosperity_achievement
    </sql>

    <select id="selectBizCommonProsperityAchievementById" parameterType="long" resultMap="BizCommonProsperityAchievementResult">
        <include refid="selectVo"/>
        where id = #{id}
    </select>

    <select id="selectBizCommonProsperityAchievementList" parameterType="com.ruoyi.web.modules.prosperity.domain.BizCommonProsperityAchievement" resultMap="BizCommonProsperityAchievementResult">
        <include refid="selectVo"/>
        <where>
            <if test="statYear != null and statYear != ''">
                and stat_period like concat(#{statYear}, '-%')
            </if>
        </where>
        order by stat_period desc, create_time desc, id desc
    </select>

    <select id="countByStatPeriod" resultType="int">
        select count(*) from biz_common_prosperity_achievement
        where stat_period = #{statPeriod}
        <if test="excludeId != null">
            and id != #{excludeId}
        </if>
    </select>

    <insert id="insertBizCommonProsperityAchievement" parameterType="com.ruoyi.web.modules.prosperity.domain.BizCommonProsperityAchievement" useGeneratedKeys="true" keyProperty="id">
        insert into biz_common_prosperity_achievement (
            stat_period, collective_economy_income, employment_driven_count, new_job_positions,
            env_project_count, new_green_area, cultural_heritage_count,
            ethnic_integration_project_count, ethnic_unity_activity_count,
            digital_platform_usage_rate, regional_public_brand_count, brand_premium_rate,
            create_by, create_time, remark
        ) values (
            #{statPeriod}, #{collectiveEconomyIncome}, #{employmentDrivenCount}, #{newJobPositions},
            #{envProjectCount}, #{newGreenArea}, #{culturalHeritageCount},
            #{ethnicIntegrationProjectCount}, #{ethnicUnityActivityCount},
            #{digitalPlatformUsageRate}, #{regionalPublicBrandCount}, #{brandPremiumRate},
            #{createBy}, sysdate(), #{remark}
        )
    </insert>

    <update id="updateBizCommonProsperityAchievement" parameterType="com.ruoyi.web.modules.prosperity.domain.BizCommonProsperityAchievement">
        update biz_common_prosperity_achievement set
            stat_period = #{statPeriod},
            collective_economy_income = #{collectiveEconomyIncome},
            employment_driven_count = #{employmentDrivenCount},
            new_job_positions = #{newJobPositions},
            env_project_count = #{envProjectCount},
            new_green_area = #{newGreenArea},
            cultural_heritage_count = #{culturalHeritageCount},
            ethnic_integration_project_count = #{ethnicIntegrationProjectCount},
            ethnic_unity_activity_count = #{ethnicUnityActivityCount},
            digital_platform_usage_rate = #{digitalPlatformUsageRate},
            regional_public_brand_count = #{regionalPublicBrandCount},
            brand_premium_rate = #{brandPremiumRate},
            update_by = #{updateBy},
            update_time = sysdate(),
            remark = #{remark}
        where id = #{id}
    </update>

    <delete id="deleteBizCommonProsperityAchievementByIds" parameterType="long">
        delete from biz_common_prosperity_achievement where id in
        <foreach collection="array" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectByStatYear" resultMap="BizCommonProsperityAchievementResult">
        <include refid="selectVo"/>
        where stat_period like concat(#{statYear}, '-%')
        order by stat_period asc
    </select>

    <select id="selectDistinctStatYears" resultType="string">
        select distinct left(stat_period, 4) as stat_year
        from biz_common_prosperity_achievement
        order by stat_year desc
    </select>
</mapper>
