dept
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.nl.system.controller.dept;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.modules.common.utils.PageUtil;
|
||||
import org.nl.system.service.dept.ISysDeptService;
|
||||
import org.nl.system.service.dept.dao.SysDept;
|
||||
import org.nl.system.service.dept.dto.DeptQuery;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-03-25
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "系统:部门管理")
|
||||
@RequestMapping("/api/dept")
|
||||
public class DeptController {
|
||||
|
||||
private final ISysDeptService deptService;
|
||||
private static final String ENTITY_NAME = "dept";
|
||||
|
||||
@ApiOperation("查询部门")
|
||||
@GetMapping
|
||||
public ResponseEntity<Object> query(DeptQuery query) throws Exception {
|
||||
List<SysDept> list = deptService.list(query.build());
|
||||
return new ResponseEntity<>(PageUtil.toPage(list, list.size()),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("查询部门")
|
||||
@GetMapping("/vo")
|
||||
public ResponseEntity<Object> queryvo(DeptQuery query) throws Exception {
|
||||
List<SysDept> sysDepts = deptService.queryVo(query);
|
||||
return new ResponseEntity<>(PageUtil.toPage(sysDepts, sysDepts.size()),HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("查询所有部门树")
|
||||
@GetMapping("/allTree")
|
||||
public ResponseEntity<Object> allTree(DeptQuery query) {
|
||||
return new ResponseEntity<>(deptService.buildTree(query),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("查询部门:根据ID获取同级与上级数据")
|
||||
@PostMapping("/superior")
|
||||
@SaCheckPermission(value = {"user:list", "dept:list"}, mode = SaMode.AND)
|
||||
public ResponseEntity<Object> getSuperior(@RequestBody List<Long> ids) {
|
||||
if (CollectionUtils.isEmpty(ids)){
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
return new ResponseEntity<>(deptService.getSuperior(ids),HttpStatus.OK);
|
||||
}
|
||||
//
|
||||
// @Log("新增部门")
|
||||
// @ApiOperation("新增部门")
|
||||
// @PostMapping
|
||||
//// @SaCheckPermission("dept:add")
|
||||
// public ResponseEntity<Object> create(@Validated @RequestBody Dept resources){
|
||||
//// deptService.create(resources);
|
||||
// return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
// }
|
||||
//
|
||||
// @Log("修改部门")
|
||||
// @ApiOperation("修改部门")
|
||||
// @PutMapping
|
||||
//// @SaCheckPermission("dept:edit")
|
||||
// public ResponseEntity<Object> update(@RequestBody Dept resources){
|
||||
// deptService.update(resources);
|
||||
// return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
// }
|
||||
//
|
||||
// @Log("删除部门")
|
||||
// @ApiOperation("删除部门")
|
||||
// @DeleteMapping
|
||||
//// @SaCheckPermission("dept:del")
|
||||
// public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
|
||||
// deptService.delete(ids);
|
||||
// return new ResponseEntity<>(HttpStatus.OK);
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.nl.system.controller.dept;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-15
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sysUserDept")
|
||||
public class SysUserDeptController {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.nl.system.service.dept;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.system.service.dept.dao.SysDept;
|
||||
import org.nl.system.service.dept.dto.DeptQuery;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-15
|
||||
*/
|
||||
public interface ISysDeptService extends IService<SysDept> {
|
||||
/**
|
||||
* 条件查询
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
List<SysDept> queryVo(DeptQuery query);
|
||||
|
||||
/**
|
||||
* 条件查询树结构
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> buildTree(DeptQuery query);
|
||||
Map<String, Object> getSuperior(List<Long> deptIds);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.nl.system.service.dept;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.system.service.dept.dao.SysUserDept;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-15
|
||||
*/
|
||||
public interface ISysUserDeptService extends IService<SysUserDept> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package org.nl.system.service.dept.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-15
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_dept")
|
||||
public class SysDept implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId(value = "dept_id", type = IdType.AUTO)
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 上级部门
|
||||
*/
|
||||
private Long pid;
|
||||
|
||||
/**
|
||||
* 子部门数目
|
||||
*/
|
||||
private Integer subCount;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer deptSort;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private String isUsed;
|
||||
|
||||
private Long createId;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private String createName;
|
||||
|
||||
private Long updateOptid;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
private String updateOptname;
|
||||
|
||||
/**
|
||||
* 创建日期
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private String updateTime;
|
||||
|
||||
/**
|
||||
* 部门编号
|
||||
*/
|
||||
private String code;
|
||||
|
||||
private String extId;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.nl.system.service.dept.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门表
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-15
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_user_dept")
|
||||
public class SysUserDept implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户标识
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 部门标识
|
||||
*/
|
||||
private Long deptId;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.nl.system.service.dept.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.nl.system.service.dept.dao.SysDept;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-15
|
||||
*/
|
||||
public interface SysDeptMapper extends BaseMapper<SysDept> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.system.service.dept.dao.mapper.SysDeptMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.nl.system.service.dept.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.nl.system.service.dept.dao.SysUserDept;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-15
|
||||
*/
|
||||
public interface SysUserDeptMapper extends BaseMapper<SysUserDept> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.system.service.dept.dao.mapper.SysUserDeptMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.nl.system.service.dept.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nl.common.domain.query.BaseQuery;
|
||||
import org.nl.common.domain.query.QParam;
|
||||
import org.nl.common.enums.QueryTEnum;
|
||||
import org.nl.system.service.dept.dao.SysDept;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2022/12/15 4:20 下午
|
||||
*/
|
||||
@Data
|
||||
public class DeptQuery extends BaseQuery<SysDept> {
|
||||
|
||||
private List<Long> deptIds;
|
||||
|
||||
private String name;
|
||||
|
||||
private String code;
|
||||
|
||||
private Long pid;
|
||||
|
||||
private Boolean pidIsNull;
|
||||
|
||||
@Override
|
||||
public void paramMapping() {
|
||||
super.doP.put("pidIsNull", QParam.builder().k(new String[]{"pid"}).type(QueryTEnum.LK).build());
|
||||
super.doP.put("deptIds", QParam.builder().k(new String[]{"deptId"}).type(QueryTEnum.IN).build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package org.nl.system.service.dept.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.modules.system.domain.Dept;
|
||||
import org.nl.modules.system.domain.vo.DeptVo;
|
||||
import org.nl.modules.system.service.dto.DeptTree;
|
||||
import org.nl.modules.system.util.CopyUtil;
|
||||
import org.nl.system.service.dept.ISysDeptService;
|
||||
import org.nl.system.service.dept.dao.SysDept;
|
||||
import org.nl.system.service.dept.dao.mapper.SysDeptMapper;
|
||||
import org.nl.system.service.dept.dto.DeptQuery;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-15
|
||||
*/
|
||||
@Service
|
||||
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements ISysDeptService {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> buildTree(DeptQuery query) {
|
||||
List<SysDept> list = this.list(query.build());
|
||||
List<DeptTree> deptTrees = CopyUtil.copyList(list, DeptTree.class);
|
||||
return this.buildTree(deptTrees);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getSuperior(List<Long> deptIds) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<String, Object> buildTree(List<DeptTree> deptDtos) {
|
||||
List<DeptTree> trees= new ArrayList<>();
|
||||
Set<DeptTree> depts = new LinkedHashSet<>();
|
||||
List<String> deptNames = deptDtos.stream().map(DeptTree::getName).collect(Collectors.toList());
|
||||
boolean isChild;
|
||||
for (DeptTree deptDTO : deptDtos) {
|
||||
isChild = false;
|
||||
if (deptDTO.getPid() == null) {
|
||||
trees.add(deptDTO);
|
||||
}
|
||||
for (DeptTree it : deptDtos) {
|
||||
if (it.getPid() != null && deptDTO.getDept_id().equals(it.getPid())) {
|
||||
isChild = true;
|
||||
if (deptDTO.getChildren() == null) {
|
||||
deptDTO.setChildren(new ArrayList<>());
|
||||
}
|
||||
deptDTO.getChildren().add(it);
|
||||
}
|
||||
}
|
||||
if (isChild) {
|
||||
depts.add(deptDTO);
|
||||
} else if (deptDTO.getPid() != null && !deptNames.contains(this.getById(deptDTO.getPid()).getName())) {
|
||||
depts.add(deptDTO);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("totalElements", deptDtos.size());
|
||||
map.put("content", CollectionUtil.isEmpty(trees) ? deptDtos : trees);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDept> queryVo(DeptQuery query) {
|
||||
Boolean hasChild = false;
|
||||
if (query.getPidIsNull() == null){
|
||||
if (query.getPid() == null){
|
||||
query.setPidIsNull(true);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(query.getName())||!query.getIsUsed()){
|
||||
query.setPidIsNull(null);
|
||||
hasChild=true;
|
||||
}
|
||||
}
|
||||
List<SysDept> list = this.list(query.build());
|
||||
List<DeptVo> deptVos = CopyUtil.copyList(list, DeptVo.class);
|
||||
if (hasChild){
|
||||
deptVos.forEach(a->{
|
||||
a.setHasChildren(false);
|
||||
});
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.nl.system.service.dept.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.nl.system.service.dept.ISysUserDeptService;
|
||||
import org.nl.system.service.dept.dao.SysUserDept;
|
||||
import org.nl.system.service.dept.dao.mapper.SysUserDeptMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 部门表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-15
|
||||
*/
|
||||
@Service
|
||||
public class SysUserDeptServiceImpl extends ServiceImpl<SysUserDeptMapper, SysUserDept> implements ISysUserDeptService {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user