mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-29 02:57:11 +08:00
优化:优化后端 CRUD 公共组件(移除 BaseService 中无用的默认实现,抽取 BaseRequest 基类来方便使用分组校验),并同步调整部门管理 API
This commit is contained in:
@@ -16,9 +16,9 @@
|
||||
|
||||
package top.charles7c.cnadmin.system.model.request;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Null;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -26,6 +26,9 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.BaseRequest;
|
||||
import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
|
||||
|
||||
/**
|
||||
* 创建或修改部门信息
|
||||
*
|
||||
@@ -34,15 +37,23 @@ import org.hibernate.validator.constraints.Length;
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "创建或修改部门信息")
|
||||
public class DeptRequest implements Serializable {
|
||||
public class DeptRequest extends BaseRequest {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 部门 ID
|
||||
*/
|
||||
@Schema(description = "部门 ID")
|
||||
@Null(message = "新增时,ID 必须为空", groups = Create.class)
|
||||
@NotNull(message = "修改时,ID 不能为空", groups = Update.class)
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 上级部门 ID
|
||||
*/
|
||||
@Schema(description = "上级部门 ID", defaultValue = "0")
|
||||
private Long parentId = 0L;
|
||||
@Schema(description = "上级部门 ID")
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
@@ -54,8 +65,8 @@ public class DeptRequest implements Serializable {
|
||||
/**
|
||||
* 部门排序
|
||||
*/
|
||||
@Schema(description = "部门排序", defaultValue = "999")
|
||||
private Integer deptSort = 999;
|
||||
@Schema(description = "部门排序")
|
||||
private Integer deptSort;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
@@ -63,4 +74,10 @@ public class DeptRequest implements Serializable {
|
||||
@Schema(description = "描述")
|
||||
@Length(max = 200, message = "描述长度不能超过 200 个字符")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 状态(1启用 2禁用)
|
||||
*/
|
||||
@Schema(description = "状态(1启用 2禁用)", type = "Integer", allowableValues = {"1", "2"})
|
||||
private DisEnableStatusEnum status;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.List;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.BaseService;
|
||||
import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
|
||||
import top.charles7c.cnadmin.system.model.query.DeptQuery;
|
||||
import top.charles7c.cnadmin.system.model.request.DeptRequest;
|
||||
import top.charles7c.cnadmin.system.model.vo.DeptVO;
|
||||
@@ -32,7 +31,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, DeptRequest> {
|
||||
public interface DeptService extends BaseService<DeptVO, DeptVO, DeptQuery, DeptRequest> {
|
||||
|
||||
/**
|
||||
* 构建树
|
||||
@@ -52,16 +51,6 @@ public interface DeptService extends BaseService<DeptVO, DeptVO, DeptQuery, Dept
|
||||
*/
|
||||
List<Tree<Long>> buildTree(List<DeptVO> list);
|
||||
|
||||
/**
|
||||
* 修改状态
|
||||
*
|
||||
* @param ids
|
||||
* ID 列表
|
||||
* @param status
|
||||
* 状态
|
||||
*/
|
||||
void updateStatus(List<Long> ids, DisEnableStatusEnum status);
|
||||
|
||||
/**
|
||||
* 检查部门名称是否存在
|
||||
*
|
||||
|
||||
@@ -55,8 +55,8 @@ import top.charles7c.cnadmin.system.service.UserService;
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeptServiceImpl extends
|
||||
BaseServiceImpl<DeptMapper, DeptDO, DeptVO, DeptVO, DeptQuery, DeptRequest, DeptRequest> implements DeptService {
|
||||
public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO, DeptVO, DeptQuery, DeptRequest>
|
||||
implements DeptService {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
@@ -112,24 +112,24 @@ public class DeptServiceImpl extends
|
||||
/**
|
||||
* 获取指定部门的子部门列表
|
||||
*
|
||||
* @param dept
|
||||
* @param deptVO
|
||||
* 指定部门
|
||||
* @param list
|
||||
* 部门列表
|
||||
* @return 子部门列表
|
||||
*/
|
||||
private List<DeptVO> getChildren(DeptVO dept, List<DeptVO> list) {
|
||||
return list.stream().filter(d -> Objects.equals(d.getParentId(), dept.getDeptId()))
|
||||
private List<DeptVO> getChildren(DeptVO deptVO, List<DeptVO> list) {
|
||||
return list.stream().filter(d -> Objects.equals(d.getParentId(), deptVO.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());
|
||||
return TreeUtils.build(list, (d, tree) -> {
|
||||
tree.setId(d.getDeptId());
|
||||
tree.setName(d.getDeptName());
|
||||
tree.setParentId(d.getParentId());
|
||||
tree.setWeight(d.getDeptSort());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -147,13 +147,6 @@ public class DeptServiceImpl extends
|
||||
return deptDO.getDeptId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateStatus(List<Long> ids, DisEnableStatusEnum status) {
|
||||
baseMapper.update(null,
|
||||
Wrappers.<DeptDO>lambdaUpdate().set(DeptDO::getStatus, status).in(DeptDO::getDeptId, ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(List<Long> ids) {
|
||||
@@ -178,7 +171,6 @@ public class DeptServiceImpl extends
|
||||
if (createUser == null) {
|
||||
return;
|
||||
}
|
||||
deptVO.setCreateUserString(
|
||||
ExceptionUtils.exToNull(() -> userService.getById(createUser)).getNickname());
|
||||
deptVO.setCreateUserString(ExceptionUtils.exToNull(() -> userService.getById(createUser)).getNickname());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user