package com.xunmei.system.controller; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.xunmei.common.core.domain.R; import com.xunmei.common.core.vo.IdNameVo; import com.xunmei.common.core.web.controller.BaseController; import com.xunmei.common.core.web.domain.AjaxResult; import com.xunmei.common.core.web.page.TableDataInfo; import com.xunmei.common.log.annotation.Log; import com.xunmei.common.log.enums.BusinessType; import com.xunmei.common.security.annotation.InnerAuth; import com.xunmei.common.security.annotation.RequiresPermissions; import com.xunmei.system.api.domain.SysOrg; import com.xunmei.system.mapper.SysOrgMapper; import com.xunmei.system.service.ISysOrgService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; /** * 【机构管理】Controller * * @author xunmei * @date 2023-08-10 */ @Api(tags = {"SysOrg"}) @RestController @RequestMapping("/org") public class SysOrgController extends BaseController { @Autowired private ISysOrgService sysOrgService; @Autowired private SysOrgMapper sysOrgMapper; /** * 查询【机构管理】列表 */ @ApiOperation(value = "查询SysOrg列表") @RequiresPermissions("system:org:list") @GetMapping("/list") public TableDataInfo list(SysOrg sysOrg) { return sysOrgService.selectPage(sysOrg); } /** * 获取【机构管理】详细信息 */ @ApiOperation(value = "获取SysOrg详细信息") @RequiresPermissions("system:org:query") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { return success(sysOrgService.selectSysOrgById(id)); } /** * 新增【机构管理】 */ @ApiOperation(value = "新增SysOrg") @RequiresPermissions("system:org:add") @Log(title = "【机构管理】", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody SysOrg sysOrg) { return toAjax(sysOrgService.insertSysOrg(sysOrg)); } /** * 修改【机构管理】 */ @ApiOperation(value = "修改SysOrg") @RequiresPermissions("system:org:edit") @Log(title = "【机构管理】", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody SysOrg sysOrg) { return toAjax(sysOrgService.updateSysOrg(sysOrg)); } /** * 删除【机构管理】 */ @ApiOperation(value = "删除SysOrg") @RequiresPermissions("system:org:remove") @Log(title = "【机构管理】", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(sysOrgService.deleteSysOrgByIds(ids)); } /** * 查询机构列表 */ @ApiOperation(value = "查询SysOrg列表") @InnerAuth @GetMapping("/list/nopage") public R> listNotPage(SysOrg sysOrg) { return R.ok(sysOrgService.selectSysOrgList(sysOrg)); } @ApiOperation(value = "查询SysOrg列表") @InnerAuth @GetMapping("/list/findAllOrg") public List findAllOrg() { return sysOrgService.list(); } /** * 查询机构列表 */ @ApiOperation(value = "批量保存同步机构数据") @InnerAuth @PostMapping("/sync/batch") public R batchSaveSyncSysOrgs(@RequestBody List sysOrgList) { //异步 sysOrgService.batchSaveOrUpdate(sysOrgList); return R.ok(true); } /** * 查询机构列表 */ @ApiOperation(value = "获取单个机构信息") @InnerAuth @GetMapping("/{orgId}") public SysOrg selectSysOrgById(@PathVariable("orgId") Long orgId) { return sysOrgService.getById(orgId); } /** * 通过父类查询子集合 */ @ApiOperation(value = "通过父类查询子集合") @InnerAuth @GetMapping("/selectSysOrgByParentId") public List selectSysOrgByParentId(Long id) { QueryWrapper queryWrapper = new QueryWrapper(); queryWrapper.eq("parent_id", id); return sysOrgMapper.selectList(queryWrapper); } @ApiOperation(value = "通过路径和机构类型查询") @InnerAuth @GetMapping("/selectSysOrgByPathAndType") public List selectSysOrgByPathAndType(String path,Integer type) { return sysOrgService.selectSysOrgByPathAndType(path,type); } /** * 通过父类查询子集合 */ @ApiOperation(value = "通过父类查询子集合") @InnerAuth @PostMapping("/selectSysOrgByParentIds") public List selectSysOrgByParentIds(@RequestBody List parentIds) { QueryWrapper queryWrapper = new QueryWrapper(); queryWrapper.in("parent_id", parentIds); return sysOrgMapper.selectList(queryWrapper); } @ApiOperation(value = "通过当前用户所在机构id查询机构列表") @InnerAuth @GetMapping("/selectOrgTreeListByCurOrgId") public List selectOrgTreeListByCurOrgId(Long id) { return sysOrgService.selectOrgTreeListByCurOrgId(id); } /** * 获取机构及其上级机构的id列表 * * @param orgId * @return */ @GetMapping("/getUpOrgs/{orgId}") public List getUpOrgs(@PathVariable("orgId") Long orgId) { SysOrg org=sysOrgMapper.selectById(orgId); if(ObjectUtil.isNull(org)){ return null; } String path = org.getPath(); if (ObjectUtil.isEmpty(path)) { return new ArrayList<>(); } List list = Arrays.stream(path.split("-")) .filter(p -> NumberUtil.isLong(p)) .map(p -> NumberUtil.parseLong(p)) .collect(Collectors.toList()); return list; } /** * 获取机构及父级机构的名称 * * @param ids * @return */ @PostMapping("/getParentNames") @InnerAuth public R> getParentName(@RequestBody List ids) { return R.ok(sysOrgMapper.getParentName(ids)); } }