登录记录-增加ipRegion

This commit is contained in:
khalil
2024-07-02 15:02:08 +08:00
parent 496f33450b
commit f4cdf8f17c
13 changed files with 61 additions and 2279 deletions

View File

@@ -3,10 +3,11 @@ package com.accompany.admin.service;
import com.accompany.admin.service.base.BaseService; import com.accompany.admin.service.base.BaseService;
import com.accompany.common.utils.StringUtils; import com.accompany.common.utils.StringUtils;
import com.accompany.core.model.AccountLoginRecord; import com.accompany.core.model.AccountLoginRecord;
import com.accompany.core.model.AccountLoginRecordExample;
import com.accompany.core.model.Users; import com.accompany.core.model.Users;
import com.accompany.core.mybatismapper.AccountLoginRecordMapper; import com.accompany.core.mybatismapper.AccountLoginRecordMapper;
import com.accompany.core.service.user.UsersBaseService; import com.accompany.core.service.user.UsersBaseService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -29,27 +30,22 @@ public class AccountLoginRecordService extends BaseService {
public PageInfo<AccountLoginRecord> getAccountLoginRecordList(Integer pageSize, Integer pageNum, public PageInfo<AccountLoginRecord> getAccountLoginRecordList(Integer pageSize, Integer pageNum,
Long erbanNo, String phone, Long erbanNo, String phone,
Integer loginType, String deviceId) { Integer loginType, String deviceId) {
AccountLoginRecordExample accountLoginRecordExample = new AccountLoginRecordExample(); Long uid = null;
AccountLoginRecordExample.Criteria criteria = accountLoginRecordExample.createCriteria();
if (StringUtils.isNotBlank(deviceId)) {
criteria.andDeviceIdEqualTo(deviceId);
}
if (StringUtils.isNotBlank(phone)) {
criteria.andPhoneEqualTo(phone);
}
if (erbanNo != null) { if (erbanNo != null) {
Users u = usersBaseService.getUsersByErBanNo(erbanNo); Users u = usersBaseService.getUsersByErBanNo(erbanNo);
if (null == u){ if (null == u){
return new PageInfo<>(Collections.EMPTY_LIST); return new PageInfo<>(Collections.EMPTY_LIST);
} }
criteria.andUidEqualTo(u.getUid()); uid = u.getUid();
} }
if (loginType != null) { LambdaQueryWrapper<AccountLoginRecord> queryWrapper = Wrappers.<AccountLoginRecord>lambdaQuery()
criteria.andLoginTypeEqualTo(loginType.byteValue()); .eq(null != uid, AccountLoginRecord::getUid, uid)
} .eq(StringUtils.isNotBlank(deviceId), AccountLoginRecord::getDeviceId, deviceId)
accountLoginRecordExample.setOrderByClause("create_time desc"); .eq(StringUtils.isNotBlank(phone), AccountLoginRecord::getPhone, deviceId)
.eq(null != loginType, AccountLoginRecord::getLoginType, loginType)
.orderByDesc(AccountLoginRecord::getCreateTime);
PageHelper.startPage(pageNum, pageSize); PageHelper.startPage(pageNum, pageSize);
List<AccountLoginRecord> accountLoginRecord = accountLoginRecordMapper.selectByExample(accountLoginRecordExample); List<AccountLoginRecord> accountLoginRecord = accountLoginRecordMapper.selectList(queryWrapper);
return new PageInfo<>(accountLoginRecord); return new PageInfo<>(accountLoginRecord);
} }

View File

@@ -11,9 +11,10 @@ import com.accompany.common.result.BusiResult;
import com.accompany.common.status.BusiStatus; import com.accompany.common.status.BusiStatus;
import com.accompany.core.constant.BlockTypeEnum; import com.accompany.core.constant.BlockTypeEnum;
import com.accompany.core.model.AccountLoginRecord; import com.accompany.core.model.AccountLoginRecord;
import com.accompany.core.model.AccountLoginRecordExample;
import com.accompany.core.mybatismapper.AccountLoginRecordMapper; import com.accompany.core.mybatismapper.AccountLoginRecordMapper;
import com.accompany.core.util.StringUtils; import com.accompany.core.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
@@ -109,20 +110,18 @@ public class BlockAdminService extends BaseService {
} }
public List<AccountLoginRecord> searchUser(String phone, String deviceId, String ip) { public List<AccountLoginRecord> searchUser(String phone, String deviceId, String ip) {
AccountLoginRecordExample example = new AccountLoginRecordExample(); LambdaQueryWrapper<AccountLoginRecord> queryWrapper = Wrappers.<AccountLoginRecord>lambdaQuery();
AccountLoginRecordExample.Criteria criteria = example.createCriteria();
if (StringUtils.isNotBlank(phone)) { if (StringUtils.isNotBlank(phone)) {
criteria.andPhoneEqualTo(phone); queryWrapper.eq(AccountLoginRecord::getPhone, phone);
} }
if (StringUtils.isNotBlank(deviceId)) { if (StringUtils.isNotBlank(deviceId)) {
criteria.andDeviceIdEqualTo(deviceId); queryWrapper.eq(AccountLoginRecord::getDeviceId, deviceId);
} }
if (StringUtils.isNotBlank(ip)) { if (StringUtils.isNotBlank(ip)) {
criteria.andLoginIpEqualTo(ip); queryWrapper.eq(AccountLoginRecord::getLoginIp, ip);
} }
List<AccountLoginRecord> users = accountLoginRecordMapper.selectByExample(example); List<AccountLoginRecord> users = accountLoginRecordMapper.selectList(queryWrapper);
List<AccountLoginRecord> collect = users.stream().filter(distinctByKey((u) -> u.getErbanNo())).collect(Collectors.toList()); return users.stream().filter(distinctByKey((u) -> u.getErbanNo())).collect(Collectors.toList());
return collect;
} }
} }

