package com.yeshi.fanli.service.impl.user.invite;
|
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Service;
|
|
import com.yeshi.fanli.dao.user.invite.TeamDailyRecordDao;
|
import com.yeshi.fanli.entity.bus.user.ThreeSale;
|
import com.yeshi.fanli.entity.bus.user.vip.TeamDailyRecord;
|
import com.yeshi.fanli.exception.user.TeamDailyRecordException;
|
import com.yeshi.fanli.log.LogHelper;
|
import com.yeshi.fanli.service.inter.user.invite.TeamDailyRecordService;
|
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
|
import com.yeshi.fanli.util.StringUtil;
|
import com.yeshi.fanli.util.TimeUtil;
|
import com.yeshi.fanli.util.annotation.RequestSerializableByKeyService;
|
|
@Service
|
public class TeamDailyRecordServiceImpl implements TeamDailyRecordService {
|
|
@Resource
|
private TeamDailyRecordDao teamDailyRecordDao;
|
|
@Resource
|
private ThreeSaleSerivce threeSaleSerivce;
|
|
|
@Override
|
public void save(TeamDailyRecord record) throws TeamDailyRecordException {
|
if (record == null || record.getCountDay() == null || record.getUid() == null) {
|
throw new TeamDailyRecordException(1, "数据不完整");
|
}
|
|
// 创建id
|
String gernalTime = TimeUtil.getGernalTime(record.getCountDay().getTime());
|
String id = StringUtil.Md5(record.getUid() + "#" + gernalTime);
|
|
// id
|
record.setId(id);
|
TeamDailyRecord teamDaily = teamDailyRecordDao.getById(id);
|
if (teamDaily != null) {
|
teamDailyRecordDao.updateSelective(record);
|
} else {
|
record.setCountDay(new Date(TimeUtil.convertDateToTemp(gernalTime)));
|
SimpleDateFormat formatMonth = new SimpleDateFormat("yyyy-MM");
|
record.setYearMonth(formatMonth.format(record.getCountDay()));
|
teamDailyRecordDao.save(record);
|
}
|
}
|
|
|
@Override
|
@RequestSerializableByKeyService(key = "#uid")
|
public void addDailyRecord(Long uid) {
|
// 重新统计队员等级数量
|
recountRecord(uid);
|
|
// 统计上级队员数量
|
ThreeSale threeSale = threeSaleSerivce.getByWorkerId(uid);
|
if (threeSale != null) {
|
recountRecord(threeSale.getBoss().getId());
|
}
|
}
|
|
private void recountRecord(Long uid) {
|
try {
|
// 直接粉丝
|
int firstCount = (int) threeSaleSerivce.countFirstTeamByDate(uid, 1);
|
// 间接粉丝
|
int secondCount = (int) threeSaleSerivce.countSecondTeamByDate(uid, 1);
|
|
int secondBeyond = 0;
|
|
|
} catch (Exception e) {
|
e.getSuppressed();
|
LogHelper.errorDetailInfo(e);
|
}
|
}
|
|
@Override
|
public List<TeamDailyRecord> getbyUid(Long uid) {
|
return teamDailyRecordDao.getbyUid(uid);
|
}
|
|
@Override
|
public List<TeamDailyRecord> getbyUid(Long uid, Date minTime) {
|
return teamDailyRecordDao.getbyUid(uid, minTime);
|
}
|
|
}
|