From da02fba0ae5aacb69f070423338d45d0685a890e Mon Sep 17 00:00:00 2001 From: zhangzhiqiang Date: Mon, 19 Dec 2022 18:19:01 +0800 Subject: [PATCH] dept --- .../dept/dao/mapper/SysDeptMapper.java | 1 - .../service/dept/impl/SysDeptServiceImpl.java | 19 +++++++++--- nladmin-ui/src/views/system/dept/index.vue | 31 ++++++++----------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/dept/dao/mapper/SysDeptMapper.java b/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/dept/dao/mapper/SysDeptMapper.java index 978d383..97d0e9b 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/dept/dao/mapper/SysDeptMapper.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/dept/dao/mapper/SysDeptMapper.java @@ -41,5 +41,4 @@ public interface SysDeptMapper extends BaseMapper { * @return */ String findAllChild(String pid); - } diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/dept/impl/SysDeptServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/dept/impl/SysDeptServiceImpl.java index 844dd04..fe66106 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/dept/impl/SysDeptServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/dept/impl/SysDeptServiceImpl.java @@ -29,6 +29,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.util.*; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -94,11 +97,13 @@ public class SysDeptServiceImpl extends ServiceImpl impl if (query.getPid() == null){ query.setPidIsNull(true); } + if (StringUtils.isNotEmpty(query.getName()) || query.getIsUsed()!=null){ + query.setPidIsNull(null); + } } Page page = this.page(pageQuery.build(SysDept.class), query.build()); - page.setRecords(CopyUtil.copyList(page.getRecords(), DeptVo.class)); - if (StringUtils.isNotEmpty(query.getName())){ + if (StringUtils.isNotEmpty(query.getName()) || query.getIsUsed()!=null){ page.getRecords().forEach(a->((DeptVo)a).setHasChildren(false) ); } return page; @@ -140,7 +145,10 @@ public class SysDeptServiceImpl extends ServiceImpl impl } verification(deptIds); Set depts = new HashSet<>(); + Set pids = new HashSet<>(); + List deptList = sysDeptMapper.selectList(new QueryWrapper().in("dept_id", deptIds)); for (String deptId : deptIds) { + depts.add(deptId); String allChild = sysDeptMapper.findAllChild(deptId); if (StringUtils.isNotEmpty(allChild)){ String[] split = allChild.split(","); @@ -148,9 +156,10 @@ public class SysDeptServiceImpl extends ServiceImpl impl } } this.remove(new QueryWrapper().in("dept_id", depts)); - for (String deptId : deptIds) { - sysDeptMapper.updateSubCount(deptId); - } + deptList.forEach(dept -> { + if (StringUtils.isNotEmpty(dept.getPid())){sysDeptMapper.updateSubCount(dept.getPid());} + }); + } private void verification(Set depeIds) { diff --git a/nladmin-ui/src/views/system/dept/index.vue b/nladmin-ui/src/views/system/dept/index.vue index 870c5af..ff46232 100644 --- a/nladmin-ui/src/views/system/dept/index.vue +++ b/nladmin-ui/src/views/system/dept/index.vue @@ -53,7 +53,7 @@ /> - + @@ -61,13 +61,11 @@ - + @@ -110,8 +108,6 @@ :disabled="scope.row.id === 1" active-color="#409EFF" inactive-color="#F56C6C" - active-value="1" - inactive-value="0" @change="changeEnabled(scope.row, scope.row.isUsed,)" /> @@ -153,8 +149,8 @@ const defaultForm = { sub_count: 0, pid: null, deptSort: 999, - isUsed: '1', - ext_id: null + isUsed: true, + extId: null } export default { name: 'Dept', @@ -182,8 +178,8 @@ export default { del: ['admin', 'dept:del'] }, enabledTypeOptions: [ - { key: '1', display_name: '正常' }, - { key: '0', display_name: '禁用' } + { key: true, display_name: '启用' }, + { key: false, display_name: '禁用' } ] } }, @@ -228,7 +224,7 @@ export default { }) }, getDepts() { - crudDept.getDeptvo({ isUsed: '1' }).then(res => { + crudDept.getDeptvo({ isUsed: true }).then(res => { this.depts = res.content.map(function(obj) { if (obj.hasChildren) { obj.children = null @@ -240,7 +236,7 @@ export default { // 获取弹窗内部门数据 loadDepts({ action, parentNode, callback }) { if (action === LOAD_CHILDREN_OPTIONS) { - crudDept.getDeptvo({ isUsed: '1', pid: parentNode.deptId }).then(res => { + crudDept.getDeptvo({ isUsed: true, pid: parentNode.deptId }).then(res => { parentNode.children = res.content.map(function(obj) { obj.children = null return obj @@ -267,19 +263,18 @@ export default { }, // 改变状态 changeEnabled(data, val) { - this.$confirm('此操作将 "' + this.dict.label.dept_status[val] + '" ' + data.name + '部门, 是否继续?', '提示', { + const satus = this.enabledTypeOptions.find(item => { return item.key == data.isUsed }) + debugger + this.$confirm('此操作将 "' + satus.display_name + '" ' + data.name + '部门, 是否继续?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { crudDept.edit(data).then(res => { - this.crud.notify(this.dict.label.dept_status[val] + '成功', CRUD.NOTIFICATION_TYPE.SUCCESS) - }).catch(err => { - data.enabled = !data.enabled - console.log(err.response.data.message) + this.crud.notify(satus.display_name + '成功', CRUD.NOTIFICATION_TYPE.SUCCESS) }) }).catch(() => { - data.enabled = !data.enabled + data.isUsed = !data.isUsed }) }, checkboxT(row, rowIndex) {