admin
2020-05-12 2bb5bd3c989dcdb07779e3d870d567cd8a06ffa5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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);
    }
    
}