Merge branch 'master' of http://121.40.234.130:8899/root/nl-sso-server
# Conflicts: # nladmin-ui/src/views/system/user/index.vue
This commit is contained in:
@@ -18,6 +18,8 @@ package org.nl.modules.system.rest;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -58,6 +60,16 @@ public class DeptController {
|
||||
return new ResponseEntity<>(PageUtil.toPage(deptDtos, deptDtos.size()),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("查询所有部门树")
|
||||
@GetMapping("/allTree")
|
||||
public ResponseEntity<Object> allTree(DeptQueryCriteria criteria) throws Exception {
|
||||
List<Dept> deptDtos = deptService.queryAll(criteria, true);
|
||||
JSONArray array = JSON.parseArray(JSON.toJSONString(deptDtos));
|
||||
List<DeptTree> deptTrees = array.toJavaList(DeptTree.class);
|
||||
Object o = deptService.buildTree(deptTrees);
|
||||
return new ResponseEntity<>(o,HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("查询部门:根据ID获取同级与上级数据")
|
||||
@PostMapping("/superior")
|
||||
@SaCheckPermission(value = {"user:list", "dept:list"}, mode = SaMode.AND)
|
||||
|
||||
@@ -85,25 +85,7 @@ public class UserController {
|
||||
@GetMapping
|
||||
@SaCheckPermission("user:list")
|
||||
public ResponseEntity<Object> query(UserQueryCriteria criteria, Pageable pageable){
|
||||
if (!ObjectUtils.isEmpty(criteria.getDeptId())) {
|
||||
criteria.getDeptIds().add(criteria.getDeptId());
|
||||
criteria.getDeptIds().addAll(deptService.getDeptChildren(deptService.findByPid(criteria.getDeptId())));
|
||||
}
|
||||
// 数据权限
|
||||
List<Long> dataScopes = dataService.getDeptIds(userService.findByName(SecurityUtils.getCurrentUsername()));
|
||||
// criteria.getDeptIds() 不为空并且数据权限不为空则取交集
|
||||
if (!CollectionUtils.isEmpty(criteria.getDeptIds()) && !CollectionUtils.isEmpty(dataScopes)){
|
||||
// 取交集
|
||||
criteria.getDeptIds().retainAll(dataScopes);
|
||||
if(!CollectionUtil.isEmpty(criteria.getDeptIds())){
|
||||
return new ResponseEntity<>(userService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
} else {
|
||||
// 否则取并集
|
||||
criteria.getDeptIds().addAll(dataScopes);
|
||||
return new ResponseEntity<>(userService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
return new ResponseEntity<>(PageUtil.toPage(null,0),HttpStatus.OK);
|
||||
return new ResponseEntity<>(userService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增用户")
|
||||
|
||||
@@ -72,6 +72,12 @@ public interface DeptService {
|
||||
*/
|
||||
void update(Dept resources);
|
||||
|
||||
/**
|
||||
* 查询pid所有子集
|
||||
*
|
||||
*/
|
||||
Set<Long> findPidChild(Long pid);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
|
||||
@@ -30,35 +30,12 @@ import java.util.Objects;
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class DeptTree extends BaseDTO implements Serializable {
|
||||
|
||||
public class DeptTree implements Serializable {
|
||||
|
||||
private Long Dept_id;
|
||||
|
||||
private Long pid;
|
||||
private String name;
|
||||
|
||||
private Boolean is_used;
|
||||
|
||||
private Integer dept_sort;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
private List<DeptTree> children;
|
||||
|
||||
private Long pid;
|
||||
|
||||
private Integer sub_count;
|
||||
|
||||
private String versionId;
|
||||
|
||||
public Boolean getHasChildren() {
|
||||
return sub_count > 0;
|
||||
}
|
||||
|
||||
public Boolean getLeaf() {
|
||||
return sub_count <= 0;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ public class UserQueryCriteria implements Serializable {
|
||||
@Query(blurry = "email,username,nickName")
|
||||
private String blurry;
|
||||
|
||||
private Boolean needAll;
|
||||
|
||||
@Query
|
||||
private Boolean is_used;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.utils.CacheKey;
|
||||
import org.nl.modules.common.utils.RedisUtils;
|
||||
@@ -98,6 +99,31 @@ public class DeptServiceImpl implements DeptService {
|
||||
JSONArray result = WQLObject.getWQLObject("sys_dept").query("pid ='" + pid + "'").getResultJSONArray(0);
|
||||
return result.toJavaList(Dept.class);
|
||||
}
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public Set<Long> findPidChild(Long pid) {
|
||||
if (pid!=null) {
|
||||
String sql = "SELECT\n" +
|
||||
" max(t3.childId) as deptIds \n" +
|
||||
" from\n" +
|
||||
" (\n" +
|
||||
" select *,\n" +
|
||||
" if( find_in_set(t1.pid, @p) > 0,@p := concat(@p,',',id),0 ) as childId\n" +
|
||||
" from\n" +
|
||||
" (select dept_id as id, pid from sys_dept t order by id) t1,\n" +
|
||||
" (select @p := '" + pid + "') t2\n" +
|
||||
" ) t3\n" +
|
||||
" where childId != '0'";
|
||||
List<Entity> list = Db.use((DataSource) SpringContextHolder.getBean("dataSource")).query(sql);
|
||||
System.out.println(list);
|
||||
Object deptIds = list.get(0).get("deptIds");
|
||||
if (deptIds != null && (deptIds instanceof String)) {
|
||||
String[] split = ((String) deptIds).split(",");
|
||||
return Arrays.stream(split).map(a -> Long.valueOf(a)).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
return new HashSet();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@@ -166,7 +192,7 @@ public class DeptServiceImpl implements DeptService {
|
||||
|
||||
@Override
|
||||
public Object buildTree(List<DeptTree> deptDtos) {
|
||||
Set<DeptTree> trees = new LinkedHashSet<>();
|
||||
List<DeptTree> trees= new ArrayList<>();
|
||||
Set<DeptTree> depts = new LinkedHashSet<>();
|
||||
List<String> deptNames = deptDtos.stream().map(DeptTree::getName).collect(Collectors.toList());
|
||||
boolean isChild;
|
||||
@@ -191,9 +217,6 @@ public class DeptServiceImpl implements DeptService {
|
||||
}
|
||||
}
|
||||
|
||||
if (CollectionUtil.isEmpty(trees)) {
|
||||
trees = depts;
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("totalElements", deptDtos.size());
|
||||
map.put("content", CollectionUtil.isEmpty(trees) ? deptDtos : trees);
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.nl.modules.common.utils.*;
|
||||
import org.nl.modules.common.utils.dto.CurrentUser;
|
||||
import org.nl.modules.security.service.OnlineUserService;
|
||||
import org.nl.modules.system.domain.User;
|
||||
import org.nl.modules.system.service.DeptService;
|
||||
import org.nl.modules.system.service.UserService;
|
||||
|
||||
import org.nl.modules.system.service.dto.UserQueryCriteria;
|
||||
@@ -66,11 +67,18 @@ public class UserServiceImpl implements UserService {
|
||||
private final FileProperties properties;
|
||||
private final RedisUtils redisUtils;
|
||||
private final OnlineUserService onlineUserService;
|
||||
private final DeptService deptService;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Object queryAll(UserQueryCriteria criteria, Pageable pageable) {
|
||||
if(criteria.getNeedAll()!=null && criteria.getNeedAll()){
|
||||
Set<Long> pidChild = deptService.findPidChild(criteria.getDeptId());
|
||||
criteria.getDeptIds().addAll(pidChild);
|
||||
criteria.getDeptIds().add(criteria.getDeptId());
|
||||
criteria.setDeptId(null);
|
||||
}
|
||||
JSONObject o = (JSONObject)JSON.toJSON(criteria);
|
||||
HashMap map = MapOf.of("user_id", MapUtil.getStr(o, "user_id")
|
||||
, "blurry", MapUtil.getStr(o, "blurry")
|
||||
|
||||
@@ -75,3 +75,20 @@
|
||||
ENDSELECT
|
||||
ENDPAGEQUERY
|
||||
ENDIF
|
||||
|
||||
IF 输入.flag = "2"
|
||||
PAGEQUERY
|
||||
SELECT
|
||||
max(t3.childId)
|
||||
from
|
||||
(
|
||||
select *,
|
||||
if( find_in_set(t1.pid, @p) > 0,@p := concat(@p,',',id),0 ) as childId
|
||||
from
|
||||
(select dept_id as id, pid from sys_dept t order by id) t1,
|
||||
(select @p := '输入.pid') t2
|
||||
) t3
|
||||
where childId != '0'
|
||||
ENDSELECT
|
||||
ENDPAGEQUERY
|
||||
ENDIF
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
## 表字段对应输入参数
|
||||
#################################################
|
||||
输入.flag TYPEAS s_string
|
||||
输入.deptIds TYPEAS s_string
|
||||
输入.deptId TYPEAS s_string
|
||||
输入.deptIds TYPEAS f_string
|
||||
输入.deptId TYPEAS f_string
|
||||
输入.id TYPEAS s_string
|
||||
输入.blurry TYPEAS s_string
|
||||
输入.is_used TYPEAS s_string
|
||||
@@ -60,7 +60,7 @@
|
||||
sys_user.id = 输入.id
|
||||
ENDOPTION
|
||||
OPTION 输入.deptIds <> ""
|
||||
sys_user.dept_id in 输入.deptIds
|
||||
sys_user_dept.dept_id in 输入.deptIds
|
||||
ENDOPTION
|
||||
OPTION 输入.blurry <> ""
|
||||
(email like 输入.blurry or username like 输入.blurry or nickName like 输入.blurry)
|
||||
@@ -69,7 +69,7 @@
|
||||
sys_user.is_used = 输入.enabled
|
||||
ENDOPTION
|
||||
OPTION 输入.deptId <> ""
|
||||
sys_user.dept_id = 输入.deptId
|
||||
sys_user_dept.dept_id = 输入.deptId
|
||||
ENDOPTION
|
||||
OPTION 输入.startTime <> ""
|
||||
sys_user.create_time >= 输入.startTime
|
||||
|
||||
@@ -8,6 +8,13 @@ export function getDepts(params) {
|
||||
})
|
||||
}
|
||||
|
||||
export function getDeptTreee() {
|
||||
return request({
|
||||
url: '/api/dept/allTree',
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
export function getDeptSuperior(ids) {
|
||||
const data = ids.length || ids.length === 0 ? ids : Array.of(ids)
|
||||
return request({
|
||||
|
||||
@@ -16,10 +16,7 @@
|
||||
</div>
|
||||
<el-tree
|
||||
:data="deptDatas"
|
||||
:load="getDeptDatas"
|
||||
:props="defaultProps"
|
||||
:expand-on-click-node="false"
|
||||
lazy
|
||||
@node-click="handleNodeClick"
|
||||
/>
|
||||
</el-col>
|
||||
@@ -200,7 +197,7 @@
|
||||
|
||||
<script>
|
||||
import crudUser from '@/api/system/user'
|
||||
import { getDepts, getDeptSuperior } from '@/api/system/dept'
|
||||
import { getDepts, getDeptSuperior, getDeptTreee } from '@/api/system/dept'
|
||||
import { getAll, getLevel } from '@/api/system/role'
|
||||
import CRUD, { crud, form, header, presenter } from '@crud/crud'
|
||||
import rrOperation from '@crud/RR.operation'
|
||||
@@ -239,7 +236,7 @@ export default {
|
||||
height: document.documentElement.clientHeight - 180 + 'px;',
|
||||
deptName: '', depts: [], deptDatas: [], level: 3, roles: [],
|
||||
roleDatas: [], // 多选时使用
|
||||
defaultProps: { children: 'children', label: 'name', isLeaf: 'leaf' },
|
||||
defaultProps: { children: 'children', label: 'name' },
|
||||
permission: {
|
||||
add: ['admin', 'user:add'],
|
||||
edit: ['admin', 'user:edit'],
|
||||
@@ -266,6 +263,9 @@ export default {
|
||||
'user'
|
||||
])
|
||||
},
|
||||
beforeMount() {
|
||||
this.getDeptTree()
|
||||
},
|
||||
created() {
|
||||
this.crud.msg.add = '新增成功'
|
||||
},
|
||||
@@ -351,7 +351,7 @@ export default {
|
||||
}
|
||||
console.log('params', params)
|
||||
setTimeout(() => {
|
||||
getDepts(params).then(res => {
|
||||
getDeptTreee().then(res => {
|
||||
console.log('res', res)
|
||||
if (resolve) {
|
||||
resolve(res.content)
|
||||
@@ -361,6 +361,15 @@ export default {
|
||||
})
|
||||
}, 100)
|
||||
},
|
||||
|
||||
getDeptTree() {
|
||||
setTimeout(() => {
|
||||
getDeptTreee().then(res => {
|
||||
debugger
|
||||
this.deptDatas = res.content
|
||||
})
|
||||
}, 100)
|
||||
},
|
||||
getDepts() {
|
||||
console.log('获取部门')
|
||||
getDepts({ is_used: 1 }).then(res => {
|
||||
@@ -409,11 +418,8 @@ export default {
|
||||
},
|
||||
// 切换部门
|
||||
handleNodeClick(data) {
|
||||
if (data.pid === 0) {
|
||||
this.query.deptId = null
|
||||
} else {
|
||||
this.query.deptId = data.id
|
||||
}
|
||||
this.query.deptId = data.dept_id
|
||||
this.query.needAll = true
|
||||
this.crud.toQuery()
|
||||
},
|
||||
// 改变状态
|
||||
|
||||
Reference in New Issue
Block a user