新增:新增系统管理/部门管理/查询列表功能,并将所有描述字段名从 notes 调整为 description,将部分前端方法名前缀从 query 调整为 get,以及去除部分冗余代码

This commit is contained in:
2023-01-23 19:00:47 +08:00
parent 6bd6d1eb39
commit bdf8eeb1b4
40 changed files with 820 additions and 42 deletions

View File

@@ -87,10 +87,10 @@ public class UserInfoVO implements Serializable {
private String avatar;
/**
* 备注
* 描述
*/
@Schema(description = "备注")
private String notes;
@Schema(description = "描述")
private String description;
/**
* 最后一次修改密码的时间

View File

@@ -0,0 +1,29 @@
/*
* 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.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import top.charles7c.cnadmin.system.model.entity.SysDept;
/**
* 部门 Mapper
*
* @author Charles7c
* @since 2023/1/22 17:56
*/
public interface DeptMapper extends BaseMapper<SysDept> {}

View File

@@ -0,0 +1,69 @@
/*
* 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.entity;
import lombok.Data;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
import top.charles7c.cnadmin.common.model.entity.BaseEntity;
/**
* 部门实体
*
* @author Charles7c
* @since 2023/1/22 13:50
*/
@Data
@TableName("sys_dept")
public class SysDept extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 部门 ID
*/
@TableId
private Long deptId;
/**
* 部门名称
*/
private String deptName;
/**
* 上级部门 ID
*/
private Long parentId;
/**
* 部门排序
*/
private Integer deptSort;
/**
* 描述
*/
private String description;
/**
* 状态1启用 2禁用
*/
private DisEnableStatusEnum status;
}

View File

@@ -40,7 +40,7 @@ public class SysUser extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 用户ID
* 用户 ID
*/
@TableId
private Long userId;
@@ -81,9 +81,9 @@ public class SysUser extends BaseEntity {
private String avatar;
/**
* 备注
* 描述
*/
private String notes;
private String description;
/**
* 状态1启用 2禁用

View File

@@ -0,0 +1,55 @@
/*
* 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.query;
import java.io.Serializable;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springdoc.api.annotations.ParameterObject;
import top.charles7c.cnadmin.common.annotation.Query;
/**
* 部门查询条件
*
* @author Charles7c
* @since 2023/1/22 17:52
*/
@Data
@ParameterObject
@Schema(description = "部门查询条件")
public class DeptQuery implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 部门名称
*/
@Schema(description = "部门名称")
@Query(type = Query.Type.INNER_LIKE)
private String deptName;
/**
* 状态1启用 2禁用
*/
@Schema(description = "状态1启用 2禁用")
@Query
private Integer status;
}

View File

@@ -0,0 +1,104 @@
/*
* 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.vo;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import lombok.Data;
import lombok.experimental.Accessors;
import io.swagger.v3.oas.annotations.media.Schema;
import com.fasterxml.jackson.annotation.JsonIgnore;
import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
/**
* 部门信息
*
* @author Charles7c
* @since 2023/1/22 13:53
*/
@Data
@Accessors(chain = true)
@Schema(description = "部门信息")
public class DeptVO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 部门 ID
*/
@Schema(description = "部门 ID")
private Long deptId;
/**
* 部门名称
*/
@Schema(description = "部门名称")
private String deptName;
/**
* 上级部门 ID
*/
@Schema(description = "上级部门 ID")
private Long parentId;
/**
* 部门排序
*/
@Schema(description = "部门排序")
private Integer deptSort;
/**
* 描述
*/
@Schema(description = "描述")
private String description;
/**
* 状态1启用 2禁用
*/
@Schema(description = "状态1启用 2禁用")
private DisEnableStatusEnum status;
/**
* 修改人
*/
@JsonIgnore
private Long updateUser;
/**
* 修改人昵称
*/
@Schema(description = "修改人昵称")
private String updateUserString;
/**
* 修改时间
*/
@Schema(description = "修改时间")
private LocalDateTime updateTime;
/**
* 子部门列表
*/
@Schema(description = "子部门列表")
private List<DeptVO> children;
}

View File

@@ -0,0 +1,40 @@
/*
* 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.service;
import java.util.List;
import top.charles7c.cnadmin.system.model.query.DeptQuery;
import top.charles7c.cnadmin.system.model.vo.DeptVO;
/**
* 部门业务接口
*
* @author Charles7c
* @since 2023/1/22 17:54
*/
public interface DeptService {
/**
* 查询列表
*
* @param query
* 查询条件
* @return 列表数据
*/
List<DeptVO> list(DeptQuery query);
}

View File

@@ -0,0 +1,137 @@
/*
* 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.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import top.charles7c.cnadmin.common.util.ExceptionUtils;
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.vo.DeptVO;
import top.charles7c.cnadmin.system.service.DeptService;
import top.charles7c.cnadmin.system.service.UserService;
/**
* 部门业务实现类
*
* @author Charles7c
* @since 2023/1/22 17:55
*/
@Service
@RequiredArgsConstructor
public class DeptServiceImpl implements DeptService {
private final DeptMapper deptMapper;
private final UserService userService;
@Override
public List<DeptVO> list(DeptQuery query) {
QueryWrapper<SysDept> queryWrapper = QueryHelper.build(query);
queryWrapper.lambda().orderByAsc(SysDept::getParentId).orderByAsc(SysDept::getDeptSort)
.orderByDesc(SysDept::getUpdateTime);
List<SysDept> list = deptMapper.selectList(queryWrapper);
List<DeptVO> voList = BeanUtil.copyToList(list, DeptVO.class);
voList.forEach(this::fill);
return buildTree(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) {
if (CollUtil.isEmpty(list)) {
return new ArrayList<>();
}
// 去重
List<DeptVO> deDuplicationDeptList = deDuplication(list);
return deDuplicationDeptList.stream().map(d -> d.setChildren(this.getChildren(d, list)))
.collect(Collectors.toList());
}
/**
* 数据去重(去除重复子部门列表)
*
* @param list
* 部门列表
* @return 去重后部门列表
*/
private List<DeptVO> deDuplication(List<DeptVO> list) {
List<DeptVO> deptList = new ArrayList<>();
for (DeptVO outerDept : list) {
boolean flag = true;
for (DeptVO innerDept : list) {
// 忽略重复子列表
if (innerDept.getDeptId().equals(outerDept.getParentId())) {
flag = false;
break;
}
}
if (flag) {
deptList.add(outerDept);
}
}
return deptList;
}
/**
* 获取指定部门的子部门列表
*
* @param dept
* 指定部门
* @param list
* 部门列表
* @return 子部门列表
*/
private List<DeptVO> getChildren(DeptVO dept, List<DeptVO> list) {
return list.stream().filter(d -> Objects.equals(d.getParentId(), dept.getDeptId()))
.map(d -> d.setChildren(this.getChildren(d, list))).collect(Collectors.toList());
}
}