InspectServiceImpl.java
3.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
package vion.service.impl;
import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.collection.ListUtil;
import org.dromara.hutool.core.lang.Opt;
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.springframework.stereotype.Service;
import vion.dto.InspectDTO;
import vion.mapper.InspectMapper;
import vion.model.Account;
import vion.model.Form;
import vion.model.Inspect;
import vion.model.Store;
import vion.service.IFormService;
import vion.service.IInspectService;
import vion.vo.FormVO;
import vion.vo.InspectVO;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class InspectServiceImpl extends MPJBaseServiceImpl<InspectMapper, Inspect> implements IInspectService {
private final IFormService formService;
private final Converter converter;
@Override
public Page<InspectVO> getInspectList(InspectDTO data) {
MPJLambdaWrapper<Inspect> wrapper = new MPJLambdaWrapper<>(converter.convert(data, Inspect.class))
.selectAll(Inspect.class)
.selectAs(Account::getName, InspectVO::getAccountName)
.selectAs(Store::getName, InspectVO::getStoreName)
.leftJoin(Account.class, Account::getId, Inspect::getAccountId)
.leftJoin(Store.class, Store::getId, Inspect::getStoreId)
.between(data.getStartdate() != null && data.getEnddate() != null, Inspect::getInspectDate, data.getStartdate(), data.getEnddate())
.orderByDesc(Inspect::getCreateTime);
Page<InspectVO> inspectVOPage = this.selectJoinListPage(Page.of(data.getPageNum(), data.getPageSize()), InspectVO.class, wrapper);
Opt.ofEmptyAble(inspectVOPage.getRecords())
.map(l -> l.stream().map(InspectVO::getId).collect(Collectors.toList()))
.map(idList -> formService.lambdaQuery().eq(Form::getSourceId, 2).in(Form::getPid, idList).list())
.filter(CollUtil::isNotEmpty)
.ifPresent(formList -> {
Map<Long, List<FormVO>> inspectId2FormIdMap = formList.stream().collect(Collectors.groupingBy(Form::getPid, Collectors.mapping(form -> converter.convert(form, FormVO.class), Collectors.toList())));
inspectVOPage.getRecords().forEach(inspectVO -> {
inspectVO.setFormList(inspectId2FormIdMap.getOrDefault(inspectVO.getId(), ListUtil.empty()));
});
});
return inspectVOPage;
}
@Override
public InspectVO getById(Long id) {
MPJLambdaWrapper<Inspect> wrapper = new MPJLambdaWrapper<Inspect>()
.selectAll(Inspect.class)
.selectAs(Account::getName, InspectVO::getAccountName)
.selectAs(Store::getName, InspectVO::getStoreName)
.leftJoin(Account.class, Account::getId, Inspect::getAccountId)
.leftJoin(Store.class, Store::getId, Inspect::getStoreId)
.eq(Inspect::getId, id);
return this.selectJoinOne(InspectVO.class, wrapper);
}
}