开始尝试进行业务化模板

This commit is contained in:
2025-03-27 23:42:53 +08:00
parent 7c6c387a07
commit dd9f966597
11 changed files with 166 additions and 34 deletions

View File

@@ -5,5 +5,5 @@ package com.lanyuanxiaoyao.server.configuration;
* @version 20250327
*/
public interface Constants {
String DATABASE_TABLE_PREFIX = "system_";
String DATABASE_TABLE_PREFIX = "platform_";
}

View File

@@ -22,7 +22,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Slf4j
public class SnowflakeId {
@IdGeneratorType(IdGenerator.class)
@ValueGenerationType(generatedBy = IdGenerator.class)
@Retention(RUNTIME)
@Target({FIELD, METHOD})
public @interface Generator {

View File

@@ -2,6 +2,7 @@ package com.lanyuanxiaoyao.server.entity;
import com.lanyuanxiaoyao.server.configuration.Constants;
import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId;
import com.yahoo.elide.annotation.Include;
import jakarta.persistence.ConstraintMode;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
@@ -27,19 +28,24 @@ import lombok.ToString;
@ToString
@Entity
@Table(name = Constants.DATABASE_TABLE_PREFIX + "department")
@Include
public class Department {
@Id
@SnowflakeId.Generator
private Long departmentId;
private String departmentName;
@ManyToOne
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ManyToOne(optional = false)
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Organization organization;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "department")
@ToString.Exclude
private Set<User> users;
@ManyToOne
private Department parent;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "departmentParent")
@OneToMany(fetch = FetchType.LAZY, mappedBy = "parent")
@ToString.Exclude
private Set<Department> children;
}

View File

@@ -2,6 +2,7 @@ package com.lanyuanxiaoyao.server.entity;
import com.lanyuanxiaoyao.server.configuration.Constants;
import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId;
import com.yahoo.elide.annotation.Include;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
@@ -23,12 +24,17 @@ import lombok.ToString;
@ToString
@Entity
@Table(name = Constants.DATABASE_TABLE_PREFIX + "organization")
@Include
public class Organization {
@Id
@SnowflakeId.Generator
private Long organizationId;
private String organizationName;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "organization")
@ToString.Exclude
private Set<User> users;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "organization")
@ToString.Exclude
private Set<Department> departments;

View File

@@ -2,9 +2,15 @@ package com.lanyuanxiaoyao.server.entity;
import com.lanyuanxiaoyao.server.configuration.Constants;
import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId;
import com.yahoo.elide.annotation.Include;
import jakarta.persistence.ConstraintMode;
import jakarta.persistence.Entity;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@@ -20,11 +26,20 @@ import lombok.ToString;
@ToString
@Entity
@Table(name = Constants.DATABASE_TABLE_PREFIX + "user")
@Include
public class User {
@Id
@SnowflakeId.Generator
private Long userId;
private String userCode;
private String userNickName;
private String userNickname;
private String userSecret;
@ManyToOne
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Organization organization;
@ManyToOne
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Department department;
}

View File

@@ -0,0 +1,10 @@
### Create
POST http://localhost:8080/jsonapi/organization
Content-Type: application/json
{
"type": "organization",
"attributes": {
"organizationName": "苹果公司"
}
}