dept
This commit is contained in:
@@ -24,7 +24,10 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
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.util.CopyUtil;
|
||||
import org.nl.system.service.dept.ISysDeptService;
|
||||
@@ -33,9 +36,11 @@ import org.nl.system.service.dept.dto.DeptQuery;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
@@ -48,7 +53,6 @@ import java.util.List;
|
||||
public class DeptController {
|
||||
|
||||
private final ISysDeptService deptService;
|
||||
private static final String ENTITY_NAME = "dept";
|
||||
|
||||
@ApiOperation("查询部门")
|
||||
@GetMapping
|
||||
@@ -81,30 +85,36 @@ public class DeptController {
|
||||
return new ResponseEntity<>(deptService.getSuperior(ids),HttpStatus.OK);
|
||||
}
|
||||
//
|
||||
// @Log("新增部门")
|
||||
// @ApiOperation("新增部门")
|
||||
// @PostMapping
|
||||
//// @SaCheckPermission("dept:add")
|
||||
// public ResponseEntity<Object> create(@Validated @RequestBody Dept resources){
|
||||
//// deptService.create(resources);
|
||||
// return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
// }
|
||||
@Log("新增部门")
|
||||
@ApiOperation("新增部门")
|
||||
@PostMapping
|
||||
// @SaCheckPermission("dept:add")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody SysDept resources){
|
||||
deptService.createDept(resources);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
//
|
||||
// @Log("修改部门")
|
||||
// @ApiOperation("修改部门")
|
||||
// @PutMapping
|
||||
//// @SaCheckPermission("dept:edit")
|
||||
// public ResponseEntity<Object> update(@RequestBody Dept resources){
|
||||
// deptService.update(resources);
|
||||
// return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
// }
|
||||
@Log("修改部门")
|
||||
@ApiOperation("修改部门")
|
||||
@PutMapping
|
||||
// @SaCheckPermission("dept:edit")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody SysDept dept){
|
||||
if (dept.getPid() != null && dept.getDeptId().equals(dept.getPid())) {
|
||||
throw new BadRequestException("上级不能为自己");
|
||||
}
|
||||
deptService.updateDept(dept);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
//
|
||||
// @Log("删除部门")
|
||||
// @ApiOperation("删除部门")
|
||||
// @DeleteMapping
|
||||
//// @SaCheckPermission("dept:del")
|
||||
// public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
|
||||
// deptService.delete(ids);
|
||||
// return new ResponseEntity<>(HttpStatus.OK);
|
||||
// }
|
||||
@Log("删除部门")
|
||||
@ApiOperation("删除部门")
|
||||
@DeleteMapping
|
||||
// @SaCheckPermission("dept:del")
|
||||
public ResponseEntity<Object> delete(@RequestBody Set<String> deptIds){
|
||||
if (CollectionUtils.isEmpty(deptIds)){
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
deptService.delateDept(deptIds);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.nl.system.service.dept.dto.DeptQuery;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -49,4 +50,18 @@ public interface ISysDeptService extends IService<SysDept> {
|
||||
*/
|
||||
void saveUserDeptRelation(String UserId, Collection<String> deptIds);
|
||||
|
||||
/**
|
||||
* 更新部门:同时更新节点
|
||||
* @param dept
|
||||
*/
|
||||
void updateDept(SysDept dept);
|
||||
|
||||
/**
|
||||
* 删除部门及子部门
|
||||
* @param deptIds
|
||||
*/
|
||||
void delateDept(Set<String> deptIds);
|
||||
|
||||
void createDept(SysDept dept);
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.nl.system.service.dept.dao.SysDept;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -17,6 +18,27 @@ import java.util.List;
|
||||
*/
|
||||
public interface SysDeptMapper extends BaseMapper<SysDept> {
|
||||
|
||||
/**
|
||||
* 保存依赖关系
|
||||
* @param UserId
|
||||
* @param deptId
|
||||
*/
|
||||
void saveDeptRelation(@Param("user") String UserId,@Param("depts") Collection<String> deptId);
|
||||
|
||||
List<Map> getDeptRelation(@Param("deptIds") Collection<String> deptIds);
|
||||
|
||||
/**
|
||||
* 跟新sub_count字段
|
||||
* @param deptId
|
||||
* @return
|
||||
*/
|
||||
int updateSubCount(String deptId);
|
||||
|
||||
/**
|
||||
* 返回字符串列表 split = ,
|
||||
* @param pid
|
||||
* @return
|
||||
*/
|
||||
String findAllChild(String pid);
|
||||
|
||||
}
|
||||
|
||||
@@ -8,4 +8,29 @@
|
||||
(#{user},#{dept})
|
||||
</foreach>
|
||||
</insert>
|
||||
<update id="updateSubCount">
|
||||
update sys_dept set sub_count =
|
||||
(select m.count from (select count(*) count from sys_dept where pid = #{pid}) as m)
|
||||
where dept_id = #{pid}
|
||||
</update>
|
||||
<select id="findAllChild" resultType="java.lang.String">
|
||||
SELECT
|
||||
max(t3.childId) as deptIds
|
||||
from
|
||||
(
|
||||
select *,
|
||||
if( find_in_set(t1.pid, @p) > 0,@p := concat(@p,',',id),0 ) as childId
|
||||
from
|
||||
(select dept_id as id, pid from sys_dept t order by id) t1,
|
||||
(select @p := #{pid}) t2
|
||||
) t3
|
||||
where childId != '0'
|
||||
</select>
|
||||
<select id="getDeptRelation" resultType="java.util.Map">
|
||||
select * from sys_user_dept where dept_id in (
|
||||
<foreach collection="deptIds" separator="," item="dept">
|
||||
#{dept}
|
||||
</foreach>
|
||||
)
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.nl.system.service.dept.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -9,15 +11,22 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.utils.SecurityUtils;
|
||||
import org.nl.modules.common.utils.dto.CurrentUser;
|
||||
import org.nl.modules.system.domain.vo.DeptVo;
|
||||
import org.nl.modules.system.service.dto.DeptTree;
|
||||
import org.nl.modules.system.util.CopyUtil;
|
||||
import org.nl.modules.tools.IdUtil;
|
||||
import org.nl.modules.wql.core.bean.ResultBean;
|
||||
import org.nl.modules.wql.core.bean.WQLObject;
|
||||
import org.nl.system.service.dept.ISysDeptService;
|
||||
import org.nl.system.service.dept.dao.SysDept;
|
||||
import org.nl.system.service.dept.dao.mapper.SysDeptMapper;
|
||||
import org.nl.system.service.dept.dto.DeptQuery;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -103,4 +112,63 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
}
|
||||
sysDeptMapper.saveDeptRelation(userId,deptIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateDept(SysDept dept) {
|
||||
if (dept == null ||StringUtils.isEmpty(dept.getDeptId())){
|
||||
return;
|
||||
}
|
||||
this.updateById(dept);
|
||||
//删除节点信息
|
||||
sysDeptMapper.updateSubCount(dept.getDeptId());
|
||||
if (StringUtils.isNotEmpty(dept.getPid())){
|
||||
sysDeptMapper.updateSubCount(dept.getPid());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delateDept(Set<String> deptIds) {
|
||||
if (CollectionUtils.isEmpty(deptIds)){
|
||||
return;
|
||||
}
|
||||
verification(deptIds);
|
||||
Set<String> depts = new HashSet<>();
|
||||
for (String deptId : deptIds) {
|
||||
String allChild = sysDeptMapper.findAllChild(deptId);
|
||||
if (StringUtils.isNotEmpty(allChild)){
|
||||
String[] split = allChild.split(",");
|
||||
depts.addAll(Arrays.asList(split));
|
||||
}
|
||||
}
|
||||
this.remove(new QueryWrapper<SysDept>().in("dept_id", depts));
|
||||
for (String deptId : deptIds) {
|
||||
sysDeptMapper.updateSubCount(deptId);
|
||||
}
|
||||
}
|
||||
|
||||
private void verification(Set<String> depeIds) {
|
||||
if (!CollectionUtils.isEmpty(depeIds)){
|
||||
List<Map> deptRelation = sysDeptMapper.getDeptRelation(depeIds);
|
||||
if (!CollectionUtils.isEmpty(deptRelation)){
|
||||
throw new BadRequestException("部门存在绑定的人员,请先解绑人员对应部门");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void createDept(SysDept dept) {
|
||||
dept.setDeptId(IdUtil.getStringId());
|
||||
CurrentUser user = SecurityUtils.getCurrentUser();
|
||||
dept.setCreateId(user.getId());
|
||||
dept.setCreateName(user.getPresonName());
|
||||
dept.setCreateTime(new Date());
|
||||
this.save(dept);
|
||||
// 清理缓存
|
||||
if (StringUtils.isNotEmpty(dept.getPid())){
|
||||
sysDeptMapper.updateSubCount(dept.getPid());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.utils.SecurityUtils;
|
||||
import org.nl.system.service.menu.dao.mapper.SysMenuMapper;
|
||||
import org.nl.system.service.role.ISysRoleService;
|
||||
import org.nl.system.service.role.dao.SysRole;
|
||||
import org.nl.system.service.role.dao.mapper.SysRoleMapper;
|
||||
import org.nl.system.service.menu.dao.mapper.SysMenuMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
@@ -43,9 +43,9 @@
|
||||
<el-form-item label="部门名称" prop="name">
|
||||
<el-input v-model="form.name" style="width: 370px;" />
|
||||
</el-form-item>
|
||||
<el-form-item label="部门排序" prop="dept_sort">
|
||||
<el-form-item label="部门排序" prop="deptSort">
|
||||
<el-input-number
|
||||
v-model.number="form.dept_sort"
|
||||
v-model.number="form.deptSort"
|
||||
:min="0"
|
||||
:max="999"
|
||||
controls-position="right"
|
||||
@@ -94,7 +94,7 @@
|
||||
:load="getDeptDatas"
|
||||
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
|
||||
:data="crud.data"
|
||||
row-key="dept_id"
|
||||
row-key="deptId"
|
||||
@select="crud.selectChange"
|
||||
@select-all="crud.selectAllChange"
|
||||
@selection-change="crud.selectionChangeHandler"
|
||||
@@ -102,7 +102,7 @@
|
||||
<el-table-column :selectable="checkboxT" type="selection" width="55" />
|
||||
<!-- <el-table-column label="编码" prop="code" />-->
|
||||
<el-table-column label="名称" prop="name" />
|
||||
<el-table-column label="排序" prop="dept_sort" />
|
||||
<el-table-column label="排序" prop="deptSort" />
|
||||
<el-table-column label="状态" align="center" prop="isUsed">
|
||||
<template slot-scope="scope">
|
||||
<el-switch
|
||||
@@ -112,11 +112,11 @@
|
||||
inactive-color="#F56C6C"
|
||||
active-value="1"
|
||||
inactive-value="0"
|
||||
@change="changeEnabled(scope.row, scope.row.enabled,)"
|
||||
@change="changeEnabled(scope.row, scope.row.isUsed,)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="create_time" label="创建日期" />
|
||||
<el-table-column prop="createTime" label="创建日期" />
|
||||
<el-table-column
|
||||
v-permission="['admin','dept:edit','dept:del']"
|
||||
label="操作"
|
||||
@@ -152,7 +152,7 @@ const defaultForm = {
|
||||
isTop: '1',
|
||||
sub_count: 0,
|
||||
pid: null,
|
||||
dept_sort: 999,
|
||||
deptSort: 999,
|
||||
isUsed: '1',
|
||||
ext_id: null
|
||||
}
|
||||
@@ -160,7 +160,7 @@ export default {
|
||||
name: 'Dept',
|
||||
components: { Treeselect, crudOperation, rrOperation, udOperation },
|
||||
cruds() {
|
||||
return CRUD({ title: '部门', idField: 'dept_id', url: 'api/dept/vo', crudMethod: { ...crudDept }})
|
||||
return CRUD({ title: '部门', idField: 'deptId', url: 'api/dept/vo', crudMethod: { ...crudDept }})
|
||||
},
|
||||
mixins: [presenter(), header(), form(defaultForm), crud()],
|
||||
// 设置数据字典
|
||||
@@ -172,7 +172,7 @@ export default {
|
||||
name: [
|
||||
{ required: true, message: '请输入名称', trigger: 'blur' }
|
||||
],
|
||||
dept_sort: [
|
||||
deptSort: [
|
||||
{ required: true, message: '请输入序号', trigger: 'blur', type: 'number' }
|
||||
]
|
||||
},
|
||||
@@ -189,7 +189,7 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
getDeptDatas(tree, treeNode, resolve) {
|
||||
const params = { pid: tree.dept_id }
|
||||
const params = { pid: tree.deptId }
|
||||
setTimeout(() => {
|
||||
crudDept.getDeptvo(params).then(res => {
|
||||
resolve(res.content)
|
||||
@@ -240,7 +240,7 @@ export default {
|
||||
// 获取弹窗内部门数据
|
||||
loadDepts({ action, parentNode, callback }) {
|
||||
if (action === LOAD_CHILDREN_OPTIONS) {
|
||||
crudDept.getDeptvo({ isUsed: '1', pid: parentNode.dept_id }).then(res => {
|
||||
crudDept.getDeptvo({ isUsed: '1', pid: parentNode.deptId }).then(res => {
|
||||
parentNode.children = res.content.map(function(obj) {
|
||||
obj.children = null
|
||||
return obj
|
||||
@@ -287,7 +287,7 @@ export default {
|
||||
},
|
||||
normalizer(node) {
|
||||
return {
|
||||
id: node.dept_id,
|
||||
id: node.deptId,
|
||||
label: node.name,
|
||||
children: node.children
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user