TUserLocationMapper.xml 4.48 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?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.zehong.system.mapper.TUserLocationMapper">
    
    <resultMap type="TUserLocation" id="TUserLocationResult">
        <result property="locationId"    column="location_id"    />
        <result property="userId"    column="user_id"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectTUserLocationVo">
16
        select location.location_id, location.user_id, location.longitude, location.latitude, location.create_time,(SELECT sysU.user_name FROM sys_user sysU WHERE sysU.user_id = location.user_id) AS userName,(SELECT sysU.phonenumber FROM sys_user sysU WHERE sysU.user_id = location.user_id) AS phonenumber,(SELECT sysU.nick_name FROM sys_user sysU WHERE sysU.user_id = location.user_id) AS nickName from t_user_location location
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
    </sql>

    <select id="selectTUserLocationList" parameterType="TUserLocation" resultMap="TUserLocationResult">
        <include refid="selectTUserLocationVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="longitude != null "> and longitude = #{longitude}</if>
            <if test="latitude != null "> and latitude = #{latitude}</if>
        </where>
    </select>

    <select id="selectTUserLocationListByMap" parameterType="java.util.Map" resultMap="TUserLocationResult">
        <include refid="selectTUserLocationVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="longitude != null "> and longitude = #{longitude}</if>
            <if test="latitude != null "> and latitude = #{latitude}</if>
            <if test="beginTime != null and endTime != null"> and create_time BETWEEN #{beginTime} AND #{endTime}</if>
        </where>
36
        <if test="userName !=null and userName != ''">HAVING userName LIKE concat('%', #{userName}, '%')</if>
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
        ORDER BY create_time DESC
        <if test="initInspectors == 'initInspectors'">
            LIMIT 1
        </if>

    </select>
    
    <select id="selectTUserLocationById" parameterType="Long" resultMap="TUserLocationResult">
        <include refid="selectTUserLocationVo"/>
        where location_id = #{locationId}
    </select>
        
    <insert id="insertTUserLocation" parameterType="TUserLocation" useGeneratedKeys="true" keyProperty="locationId">
        insert into t_user_location
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>
jianqian's avatar
jianqian committed
64 65 66 67 68 69 70 71 72 73
    <insert id="insertTUserLocationList">
        INSERT INTO t_user_location (user_id,longitude,latitude,create_time)
        VALUES
        <foreach collection="list" index="index" separator="," item="item">
            (#{item.userId},
            #{item.longitude},
            #{item.latitude},
            #{item.createTime})
        </foreach>
    </insert>
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
    <update id="updateTUserLocation" parameterType="TUserLocation">
        update t_user_location
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where location_id = #{locationId}
    </update>

    <delete id="deleteTUserLocationById" parameterType="Long">
        delete from t_user_location where location_id = #{locationId}
    </delete>

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