<?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.plant.mapper.TAwardrecordMapper">

    <resultMap type="TAwardrecord" id="TAwardrecordResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="staffid"    column="staffid"    />
        <result property="name"    column="name"    />
        <result property="team"    column="team"    />
        <result property="commendation"    column="commendation"    />
        <result property="commendationdate"    column="commendationdate"    />
        <result property="deptId"    column="dept_id"    />
        <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="remarks"    column="remarks"    />
        <result property="deptName" column="dept_name" />
        <result property="startDate"    column="commendationdate"    />
        <result property="endDate"    column="commendationdate"    />
    </resultMap>

    <sql id="selectTAwardrecordVo">
        select d.id, d.plant_code, d.staffid, d.name, d.team, d.commendation, d.commendationdate, d.dept_id, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks ,s.dept_name from t_awardrecord d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTAwardrecordList" parameterType="TAwardrecord" resultMap="TAwardrecordResult">
        <include refid="selectTAwardrecordVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat(concat('%', #{name}), '%')</if>
            <if test="team != null  and team != ''"> and team = #{team}</if>
            <if test="teams != null  and teams != ''">
                and
                team in
                <foreach collection="teams.split(',')" item="item" index="index"
                         open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="startDate != null ">and commendationdate <![CDATA[>=]]> #{startDate}</if>
            <if test="endDate != null">and commendationdate <![CDATA[<=]]>#{endDate}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>

    <select id="selectTAwardrecordById" parameterType="Long" resultMap="TAwardrecordResult">
        <include refid="selectTAwardrecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertTAwardrecord" parameterType="TAwardrecord">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_awardrecord.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_awardrecord
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="staffid != null">staffid,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="team != null">team,</if>
            <if test="commendation != null">commendation,</if>
            <if test="commendationdate != null">commendationdate,</if>
            <if test="deptId != null">dept_id,</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="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="staffid != null">#{staffid},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="team != null">#{team},</if>
            <if test="commendation != null">#{commendation},</if>
            <if test="commendationdate != null">#{commendationdate},</if>
            <if test="deptId != null">#{deptId},</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="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTAwardrecord" parameterType="TAwardrecord">
        update t_awardrecord
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="staffid != null">staffid = #{staffid},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="team != null">team = #{team},</if>
            <if test="commendation != null">commendation = #{commendation},</if>
            <if test="commendationdate != null">commendationdate = #{commendationdate},</if>
            <if test="deptId != null">dept_id = #{deptId},</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="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
