LivePoolServiceImpl.java
4.25 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package cn.fw.dalaran.service.data.impl;
import cn.fw.dalaran.dao.LivePoolDao;
import cn.fw.dalaran.domain.db.Account;
import cn.fw.dalaran.domain.db.ActivityTheme;
import cn.fw.dalaran.domain.db.LivePool;
import cn.fw.dalaran.domain.dto.PoolQueryDTO;
import cn.fw.dalaran.domain.vo.LivePoolVO;
import cn.fw.dalaran.service.data.AccountService;
import cn.fw.dalaran.service.data.ActivityThemeService;
import cn.fw.dalaran.service.data.LivePoolService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author kurisu
* @date 2021-11-17 14:54
* @description LivePoolService
*/
@Service
@RequiredArgsConstructor
@SuppressWarnings("Duplicates")
public class LivePoolServiceImpl extends ServiceImpl<LivePoolDao, LivePool> implements LivePoolService {
private final ActivityThemeService activityThemeService;
private final AccountService accountService;
@Override
public void removeAccountDataByDate(Long accountId, LocalDate date) {
this.getBaseMapper().deleteByAccountDate(accountId, date);
}
@Override
public List<LivePoolVO> liveList(PoolQueryDTO queryDTO) {
int current = queryDTO.getCurrent() <= 0 ? 1 : queryDTO.getCurrent();
Integer pageSize = queryDTO.getPageSize();
Integer startIndex = (current - 1) * pageSize;
return Optional.ofNullable(getBaseMapper().liveList(startIndex, pageSize, queryDTO)).orElse(new ArrayList<>());
}
@Override
public long liveCount(PoolQueryDTO queryDTO) {
return Optional.ofNullable(getBaseMapper().liveCount(queryDTO)).orElse(0L);
}
/**
* 获取主题活动员工有效直播数
*
* @param userId 用户id
* @param themeId 活动主题id
* @return 有效直播数
*/
@Override
public Integer getValidLiveCnt(Long userId, Long themeId) {
final ActivityTheme activityTheme = activityThemeService.getById(themeId);
if (Objects.isNull(activityTheme))
return 0;
final Set<Long> accountIds = accountService.lambdaQuery()
.eq(Account::getUserId, userId)
.list()
.stream()
.map(Account::getId)
.collect(Collectors.toSet());
if (Objects.equals(accountIds.size(), 0))
return 0;
final List<LivePool> list = this.lambdaQuery()
.in(LivePool::getAccountId, accountIds)
.eq(LivePool::getValidLive, 1)
.ge(LivePool::getLiveStartTime, activityTheme.getStartTime())
.le(LivePool::getLiveStartTime, activityTheme.getEndTime())
.list();
if (Objects.equals(list.size(), 0))
return 0;
return list.stream().collect(Collectors.groupingBy(LivePool::getRoomNo)).size();
}
/**
* 设置最佳直播
*
* @param liveId 直播数据id
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean markBestLive(Long liveId) {
final LivePool live = this.getById(liveId);
final Long themeId = live.getThemeId();// 获取主题id
final Account currentAccount = accountService.getById(live.getAccountId());
final Long userId = currentAccount.getUserId();// 获取用户id
final List<Account> accounts = accountService.getByUserId(userId);// 根据用户id获取拥有的所有账户
this.lambdaUpdate()
.set(LivePool::getValidLive, 1)
.eq(LivePool::getValidLive, 11)
.eq(LivePool::getThemeId, themeId)
.in(LivePool::getAccountId, accounts
.stream()
.map(Account::getId)
.collect(Collectors.toList())
)
.update();// 还原以前标记过的最佳直播
this.lambdaUpdate()
.set(LivePool::getValidLive, 11)
.eq(LivePool::getThemeId, themeId)
.eq(LivePool::getId, liveId)
.update();// 设置最新的最佳直播
return true;
}
}