MAccountServiceImpl.java
3.18 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
package vion.service.impl.monitor;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.github.yulichang.base.MPJBaseServiceImpl;
import lombok.RequiredArgsConstructor;
import org.dromara.hutool.core.bean.BeanUtil;
import org.dromara.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import vion.mapper.monitor.MAccountMapper;
import vion.model.monitor.*;
import vion.service.monitor.IMAccountService;
import vion.service.monitor.IRAccountEventService;
import vion.service.monitor.IRAgentEventService;
import vion.service.monitor.IRUserAccountService;
import java.util.List;
/**
* @author vion
* @date 2024/10/31
*/
@Service
@RequiredArgsConstructor
public class MAccountServiceImpl extends MPJBaseServiceImpl<MAccountMapper, MAccount> implements IMAccountService {
private final IRAccountEventService accountEventService;
private final IRAgentEventService agentEventService;
private final IRUserAccountService userAccountService;
@Override
public List<RAccountEvent> getEventById(String uid) {
return accountEventService.lambdaQuery().eq(RAccountEvent::getAccountUid, uid).list();
}
@Override
public String saveEvent(String agentUid, String uid, RAccountEvent event) {
event.setAgentUid(agentUid);
event.setAccountUid(uid);
var save = accountEventService.save(event);
if (save) {
var mallList = Db.lambdaQuery(Mall.class).eq(Mall::getAccountUid, uid).list();
var mallUidList = mallList.stream().map(Mall::getUid).toList();
var eventList = agentEventService.lambdaQuery()
.eq(RAgentEvent::getAccountUid, uid)
.eq(RAgentEvent::getEventUid, event.getEventUid())
.list();
var existMallUidList = eventList.stream().map(RAgentEvent::getMallUid).toList();
if (CollUtil.isNotEmpty(mallUidList) && CollUtil.isNotEmpty(existMallUidList)) {
// 把 existMallUidList 从 mallUidList 中移除
mallUidList.removeAll(existMallUidList);
var saveList = mallUidList.stream().map(mUid -> {
var rAgentEvent = BeanUtil.copyProperties(event, RAgentEvent.class);
rAgentEvent.setMallUid(mUid);
return rAgentEvent;
}).toList();
var res = agentEventService.saveBatch(saveList);
if (!res) {
throw new RuntimeException();
}
}
}
return save ? "成功" : "失败";
}
@Override
public List<RUserAccount> subList(Long userId) {
return userAccountService.lambdaQuery().eq(RUserAccount::getUserId, userId).list();
}
@Override
public String sub(RUserAccount userAccount) {
return userAccountService.save(userAccount) ? "订阅成功" : "订阅失败";
}
@Override
public String unsub(RUserAccount userAccount) {
return userAccountService.lambdaUpdate()
.eq(RUserAccount::getAccountId, userAccount.getAccountId())
.eq(RUserAccount::getUserId, userAccount.getUserId()).remove() ? "取消订阅成功" : "取消订阅失败";
}
}