SysLogMapper.xml 13.5 KB
Newer Older
苗卫卫 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
<?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.boco.nbd.wios.log.mapper.def.SysLogMapper">
	<resultMap id="SysLog"
		type="com.boco.nbd.wios.log.entity.po.SysLogPO">
		<result column="module_id" property="moduleId" />
		<result column="bussiness_name" property="bussinessName" />
		<result column="use_time" property="useTime" />
		<result column="logcontent" property="logcontent" />
		<result column="region_id" property="regionId" />
		<result column="user_id" property="userId" />
		<result column="log_id" property="logId" />
		<result column="user_name" property="userName" />
		<result column="handle_consuming_time" property="handleConsumingTime" />
		<result column="ip_address" property="ipAddress" />
		<result column="service_name" property="serviceName" />
		<result column="service_ip" property="serviceIp" />
	</resultMap>

	<sql id="Base_Column_List">
		module_id,
		bussiness_name,
		use_time,
		logcontent,
		region_id,
		user_id,
		log_id,
		user_name,
		handle_consuming_time,
		ip_address,
		service_name,
		service_ip
	</sql>

	<!-- 新增一条实体 -->
	<insert id="insert" parameterType="com.boco.nbd.wios.log.entity.qo.SysLogQO">
		INSERT INTO tv3_sys_log
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="moduleId != null">
				module_id ,
			</if>
			<if test="bussinessName != null">
				bussiness_name ,
			</if>
			<if test="useTime != null">
				use_time ,
			</if>
			<if test="logcontent != null">
				logcontent ,
			</if>
			<if test="regionId != null">
				region_id ,
			</if>
			<if test="userId != null">
				user_id ,
			</if>
			<if test="logId != null">
				log_id ,
			</if>
			<if test="userName != null">
				user_name ,
			</if>
			<if test="handleConsumingTime != null">
				handle_consuming_time ,
			</if>
			<if test="ipAddress != null">
				ip_address ,
			</if>
			<if test="serviceName != null">
				service_name ,
			</if>
			<if test="serviceIp != null">
				service_ip
			</if>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="moduleId != null">
				#{moduleId},
			</if>
			<if test="bussinessName != null">
				#{bussinessName},
			</if>
			<if test="useTime != null">
				DATE_FORMAT(#{useTime}, '%Y-%m-%d %H:%i:%S'),
			</if>
			<if test="logcontent != null">
				#{logcontent},
			</if>
			<if test="regionId != null">
				#{regionId},
			</if>
			<if test="userId != null">
				#{userId},
			</if>
			<if test="logId != null">
				#{logId},
			</if>
			<if test="userName != null">
				#{userName},
			</if>
			<if test="handleConsumingTime != null">
				#{handleConsumingTime},
			</if>
			<if test="ipAddress != null">
				#{ipAddress},
			</if>
			<if test="serviceName != null">
				#{serviceName},
			</if>
			<if test="serviceIp != null">
				#{serviceIp}
			</if>
		</trim>
	</insert>

	<!-- ############################################登录日志统计############################################ -->


	<!-- 关联了用户模块地市的日志信息详情 -->
	<resultMap id="SysLogInfo"
			   type="com.boco.nbd.wios.log.entity.po.SysLogInfoPO">
		<result column="module_id" property="moduleId" />
		<result column="bussiness_name" property="bussinessName" />
		<result column="use_time" property="useTime" />
		<result column="logcontent" property="logcontent" />
		<result column="user_id" property="userId" />
		<result column="log_id" property="logId" />
		<result column="user_name" property="userName" />
		<result column="handle_consuming_time" property="handleConsumingTime" />
		<result column="ip_address" property="ipAddress" />
		<result column="service_name" property="serviceName" />
		<result column="service_ip" property="serviceIp" />
		<result column="display_name" property="displayName" />
		<result column="parent_id" property="parentId" />
		<result column="role_id" property="roleId" />
		<result column="parent_role_id" property="parentRoleId" />
		<result column="parent_user_name" property="parentUserName" />
	</resultMap>


	<sql id="Include_Login_Where">
		and date_format(USE_TIME,<include refid="framework.framework-datestr" />)
		between #{start} and #{end}
		AND upper(bussiness_name) IN
		(UPPER('login'),UPPER('logout'))
	</sql>

	<sql id="login_counts">
		SUM(CASE WHEN upper(bussiness_name) = UPPER('login') THEN 1 ELSE 0 END ) AS login_Counts,
    	SUM(CASE WHEN upper(bussiness_name) = UPPER('logout') THEN 1 ELSE 0 END ) AS logout_Counts
	</sql>

	<resultMap id="UsersLoginStat"
			   type="com.boco.nbd.wios.log.entity.po.UserLogCountInfoPO">
		<result column="indexs" property="indexs" />
		<result column="id" property="userId" />
		<result column="role_id" property="roleId" />
		<result column="account" property="userName" />
		<result column="name" property="displayName" />
		<result column="login_Counts" property="loginCounts" />
		<result column="logout_Counts" property="logoutCounts" />
	</resultMap>

	<!-- 统计用户级别登录日志 -->
	<select id="getUsersLoginStat" parameterType="java.lang.String"
			resultMap="UsersLoginStat">
		select d.* ,
		-999 as indexs
		from(
			select
				a.id,
				c.role_id,
				a.account,
				a.name,
				IFNULL(login_Counts,0) as login_Counts,
				IFNULL(logout_Counts,0) as logout_Counts
			from
			  wb_account a inner join
			(
			select tv3_sys_log.user_id,
			<include refid="login_counts" />
			from tv3_sys_log
			where 1 = 1
			<include refid="Include_Login_Where" />
			group by tv3_sys_log.user_id
			) b
			on a.id=b.user_id
			INNER JOIN wb_account_role c on a.id=c.account_id
		) d
		order by login_counts desc
	</select>


	<!-- 查询用户的登录日志详细信息 -->
	<select id="getUsersLoginDetails" resultMap="SysLogInfo">
		select a.*,b.name display_name,a.module_id module_name,b.parent_id,c.role_id parent_role_id,d.role_id,e.account parent_user_name
		from
		(
		select * from tv3_sys_log
		where 1=1
		<if test="userId != null and userId != ''">
			and user_id = #{userId}
		</if>
		<include refid="Include_Login_Where" />
		order by use_time desc
		) a
		LEFT JOIN wb_account b ON a.user_id = b.id
		left join wb_account_role c on c.account_id = b.parent_id
		left join wb_account_role d on d.account_id = b.id
		left join wb_account e on b.parent_id = e.id
		ORDER BY USE_TIME DESC
	</select>


	<resultMap id="RolesLoginStat"
			   type="com.boco.nbd.wios.log.entity.po.RoleLogCountInfoPO">
		<result column="indexs" property="indexs" />
		<result column="role_id" property="roleId" />
		<result column="role_name" property="roleName" />
		<result column="login_Counts" property="loginCounts" />
		<result column="logout_Counts" property="logoutCounts" />
	</resultMap>

	<!-- 根据时间角色统计日志 -->
	<select id="getRolesLoginStat" parameterType="java.lang.String"
			resultMap="RolesLoginStat">
		SELECT
			g.*,
			- 999 AS indexs
		FROM
		(
			SELECT
				e.name role_name,
				sum(IFNULL( login_Counts, 0 )) AS login_Counts,
				sum(IFNULL( logout_Counts, 0 )) AS logout_Counts
			FROM
			wb_role e
			LEFT JOIN (
				SELECT
					c.role_id,
					<include refid="login_counts" />
				FROM
				wb_account_role c,
				(
					SELECT
						a.id user_id,
						b.BUSSINESS_NAME,
						b.use_time
						FROM
						wb_account a,
						tv3_sys_log b
					WHERE
						a.id = b.user_id
						<include refid="Include_Login_Where" />
				) d
			WHERE
				c.account_id = d.user_id
				GROUP BY
				c.role_id
				) f ON e.id = f.role_id
				GROUP BY
				e.name
		) g
		ORDER BY
		login_counts DESC
	</select>


	<!-- 查询角色的登录日志详细信息 -->
	<select id="getRolesLoginDetails" parameterType="java.lang.String"
			resultMap="SysLogInfo">
		select
		a.*,b.name display_name,a.module_id module_name,b.parent_id,c.role_id parent_role_id,d.role_id,w.account parent_user_name
		from
		(
			select e.* from
			(
				SELECT * FROM
				tv3_sys_log
				WHERE 1 = 1
				<include refid="Include_Login_Where" />
				order by use_time desc
			) e join
			(
				select account_id
				from wb_account_role g left join wb_role h  on g.role_id=h.id
				where 1=1
				<if test="roleName != null and roleName != ''">
					and h.name = #{roleName}
				</if>
			) f on e.user_id=f.account_id
		) a
		left join wb_account b on a.user_id=b.id
		left join wb_account_role c on c.account_id = b.parent_id
		left join wb_account_role d on d.account_id = b.id
		left join wb_account w on b.parent_id = w.id
		ORDER BY USE_TIME DESC
	</select>


	<!-- ######################统计信息和从统计信息钻取详情##################### -->

	<sql id="Exclude_Login_Where">
		and date_format(USE_TIME,<include refid="framework.framework-datestr" />)
		between #{start} and #{end}
		AND upper(bussiness_name) NOT IN
		(UPPER('login'),UPPER('logout'))
	</sql>

	<resultMap id="UserLogCountInfoPO"
			   type="com.boco.nbd.wios.log.entity.po.UserLogCountInfoPO">
		<result column="indexs" property="indexs" />
		<result column="id" property="userId" />
		<result column="account" property="userName" />
		<result column="name" property="displayName" />
		<result column="counts" property="counts" />
	</resultMap>

	<!-- 根据时间用户统计日志-->
	<select id="countByUserDate" parameterType="java.lang.String"
			resultMap="UserLogCountInfoPO">
		select c.* ,
		-999 indexs
		from(
			select
			a.id,a.account,a.name,
			IFNULL(b.counts,0) as counts
			from
			wb_account a inner join
			(
				select tv3_sys_log.user_id,count(0) as counts
				from tv3_sys_log
				where 1 = 1
				<include refid="Exclude_Login_Where" />
				group by tv3_sys_log.user_id
			) b
			on a.id=b.user_id
		) c
		order by counts desc
	</select>



	<!-- 根据用户ID查询访问日志详细信息 -->
	<select id="selectLogInfoByUserIdDate" resultMap="SysLogInfo">
		select a.*,b.name display_name,a.module_id module_name,b.parent_id,c.role_id parent_role_id,d.role_id,e.account parent_user_name
		from
		(
		select * from tv3_sys_log
		where 1=1
		<if test="userId != null and userId != ''">
			and user_id = #{userId}
		</if>
		<include refid="Exclude_Login_Where" />
		order by use_time desc
		) a
		LEFT JOIN wb_account b ON a.user_id = b.id
		left join wb_account_role c on c.account_id = b.parent_id
		left join wb_account_role d on d.account_id = b.id
		left join wb_account e on b.parent_id = e.id
		ORDER BY USE_TIME DESC
	</select>



	<resultMap id="RoleLogCountInfoPO"
			   type="com.boco.nbd.wios.log.entity.po.RoleLogCountInfoPO">
		<result column="indexs" property="indexs" />
		<result column="role_id" property="roleId" />
		<result column="role_name" property="roleName" />
		<result column="counts" property="counts" />
	</resultMap>

	<!-- 根据时间角色统计日志 -->
	<select id="countByRoleDate" parameterType="java.lang.String"
			resultMap="RoleLogCountInfoPO">
		SELECT
			g.*,
			- 999 AS indexs
		FROM
		(
			SELECT
				e.name role_name,
				sum(IFNULL(f.counts,0)) AS counts
			FROM
			wb_role e
			LEFT JOIN (
				SELECT
					c.role_id,
					count(*)as counts
				FROM
				wb_account_role c,
				(
					SELECT
						a.id user_id,
						b.BUSSINESS_NAME,
						b.use_time
						FROM
						wb_account a,
						tv3_sys_log b
					WHERE
						a.id = b.user_id
						<include refid="Exclude_Login_Where" />
				) d
			WHERE
				c.account_id = d.user_id
				GROUP BY
				c.role_id
				) f ON e.id = f.role_id
				GROUP BY
				e.name
		) g
		ORDER BY
		counts desc
	</select>


	<!-- 根据角色查询访问日志 -->
	<select id="selectByRoleDate" parameterType="java.lang.String"
			resultMap="SysLogInfo">
		select
		a.*,b.name display_name,a.module_id module_name,b.parent_id,c.role_id parent_role_id,d.role_id,w.account parent_user_name
		from
		(
		select e.* from
		(
		SELECT * FROM
		tv3_sys_log
		WHERE 1 = 1
		<include refid="Exclude_Login_Where" />
		order by use_time desc
		) e join
		(
		select account_id
		from wb_account_role g left join wb_role h  on g.role_id=h.id
		where 1=1
		<if test="roleName != null and roleName != ''">
			and h.name = #{roleName}
		</if>
		) f on e.user_id=f.account_id
		) a
		left join wb_account b on a.user_id=b.id
		left join wb_account_role c on c.account_id = b.parent_id
		left join wb_account_role d on d.account_id = b.id
		left join wb_account w on b.parent_id = w.id
		ORDER BY USE_TIME DESC
	</select>


	<!-- ###################模块访问日志统计分割线######################### */-->
	<resultMap id="ModuleLogCountInfoPO"
			   type="com.boco.nbd.wios.log.entity.po.ModuleLogCountInfoPO">
		<result column="indexs" property="indexs" />
		<result column="module_id" property="moduleId" />
		<result column="module_name" property="moduleName" />
		<result column="counts" property="counts" />
	</resultMap>

	<!-- 根据时间模块统计日志 -->
	<select id="countByModuleDate"
			resultMap="ModuleLogCountInfoPO">
		select g.* ,
		-999 as indexs
		from(
		select module_id,module_id module_name,count(0) as counts
		from tv3_sys_log
		where 1 = 1
		<include refid="Exclude_Login_Where" />
		group by module_id
		) g

		order by counts desc
	</select>


	<!-- 根据模块ID查询日志详细信息 -->
	<select id="selectLogInfoByModuleIdDate" resultMap="SysLogInfo">
		select a.*,b.name display_name,a.module_id module_name,b.parent_id,c.role_id parent_role_id,d.role_id,w.account parent_user_name
		from
		(
		select * from
		tv3_sys_log where 1=1
		<if test="moduleId != null and moduleId != ''">
			and module_id = #{moduleId}
		</if>
		<include refid="Exclude_Login_Where" />
		order by use_time desc
		) a
		left join wb_account b on a.user_id=b.id
		left join wb_account_role c on c.account_id = b.parent_id
		left join wb_account_role d on d.account_id = b.id
		left join wb_account w on b.parent_id = w.id
		ORDER BY USE_TIME DESC
	</select>
</mapper>