<?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.powerdistribution.mapper.PdmScoreRankWorkerMapper">

    <resultMap type="PdmScoreRankWorker" id="PdmScoreRankWorkerResult">
        <result property="id"    column="id"    />
        <result property="reportYear"    column="report_year"    />
        <result property="reportDate"    column="report_date"    />
        <result property="companyNo"    column="company_no"    />
        <result property="companyName"    column="company_name"    />
        <result property="workUserId"    column="work_user_id"    />
        <result property="workUserName"    column="work_user_name"    />
        <result property="score"    column="score"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectPdmScoreRankWorkerVo">
        select id, report_year, report_date, company_no, company_name, work_user_id, work_user_name, score, create_by, create_time, update_by, update_time from pdm_score_rank_worker
    </sql>

    <select id="selectPdmScoreRankWorkerList" parameterType="PdmScoreRankWorker" resultMap="PdmScoreRankWorkerResult">
        <include refid="selectPdmScoreRankWorkerVo"/>
        <where>
            <if test="reportYear != null  and reportYear != ''"> and report_year = #{reportYear}</if>
            <if test="reportDate != null  and reportDate != ''"> and report_date = #{reportDate}</if>
            <if test="companyNo != null  and companyNo != ''"> and company_no = #{companyNo}</if>
            <if test="companyName != null  and companyName != ''"> and company_name like concat('%', #{companyName}, '%')</if>
            <if test="workUserId != null  and workUserId != ''"> and work_user_id = #{workUserId}</if>
            <if test="workUserName != null  and workUserName != ''"> and work_user_name like concat('%', #{workUserName}, '%')</if>
            <if test="score != null "> and score = #{score}</if>
        </where>
        order by score desc
    </select>

    <select id="selectPdmScoreRankWorkerById" parameterType="Long" resultMap="PdmScoreRankWorkerResult">
        <include refid="selectPdmScoreRankWorkerVo"/>
        where id = #{id}
    </select>

    <insert id="insertPdmScoreRankWorker" parameterType="PdmScoreRankWorker" useGeneratedKeys="true" keyProperty="id">
        insert into pdm_score_rank_worker
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="reportYear != null">report_year,</if>
            <if test="reportDate != null">report_date,</if>
            <if test="companyNo != null">company_no,</if>
            <if test="companyName != null">company_name,</if>
            <if test="workUserId != null">work_user_id,</if>
            <if test="workUserName != null">work_user_name,</if>
            <if test="score != null">score,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="reportYear != null">#{reportYear},</if>
            <if test="reportDate != null">#{reportDate},</if>
            <if test="companyNo != null">#{companyNo},</if>
            <if test="companyName != null">#{companyName},</if>
            <if test="workUserId != null">#{workUserId},</if>
            <if test="workUserName != null">#{workUserName},</if>
            <if test="score != null">#{score},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updatePdmScoreRankWorker" parameterType="PdmScoreRankWorker">
        update pdm_score_rank_worker
        <trim prefix="SET" suffixOverrides=",">
            <if test="reportYear != null">report_year = #{reportYear},</if>
            <if test="reportDate != null">report_date = #{reportDate},</if>
            <if test="companyNo != null">company_no = #{companyNo},</if>
            <if test="companyName != null">company_name = #{companyName},</if>
            <if test="workUserId != null">work_user_id = #{workUserId},</if>
            <if test="workUserName != null">work_user_name = #{workUserName},</if>
            <if test="score != null">score = #{score},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePdmScoreRankWorkerById" parameterType="Long">
        delete from pdm_score_rank_worker where id = #{id}
    </delete>

    <delete id="deletePdmScoreRankWorkerByIds" parameterType="String">
        delete from pdm_score_rank_worker where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
