DataDistrictController.java
4.75 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.diligrp.assistant.data.controller;
import com.diligrp.assistant.data.domain.DataDistrictDTO;
import com.diligrp.assistant.data.domain.DistrictPageQuery;
import com.diligrp.assistant.data.domain.ListDataDistrict;
import com.diligrp.assistant.data.model.DataDistrict;
import com.diligrp.assistant.data.service.DataDistrictService;
import com.diligrp.assistant.shared.domain.Message;
import com.diligrp.assistant.shared.util.AssertUtils;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping(value = "/api/district")
public class DataDistrictController {
@Resource
private DataDistrictService dataDistrictService;
@RequestMapping(value = "/findById.do")
public Message<DataDistrictDTO> findById(@RequestParam("id") Long id) {
DataDistrict district = dataDistrictService.findDataDistrictById(id);
return Message.success(DataDistrictDTO.of(district.getId(), district.getParentId(),
district.getName(), district.getLevel(), district.getFullName(), district.getPath()));
}
@RequestMapping(value = "/findParentById.do")
public Message<DataDistrictDTO> findParentById(@RequestParam("id") Long id) {
DataDistrict district = dataDistrictService.findParentDistrictById(id);
return Message.success(DataDistrictDTO.of(district.getId(), district.getParentId(),
district.getName(), district.getLevel(), district.getFullName(), district.getPath()));
}
@RequestMapping(value = "/listParentsById.do")
public Message<List<DataDistrictDTO>> listParentsById(@RequestParam("id") Long id) {
List<DataDistrictDTO> districts = dataDistrictService.listParentsById(id).stream().map(d ->
DataDistrictDTO.of(d.getId(), d.getParentId(), d.getName(), d.getLevel(), d.getFullName(), d.getPath()))
.collect(Collectors.toList());
return Message.success(districts);
}
@RequestMapping(value = "/listChildrenById.do")
public Message<List<DataDistrictDTO>> listChildrenById(@RequestBody ListDataDistrict request) {
AssertUtils.notNull(request.getId(), "id missed");
AssertUtils.notNull(request.getPageNo(), "pageNo missed");
AssertUtils.notNull(request.getPageSize(), "pageSize missed");
DistrictPageQuery query = new DistrictPageQuery();
query.setId(request.getId());
query.from(request.getPageNo(), request.getPageSize());
List<DataDistrictDTO> districts = dataDistrictService.listChildrenById(query).stream().map(d ->
DataDistrictDTO.of(d.getId(), d.getParentId(), d.getName(), d.getLevel(), d.getFullName(), d.getPath()))
.collect(Collectors.toList());
return Message.success(districts);
}
@RequestMapping(value = "/listByLevel.do")
public Message<List<DataDistrictDTO>> listByLevel(@RequestBody ListDataDistrict request) {
AssertUtils.notNull(request.getLevel(), "level missed");
AssertUtils.notNull(request.getPageNo(), "pageNo missed");
AssertUtils.notNull(request.getPageSize(), "pageSize missed");
DistrictPageQuery query = new DistrictPageQuery();
query.setLevel(request.getLevel());
query.from(request.getPageNo(), request.getPageSize());
List<DataDistrictDTO> districts = dataDistrictService.listDataDistrictsByLevel(query).stream().map(d ->
DataDistrictDTO.of(d.getId(), d.getParentId(), d.getName(), d.getLevel(), d.getFullName(), d.getPath()))
.collect(Collectors.toList());
return Message.success(districts);
}
@RequestMapping(value = "/listByDistance.do")
public Message<List<DataDistrictDTO>> listByDistance(@RequestBody ListDataDistrict request) {
AssertUtils.notEmpty(request.getLongitude(), "longitude missed");
AssertUtils.notEmpty(request.getLatitude(), "latitude missed");
AssertUtils.notNull(request.getPageNo(), "pageNo missed");
AssertUtils.notNull(request.getPageSize(), "pageSize missed");
DistrictPageQuery query = new DistrictPageQuery();
query.setLongitude(request.getLongitude());
query.setLatitude(request.getLatitude());
query.from(request.getPageNo(), request.getPageSize());
List<DataDistrictDTO> districts = dataDistrictService.listDataDistrictsByDistance(query).stream().map(d ->
DataDistrictDTO.of(d.getId(), d.getParentId(), d.getName(), d.getLevel(), d.getFullName(), d.getPath()))
.collect(Collectors.toList());
return Message.success(districts);
}
}