1121人力资源部门管理开发
Some checks failed
Java CI with Maven / build (11) (push) Has been cancelled
Java CI with Maven / build (17) (push) Has been cancelled
Java CI with Maven / build (8) (push) Has been cancelled
yudao-ui-admin CI / build (14.x) (push) Has been cancelled
yudao-ui-admin CI / build (16.x) (push) Has been cancelled
Some checks failed
Java CI with Maven / build (11) (push) Has been cancelled
Java CI with Maven / build (17) (push) Has been cancelled
Java CI with Maven / build (8) (push) Has been cancelled
yudao-ui-admin CI / build (14.x) (push) Has been cancelled
yudao-ui-admin CI / build (16.x) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.department;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.department.vo.*;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.department.PeopleDepartmentDO;
|
||||
import cn.iocoder.yudao.module.erp.service.department.PeopleDepartmentService;
|
||||
|
||||
@Tag(name = "管理后台 - 部门管理")
|
||||
@RestController
|
||||
@RequestMapping("/erp/people-department")
|
||||
@Validated
|
||||
public class PeopleDepartmentController {
|
||||
|
||||
@Resource
|
||||
private PeopleDepartmentService peopleDepartmentService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建部门管理")
|
||||
@PreAuthorize("@ss.hasPermission('erp:people-department:create')")
|
||||
public CommonResult<Integer> createPeopleDepartment(@Valid @RequestBody PeopleDepartmentSaveReqVO createReqVO) {
|
||||
return success(peopleDepartmentService.createPeopleDepartment(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新部门管理")
|
||||
@PreAuthorize("@ss.hasPermission('erp:people-department:update')")
|
||||
public CommonResult<Boolean> updatePeopleDepartment(@Valid @RequestBody PeopleDepartmentSaveReqVO updateReqVO) {
|
||||
peopleDepartmentService.updatePeopleDepartment(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除部门管理")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('erp:people-department:delete')")
|
||||
public CommonResult<Boolean> deletePeopleDepartment(@RequestParam("id") Integer id) {
|
||||
peopleDepartmentService.deletePeopleDepartment(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得部门管理")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('erp:people-department:query')")
|
||||
public CommonResult<PeopleDepartmentRespVO> getPeopleDepartment(@RequestParam("id") Integer id) {
|
||||
PeopleDepartmentDO peopleDepartment = peopleDepartmentService.getPeopleDepartment(id);
|
||||
return success(BeanUtils.toBean(peopleDepartment, PeopleDepartmentRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得部门管理列表")
|
||||
@PreAuthorize("@ss.hasPermission('erp:people-department:query')")
|
||||
public CommonResult<List<PeopleDepartmentRespVO>> getPeopleDepartmentList(@Valid PeopleDepartmentListReqVO listReqVO) {
|
||||
List<PeopleDepartmentDO> list = peopleDepartmentService.getPeopleDepartmentList(listReqVO);
|
||||
return success(BeanUtils.toBean(list, PeopleDepartmentRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出部门管理 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('erp:people-department:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportPeopleDepartmentExcel(@Valid PeopleDepartmentListReqVO listReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<PeopleDepartmentDO> list = peopleDepartmentService.getPeopleDepartmentList(listReqVO);
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "部门管理.xls", "数据", PeopleDepartmentRespVO.class,
|
||||
BeanUtils.toBean(list, PeopleDepartmentRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.department.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import java.time.LocalDateTime;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 部门管理列表 Request VO")
|
||||
@Data
|
||||
public class PeopleDepartmentListReqVO {
|
||||
|
||||
@Schema(description = "上级部门 ID", example = "30109")
|
||||
private Integer parentDepartmentId;
|
||||
|
||||
@Schema(description = "部门名称(如\"人力资源部\")", example = "王五")
|
||||
private String departmentName;
|
||||
|
||||
@Schema(description = "部门地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "部门电话")
|
||||
private String phone;
|
||||
|
||||
@Schema(description = "部门备注")
|
||||
private String remarks;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
@Schema(description = "开启状态", example = "2")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.department.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import cn.idev.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 部门管理 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class PeopleDepartmentRespVO {
|
||||
|
||||
@Schema(description = "部门唯一标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "7994")
|
||||
@ExcelProperty("部门唯一标识")
|
||||
private Integer id;
|
||||
|
||||
@Schema(description = "上级部门 ID", example = "30109")
|
||||
@ExcelProperty("上级部门 ID")
|
||||
private Integer parentDepartmentId;
|
||||
|
||||
@Schema(description = "部门名称(如\"人力资源部\")", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||
@ExcelProperty("部门名称(如\"人力资源部\")")
|
||||
private String departmentName;
|
||||
|
||||
@Schema(description = "部门地址")
|
||||
@ExcelProperty("部门地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "部门电话")
|
||||
@ExcelProperty("部门电话")
|
||||
private String phone;
|
||||
|
||||
@Schema(description = "部门备注")
|
||||
@ExcelProperty("部门备注")
|
||||
private String remarks;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "开启状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty("开启状态")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.department.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 部门管理新增/修改 Request VO")
|
||||
@Data
|
||||
public class PeopleDepartmentSaveReqVO {
|
||||
|
||||
@Schema(description = "部门唯一标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "7994")
|
||||
private Integer id;
|
||||
|
||||
@Schema(description = "上级部门 ID", example = "30109")
|
||||
private Integer parentDepartmentId;
|
||||
|
||||
@Schema(description = "部门名称(如\"人力资源部\")", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||
@NotEmpty(message = "部门名称(如\"人力资源部\")不能为空")
|
||||
private String departmentName;
|
||||
|
||||
@Schema(description = "部门地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "部门电话")
|
||||
private String phone;
|
||||
|
||||
@Schema(description = "部门备注")
|
||||
private String remarks;
|
||||
|
||||
@Schema(description = "开启状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@NotNull(message = "开启状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -21,4 +21,5 @@ public class ErpWarehousePageReqVO extends PageParam {
|
||||
@InEnum(CommonStatusEnum.class)
|
||||
private Integer status;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.dataobject.department;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 部门管理 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("erp_department")
|
||||
@KeySequence("erp_department_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PeopleDepartmentDO extends BaseDO {
|
||||
|
||||
public static final Integer PARENT_DEPARTMENT_ID_ROOT = 0;
|
||||
|
||||
/**
|
||||
* 部门唯一标识
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 上级部门 ID
|
||||
*/
|
||||
private Integer parentDepartmentId;
|
||||
/**
|
||||
* 部门名称(如"人力资源部""销售部")
|
||||
*/
|
||||
private String departmentName;
|
||||
/**
|
||||
* 部门地址
|
||||
*/
|
||||
private String address;
|
||||
/**
|
||||
* 部门电话
|
||||
*/
|
||||
private String phone;
|
||||
/**
|
||||
* 部门备注
|
||||
*/
|
||||
private String remarks;
|
||||
/**
|
||||
* 开启状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.mysql.department;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.department.PeopleDepartmentDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.department.vo.*;
|
||||
|
||||
/**
|
||||
* 部门管理 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface PeopleDepartmentMapper extends BaseMapperX<PeopleDepartmentDO> {
|
||||
|
||||
default List<PeopleDepartmentDO> selectList(PeopleDepartmentListReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<PeopleDepartmentDO>()
|
||||
.eqIfPresent(PeopleDepartmentDO::getParentDepartmentId, reqVO.getParentDepartmentId())
|
||||
.likeIfPresent(PeopleDepartmentDO::getDepartmentName, reqVO.getDepartmentName())
|
||||
.eqIfPresent(PeopleDepartmentDO::getAddress, reqVO.getAddress())
|
||||
.eqIfPresent(PeopleDepartmentDO::getPhone, reqVO.getPhone())
|
||||
.eqIfPresent(PeopleDepartmentDO::getRemarks, reqVO.getRemarks())
|
||||
.betweenIfPresent(PeopleDepartmentDO::getCreateTime, reqVO.getCreateTime())
|
||||
.eqIfPresent(PeopleDepartmentDO::getStatus, reqVO.getStatus())
|
||||
.orderByDesc(PeopleDepartmentDO::getId));
|
||||
}
|
||||
|
||||
default PeopleDepartmentDO selectByParentDepartmentIdAndDepartmentName(Integer parentDepartmentId, String departmentName) {
|
||||
return selectOne(PeopleDepartmentDO::getParentDepartmentId, parentDepartmentId, PeopleDepartmentDO::getDepartmentName, departmentName);
|
||||
}
|
||||
|
||||
default Long selectCountByParentDepartmentId(Integer parentDepartmentId) {
|
||||
return selectCount(PeopleDepartmentDO::getParentDepartmentId, parentDepartmentId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -168,4 +168,12 @@ ErrorCode PURCHASE_ORDER_ITEM_RETURN_FAIL_IN_EXCEED = new ErrorCode(1_030_101_00
|
||||
ErrorCode FINANCE_RECEIPT_NO_EXISTS = new ErrorCode(1_030_602_004, "生成收款单号失败,请重新提交");
|
||||
ErrorCode FINANCE_RECEIPT_UPDATE_FAIL_APPROVE = new ErrorCode(1_030_602_005, "收款单({})已审核,无法修改");
|
||||
|
||||
// ========== ERP 部门管理 1-030-700-000 ==========
|
||||
ErrorCode PEOPLE_DEPARTMENT_NOT_EXISTS = new ErrorCode(1_030_700_000, "部门管理不存在");
|
||||
ErrorCode PEOPLE_DEPARTMENT_EXITS_CHILDREN = new ErrorCode(1_030_700_001, "存在子部门管理,无法删除");
|
||||
ErrorCode PEOPLE_DEPARTMENT_PARENT_NOT_EXITS = new ErrorCode(1_030_700_002,"父级部门管理不存在");
|
||||
ErrorCode PEOPLE_DEPARTMENT_PARENT_ERROR = new ErrorCode(1_030_700_003, "不能设置自己为父部门管理");
|
||||
ErrorCode PEOPLE_DEPARTMENT_DEPARTMENT_NAME_DUPLICATE = new ErrorCode(1_030_700_004, "已经存在该部门名称(如\"人力资源部\"\"销售部\")的部门管理");
|
||||
ErrorCode PEOPLE_DEPARTMENT_PARENT_IS_CHILD = new ErrorCode(1_030_700_005, "不能设置自己的子PeopleDepartment为父PeopleDepartment");
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package cn.iocoder.yudao.module.erp.service.department;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.department.vo.*;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.department.PeopleDepartmentDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 部门管理 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface PeopleDepartmentService {
|
||||
|
||||
/**
|
||||
* 创建部门管理
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Integer createPeopleDepartment(@Valid PeopleDepartmentSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新部门管理
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updatePeopleDepartment(@Valid PeopleDepartmentSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除部门管理
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deletePeopleDepartment(Integer id);
|
||||
|
||||
|
||||
/**
|
||||
* 获得部门管理
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 部门管理
|
||||
*/
|
||||
PeopleDepartmentDO getPeopleDepartment(Integer id);
|
||||
|
||||
/**
|
||||
* 获得部门管理列表
|
||||
*
|
||||
* @param listReqVO 查询条件
|
||||
* @return 部门管理列表
|
||||
*/
|
||||
List<PeopleDepartmentDO> getPeopleDepartmentList(PeopleDepartmentListReqVO listReqVO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package cn.iocoder.yudao.module.erp.service.department;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.department.vo.*;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.department.PeopleDepartmentDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.department.PeopleDepartmentMapper;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 部门管理 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class PeopleDepartmentServiceImpl implements PeopleDepartmentService {
|
||||
|
||||
@Resource
|
||||
private PeopleDepartmentMapper peopleDepartmentMapper;
|
||||
|
||||
@Override
|
||||
public Integer createPeopleDepartment(PeopleDepartmentSaveReqVO createReqVO) {
|
||||
// 校验上级部门 ID的有效性
|
||||
validateParentPeopleDepartment(null, createReqVO.getParentDepartmentId());
|
||||
// 校验部门名称(如"人力资源部""销售部")的唯一性
|
||||
validatePeopleDepartmentDepartmentNameUnique(null, createReqVO.getParentDepartmentId(), createReqVO.getDepartmentName());
|
||||
|
||||
// 插入
|
||||
PeopleDepartmentDO peopleDepartment = BeanUtils.toBean(createReqVO, PeopleDepartmentDO.class);
|
||||
peopleDepartmentMapper.insert(peopleDepartment);
|
||||
|
||||
// 返回
|
||||
return peopleDepartment.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePeopleDepartment(PeopleDepartmentSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validatePeopleDepartmentExists(updateReqVO.getId());
|
||||
// 校验上级部门 ID的有效性
|
||||
validateParentPeopleDepartment(updateReqVO.getId(), updateReqVO.getParentDepartmentId());
|
||||
// 校验部门名称(如"人力资源部""销售部")的唯一性
|
||||
validatePeopleDepartmentDepartmentNameUnique(updateReqVO.getId(), updateReqVO.getParentDepartmentId(), updateReqVO.getDepartmentName());
|
||||
|
||||
// 更新
|
||||
PeopleDepartmentDO updateObj = BeanUtils.toBean(updateReqVO, PeopleDepartmentDO.class);
|
||||
peopleDepartmentMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePeopleDepartment(Integer id) {
|
||||
// 校验存在
|
||||
validatePeopleDepartmentExists(id);
|
||||
// 校验是否有子部门管理
|
||||
if (peopleDepartmentMapper.selectCountByParentDepartmentId(id) > 0) {
|
||||
throw exception(PEOPLE_DEPARTMENT_EXITS_CHILDREN);
|
||||
}
|
||||
// 删除
|
||||
peopleDepartmentMapper.deleteById(id);
|
||||
}
|
||||
|
||||
|
||||
private void validatePeopleDepartmentExists(Integer id) {
|
||||
if (peopleDepartmentMapper.selectById(id) == null) {
|
||||
throw exception(PEOPLE_DEPARTMENT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateParentPeopleDepartment(Integer id, Integer parentDepartmentId) {
|
||||
if (parentDepartmentId == null || PeopleDepartmentDO.PARENT_DEPARTMENT_ID_ROOT.equals(parentDepartmentId)) {
|
||||
return;
|
||||
}
|
||||
// 1. 不能设置自己为父部门管理
|
||||
if (Objects.equals(id, parentDepartmentId)) {
|
||||
throw exception(PEOPLE_DEPARTMENT_PARENT_ERROR);
|
||||
}
|
||||
// 2. 父部门管理不存在
|
||||
PeopleDepartmentDO parentPeopleDepartment = peopleDepartmentMapper.selectById(parentDepartmentId);
|
||||
if (parentPeopleDepartment == null) {
|
||||
throw exception(PEOPLE_DEPARTMENT_PARENT_NOT_EXITS);
|
||||
}
|
||||
// 3. 递归校验父部门管理,如果父部门管理是自己的子部门管理,则报错,避免形成环路
|
||||
if (id == null) { // id 为空,说明新增,不需要考虑环路
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < Short.MAX_VALUE; i++) {
|
||||
// 3.1 校验环路
|
||||
parentDepartmentId = parentPeopleDepartment.getParentDepartmentId();
|
||||
if (Objects.equals(id, parentDepartmentId)) {
|
||||
throw exception(PEOPLE_DEPARTMENT_PARENT_IS_CHILD);
|
||||
}
|
||||
// 3.2 继续递归下一级父部门管理
|
||||
if (parentDepartmentId == null || PeopleDepartmentDO.PARENT_DEPARTMENT_ID_ROOT.equals(parentDepartmentId)) {
|
||||
break;
|
||||
}
|
||||
parentPeopleDepartment = peopleDepartmentMapper.selectById(parentDepartmentId);
|
||||
if (parentPeopleDepartment == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validatePeopleDepartmentDepartmentNameUnique(Integer id, Integer parentDepartmentId, String departmentName) {
|
||||
PeopleDepartmentDO peopleDepartment = peopleDepartmentMapper.selectByParentDepartmentIdAndDepartmentName(parentDepartmentId, departmentName);
|
||||
if (peopleDepartment == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的部门管理
|
||||
if (id == null) {
|
||||
throw exception(PEOPLE_DEPARTMENT_DEPARTMENT_NAME_DUPLICATE);
|
||||
}
|
||||
if (!Objects.equals(peopleDepartment.getId(), id)) {
|
||||
throw exception(PEOPLE_DEPARTMENT_DEPARTMENT_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PeopleDepartmentDO getPeopleDepartment(Integer id) {
|
||||
return peopleDepartmentMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PeopleDepartmentDO> getPeopleDepartmentList(PeopleDepartmentListReqVO listReqVO) {
|
||||
return peopleDepartmentMapper.selectList(listReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.yudao.module.erp.dal.mysql.warehouse.WarehouseMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user