<?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.VehicleTempMapper">

    <select id="getVehicleTempTree" resultType="api.common.pojo.vo.model.VehicleTempVO">
        SELECT id,
               vehicle_code,
               vehicle_name,
               description,
               model_label,
               vehicle_type,
               vehicle_model,
               vehicle_colour,
               vehicle_front_view,
               vehicle_top_view,
               max_speed,
               engine_power,
               max_deceleration,
               max_steering_angle,
               mass,
               front_surface_effective,
               air_drag_coefficient,
               rolling_resistance_coefficient,
               wheel_diameter,
               wheel_drive,
               overall_efficiency,
               front_distance,
               rear_distance,
               left_distance,
               right_distance,
               height_distance,
               wheelbase,
               valid,
               sort
        FROM model_vehicle_template
        WHERE valid = '1'
          AND is_deleted = '0'
        ORDER BY sort
    </select>

    <select id="getVehicleTempPageList" parameterType="api.common.pojo.param.model.VehiclePageParam"
            resultType="api.common.pojo.vo.model.VehicleTempVO">
        SELECT
        id,
        vehicle_code,
        vehicle_name,
        description,
        model_label,
        vehicle_type,
        vehicle_model,
        vehicle_colour,
        sort,
        valid,
        create_time
        FROM model_vehicle_template
        WHERE is_deleted = '0'
        <if test="vehicleType != null and vehicleType != ''">
            and vehicle_type like CONCAT('%',#{vehicleType,jdbcType=VARCHAR},'%')
        </if>
        <if test="vehicleModel != null and vehicleModel != ''">
            and vehicle_model like CONCAT('%',#{vehicleModel,jdbcType=VARCHAR},'%')
        </if>
        <if test="vehicleColour != null and vehicleColour != ''">
            and vehicle_colour like CONCAT('%',#{vehicleColour,jdbcType=VARCHAR},'%')
        </if>
        <if test="modelLabel != null and modelLabel != ''">
            and model_label like CONCAT('%',#{modelLabel,jdbcType=VARCHAR},'%')
        </if>
        ORDER BY sort
    </select>

    <select id="getVehicleTempInfo" parameterType="api.common.pojo.param.model.VehiclePageParam"
            resultType="api.common.pojo.vo.model.VehicleTempVO">
        SELECT id,
               vehicle_code,
               vehicle_name,
               description,
               model_label,
               vehicle_type,
               vehicle_model,
               vehicle_colour,
               vehicle_front_view,
               vehicle_top_view,
               max_speed,
               engine_power,
               max_deceleration,
               max_steering_angle,
               mass,
               front_surface_effective,
               air_drag_coefficient,
               rolling_resistance_coefficient,
               wheel_diameter,
               wheel_drive,
               overall_efficiency,
               front_distance,
               rear_distance,
               left_distance,
               right_distance,
               height_distance,
               wheelbase,
               valid,
               sort
        FROM model_vehicle_template
        WHERE id = #{id,jdbcType=VARCHAR} limit 1
    </select>

    <select id="selectByModelLabel" parameterType="api.common.pojo.po.model.VehicleTempPO"
            resultType="api.common.pojo.vo.model.VehicleTempVO">
        select id,model_label
        from model_vehicle_template
        where is_deleted = '0'
            and (vehicle_type = #{vehicleType,jdbcType=VARCHAR}
                and vehicle_model = #{vehicleModel,jdbcType=VARCHAR}
                and vehicle_colour = #{vehicleColour,jdbcType=VARCHAR})
           or model_label = #{modelLabel,jdbcType=VARCHAR}
    </select>

    <select id="checkVehicleName" parameterType="api.common.pojo.po.model.VehicleTempPO"
            resultType="api.common.pojo.vo.model.VehicleTempVO">
        select id
        from model_vehicle_template
        where is_deleted = '0'
            and id &lt;&gt; #{id,jdbcType=VARCHAR}
            and (vehicle_type = #{vehicleType,jdbcType=VARCHAR}
                and vehicle_model = #{vehicleModel,jdbcType=VARCHAR}
                and vehicle_colour = #{vehicleColour,jdbcType=VARCHAR})
           or model_label = #{modelLabel,jdbcType=VARCHAR}
    </select>


    <insert id="insert" parameterType="api.common.pojo.po.model.VehicleTempPO">
        insert into model_vehicle_template(id,
                                           vehicle_code,
                                           vehicle_name,
                                           description,
                                           model_label,
                                           vehicle_type,
                                           vehicle_model,
                                           vehicle_colour,
                                           vehicle_front_view,
                                           vehicle_top_view,
                                           max_speed,
                                           engine_power,
                                           max_deceleration,
                                           max_steering_angle,
                                           mass,
                                           front_surface_effective,
                                           air_drag_coefficient,
                                           rolling_resistance_coefficient,
                                           wheel_diameter,
                                           wheel_drive,
                                           overall_efficiency,
                                           front_distance,
                                           rear_distance,
                                           left_distance,
                                           right_distance,
                                           height_distance,
                                           wheelbase,
                                           valid,
                                           sort,
                                           create_time,
                                           modify_time,
                                           create_user_id,
                                           modify_user_id,
                                           is_deleted)
        values (#{id,jdbcType=VARCHAR},
                #{vehicleCode,jdbcType=VARCHAR},
                #{vehicleName,jdbcType=VARCHAR},
                #{description,jdbcType=VARCHAR},
                #{modelLabel,jdbcType=VARCHAR},
                #{vehicleType,jdbcType=VARCHAR},
                #{vehicleModel,jdbcType=VARCHAR},
                #{vehicleColour,jdbcType=VARCHAR},
                #{vehicleFrontView,jdbcType=VARCHAR},
                #{vehicleTopView,jdbcType=VARCHAR},
                #{maxSpeed,jdbcType=DECIMAL},
                #{enginePower,jdbcType=DECIMAL},
                #{maxDeceleration,jdbcType=DECIMAL},
                #{maxSteeringAngle,jdbcType=DECIMAL},
                #{mass,jdbcType=DECIMAL},
                #{frontSurfaceEffective,jdbcType=DECIMAL},
                #{airDragCoefficient,jdbcType=DECIMAL},
                #{rollingResistanceCoefficient,jdbcType=DECIMAL},
                #{wheelDiameter,jdbcType=DECIMAL},
                #{wheelDrive,jdbcType=VARCHAR},
                #{overallEfficiency,jdbcType=DECIMAL},
                #{frontDistance,jdbcType=DECIMAL},
                #{rearDistance,jdbcType=DECIMAL},
                #{leftDistance,jdbcType=DECIMAL},
                #{rightDistance,jdbcType=DECIMAL},
                #{heightDistance,jdbcType=DECIMAL},
                #{wheelbase,jdbcType=DECIMAL},
                #{valid,jdbcType=VARCHAR},
                #{sort,jdbcType=INTEGER},
                #{createTime,jdbcType=TIMESTAMP},
                #{modifyTime,jdbcType=TIMESTAMP},
                #{createUserId,jdbcType=VARCHAR},
                #{modifyUserId,jdbcType=VARCHAR},
                #{isDeleted,jdbcType=VARCHAR})
    </insert>

    <update id="update" parameterType="api.common.pojo.po.model.VehicleTempPO">
        update model_vehicle_template
        set vehicle_name                   = #{vehicleName,jdbcType=VARCHAR},
            description                    = #{description,jdbcType=VARCHAR},
            model_label                    = #{modelLabel,jdbcType=VARCHAR},
            vehicle_type                   = #{vehicleType,jdbcType=VARCHAR},
            vehicle_model                  = #{vehicleModel,jdbcType=VARCHAR},
            vehicle_colour                 = #{vehicleColour,jdbcType=VARCHAR},
            vehicle_front_view             = #{vehicleFrontView,jdbcType=VARCHAR},
            vehicle_top_view               = #{vehicleTopView,jdbcType=VARCHAR},
            max_speed                      = #{maxSpeed,jdbcType=DECIMAL},
            engine_power                   = #{enginePower,jdbcType=DECIMAL},
            max_deceleration               = #{maxDeceleration,jdbcType=DECIMAL},
            max_steering_angle             = #{maxSteeringAngle,jdbcType=DECIMAL},
            mass                           = #{mass,jdbcType=DECIMAL},
            front_surface_effective        = #{frontSurfaceEffective,jdbcType=DECIMAL},
            air_drag_coefficient           = #{airDragCoefficient,jdbcType=DECIMAL},
            rolling_resistance_coefficient = #{rollingResistanceCoefficient,jdbcType=DECIMAL},
            wheel_diameter                 = #{wheelDiameter,jdbcType=DECIMAL},
            wheel_drive                    = #{wheelDrive,jdbcType=VARCHAR},
            overall_efficiency             = #{overallEfficiency,jdbcType=DECIMAL},
            front_distance                 = #{frontDistance,jdbcType=DECIMAL},
            rear_distance                  = #{rearDistance,jdbcType=DECIMAL},
            left_distance                  = #{leftDistance,jdbcType=DECIMAL},
            right_distance                 = #{rightDistance,jdbcType=DECIMAL},
            height_distance                = #{heightDistance,jdbcType=DECIMAL},
            wheelbase                      = #{wheelbase,jdbcType=DECIMAL},
            valid                          = #{valid,jdbcType=VARCHAR},
            sort                           = #{sort,jdbcType=INTEGER},
            modify_time                    = #{modifyTime,jdbcType=TIMESTAMP},
            modify_user_id                 = #{modifyUserId,jdbcType=VARCHAR}
        where id = #{id,jdbcType=VARCHAR}
    </update>

    <update id="delVehicleTempById" parameterType="api.common.pojo.po.model.VehicleTempPO">
        update model_vehicle_template
        set modify_time    = #{modifyTime,jdbcType=TIMESTAMP},
            modify_user_id = #{modifyUserId,jdbcType=VARCHAR},
            is_deleted     = #{isDeleted,jdbcType=VARCHAR}
        where id = #{id,jdbcType=VARCHAR}
    </update>
</mapper>
