package com.yeshi.fanli.service.impl.user.vip;
|
|
import java.util.Date;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Service;
|
|
import com.yeshi.fanli.dao.user.vip.TeamLevelDailyRecordDao;
|
import com.yeshi.fanli.entity.bus.user.ThreeSale;
|
import com.yeshi.fanli.entity.bus.user.vip.TeamLevelDailyRecord;
|
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
|
import com.yeshi.fanli.entity.bus.user.vip.UserVIPPreInfo;
|
import com.yeshi.fanli.log.LogHelper;
|
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
|
import com.yeshi.fanli.service.inter.user.vip.TeamLevelDailyRecordService;
|
import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService;
|
import com.yeshi.fanli.service.manger.user.UserLevelManager;
|
import com.yeshi.fanli.util.StringUtil;
|
import com.yeshi.fanli.util.TimeUtil;
|
|
@Service
|
public class TeamLevelDailyRecordServiceImpl implements TeamLevelDailyRecordService {
|
|
@Resource
|
private TeamLevelDailyRecordDao teamLevelDailyRecordDao;
|
|
@Resource
|
private ThreeSaleSerivce threeSaleSerivce;
|
|
@Resource
|
private UserLevelManager userLevelManager;
|
|
@Resource
|
private UserVIPPreInfoService userVIPPreInfoService;
|
|
@Override
|
public List<TeamLevelDailyRecord> getbyUidAndType(Long uid, UserLevelEnum level, Date minTime) {
|
return teamLevelDailyRecordDao.getbyUidAndType(uid, level, minTime);
|
}
|
|
@Override
|
public void addStatisticByUid(Long uid) {
|
// 重新统计队员等级数量
|
initData(uid);
|
|
// 统计上级队员数量
|
ThreeSale threeSale = threeSaleSerivce.getByWorkerId(uid);
|
if (threeSale != null) {
|
initData(threeSale.getBoss().getId());
|
}
|
}
|
|
private void initData(Long uid) {
|
int pageSize = 1000;
|
Date date = new Date();
|
String countDay = TimeUtil.getGernalTime(java.lang.System.currentTimeMillis());
|
|
// 直接粉丝统计
|
int daRenFirstCount = 0;
|
int highFirstCount = 0;
|
int superFirstCount = 0;
|
int tearcherFirstCount = 0;
|
for (int i = 0; i < 100; i++) {
|
List<ThreeSale> list = threeSaleSerivce.listFirstTeam(i * pageSize, pageSize, uid);
|
if (list == null || list.size() == 0) {
|
break;
|
}
|
|
for (ThreeSale ts : list) {
|
Long succeedTime = ts.getSucceedTime();
|
if (succeedTime == null) {
|
succeedTime = ts.getCreateTime();
|
}
|
|
// 当日生产邀请关系
|
if (countDay.equals(TimeUtil.getGernalTime(succeedTime))) {
|
daRenFirstCount++;
|
continue;
|
}
|
|
|
UserVIPPreInfo info = userVIPPreInfoService.getProcessInfo(uid, date);
|
// 是否当日升级
|
if (info != null && countDay.equals(TimeUtil.getGernalTime(info.getCreateTime().getTime())) ) {
|
for (UserLevelEnum level : UserLevelEnum.values()) {
|
if (level.getLevel() == info.getProcess()) {
|
if (level == UserLevelEnum.highVIP) {
|
highFirstCount++;
|
} else if (level == UserLevelEnum.superVIP) {
|
superFirstCount++;
|
} else if (level == UserLevelEnum.tearcher) {
|
tearcherFirstCount++;
|
}
|
break;
|
}
|
}
|
}
|
}
|
}
|
|
// 间接粉丝
|
int daRenSecondCount = 0;
|
int highSecondCount = 0;
|
int superSecondCount = 0;
|
int tearcherSecondCount = 0;
|
for (int i = 0; i < 100; i++) {
|
List<ThreeSale> list = threeSaleSerivce.listSecondTeam(i * pageSize, pageSize, uid);
|
if (list == null || list.size() == 0) {
|
break;
|
}
|
|
for (ThreeSale ts : list) {
|
Long succeedTime = ts.getSucceedTime();
|
if (succeedTime == null) {
|
succeedTime = ts.getCreateTime();
|
}
|
|
// 当日生产邀请关系
|
if (countDay.equals(TimeUtil.getGernalTime(succeedTime))) {
|
daRenFirstCount++;
|
continue;
|
}
|
|
UserVIPPreInfo info = userVIPPreInfoService.getProcessInfo(uid, date);
|
// 是否当日升级
|
if (info != null && countDay.equals(TimeUtil.getGernalTime(info.getCreateTime().getTime())) ) {
|
for (UserLevelEnum level : UserLevelEnum.values()) {
|
if (level.getLevel() == info.getProcess()) {
|
if (level == UserLevelEnum.highVIP) {
|
highSecondCount++;
|
} else if (level == UserLevelEnum.superVIP) {
|
superSecondCount++;
|
} else if (level == UserLevelEnum.tearcher) {
|
tearcherSecondCount++;
|
}
|
break;
|
}
|
}
|
}
|
}
|
}
|
|
save(uid, UserLevelEnum.daRen, daRenFirstCount, daRenSecondCount);
|
save(uid, UserLevelEnum.highVIP, highFirstCount, highSecondCount);
|
save(uid, UserLevelEnum.superVIP, superFirstCount, superSecondCount);
|
save(uid, UserLevelEnum.tearcher, tearcherFirstCount, tearcherSecondCount);
|
}
|
|
|
private void save(Long uid, UserLevelEnum level, int firstCount, int secondCount) {
|
try {
|
int secondBeyond = 0;
|
// 每天只记录一次统计
|
String time = TimeUtil.getGernalTime(java.lang.System.currentTimeMillis());
|
String id = StringUtil.Md5(uid + level.name() + time);
|
TeamLevelDailyRecord record = teamLevelDailyRecordDao.getById(id);
|
if (record == null) {
|
record = new TeamLevelDailyRecord();
|
} else if (record.getSecondCount() != null) {
|
secondBeyond = record.getSecondCount();
|
}
|
|
record.setId(id);
|
record.setUid(uid);
|
record.setLevel(level);
|
record.setFirstCount(firstCount);
|
record.setSecondCount(secondCount);
|
record.setStatisticDay(TimeUtil.parse(time));
|
record.setUpdateTime(new Date());
|
record.setSecondBeyond(secondBeyond);
|
teamLevelDailyRecordDao.save(record);
|
} catch (Exception e) {
|
e.getSuppressed();
|
LogHelper.errorDetailInfo(e);
|
}
|
}
|
|
}
|