OnlineMapper.xml 3.88 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.huaheng.pc.monitor.online.mapper.UserOnlineMapper">

	<resultMap type="UserOnline" id="UserOnlineResult">
		<id     property="id"         column="id"         />
		<result     property="sessionId"         column="sessionId"         />
		<result property="loginName"         column="loginName"        />
		<result property="deptName"          column="deptName"         />
		<result property="ipaddr"            column="ipaddr"            />
		<result property="longinLocation"    column="loginLocation"    />
		<result property="browser"           column="browser"           />
		<result property="os"                column="os"                />
		<result property="status"            column="status"            />
		<result property="startTimestamp"    column="startTimestsamp"  />
		<result property="lastAccessTime"    column="lastAccessTime"  />
		<result property="expireTime"        column="expireTime"       />
		<result property="warehouseCode"        column="warehouseCode"       />
		<association property="session" javaType="OnlineSession" resultMap="OnlineSessionResult" />
	</resultMap>
	
	<resultMap type="OnlineSession" id="OnlineSessionResult">
		<result property="host"              column="ipaddr"            />
		<result property="browser"           column="browser"           />
		<result property="os"                column="os"                />
		<result property="status"            column="status"            />
	</resultMap>
	
	<sql id="selectOnlineVo">
       select  id,sessionId,loginName,deptName,ipaddr,loginLocation,browser,os,status,status,startTimestsamp,lastAccessTime,expireTime,warehouseCode
		from sys_user_online
    </sql>
    
	<select id="selectOnlineById" parameterType="String" resultMap="UserOnlineResult">
		<include refid="selectOnlineVo"/>
		where sessionid = #{sessionid}
	</select>

	<insert id="saveOnline" parameterType="UserOnline">
		insert into sys_user_online(sessionId, loginName, deptName, ipaddr, loginLocation, browser, os, status, startTimestsamp, lastAccessTime, expireTime,warehouseCode)
        values (#{sessionId}, #{loginName}, #{deptName}, #{ipaddr}, #{longinLocation}, #{browser}, #{os}, #{status}, #{startTimestamp}, #{lastAccessTime}, #{expireTime},#{warehouseCode})
	</insert>

	<update id="updateOnline" parameterType="UserOnline">
		update  sys_user_online
		<set>
			<if test="ipaddr != null">
				ipaddr = #{ipaddr, jdbcType=VARCHAR},
			</if>
			<if test="browser != null">
				browser = #{browser, jdbcType=VARCHAR},
			</if>
			<if test="os != null">
				os = #{os, jdbcType=VARCHAR},
			</if>
			<if test="startTimestamp != null">
				startTimestsamp = #{startTimestamp, jdbcType=TIMESTAMP},
			</if>
			<if test="lastAccessTime != null">
				lastAccessTime = #{lastAccessTime, jdbcType=TIMESTAMP},
			</if>
			<if test="expireTime != null">
				expireTime = #{expireTime, jdbcType=VARCHAR},
			</if>
		</set>
		where id=#{id, jdbcType=INTEGER}
	</update>
	
 	<delete id="deleteOnlineById" parameterType="String">
 		delete from sys_user_online where sessionId = #{sessionId}
 	</delete>
 	
 	<select id="selectUserOnlineList" parameterType="UserOnline" resultMap="UserOnlineResult">
		<include refid="selectOnlineVo"/>
		<where>
			<if test="ipaddr != null and ipaddr != ''">
				AND ipaddr like concat('%', #{ipaddr}, '%')
			</if>
			<if test="warehouseCode != null and warehouseCode != ''">
				AND warehouseCode = #{warehouseCode}
			</if>
			<if test="loginName != null and loginName != ''">
				AND loginName like concat('%', #{loginName}, '%')
			</if>
		</where>
	</select>
	
	<select id="selectOnlineByExpired" parameterType="String" resultMap="UserOnlineResult">
		<include refid="selectOnlineVo"/> o 
		WHERE o.lastAccessTime <![CDATA[ <= ]]> #{lastAccessTime} ORDER BY o.lastAccessTime ASC
	</select>

</mapper>