Skip to content

Commit bf31875

Browse files
authored
Merge pull request #3464 from KouShenhai/dev
Dev
2 parents 8e48b9b + 82bf5a5 commit bf31875

File tree

15 files changed

+760
-31
lines changed

15 files changed

+760
-31
lines changed

doc/db/kcloud_platform.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ INSERT INTO "public"."boot_sys_menu" ("id", "creator", "editor", "create_time",
774774
INSERT INTO "public"."boot_sys_menu" ("id", "creator", "editor", "create_time", "update_time", "del_flag", "version", "tenant_id", "pid", "permission", "type", "name", "path", "icon", "sort", "status") VALUES (42, 1, 1, '2025-01-21 05:19:17', '2025-01-29 14:32:03.026995', 0, 0, 0, 23, 'sys:menu:save', 1, '新增', '', NULL, 40, 0);
775775
INSERT INTO "public"."boot_sys_menu" ("id", "creator", "editor", "create_time", "update_time", "del_flag", "version", "tenant_id", "pid", "permission", "type", "name", "path", "icon", "sort", "status") VALUES (43, 1, 1, '2025-01-31 13:08:53.459704', '2025-01-31 13:08:53.459779', 0, 0, 0, 23, 'sys:menu:detail', 1, '查看', NULL, NULL, 10, 0);
776776
INSERT INTO "public"."boot_sys_menu" ("id", "creator", "editor", "create_time", "update_time", "del_flag", "version", "tenant_id", "pid", "permission", "type", "name", "path", "icon", "sort", "status") VALUES (44, 1, 1, '2025-01-31 13:50:50.855744', '2025-01-31 13:50:50.856767', 0, 0, 0, 23, 'sys:menu:modify', 1, '修改', NULL, NULL, 30, 0);
777+
INSERT INTO "public"."boot_sys_menu" ("id", "creator", "editor", "create_time", "update_time", "del_flag", "version", "tenant_id", "pid", "permission", "type", "name", "path", "icon", "sort", "status") VALUES (45, 1, 1, '2025-02-01 09:57:06.903239', '2025-02-01 09:57:16.643637', 0, 1, 0, 24, 'sys:dept:tree-list', 1, '查询树列表', NULL, NULL, 50, 0);
777778

778779
-- ----------------------------
779780
-- Table structure for boot_sys_menu_package

laokou-service/laokou-admin/laokou-admin-adapter/src/main/java/org/laokou/admin/web/DeptsControllerV3.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.laokou.admin.dept.api.DeptsServiceI;
2424
import org.laokou.admin.dept.dto.*;
2525
import org.laokou.admin.dept.dto.clientobject.DeptCO;
26+
import org.laokou.admin.dept.dto.clientobject.DeptTreeCO;
2627
import org.laokou.common.data.cache.annotation.DataCache;
2728
import org.laokou.common.i18n.dto.Page;
2829
import org.laokou.common.i18n.dto.Result;
@@ -34,6 +35,8 @@
3435
import org.springframework.web.bind.annotation.*;
3536
import org.springframework.web.multipart.MultipartFile;
3637

38+
import java.util.List;
39+
3740
import static org.laokou.common.data.cache.constant.NameConstant.DEPTS;
3841
import static org.laokou.common.data.cache.constant.Type.DEL;
3942

@@ -100,6 +103,14 @@ public Result<Page<DeptCO>> pageV3(@RequestBody DeptPageQry qry) {
100103
return deptsServiceI.page(qry);
101104
}
102105

106+
@TraceLog
107+
@PostMapping("tree-list")
108+
@PreAuthorize("hasAuthority('sys:dept:tree-list')")
109+
@Operation(summary = "查询部门树列表", description = "查询部门树列表")
110+
public Result<List<DeptTreeCO>> treeListV3(@RequestBody DeptTreeListQry qry) {
111+
return deptsServiceI.treeList(qry);
112+
}
113+
103114
@TraceLog
104115
@GetMapping("{id}")
105116
@DataCache(name = DEPTS, key = "#id")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2022-2025 KCloud-Platform-IoT Author or Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.laokou.admin.dept.command.query;
19+
20+
import lombok.RequiredArgsConstructor;
21+
import org.laokou.admin.dept.convertor.DeptConvertor;
22+
import org.laokou.admin.dept.dto.DeptTreeListQry;
23+
import org.laokou.admin.dept.dto.clientobject.DeptTreeCO;
24+
import org.laokou.admin.dept.gatewayimpl.database.DeptMapper;
25+
import org.laokou.common.core.utils.TreeUtil;
26+
import org.laokou.common.i18n.dto.Result;
27+
import org.springframework.stereotype.Component;
28+
29+
import java.util.List;
30+
31+
/**
32+
* 查询部门请求执行器.
33+
*
34+
* @author laokou
35+
*/
36+
@Component
37+
@RequiredArgsConstructor
38+
public class DeptTreeListQryExe {
39+
40+
private final DeptMapper deptMapper;
41+
42+
public Result<List<DeptTreeCO>> execute(DeptTreeListQry qry) {
43+
DeptTreeCO co = TreeUtil.buildTreeNode(DeptConvertor.toClientObjs(deptMapper.selectObjectList(qry)),
44+
DeptTreeCO.class);
45+
return Result.ok(co.getChildren());
46+
}
47+
48+
}

laokou-service/laokou-admin/laokou-admin-app/src/main/java/org/laokou/admin/dept/service/DeptsServiceImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@
2222
import org.laokou.admin.dept.command.*;
2323
import org.laokou.admin.dept.command.query.DeptGetQryExe;
2424
import org.laokou.admin.dept.command.query.DeptPageQryExe;
25+
import org.laokou.admin.dept.command.query.DeptTreeListQryExe;
2526
import org.laokou.admin.dept.dto.*;
2627
import org.laokou.admin.dept.dto.clientobject.DeptCO;
28+
import org.laokou.admin.dept.dto.clientobject.DeptTreeCO;
2729
import org.laokou.common.i18n.dto.Page;
2830
import org.laokou.common.i18n.dto.Result;
2931
import org.springframework.stereotype.Service;
3032

33+
import java.util.List;
34+
3135
/**
3236
* 部门接口实现类.
3337
*
@@ -51,6 +55,8 @@ public class DeptsServiceImpl implements DeptsServiceI {
5155

5256
private final DeptGetQryExe deptGetQryExe;
5357

58+
private final DeptTreeListQryExe deptTreeListQryExe;
59+
5460
@Override
5561
public void save(DeptSaveCmd cmd) {
5662
deptSaveCmdExe.executeVoid(cmd);
@@ -81,6 +87,11 @@ public Result<Page<DeptCO>> page(DeptPageQry qry) {
8187
return deptPageQryExe.execute(qry);
8288
}
8389

90+
@Override
91+
public Result<List<DeptTreeCO>> treeList(DeptTreeListQry qry) {
92+
return deptTreeListQryExe.execute(qry);
93+
}
94+
8495
@Override
8596
public Result<DeptCO> getById(DeptGetQry qry) {
8697
return deptGetQryExe.execute(qry);

laokou-service/laokou-admin/laokou-admin-client/src/main/java/org/laokou/admin/dept/api/DeptsServiceI.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919

2020
import org.laokou.admin.dept.dto.*;
2121
import org.laokou.admin.dept.dto.clientobject.DeptCO;
22+
import org.laokou.admin.dept.dto.clientobject.DeptTreeCO;
2223
import org.laokou.common.i18n.dto.Page;
2324
import org.laokou.common.i18n.dto.Result;
2425

26+
import java.util.List;
27+
2528
/**
2629
* 部门接口.
2730
*
@@ -65,6 +68,12 @@ public interface DeptsServiceI {
6568
*/
6669
Result<Page<DeptCO>> page(DeptPageQry qry);
6770

71+
/**
72+
* 查询部门树.
73+
* @param qry 查询请求
74+
*/
75+
Result<List<DeptTreeCO>> treeList(DeptTreeListQry qry);
76+
6877
/**
6978
* 查看部门.
7079
* @param qry 查看请求

laokou-service/laokou-admin/laokou-admin-client/src/main/java/org/laokou/admin/dept/dto/DeptPageQry.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@
2828
@Data
2929
public class DeptPageQry extends PageQuery {
3030

31+
private String name;
32+
3133
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2022-2025 KCloud-Platform-IoT Author or Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.laokou.admin.dept.dto;
19+
20+
/**
21+
* @author laokou
22+
*/
23+
public class DeptTreeListQry extends DeptPageQry {
24+
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2022-2025 KCloud-Platform-IoT Author or Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.laokou.admin.dept.dto.clientobject;
19+
20+
import com.fasterxml.jackson.annotation.JsonInclude;
21+
import lombok.AllArgsConstructor;
22+
import lombok.Data;
23+
import lombok.NoArgsConstructor;
24+
import org.laokou.common.core.utils.TreeUtil;
25+
26+
/**
27+
* 部门树客户端对象.
28+
*
29+
* @author laokou
30+
*/
31+
@Data
32+
@NoArgsConstructor
33+
@AllArgsConstructor
34+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
35+
public class DeptTreeCO extends TreeUtil.TreeNode<DeptTreeCO> {
36+
37+
/**
38+
* 部门路径.
39+
*/
40+
private String path;
41+
42+
/**
43+
* 部门排序.
44+
*/
45+
private Integer sort;
46+
47+
}

laokou-service/laokou-admin/laokou-admin-infrastructure/src/main/java/org/laokou/admin/dept/convertor/DeptConvertor.java

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
package org.laokou.admin.dept.convertor;
1919

2020
import org.laokou.admin.dept.dto.clientobject.DeptCO;
21+
import org.laokou.admin.dept.dto.clientobject.DeptTreeCO;
2122
import org.laokou.admin.dept.gatewayimpl.database.dataobject.DeptDO;
2223
import org.laokou.admin.dept.model.DeptE;
23-
import org.laokou.common.core.utils.ConvertUtil;
2424
import org.laokou.common.core.utils.IdGenerator;
25-
import org.laokou.common.i18n.utils.ObjectUtil;
25+
26+
import java.util.List;
2627

2728
/**
2829
* 部门转换器.
@@ -31,20 +32,58 @@
3132
*/
3233
public class DeptConvertor {
3334

34-
public static DeptDO toDataObject(DeptE deptE) {
35-
DeptDO deptDO = ConvertUtil.sourceToTarget(deptE, DeptDO.class);
36-
if (ObjectUtil.isNull(deptDO.getId())) {
35+
public static DeptDO toDataObject(DeptE deptE, boolean isInsert) {
36+
DeptDO deptDO = new DeptDO();
37+
if (isInsert) {
3738
deptDO.setId(IdGenerator.defaultSnowflakeId());
3839
}
40+
else {
41+
deptDO.setId(deptE.getId());
42+
}
43+
deptDO.setPid(deptE.getPid());
44+
deptDO.setName(deptE.getName());
45+
deptDO.setPath(deptE.getPath());
46+
deptDO.setSort(deptE.getSort());
3947
return deptDO;
4048
}
4149

4250
public static DeptCO toClientObject(DeptDO deptDO) {
43-
return ConvertUtil.sourceToTarget(deptDO, DeptCO.class);
51+
DeptCO deptCO = new DeptCO();
52+
deptCO.setId(deptDO.getId());
53+
deptCO.setPid(deptDO.getPid());
54+
deptCO.setName(deptDO.getName());
55+
deptCO.setPath(deptDO.getPath());
56+
deptCO.setSort(deptDO.getSort());
57+
return deptCO;
58+
}
59+
60+
public static List<DeptCO> toClientObjects(List<DeptDO> list) {
61+
return list.stream().map(DeptConvertor::toClientObject).toList();
4462
}
4563

4664
public static DeptE toEntity(DeptCO deptCO) {
47-
return ConvertUtil.sourceToTarget(deptCO, DeptE.class);
65+
DeptE deptE = new DeptE();
66+
deptE.setId(deptCO.getId());
67+
deptE.setPid(deptCO.getPid());
68+
deptE.setName(deptCO.getName());
69+
deptE.setPath(deptCO.getPath());
70+
deptE.setSort(deptCO.getSort());
71+
return deptE;
72+
}
73+
74+
public static DeptTreeCO toClientObj(DeptDO deptDO) {
75+
DeptTreeCO co = new DeptTreeCO();
76+
co.setId(deptDO.getId());
77+
co.setName(deptDO.getName());
78+
co.setPid(deptDO.getPid());
79+
co.setPath(deptDO.getPath());
80+
co.setSort(deptDO.getSort());
81+
return co;
82+
83+
}
84+
85+
public static List<DeptTreeCO> toClientObjs(List<DeptDO> list) {
86+
return list.stream().map(DeptConvertor::toClientObj).toList();
4887
}
4988

5089
}

laokou-service/laokou-admin/laokou-admin-infrastructure/src/main/java/org/laokou/admin/dept/gatewayimpl/DeptGatewayImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ public class DeptGatewayImpl implements DeptGateway {
4040

4141
@Override
4242
public void create(DeptE deptE) {
43-
deptMapper.insert(DeptConvertor.toDataObject(deptE));
43+
deptMapper.insert(DeptConvertor.toDataObject(deptE, true));
4444
}
4545

4646
@Override
4747
public void update(DeptE deptE) {
48-
DeptDO deptDO = DeptConvertor.toDataObject(deptE);
48+
DeptDO deptDO = DeptConvertor.toDataObject(deptE, false);
4949
deptDO.setVersion(deptMapper.selectVersion(deptE.getId()));
5050
deptMapper.updateById(deptDO);
5151
}

0 commit comments

Comments
 (0)