|
|
@ -11,6 +11,7 @@ import com.shuili.common.core.domain.entity.SysDept; |
|
|
|
import com.shuili.common.enums.BusinessType; |
|
|
|
import com.shuili.common.utils.FastDfsUtil; |
|
|
|
import com.shuili.common.utils.StringUtils; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import org.apache.commons.lang3.ArrayUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
@ -27,8 +28,7 @@ import java.util.List; |
|
|
|
*/ |
|
|
|
@RestController |
|
|
|
@RequestMapping("/system/dept") |
|
|
|
public class SysDeptController extends BaseController |
|
|
|
{ |
|
|
|
public class SysDeptController extends BaseController { |
|
|
|
@Autowired |
|
|
|
private SysDeptService deptService; |
|
|
|
|
|
|
@ -41,8 +41,7 @@ public class SysDeptController extends BaseController |
|
|
|
@SaCheckLogin |
|
|
|
@GetMapping("/list") |
|
|
|
@SaCheckPermission(value = "system:dept:list") |
|
|
|
public AjaxResult list(SysDept dept) |
|
|
|
{ |
|
|
|
public AjaxResult list(SysDept dept) { |
|
|
|
List<SysDept> depts = deptService.selectDeptList(dept); |
|
|
|
return AjaxResult.success(depts); |
|
|
|
} |
|
|
@ -53,16 +52,13 @@ public class SysDeptController extends BaseController |
|
|
|
@SaCheckLogin |
|
|
|
@GetMapping("/list/exclude/{deptId}") |
|
|
|
@SaCheckPermission(value = "system:dept:list") |
|
|
|
public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) String deptId) |
|
|
|
{ |
|
|
|
public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) String deptId) { |
|
|
|
List<SysDept> depts = deptService.selectDeptList(new SysDept()); |
|
|
|
Iterator<SysDept> it = depts.iterator(); |
|
|
|
while (it.hasNext()) |
|
|
|
{ |
|
|
|
while (it.hasNext()) { |
|
|
|
SysDept d = (SysDept) it.next(); |
|
|
|
if (d.getId().equals(deptId) |
|
|
|
|| ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")) |
|
|
|
{ |
|
|
|
|| ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")) { |
|
|
|
it.remove(); |
|
|
|
} |
|
|
|
} |
|
|
@ -75,8 +71,7 @@ public class SysDeptController extends BaseController |
|
|
|
@SaCheckLogin |
|
|
|
@GetMapping(value = "/{deptId}") |
|
|
|
@SaCheckPermission(value = "system:dept:query") |
|
|
|
public AjaxResult getInfo(@PathVariable String deptId) |
|
|
|
{ |
|
|
|
public AjaxResult getInfo(@PathVariable String deptId) { |
|
|
|
SysDept selectDeptById = deptService.get(deptId); |
|
|
|
return AjaxResult.success(selectDeptById); |
|
|
|
} |
|
|
@ -86,8 +81,7 @@ public class SysDeptController extends BaseController |
|
|
|
*/ |
|
|
|
@SaCheckLogin |
|
|
|
@PostMapping("/uploadLogo") |
|
|
|
public AjaxResult uploadLogo(@RequestParam("avatarfile") MultipartFile file) |
|
|
|
{ |
|
|
|
public AjaxResult uploadLogo(@RequestParam("avatarfile") MultipartFile file) { |
|
|
|
try { |
|
|
|
String uploadFile = fastUtil.uploadFile(file); |
|
|
|
// String uploadFile = "group1/M00/05/27/wKgBFGCvaeiAPWu5AADSPy2Q2g0276.jpg";
|
|
|
@ -104,8 +98,7 @@ public class SysDeptController extends BaseController |
|
|
|
* 获取部门下拉树列表 |
|
|
|
*/ |
|
|
|
@GetMapping("/treeselect") |
|
|
|
public AjaxResult treeselect(SysDept dept) |
|
|
|
{ |
|
|
|
public AjaxResult treeselect(SysDept dept) { |
|
|
|
List<SysDept> depts = deptService.selectDeptList(dept); |
|
|
|
return AjaxResult.success(deptService.buildDeptTreeSelect(depts)); |
|
|
|
} |
|
|
@ -114,8 +107,7 @@ public class SysDeptController extends BaseController |
|
|
|
* 加载对应角色部门列表树 |
|
|
|
*/ |
|
|
|
@GetMapping(value = "/roleDeptTreeselect/{roleId}") |
|
|
|
public AjaxResult roleDeptTreeselect(@PathVariable("roleId") String roleId) |
|
|
|
{ |
|
|
|
public AjaxResult roleDeptTreeselect(@PathVariable("roleId") String roleId) { |
|
|
|
List<SysDept> depts = deptService.selectDeptList(new SysDept()); |
|
|
|
AjaxResult ajax = AjaxResult.success(); |
|
|
|
ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId)); |
|
|
@ -130,10 +122,8 @@ public class SysDeptController extends BaseController |
|
|
|
@Log(title = "部门管理", businessType = BusinessType.INSERT) |
|
|
|
@SaCheckPermission(value = "system:dept:add") |
|
|
|
@PostMapping |
|
|
|
public AjaxResult add(@Validated @RequestBody SysDept dept) |
|
|
|
{ |
|
|
|
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) |
|
|
|
{ |
|
|
|
public AjaxResult add(@Validated @RequestBody SysDept dept) { |
|
|
|
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) { |
|
|
|
return AjaxResult.error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在"); |
|
|
|
} |
|
|
|
dept.setParentId("100"); |
|
|
@ -148,19 +138,14 @@ public class SysDeptController extends BaseController |
|
|
|
@Log(title = "部门管理", businessType = BusinessType.UPDATE) |
|
|
|
@SaCheckPermission(value = "system:dept:edit") |
|
|
|
@PutMapping |
|
|
|
public AjaxResult edit(@Validated @RequestBody SysDept dept) |
|
|
|
{ |
|
|
|
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) |
|
|
|
{ |
|
|
|
@ApiOperation("部门修改") |
|
|
|
public AjaxResult edit(@Validated @RequestBody SysDept dept) { |
|
|
|
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) { |
|
|
|
return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在"); |
|
|
|
} |
|
|
|
else if (dept.getParentId().equals(dept.getId())) |
|
|
|
{ |
|
|
|
} else if (dept.getParentId().equals(dept.getId())) { |
|
|
|
return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己"); |
|
|
|
} |
|
|
|
else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) |
|
|
|
&& deptService.selectNormalChildrenDeptById(dept.getId()) > 0) |
|
|
|
{ |
|
|
|
} else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) |
|
|
|
&& deptService.selectNormalChildrenDeptById(dept.getId()) > 0) { |
|
|
|
return AjaxResult.error("该部门包含未停用的子部门!"); |
|
|
|
} |
|
|
|
return toAjax(deptService.updateDept(dept) > 0); |
|
|
@ -173,14 +158,11 @@ public class SysDeptController extends BaseController |
|
|
|
@Log(title = "部门管理", businessType = BusinessType.DELETE) |
|
|
|
@SaCheckPermission(value = "system:dept:remove") |
|
|
|
@DeleteMapping("/{deptId}") |
|
|
|
public AjaxResult remove(@PathVariable String deptId) |
|
|
|
{ |
|
|
|
if (deptService.hasChildByDeptId(deptId)) |
|
|
|
{ |
|
|
|
public AjaxResult remove(@PathVariable String deptId) { |
|
|
|
if (deptService.hasChildByDeptId(deptId)) { |
|
|
|
return AjaxResult.error("存在下级部门,不允许删除"); |
|
|
|
} |
|
|
|
if (deptService.checkDeptExistUser(deptId)) |
|
|
|
{ |
|
|
|
if (deptService.checkDeptExistUser(deptId)) { |
|
|
|
return AjaxResult.error("部门存在用户,不允许删除"); |
|
|
|
} |
|
|
|
return toAjax(deptService.deleteDeptById(deptId) > 0); |
|
|
|