<?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.ygtx.gxt.mapper.GxtSafeOperationRewardMapper">

    <resultMap type="GxtSafeOperationReward" id="GxtSafeOperationRewardResult">
        <result property="id" column="id"/>
        <result property="safeDuration" column="safe_duration"/>
        <result property="plannedMaintenanceScore" column="planned_maintenance_score"/>
        <result property="unplannedMaintenanceScore" column="unplanned_maintenance_score"/>
        <result property="downtimeScore" column="downtime_score"/>
        <result property="status" column="status"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectGxtSafeOperationRewardVo">
        select id, safe_duration, planned_maintenance_score, unplanned_maintenance_score, downtime_score, status, create_by, create_time, update_by, update_time, remark from gxt_safe_operation_reward
    </sql>

    <select id="selectGxtSafeOperationRewardList" parameterType="GxtSafeOperationReward" resultMap="GxtSafeOperationRewardResult">
        <include refid="selectGxtSafeOperationRewardVo"/>
        <where>  
            <if test="safeDuration != null "> and safe_duration = #{safeDuration}</if>
            <if test="plannedMaintenanceScore != null "> and planned_maintenance_score = #{plannedMaintenanceScore}</if>
            <if test="unplannedMaintenanceScore != null "> and unplanned_maintenance_score = #{unplannedMaintenanceScore}</if>
            <if test="downtimeScore != null "> and downtime_score = #{downtimeScore}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
        order by safe_duration asc
    </select>
    
    <select id="selectGxtSafeOperationRewardById" parameterType="Long" resultMap="GxtSafeOperationRewardResult">
        <include refid="selectGxtSafeOperationRewardVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertGxtSafeOperationReward" parameterType="GxtSafeOperationReward" useGeneratedKeys="true" keyProperty="id">
        insert into gxt_safe_operation_reward
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="safeDuration != null">safe_duration,</if>
            <if test="plannedMaintenanceScore != null">planned_maintenance_score,</if>
            <if test="unplannedMaintenanceScore != null">unplanned_maintenance_score,</if>
            <if test="downtimeScore != null">downtime_score,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null and updateBy != ''">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="safeDuration != null">#{safeDuration},</if>
            <if test="plannedMaintenanceScore != null">#{plannedMaintenanceScore},</if>
            <if test="unplannedMaintenanceScore != null">#{unplannedMaintenanceScore},</if>
            <if test="downtimeScore != null">#{downtimeScore},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateGxtSafeOperationReward" parameterType="GxtSafeOperationReward">
        update gxt_safe_operation_reward
        <trim prefix="SET" suffixOverrides=",">
            <if test="safeDuration != null">safe_duration = #{safeDuration},</if>
            <if test="plannedMaintenanceScore != null">planned_maintenance_score = #{plannedMaintenanceScore},</if>
            <if test="unplannedMaintenanceScore != null">unplanned_maintenance_score = #{unplannedMaintenanceScore},</if>
            <if test="downtimeScore != null">downtime_score = #{downtimeScore},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGxtSafeOperationRewardById" parameterType="Long">
        delete from gxt_safe_operation_reward where id = #{id}
    </delete>

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