View File

@@ -1,7 +1,10 @@
package com.accompany.core.model; package com.accompany.core.model;
import lombok.Data;
import java.util.Date; import java.util.Date;
@Data
public class AccountLoginRecord { public class AccountLoginRecord {
private Long recordId; private Long recordId;
@@ -15,11 +18,7 @@ public class AccountLoginRecord {
private String loginIp; private String loginIp;
private String loginPort; private String loginIpRegion;
private String weixinOpenid;
private String qqOpenid;
private String appleUid; private String appleUid;
@@ -43,163 +42,4 @@ public class AccountLoginRecord {
private Date createTime; private Date createTime;
public Long getRecordId() {
return recordId;
}
public void setRecordId(Long recordId) {
this.recordId = recordId;
}
public Long getUid() {
return uid;
}
public void setUid(Long uid) {
this.uid = uid;
}
public Long getErbanNo() {
return erbanNo;
}
public void setErbanNo(Long erbanNo) {
this.erbanNo = erbanNo;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone == null ? null : phone.trim();
}
public Byte getLoginType() {
return loginType;
}
public void setLoginType(Byte loginType) {
this.loginType = loginType;
}
public String getLoginIp() {
return loginIp;
}
public void setLoginIp(String loginIp) {
this.loginIp = loginIp == null ? null : loginIp.trim();
}
public String getLoginPort() {
return loginPort;
}
public void setLoginPort(String loginPort) {
this.loginPort = loginPort == null ? null : loginPort.trim();
}
public String getWeixinOpenid() {
return weixinOpenid;
}
public void setWeixinOpenid(String weixinOpenid) {
this.weixinOpenid = weixinOpenid == null ? null : weixinOpenid.trim();
}
public String getQqOpenid() {
return qqOpenid;
}
public void setQqOpenid(String qqOpenid) {
this.qqOpenid = qqOpenid == null ? null : qqOpenid.trim();
}
public String getAppleUid() {
return appleUid;
}
public void setAppleUid(String appleUid) {
this.appleUid = appleUid == null ? null : appleUid.trim();
}
public String getOs() {
return os;
}
public void setOs(String os) {
this.os = os == null ? null : os.trim();
}
public String getOsversion() {
return osversion;
}
public void setOsversion(String osversion) {
this.osversion = osversion == null ? null : osversion.trim();
}
public String getApp() {
return app;
}
public void setApp(String app) {
this.app = app == null ? null : app.trim();
}
public String getImei() {
return imei;
}
public void setImei(String imei) {
this.imei = imei == null ? null : imei.trim();
}
public String getIspType() {
return ispType;
}
public void setIspType(String ispType) {
this.ispType = ispType == null ? null : ispType.trim();
}
public String getNetType() {
return netType;
}
public void setNetType(String netType) {
this.netType = netType == null ? null : netType.trim();
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model == null ? null : model.trim();
}
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId == null ? null : deviceId.trim();
}
public String getAppVersion() {
return appVersion;
}
public void setAppVersion(String appVersion) {
this.appVersion = appVersion == null ? null : appVersion.trim();
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
} }

View File

@@ -1,33 +1,12 @@
package com.accompany.core.mybatismapper; package com.accompany.core.mybatismapper;
import com.accompany.core.model.AccountLoginRecord; import com.accompany.core.model.AccountLoginRecord;
import com.accompany.core.model.AccountLoginRecordExample; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
public interface AccountLoginRecordMapper { public interface AccountLoginRecordMapper extends BaseMapper<AccountLoginRecord> {
int countByExample(AccountLoginRecordExample example);
int deleteByExample(AccountLoginRecordExample example);
int deleteByPrimaryKey(Long recordId);
int insert(AccountLoginRecord record);
int insertSelective(AccountLoginRecord record);
List<AccountLoginRecord> selectByExample(AccountLoginRecordExample example);
AccountLoginRecord selectByPrimaryKey(Long recordId);
int updateByExampleSelective(@Param("record") AccountLoginRecord record, @Param("example") AccountLoginRecordExample example);
int updateByExample(@Param("record") AccountLoginRecord record, @Param("example") AccountLoginRecordExample example);
int updateByPrimaryKeySelective(AccountLoginRecord record);
int updateByPrimaryKey(AccountLoginRecord record);
String getLastDeviceId(Long uid); String getLastDeviceId(Long uid);

View File

@@ -8,14 +8,10 @@ import java.util.List;
public interface AccountLoginRecordMapperExpand { public interface AccountLoginRecordMapperExpand {
Long countLoginDay(@Param("uid") Long uid, @Param("startDay") Date startDay, @Param("endDay") Date endDay);
List<Long> getRecentLoginUids(@Param("startDay") Date startDay, @Param("partitionId") Integer partitionId); List<Long> getRecentLoginUids(@Param("startDay") Date startDay, @Param("partitionId") Integer partitionId);
List<String> listUserLoginDevice(Long uid); List<String> listUserLoginDevice(Long uid);
Integer countLoginRecord(@Param("uid") Long uid);
List<Long> getUidByRecent60Day(@Param("channel") String channel, @Param("ignoreVersion") String ignoreVersion, @Param("ignoreChannel") String ignoreChannel, @Param("partitionId") Integer partitionId, @Param("index") Integer index, @Param("offset") Integer offset); List<Long> getUidByRecent60Day(@Param("channel") String channel, @Param("ignoreVersion") String ignoreVersion, @Param("ignoreChannel") String ignoreChannel, @Param("partitionId") Integer partitionId, @Param("index") Integer index, @Param("offset") Integer offset);
/** /**

View File

@@ -2,8 +2,9 @@ package com.accompany.core.service.account;
import com.accompany.common.utils.DateTimeUtil; import com.accompany.common.utils.DateTimeUtil;
import com.accompany.core.model.AccountLoginRecord; import com.accompany.core.model.AccountLoginRecord;
import com.accompany.core.model.AccountLoginRecordExample;
import com.accompany.core.mybatismapper.AccountLoginRecordMapper; import com.accompany.core.mybatismapper.AccountLoginRecordMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -34,9 +35,9 @@ public class LoginRecordService {
} }
public int countLoginRecordBetweenQueryTime(Long uid, Date startTime, Date endTime) { public int countLoginRecordBetweenQueryTime(Long uid, Date startTime, Date endTime) {
AccountLoginRecordExample example = new AccountLoginRecordExample(); LambdaQueryWrapper<AccountLoginRecord> wrapper = Wrappers.<AccountLoginRecord>lambdaQuery()
example.createCriteria().andUidEqualTo(uid) .eq(AccountLoginRecord::getUid, uid)
.andCreateTimeBetween(startTime, endTime); .between(AccountLoginRecord::getCreateTime, startTime, endTime);
return accountLoginRecordMapper.countByExample(example); return accountLoginRecordMapper.selectCount(wrapper);
} }
} }

View File

@@ -1,455 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?> <?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" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.accompany.core.mybatismapper.AccountLoginRecordMapper" > <mapper namespace="com.accompany.core.mybatismapper.AccountLoginRecordMapper" >
<resultMap id="BaseResultMap" type="com.accompany.core.model.AccountLoginRecord" >
<id column="record_id" property="recordId" jdbcType="BIGINT" />
<result column="uid" property="uid" jdbcType="BIGINT" />
<result column="erban_no" property="erbanNo" jdbcType="BIGINT" />
<result column="phone" property="phone" jdbcType="VARCHAR" />
<result column="login_type" property="loginType" jdbcType="TINYINT" />
<result column="login_ip" property="loginIp" jdbcType="VARCHAR" />
<result column="login_port" property="loginPort" jdbcType="VARCHAR" />
<result column="weixin_openid" property="weixinOpenid" jdbcType="VARCHAR" />
<result column="qq_openid" property="qqOpenid" jdbcType="VARCHAR" />
<result column="apple_uid" property="appleUid" jdbcType="VARCHAR" />
<result column="os" property="os" jdbcType="VARCHAR" />
<result column="osVersion" property="osversion" jdbcType="VARCHAR" />
<result column="app" property="app" jdbcType="VARCHAR" />
<result column="imei" property="imei" jdbcType="VARCHAR" />
<result column="isp_type" property="ispType" jdbcType="VARCHAR" />
<result column="net_type" property="netType" jdbcType="VARCHAR" />
<result column="model" property="model" jdbcType="VARCHAR" />
<result column="device_id" property="deviceId" jdbcType="VARCHAR" />
<result column="app_version" property="appVersion" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Example_Where_Clause" >
<where >
<foreach collection="oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause" >
<where >
<foreach collection="example.oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List" >
record_id, `uid`, erban_no, phone, login_type, login_ip, login_port, weixin_openid,
qq_openid, apple_uid, os, osVersion, app, imei, isp_type, net_type, model, device_id,
app_version, create_time
</sql>
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.accompany.core.model.AccountLoginRecordExample" >
select
<if test="distinct" >
distinct
</if>
'true' as QUERYID,
<include refid="Base_Column_List" />
from account_login_record
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
from account_login_record
where record_id = #{recordId,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from account_login_record
where record_id = #{recordId,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="com.accompany.core.model.AccountLoginRecordExample" >
delete from account_login_record
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.accompany.core.model.AccountLoginRecord" useGeneratedKeys="true" keyProperty="recordId" keyColumn="record_id" >
insert into account_login_record (`uid`, erban_no, phone,
login_type, login_ip, login_port,
weixin_openid, qq_openid, apple_uid,
os, osVersion, app,
imei, isp_type, net_type,
model, device_id, app_version,
create_time)
values (#{uid,jdbcType=BIGINT}, #{erbanNo,jdbcType=BIGINT}, #{phone,jdbcType=VARCHAR},
#{loginType,jdbcType=TINYINT}, #{loginIp,jdbcType=VARCHAR}, #{loginPort,jdbcType=VARCHAR},
#{weixinOpenid,jdbcType=VARCHAR}, #{qqOpenid,jdbcType=VARCHAR}, #{appleUid,jdbcType=VARCHAR},
#{os,jdbcType=VARCHAR}, #{osversion,jdbcType=VARCHAR}, #{app,jdbcType=VARCHAR},
#{imei,jdbcType=VARCHAR}, #{ispType,jdbcType=VARCHAR}, #{netType,jdbcType=VARCHAR},
#{model,jdbcType=VARCHAR}, #{deviceId,jdbcType=VARCHAR}, #{appVersion,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.accompany.core.model.AccountLoginRecord" useGeneratedKeys="true" keyProperty="recordId" keyColumn="record_id" >
insert into account_login_record
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="uid != null" >
`uid`,
</if>
<if test="erbanNo != null" >
erban_no,
</if>
<if test="phone != null" >
phone,
</if>
<if test="loginType != null" >
login_type,
</if>
<if test="loginIp != null" >
login_ip,
</if>
<if test="loginPort != null" >
login_port,
</if>
<if test="weixinOpenid != null" >
weixin_openid,
</if>
<if test="qqOpenid != null" >
qq_openid,
</if>
<if test="appleUid != null" >
apple_uid,
</if>
<if test="os != null" >
os,
</if>
<if test="osversion != null" >
osVersion,
</if>
<if test="app != null" >
app,
</if>
<if test="imei != null" >
imei,
</if>
<if test="ispType != null" >
isp_type,
</if>
<if test="netType != null" >
net_type,
</if>
<if test="model != null" >
model,
</if>
<if test="deviceId != null" >
device_id,
</if>
<if test="appVersion != null" >
app_version,
</if>
<if test="createTime != null" >
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="uid != null" >
#{uid,jdbcType=BIGINT},
</if>
<if test="erbanNo != null" >
#{erbanNo,jdbcType=BIGINT},
</if>
<if test="phone != null" >
#{phone,jdbcType=VARCHAR},
</if>
<if test="loginType != null" >
#{loginType,jdbcType=TINYINT},
</if>
<if test="loginIp != null" >
#{loginIp,jdbcType=VARCHAR},
</if>
<if test="loginPort != null" >
#{loginPort,jdbcType=VARCHAR},
</if>
<if test="weixinOpenid != null" >
#{weixinOpenid,jdbcType=VARCHAR},
</if>
<if test="qqOpenid != null" >
#{qqOpenid,jdbcType=VARCHAR},
</if>
<if test="appleUid != null" >
#{appleUid,jdbcType=VARCHAR},
</if>
<if test="os != null" >
#{os,jdbcType=VARCHAR},
</if>
<if test="osversion != null" >
#{osversion,jdbcType=VARCHAR},
</if>
<if test="app != null" >
#{app,jdbcType=VARCHAR},
</if>
<if test="imei != null" >
#{imei,jdbcType=VARCHAR},
</if>
<if test="ispType != null" >
#{ispType,jdbcType=VARCHAR},
</if>
<if test="netType != null" >
#{netType,jdbcType=VARCHAR},
</if>
<if test="model != null" >
#{model,jdbcType=VARCHAR},
</if>
<if test="deviceId != null" >
#{deviceId,jdbcType=VARCHAR},
</if>
<if test="appVersion != null" >
#{appVersion,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.accompany.core.model.AccountLoginRecordExample" resultType="java.lang.Integer" >
select count(*) from account_login_record
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map" >
update account_login_record
<set >
<if test="record.recordId != null" >
record_id = #{record.recordId,jdbcType=BIGINT},
</if>
<if test="record.uid != null" >
`uid` = #{record.uid,jdbcType=BIGINT},
</if>
<if test="record.erbanNo != null" >
erban_no = #{record.erbanNo,jdbcType=BIGINT},
</if>
<if test="record.phone != null" >
phone = #{record.phone,jdbcType=VARCHAR},
</if>
<if test="record.loginType != null" >
login_type = #{record.loginType,jdbcType=TINYINT},
</if>
<if test="record.loginIp != null" >
login_ip = #{record.loginIp,jdbcType=VARCHAR},
</if>
<if test="record.loginPort != null" >
login_port = #{record.loginPort,jdbcType=VARCHAR},
</if>
<if test="record.weixinOpenid != null" >
weixin_openid = #{record.weixinOpenid,jdbcType=VARCHAR},
</if>
<if test="record.qqOpenid != null" >
qq_openid = #{record.qqOpenid,jdbcType=VARCHAR},
</if>
<if test="record.appleUid != null" >
apple_uid = #{record.appleUid,jdbcType=VARCHAR},
</if>
<if test="record.os != null" >
os = #{record.os,jdbcType=VARCHAR},
</if>
<if test="record.osversion != null" >
osVersion = #{record.osversion,jdbcType=VARCHAR},
</if>
<if test="record.app != null" >
app = #{record.app,jdbcType=VARCHAR},
</if>
<if test="record.imei != null" >
imei = #{record.imei,jdbcType=VARCHAR},
</if>
<if test="record.ispType != null" >
isp_type = #{record.ispType,jdbcType=VARCHAR},
</if>
<if test="record.netType != null" >
net_type = #{record.netType,jdbcType=VARCHAR},
</if>
<if test="record.model != null" >
model = #{record.model,jdbcType=VARCHAR},
</if>
<if test="record.deviceId != null" >
device_id = #{record.deviceId,jdbcType=VARCHAR},
</if>
<if test="record.appVersion != null" >
app_version = #{record.appVersion,jdbcType=VARCHAR},
</if>
<if test="record.createTime != null" >
create_time = #{record.createTime,jdbcType=TIMESTAMP},
</if>
</set>
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map" >
update account_login_record
set record_id = #{record.recordId,jdbcType=BIGINT},
`uid` = #{record.uid,jdbcType=BIGINT},
erban_no = #{record.erbanNo,jdbcType=BIGINT},
phone = #{record.phone,jdbcType=VARCHAR},
login_type = #{record.loginType,jdbcType=TINYINT},
login_ip = #{record.loginIp,jdbcType=VARCHAR},
login_port = #{record.loginPort,jdbcType=VARCHAR},
weixin_openid = #{record.weixinOpenid,jdbcType=VARCHAR},
qq_openid = #{record.qqOpenid,jdbcType=VARCHAR},
apple_uid = #{record.appleUid,jdbcType=VARCHAR},
os = #{record.os,jdbcType=VARCHAR},
osVersion = #{record.osversion,jdbcType=VARCHAR},
app = #{record.app,jdbcType=VARCHAR},
imei = #{record.imei,jdbcType=VARCHAR},
isp_type = #{record.ispType,jdbcType=VARCHAR},
net_type = #{record.netType,jdbcType=VARCHAR},
model = #{record.model,jdbcType=VARCHAR},
device_id = #{record.deviceId,jdbcType=VARCHAR},
app_version = #{record.appVersion,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=TIMESTAMP}
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.accompany.core.model.AccountLoginRecord" >
update account_login_record
<set >
<if test="uid != null" >
`uid` = #{uid,jdbcType=BIGINT},
</if>
<if test="erbanNo != null" >
erban_no = #{erbanNo,jdbcType=BIGINT},
</if>
<if test="phone != null" >
phone = #{phone,jdbcType=VARCHAR},
</if>
<if test="loginType != null" >
login_type = #{loginType,jdbcType=TINYINT},
</if>
<if test="loginIp != null" >
login_ip = #{loginIp,jdbcType=VARCHAR},
</if>
<if test="loginPort != null" >
login_port = #{loginPort,jdbcType=VARCHAR},
</if>
<if test="weixinOpenid != null" >
weixin_openid = #{weixinOpenid,jdbcType=VARCHAR},
</if>
<if test="qqOpenid != null" >
qq_openid = #{qqOpenid,jdbcType=VARCHAR},
</if>
<if test="appleUid != null" >
apple_uid = #{appleUid,jdbcType=VARCHAR},
</if>
<if test="os != null" >
os = #{os,jdbcType=VARCHAR},
</if>
<if test="osversion != null" >
osVersion = #{osversion,jdbcType=VARCHAR},
</if>
<if test="app != null" >
app = #{app,jdbcType=VARCHAR},
</if>
<if test="imei != null" >
imei = #{imei,jdbcType=VARCHAR},
</if>
<if test="ispType != null" >
isp_type = #{ispType,jdbcType=VARCHAR},
</if>
<if test="netType != null" >
net_type = #{netType,jdbcType=VARCHAR},
</if>
<if test="model != null" >
model = #{model,jdbcType=VARCHAR},
</if>
<if test="deviceId != null" >
device_id = #{deviceId,jdbcType=VARCHAR},
</if>
<if test="appVersion != null" >
app_version = #{appVersion,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
</set>
where record_id = #{recordId,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.accompany.core.model.AccountLoginRecord" >
update account_login_record
set `uid` = #{uid,jdbcType=BIGINT},
erban_no = #{erbanNo,jdbcType=BIGINT},
phone = #{phone,jdbcType=VARCHAR},
login_type = #{loginType,jdbcType=TINYINT},
login_ip = #{loginIp,jdbcType=VARCHAR},
login_port = #{loginPort,jdbcType=VARCHAR},
weixin_openid = #{weixinOpenid,jdbcType=VARCHAR},
qq_openid = #{qqOpenid,jdbcType=VARCHAR},
apple_uid = #{appleUid,jdbcType=VARCHAR},
os = #{os,jdbcType=VARCHAR},
osVersion = #{osversion,jdbcType=VARCHAR},
app = #{app,jdbcType=VARCHAR},
imei = #{imei,jdbcType=VARCHAR},
isp_type = #{ispType,jdbcType=VARCHAR},
net_type = #{netType,jdbcType=VARCHAR},
model = #{model,jdbcType=VARCHAR},
device_id = #{deviceId,jdbcType=VARCHAR},
app_version = #{appVersion,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP}
where record_id = #{recordId,jdbcType=BIGINT}
</update>
<select id="getLastDeviceId" parameterType="java.lang.Long" resultType="java.lang.String"> <select id="getLastDeviceId" parameterType="java.lang.Long" resultType="java.lang.String">
select device_id from account_login_record where uid = #{uid} and device_id is not null order by create_time desc limit 0,1; select device_id from account_login_record where uid = #{uid} and device_id is not null order by create_time desc limit 0,1;
</select> </select>
<select id="getLatestLoginRecordFromDB" resultMap="BaseResultMap"> <select id="getLatestLoginRecordFromDB" resultType="com.accompany.core.model.AccountLoginRecord">
SELECT * from account_login_record where uid = #{uid} ORDER BY create_time DESC limit 1; SELECT * from account_login_record where uid = #{uid} ORDER BY create_time DESC limit 1;
</select> </select>
<select id="getLastLoginIpByUids" resultMap="BaseResultMap"> <select id="getLastLoginIpByUids" resultType="com.accompany.core.model.AccountLoginRecord">
select alr.uid, login_ip from account_login_record alr select alr.uid, login_ip from account_login_record alr
inner join (select `uid`, max(create_time) create_time inner join (select `uid`, max(create_time) create_time
from account_login_record alr from account_login_record alr

View File

@@ -1,12 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?> <?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" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.accompany.core.mybatismapper.AccountLoginRecordMapperExpand"> <mapper namespace="com.accompany.core.mybatismapper.AccountLoginRecordMapperExpand">
<select id="countLoginDay" resultType="java.lang.Long">
select COUNT(1) from (
select left(create_time, 10) as days from account_login_record
where uid=#{uid} and create_time BETWEEN #{startDay} AND #{endDay}
GROUP BY days) as a
</select>
<select id="getRecentLoginUids" resultType="java.lang.Long"> <select id="getRecentLoginUids" resultType="java.lang.Long">
SELECT DISTINCT(uid) FROM account_login_record as alr SELECT DISTINCT(uid) FROM account_login_record as alr
left join users as u on u.uid = alr.uid left join users as u on u.uid = alr.uid
@@ -16,9 +10,6 @@
<select id="listUserLoginDevice" resultType="java.lang.String"> <select id="listUserLoginDevice" resultType="java.lang.String">
select device_id from account_login_record where uid = #{uid} group by device_id; select device_id from account_login_record where uid = #{uid} group by device_id;
</select> </select>
<select id="countLoginRecord" resultType="java.lang.Integer" parameterType="java.lang.Long">
select count(1) from account_login_record where uid = #{uid};
</select>
<select id="getUidByRecent60Day" resultType="java.lang.Long"> <select id="getUidByRecent60Day" resultType="java.lang.Long">
select distinct alr.uid from account_login_record as alr select distinct alr.uid from account_login_record as alr
left join users as u on u.uid = alr.uid left join users as u on u.uid = alr.uid

View File

@@ -1,10 +1,11 @@
package com.accompany.business.service; package com.accompany.business.service;
import com.accompany.core.model.AccountLoginRecord; import com.accompany.core.model.AccountLoginRecord;
import com.accompany.core.model.AccountLoginRecordExample;
import com.accompany.core.mybatismapper.AccountLoginRecordMapper; import com.accompany.core.mybatismapper.AccountLoginRecordMapper;
import com.accompany.core.mybatismapper.AccountLoginRecordMapperExpand; import com.accompany.core.mybatismapper.AccountLoginRecordMapperExpand;
import com.accompany.core.service.base.BaseService; import com.accompany.core.service.base.BaseService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -25,29 +26,23 @@ public class AccountLoginRecordService extends BaseService {
private AccountLoginRecordMapperExpand accountLoginRecordMapperExpand; private AccountLoginRecordMapperExpand accountLoginRecordMapperExpand;
public AccountLoginRecord getLastLoginRecord(Long uid) { public AccountLoginRecord getLastLoginRecord(Long uid) {
AccountLoginRecordExample example = new AccountLoginRecordExample(); LambdaQueryWrapper<AccountLoginRecord> queryWrapper = Wrappers.<AccountLoginRecord>lambdaQuery()
AccountLoginRecordExample.Criteria criteria = example.createCriteria(); .eq(AccountLoginRecord::getUid, uid)
criteria.andUidEqualTo(uid); .orderByDesc(AccountLoginRecord::getCreateTime)
example.setOrderByClause(" create_time desc limit 1 "); .last("limit 1");
List<AccountLoginRecord> list = accountLoginRecordMapper.selectByExample(example); List<AccountLoginRecord> list = accountLoginRecordMapper.selectList(queryWrapper);
return (null == list || list.isEmpty()) ? null : list.get(0); return (null == list || list.isEmpty()) ? null : list.get(0);
} }
public AccountLoginRecord getLastLoginRecordByDevice(String deviceId) { public AccountLoginRecord getLastLoginRecordByDevice(String deviceId) {
AccountLoginRecordExample example = new AccountLoginRecordExample(); LambdaQueryWrapper<AccountLoginRecord> queryWrapper = Wrappers.<AccountLoginRecord>lambdaQuery()
AccountLoginRecordExample.Criteria criteria = example.createCriteria(); .eq(AccountLoginRecord::getDeviceId, deviceId)
criteria.andDeviceIdEqualTo(deviceId); .orderByDesc(AccountLoginRecord::getCreateTime)
example.setOrderByClause(" create_time desc limit 1 "); .last("limit 1");
List<AccountLoginRecord> list = accountLoginRecordMapper.selectByExample(example); List<AccountLoginRecord> list = accountLoginRecordMapper.selectList(queryWrapper);
return (null == list || list.isEmpty()) ? null : list.get(0); return (null == list || list.isEmpty()) ? null : list.get(0);
} }
public Long countLoginDay(Long uid, Date startDay, Date endDay) {
Long count = accountLoginRecordMapperExpand.countLoginDay(uid, startDay, endDay);
return Optional.ofNullable(count).orElse(0L);
}
/** /**
* 获取最近时间登陆的用户id * 获取最近时间登陆的用户id
*/ */
@@ -59,7 +54,4 @@ public class AccountLoginRecordService extends BaseService {
return accountLoginRecordMapperExpand.listUserLoginDevice(uid); return accountLoginRecordMapperExpand.listUserLoginDevice(uid);
} }
public Integer countLoginRecord(Long uid){
return accountLoginRecordMapperExpand.countLoginRecord(uid);
}
} }

View File

@@ -1,8 +1,9 @@
package com.accompany.business.service.user; package com.accompany.business.service.user;
import com.accompany.core.model.AccountLoginRecord; import com.accompany.core.model.AccountLoginRecord;
import com.accompany.core.model.AccountLoginRecordExample;
import com.accompany.core.mybatismapper.AccountLoginRecordMapper; import com.accompany.core.mybatismapper.AccountLoginRecordMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.NonNull; import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -21,19 +22,20 @@ public class UserLoginService {
private AccountLoginRecordMapper accountLoginRecordMapper; private AccountLoginRecordMapper accountLoginRecordMapper;
public AccountLoginRecord getDeviceFirstLoginRecord(String deviceId) { public AccountLoginRecord getDeviceFirstLoginRecord(String deviceId) {
AccountLoginRecordExample example = new AccountLoginRecordExample(); LambdaQueryWrapper<AccountLoginRecord> queryWrapper = Wrappers.<AccountLoginRecord>lambdaQuery()
example.createCriteria().andDeviceIdEqualTo(deviceId); .eq(AccountLoginRecord::getDeviceId, deviceId)
example.setOrderByClause(" create_time asc"); .orderByAsc(AccountLoginRecord::getCreateTime)
example.setLimit(1); .last("limit 1");
List<AccountLoginRecord> records = this.accountLoginRecordMapper.selectByExample(example); List<AccountLoginRecord> records = accountLoginRecordMapper.selectList(queryWrapper);
return records == null || records.isEmpty() ? null : records.get(0); return records == null || records.isEmpty() ? null : records.get(0);
} }
public AccountLoginRecord getDeviceFirstLoginRecordV2(@NonNull Long uid, @NonNull String deviceId) { public AccountLoginRecord getDeviceFirstLoginRecordV2(@NonNull Long uid, @NonNull String deviceId) {
AccountLoginRecordExample example = new AccountLoginRecordExample(); LambdaQueryWrapper<AccountLoginRecord> queryWrapper = Wrappers.<AccountLoginRecord>lambdaQuery()
example.createCriteria().andDeviceIdEqualTo(deviceId).andUidNotEqualTo(uid); .eq(AccountLoginRecord::getDeviceId, deviceId)
example.setLimit(1); .ne(AccountLoginRecord::getUid, uid)
List<AccountLoginRecord> records = this.accountLoginRecordMapper.selectByExample(example); .last("limit 1");
List<AccountLoginRecord> records = this.accountLoginRecordMapper.selectList(queryWrapper);
return records == null || records.isEmpty() ? null : records.get(0); return records == null || records.isEmpty() ? null : records.get(0);
} }
} }

View File

@@ -157,8 +157,6 @@ public class UsersService extends BaseService {
private AccountBlockService accountBlockService; private AccountBlockService accountBlockService;
@Autowired @Autowired
private UserCancelRecordService userCancelRecordService; private UserCancelRecordService userCancelRecordService;
@Autowired
private AliyunSmsService aliyunSmsService;
@Lazy @Lazy
@Autowired @Autowired
private UserPurseService userPurseService; private UserPurseService userPurseService;

View File

@@ -16,6 +16,7 @@ import com.accompany.core.service.account.AccountService;
import com.accompany.core.service.account.LoginRecordService; import com.accompany.core.service.account.LoginRecordService;
import com.accompany.core.service.account.UserAppService; import com.accompany.core.service.account.UserAppService;
import com.accompany.core.service.common.JedisService; import com.accompany.core.service.common.JedisService;
import com.accompany.core.service.region.RegionService;
import com.accompany.core.service.user.PhoneBlackService; import com.accompany.core.service.user.PhoneBlackService;
import com.accompany.core.service.user.UsersBaseService; import com.accompany.core.service.user.UsersBaseService;
import com.accompany.oauth2.constant.LoginTypeEnum; import com.accompany.oauth2.constant.LoginTypeEnum;
@@ -66,6 +67,8 @@ public class MyUserDetailsServiceImpl implements MyUserDetailsService {
private SysConfService sysConfService; private SysConfService sysConfService;
@Autowired @Autowired
private PhoneBlackService phoneBlackService; private PhoneBlackService phoneBlackService;
@Autowired
private RegionService regionService;
/** /**
* 不允许登录的用户账号类型 * 不允许登录的用户账号类型
@@ -183,6 +186,7 @@ public class MyUserDetailsServiceImpl implements MyUserDetailsService {
public AccountLoginRecord buildAccountLoginRecord(String ipAddress, Account account, byte loginType, DeviceInfo deviceInfo, String openId) { public AccountLoginRecord buildAccountLoginRecord(String ipAddress, Account account, byte loginType, DeviceInfo deviceInfo, String openId) {
AccountLoginRecord accountLoginRecord = new AccountLoginRecord(); AccountLoginRecord accountLoginRecord = new AccountLoginRecord();
accountLoginRecord.setLoginIp(ipAddress); accountLoginRecord.setLoginIp(ipAddress);
accountLoginRecord.setLoginIpRegion(regionService.getRegion(ipAddress));
accountLoginRecord.setUid(account.getUid()); accountLoginRecord.setUid(account.getUid());
accountLoginRecord.setErbanNo(account.getErbanNo()); accountLoginRecord.setErbanNo(account.getErbanNo());
accountLoginRecord.setLoginType(loginType); accountLoginRecord.setLoginType(loginType);
@@ -196,12 +200,6 @@ public class MyUserDetailsServiceImpl implements MyUserDetailsService {
accountLoginRecord.setOsversion(deviceInfo.getOsVersion()); accountLoginRecord.setOsversion(deviceInfo.getOsVersion());
accountLoginRecord.setCreateTime(new Date()); accountLoginRecord.setCreateTime(new Date());
if (loginType == LoginTypeEnum.WECHAT.getValue()) {
accountLoginRecord.setWeixinOpenid(openId);
}
if (loginType == LoginTypeEnum.QQ.getValue()) {
accountLoginRecord.setQqOpenid(openId);
}
if (loginType == LoginTypeEnum.APPLE.getValue()) { if (loginType == LoginTypeEnum.APPLE.getValue()) {
accountLoginRecord.setAppleUid(openId); accountLoginRecord.setAppleUid(openId);
} }