|
|
@@ -9,11 +9,20 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
9
|
9
|
import org.springframework.stereotype.Component;
|
|
10
|
10
|
import com.ruoyi.common.core.domain.TreeSelect;
|
|
11
|
11
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
12
|
+import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
13
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
12
|
14
|
import com.ruoyi.common.utils.StringUtils;
|
|
13
|
15
|
import com.ruoyi.system.service.ISysDeptService;
|
|
14
|
16
|
|
|
15
|
17
|
/**
|
|
16
|
|
- * 填报乡镇 / 村字典(县 → 乡镇 → 村;乡镇为县级下 order_num > 12 节点)
|
|
|
18
|
+ * 填报乡镇 / 村字典(县 → 乡镇 → 村;乡镇为县级下 order_num > 12 节点)。
|
|
|
19
|
+ * <p>
|
|
|
20
|
+ * 下拉范围:
|
|
|
21
|
+ * <ul>
|
|
|
22
|
+ * <li>乡镇人员:仅本镇 + 本镇下各村</li>
|
|
|
23
|
+ * <li>村级人员:仅上级乡镇 + 本村(不依赖 selectDeptList 的 @DataScope,避免查不到上级镇)</li>
|
|
|
24
|
+ * <li>其余(含超管):按部门数据权限列出填报乡镇/村</li>
|
|
|
25
|
+ * </ul>
|
|
17
|
26
|
*/
|
|
18
|
27
|
@Component
|
|
19
|
28
|
public class TownDeptSupport
|
|
|
@@ -23,30 +32,17 @@ public class TownDeptSupport
|
|
23
|
32
|
|
|
24
|
33
|
public List<SysDept> listReportTowns()
|
|
25
|
34
|
{
|
|
26
|
|
- SysDept query = new SysDept();
|
|
27
|
|
- query.setParentId(YakHerdInventoryRules.TOWN_PARENT_ID);
|
|
28
|
|
- query.setStatus("0");
|
|
29
|
|
- List<SysDept> depts = deptService.selectDeptList(query);
|
|
30
|
|
- List<SysDept> towns = new ArrayList<>();
|
|
31
|
|
- if (depts == null)
|
|
|
35
|
+ ReportOrgScope scope = resolveReportOrgScope();
|
|
|
36
|
+ if (scope.townDeptId != null)
|
|
32
|
37
|
{
|
|
33
|
|
- return towns;
|
|
34
|
|
- }
|
|
35
|
|
- for (SysDept dept : depts)
|
|
36
|
|
- {
|
|
37
|
|
- if (dept == null || !"0".equals(dept.getDelFlag()))
|
|
38
|
|
- {
|
|
39
|
|
- continue;
|
|
40
|
|
- }
|
|
41
|
|
- if (dept.getOrderNum() != null && dept.getOrderNum() > YakHerdInventoryRules.TOWN_MIN_ORDER_NUM)
|
|
|
38
|
+ SysDept town = deptService.selectDeptById(scope.townDeptId);
|
|
|
39
|
+ if (isActiveReportTown(town))
|
|
42
|
40
|
{
|
|
43
|
|
- towns.add(dept);
|
|
|
41
|
+ return Collections.singletonList(town);
|
|
44
|
42
|
}
|
|
|
43
|
+ return Collections.emptyList();
|
|
45
|
44
|
}
|
|
46
|
|
- towns.sort((a, b) -> Integer.compare(
|
|
47
|
|
- a.getOrderNum() == null ? 0 : a.getOrderNum(),
|
|
48
|
|
- b.getOrderNum() == null ? 0 : b.getOrderNum()));
|
|
49
|
|
- return towns;
|
|
|
45
|
+ return queryReportTownsByDataScope();
|
|
50
|
46
|
}
|
|
51
|
47
|
|
|
52
|
48
|
public List<SysDept> listVillagesUnderTown(Long townDeptId)
|
|
|
@@ -56,25 +52,21 @@ public class TownDeptSupport
|
|
56
|
52
|
{
|
|
57
|
53
|
return villages;
|
|
58
|
54
|
}
|
|
59
|
|
- SysDept query = new SysDept();
|
|
60
|
|
- query.setParentId(townDeptId);
|
|
61
|
|
- query.setStatus("0");
|
|
62
|
|
- List<SysDept> depts = deptService.selectDeptList(query);
|
|
63
|
|
- if (depts == null)
|
|
|
55
|
+ ReportOrgScope scope = resolveReportOrgScope();
|
|
|
56
|
+ if (scope.townDeptId != null && !scope.townDeptId.equals(townDeptId))
|
|
64
|
57
|
{
|
|
65
|
58
|
return villages;
|
|
66
|
59
|
}
|
|
67
|
|
- for (SysDept dept : depts)
|
|
|
60
|
+ if (scope.villageDeptId != null)
|
|
68
|
61
|
{
|
|
69
|
|
- if (dept != null && "0".equals(dept.getDelFlag()))
|
|
|
62
|
+ SysDept village = deptService.selectDeptById(scope.villageDeptId);
|
|
|
63
|
+ if (isActiveDept(village) && townDeptId.equals(village.getParentId()))
|
|
70
|
64
|
{
|
|
71
|
|
- villages.add(dept);
|
|
|
65
|
+ villages.add(village);
|
|
72
|
66
|
}
|
|
|
67
|
+ return villages;
|
|
73
|
68
|
}
|
|
74
|
|
- villages.sort((a, b) -> Integer.compare(
|
|
75
|
|
- a.getOrderNum() == null ? 0 : a.getOrderNum(),
|
|
76
|
|
- b.getOrderNum() == null ? 0 : b.getOrderNum()));
|
|
77
|
|
- return villages;
|
|
|
69
|
+ return queryVillagesByParent(townDeptId);
|
|
78
|
70
|
}
|
|
79
|
71
|
|
|
80
|
72
|
/**
|
|
|
@@ -152,7 +144,7 @@ public class TownDeptSupport
|
|
152
|
144
|
return null;
|
|
153
|
145
|
}
|
|
154
|
146
|
SysDept village = deptService.selectDeptById(villageDeptId);
|
|
155
|
|
- if (village == null || !"0".equals(village.getDelFlag()) || !"0".equals(village.getStatus()))
|
|
|
147
|
+ if (!isActiveDept(village))
|
|
156
|
148
|
{
|
|
157
|
149
|
return null;
|
|
158
|
150
|
}
|
|
|
@@ -237,4 +229,156 @@ public class TownDeptSupport
|
|
237
|
229
|
}
|
|
238
|
230
|
return Collections.unmodifiableList(options);
|
|
239
|
231
|
}
|
|
|
232
|
+
|
|
|
233
|
+ /**
|
|
|
234
|
+ * 当前登录人锁定的填报乡镇 id(乡镇/村人员);非此类人员返回 null(不限制)。
|
|
|
235
|
+ */
|
|
|
236
|
+ public Long resolveScopedTownDeptId()
|
|
|
237
|
+ {
|
|
|
238
|
+ return resolveReportOrgScope().townDeptId;
|
|
|
239
|
+ }
|
|
|
240
|
+
|
|
|
241
|
+ /**
|
|
|
242
|
+ * 当前登录人是否落在填报乡镇/村:返回应锁定的乡镇、村;否则不限制(走 @DataScope 列表)。
|
|
|
243
|
+ */
|
|
|
244
|
+ ReportOrgScope resolveReportOrgScope()
|
|
|
245
|
+ {
|
|
|
246
|
+ LoginUser loginUser = tryGetLoginUser();
|
|
|
247
|
+ if (loginUser == null || SecurityUtils.isAdmin(loginUser.getUserId()))
|
|
|
248
|
+ {
|
|
|
249
|
+ return ReportOrgScope.unrestricted();
|
|
|
250
|
+ }
|
|
|
251
|
+ Long deptId = loginUser.getDeptId();
|
|
|
252
|
+ if (deptId == null && loginUser.getUser() != null)
|
|
|
253
|
+ {
|
|
|
254
|
+ deptId = loginUser.getUser().getDeptId();
|
|
|
255
|
+ }
|
|
|
256
|
+ if (deptId == null)
|
|
|
257
|
+ {
|
|
|
258
|
+ return ReportOrgScope.unrestricted();
|
|
|
259
|
+ }
|
|
|
260
|
+ SysDept self = deptService.selectDeptById(deptId);
|
|
|
261
|
+ if (!isActiveDept(self))
|
|
|
262
|
+ {
|
|
|
263
|
+ return ReportOrgScope.unrestricted();
|
|
|
264
|
+ }
|
|
|
265
|
+ if (isActiveReportTown(self))
|
|
|
266
|
+ {
|
|
|
267
|
+ return ReportOrgScope.townOnly(self.getDeptId());
|
|
|
268
|
+ }
|
|
|
269
|
+ if (self.getParentId() != null)
|
|
|
270
|
+ {
|
|
|
271
|
+ SysDept parent = deptService.selectDeptById(self.getParentId());
|
|
|
272
|
+ if (isActiveReportTown(parent))
|
|
|
273
|
+ {
|
|
|
274
|
+ return ReportOrgScope.villageOnly(parent.getDeptId(), self.getDeptId());
|
|
|
275
|
+ }
|
|
|
276
|
+ }
|
|
|
277
|
+ return ReportOrgScope.unrestricted();
|
|
|
278
|
+ }
|
|
|
279
|
+
|
|
|
280
|
+ private List<SysDept> queryReportTownsByDataScope()
|
|
|
281
|
+ {
|
|
|
282
|
+ SysDept query = new SysDept();
|
|
|
283
|
+ query.setParentId(YakHerdInventoryRules.TOWN_PARENT_ID);
|
|
|
284
|
+ query.setStatus("0");
|
|
|
285
|
+ List<SysDept> depts = deptService.selectDeptList(query);
|
|
|
286
|
+ List<SysDept> towns = new ArrayList<>();
|
|
|
287
|
+ if (depts == null)
|
|
|
288
|
+ {
|
|
|
289
|
+ return towns;
|
|
|
290
|
+ }
|
|
|
291
|
+ for (SysDept dept : depts)
|
|
|
292
|
+ {
|
|
|
293
|
+ if (isActiveReportTown(dept))
|
|
|
294
|
+ {
|
|
|
295
|
+ towns.add(dept);
|
|
|
296
|
+ }
|
|
|
297
|
+ }
|
|
|
298
|
+ towns.sort((a, b) -> Integer.compare(
|
|
|
299
|
+ a.getOrderNum() == null ? 0 : a.getOrderNum(),
|
|
|
300
|
+ b.getOrderNum() == null ? 0 : b.getOrderNum()));
|
|
|
301
|
+ return towns;
|
|
|
302
|
+ }
|
|
|
303
|
+
|
|
|
304
|
+ private List<SysDept> queryVillagesByParent(Long townDeptId)
|
|
|
305
|
+ {
|
|
|
306
|
+ List<SysDept> villages = new ArrayList<>();
|
|
|
307
|
+ SysDept query = new SysDept();
|
|
|
308
|
+ query.setParentId(townDeptId);
|
|
|
309
|
+ query.setStatus("0");
|
|
|
310
|
+ List<SysDept> depts = deptService.selectDeptList(query);
|
|
|
311
|
+ if (depts == null)
|
|
|
312
|
+ {
|
|
|
313
|
+ return villages;
|
|
|
314
|
+ }
|
|
|
315
|
+ for (SysDept dept : depts)
|
|
|
316
|
+ {
|
|
|
317
|
+ if (isActiveDept(dept))
|
|
|
318
|
+ {
|
|
|
319
|
+ villages.add(dept);
|
|
|
320
|
+ }
|
|
|
321
|
+ }
|
|
|
322
|
+ villages.sort((a, b) -> Integer.compare(
|
|
|
323
|
+ a.getOrderNum() == null ? 0 : a.getOrderNum(),
|
|
|
324
|
+ b.getOrderNum() == null ? 0 : b.getOrderNum()));
|
|
|
325
|
+ return villages;
|
|
|
326
|
+ }
|
|
|
327
|
+
|
|
|
328
|
+ static boolean isActiveReportTown(SysDept dept)
|
|
|
329
|
+ {
|
|
|
330
|
+ if (!isActiveDept(dept))
|
|
|
331
|
+ {
|
|
|
332
|
+ return false;
|
|
|
333
|
+ }
|
|
|
334
|
+ if (!Long.valueOf(YakHerdInventoryRules.TOWN_PARENT_ID).equals(dept.getParentId()))
|
|
|
335
|
+ {
|
|
|
336
|
+ return false;
|
|
|
337
|
+ }
|
|
|
338
|
+ return dept.getOrderNum() != null && dept.getOrderNum() > YakHerdInventoryRules.TOWN_MIN_ORDER_NUM;
|
|
|
339
|
+ }
|
|
|
340
|
+
|
|
|
341
|
+ static boolean isActiveDept(SysDept dept)
|
|
|
342
|
+ {
|
|
|
343
|
+ return dept != null && "0".equals(dept.getDelFlag()) && "0".equals(dept.getStatus());
|
|
|
344
|
+ }
|
|
|
345
|
+
|
|
|
346
|
+ private static LoginUser tryGetLoginUser()
|
|
|
347
|
+ {
|
|
|
348
|
+ try
|
|
|
349
|
+ {
|
|
|
350
|
+ return SecurityUtils.getLoginUser();
|
|
|
351
|
+ }
|
|
|
352
|
+ catch (Exception e)
|
|
|
353
|
+ {
|
|
|
354
|
+ return null;
|
|
|
355
|
+ }
|
|
|
356
|
+ }
|
|
|
357
|
+
|
|
|
358
|
+ static final class ReportOrgScope
|
|
|
359
|
+ {
|
|
|
360
|
+ final Long townDeptId;
|
|
|
361
|
+ final Long villageDeptId;
|
|
|
362
|
+
|
|
|
363
|
+ private ReportOrgScope(Long townDeptId, Long villageDeptId)
|
|
|
364
|
+ {
|
|
|
365
|
+ this.townDeptId = townDeptId;
|
|
|
366
|
+ this.villageDeptId = villageDeptId;
|
|
|
367
|
+ }
|
|
|
368
|
+
|
|
|
369
|
+ static ReportOrgScope unrestricted()
|
|
|
370
|
+ {
|
|
|
371
|
+ return new ReportOrgScope(null, null);
|
|
|
372
|
+ }
|
|
|
373
|
+
|
|
|
374
|
+ static ReportOrgScope townOnly(Long townDeptId)
|
|
|
375
|
+ {
|
|
|
376
|
+ return new ReportOrgScope(townDeptId, null);
|
|
|
377
|
+ }
|
|
|
378
|
+
|
|
|
379
|
+ static ReportOrgScope villageOnly(Long townDeptId, Long villageDeptId)
|
|
|
380
|
+ {
|
|
|
381
|
+ return new ReportOrgScope(townDeptId, villageDeptId);
|
|
|
382
|
+ }
|
|
|
383
|
+ }
|
|
240
|
384
|
}
|