<?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.css.simulation.resource.server.infra.db.mysql.mapper.ScoringRulesMapper">

    <insert id="saveSceneEvaluationRule" parameterType="api.common.pojo.po.scene.SceneEvaluationRulePO">
        insert into simulation.scene_evaluation_rule
        (rule_id, rule_code, rule_name, rule_description, rule_type, script_name, script_path,
         create_user_id, create_time, modify_user_id, modify_time,
         is_deleted)
        values (#{ruleId,jdbcType=VARCHAR}, #{ruleCode,jdbcType=VARCHAR}, #{ruleName,jdbcType=VARCHAR},
                #{ruleDescription,jdbcType=VARCHAR}, #{ruleType,jdbcType=VARCHAR}, #{scriptName,jdbcType=VARCHAR},
                #{scriptPath,jdbcType=VARCHAR},
                #{createUserId,jdbcType=VARCHAR}, #{createTime}, #{modifyUserId,jdbcType=VARCHAR}, #{modifyTime},
                #{isDeleted,jdbcType=VARCHAR})
    </insert>

    <update id="updateSceneEvaluationRule" parameterType="api.common.pojo.po.scene.SceneEvaluationRulePO">
        update simulation.scene_evaluation_rule
        <set>
            <if test="isDeleted != null and isDeleted!=''">
                is_deleted = #{isDeleted,jdbcType=VARCHAR},
            </if>
            <if test="ruleName != null and ruleName!=''">
                rule_name = #{ruleName,jdbcType=VARCHAR},
            </if>
            <if test="ruleDescription != null and ruleDescription!=''">
                rule_description = #{ruleDescription,jdbcType=VARCHAR},
            </if>
            <if test="scriptName != null and scriptName!=''">
                script_name = #{scriptName,jdbcType=VARCHAR},
            </if>
            <if test="scriptPath != null and scriptPath!=''">
                script_path = #{scriptPath,jdbcType=VARCHAR},
            </if>
            <if test="modifyUserId != null and modifyUserId!=''">
                modify_user_id = #{modifyUserId,jdbcType=VARCHAR},
            </if>
            <if test="modifyTime != null">
                modify_time = #{modifyTime},
            </if>
        </set>
        where rule_id = #{ruleId,jdbcType=VARCHAR}
    </update>

    <select id="querySceneEvaluationRuleList" parameterType="api.common.pojo.param.scene.SceneEvaluationRuleParam"
            resultType="api.common.pojo.po.scene.SceneEvaluationRulePO">
        select
        rule_id,rule_code,rule_name, rule_description,rule_type,script_name,script_path,
        create_user_id,create_time,modify_user_id,modify_time,
        is_deleted
        from simulation.scene_evaluation_rule
        <where>
            is_deleted = '0'
            <if test="ruleId != null and ruleId != ''">
                and rule_id = #{ruleId,jdbcType=VARCHAR}
            </if>
            <if test="ruleCode != null and ruleCode != ''">
                and rule_code = #{ruleCode,jdbcType=VARCHAR}
            </if>
            <if test="ruleName != null and ruleName != ''">
                and rule_name like CONCAT('%',#{ruleName,jdbcType=VARCHAR},'%')
            </if>
            <if test="ruleDescription != null and ruleDescription != ''">
                and rule_description like CONCAT('%',#{ruleDescription},'%')
            </if>
            <if test="createUserId != null and createUserId != ''">
                and create_user_id=#{createUserId,jdbcType=VARCHAR}
            </if>
            order by modify_time desc
        </where>

    </select>

</mapper>
