RAgentEventServiceImpl.java
1.67 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
package vion.service.impl.monitor;
import com.github.yulichang.base.MPJBaseServiceImpl;
import org.dromara.hutool.core.lang.Opt;
import org.springframework.stereotype.Service;
import vion.mapper.monitor.RAgentEventMapper;
import vion.model.monitor.RAgentEvent;
import vion.service.monitor.IRAgentEventService;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author vion
* @date 2024/10/31
*/
@Service
public class RAgentEventServiceImpl extends MPJBaseServiceImpl<RAgentEventMapper, RAgentEvent> implements IRAgentEventService {
@Override
public String bind(String agentUid, List<RAgentEvent> dtoList) {
dtoList.forEach(ae -> ae.setAgentUid(agentUid));
var agentEventList = this.lambdaQuery().eq(RAgentEvent::getAgentUid, agentUid).list();
var mallUid2AEMap = agentEventList.stream().collect(Collectors.toMap(RAgentEvent::getMallUid, Function.identity()));
List<RAgentEvent> updList = new ArrayList<>();
List<RAgentEvent> insList = new ArrayList<>();
dtoList.forEach(dto -> {
if (mallUid2AEMap.containsKey(dto.getMallUid())) {
var ae = mallUid2AEMap.get(dto.getMallUid());
dto.setId(ae.getId());
updList.add(dto);
} else {
insList.add(dto);
}
});
Opt.ofEmptyAble(updList).ifPresent(this::updateBatchById);
Opt.ofEmptyAble(insList).ifPresent(this::saveBatch);
return "绑定成功";
}
@Override
public String unbind(List<Long> idList) {
return this.removeBatchByIds(idList) ? "解绑成功" : "解绑失败";
}
}