mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-11-04 10:57:10 +08:00 
			
		
		
		
	重构:重构部门管理前端代码;新增修改部门、批量删除部门、查看部门详情功能(后端主要基于 CRUD 通用组件提供 API)
This commit is contained in:
		@@ -0,0 +1,75 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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 lombok.Data;
 | 
			
		||||
import lombok.experimental.Accessors;
 | 
			
		||||
 | 
			
		||||
import io.swagger.v3.oas.annotations.media.Schema;
 | 
			
		||||
 | 
			
		||||
import top.charles7c.cnadmin.common.base.BaseDetailVO;
 | 
			
		||||
import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 部门详情信息
 | 
			
		||||
 *
 | 
			
		||||
 * @author Charles7c
 | 
			
		||||
 * @since 2023/2/1 22:19
 | 
			
		||||
 */
 | 
			
		||||
@Data
 | 
			
		||||
@Accessors(chain = true)
 | 
			
		||||
@Schema(description = "部门详情信息")
 | 
			
		||||
public class DeptDetailVO extends BaseDetailVO {
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
}
 | 
			
		||||
@@ -23,6 +23,7 @@ import cn.hutool.core.lang.tree.Tree;
 | 
			
		||||
import top.charles7c.cnadmin.common.base.BaseService;
 | 
			
		||||
import top.charles7c.cnadmin.system.model.query.DeptQuery;
 | 
			
		||||
import top.charles7c.cnadmin.system.model.request.DeptRequest;
 | 
			
		||||
import top.charles7c.cnadmin.system.model.vo.DeptDetailVO;
 | 
			
		||||
import top.charles7c.cnadmin.system.model.vo.DeptVO;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -31,7 +32,7 @@ import top.charles7c.cnadmin.system.model.vo.DeptVO;
 | 
			
		||||
 * @author Charles7c
 | 
			
		||||
 * @since 2023/1/22 17:54
 | 
			
		||||
 */
 | 
			
		||||
public interface DeptService extends BaseService<DeptVO, DeptVO, DeptQuery, DeptRequest> {
 | 
			
		||||
public interface DeptService extends BaseService<DeptVO, DeptDetailVO, DeptQuery, DeptRequest> {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 构建树
 | 
			
		||||
 
 | 
			
		||||
@@ -33,7 +33,9 @@ import cn.hutool.core.bean.BeanUtil;
 | 
			
		||||
import cn.hutool.core.collection.CollUtil;
 | 
			
		||||
import cn.hutool.core.lang.tree.Tree;
 | 
			
		||||
 | 
			
		||||
import top.charles7c.cnadmin.common.base.BaseDetailVO;
 | 
			
		||||
import top.charles7c.cnadmin.common.base.BaseServiceImpl;
 | 
			
		||||
import top.charles7c.cnadmin.common.base.BaseVO;
 | 
			
		||||
import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
 | 
			
		||||
import top.charles7c.cnadmin.common.util.ExceptionUtils;
 | 
			
		||||
import top.charles7c.cnadmin.common.util.TreeUtils;
 | 
			
		||||
@@ -43,6 +45,7 @@ import top.charles7c.cnadmin.system.mapper.DeptMapper;
 | 
			
		||||
import top.charles7c.cnadmin.system.model.entity.DeptDO;
 | 
			
		||||
import top.charles7c.cnadmin.system.model.query.DeptQuery;
 | 
			
		||||
import top.charles7c.cnadmin.system.model.request.DeptRequest;
 | 
			
		||||
import top.charles7c.cnadmin.system.model.vo.DeptDetailVO;
 | 
			
		||||
import top.charles7c.cnadmin.system.model.vo.DeptVO;
 | 
			
		||||
import top.charles7c.cnadmin.system.service.DeptService;
 | 
			
		||||
import top.charles7c.cnadmin.system.service.UserService;
 | 
			
		||||
@@ -55,7 +58,7 @@ import top.charles7c.cnadmin.system.service.UserService;
 | 
			
		||||
 */
 | 
			
		||||
@Service
 | 
			
		||||
@RequiredArgsConstructor
 | 
			
		||||
public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO, DeptVO, DeptQuery, DeptRequest>
 | 
			
		||||
public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO, DeptDetailVO, DeptQuery, DeptRequest>
 | 
			
