105 lines
4.2 KiB
Java
105 lines
4.2 KiB
Java
package com.yunhai.userbase.controller.oapi;
|
|
|
|
import com.yunhai.platform.utils.model.BoaGroup;
|
|
import com.yunhai.userbase.common.validation.ValidationGroups;
|
|
import com.yunhai.userbase.config.Config;
|
|
import com.yunhai.userbase.model.sysgroup.SysGroupBatchRequest;
|
|
import com.yunhai.userbase.model.sysgroup.SysGroupRequest;
|
|
import com.yunhai.userbase.service.ISysGroupService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
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.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 组织架构开放接口:供其他业务服务经 yh-app-auth 签名调用({@code /oapi/group/...})。<br>
|
|
* <br>
|
|
* 路径复用 {@link Config#OPEN_API_PATH} 统一前缀,与基础平台 {@code DefaultUserCenterClient}
|
|
* 硬编码的契约严格一致:
|
|
* {@code GET /oapi/group/tree}、{@code /byId?groupId=&withSub=}、{@code /list?ids=&withSub=}。<br>
|
|
* 接口本身不做验签——签名由 {@code OpenApiAuthEnforceConfiguration} 在过滤器层强制要求,
|
|
* 未带 {@code X-App-Key/X-Timestamp/X-Signature} 的请求直接 401。
|
|
*/
|
|
@RestController
|
|
@RequestMapping(Config.OPEN_API_PATH + "group/")
|
|
public class GroupController {
|
|
|
|
@Autowired
|
|
private ISysGroupService sysGroupService;
|
|
|
|
/**
|
|
* 获取整个平台的组树(从根节点开始,children 递归嵌套全部后代)。
|
|
*/
|
|
@GetMapping("tree")
|
|
public BoaGroup tree() {
|
|
return sysGroupService.getGroups();
|
|
}
|
|
|
|
/**
|
|
* 获取单个组;withSub=true 时递归挂上全部子孙(整棵子树)。
|
|
*
|
|
* @param groupId 组ID(必填)
|
|
* @param withSub 是否展开子节点,缺省 false
|
|
* @return 组节点;不存在返回 null
|
|
*/
|
|
@GetMapping("byId")
|
|
public BoaGroup byId(@RequestParam("groupId") Integer groupId,
|
|
@RequestParam(value = "withSub", required = false) Boolean withSub) {
|
|
return sysGroupService.getGroupById(groupId, withSub);
|
|
}
|
|
|
|
/**
|
|
* 批量获取组;ids 逗号/空格分隔,按入参顺序返回,不存在的跳过。
|
|
*
|
|
* @param ids 组ID列表(逗号/空格分隔)
|
|
* @param withSub 是否展开子节点,缺省 false
|
|
* @return 组节点列表(按入参顺序;不存在的跳过)
|
|
*/
|
|
@GetMapping("list")
|
|
public List<BoaGroup> list(@RequestParam("ids") String ids,
|
|
@RequestParam(value = "withSub", required = false) Boolean withSub) {
|
|
return sysGroupService.getGroupList(ids, withSub);
|
|
}
|
|
|
|
/**
|
|
* 新增组:返回创建后的组节点(含 id)。<br>
|
|
* 层级类型约束、根节点保护等复用后台逻辑;鉴权由 OpenApiAuthEnforceConfiguration 在过滤器层强制签名。
|
|
*/
|
|
@PostMapping("add")
|
|
public BoaGroup add(@RequestBody @Validated(ValidationGroups.Create.class) SysGroupRequest request) {
|
|
return sysGroupService.add(request);
|
|
}
|
|
|
|
/**
|
|
* 编辑组(不含移动,移动请走 group/move 后台接口):返回更新后的组节点(含 id)。
|
|
*/
|
|
@PostMapping("edit/{id}")
|
|
public BoaGroup edit(@PathVariable Integer id,
|
|
@RequestBody @Validated(ValidationGroups.Update.class) SysGroupRequest request) {
|
|
return sysGroupService.edit(id, request);
|
|
}
|
|
|
|
/**
|
|
* 删除组:组下存在子组或用户时拒绝删除(根节点不可删)。无返回值。
|
|
*/
|
|
@PostMapping("delete/{id}")
|
|
public void delete(@PathVariable Integer id) {
|
|
sysGroupService.delete(id);
|
|
}
|
|
|
|
/**
|
|
* 批量新增子组:请求体 { pid, type, items:[{name},...] },返回创建后的组节点列表(均含 id)。
|
|
*/
|
|
@PostMapping("batchAdd")
|
|
public List<BoaGroup> batchAdd(@RequestBody @Validated SysGroupBatchRequest request) {
|
|
return sysGroupService.batchAdd(request);
|
|
}
|
|
}
|