添加部门相关功能代码
parent
95c44aa499
commit
eddea4349a
@ -0,0 +1,52 @@
|
||||
package com.supervision.knowsub.controller.system;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.supervision.knowsub.service.DeptManageService;
|
||||
import com.supervision.knowsub.vo.dept.DeptInfoReqVo;
|
||||
import com.supervision.knowsub.vo.dept.DeptInfoResVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Tag(name = "部门管理")
|
||||
@RestController
|
||||
@RequestMapping("/deptManage")
|
||||
@RequiredArgsConstructor
|
||||
public class DeptManageController {
|
||||
|
||||
|
||||
private final DeptManageService deptManageService;
|
||||
|
||||
@Operation(summary = "增加部门信息")
|
||||
@PostMapping("/save")
|
||||
public String saveDept(@RequestBody DeptInfoReqVo deptInfoReqVo) {
|
||||
|
||||
return deptManageService.saveDept(deptInfoReqVo);
|
||||
}
|
||||
|
||||
@Operation(summary = "修改部门信息")
|
||||
@PostMapping("/update")
|
||||
public void updateDept(@RequestBody DeptInfoReqVo deptInfoReqVo) {
|
||||
|
||||
deptManageService.updateDept(deptInfoReqVo);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除部门信息")
|
||||
@DeleteMapping("/delete")
|
||||
public Boolean deleteDept(@Parameter(name = "id") @RequestParam(name="id") String id) {
|
||||
|
||||
return deptManageService.deleteDept(id);
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询部门信息列表")
|
||||
@GetMapping("/list")
|
||||
public IPage<DeptInfoResVo> listDept(@Parameter(name = "deptName",description = "机构名称") @RequestParam(required = false) String deptName,
|
||||
@Parameter(name = "deptCode",description = "机构编码") @RequestParam(required = false) String deptCode,
|
||||
@Parameter(name = "pageNum",description = "页码") @RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@Parameter(name = "pageSize",description = "每页大小") @RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
|
||||
return deptManageService.pageListDept(deptName,deptCode,pageNum,pageSize);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.supervision.knowsub.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.supervision.knowsub.vo.dept.DeptInfoReqVo;
|
||||
import com.supervision.knowsub.vo.dept.DeptInfoResVo;
|
||||
|
||||
public interface DeptManageService {
|
||||
|
||||
String saveDept(DeptInfoReqVo deptInfoReqVo);
|
||||
|
||||
void updateDept(DeptInfoReqVo deptInfoReqVo);
|
||||
|
||||
Boolean deleteDept(String id);
|
||||
|
||||
IPage<DeptInfoResVo> pageListDept(String deptName, String deptCode, Integer pageNum, Integer pageSize);
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.supervision.knowsub.service;
|
||||
|
||||
import com.supervision.knowsub.model.SystemUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserManageService {
|
||||
|
||||
|
||||
List<SystemUser> listUserByDeptId(String deptId,Integer status);
|
||||
|
||||
|
||||
Long countUserByDeptId(String deptId,Integer status);
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.supervision.knowsub.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.supervision.knowsub.model.SystemDept;
|
||||
import com.supervision.knowsub.service.DeptManageService;
|
||||
import com.supervision.knowsub.service.SystemDeptService;
|
||||
import com.supervision.knowsub.service.UserManageService;
|
||||
import com.supervision.knowsub.vo.dept.DeptInfoReqVo;
|
||||
import com.supervision.knowsub.vo.dept.DeptInfoResVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeptManageServiceImpl implements DeptManageService {
|
||||
|
||||
private final SystemDeptService systemDeptService;
|
||||
|
||||
private final UserManageService userManageService;
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String saveDept(DeptInfoReqVo deptInfoReqVo) {
|
||||
|
||||
Assert.notEmpty(deptInfoReqVo.getDeptName(), "部门名称不能为空");
|
||||
Assert.notEmpty(deptInfoReqVo.getDeptCode(), "部门编码不能为空");
|
||||
|
||||
SystemDept systemDept = new SystemDept();
|
||||
systemDept.setDeptCode(deptInfoReqVo.getDeptCode());
|
||||
systemDept.setDeptName(deptInfoReqVo.getDeptName());
|
||||
systemDept.setParentDeptId(deptInfoReqVo.getParentDeptId());
|
||||
systemDept.setRemark(deptInfoReqVo.getRemark());
|
||||
|
||||
systemDeptService.save(systemDept);
|
||||
|
||||
return systemDept.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateDept(DeptInfoReqVo deptInfoReqVo) {
|
||||
|
||||
Assert.notEmpty(deptInfoReqVo.getId(), "id不能为空");
|
||||
Assert.notEmpty(deptInfoReqVo.getDeptName(), "部门名称不能为空");
|
||||
Assert.notEmpty(deptInfoReqVo.getDeptCode(), "部门编码不能为空");
|
||||
|
||||
SystemDept systemDept = new SystemDept();
|
||||
systemDept.setId(deptInfoReqVo.getId());
|
||||
systemDept.setDeptCode(deptInfoReqVo.getDeptCode());
|
||||
systemDept.setDeptName(deptInfoReqVo.getDeptName());
|
||||
systemDept.setParentDeptId(deptInfoReqVo.getParentDeptId());
|
||||
systemDept.setRemark(deptInfoReqVo.getRemark());
|
||||
|
||||
systemDeptService.updateById(systemDept);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean deleteDept(String id) {
|
||||
Long count = userManageService.countUserByDeptId(id, 0);
|
||||
Assert.isTrue(count == 0, "该部门下存在用户,不能删除");
|
||||
return systemDeptService.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<DeptInfoResVo> pageListDept(String deptName, String deptCode, Integer pageNum, Integer pageSize) {
|
||||
return systemDeptService.pageListDept(deptName, deptCode, pageNum, pageSize);
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.supervision.knowsub.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import com.supervision.knowsub.model.SystemUser;
|
||||
import com.supervision.knowsub.service.UserManageService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserManageServiceImpl implements UserManageService {
|
||||
|
||||
private final SystemUserServiceImpl systemUserService;
|
||||
|
||||
@Override
|
||||
public List<SystemUser> listUserByDeptId(String deptId,Integer status) {
|
||||
Assert.notEmpty(deptId,"部门id不能为空");
|
||||
return systemUserService.lambdaQuery().eq(SystemUser::getDeptId,deptId).
|
||||
eq(ObjUtil.isNull(status),SystemUser::getStatus,status).list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countUserByDeptId(String deptId,Integer status) {
|
||||
Assert.notEmpty(deptId,"部门id不能为空");
|
||||
return systemUserService.lambdaQuery().eq(SystemUser::getDeptId,deptId)
|
||||
.eq(ObjUtil.isNull(status),SystemUser::getStatus,status).count();
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.supervision.knowsub.vo.dept;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DeptInfoReqVo {
|
||||
|
||||
@Schema(description = "部门id")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "部门名称")
|
||||
private String deptName;
|
||||
|
||||
@Schema(description = "部门编码")
|
||||
private String deptCode;
|
||||
|
||||
@Schema(description = "父部门id")
|
||||
private String parentDeptId;
|
||||
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.supervision.knowsub.vo.dept;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DeptInfoResVo {
|
||||
|
||||
@Schema(description = "部门id")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "部门名称")
|
||||
private String deptName;
|
||||
|
||||
@Schema(description = "部门编码")
|
||||
private String deptCode;
|
||||
|
||||
@Schema(description = "父部门id")
|
||||
private String parentDeptId;
|
||||
|
||||
@Schema(description = "父部门名称")
|
||||
private String parentDeptName;
|
||||
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
}
|
Loading…
Reference in New Issue