<?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.hotent.uc.dao.LoginLogDao">
	<resultMap id="LoginLog" type="com.hotent.uc.model.LoginLog">
		<id property="id" column="ID_" jdbcType="VARCHAR"/>
		<result property="name" column="NAME_" jdbcType="VARCHAR"/>
		<result property="account" column="ACCOUNT_" jdbcType="VARCHAR"/>
		<result property="ip" column="IP_" jdbcType="VARCHAR"/>
		<result property="loginType" column="LOGIN_TYPE_" jdbcType="VARCHAR"/>
		<result property="pcSum" column="PC_SUM_" jdbcType="NUMERIC"/>
		<result property="mobileSum" column="MOBILE_SUM_" jdbcType="NUMERIC"/>
		<result property="loginSum" column="LOGIN_SUM_" jdbcType="NUMERIC"/>
		<result property="createBy" column="CREATE_BY_" jdbcType="VARCHAR"/>
		<result property="createTime" column="CREATE_TIME_" jdbcType="TIMESTAMP"/>
		<result property="updateTime" column="UPDATE_TIME_" jdbcType="TIMESTAMP"/>
		<result property="createOrgId" column="CREATE_ORG_ID_" jdbcType="VARCHAR"/>
		<result property="updateBy" column="UPDATE_BY_" jdbcType="VARCHAR"/>
		<result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR"/>
		<result property="isDele" column="IS_DELE_" jdbcType="VARCHAR"/>
		<result property="version" column="VERSION_" jdbcType="NUMERIC"/>
	</resultMap>
	
	<select id="getByAccount"   parameterType="java.lang.String" resultMap="LoginLog">
		SELECT *
		FROM uc_login_log 
		WHERE 
		ACCOUNT_=#{account}
	</select>


	<select id="getLoginLogList"    resultMap="LoginLog">
select * from uc_login_log log
left join (select ACCOUNT_ as accountU,id_ as user_id from uc_user )u on u.accountU=log.ACCOUNT_
left join (select ORG_ID_,USER_ID_ from uc_org_user ) orgUser on orgUser.USER_ID_=u.user_id
		left join (select NAME_ as orgName,id_ as org_id from uc_org where IS_DELE_='0' and ORG_TYPE_!='1') org on org.org_id=orgUser.ORG_ID_
		where orgUser.ORG_ID_ in
		<foreach collection="orgList" item="id" open="(" separator="," close=")">
			#{id}
		</foreach>
GROUP BY log.ACCOUNT_ ORDER BY LOGIN_SUM_ desc
limit 10
	</select>

	<delete id="removePhysical" >
		DELETE FROM uc_login_log WHERE IS_DELE_='1'
	</delete>
</mapper>