<?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.project.shiftmgr.mapper.TShiftAnnualAssessmentMapper">
    
    <resultMap type="TShiftAnnualAssessment" id="TShiftAnnualAssessmentResult">
        <result property="id"    column="id"    />
        <result property="staffId"    column="staff_id"    />
        <result property="team"    column="team"    />
        <result property="leaderId"    column="leader_id"    />
        <result property="assYear"    column="ass_year"    />
        <result property="leaderScore"    column="leader_score"    />
        <result property="foremanScore"    column="foreman_score"    />
        <result property="directorScore"    column="director_score"    />
        <result property="engineerScore"    column="engineer_score"    />
        <result property="managerSocre"    column="manager_socre"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTShiftAnnualAssessmentVo">
        select d.id, d.staff_id, d.team, d.leader_id, d.ass_year, d.leader_score, d.foreman_score, d.director_score, d.engineer_score, d.manager_socre, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id ,s.dept_name from t_shift_annual_assessment d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTShiftAnnualAssessmentList" parameterType="TShiftAnnualAssessment" resultMap="TShiftAnnualAssessmentResult">
        <include refid="selectTShiftAnnualAssessmentVo"/>
        <where>  
            <if test="staffId != null  and staffId != ''"> and staff_id = #{staffId}</if>
            <if test="team != null  and team != ''"> and team = #{team}</if>
            <if test="leaderId != null  and leaderId != ''"> and leader_id = #{leaderId}</if>
            <if test="assYear != null  and assYear != ''"> and ass_year = #{assYear}</if>
            <if test="leaderScore != null "> and leader_score = #{leaderScore}</if>
            <if test="foremanScore != null "> and foreman_score = #{foremanScore}</if>
            <if test="directorScore != null "> and director_score = #{directorScore}</if>
            <if test="engineerScore != null "> and engineer_score = #{engineerScore}</if>
            <if test="managerSocre != null "> and manager_socre = #{managerSocre}</if>
            <if test="createrCode != null "> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTShiftAnnualAssessmentById" parameterType="Long" resultMap="TShiftAnnualAssessmentResult">
        <include refid="selectTShiftAnnualAssessmentVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTShiftAnnualAssessment" parameterType="TShiftAnnualAssessment">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT SEQ_T_SHIFT_ANNUAL_ASSESSMENT.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_shift_annual_assessment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="staffId != null">staff_id,</if>
            <if test="team != null">team,</if>
            <if test="leaderId != null">leader_id,</if>
            <if test="assYear != null">ass_year,</if>
            <if test="leaderScore != null">leader_score,</if>
            <if test="foremanScore != null">foreman_score,</if>
            <if test="directorScore != null">director_score,</if>
            <if test="engineerScore != null">engineer_score,</if>
            <if test="managerSocre != null">manager_socre,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="staffId != null">#{staffId},</if>
            <if test="team != null">#{team},</if>
            <if test="leaderId != null">#{leaderId},</if>
            <if test="assYear != null">#{assYear},</if>
            <if test="leaderScore != null">#{leaderScore},</if>
            <if test="foremanScore != null">#{foremanScore},</if>
            <if test="directorScore != null">#{directorScore},</if>
            <if test="engineerScore != null">#{engineerScore},</if>
            <if test="managerSocre != null">#{managerSocre},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTShiftAnnualAssessment" parameterType="TShiftAnnualAssessment">
        update t_shift_annual_assessment
        <trim prefix="SET" suffixOverrides=",">
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="team != null">team = #{team},</if>
            <if test="leaderId != null">leader_id = #{leaderId},</if>
            <if test="assYear != null">ass_year = #{assYear},</if>
            <if test="leaderScore != null">leader_score = #{leaderScore},</if>
            <if test="foremanScore != null">foreman_score = #{foremanScore},</if>
            <if test="directorScore != null">director_score = #{directorScore},</if>
            <if test="engineerScore != null">engineer_score = #{engineerScore},</if>
            <if test="managerSocre != null">manager_socre = #{managerSocre},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTShiftAnnualAssessmentById" parameterType="Long">
        update t_shift_annual_assessment set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTShiftAnnualAssessmentByIds" parameterType="String">
        update t_shift_annual_assessment set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    
</mapper>