| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package com.etotem.cfc.controller.admin;
- import com.etotem.cfc.common.Result;
- import com.etotem.cfc.entity.FamilyRelationType;
- import com.etotem.cfc.service.FamilyRelationTypeService;
- import com.etotem.cfc.util.ParamUtils;
- import io.swagger.v3.oas.annotations.Operation;
- import io.swagger.v3.oas.annotations.tags.Tag;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestAttribute;
- import org.springframework.web.bind.annotation.RestController;
- import javax.annotation.Resource;
- import java.util.List;
- import java.util.Map;
- /**
- * 平台运营·关系类型字典管理(SC-A-04 / 能力键 {@code admin.familyRelation.manage})。
- *
- * <p>契约载体:{@code /api/admin/family-relation/types} 提供关系类型字典的
- * 列表 / 新增 / 编辑 / 停用(GET/POST/PUT/DELETE 语义映射,项目统一 {@code @PostMapping})。</p>
- *
- * <p>权限:JwtInterceptor 拦截 {@code /api/admin/**}(TC-A-10-P),
- * 控制器内再按 {@code role=admin} 做角色门禁,非 admin 统一拒绝,不泄露后台数据。</p>
- */
- @Tag(name = "家庭关系类型管理", description = "平台运营·关系类型字典 CRUD(SC-A-04 / admin.familyRelation.manage)")
- @RestController
- @RequestMapping("/api/admin/family-relation")
- public class AdminFamilyRelationController {
- @Resource
- private FamilyRelationTypeService familyRelationTypeService;
- @Operation(summary = "关系类型字典列表")
- @PostMapping("/types/list")
- public Result<List<FamilyRelationType>> listTypes(@RequestAttribute("role") String role) {
- if (!"admin".equals(role)) {
- return Result.error("无权限");
- }
- return Result.success(familyRelationTypeService.listTypes());
- }
- @Operation(summary = "新增关系类型")
- @PostMapping("/types/save")
- public Result<FamilyRelationType> saveType(@RequestBody FamilyRelationType type,
- @RequestAttribute("role") String role) {
- if (!"admin".equals(role)) {
- return Result.error("无权限");
- }
- try {
- return Result.success(familyRelationTypeService.createType(type));
- } catch (IllegalArgumentException e) {
- return Result.badRequest(e.getMessage());
- }
- }
- @Operation(summary = "编辑关系类型")
- @PostMapping("/types/update")
- public Result<FamilyRelationType> updateType(@RequestBody FamilyRelationType type,
- @RequestAttribute("role") String role) {
- if (!"admin".equals(role)) {
- return Result.error("无权限");
- }
- try {
- boolean ok = familyRelationTypeService.updateType(type);
- if (!ok) {
- return Result.error("更新失败");
- }
- return Result.success(familyRelationTypeService.getById(type.getId()));
- } catch (IllegalArgumentException e) {
- return Result.badRequest(e.getMessage());
- }
- }
- @Operation(summary = "停用关系类型")
- @PostMapping("/types/disable")
- public Result<Void> disableType(@RequestBody Map<String, Object> body,
- @RequestAttribute("role") String role) {
- if (!"admin".equals(role)) {
- return Result.error("无权限");
- }
- Long id = ParamUtils.getLong(body == null ? null : body.get("id"));
- if (id == null) {
- return Result.badRequest("关系类型ID不能为空");
- }
- try {
- boolean ok = familyRelationTypeService.disableType(id);
- return ok ? Result.success(null) : Result.error("停用失败");
- } catch (IllegalArgumentException e) {
- return Result.badRequest(e.getMessage());
- }
- }
- }
|