<?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.system.mapper.PosFreightMapper">
    
    <resultMap type="PosFreight" id="PosFreightResult">
        <result property="id"    column="id"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="freight"    column="freight"    />
        <result property="distance"    column="distance"    />
        <result property="startingFare"    column="starting_fare"    />
        <result property="startingDistance"    column="starting_distance"    />
    </resultMap>

    <sql id="selectPosFreightVo">
        select id, start_time, end_time, freight, distance,starting_fare,starting_distance from pos_freight
    </sql>

    <select id="selectPosFreightList" parameterType="PosFreight" resultMap="PosFreightResult">
        <include refid="selectPosFreightVo"/>
        <where>  
            <if test="freight != null "> and freight = #{freight}</if>
        </where>
        order by id desc
    </select>
    
    <select id="selectPosFreightById" parameterType="Long" resultMap="PosFreightResult">
        <include refid="selectPosFreightVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertPosFreight" parameterType="PosFreight" useGeneratedKeys="true" keyProperty="id">
        insert into pos_freight
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="freight != null">freight,</if>
            <if test="distance != null">distance,</if>
            <if test="startingFare != null">starting_fare,</if>
            <if test="startingDistance != null">starting_distance,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="freight != null">#{freight},</if>
            <if test="distance != null">#{distance},</if>
            <if test="startingFare != null">#{startingFare},</if>
            <if test="startingDistance != null">#{startingDistance},</if>
         </trim>
    </insert>

    <update id="updatePosFreight" parameterType="PosFreight">
        update pos_freight
        <trim prefix="SET" suffixOverrides=",">
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="freight != null">freight = #{freight},</if>
            <if test="distance != null">distance = #{distance},</if>
            <if test="startingFare != null">starting_fare = #{startingFare},</if>
            <if test="startingDistance != null">starting_distance = #{startingDistance},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePosFreightById" parameterType="Long">
        delete from pos_freight where id = #{id}
    </delete>

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