mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-28 04:57:17 +08:00
新增:新增系统管理/部门管理/新增功能
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* 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 top.charles7c.cnadmin.system.model.request;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
/**
|
||||
* 创建部门信息
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/1/24 00:21
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "创建部门信息")
|
||||
public class CreateDeptRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 上级部门 ID
|
||||
*/
|
||||
@Schema(description = "上级部门 ID", defaultValue = "0")
|
||||
private Long parentId = 0L;
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
@Schema(description = "部门名称")
|
||||
@NotBlank(message = "部门名称不能为空")
|
||||
private String deptName;
|
||||
|
||||
/**
|
||||
* 部门排序
|
||||
*/
|
||||
@Schema(description = "部门排序", defaultValue = "999")
|
||||
private Integer deptSort = 999;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Schema(description = "描述")
|
||||
@Size(max = 200, message = "描述长度不能超过 200 个字符")
|
||||
private String description;
|
||||
}
|
||||
@@ -18,7 +18,10 @@ package top.charles7c.cnadmin.system.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
|
||||
import top.charles7c.cnadmin.system.model.query.DeptQuery;
|
||||
import top.charles7c.cnadmin.system.model.request.CreateDeptRequest;
|
||||
import top.charles7c.cnadmin.system.model.vo.DeptVO;
|
||||
|
||||
/**
|
||||
@@ -37,4 +40,44 @@ public interface DeptService {
|
||||
* @return 列表数据
|
||||
*/
|
||||
List<DeptVO> list(DeptQuery query);
|
||||
|
||||
/**
|
||||
* 构建树
|
||||
*
|
||||
* @param list
|
||||
* 原始列表数据
|
||||
* @return 树列表
|
||||
*/
|
||||
List<DeptVO> buildListTree(List<DeptVO> list);
|
||||
|
||||
/**
|
||||
* 构建树
|
||||
*
|
||||
* @param list
|
||||
* 原始列表数据
|
||||
* @return 树列表
|
||||
*/
|
||||
List<Tree<Long>> buildTree(List<DeptVO> list);
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param request
|
||||
* 创建信息
|
||||
* @return 新增记录 ID
|
||||
*/
|
||||
Long create(CreateDeptRequest request);
|
||||
|
||||
/**
|
||||
* 检查部门名称是否存在
|
||||
*
|
||||
* @param deptName
|
||||
* 部门名称
|
||||
* @param parentId
|
||||
* 上级部门 ID
|
||||
* @param deptId
|
||||
* 部门 ID
|
||||
* @return 是否存在
|
||||
*/
|
||||
boolean checkDeptNameExist(String deptName, Long parentId, Long deptId);
|
||||
}
|
||||
|
||||
@@ -24,17 +24,23 @@ import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
|
||||
import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
|
||||
import top.charles7c.cnadmin.common.util.ExceptionUtils;
|
||||
import top.charles7c.cnadmin.common.util.TreeUtils;
|
||||
import top.charles7c.cnadmin.common.util.helper.QueryHelper;
|
||||
import top.charles7c.cnadmin.system.mapper.DeptMapper;
|
||||
import top.charles7c.cnadmin.system.model.entity.SysDept;
|
||||
import top.charles7c.cnadmin.system.model.query.DeptQuery;
|
||||
import top.charles7c.cnadmin.system.model.request.CreateDeptRequest;
|
||||
import top.charles7c.cnadmin.system.model.vo.DeptVO;
|
||||
import top.charles7c.cnadmin.system.service.DeptService;
|
||||
import top.charles7c.cnadmin.system.service.UserService;
|
||||
@@ -60,31 +66,11 @@ public class DeptServiceImpl implements DeptService {
|
||||
List<SysDept> list = deptMapper.selectList(queryWrapper);
|
||||
List<DeptVO> voList = BeanUtil.copyToList(list, DeptVO.class);
|
||||
voList.forEach(this::fill);
|
||||
return buildTree(voList);
|
||||
return voList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充数据
|
||||
*
|
||||
* @param vo
|
||||
* VO
|
||||
*/
|
||||
private void fill(DeptVO vo) {
|
||||
Long updateUser = vo.getUpdateUser();
|
||||
if (updateUser == null) {
|
||||
return;
|
||||
}
|
||||
vo.setUpdateUserString(ExceptionUtils.exToNull(() -> userService.getById(vo.getUpdateUser())).getNickname());
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建树
|
||||
*
|
||||
* @param list
|
||||
* 原始列表数据
|
||||
* @return 树列表
|
||||
*/
|
||||
private List<DeptVO> buildTree(List<DeptVO> list) {
|
||||
@Override
|
||||
public List<DeptVO> buildListTree(List<DeptVO> list) {
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@@ -134,4 +120,43 @@ public class DeptServiceImpl implements DeptService {
|
||||
return list.stream().filter(d -> Objects.equals(d.getParentId(), dept.getDeptId()))
|
||||
.map(d -> d.setChildren(this.getChildren(d, list))).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tree<Long>> buildTree(List<DeptVO> list) {
|
||||
return TreeUtils.build(list, (dept, tree) -> {
|
||||
tree.setId(dept.getDeptId());
|
||||
tree.setName(dept.getDeptName());
|
||||
tree.setParentId(dept.getParentId());
|
||||
tree.setWeight(dept.getDeptSort());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long create(CreateDeptRequest request) {
|
||||
SysDept sysDept = BeanUtil.copyProperties(request, SysDept.class);
|
||||
sysDept.setStatus(DisEnableStatusEnum.ENABLE);
|
||||
deptMapper.insert(sysDept);
|
||||
return sysDept.getDeptId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkDeptNameExist(String deptName, Long parentId, Long deptId) {
|
||||
return deptMapper.exists(Wrappers.<SysDept>lambdaQuery().eq(SysDept::getDeptName, deptName)
|
||||
.eq(SysDept::getParentId, parentId).ne(deptId != null, SysDept::getDeptId, deptId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充数据
|
||||
*
|
||||
* @param vo
|
||||
* VO
|
||||
*/
|
||||
private void fill(DeptVO vo) {
|
||||
Long updateUser = vo.getUpdateUser();
|
||||
if (updateUser == null) {
|
||||
return;
|
||||
}
|
||||
vo.setUpdateUserString(ExceptionUtils.exToNull(() -> userService.getById(vo.getUpdateUser())).getNickname());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user