<?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.ehs.mapper.TEhskpinewMapper">
    
    <resultMap type="TEhskpinew" id="TEhskpinewResult">
        <result property="id"    column="id"    />
        <result property="plants"    column="plants"    />
        <result property="year"    column="year"    />
        <result property="kpiname"    column="kpiname"    />
        <result property="kpinameen"    column="kpinameen"    />
        <result property="spring"    column="spring"    />
        <result property="summer"    column="summer"    />
        <result property="autumn"    column="autumn"    />
        <result property="winter"    column="winter"    />
        <result property="annual"    column="annual"    />
        <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="remarks"    column="remarks"    />
        <result property="firstquarterStatus"    column="firstquarter_status"    />
        <result property="secondquarterStatus"    column="secondquarter_status"    />
        <result property="threequarterStatus"    column="threequarter_status"    />
        <result property="annualStatus"    column="annual_status"    />
        <result property="fourquarterStatus"    column="fourquarter_status"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTEhskpinewVo">
         select d.id, d.plants, d.year, d.kpiname, d.kpinameen, d.spring, d.summer, d.autumn, d.winter, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks, d.annual, d.firstquarter_status, d.secondquarter_status, d.threequarter_status, d.annual_status, d.fourquarter_status ,s.dept_name from t_ehskpinew d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTEhskpinewList" parameterType="TEhskpinew" resultMap="TEhskpinewResult">
        <include refid="selectTEhskpinewVo"/>
        <where>
            <if test="year != null "> and year = #{year}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>
    
    <select id="selectTEhskpinewById" parameterType="Long" resultMap="TEhskpinewResult">
        <include refid="selectTEhskpinewVo"/>
        where d.id = #{id}
    </select>
        
    <insert id="insertTEhskpinew" parameterType="TEhskpinew">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_ehskpinew.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_ehskpinew
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plants != null">plants,</if>
            <if test="year != null">year,</if>
            <if test="kpiname != null">kpiname,</if>
            <if test="kpinameen != null">kpinameen,</if>
            <if test="spring != null">spring,</if>
            <if test="summer != null">summer,</if>
            <if test="autumn != null">autumn,</if>
            <if test="winter != null">winter,</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>
            <if test="remarks != null">remarks,</if>
            <if test="annual != null">annual,</if>
            <if test="firstquarterStatus != null">firstquarter_status,</if>
            <if test="secondquarterStatus != null">secondquarter_status,</if>
            <if test="threequarterStatus != null">threequarter_status,</if>
            <if test="annualStatus != null">annual_status,</if>
            <if test="fourquarterStatus != null">fourquarter_status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plants != null">#{plants},</if>
            <if test="year != null">#{year},</if>
            <if test="kpiname != null">#{kpiname},</if>
            <if test="kpinameen != null">#{kpinameen},</if>
            <if test="spring != null">#{spring},</if>
            <if test="summer != null">#{summer},</if>
            <if test="autumn != null">#{autumn},</if>
            <if test="winter != null">#{winter},</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>
            <if test="remarks != null">#{remarks},</if>
            <if test="annual != null">#{annual},</if>
            <if test="firstquarterStatus != null">#{firstquarterStatus},</if>
            <if test="secondquarterStatus != null">#{secondquarterStatus},</if>
            <if test="threequarterStatus != null">#{threequarterStatus},</if>
            <if test="annualStatus != null">#{annualStatus},</if>
            <if test="fourquarterStatus != null">#{fourquarterStatus},</if>
         </trim>
    </insert>

    <update id="updateTEhskpinew" parameterType="TEhskpinew">
        update t_ehskpinew
        <trim prefix="SET" suffixOverrides=",">
            <if test="plants != null">plants = #{plants},</if>
            <if test="year != null">year = #{year},</if>
            <if test="kpiname != null">kpiname = #{kpiname},</if>
            <if test="kpinameen != null">kpinameen = #{kpinameen},</if>
            <if test="spring != null">spring = #{spring},</if>
            <if test="summer != null">summer = #{summer},</if>
            <if test="autumn != null">autumn = #{autumn},</if>
            <if test="winter != null">winter = #{winter},</if>
            <if test="spring == null">spring = null,</if>
            <if test="summer == null">summer = null,</if>
            <if test="autumn == null">autumn = null,</if>
            <if test="winter == null">winter = null,</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>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="annual != null">annual = #{annual},</if>
            <if test="annual == null">annual = null,</if>
            <if test="firstquarterStatus != null">firstquarter_status = #{firstquarterStatus},</if>
            <if test="secondquarterStatus != null">secondquarter_status = #{secondquarterStatus},</if>
            <if test="threequarterStatus != null">threequarter_status = #{threequarterStatus},</if>
            <if test="annualStatus != null">annual_status = #{annualStatus},</if>
            <if test="fourquarterStatus != null">fourquarter_status = #{fourquarterStatus},</if>
            <if test="firstquarterStatus == null">firstquarter_status = NULL,</if>
            <if test="secondquarterStatus == null">secondquarter_status = NULL,</if>
            <if test="threequarterStatus == null">threequarter_status = NULL,</if>
            <if test="annualStatus == null">annual_status = NULL,</if>
            <if test="fourquarterStatus == null">fourquarter_status = NULL,</if>
        </trim>
        where id = #{id}
    </update>

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

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