From c5d4e8ae21a728da98e4a334db6ce97484f0627b Mon Sep 17 00:00:00 2001 From: Charles7c Date: Wed, 1 Feb 2023 23:25:36 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=9A=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E9=83=A8=E9=97=A8=E7=AE=A1=E7=90=86=E5=89=8D=E7=AB=AF=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=9B=E6=96=B0=E5=A2=9E=E4=BF=AE=E6=94=B9=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E3=80=81=E6=89=B9=E9=87=8F=E5=88=A0=E9=99=A4=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E3=80=81=E6=9F=A5=E7=9C=8B=E9=83=A8=E9=97=A8=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E5=8A=9F=E8=83=BD=EF=BC=88=E5=90=8E=E7=AB=AF=E4=B8=BB?= =?UTF-8?q?=E8=A6=81=E5=9F=BA=E4=BA=8E=20CRUD=20=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=8F=90=E4=BE=9B=20API=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/annotation/CrudRequestMapping.java | 4 +- .../cnadmin/common/base/BaseController.java | 6 +- .../cnadmin/common/base/BaseService.java | 2 +- .../cnadmin/common/base/BaseServiceImpl.java | 2 +- .../cnadmin/common/model/query/PageQuery.java | 4 +- .../cnadmin/system/model/vo/DeptDetailVO.java | 75 ++ .../cnadmin/system/service/DeptService.java | 3 +- .../system/service/impl/DeptServiceImpl.java | 80 +- continew-admin-ui/src/api/common/index.ts | 2 +- continew-admin-ui/src/api/system/dept.ts | 30 +- .../src/views/system/dept/index.vue | 821 ++++++++---------- .../controller/common/CommonController.java | 2 +- .../controller/system/DeptController.java | 5 +- 13 files changed, 532 insertions(+), 504 deletions(-) create mode 100644 continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/vo/DeptDetailVO.java diff --git a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/annotation/CrudRequestMapping.java b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/annotation/CrudRequestMapping.java index 377f7fdd..8e461eef 100644 --- a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/annotation/CrudRequestMapping.java +++ b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/annotation/CrudRequestMapping.java @@ -37,7 +37,7 @@ public @interface CrudRequestMapping { /** * API 列表 */ - Api[] api() default {Api.PAGE, Api.DETAIL, Api.CREATE, Api.UPDATE, Api.DELETE}; + Api[] api() default {Api.PAGE, Api.GET, Api.CREATE, Api.UPDATE, Api.DELETE}; /** * API 枚举 @@ -58,7 +58,7 @@ public @interface CrudRequestMapping { /** * 详情 */ - DETAIL, + GET, /** * 新增 */ diff --git a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/base/BaseController.java b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/base/BaseController.java index 95dc11fc..8bf180d3 100644 --- a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/base/BaseController.java +++ b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/base/BaseController.java @@ -93,12 +93,12 @@ public abstract class BaseController, V, D, Q, * ID * @return 详情信息 */ - @Operation(summary = "查看数据详情") + @Operation(summary = "查看详情") @Parameter(name = "id", description = "ID", in = ParameterIn.PATH) @ResponseBody @GetMapping("/{id}") - protected R detail(@PathVariable Long id) { - D detail = baseService.detail(id); + protected R get(@PathVariable Long id) { + D detail = baseService.get(id); return R.ok(detail); } diff --git a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/base/BaseService.java b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/base/BaseService.java index 892ad29b..d3456e22 100644 --- a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/base/BaseService.java +++ b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/base/BaseService.java @@ -64,7 +64,7 @@ public interface BaseService { * ID * @return 详情信息 */ - D detail(Long id); + D get(Long id); /** * 新增 diff --git a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/base/BaseServiceImpl.java b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/base/BaseServiceImpl.java index 2e53cb20..1302eafc 100644 --- a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/base/BaseServiceImpl.java +++ b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/base/BaseServiceImpl.java @@ -76,7 +76,7 @@ public abstract class BaseServiceImpl, T, V, D, Q, C ext } @Override - public D detail(Long id) { + public D get(Long id) { T entity = this.getById(id); return BeanUtil.copyProperties(entity, detailVoClass); } diff --git a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/model/query/PageQuery.java b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/model/query/PageQuery.java index a8643987..ecc877bd 100644 --- a/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/model/query/PageQuery.java +++ b/continew-admin-common/src/main/java/top/charles7c/cnadmin/common/model/query/PageQuery.java @@ -69,8 +69,8 @@ public class PageQuery implements Serializable { /** 默认页码:1 */ private static final int DEFAULT_PAGE = 1; - /** 默认每页记录数:int 最大值 */ - private static final int DEFAULT_SIZE = Integer.MAX_VALUE; + /** 默认每页记录数:10 */ + private static final int DEFAULT_SIZE = 10; private static final String DELIMITER = ","; public PageQuery() { diff --git a/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/vo/DeptDetailVO.java b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/vo/DeptDetailVO.java new file mode 100644 index 00000000..163da626 --- /dev/null +++ b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/model/vo/DeptDetailVO.java @@ -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; +} diff --git a/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/DeptService.java b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/DeptService.java index 40713dd6..468f2d50 100644 --- a/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/DeptService.java +++ b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/DeptService.java @@ -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 { +public interface DeptService extends BaseService { /** * 构建树 diff --git a/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/DeptServiceImpl.java b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/DeptServiceImpl.java index c96a4a6c..e9a2b714 100644 --- a/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/DeptServiceImpl.java +++ b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/DeptServiceImpl.java @@ -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 +public class DeptServiceImpl extends BaseServiceImpl implements DeptService { private final UserService userService; @@ -71,6 +74,34 @@ public class DeptServiceImpl extends BaseServiceImpl 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 ids) { + super.delete(ids); + baseMapper.delete(Wrappers.lambdaQuery().in(DeptDO::getParentId, ids)); + } + @Override public List buildListTree(List list) { if (CollUtil.isEmpty(list)) { @@ -133,27 +164,6 @@ public class DeptServiceImpl extends BaseServiceImpl 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 ids) { - super.delete(ids); - baseMapper.delete(Wrappers.lambdaQuery().in(DeptDO::getParentId, ids)); - } - @Override public boolean checkDeptNameExist(String deptName, Long parentId, Long deptId) { return baseMapper.exists(Wrappers.lambdaQuery().eq(DeptDO::getDeptName, deptName) @@ -163,14 +173,30 @@ public class DeptServiceImpl extends BaseServiceImpl 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()); } } diff --git a/continew-admin-ui/src/api/common/index.ts b/continew-admin-ui/src/api/common/index.ts index b0365b6e..f07a5788 100644 --- a/continew-admin-ui/src/api/common/index.ts +++ b/continew-admin-ui/src/api/common/index.ts @@ -3,7 +3,7 @@ import qs from 'query-string'; import { DeptParams } from '@/api/system/dept'; import { TreeNodeData } from '@arco-design/web-vue'; -export default function getDeptTree(params: DeptParams) { +export default function listDeptTree(params: DeptParams) { return axios.get('/common/tree/dept', { params, paramsSerializer: (obj) => { diff --git a/continew-admin-ui/src/api/system/dept.ts b/continew-admin-ui/src/api/system/dept.ts index aacd3598..71bd5f3d 100644 --- a/continew-admin-ui/src/api/system/dept.ts +++ b/continew-admin-ui/src/api/system/dept.ts @@ -6,11 +6,13 @@ export interface DeptRecord { deptName: string; parentId?: number; deptSort: number; - description: string; + description?: string; status?: number; - createUserString: string; - createTime: string; - children: Array, + createUserString?: string; + createTime?: string; + updateUserString?: string; + updateTime?: string; + children?: Array, } export interface DeptParams { @@ -18,7 +20,7 @@ export interface DeptParams { status?: number; } -export function getDeptList(params: DeptParams) { +export function listDept(params: DeptParams) { return axios.get('/system/dept/all', { params, paramsSerializer: (obj) => { @@ -27,24 +29,18 @@ export function getDeptList(params: DeptParams) { }); } -export interface DeptReq { - parentId: number; - deptName: string; - deptSort: number; - description: string; +export function getDept(id: number) { + return axios.get(`/system/dept/${id}`); } -export function createDept(req: DeptReq) { + +export function createDept(req: DeptRecord) { return axios.post('/system/dept', req); } -export interface UpdateDeptReq extends Partial { - deptId: number; - status?: number; -} -export function updateDept(req: UpdateDeptReq) { +export function updateDept(req: DeptRecord) { return axios.put(`/system/dept`, req); } -export function deleteDept(ids: Array) { +export function deleteDept(ids: number | Array) { return axios.delete(`/system/dept/${ids}`); } \ No newline at end of file diff --git a/continew-admin-ui/src/views/system/dept/index.vue b/continew-admin-ui/src/views/system/dept/index.vue index 08a7c636..f6af2b55 100644 --- a/continew-admin-ui/src/views/system/dept/index.vue +++ b/continew-admin-ui/src/views/system/dept/index.vue @@ -1,154 +1,71 @@