| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.service.ISysDeptService; |
| | | import com.ruoyi.web.controller.tool.MiddlePlatformDataQuery; |
| | | |
| | | /** |
| | | * 部门信息 |
| | |
| | | @Autowired |
| | | private ISysDeptService deptService; |
| | | |
| | | @Autowired |
| | | private RuoYiConfig ruoyiConfig; |
| | | |
| | | /** |
| | | * 获取部门列表 |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:dept:list')") |
| | | @PreAuthorize("@ss.hasAnyPermi('system:dept:list,visitor:dept:view,visitor:employee:view')") |
| | | @GetMapping("/list") |
| | | public AjaxResult list(SysDept dept) |
| | | { |
| | | // 集群版对接中台时,部门来自中台组织树;本地 /system/dept/list 只作为前端兼容入口。 |
| | | if (ruoyiConfig.isConnectMiddlePlatform()) |
| | | { |
| | | try |
| | | { |
| | | return AjaxResult.success(MiddlePlatformDataQuery.deptList(dept)); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | return middlePlatformError(e); |
| | | } |
| | | } |
| | | List<SysDept> depts = deptService.selectDeptList(dept); |
| | | return AjaxResult.success(depts); |
| | | } |
| | |
| | | /** |
| | | * 查询部门列表(排除节点) |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:dept:list')") |
| | | @PreAuthorize("@ss.hasAnyPermi('system:dept:list,visitor:dept:view,visitor:employee:view')") |
| | | @GetMapping("/list/exclude/{deptId}") |
| | | public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) |
| | | { |
| | |
| | | /** |
| | | * 根据部门编号获取详细信息 |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:dept:query')") |
| | | @PreAuthorize("@ss.hasAnyPermi('system:dept:query,visitor:dept:view,visitor:dept:edit')") |
| | | @GetMapping(value = "/{deptId}") |
| | | public AjaxResult getInfo(@PathVariable Long deptId) |
| | | { |
| | | // 详情接口跟随中台组织数据源,编辑入口虽被隐藏,仍保证手动打开详情时数据一致。 |
| | | if (ruoyiConfig.isConnectMiddlePlatform()) |
| | | { |
| | | try |
| | | { |
| | | return AjaxResult.success(MiddlePlatformDataQuery.deptDetail(deptId)); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | return middlePlatformError(e); |
| | | } |
| | | } |
| | | deptService.checkDeptDataScope(deptId); |
| | | return AjaxResult.success(deptService.selectDeptById(deptId)); |
| | | } |
| | |
| | | /** |
| | | * 新增部门 |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:dept:add')") |
| | | @PreAuthorize("@ss.hasAnyPermi('system:dept:add,visitor:dept:add')") |
| | | @Log(title = "部门管理", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody SysDept dept) |
| | |
| | | /** |
| | | * 修改部门 |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:dept:edit')") |
| | | @PreAuthorize("@ss.hasAnyPermi('system:dept:edit,visitor:dept:edit')") |
| | | @Log(title = "部门管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody SysDept dept) |
| | |
| | | /** |
| | | * 删除部门 |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:dept:remove')") |
| | | @PreAuthorize("@ss.hasAnyPermi('system:dept:remove,visitor:dept:remove')") |
| | | @Log(title = "部门管理", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{deptId}") |
| | | public AjaxResult remove(@PathVariable Long deptId) |
| | |
| | | deptService.checkDeptDataScope(deptId); |
| | | return AjaxResult.success(deptService.deleteDeptById(deptId)); |
| | | } |
| | | |
| | | /** |
| | | * 目的:中台查询异常时返回统一业务错误,避免异常栈直接暴露给前端。 |
| | | */ |
| | | private AjaxResult middlePlatformError(IOException e) |
| | | { |
| | | return error("中台数据查询失败:" + e.getMessage()); |
| | | } |
| | | } |