修改上级部门(选择项排除本身和下级)

dep_wangsr
RuoYi 5 years ago committed by Limy
parent 571652229c
commit ce3dab776b

@ -153,11 +153,16 @@ public class SysDeptController extends BaseController
/** /**
* *
*
* @param deptId ID
* @param excludeId ID
*/ */
@GetMapping("/selectDeptTree/{deptId}") @GetMapping(value = { "/selectDeptTree/{deptId}", "/selectDeptTree/{deptId}/{excludeId}" })
public String selectDeptTree(@PathVariable("deptId") Long deptId, ModelMap mmap) public String selectDeptTree(@PathVariable("deptId") Long deptId,
@PathVariable(value = "excludeId", required = false) String excludeId, ModelMap mmap)
{ {
mmap.put("dept", deptService.selectDeptById(deptId)); mmap.put("dept", deptService.selectDeptById(deptId));
mmap.put("excludeId", excludeId);
return prefix + "/tree"; return prefix + "/tree";
} }
@ -172,6 +177,19 @@ public class SysDeptController extends BaseController
return ztrees; return ztrees;
} }
/**
*
*/
@GetMapping("/treeData/{excludeId}")
@ResponseBody
public List<Ztree> treeDataExcludeChild(@PathVariable(value = "excludeId", required = false) Long excludeId)
{
SysDept dept = new SysDept();
dept.setDeptId(excludeId);
List<Ztree> ztrees = deptService.selectDeptTreeExcludeChild(dept);
return ztrees;
}
/** /**
* *
*/ */

@ -113,11 +113,12 @@
/*部门管理-修改-选择部门树*/ /*部门管理-修改-选择部门树*/
function selectDeptTree() { function selectDeptTree() {
var deptId = $("#treeId").val(); var deptId = $("#treeId").val();
var excludeId = $("input[name='deptId']").val();
if(deptId > 0) { if(deptId > 0) {
var options = { var options = {
title: '部门选择', title: '部门选择',
width: "380", width: "380",
url: prefix + "/selectDeptTree/" + $("#treeId").val(), url: prefix + "/selectDeptTree/" + $("#treeId").val() + "/" + excludeId,
callBack: doSubmit callBack: doSubmit
}; };
$.modal.openOptions(options); $.modal.openOptions(options);

@ -28,8 +28,11 @@
<th:block th:include="include :: footer" /> <th:block th:include="include :: footer" />
<th:block th:include="include :: ztree-js" /> <th:block th:include="include :: ztree-js" />
<script th:inline="javascript"> <script th:inline="javascript">
var prefix = ctx + "system/dept"
var deptId = [[${deptId}]];
var excludeId = [[${excludeId}]];
$(function() { $(function() {
var url = ctx + "system/dept/treeData"; var url = $.common.isEmpty(excludeId) ? prefix + "/treeData": prefix + "/treeData/" + excludeId;
var options = { var options = {
url: url, url: url,
expandLevel: 2, expandLevel: 2,

@ -28,6 +28,14 @@ public interface ISysDeptService
*/ */
public List<Ztree> selectDeptTree(SysDept dept); public List<Ztree> selectDeptTree(SysDept dept);
/**
*
*
* @param dept
* @return
*/
public List<Ztree> selectDeptTreeExcludeChild(SysDept dept);
/** /**
* ID * ID
* *

@ -1,7 +1,9 @@
package com.ruoyi.system.service.impl; package com.ruoyi.system.service.impl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -54,6 +56,32 @@ public class SysDeptServiceImpl implements ISysDeptService
return ztrees; return ztrees;
} }
/**
*
*
* @param deptId ID
* @return
*/
@Override
@DataScope(deptAlias = "d")
public List<Ztree> selectDeptTreeExcludeChild(SysDept dept)
{
Long deptId = dept.getDeptId();
List<SysDept> deptList = deptMapper.selectDeptList(dept);
Iterator<SysDept> it = deptList.iterator();
while (it.hasNext())
{
SysDept d = (SysDept) it.next();
if (d.getDeptId().intValue() == deptId
|| ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""))
{
it.remove();
}
}
List<Ztree> ztrees = initZtree(deptList);
return ztrees;
}
/** /**
* ID * ID
* *

Loading…
Cancel
Save