| | |
| | |
|
| | | import java.util.List;
|
| | |
|
| | | import com.ruoyi.common.constant.HttpStatus; |
| | | import lombok.AllArgsConstructor;
|
| | | import org.apache.commons.lang3.ArrayUtils;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.security.access.prepost.PreAuthorize;
|
| | | import org.springframework.validation.annotation.Validated;
|
| | | import org.springframework.web.bind.annotation.DeleteMapping;
|
| | |
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.project.system.domain.SysDept;
|
| | | import com.ruoyi.project.system.service.ISysDeptService;
|
| | |
|
| | |
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('system:dept:list')")
|
| | | @GetMapping("/list")
|
| | | public AjaxResult list(SysDept dept)
|
| | | public R<?> list(SysDept dept) |
| | | {
|
| | | List<SysDept> depts = deptService.selectDeptList(dept);
|
| | | return success(depts);
|
| | | return R.ok(depts); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('system:dept:list')")
|
| | | @GetMapping("/list/exclude/{deptId}")
|
| | | public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
|
| | | public R<?> excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) |
| | | {
|
| | | List<SysDept> depts = deptService.selectDeptList(new SysDept());
|
| | | depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""));
|
| | | return success(depts);
|
| | | return R.ok(depts); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('system:dept:query')")
|
| | | @GetMapping(value = "/{deptId}")
|
| | | public AjaxResult getInfo(@PathVariable Long deptId)
|
| | | public R<?> getInfo(@PathVariable Long deptId) |
| | | {
|
| | | deptService.checkDeptDataScope(deptId);
|
| | | return success(deptService.selectDeptById(deptId));
|
| | | return R.ok(deptService.selectDeptById(deptId)); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @PreAuthorize("@ss.hasPermi('system:dept:add')")
|
| | | @Log(title = "部门管理", businessType = BusinessType.INSERT)
|
| | | @PostMapping
|
| | | public AjaxResult add(@Validated @RequestBody SysDept dept)
|
| | | public R<?> add(@Validated @RequestBody SysDept dept) |
| | | {
|
| | | if (!deptService.checkDeptNameUnique(dept))
|
| | | {
|
| | | return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
| | | return R.fail("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在"); |
| | | }
|
| | | dept.setCreateBy(getUsername());
|
| | | return toAjax(deptService.insertDept(dept));
|
| | | deptService.insertDept(dept); |
| | | return R.ok(); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @PreAuthorize("@ss.hasPermi('system:dept:edit')")
|
| | | @Log(title = "部门管理", businessType = BusinessType.UPDATE)
|
| | | @PutMapping
|
| | | public AjaxResult edit(@Validated @RequestBody SysDept dept)
|
| | | public R<?> edit(@Validated @RequestBody SysDept dept) |
| | | {
|
| | | Long deptId = dept.getDeptId();
|
| | | deptService.checkDeptDataScope(deptId);
|
| | | if (!deptService.checkDeptNameUnique(dept))
|
| | | {
|
| | | return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
| | | return R.fail("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在"); |
| | | }
|
| | | else if (dept.getParentId().equals(deptId))
|
| | | {
|
| | | return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
|
| | | return R.fail("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己"); |
| | | }
|
| | | else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0)
|
| | | {
|
| | | return error("该部门包含未停用的子部门!");
|
| | | return R.fail("该部门包含未停用的子部门!"); |
| | | }
|
| | | dept.setUpdateBy(getUsername());
|
| | | return toAjax(deptService.updateDept(dept));
|
| | | deptService.updateDept(dept); |
| | | return R.ok(); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @PreAuthorize("@ss.hasPermi('system:dept:remove')")
|
| | | @Log(title = "部门管理", businessType = BusinessType.DELETE)
|
| | | @DeleteMapping("/{deptId}")
|
| | | public AjaxResult remove(@PathVariable Long deptId)
|
| | | public R<?> remove(@PathVariable Long deptId) |
| | | {
|
| | | if (deptService.hasChildByDeptId(deptId))
|
| | | {
|
| | | return warn("存在下级部门,不允许删除");
|
| | | return R.fail(HttpStatus.WARN, "存在下级部门,不允许删除"); |
| | | }
|
| | | if (deptService.checkDeptExistUser(deptId))
|
| | | {
|
| | | return warn("部门存在用户,不允许删除");
|
| | | return R.fail(HttpStatus.WARN, "部门存在用户,不允许删除"); |
| | | }
|
| | | deptService.checkDeptDataScope(deptId);
|
| | | return toAjax(deptService.deleteDeptById(deptId));
|
| | | deptService.deleteDeptById(deptId); |
| | | return R.ok(); |
| | | }
|
| | | }
|