AdminFamilyRelationController.java 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package com.etotem.cfc.controller.admin;
  2. import com.etotem.cfc.common.Result;
  3. import com.etotem.cfc.entity.FamilyRelationType;
  4. import com.etotem.cfc.service.FamilyRelationTypeService;
  5. import com.etotem.cfc.util.ParamUtils;
  6. import io.swagger.v3.oas.annotations.Operation;
  7. import io.swagger.v3.oas.annotations.tags.Tag;
  8. import org.springframework.web.bind.annotation.PostMapping;
  9. import org.springframework.web.bind.annotation.RequestBody;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RequestAttribute;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import javax.annotation.Resource;
  14. import java.util.List;
  15. import java.util.Map;
  16. /**
  17. * 平台运营·关系类型字典管理(SC-A-04 / 能力键 {@code admin.familyRelation.manage})。
  18. *
  19. * <p>契约载体:{@code /api/admin/family-relation/types} 提供关系类型字典的
  20. * 列表 / 新增 / 编辑 / 停用(GET/POST/PUT/DELETE 语义映射,项目统一 {@code @PostMapping})。</p>
  21. *
  22. * <p>权限:JwtInterceptor 拦截 {@code /api/admin/**}(TC-A-10-P),
  23. * 控制器内再按 {@code role=admin} 做角色门禁,非 admin 统一拒绝,不泄露后台数据。</p>
  24. */
  25. @Tag(name = "家庭关系类型管理", description = "平台运营·关系类型字典 CRUD(SC-A-04 / admin.familyRelation.manage)")
  26. @RestController
  27. @RequestMapping("/api/admin/family-relation")
  28. public class AdminFamilyRelationController {
  29. @Resource
  30. private FamilyRelationTypeService familyRelationTypeService;
  31. @Operation(summary = "关系类型字典列表")
  32. @PostMapping("/types/list")
  33. public Result<List<FamilyRelationType>> listTypes(@RequestAttribute("role") String role) {
  34. if (!"admin".equals(role)) {
  35. return Result.error("无权限");
  36. }
  37. return Result.success(familyRelationTypeService.listTypes());
  38. }
  39. @Operation(summary = "新增关系类型")
  40. @PostMapping("/types/save")
  41. public Result<FamilyRelationType> saveType(@RequestBody FamilyRelationType type,
  42. @RequestAttribute("role") String role) {
  43. if (!"admin".equals(role)) {
  44. return Result.error("无权限");
  45. }
  46. try {
  47. return Result.success(familyRelationTypeService.createType(type));
  48. } catch (IllegalArgumentException e) {
  49. return Result.badRequest(e.getMessage());
  50. }
  51. }
  52. @Operation(summary = "编辑关系类型")
  53. @PostMapping("/types/update")
  54. public Result<FamilyRelationType> updateType(@RequestBody FamilyRelationType type,
  55. @RequestAttribute("role") String role) {
  56. if (!"admin".equals(role)) {
  57. return Result.error("无权限");
  58. }
  59. try {
  60. boolean ok = familyRelationTypeService.updateType(type);
  61. if (!ok) {
  62. return Result.error("更新失败");
  63. }
  64. return Result.success(familyRelationTypeService.getById(type.getId()));
  65. } catch (IllegalArgumentException e) {
  66. return Result.badRequest(e.getMessage());
  67. }
  68. }
  69. @Operation(summary = "停用关系类型")
  70. @PostMapping("/types/disable")
  71. public Result<Void> disableType(@RequestBody Map<String, Object> body,
  72. @RequestAttribute("role") String role) {
  73. if (!"admin".equals(role)) {
  74. return Result.error("无权限");
  75. }
  76. Long id = ParamUtils.getLong(body == null ? null : body.get("id"));
  77. if (id == null) {
  78. return Result.badRequest("关系类型ID不能为空");
  79. }
  80. try {
  81. boolean ok = familyRelationTypeService.disableType(id);
  82. return ok ? Result.success(null) : Result.error("停用失败");
  83. } catch (IllegalArgumentException e) {
  84. return Result.badRequest(e.getMessage());
  85. }
  86. }
  87. }