From e4bda3cc41f16a5e58278a64d2a14566389e848e Mon Sep 17 00:00:00 2001 From: zhangzhiqiang Date: Thu, 1 Dec 2022 16:24:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E9=83=A8=E9=97=A8=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nl/modules/system/domain/vo/DeptVo.java | 66 +++++++++++++++++++ .../modules/system/rest/DeptController.java | 17 ++++- .../system/service/impl/DeptServiceImpl.java | 2 +- .../org/nl/modules/system/util/CodeUtil.java | 4 +- .../org/nl/modules/system/util/CopyUtil.java | 36 ++++++++++ .../src/main/java/org/nl/sso/wql/SYS_DEPT.wql | 2 +- nladmin-ui/src/App.vue | 2 +- nladmin-ui/src/api/system/dept.js | 10 ++- nladmin-ui/src/views/system/dept/index.vue | 14 ++-- 9 files changed, 141 insertions(+), 12 deletions(-) create mode 100644 nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/vo/DeptVo.java create mode 100644 nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/util/CopyUtil.java diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/vo/DeptVo.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/vo/DeptVo.java new file mode 100644 index 0000000..f7ae6da --- /dev/null +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/domain/vo/DeptVo.java @@ -0,0 +1,66 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * 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 org.nl.modules.system.domain.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; +import org.nl.modules.system.service.dto.MenuDto; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.List; + +/** +* @author Zheng Jie +* @date 2019-03-25 +*/ +@Getter +@Setter +public class DeptVo implements Serializable { + + + private Long dept_id; + + @ApiModelProperty(value = "排序") + private Integer dept_sort; + + @NotBlank + @ApiModelProperty(value = "部门名称") + private String name; + + @NotNull + @ApiModelProperty(value = "是否启用") + private Boolean is_used; + + @ApiModelProperty(value = "上级部门") + private Long pid; + + @ApiModelProperty(value = "子节点数目", hidden = true) + private Integer sub_count = 0; + //前端显示 + private Boolean hasChildren =Boolean.FALSE; + + private List children; + + public void setSub_count(Integer sub_count) { + this.sub_count = sub_count; + if (sub_count>0){ + this.hasChildren=Boolean.TRUE; + } + } +} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/DeptController.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/DeptController.java index f94c0ea..3f55daf 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/DeptController.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/rest/DeptController.java @@ -28,10 +28,12 @@ import org.nl.modules.common.exception.BadRequestException; import org.nl.modules.common.utils.PageUtil; import org.nl.modules.logging.annotation.Log; import org.nl.modules.system.domain.Dept; +import org.nl.modules.system.domain.vo.DeptVo; import org.nl.modules.system.service.DeptService; import org.nl.modules.system.service.dto.DeptDto; import org.nl.modules.system.service.dto.DeptQueryCriteria; import org.nl.modules.system.service.dto.DeptTree; +import org.nl.modules.system.util.CopyUtil; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; @@ -60,6 +62,18 @@ public class DeptController { return new ResponseEntity<>(PageUtil.toPage(deptDtos, deptDtos.size()),HttpStatus.OK); } + @ApiOperation("查询部门") + @GetMapping("/vo") + public ResponseEntity queryvo(DeptQueryCriteria criteria) throws Exception { + if (criteria.getPid() == null){ + criteria.setPidIsNull(true); + } + List deptDtos = deptService.queryAll(criteria, true); + List deptVos = CopyUtil.copyList(deptDtos, DeptVo.class); + return new ResponseEntity<>(PageUtil.toPage(deptVos, deptVos.size()),HttpStatus.OK); + } + + @ApiOperation("查询所有部门树") @GetMapping("/allTree") public ResponseEntity allTree(DeptQueryCriteria criteria) throws Exception { @@ -80,6 +94,7 @@ public class DeptController { List superior = deptService.getSuperior(deptTree, new ArrayList<>()); deptDtos.addAll(superior); } + List deptVos = CopyUtil.copyList(deptDtos, DeptVo.class); return new ResponseEntity<>(deptService.buildTree(new ArrayList<>(deptDtos)),HttpStatus.OK); } @@ -98,7 +113,7 @@ public class DeptController { @Log("修改部门") @ApiOperation("修改部门") @PutMapping - @SaCheckPermission("dept:edit") +// @SaCheckPermission("dept:edit") public ResponseEntity update(@RequestBody Dept resources){ deptService.update(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DeptServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DeptServiceImpl.java index a2e94fb..4bdc082 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DeptServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/service/impl/DeptServiceImpl.java @@ -143,7 +143,7 @@ public class DeptServiceImpl implements DeptService { } Dept dept = findById(resources.getDept_id()); resources.setDept_id(dept.getDept_id()); - WQLObject.getWQLObject("sys_user").update((JSONObject)JSON.toJSON(resources),"dept_id = '"+resources.getDept_id()+"'"); + WQLObject.getWQLObject("sys_dept").update((JSONObject)JSON.toJSON(resources),"dept_id = '"+resources.getDept_id()+"'"); // 更新父节点中子节点数目 updateSubCnt(oldPid); updateSubCnt(newPid); diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/util/CodeUtil.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/util/CodeUtil.java index 1c12c85..14bc0a1 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/util/CodeUtil.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/util/CodeUtil.java @@ -2,8 +2,9 @@ package org.nl.modules.system.util; import org.nl.modules.system.service.GenCodeService; import org.nl.modules.wql.util.SpringContextHolder; +import org.springframework.beans.BeanUtils; -import java.util.HashMap; +import java.util.*; public class CodeUtil { @@ -15,4 +16,5 @@ public class CodeUtil { return SpringContextHolder.getBean(GenCodeService.class).codeDemo(map); } + } diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/util/CopyUtil.java b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/util/CopyUtil.java new file mode 100644 index 0000000..c67e7cc --- /dev/null +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/modules/system/util/CopyUtil.java @@ -0,0 +1,36 @@ +package org.nl.modules.system.util; + +import org.springframework.beans.BeanUtils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +/* + * @author ZZQ + * @Date 2022/12/1 3:35 下午 + */ +public class CopyUtil { + public static List copyList(final Collection sources, final Class clazz) { + if (sources == null) { + return new ArrayList(0); + } else { + List list = new ArrayList(sources.size()); + Iterator var3 = sources.iterator(); + + while(var3.hasNext()) { + Object source = var3.next(); + + try { + T dest = clazz.newInstance(); + BeanUtils.copyProperties(source, dest); + list.add(dest); + } catch (Throwable var6) { + } + } + return list; + } + } + +} diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/sso/wql/SYS_DEPT.wql b/nladmin-system/nlsso-server/src/main/java/org/nl/sso/wql/SYS_DEPT.wql index cef3186..71944a5 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/sso/wql/SYS_DEPT.wql +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/sso/wql/SYS_DEPT.wql @@ -54,7 +54,7 @@ sys_dept WHERE 1=1 OPTION 输入.pid <> "" - pid = 输入.id + pid = 输入.pid ENDOPTION OPTION 输入.name <> "" name = 输入.name diff --git a/nladmin-ui/src/App.vue b/nladmin-ui/src/App.vue index 2f82bcc..5838149 100644 --- a/nladmin-ui/src/App.vue +++ b/nladmin-ui/src/App.vue @@ -24,7 +24,7 @@ export default { this.timmer = setTimeout(() => { sessionStorage.clear() this.logout() - }, 1000 * 60 * 15) // 15分钟 https://blog.csdn.net/qq_42345108/article/details/103496456 + }, 1000 * 60 * 151) // 15分钟 https://blog.csdn.net/qq_42345108/article/details/103496456 }, logout() { this.$store.dispatch('LogOut').then(() => { diff --git a/nladmin-ui/src/api/system/dept.js b/nladmin-ui/src/api/system/dept.js index 2cbe31b..13ee310 100644 --- a/nladmin-ui/src/api/system/dept.js +++ b/nladmin-ui/src/api/system/dept.js @@ -25,6 +25,14 @@ export function getDeptSuperior(ids) { }) } +export function getDeptvo(params) { + return request({ + url: 'api/dept/vo', + method: 'get', + params + }) +} + export function add(data) { return request({ url: 'api/dept', @@ -49,4 +57,4 @@ export function edit(data) { }) } -export default { add, edit, del, getDepts, getDeptSuperior } +export default { add, edit, del, getDepts, getDeptSuperior, getDeptvo } diff --git a/nladmin-ui/src/views/system/dept/index.vue b/nladmin-ui/src/views/system/dept/index.vue index e5c87df..4cb5530 100644 --- a/nladmin-ui/src/views/system/dept/index.vue +++ b/nladmin-ui/src/views/system/dept/index.vue @@ -85,7 +85,7 @@ 确认 - + - + @@ -146,6 +146,7 @@ import CRUD, { crud, form, header, presenter } from '@crud/crud' import rrOperation from '@crud/RR.operation' import crudOperation from '@crud/CRUD.operation' import udOperation from '@crud/UD.operation' +import { getDeptvo } from '../../../api/system/dept' const defaultForm = { id: null, @@ -163,7 +164,7 @@ export default { name: 'Dept', components: { Treeselect, crudOperation, rrOperation, udOperation }, cruds() { - return CRUD({ title: '部门', url: 'api/dept', crudMethod: { ...crudDept }}) + return CRUD({ title: '部门', url: 'api/dept/vo', crudMethod: { ...crudDept }}) }, mixins: [presenter(), header(), form(defaultForm), crud()], // 设置数据字典 @@ -195,9 +196,9 @@ export default { }, methods: { getDeptDatas(tree, treeNode, resolve) { - const params = { pid: tree.id } + const params = { pid: tree.dept_id } setTimeout(() => { - crudDept.getDepts(params).then(res => { + crudDept.getDeptvo(params).then(res => { resolve(res.content) }) }, 100) @@ -235,6 +236,7 @@ export default { }, getDepts() { crudDept.getDepts({ enabled: true }).then(res => { + debugger this.depts = res.content.map(function(obj) { if (obj.hasChildren) { obj.children = null