|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+package com.water.patrol.controller;
|
|
|
2
|
+
|
|
|
3
|
+import com.water.common.core.result.R;
|
|
|
4
|
+import com.water.patrol.service.PatrolAreaService;
|
|
|
5
|
+import com.water.patrol.service.PatrolFormService;
|
|
|
6
|
+import com.water.patrol.service.PatrolRouteSetupService;
|
|
|
7
|
+import com.water.patrol.service.PatrolTemplateService;
|
|
|
8
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
9
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
10
|
+import lombok.RequiredArgsConstructor;
|
|
|
11
|
+import org.springframework.web.bind.annotation.*;
|
|
|
12
|
+
|
|
|
13
|
+import java.util.List;
|
|
|
14
|
+import java.util.Map;
|
|
|
15
|
+
|
|
|
16
|
+/**
|
|
|
17
|
+ * 巡查设置控制器 - Issue #87
|
|
|
18
|
+ * PAT-16 区域设置 / PAT-17 路线设置 / PAT-18 自定义表单 / PAT-19 表单挂接 / PAT-20 模版设置
|
|
|
19
|
+ */
|
|
|
20
|
+@Tag(name = "巡查设置")
|
|
|
21
|
+@RestController
|
|
|
22
|
+@RequestMapping("/patrol/setup")
|
|
|
23
|
+@RequiredArgsConstructor
|
|
|
24
|
+public class PatrolSetupController {
|
|
|
25
|
+
|
|
|
26
|
+ private final PatrolAreaService areaService;
|
|
|
27
|
+ private final PatrolRouteSetupService routeService;
|
|
|
28
|
+ private final PatrolFormService formService;
|
|
|
29
|
+ private final PatrolTemplateService templateService;
|
|
|
30
|
+
|
|
|
31
|
+ // ========== PAT-16 区域设置 ==========
|
|
|
32
|
+
|
|
|
33
|
+ @PostMapping("/area")
|
|
|
34
|
+ @Operation(summary = "创建巡检区域")
|
|
|
35
|
+ public R<Map<String, Object>> createArea(@RequestBody Map<String, Object> req) {
|
|
|
36
|
+ return R.ok(areaService.create(
|
|
|
37
|
+ (String) req.get("name"),
|
|
|
38
|
+ (String) req.get("code"),
|
|
|
39
|
+ req.get("parentId") != null ? Long.parseLong(String.valueOf(req.get("parentId"))) : null,
|
|
|
40
|
+ (String) req.get("description"),
|
|
|
41
|
+ req.get("lng") != null ? ((Number) req.get("lng")).doubleValue() : null,
|
|
|
42
|
+ req.get("lat") != null ? ((Number) req.get("lat")).doubleValue() : null,
|
|
|
43
|
+ req.get("radius") != null ? ((Number) req.get("radius")).doubleValue() : null));
|
|
|
44
|
+ }
|
|
|
45
|
+
|
|
|
46
|
+ @PutMapping("/area/{id}")
|
|
|
47
|
+ @Operation(summary = "更新巡检区域")
|
|
|
48
|
+ public R<Map<String, Object>> updateArea(@PathVariable Long id, @RequestBody Map<String, Object> req) {
|
|
|
49
|
+ return R.ok(areaService.update(id,
|
|
|
50
|
+ (String) req.get("name"),
|
|
|
51
|
+ (String) req.get("code"),
|
|
|
52
|
+ req.get("parentId") != null ? Long.parseLong(String.valueOf(req.get("parentId"))) : null,
|
|
|
53
|
+ (String) req.get("description"),
|
|
|
54
|
+ req.get("lng") != null ? ((Number) req.get("lng")).doubleValue() : null,
|
|
|
55
|
+ req.get("lat") != null ? ((Number) req.get("lat")).doubleValue() : null,
|
|
|
56
|
+ req.get("radius") != null ? ((Number) req.get("radius")).doubleValue() : null));
|
|
|
57
|
+ }
|
|
|
58
|
+
|
|
|
59
|
+ @DeleteMapping("/area/{id}")
|
|
|
60
|
+ @Operation(summary = "删除巡检区域")
|
|
|
61
|
+ public R<Void> deleteArea(@PathVariable Long id) {
|
|
|
62
|
+ areaService.delete(id);
|
|
|
63
|
+ return R.ok(null);
|
|
|
64
|
+ }
|
|
|
65
|
+
|
|
|
66
|
+ @GetMapping("/area/list")
|
|
|
67
|
+ @Operation(summary = "区域列表(支持树形)")
|
|
|
68
|
+ public R<Map<String, Object>> listAreas(@RequestParam(required = false) Long parentId) {
|
|
|
69
|
+ return R.ok(areaService.list(parentId));
|
|
|
70
|
+ }
|
|
|
71
|
+
|
|
|
72
|
+ @GetMapping("/area/{id}")
|
|
|
73
|
+ @Operation(summary = "区域详情(含统计)")
|
|
|
74
|
+ public R<Map<String, Object>> getAreaDetail(@PathVariable Long id) {
|
|
|
75
|
+ Map<String, Object> detail = areaService.getDetail(id);
|
|
|
76
|
+ if (detail == null) return R.fail("区域不存在");
|
|
|
77
|
+ return R.ok(detail);
|
|
|
78
|
+ }
|
|
|
79
|
+
|
|
|
80
|
+ // ========== PAT-17 路线设置 ==========
|
|
|
81
|
+
|
|
|
82
|
+ @PostMapping("/route")
|
|
|
83
|
+ @Operation(summary = "创建巡检路线")
|
|
|
84
|
+ @SuppressWarnings("unchecked")
|
|
|
85
|
+ public R<Map<String, Object>> createRoute(@RequestBody Map<String, Object> req) {
|
|
|
86
|
+ List<Map<String, Object>> checkpoints = (List<Map<String, Object>>) req.get("checkpoints");
|
|
|
87
|
+ return R.ok(routeService.create(
|
|
|
88
|
+ (String) req.get("name"),
|
|
|
89
|
+ req.get("areaId") != null ? Long.parseLong(String.valueOf(req.get("areaId"))) : null,
|
|
|
90
|
+ checkpoints,
|
|
|
91
|
+ req.get("estimDuration") != null ? ((Number) req.get("estimDuration")).intValue() : null,
|
|
|
92
|
+ (String) req.get("description")));
|
|
|
93
|
+ }
|
|
|
94
|
+
|
|
|
95
|
+ @PutMapping("/route/{id}")
|
|
|
96
|
+ @Operation(summary = "更新巡检路线")
|
|
|
97
|
+ @SuppressWarnings("unchecked")
|
|
|
98
|
+ public R<Map<String, Object>> updateRoute(@PathVariable Long id, @RequestBody Map<String, Object> req) {
|
|
|
99
|
+ List<Map<String, Object>> checkpoints = (List<Map<String, Object>>) req.get("checkpoints");
|
|
|
100
|
+ return R.ok(routeService.update(id,
|
|
|
101
|
+ (String) req.get("name"),
|
|
|
102
|
+ req.get("areaId") != null ? Long.parseLong(String.valueOf(req.get("areaId"))) : null,
|
|
|
103
|
+ checkpoints,
|
|
|
104
|
+ req.get("estimDuration") != null ? ((Number) req.get("estimDuration")).intValue() : null,
|
|
|
105
|
+ (String) req.get("description")));
|
|
|
106
|
+ }
|
|
|
107
|
+
|
|
|
108
|
+ @DeleteMapping("/route/{id}")
|
|
|
109
|
+ @Operation(summary = "删除巡检路线")
|
|
|
110
|
+ public R<Void> deleteRoute(@PathVariable Long id) {
|
|
|
111
|
+ routeService.delete(id);
|
|
|
112
|
+ return R.ok(null);
|
|
|
113
|
+ }
|
|
|
114
|
+
|
|
|
115
|
+ @GetMapping("/route/list")
|
|
|
116
|
+ @Operation(summary = "路线列表")
|
|
|
117
|
+ public R<Map<String, Object>> listRoutes(
|
|
|
118
|
+ @RequestParam(required = false) Long areaId,
|
|
|
119
|
+ @RequestParam(defaultValue = "1") int page,
|
|
|
120
|
+ @RequestParam(defaultValue = "20") int size) {
|
|
|
121
|
+ return R.ok(routeService.list(areaId, page, size));
|
|
|
122
|
+ }
|
|
|
123
|
+
|
|
|
124
|
+ @GetMapping("/route/{id}")
|
|
|
125
|
+ @Operation(summary = "路线详情(含巡检点列表)")
|
|
|
126
|
+ public R<Map<String, Object>> getRouteDetail(@PathVariable Long id) {
|
|
|
127
|
+ Map<String, Object> detail = routeService.getDetail(id);
|
|
|
128
|
+ if (detail == null) return R.fail("路线不存在");
|
|
|
129
|
+ return R.ok(detail);
|
|
|
130
|
+ }
|
|
|
131
|
+
|
|
|
132
|
+ @PostMapping("/route/{id}/copy")
|
|
|
133
|
+ @Operation(summary = "复制路线")
|
|
|
134
|
+ public R<Map<String, Object>> copyRoute(@PathVariable Long id) {
|
|
|
135
|
+ return R.ok(routeService.copyRoute(id));
|
|
|
136
|
+ }
|
|
|
137
|
+
|
|
|
138
|
+ // ========== PAT-18 自定义表单 + PAT-19 表单挂接 ==========
|
|
|
139
|
+
|
|
|
140
|
+ @PostMapping("/form")
|
|
|
141
|
+ @Operation(summary = "创建巡检表单")
|
|
|
142
|
+ @SuppressWarnings("unchecked")
|
|
|
143
|
+ public R<Map<String, Object>> createForm(@RequestBody Map<String, Object> req) {
|
|
|
144
|
+ List<Map<String, Object>> fields = (List<Map<String, Object>>) req.get("fields");
|
|
|
145
|
+ return R.ok(formService.createForm(
|
|
|
146
|
+ (String) req.get("name"),
|
|
|
147
|
+ (String) req.get("type"),
|
|
|
148
|
+ fields));
|
|
|
149
|
+ }
|
|
|
150
|
+
|
|
|
151
|
+ @GetMapping("/form/list")
|
|
|
152
|
+ @Operation(summary = "表单列表")
|
|
|
153
|
+ public R<Map<String, Object>> listForms(@RequestParam(required = false) String type) {
|
|
|
154
|
+ return R.ok(formService.listForms(type));
|
|
|
155
|
+ }
|
|
|
156
|
+
|
|
|
157
|
+ @GetMapping("/form/{id}")
|
|
|
158
|
+ @Operation(summary = "表单详情(含字段定义)")
|
|
|
159
|
+ public R<Map<String, Object>> getFormDetail(@PathVariable Long id) {
|
|
|
160
|
+ Map<String, Object> form = formService.getForm(id);
|
|
|
161
|
+ if (form == null) return R.fail("表单不存在");
|
|
|
162
|
+ return R.ok(form);
|
|
|
163
|
+ }
|
|
|
164
|
+
|
|
|
165
|
+ @PostMapping("/form/{id}/bind")
|
|
|
166
|
+ @Operation(summary = "挂接表单")
|
|
|
167
|
+ public R<Map<String, Object>> bindForm(@PathVariable Long id, @RequestBody Map<String, Object> req) {
|
|
|
168
|
+ String targetType = (String) req.get("targetType");
|
|
|
169
|
+ Long targetId = Long.parseLong(String.valueOf(req.get("targetId")));
|
|
|
170
|
+ return R.ok(formService.bindForm(id, targetType, targetId));
|
|
|
171
|
+ }
|
|
|
172
|
+
|
|
|
173
|
+ @PostMapping("/form/{id}/unbind")
|
|
|
174
|
+ @Operation(summary = "解绑表单")
|
|
|
175
|
+ public R<Map<String, Object>> unbindForm(@PathVariable Long id, @RequestBody Map<String, Object> req) {
|
|
|
176
|
+ String targetType = (String) req.get("targetType");
|
|
|
177
|
+ Long targetId = Long.parseLong(String.valueOf(req.get("targetId")));
|
|
|
178
|
+ return R.ok(formService.unbindForm(id, targetType, targetId));
|
|
|
179
|
+ }
|
|
|
180
|
+
|
|
|
181
|
+ @GetMapping("/form/bound")
|
|
|
182
|
+ @Operation(summary = "获取已绑定的表单")
|
|
|
183
|
+ public R<Map<String, Object>> getBoundForms(
|
|
|
184
|
+ @RequestParam String targetType,
|
|
|
185
|
+ @RequestParam Long targetId) {
|
|
|
186
|
+ return R.ok(formService.getBoundForms(targetType, targetId));
|
|
|
187
|
+ }
|
|
|
188
|
+
|
|
|
189
|
+ // ========== PAT-20 模版设置 ==========
|
|
|
190
|
+
|
|
|
191
|
+ @PostMapping("/template")
|
|
|
192
|
+ @Operation(summary = "创建巡检模板")
|
|
|
193
|
+ @SuppressWarnings("unchecked")
|
|
|
194
|
+ public R<Map<String, Object>> createTemplate(@RequestBody Map<String, Object> req) {
|
|
|
195
|
+ Map<String, Object> config = (Map<String, Object>) req.get("config");
|
|
|
196
|
+ return R.ok(templateService.create(
|
|
|
197
|
+ (String) req.get("name"),
|
|
|
198
|
+ (String) req.get("type"),
|
|
|
199
|
+ config));
|
|
|
200
|
+ }
|
|
|
201
|
+
|
|
|
202
|
+ @PutMapping("/template/{id}")
|
|
|
203
|
+ @Operation(summary = "更新巡检模板")
|
|
|
204
|
+ @SuppressWarnings("unchecked")
|
|
|
205
|
+ public R<Map<String, Object>> updateTemplate(@PathVariable Long id, @RequestBody Map<String, Object> req) {
|
|
|
206
|
+ Map<String, Object> config = (Map<String, Object>) req.get("config");
|
|
|
207
|
+ return R.ok(templateService.update(id,
|
|
|
208
|
+ (String) req.get("name"),
|
|
|
209
|
+ (String) req.get("type"),
|
|
|
210
|
+ config));
|
|
|
211
|
+ }
|
|
|
212
|
+
|
|
|
213
|
+ @DeleteMapping("/template/{id}")
|
|
|
214
|
+ @Operation(summary = "删除巡检模板")
|
|
|
215
|
+ public R<Void> deleteTemplate(@PathVariable Long id) {
|
|
|
216
|
+ templateService.delete(id);
|
|
|
217
|
+ return R.ok(null);
|
|
|
218
|
+ }
|
|
|
219
|
+
|
|
|
220
|
+ @GetMapping("/template/list")
|
|
|
221
|
+ @Operation(summary = "模板列表")
|
|
|
222
|
+ public R<Map<String, Object>> listTemplates(@RequestParam(required = false) String type) {
|
|
|
223
|
+ return R.ok(templateService.list(type));
|
|
|
224
|
+ }
|
|
|
225
|
+
|
|
|
226
|
+ @GetMapping("/template/{id}")
|
|
|
227
|
+ @Operation(summary = "模板详情(含关联路线/表单)")
|
|
|
228
|
+ public R<Map<String, Object>> getTemplateDetail(@PathVariable Long id) {
|
|
|
229
|
+ Map<String, Object> detail = templateService.getDetail(id);
|
|
|
230
|
+ if (detail == null) return R.fail("模板不存在");
|
|
|
231
|
+ return R.ok(detail);
|
|
|
232
|
+ }
|
|
|
233
|
+
|
|
|
234
|
+ @PostMapping("/template/{id}/apply")
|
|
|
235
|
+ @Operation(summary = "应用模板生成巡检计划")
|
|
|
236
|
+ @SuppressWarnings("unchecked")
|
|
|
237
|
+ public R<Map<String, Object>> applyTemplate(@PathVariable Long id, @RequestBody Map<String, Object> req) {
|
|
|
238
|
+ Map<String, String> dateRange = (Map<String, String>) req.get("dateRange");
|
|
|
239
|
+ return R.ok(templateService.applyTemplate(id, dateRange));
|
|
|
240
|
+ }
|
|
|
241
|
+}
|