<?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.dcsoft.system.vehicle.mapper.CarChargeMapper">

    <resultMap type="CarCharge" id="CarChargeResult">
        <result property="id"    column="id"    />
        <result property="parkId"    column="park_id"    />
        <result property="parkName"    column="park_name"    />
        <result property="name"    column="name"    />
        <result property="type"    column="type"    />
        <result property="timeLong"    column="time_long"    />
        <result property="chargeMoney"    column="charge_money"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectCarChargeVo">
        select cc.id, cc.park_id, cc.name, cc.type, cc.time_long, cc.charge_money, cc.status, cc.remark, cc.create_by,
               cc.create_time, cc.update_by, cc.update_time ,cp.name park_name
        from car_charge cc
        left join car_park cp on cc.park_id=cp.id
    </sql>

    <select id="selectCarChargeList" parameterType="CarCharge" resultMap="CarChargeResult">
        <include refid="selectCarChargeVo"/>
        <where>
            <if test="parkId != null "> and cc.park_id = #{parkId}</if>
            <if test="name != null  and name != ''"> and cc.name like concat('%', #{name}, '%')</if>
            <if test="status != null  and status != ''"> and cc.status = #{status}</if>
        </where>
    </select>

    <select id="selectCarChargeById" parameterType="Long" resultMap="CarChargeResult">
        <include refid="selectCarChargeVo"/>
        where cc.id = #{id}
    </select>

    <insert id="insertCarCharge" parameterType="CarCharge" useGeneratedKeys="true" keyProperty="id">
        insert into car_charge
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parkId != null">park_id,</if>
            <if test="name != null">name,</if>
            <if test="type != null">type,</if>
            <if test="timeLong != null">time_long,</if>
            <if test="chargeMoney != null">charge_money,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="parkId != null">#{parkId},</if>
            <if test="name != null">#{name},</if>
            <if test="type != null">#{type},</if>
            <if test="timeLong != null">#{timeLong},</if>
            <if test="chargeMoney != null">#{chargeMoney},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateCarCharge" parameterType="CarCharge">
        update car_charge
        <trim prefix="SET" suffixOverrides=",">
            <if test="parkId != null">park_id = #{parkId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="type != null">type = #{type},</if>
            <if test="timeLong != null">time_long = #{timeLong},</if>
            <if test="chargeMoney != null">charge_money = #{chargeMoney},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCarChargeById" parameterType="Long">
        delete from car_charge where id = #{id}
    </delete>

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