尝试增加组织架构
This commit is contained in:
1
.idea/compiler.xml
generated
1
.idea/compiler.xml
generated
@@ -8,6 +8,7 @@
|
|||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
<outputRelativeToContentRoot value="true" />
|
<outputRelativeToContentRoot value="true" />
|
||||||
<module name="spring-boot-server-template" />
|
<module name="spring-boot-server-template" />
|
||||||
|
<module name="spring-boot-apijson-server" />
|
||||||
</profile>
|
</profile>
|
||||||
</annotationProcessing>
|
</annotationProcessing>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.lanyuanxiaoyao.server.configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250327
|
||||||
|
*/
|
||||||
|
public interface Constants {
|
||||||
|
String DATABASE_TABLE_PREFIX = "system_";
|
||||||
|
}
|
||||||
@@ -1,11 +1,17 @@
|
|||||||
package com.lanyuanxiaoyao.server.configuration.database;
|
package com.lanyuanxiaoyao.server.configuration.database;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.hibernate.annotations.IdGeneratorType;
|
||||||
|
import org.hibernate.annotations.ValueGenerationType;
|
||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
import org.hibernate.id.IdentifierGenerator;
|
import org.hibernate.id.IdentifierGenerator;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
import static java.lang.annotation.ElementType.FIELD;
|
||||||
|
import static java.lang.annotation.ElementType.METHOD;
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用雪花算法作为ID生成器
|
* 使用雪花算法作为ID生成器
|
||||||
@@ -13,18 +19,26 @@ import org.slf4j.LoggerFactory;
|
|||||||
* @author lanyuanxiaoyao
|
* @author lanyuanxiaoyao
|
||||||
* @date 2024-11-14
|
* @date 2024-11-14
|
||||||
*/
|
*/
|
||||||
public class SnowflakeIdGenerator implements IdentifierGenerator {
|
@Slf4j
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SnowflakeIdGenerator.class);
|
public class SnowflakeId {
|
||||||
|
@IdGeneratorType(IdGenerator.class)
|
||||||
|
@ValueGenerationType(generatedBy = IdGenerator.class)
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
@Target({FIELD, METHOD})
|
||||||
|
public @interface Generator {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class IdGenerator implements IdentifierGenerator {
|
||||||
@Override
|
@Override
|
||||||
public Serializable generate(SharedSessionContractImplementor session, Object object) {
|
public Object generate(SharedSessionContractImplementor session, Object object) {
|
||||||
try {
|
try {
|
||||||
return Snowflake.next();
|
return Snowflake.next();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Generate snowflake id failed", e);
|
log.error("Generate snowflake id failed", e);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class Snowflake {
|
private static class Snowflake {
|
||||||
/**
|
/**
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.lanyuanxiaoyao.server.entity;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.server.configuration.Constants;
|
||||||
|
import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId;
|
||||||
|
import jakarta.persistence.ConstraintMode;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.ForeignKey;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.OneToMany;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import java.util.Set;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组织
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250327
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Entity
|
||||||
|
@Table(name = Constants.DATABASE_TABLE_PREFIX + "department")
|
||||||
|
public class Department {
|
||||||
|
@Id
|
||||||
|
@SnowflakeId.Generator
|
||||||
|
private Long departmentId;
|
||||||
|
private String departmentName;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||||
|
private Organization organization;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
private Department parent;
|
||||||
|
@OneToMany(fetch = FetchType.LAZY, mappedBy = "departmentParent")
|
||||||
|
@ToString.Exclude
|
||||||
|
private Set<Department> children;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.lanyuanxiaoyao.server.entity;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.server.configuration.Constants;
|
||||||
|
import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.OneToMany;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import java.util.Set;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组织
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250327
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Entity
|
||||||
|
@Table(name = Constants.DATABASE_TABLE_PREFIX + "organization")
|
||||||
|
public class Organization {
|
||||||
|
@Id
|
||||||
|
@SnowflakeId.Generator
|
||||||
|
private Long organizationId;
|
||||||
|
private String organizationName;
|
||||||
|
|
||||||
|
@OneToMany(fetch = FetchType.LAZY, mappedBy = "organization")
|
||||||
|
@ToString.Exclude
|
||||||
|
private Set<Department> departments;
|
||||||
|
}
|
||||||
30
src/main/java/com/lanyuanxiaoyao/server/entity/User.java
Normal file
30
src/main/java/com/lanyuanxiaoyao/server/entity/User.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package com.lanyuanxiaoyao.server.entity;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.server.configuration.Constants;
|
||||||
|
import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250327
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Entity
|
||||||
|
@Table(name = Constants.DATABASE_TABLE_PREFIX + "user")
|
||||||
|
public class User {
|
||||||
|
@Id
|
||||||
|
@SnowflakeId.Generator
|
||||||
|
private Long userId;
|
||||||
|
private String userCode;
|
||||||
|
private String userNickName;
|
||||||
|
private String userSecret;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user