优化:优化后端 CRUD 公共组件(移除 BaseService 中无用的默认实现,抽取 BaseRequest 基类来方便使用分组校验),并同步调整部门管理 API
This commit is contained in:
parent
2c6bef91e8
commit
83b01c2e4f
@ -37,7 +37,7 @@ public @interface CrudRequestMapping {
|
|||||||
/**
|
/**
|
||||||
* API 列表
|
* API 列表
|
||||||
*/
|
*/
|
||||||
Api[] api() default Api.ALL;
|
Api[] api() default {Api.PAGE, Api.DETAIL, Api.CREATE, Api.UPDATE, Api.DELETE};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API 枚举
|
* API 枚举
|
||||||
|
@ -44,14 +44,12 @@ import top.charles7c.cnadmin.common.model.vo.R;
|
|||||||
* @param <Q>
|
* @param <Q>
|
||||||
* 查询条件
|
* 查询条件
|
||||||
* @param <C>
|
* @param <C>
|
||||||
* 创建信息
|
* 创建或修改信息
|
||||||
* @param <U>
|
|
||||||
* 修改信息
|
|
||||||
* @author Charles7c
|
* @author Charles7c
|
||||||
* @since 2023/1/26 10:45
|
* @since 2023/1/26 10:45
|
||||||
*/
|
*/
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public abstract class BaseController<S extends BaseService<V, D, Q, C, U>, V, D, Q, C, U> {
|
public abstract class BaseController<S extends BaseService<V, D, Q, C>, V, D, Q, C extends BaseRequest> {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected S baseService;
|
protected S baseService;
|
||||||
@ -63,9 +61,10 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C, U>, V, D,
|
|||||||
* 查询条件
|
* 查询条件
|
||||||
* @param pageQuery
|
* @param pageQuery
|
||||||
* 分页查询条件
|
* 分页查询条件
|
||||||
* @return 分页列表信息
|
* @return 分页信息
|
||||||
*/
|
*/
|
||||||
@Operation(summary = "分页查询列表")
|
@Operation(summary = "分页查询列表")
|
||||||
|
@ResponseBody
|
||||||
@GetMapping
|
@GetMapping
|
||||||
protected R<PageDataVO<V>> page(@Validated Q query, @Validated PageQuery pageQuery) {
|
protected R<PageDataVO<V>> page(@Validated Q query, @Validated PageQuery pageQuery) {
|
||||||
PageDataVO<V> pageDataVO = baseService.page(query, pageQuery);
|
PageDataVO<V> pageDataVO = baseService.page(query, pageQuery);
|
||||||
@ -80,6 +79,7 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C, U>, V, D,
|
|||||||
* @return 列表信息
|
* @return 列表信息
|
||||||
*/
|
*/
|
||||||
@Operation(summary = "查询列表")
|
@Operation(summary = "查询列表")
|
||||||
|
@ResponseBody
|
||||||
@GetMapping("/all")
|
@GetMapping("/all")
|
||||||
protected R<List<V>> list(@Validated Q query) {
|
protected R<List<V>> list(@Validated Q query) {
|
||||||
List<V> list = baseService.list(query);
|
List<V> list = baseService.list(query);
|
||||||
@ -95,6 +95,7 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C, U>, V, D,
|
|||||||
*/
|
*/
|
||||||
@Operation(summary = "查看详情")
|
@Operation(summary = "查看详情")
|
||||||
@Parameter(name = "id", description = "ID", in = ParameterIn.PATH)
|
@Parameter(name = "id", description = "ID", in = ParameterIn.PATH)
|
||||||
|
@ResponseBody
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
protected R<D> detail(@PathVariable Long id) {
|
protected R<D> detail(@PathVariable Long id) {
|
||||||
D detail = baseService.detail(id);
|
D detail = baseService.detail(id);
|
||||||
@ -109,8 +110,9 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C, U>, V, D,
|
|||||||
* @return 自增 ID
|
* @return 自增 ID
|
||||||
*/
|
*/
|
||||||
@Operation(summary = "新增")
|
@Operation(summary = "新增")
|
||||||
|
@ResponseBody
|
||||||
@PostMapping
|
@PostMapping
|
||||||
protected R<Long> create(@Validated @RequestBody C request) {
|
protected R<Long> create(@Validated(BaseRequest.Create.class) @RequestBody C request) {
|
||||||
Long id = baseService.create(request);
|
Long id = baseService.create(request);
|
||||||
return R.ok("新增成功", id);
|
return R.ok("新增成功", id);
|
||||||
}
|
}
|
||||||
@ -118,17 +120,15 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C, U>, V, D,
|
|||||||
/**
|
/**
|
||||||
* 修改
|
* 修改
|
||||||
*
|
*
|
||||||
* @param id
|
|
||||||
* ID
|
|
||||||
* @param request
|
* @param request
|
||||||
* 修改信息
|
* 修改信息
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
@Operation(summary = "修改")
|
@Operation(summary = "修改")
|
||||||
@Parameter(name = "id", description = "ID", in = ParameterIn.PATH)
|
@ResponseBody
|
||||||
@PutMapping("/{id}")
|
@PutMapping
|
||||||
protected R update(@PathVariable Long id, @Validated @RequestBody U request) {
|
protected R update(@Validated(BaseRequest.Update.class) @RequestBody C request) {
|
||||||
baseService.update(id, request);
|
baseService.update(request);
|
||||||
return R.ok("修改成功");
|
return R.ok("修改成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,6 +141,7 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C, U>, V, D,
|
|||||||
*/
|
*/
|
||||||
@Operation(summary = "删除")
|
@Operation(summary = "删除")
|
||||||
@Parameter(name = "ids", description = "ID 列表", in = ParameterIn.PATH)
|
@Parameter(name = "ids", description = "ID 列表", in = ParameterIn.PATH)
|
||||||
|
@ResponseBody
|
||||||
@DeleteMapping("/{ids}")
|
@DeleteMapping("/{ids}")
|
||||||
protected R delete(@PathVariable List<Long> ids) {
|
protected R delete(@PathVariable List<Long> ids) {
|
||||||
baseService.delete(ids);
|
baseService.delete(ids);
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.common.base;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request 基类
|
||||||
|
*
|
||||||
|
* @author Charles7c
|
||||||
|
* @since 2023/1/30 21:51
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class BaseRequest implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组校验-创建
|
||||||
|
*/
|
||||||
|
public @interface Create {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组校验-修改
|
||||||
|
*/
|
||||||
|
public @interface Update {}
|
||||||
|
}
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package top.charles7c.cnadmin.common.base;
|
package top.charles7c.cnadmin.common.base;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import top.charles7c.cnadmin.common.model.query.PageQuery;
|
import top.charles7c.cnadmin.common.model.query.PageQuery;
|
||||||
@ -32,13 +31,11 @@ import top.charles7c.cnadmin.common.model.vo.PageDataVO;
|
|||||||
* @param <Q>
|
* @param <Q>
|
||||||
* 查询条件
|
* 查询条件
|
||||||
* @param <C>
|
* @param <C>
|
||||||
* 创建信息
|
* 创建或修改信息
|
||||||
* @param <U>
|
|
||||||
* 修改信息
|
|
||||||
* @author Charles7c
|
* @author Charles7c
|
||||||
* @since 2023/1/26 16:54
|
* @since 2023/1/26 16:54
|
||||||
*/
|
*/
|
||||||
public interface BaseService<V, D, Q, C, U> {
|
public interface BaseService<V, D, Q, C extends BaseRequest> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询列表
|
* 分页查询列表
|
||||||
@ -49,9 +46,7 @@ public interface BaseService<V, D, Q, C, U> {
|
|||||||
* 分页查询条件
|
* 分页查询条件
|
||||||
* @return 分页列表信息
|
* @return 分页列表信息
|
||||||
*/
|
*/
|
||||||
default PageDataVO<V> page(Q query, PageQuery pageQuery) {
|
PageDataVO<V> page(Q query, PageQuery pageQuery);
|
||||||
return new PageDataVO<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询列表
|
* 查询列表
|
||||||
@ -60,9 +55,7 @@ public interface BaseService<V, D, Q, C, U> {
|
|||||||
* 查询条件
|
* 查询条件
|
||||||
* @return 列表信息
|
* @return 列表信息
|
||||||
*/
|
*/
|
||||||
default List<V> list(Q query) {
|
List<V> list(Q query);
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查看详情
|
* 查看详情
|
||||||
@ -71,9 +64,7 @@ public interface BaseService<V, D, Q, C, U> {
|
|||||||
* ID
|
* ID
|
||||||
* @return 详情信息
|
* @return 详情信息
|
||||||
*/
|
*/
|
||||||
default D detail(Long id) {
|
D detail(Long id);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增
|
* 新增
|
||||||
@ -82,19 +73,15 @@ public interface BaseService<V, D, Q, C, U> {
|
|||||||
* 创建信息
|
* 创建信息
|
||||||
* @return 自增 ID
|
* @return 自增 ID
|
||||||
*/
|
*/
|
||||||
default Long create(C request) {
|
Long create(C request);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改
|
* 修改
|
||||||
*
|
*
|
||||||
* @param id
|
|
||||||
* ID
|
|
||||||
* @param request
|
* @param request
|
||||||
* 修改信息
|
* 修改信息
|
||||||
*/
|
*/
|
||||||
default void update(Long id, U request) {}
|
void update(C request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除
|
* 删除
|
||||||
@ -102,5 +89,5 @@ public interface BaseService<V, D, Q, C, U> {
|
|||||||
* @param ids
|
* @param ids
|
||||||
* ID 列表
|
* ID 列表
|
||||||
*/
|
*/
|
||||||
default void delete(List<Long> ids) {}
|
void delete(List<Long> ids);
|
||||||
}
|
}
|
||||||
|
@ -40,10 +40,19 @@ import top.charles7c.cnadmin.common.util.validate.CheckUtils;
|
|||||||
* Mapper 接口
|
* Mapper 接口
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* 实体类
|
* 实体类
|
||||||
|
* @param <V>
|
||||||
|
* 列表信息
|
||||||
|
* @param <D>
|
||||||
|
* 详情信息
|
||||||
|
* @param <Q>
|
||||||
|
* 查询条件
|
||||||
|
* @param <C>
|
||||||
|
* 创建或修改信息
|
||||||
* @author Charles7c
|
* @author Charles7c
|
||||||
* @since 2023/1/26 21:52
|
* @since 2023/1/26 21:52
|
||||||
*/
|
*/
|
||||||
public abstract class BaseServiceImpl<M extends BaseMapper<T>, T, V, D, Q, C, U> implements BaseService<V, D, Q, C, U> {
|
public abstract class BaseServiceImpl<M extends BaseMapper<T>, T, V, D, Q, C extends BaseRequest>
|
||||||
|
implements BaseService<V, D, Q, C> {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected M baseMapper;
|
protected M baseMapper;
|
||||||
@ -68,8 +77,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T, V, D, Q, C, U>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public D detail(Long id) {
|
public D detail(Long id) {
|
||||||
T entity = baseMapper.selectById(id);
|
T entity = this.getById(id);
|
||||||
CheckUtils.throwIfNull(entity, String.format("ID为 [%s] 的记录已不存在", id));
|
|
||||||
return BeanUtil.copyProperties(entity, detailVoClass);
|
return BeanUtil.copyProperties(entity, detailVoClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +87,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T, V, D, Q, C, U>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(Long id, U request) {
|
public void update(C request) {
|
||||||
T entity = BeanUtil.copyProperties(request, entityClass);
|
T entity = BeanUtil.copyProperties(request, entityClass);
|
||||||
baseMapper.updateById(entity);
|
baseMapper.updateById(entity);
|
||||||
}
|
}
|
||||||
@ -90,6 +98,19 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T, V, D, Q, C, U>
|
|||||||
baseMapper.deleteBatchIds(ids);
|
baseMapper.deleteBatchIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 ID 查询
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* ID
|
||||||
|
* @return 实体信息
|
||||||
|
*/
|
||||||
|
protected T getById(Long id) {
|
||||||
|
T entity = baseMapper.selectById(id);
|
||||||
|
CheckUtils.throwIfNull(entity, String.format("ID为 [%s] 的记录已不存在", id));
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取实体类 Class 对象
|
* 获取实体类 Class 对象
|
||||||
*
|
*
|
||||||
|
@ -153,7 +153,6 @@ public class LogServiceImpl implements LogService {
|
|||||||
if (createUser == null) {
|
if (createUser == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logVO.setCreateUserString(
|
logVO.setCreateUserString(ExceptionUtils.exToNull(() -> userService.getById(createUser)).getNickname());
|
||||||
ExceptionUtils.exToNull(() -> userService.getById(createUser)).getNickname());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,9 @@
|
|||||||
|
|
||||||
package top.charles7c.cnadmin.system.model.request;
|
package top.charles7c.cnadmin.system.model.request;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Null;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@ -26,6 +26,9 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
|
|
||||||
import org.hibernate.validator.constraints.Length;
|
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
|
@Data
|
||||||
@Schema(description = "创建或修改部门信息")
|
@Schema(description = "创建或修改部门信息")
|
||||||
public class DeptRequest implements Serializable {
|
public class DeptRequest extends BaseRequest {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
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
|
* 上级部门 ID
|
||||||
*/
|
*/
|
||||||
@Schema(description = "上级部门 ID", defaultValue = "0")
|
@Schema(description = "上级部门 ID")
|
||||||
private Long parentId = 0L;
|
private Long parentId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门名称
|
* 部门名称
|
||||||
@ -54,8 +65,8 @@ public class DeptRequest implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 部门排序
|
* 部门排序
|
||||||
*/
|
*/
|
||||||
@Schema(description = "部门排序", defaultValue = "999")
|
@Schema(description = "部门排序")
|
||||||
private Integer deptSort = 999;
|
private Integer deptSort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 描述
|
* 描述
|
||||||
@ -63,4 +74,10 @@ public class DeptRequest implements Serializable {
|
|||||||
@Schema(description = "描述")
|
@Schema(description = "描述")
|
||||||
@Length(max = 200, message = "描述长度不能超过 200 个字符")
|
@Length(max = 200, message = "描述长度不能超过 200 个字符")
|
||||||
private String description;
|
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 cn.hutool.core.lang.tree.Tree;
|
||||||
|
|
||||||
import top.charles7c.cnadmin.common.base.BaseService;
|
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.query.DeptQuery;
|
||||||
import top.charles7c.cnadmin.system.model.request.DeptRequest;
|
import top.charles7c.cnadmin.system.model.request.DeptRequest;
|
||||||
import top.charles7c.cnadmin.system.model.vo.DeptVO;
|
import top.charles7c.cnadmin.system.model.vo.DeptVO;
|
||||||
@ -32,7 +31,7 @@ import top.charles7c.cnadmin.system.model.vo.DeptVO;
|
|||||||
* @author Charles7c
|
* @author Charles7c
|
||||||
* @since 2023/1/22 17:54
|
* @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);
|
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
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class DeptServiceImpl extends
|
public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO, DeptVO, DeptQuery, DeptRequest>
|
||||||
BaseServiceImpl<DeptMapper, DeptDO, DeptVO, DeptVO, DeptQuery, DeptRequest, DeptRequest> implements DeptService {
|
implements DeptService {
|
||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
@ -112,24 +112,24 @@ public class DeptServiceImpl extends
|
|||||||
/**
|
/**
|
||||||
* 获取指定部门的子部门列表
|
* 获取指定部门的子部门列表
|
||||||
*
|
*
|
||||||
* @param dept
|
* @param deptVO
|
||||||
* 指定部门
|
* 指定部门
|
||||||
* @param list
|
* @param list
|
||||||
* 部门列表
|
* 部门列表
|
||||||
* @return 子部门列表
|
* @return 子部门列表
|
||||||
*/
|
*/
|
||||||
private List<DeptVO> getChildren(DeptVO dept, List<DeptVO> list) {
|
private List<DeptVO> getChildren(DeptVO deptVO, List<DeptVO> list) {
|
||||||
return list.stream().filter(d -> Objects.equals(d.getParentId(), dept.getDeptId()))
|
return list.stream().filter(d -> Objects.equals(d.getParentId(), deptVO.getDeptId()))
|
||||||
.map(d -> d.setChildren(this.getChildren(d, list))).collect(Collectors.toList());
|
.map(d -> d.setChildren(this.getChildren(d, list))).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Tree<Long>> buildTree(List<DeptVO> list) {
|
public List<Tree<Long>> buildTree(List<DeptVO> list) {
|
||||||
return TreeUtils.build(list, (dept, tree) -> {
|
return TreeUtils.build(list, (d, tree) -> {
|
||||||
tree.setId(dept.getDeptId());
|
tree.setId(d.getDeptId());
|
||||||
tree.setName(dept.getDeptName());
|
tree.setName(d.getDeptName());
|
||||||
tree.setParentId(dept.getParentId());
|
tree.setParentId(d.getParentId());
|
||||||
tree.setWeight(dept.getDeptSort());
|
tree.setWeight(d.getDeptSort());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,13 +147,6 @@ public class DeptServiceImpl extends
|
|||||||
return deptDO.getDeptId();
|
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
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(List<Long> ids) {
|
public void delete(List<Long> ids) {
|
||||||
@ -178,7 +171,6 @@ public class DeptServiceImpl extends
|
|||||||
if (createUser == null) {
|
if (createUser == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
deptVO.setCreateUserString(
|
deptVO.setCreateUserString(ExceptionUtils.exToNull(() -> userService.getById(createUser)).getNickname());
|
||||||
ExceptionUtils.exToNull(() -> userService.getById(createUser)).getNickname());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,21 +27,22 @@ export function getDeptList(params: DeptParams) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateDeptReq {
|
export interface DeptReq {
|
||||||
parentId: number;
|
parentId: number;
|
||||||
deptName: string;
|
deptName: string;
|
||||||
deptSort: number;
|
deptSort: number;
|
||||||
description: string;
|
description: string;
|
||||||
}
|
}
|
||||||
export function createDept(req: CreateDeptReq) {
|
export function createDept(req: DeptReq) {
|
||||||
return axios.post('/system/dept', req);
|
return axios.post('/system/dept', req);
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateDeptStatusReq {
|
export interface UpdateDeptReq extends Partial<DeptReq> {
|
||||||
status: number;
|
deptId: number;
|
||||||
|
status?: number;
|
||||||
}
|
}
|
||||||
export function updateDeptStatus(ids: Array<number>, req: UpdateDeptStatusReq) {
|
export function updateDept(req: UpdateDeptReq) {
|
||||||
return axios.patch(`/system/dept/${ids}`, req);
|
return axios.put(`/system/dept`, req);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteDept(ids: Array<number>) {
|
export function deleteDept(ids: Array<number>) {
|
||||||
|
@ -281,7 +281,7 @@
|
|||||||
DeptRecord,
|
DeptRecord,
|
||||||
DeptParams,
|
DeptParams,
|
||||||
createDept,
|
createDept,
|
||||||
updateDeptStatus,
|
updateDept,
|
||||||
deleteDept,
|
deleteDept,
|
||||||
} from '@/api/system/dept';
|
} from '@/api/system/dept';
|
||||||
import getDeptTree from '@/api/common';
|
import getDeptTree from '@/api/common';
|
||||||
@ -405,7 +405,7 @@
|
|||||||
// 改变状态
|
// 改变状态
|
||||||
const handleChangeStatus = async (record: DeptRecord, val: number) => {
|
const handleChangeStatus = async (record: DeptRecord, val: number) => {
|
||||||
if (record.deptId) {
|
if (record.deptId) {
|
||||||
const res = await updateDeptStatus([record.deptId], { status: val });
|
const res = await updateDept({ deptId: record.deptId, status: val });
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
Message.success(res.msg);
|
Message.success(res.msg);
|
||||||
} else {
|
} else {
|
||||||
|
@ -23,7 +23,6 @@ import io.swagger.v3.oas.annotations.Parameter;
|
|||||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@ -53,7 +52,7 @@ import top.charles7c.cnadmin.common.util.validate.ValidationUtils;
|
|||||||
@Tag(name = "登录 API")
|
@Tag(name = "登录 API")
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping(value = "/auth", produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping("/auth")
|
||||||
public class LoginController {
|
public class LoginController {
|
||||||
|
|
||||||
private final LoginService loginService;
|
private final LoginService loginService;
|
||||||
|
@ -27,7 +27,6 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@ -60,7 +59,7 @@ import top.charles7c.cnadmin.common.util.validate.CheckUtils;
|
|||||||
@Validated
|
@Validated
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping(value = "/common/captcha", produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping("/common/captcha")
|
||||||
public class CaptchaController {
|
public class CaptchaController {
|
||||||
|
|
||||||
private final CaptchaProperties captchaProperties;
|
private final CaptchaProperties captchaProperties;
|
||||||
|
@ -23,7 +23,6 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@ -45,7 +44,7 @@ import top.charles7c.cnadmin.system.service.DeptService;
|
|||||||
@Tag(name = "公共 API")
|
@Tag(name = "公共 API")
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping(value = "/common", produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping("/common")
|
||||||
public class CommonController {
|
public class CommonController {
|
||||||
|
|
||||||
private final DeptService deptService;
|
private final DeptService deptService;
|
||||||
|
@ -21,7 +21,6 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
@ -49,7 +48,7 @@ import top.charles7c.cnadmin.monitor.service.LogService;
|
|||||||
@Tag(name = "日志管理 API")
|
@Tag(name = "日志管理 API")
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping(value = "/monitor/log", produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping("/monitor/log")
|
||||||
public class LogController {
|
public class LogController {
|
||||||
|
|
||||||
private final LogService logService;
|
private final LogService logService;
|
||||||
|
@ -26,7 +26,6 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@ -56,7 +55,7 @@ import top.charles7c.cnadmin.monitor.model.vo.*;
|
|||||||
@Tag(name = "在线用户 API")
|
@Tag(name = "在线用户 API")
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping(value = "/monitor/online/user", produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping("/monitor/online/user")
|
||||||
public class OnlineUserController {
|
public class OnlineUserController {
|
||||||
|
|
||||||
@Operation(summary = "分页查询在线用户列表")
|
@Operation(summary = "分页查询在线用户列表")
|
||||||
|
@ -21,8 +21,6 @@ import static top.charles7c.cnadmin.common.annotation.CrudRequestMapping.Api;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
|
||||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
@ -30,7 +28,6 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import top.charles7c.cnadmin.common.annotation.CrudRequestMapping;
|
import top.charles7c.cnadmin.common.annotation.CrudRequestMapping;
|
||||||
import top.charles7c.cnadmin.common.base.BaseController;
|
import top.charles7c.cnadmin.common.base.BaseController;
|
||||||
import top.charles7c.cnadmin.common.model.request.UpdateStatusRequest;
|
|
||||||
import top.charles7c.cnadmin.common.model.vo.R;
|
import top.charles7c.cnadmin.common.model.vo.R;
|
||||||
import top.charles7c.cnadmin.system.model.query.DeptQuery;
|
import top.charles7c.cnadmin.system.model.query.DeptQuery;
|
||||||
import top.charles7c.cnadmin.system.model.request.DeptRequest;
|
import top.charles7c.cnadmin.system.model.request.DeptRequest;
|
||||||
@ -45,8 +42,8 @@ import top.charles7c.cnadmin.system.service.DeptService;
|
|||||||
*/
|
*/
|
||||||
@Tag(name = "部门管理 API")
|
@Tag(name = "部门管理 API")
|
||||||
@RestController
|
@RestController
|
||||||
@CrudRequestMapping(value = "/system/dept", api = {Api.ALL})
|
@CrudRequestMapping(value = "/system/dept", api = {Api.LIST, Api.DETAIL, Api.CREATE, Api.UPDATE, Api.DELETE})
|
||||||
public class DeptController extends BaseController<DeptService, DeptVO, DeptVO, DeptQuery, DeptRequest, DeptRequest> {
|
public class DeptController extends BaseController<DeptService, DeptVO, DeptVO, DeptQuery, DeptRequest> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Operation(summary = "查询部门列表树")
|
@Operation(summary = "查询部门列表树")
|
||||||
@ -54,12 +51,4 @@ public class DeptController extends BaseController<DeptService, DeptVO, DeptVO,
|
|||||||
List<DeptVO> list = baseService.list(query);
|
List<DeptVO> list = baseService.list(query);
|
||||||
return R.ok(baseService.buildListTree(list));
|
return R.ok(baseService.buildListTree(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "修改部门状态")
|
|
||||||
@Parameter(name = "ids", description = "ID 列表", in = ParameterIn.PATH)
|
|
||||||
@PatchMapping("/{ids}")
|
|
||||||
public R updateStatus(@PathVariable List<Long> ids, @Validated @RequestBody UpdateStatusRequest request) {
|
|
||||||
baseService.updateStatus(ids, request.getStatus());
|
|
||||||
return R.ok(String.format("%s成功", request.getStatus().getDescription()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@ -56,7 +55,7 @@ import top.charles7c.cnadmin.system.service.UserService;
|
|||||||
@Validated
|
@Validated
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping(value = "/system/user/center", produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping("/system/user/center")
|
||||||
public class UserCenterController {
|
public class UserCenterController {
|
||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
Loading…
Reference in New Issue
Block a user