		||||
    implements DeptService {
 | 
			
		||||
 | 
			
		||||
    private final UserService userService;
 | 
			
		||||
@@ -71,6 +74,34 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
 | 
			
		||||
        return list;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public DeptDetailVO get(Long id) {
 | 
			
		||||
        DeptDetailVO deptDetailVO = super.get(id);
 | 
			
		||||
        this.fillDetail(deptDetailVO);
 | 
			
		||||
        return deptDetailVO;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional(rollbackFor = Exception.class)
 | 
			
		||||
    public Long create(DeptRequest request) {
 | 
			
		||||
        String deptName = request.getDeptName();
 | 
			
		||||
        boolean isExist = this.checkDeptNameExist(deptName, request.getParentId(), null);
 | 
			
		||||
        CheckUtils.throwIf(() -> isExist, String.format("新增失败,'%s'已存在", deptName));
 | 
			
		||||
 | 
			
		||||
        // 保存部门信息
 | 
			
		||||
        DeptDO deptDO = BeanUtil.copyProperties(request, DeptDO.class);
 | 
			
		||||
        deptDO.setStatus(DisEnableStatusEnum.ENABLE);
 | 
			
		||||
        baseMapper.insert(deptDO);
 | 
			
		||||
        return deptDO.getDeptId();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional(rollbackFor = Exception.class)
 | 
			
		||||
    public void delete(List<Long> ids) {
 | 
			
		||||
        super.delete(ids);
 | 
			
		||||
        baseMapper.delete(Wrappers.<DeptDO>lambdaQuery().in(DeptDO::getParentId, ids));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<DeptVO> buildListTree(List<DeptVO> list) {
 | 
			
		||||
        if (CollUtil.isEmpty(list)) {
 | 
			
		||||
@@ -133,27 +164,6 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional(rollbackFor = Exception.class)
 | 
			
		||||
    public Long create(DeptRequest request) {
 | 
			
		||||
        String deptName = request.getDeptName();
 | 
			
		||||
        boolean isExist = this.checkDeptNameExist(deptName, request.getParentId(), null);
 | 
			
		||||
        CheckUtils.throwIf(() -> isExist, String.format("新增失败,'%s'已存在", deptName));
 | 
			
		||||
 | 
			
		||||
        // 保存部门信息
 | 
			
		||||
        DeptDO deptDO = BeanUtil.copyProperties(request, DeptDO.class);
 | 
			
		||||
        deptDO.setStatus(DisEnableStatusEnum.ENABLE);
 | 
			
		||||
        baseMapper.insert(deptDO);
 | 
			
		||||
        return deptDO.getDeptId();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional(rollbackFor = Exception.class)
 | 
			
		||||
    public void delete(List<Long> ids) {
 | 
			
		||||
        super.delete(ids);
 | 
			
		||||
        baseMapper.delete(Wrappers.<DeptDO>lambdaQuery().in(DeptDO::getParentId, ids));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean checkDeptNameExist(String deptName, Long parentId, Long deptId) {
 | 
			
		||||
        return baseMapper.exists(Wrappers.<DeptDO>lambdaQuery().eq(DeptDO::getDeptName, deptName)
 | 
			
		||||
@@ -163,14 +173,30 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
 | 
			
		||||
    /**
 | 
			
		||||
     * 填充数据
 | 
			
		||||
     *
 | 
			
		||||
     * @param deptVO
 | 
			
		||||
     *            部门信息
 | 
			
		||||
     * @param baseVO
 | 
			
		||||
     *            待填充列表信息
 | 
			
		||||
     */
 | 
			
		||||
    private void fill(DeptVO deptVO) {
 | 
			
		||||
        Long createUser = deptVO.getCreateUser();
 | 
			
		||||
    private void fill(BaseVO baseVO) {
 | 
			
		||||
        Long createUser = baseVO.getCreateUser();
 | 
			
		||||
        if (createUser == null) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        deptVO.setCreateUserString(ExceptionUtils.exToNull(() -> userService.getById(createUser)).getNickname());
 | 
			
		||||
        baseVO.setCreateUserString(ExceptionUtils.exToNull(() -> userService.getById(createUser)).getNickname());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 填充详情数据
 | 
			
		||||
     *
 | 
			
		||||
     * @param baseDetailVO
 | 
			
		||||
     *            待填充详情信息
 | 
			
		||||
     */
 | 
			
		||||
    private void fillDetail(BaseDetailVO baseDetailVO) {
 | 
			
		||||
        this.fill(baseDetailVO);
 | 
			
		||||
 | 
			
		||||
        Long updateUser = baseDetailVO.getUpdateUser();
 | 
			
		||||
        if (updateUser == null) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        baseDetailVO.setUpdateUserString(ExceptionUtils.exToNull(() -> userService.getById(updateUser)).getNickname());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user