EventServiceImpl.java
3.03 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
package vion.service.impl.monitor;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.lang.Opt;
import org.springframework.stereotype.Service;
import vion.dto.monitor.EventDTO;
import vion.mapper.monitor.EventMapper;
import vion.model.monitor.Event;
import vion.model.monitor.EventRecord;
import vion.model.monitor.RAgentEvent;
import vion.service.monitor.IEventRecordService;
import vion.service.monitor.IEventService;
import vion.vo.monitor.EventVO;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author vion
* @date 2024/10/31
*/
@Service
@RequiredArgsConstructor
public class EventServiceImpl extends MPJBaseServiceImpl<EventMapper, Event> implements IEventService {
private final IEventRecordService eventRecordService;
private final Converter converter;
@Override
public Page<EventVO> list(EventDTO dto) {
Assert.notNull(dto.getMallUid(), "mallUid 不能为空");
var wrapper = new MPJLambdaWrapper<>(converter.convert(dto, Event.class))
.selectAs(Event::getName, EventVO::getName)
.selectAs(Event::getUid, EventVO::getUid)
.selectAsClass(RAgentEvent.class, EventVO.class)
.leftJoin(RAgentEvent.class, RAgentEvent::getEventUid, Event::getUid)
.eq(RAgentEvent::getMallUid, dto.getMallUid())
.orderByDesc(RAgentEvent::getUpdateTime);
var eventVOPage = this.selectJoinListPage(Page.of(dto.getPageNum(), dto.getPageSize()), EventVO.class, wrapper);
Opt.ofEmptyAble(eventVOPage.getRecords())
.ifPresent(r -> {
var eventUidList = r.stream().map(EventVO::getUid).toList();
// fixme data 是字符串
/* var eventRecWrapper1 = new MPJLambdaWrapper<EventRecord>()
.select("DISTINCT on (event_uid) *")
.in("event_uid", eventUidList)
.orderByDesc("event_uid", "create_time");
var eventRecordList1 = eventRecordService.selectJoinList(EventRecord.class, eventRecWrapper1);*/
var eventRecWrapper = Wrappers.<EventRecord>query()
.select("DISTINCT on (event_uid) *")
.in("event_uid", eventUidList)
.orderByDesc("event_uid", "create_time");
var eventRecordList = eventRecordService.list(eventRecWrapper);
var eventUid2SelfMap = eventRecordList.stream().collect(Collectors.toMap(EventRecord::getEventUid, Function.identity()));
r.forEach(tmp -> tmp.setEventRecord(eventUid2SelfMap.get(tmp.getUid())));
});
return eventVOPage;
}
}