GpsOrientationMapper.xml 4.55 KB
<?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.trash.gps.mapper.GpsOrientationMapper">
    
    <resultMap type="GpsOrientation" id="GpsOrientationResult">
        <result property="id"    column="id"    />
        <result property="terminalNumber"    column="terminal_number"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="createTime"    column="create_time"    />
        <result property="carCode"    column="car_code"    />
        <result property="speed"    column="speed"    />
    </resultMap>

    <sql id="selectGpsOrientationVo">
        select id, terminal_number, longitude, latitude, create_time,car_code,speed from gps_orientation_${yearMonth}
    </sql>

    <select id="selectGpsOrientationList" parameterType="GpsOrientation" resultMap="GpsOrientationResult">
        <include refid="selectGpsOrientationVo"/>
        <where>  
            <if test="terminalNumber != null  and terminalNumber != ''"> and terminal_number = #{terminalNumber}</if>
            <if test="createTimeStart!=null and createTimeEnd!=null">create_time between #{createTimeStart} and #{createTimeEnd}</if>
            <if test="carCode!=null and carCode != ''">and car_code = #{carCode}</if>
        </where>
    </select>
    
    <select id="selectGpsOrientationById" parameterType="Long" resultMap="GpsOrientationResult">
        <include refid="selectGpsOrientationVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertGpsOrientation" parameterType="GpsOrientation" useGeneratedKeys="true" keyProperty="id">
        insert into gps_orientation_${yearMonth}
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="terminalNumber != null">terminal_number,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="createTime != null">create_time,</if>
            <if test="carCode != null">car_code,</if>
            <if test="speed != null">speed,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="terminalNumber != null">#{terminalNumber},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="carCode != null">#{carCode},</if>
            <if test="speed != null">#{speed},</if>
         </trim>
    </insert>

    <update id="updateGpsOrientation" parameterType="GpsOrientation">
        update gps_orientation_${yearMonth}
        <trim prefix="SET" suffixOverrides=",">
            <if test="terminalNumber != null">terminal_number = #{terminalNumber},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="carCode != null">car_code = #{carCode},</if>
            <if test="speed != null">speed = #{speed},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGpsOrientationById" parameterType="Long">
        delete from gps_orientation_${yearMonth} where id = #{id}
    </delete>

    <delete id="deleteGpsOrientationByIds" parameterType="String">
        delete from gps_orientation_${yearMonth} where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectCarCodeList" parameterType="String" resultMap="GpsOrientationResult">
        select terminal_number,car_code from gps_orientation_${yearMonth}
        group by terminal_number,car_code
    </select>

    <update id="createGpsTable" parameterType="String">
        CREATE TABLE IF NOT EXISTS gps_orientation_${yearMonth} (
            id bigint(20) NOT NULL AUTO_INCREMENT,
            terminal_number varchar(20) DEFAULT NULL COMMENT '终端号',
            longitude varchar(20) DEFAULT NULL COMMENT '经度',
            latitude varchar(20) DEFAULT NULL COMMENT '纬度',
            create_time datetime DEFAULT NULL COMMENT '创建时间',
            car_code varchar(20) DEFAULT NULL COMMENT '车牌号',
            speed varchar(20) DEFAULT NULL COMMENT '速度km/h',
            PRIMARY KEY (id)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='gps定位表';
    </update>

</mapper>