<?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.goldenwater.slaj.acci.mapper.BisAcciAssessMapper">
    <resultMap type="com.goldenwater.slaj.acci.domain.BisAcciAssess" id="BisAcciAssessResult">
        <result property="id" column="id"/>
        <result property="orgGuid" column="org_guid"/>
        <result property="orgName" column="org_name"/>
        <result property="orgCode" column="org_code"/>
        <result property="assessYear" column="assess_year"/>
        <result property="assessDateNum" column="assess_date_num"/>
        <result property="unitRange" column="unit_range"/>
        <result property="coeffAcciScore" column="coeff_acci_score"/>
        <result property="coeffAcciJumbo" column="coeff_acci_jumbo"/>
        <result property="coeffAcciMajor" column="coeff_acci_major"/>
        <result property="coeffAcciLarger" column="coeff_acci_larger"/>
        <result property="coeffAcciNormal" column="coeff_acci_normal"/>
        <result property="collTime" column="coll_time"/>
    </resultMap>
    <sql id="selectBisAcciAssessVo">
        select id, org_guid, org_name, org_code, assess_year, assess_date_num,
               unit_range, coeff_acci_score, coeff_acci_jumbo, coeff_acci_major,
               coeff_acci_larger, coeff_acci_normal, coll_time
        from bis_acci_assess
    </sql>
    <select id="selectBisAcciAssessById" parameterType="Long" resultMap="BisAcciAssessResult">
        <include refid="selectBisAcciAssessVo"/>
        where id = #{id}
    </select>
    <select id="selectBisAcciAssessList" parameterType="com.goldenwater.slaj.acci.domain.BisAcciAssess" resultMap="BisAcciAssessResult">
        <include refid="selectBisAcciAssessVo"/>
        <where>
            <if test="orgGuid != null and orgGuid != ''">AND org_guid = #{orgGuid}</if>
            <if test="orgName != null and orgName != ''">AND org_name like '%' || #{orgName} || '%'</if>
            <if test="orgCode != null and orgCode != ''">AND org_code = #{orgCode}</if>
            <if test="assessYear != null">AND assess_year = #{assessYear}</if>
            <if test="assessDateNum != null">AND assess_date_num = #{assessDateNum}</if>
            <if test="unitRange != null">AND unit_range = #{unitRange}</if>
        </where>
    </select>
    <insert id="insertBisAcciAssess" parameterType="com.goldenwater.slaj.acci.domain.BisAcciAssess">
        insert into bis_acci_assess (
            id, org_guid, org_name, org_code, assess_year, assess_date_num,
            unit_range, coeff_acci_score, coeff_acci_jumbo, coeff_acci_major,
            coeff_acci_larger, coeff_acci_normal, coll_time
        ) values (
            #{id}, #{orgGuid}, #{orgName}, #{orgCode}, #{assessYear}, #{assessDateNum},
            #{unitRange}, #{coeffAcciScore}, #{coeffAcciJumbo}, #{coeffAcciMajor},
            #{coeffAcciLarger}, #{coeffAcciNormal}, #{collTime}
        )
    </insert>
    <update id="updateBisAcciAssess" parameterType="com.goldenwater.slaj.acci.domain.BisAcciAssess">
        update bis_acci_assess
        <set>
            <if test="orgGuid != null">org_guid = #{orgGuid},</if>
            <if test="orgName != null">org_name = #{orgName},</if>
            <if test="orgCode != null">org_code = #{orgCode},</if>
            <if test="assessYear != null">assess_year = #{assessYear},</if>
            <if test="assessDateNum != null">assess_date_num = #{assessDateNum},</if>
            <if test="unitRange != null">unit_range = #{unitRange},</if>
            <if test="coeffAcciScore != null">coeff_acci_score = #{coeffAcciScore},</if>
            <if test="coeffAcciJumbo != null">coeff_acci_jumbo = #{coeffAcciJumbo},</if>
            <if test="coeffAcciMajor != null">coeff_acci_major = #{coeffAcciMajor},</if>
            <if test="coeffAcciLarger != null">coeff_acci_larger = #{coeffAcciLarger},</if>
            <if test="coeffAcciNormal != null">coeff_acci_normal = #{coeffAcciNormal},</if>
            <if test="collTime != null">coll_time = #{collTime},</if>
        </set>
        where id = #{id}
    </update>
    <delete id="deleteBisAcciAssessById" parameterType="Long">
        delete from bis_acci_assess where id = #{id}
    </delete>
    <delete id="deleteBisAcciAssessByIds" parameterType="Long">
        delete from bis_acci_assess where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectAcciAssessRanking" parameterType="com.goldenwater.slaj.acci.domain.BisAcciAssess" resultType="java.util.LinkedHashMap">
        select a.id,
               a.org_guid as orgGuid,
               a.org_name as orgName,
               a.assess_year as assessYear,
               a.assess_date_num as assessDateNum,
               a.coeff_acci_score as coeffAcciScore,
               a.coeff_acci_jumbo as coeffAcciJumbo,
               a.coeff_acci_major as coeffAcciMajor,
               a.coeff_acci_larger as coeffAcciLarger,
               a.coeff_acci_normal as coeffAcciNormal
        from bis_acci_assess a
        <where>
            <if test="assessYear != null">AND a.assess_year = #{assessYear}</if>
            <if test="assessDateNum != null">AND a.assess_date_num = #{assessDateNum}</if>
            <if test="orgGuid != null and orgGuid != ''">AND a.org_guid = #{orgGuid}</if>
            <if test="unitRange != null">AND a.unit_range = #{unitRange}</if>
        </where>
        order by a.assess_year desc, a.assess_date_num desc, a.coeff_acci_score desc
    </select>
</mapper>
