package com.yeshi.fanli.service.impl.user;
|
|
import java.util.Date;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Service;
|
|
import com.yeshi.fanli.dao.mybatis.user.UserActiveLogMapper;
|
import com.yeshi.fanli.entity.bus.user.UserActiveLog;
|
import com.yeshi.fanli.service.inter.user.UserActiveLogService;
|
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
|
@Service
|
public class UserActiveLogServiceImpl implements UserActiveLogService {
|
|
@Resource
|
private UserActiveLogMapper userActiveLogMapper;
|
|
@Resource
|
private UserInfoExtraService userInfoExtraService;
|
|
@Override
|
public void addUserActiveLog(UserActiveLog userActiveLog) {
|
if (userActiveLog == null)
|
return;
|
if (userActiveLog.getUid() == null || userActiveLog.getUid() == 0)
|
return;
|
UserActiveLog latestLog = getUserLatestActiveInfo(userActiveLog.getUid());
|
// 间隔5分钟以上再记录
|
if (latestLog == null || System.currentTimeMillis() - latestLog.getCreateTime().getTime() > 1000 * 60 * 5L) {
|
userActiveLog.setCreateTime(new Date());
|
userActiveLog.setUpdateTime(new Date());
|
userActiveLogMapper.insertSelective(userActiveLog);
|
// 更新最新活跃时间
|
userInfoExtraService.updateActiveTime(userActiveLog.getUid() , new Date());
|
} else if (latestLog != null) {
|
// 如果设备 ,版本,渠道有变化则需要更改
|
String oldIdentify = latestLog.getDevice() + "#" + latestLog.getVersionCode() + "#"
|
+ latestLog.getChannel();
|
String newIdentify = userActiveLog.getDevice() + "#" + userActiveLog.getVersionCode() + "#"
|
+ userActiveLog.getChannel();
|
if (!oldIdentify.equalsIgnoreCase(newIdentify)) {// 设备信息变化要记录信息
|
userActiveLog.setCreateTime(new Date());
|
userActiveLog.setUpdateTime(new Date());
|
userActiveLogMapper.insertSelective(userActiveLog);
|
// 更新最新活跃时间
|
userInfoExtraService.updateActiveTime(userActiveLog.getUid() , new Date());
|
}
|
}
|
}
|
|
@Override
|
public UserActiveLog getUserLatestActiveInfo(Long uid) {
|
return userActiveLogMapper.selectLatestByUid(uid);
|
}
|
|
@Override
|
public UserActiveLog getFirstActiveInfo(Long uid) {
|
|
return userActiveLogMapper.selectFirstActiveInfo(uid);
|
}
|
|
}
|