From a74abce2d64fef0282046f4536f485ffee0fd018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Wed, 6 May 2026 19:17:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(dept):=20=E6=B7=BB=E5=8A=A0=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E7=AE=A1=E7=90=86=E6=95=B0=E6=8D=AE=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 SysDept 领域模型(manage-sys) - 新增 ISysDeptRepository 接口(manage-sys) - 新增 SysDeptEntity 实体类(manage-db) - 新增 SysDeptDao R2DBC 接口(manage-db) - 新增 SysDeptConverter 转换器(manage-db) - 新增 SysDeptRepository 实现类(manage-db) - 新增 V6 Flyway 迁移脚本创建 sys_dept 表 --- .../manage/db/converter/SysDeptConverter.java | 61 +++++++++++++++ .../cn/novalon/manage/db/dao/SysDeptDao.java | 22 ++++++ .../manage/db/entity/SysDeptEntity.java | 77 +++++++++++++++++++ .../db/repository/SysDeptRepository.java | 58 ++++++++++++++ .../migration/V6__Create_sys_dept_table.sql | 18 +++++ .../manage/sys/core/domain/SysDept.java | 47 +++++++++++ .../core/repository/ISysDeptRepository.java | 20 +++++ 7 files changed, 303 insertions(+) create mode 100644 novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/converter/SysDeptConverter.java create mode 100644 novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/dao/SysDeptDao.java create mode 100644 novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/entity/SysDeptEntity.java create mode 100644 novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/repository/SysDeptRepository.java create mode 100644 novalon-manage-api/manage-db/src/main/resources/db/migration/V6__Create_sys_dept_table.sql create mode 100644 novalon-manage-api/manage-sys/src/main/java/cn/novalon/manage/sys/core/domain/SysDept.java create mode 100644 novalon-manage-api/manage-sys/src/main/java/cn/novalon/manage/sys/core/repository/ISysDeptRepository.java diff --git a/novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/converter/SysDeptConverter.java b/novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/converter/SysDeptConverter.java new file mode 100644 index 0000000..8dd52fa --- /dev/null +++ b/novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/converter/SysDeptConverter.java @@ -0,0 +1,61 @@ +package cn.novalon.manage.db.converter; + +import cn.novalon.manage.sys.core.domain.SysDept; +import cn.novalon.manage.db.entity.SysDeptEntity; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.stream.Collectors; + +@Component +public class SysDeptConverter { + + public SysDept toDomain(SysDeptEntity entity) { + if (entity == null) { + return null; + } + SysDept domain = new SysDept(); + domain.setId(entity.getId()); + domain.setParentId(entity.getParentId()); + domain.setDeptName(entity.getDeptName()); + domain.setOrderNum(entity.getOrderNum()); + domain.setLeader(entity.getLeader()); + domain.setPhone(entity.getPhone()); + domain.setEmail(entity.getEmail()); + domain.setStatus(entity.getStatus()); + domain.setCreateBy(entity.getCreateBy()); + domain.setUpdateBy(entity.getUpdateBy()); + domain.setCreatedAt(entity.getCreatedAt()); + domain.setUpdatedAt(entity.getUpdatedAt()); + domain.setDeletedAt(entity.getDeletedAt()); + return domain; + } + + public SysDeptEntity toEntity(SysDept domain) { + if (domain == null) { + return null; + } + SysDeptEntity entity = new SysDeptEntity(); + entity.setId(domain.getId()); + entity.setParentId(domain.getParentId()); + entity.setDeptName(domain.getDeptName()); + entity.setOrderNum(domain.getOrderNum()); + entity.setLeader(domain.getLeader()); + entity.setPhone(domain.getPhone()); + entity.setEmail(domain.getEmail()); + entity.setStatus(domain.getStatus()); + entity.setCreateBy(domain.getCreateBy()); + entity.setUpdateBy(domain.getUpdateBy()); + entity.setCreatedAt(domain.getCreatedAt()); + entity.setUpdatedAt(domain.getUpdatedAt()); + entity.setDeletedAt(domain.getDeletedAt()); + return entity; + } + + public List toDomainList(List entities) { + if (entities == null) { + return null; + } + return entities.stream().map(this::toDomain).collect(Collectors.toList()); + } +} diff --git a/novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/dao/SysDeptDao.java b/novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/dao/SysDeptDao.java new file mode 100644 index 0000000..173ec5c --- /dev/null +++ b/novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/dao/SysDeptDao.java @@ -0,0 +1,22 @@ +package cn.novalon.manage.db.dao; + +import cn.novalon.manage.db.entity.SysDeptEntity; +import org.springframework.data.domain.Sort; +import org.springframework.data.r2dbc.repository.R2dbcRepository; +import org.springframework.stereotype.Repository; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@Repository +public interface SysDeptDao extends R2dbcRepository { + + Flux findByDeletedAtIsNull(Sort sort); + + Flux findByParentIdAndDeletedAtIsNull(Long parentId, Sort sort); + + Mono findByIdAndDeletedAtIsNull(Long id); + + Mono countByParentIdAndDeletedAtIsNull(Long parentId); + + Mono deleteByIdAndDeletedAtIsNull(Long id); +} diff --git a/novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/entity/SysDeptEntity.java b/novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/entity/SysDeptEntity.java new file mode 100644 index 0000000..a3006a1 --- /dev/null +++ b/novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/entity/SysDeptEntity.java @@ -0,0 +1,77 @@ +package cn.novalon.manage.db.entity; + +import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.Column; +import org.springframework.data.relational.core.mapping.Table; + +import java.time.LocalDateTime; + +@Table("sys_dept") +public class SysDeptEntity { + + @Id + private Long id; + + @Column("parent_id") + private Long parentId; + + @Column("dept_name") + private String deptName; + + @Column("order_num") + private Integer orderNum; + + @Column("leader") + private String leader; + + @Column("phone") + private String phone; + + @Column("email") + private String email; + + @Column("status") + private Integer status; + + @Column("create_by") + private String createBy; + + @Column("update_by") + private String updateBy; + + @Column("created_at") + private LocalDateTime createdAt; + + @Column("updated_at") + private LocalDateTime updatedAt; + + @Column("deleted_at") + private LocalDateTime deletedAt; + + public Long getId() { return id; } + public void setId(Long id) { this.id = id; } + public Long getParentId() { return parentId; } + public void setParentId(Long parentId) { this.parentId = parentId; } + public String getDeptName() { return deptName; } + public void setDeptName(String deptName) { this.deptName = deptName; } + public Integer getOrderNum() { return orderNum; } + public void setOrderNum(Integer orderNum) { this.orderNum = orderNum; } + public String getLeader() { return leader; } + public void setLeader(String leader) { this.leader = leader; } + public String getPhone() { return phone; } + public void setPhone(String phone) { this.phone = phone; } + public String getEmail() { return email; } + public void setEmail(String email) { this.email = email; } + public Integer getStatus() { return status; } + public void setStatus(Integer status) { this.status = status; } + public String getCreateBy() { return createBy; } + public void setCreateBy(String createBy) { this.createBy = createBy; } + public String getUpdateBy() { return updateBy; } + public void setUpdateBy(String updateBy) { this.updateBy = updateBy; } + public LocalDateTime getCreatedAt() { return createdAt; } + public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; } + public LocalDateTime getUpdatedAt() { return updatedAt; } + public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; } + public LocalDateTime getDeletedAt() { return deletedAt; } + public void setDeletedAt(LocalDateTime deletedAt) { this.deletedAt = deletedAt; } +} diff --git a/novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/repository/SysDeptRepository.java b/novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/repository/SysDeptRepository.java new file mode 100644 index 0000000..df05111 --- /dev/null +++ b/novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/repository/SysDeptRepository.java @@ -0,0 +1,58 @@ +package cn.novalon.manage.db.repository; + +import cn.novalon.manage.sys.core.domain.SysDept; +import cn.novalon.manage.sys.core.repository.ISysDeptRepository; +import cn.novalon.manage.db.converter.SysDeptConverter; +import cn.novalon.manage.db.dao.SysDeptDao; +import cn.novalon.manage.db.entity.SysDeptEntity; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Repository; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@Repository +public class SysDeptRepository implements ISysDeptRepository { + + private final SysDeptDao sysDeptDao; + private final SysDeptConverter sysDeptConverter; + + public SysDeptRepository(SysDeptDao sysDeptDao, SysDeptConverter sysDeptConverter) { + this.sysDeptDao = sysDeptDao; + this.sysDeptConverter = sysDeptConverter; + } + + @Override + public Flux findAll() { + return sysDeptDao.findByDeletedAtIsNull(Sort.by(Sort.Direction.ASC, "order_num")) + .map(sysDeptConverter::toDomain); + } + + @Override + public Flux findByParentId(Long parentId) { + return sysDeptDao.findByParentIdAndDeletedAtIsNull(parentId, Sort.by(Sort.Direction.ASC, "order_num")) + .map(sysDeptConverter::toDomain); + } + + @Override + public Mono findById(Long id) { + return sysDeptDao.findByIdAndDeletedAtIsNull(id) + .map(sysDeptConverter::toDomain); + } + + @Override + public Mono countByParentId(Long parentId) { + return sysDeptDao.countByParentIdAndDeletedAtIsNull(parentId); + } + + @Override + public Mono save(SysDept dept) { + SysDeptEntity entity = sysDeptConverter.toEntity(dept); + return sysDeptDao.save(entity) + .map(sysDeptConverter::toDomain); + } + + @Override + public Mono deleteById(Long id) { + return sysDeptDao.deleteByIdAndDeletedAtIsNull(id); + } +} diff --git a/novalon-manage-api/manage-db/src/main/resources/db/migration/V6__Create_sys_dept_table.sql b/novalon-manage-api/manage-db/src/main/resources/db/migration/V6__Create_sys_dept_table.sql new file mode 100644 index 0000000..cad1673 --- /dev/null +++ b/novalon-manage-api/manage-db/src/main/resources/db/migration/V6__Create_sys_dept_table.sql @@ -0,0 +1,18 @@ +CREATE TABLE IF NOT EXISTS sys_dept ( + id BIGSERIAL PRIMARY KEY, + parent_id BIGINT DEFAULT 0, + dept_name VARCHAR(100) NOT NULL, + order_num INTEGER DEFAULT 0, + leader VARCHAR(50), + phone VARCHAR(20), + email VARCHAR(100), + status INTEGER DEFAULT 1, + create_by VARCHAR(50), + update_by VARCHAR(50), + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + deleted_at TIMESTAMP +); + +CREATE INDEX IF NOT EXISTS idx_sys_dept_parent_id ON sys_dept(parent_id); +CREATE INDEX IF NOT EXISTS idx_sys_dept_status ON sys_dept(status); diff --git a/novalon-manage-api/manage-sys/src/main/java/cn/novalon/manage/sys/core/domain/SysDept.java b/novalon-manage-api/manage-sys/src/main/java/cn/novalon/manage/sys/core/domain/SysDept.java new file mode 100644 index 0000000..c8d70e5 --- /dev/null +++ b/novalon-manage-api/manage-sys/src/main/java/cn/novalon/manage/sys/core/domain/SysDept.java @@ -0,0 +1,47 @@ +package cn.novalon.manage.sys.core.domain; + +import java.time.LocalDateTime; + +public class SysDept { + + private Long id; + private Long parentId; + private String deptName; + private Integer orderNum; + private String leader; + private String phone; + private String email; + private Integer status; + private String createBy; + private String updateBy; + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + private LocalDateTime deletedAt; + + public Long getId() { return id; } + public void setId(Long id) { this.id = id; } + public Long getParentId() { return parentId; } + public void setParentId(Long parentId) { this.parentId = parentId; } + public String getDeptName() { return deptName; } + public void setDeptName(String deptName) { this.deptName = deptName; } + public Integer getOrderNum() { return orderNum; } + public void setOrderNum(Integer orderNum) { this.orderNum = orderNum; } + public String getLeader() { return leader; } + public void setLeader(String leader) { this.leader = leader; } + public String getPhone() { return phone; } + public void setPhone(String phone) { this.phone = phone; } + public String getEmail() { return email; } + public void setEmail(String email) { this.email = email; } + public Integer getStatus() { return status; } + public void setStatus(Integer status) { this.status = status; } + public String getCreateBy() { return createBy; } + public void setCreateBy(String createBy) { this.createBy = createBy; } + public String getUpdateBy() { return updateBy; } + public void setUpdateBy(String updateBy) { this.updateBy = updateBy; } + public LocalDateTime getCreatedAt() { return createdAt; } + public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; } + public LocalDateTime getUpdatedAt() { return updatedAt; } + public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; } + public LocalDateTime getDeletedAt() { return deletedAt; } + public void setDeletedAt(LocalDateTime deletedAt) { this.deletedAt = deletedAt; } +} diff --git a/novalon-manage-api/manage-sys/src/main/java/cn/novalon/manage/sys/core/repository/ISysDeptRepository.java b/novalon-manage-api/manage-sys/src/main/java/cn/novalon/manage/sys/core/repository/ISysDeptRepository.java new file mode 100644 index 0000000..01d6ed9 --- /dev/null +++ b/novalon-manage-api/manage-sys/src/main/java/cn/novalon/manage/sys/core/repository/ISysDeptRepository.java @@ -0,0 +1,20 @@ +package cn.novalon.manage.sys.core.repository; + +import cn.novalon.manage.sys.core.domain.SysDept; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public interface ISysDeptRepository { + + Flux findAll(); + + Flux findByParentId(Long parentId); + + Mono findById(Long id); + + Mono countByParentId(Long parentId); + + Mono save(SysDept dept); + + Mono deleteById(Long id); +}