MallServiceImpl.java
2.82 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
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.MallDTO;
import vion.mapper.monitor.MallMapper;
import vion.model.monitor.EventRecord;
import vion.model.monitor.MAccount;
import vion.model.monitor.Mall;
import vion.service.monitor.IEventRecordService;
import vion.service.monitor.IMallService;
import vion.vo.monitor.MallVO;
import java.util.stream.Collectors;
/**
* @author vion
* @date 2024/10/31
*/
@Service
@RequiredArgsConstructor
public class MallServiceImpl extends MPJBaseServiceImpl<MallMapper, Mall> implements IMallService {
private final IEventRecordService eventRecordService;
private final Converter converter;
@Override
public Page<MallVO> list(MallDTO dto) {
Assert.notNull(dto.getAgentType(), "agentType 不能为空");
var wrapper = new MPJLambdaWrapper<>(converter.convert(dto, Mall.class))
.selectAll(Mall.class)
.selectAs(MAccount::getName, MallVO::getAccountName)
.leftJoin(MAccount.class, MAccount::getUid, Mall::getAccountUid)
.orderByDesc(Mall::getUpdateTime);
var mallVOPage = this.selectJoinListPage(Page.of(dto.getPageNum(), dto.getPageSize()), MallVO.class, wrapper);
Opt.ofEmptyAble(mallVOPage.getRecords())
.ifPresent(r -> {
var mallUidList = r.stream().map(MallVO::getUid).toList();
// fixme {@link EventServiceImpl #51}
var eventRecWrapper = Wrappers.<EventRecord>query()
.select("DISTINCT on (mall_uid) *")
.in("mall_uid", mallUidList)
.orderByDesc("mall_uid", "create_time");
var eventRecordList = eventRecordService.list(eventRecWrapper);
var mallUid2SelfMap = eventRecordList.stream().collect(Collectors.groupingBy(EventRecord::getMallUid));
r.forEach(tmp -> tmp.setEventRecordList(mallUid2SelfMap.get(tmp.getUid())));
});
return mallVOPage;
}
@Override
public MallVO get(Long id) {
var wrapper = new MPJLambdaWrapper<Mall>()
.selectAll(Mall.class)
.selectAs(MAccount::getName, MallVO::getAccountName)
.leftJoin(MAccount.class, MAccount::getUid, Mall::getAccountUid)
.eq(Mall::getId, id);
return this.selectJoinOne(MallVO.class, wrapper);
}
}