<?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.szxc.mapper.SzxcCarInfoMapper">
    
    <resultMap type="SzxcCarInfo" id="SzxcCarInfoResult">
        <result property="id"    column="id"    />
        <result property="ownerId"    column="owner_id"    />
        <result property="ownerName"    column="owner_name"    />
        <result property="phone"    column="phone"    />
        <result property="carNo"    column="car_no"    />
        <result property="carType"    column="car_type"    />
        <result property="colour"    column="colour"    />
        <result property="carBand"    column="car_band"    />
        <result property="carPicture"    column="car_picture"    />
        <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="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="userId"    column="user_id"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectSzxcCarInfoVo">
        select id, owner_id, owner_name, phone, car_no, car_type, colour, car_band, car_picture, create_by, create_time, update_by, update_time, dept_id, dept_name, user_id, remark from szxc_car_info
    </sql>

    <select id="selectSzxcCarInfoList" parameterType="SzxcCarInfo" resultMap="SzxcCarInfoResult">
        <include refid="selectSzxcCarInfoVo"/> as c
        <where>  
            <if test="ownerId != null "> and owner_id = #{ownerId}</if>
            <if test="ownerName != null  and ownerName != ''"> and owner_name like concat('%', #{ownerName}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="carNo != null  and carNo != ''"> and car_no = #{carNo}</if>
            <if test="carType != null  and carType != ''"> and car_type = #{carType}</if>
            <if test="colour != null  and colour != ''"> and colour = #{colour}</if>
            <if test="carBand != null  and carBand != ''"> and car_band = #{carBand}</if>
            <if test="carPicture != null  and carPicture != ''"> and car_picture = #{carPicture}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="params.dataScope != null and params.dataScope !=''">
                ${params.dataScope}
            </if>
        </where>
    </select>
    
    <select id="selectSzxcCarInfoById" parameterType="Long" resultMap="SzxcCarInfoResult">
        <include refid="selectSzxcCarInfoVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSzxcCarInfo" parameterType="SzxcCarInfo" useGeneratedKeys="true" keyProperty="id">
        insert into szxc_car_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ownerId != null">owner_id,</if>
            <if test="ownerName != null and ownerName != ''">owner_name,</if>
            <if test="phone != null">phone,</if>
            <if test="carNo != null and carNo != ''">car_no,</if>
            <if test="carType != null and carType != ''">car_type,</if>
            <if test="colour != null and colour != ''">colour,</if>
            <if test="carBand != null">car_band,</if>
            <if test="carPicture != null">car_picture,</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>
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="userId != null">user_id,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="ownerId != null">#{ownerId},</if>
            <if test="ownerName != null and ownerName != ''">#{ownerName},</if>
            <if test="phone != null">#{phone},</if>
            <if test="carNo != null and carNo != ''">#{carNo},</if>
            <if test="carType != null and carType != ''">#{carType},</if>
            <if test="colour != null and colour != ''">#{colour},</if>
            <if test="carBand != null">#{carBand},</if>
            <if test="carPicture != null">#{carPicture},</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>
            <if test="deptId != null">#{deptId},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="userId != null">#{userId},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateSzxcCarInfo" parameterType="SzxcCarInfo">
        update szxc_car_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="ownerId != null">owner_id = #{ownerId},</if>
            <if test="ownerName != null and ownerName != ''">owner_name = #{ownerName},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="carNo != null and carNo != ''">car_no = #{carNo},</if>
            <if test="carType != null and carType != ''">car_type = #{carType},</if>
            <if test="colour != null and colour != ''">colour = #{colour},</if>
            <if test="carBand != null">car_band = #{carBand},</if>
            <if test="carPicture != null">car_picture = #{carPicture},</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>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSzxcCarInfoById" parameterType="Long">
        delete from szxc_car_info where id = #{id}
    </delete>

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