diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index a6ba966..c848fd6 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -26,5 +26,17 @@ $ProjectFileDir$ + + h2.unified + true + org.h2.Driver + jdbc:h2:$PROJECT_DIR$/database + + + + + + $ProjectFileDir$ + \ No newline at end of file diff --git a/client/src/utils.js b/client/src/utils.js index 4a93dc7..9120c75 100644 --- a/client/src/utils.js +++ b/client/src/utils.js @@ -14,8 +14,7 @@ export function amisRender(target, amisJson) { information, { theme: 'antd', - enableAMISDebug: - information.debug, + enableAMISDebug: information.debug, }, ) } \ No newline at end of file diff --git a/client/src/views/management/Organization.vue b/client/src/views/management/Organization.vue index 6ec77f9..338c6d0 100644 --- a/client/src/views/management/Organization.vue +++ b/client/src/views/management/Organization.vue @@ -28,16 +28,11 @@ onMounted(() => { type: 'form', api: { method: 'post', - url: `${information.baseUrl}/jsonapi/organization`, - dataType: 'application/vnd.api+json', - headers: { - 'Content-Type': 'application/vnd.api+json', - }, + url: `${information.baseUrl}/graphql`, + dataType: 'application/json', data: { - type: 'user', - attributes: { - organizationName: '${organizationName}', - }, + // language=GraphQL + query: 'mutation {\n organization(op: UPSERT, data: {\n organizationName: "苹果"\n }) {\n edges {\n node {\n organizationId\n organizationName\n }\n }\n }\n}', }, }, body: [ diff --git a/src/main/java/com/lanyuanxiaoyao/server/ServerApplication.java b/src/main/java/com/lanyuanxiaoyao/server/ServerApplication.java index 75f542a..bfed158 100644 --- a/src/main/java/com/lanyuanxiaoyao/server/ServerApplication.java +++ b/src/main/java/com/lanyuanxiaoyao/server/ServerApplication.java @@ -1,6 +1,7 @@ package com.lanyuanxiaoyao.server; import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; @@ -31,4 +32,10 @@ public class ServerApplication { } }; } + + @Bean + public ApplicationRunner initialRunner() { + return args -> { + }; + } } diff --git a/src/main/java/com/lanyuanxiaoyao/server/entity/Department.java b/src/main/java/com/lanyuanxiaoyao/server/entity/Department.java index eaf1e13..c64981e 100644 --- a/src/main/java/com/lanyuanxiaoyao/server/entity/Department.java +++ b/src/main/java/com/lanyuanxiaoyao/server/entity/Department.java @@ -7,6 +7,7 @@ import jakarta.persistence.ConstraintMode; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.ForeignKey; +import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; @@ -16,6 +17,7 @@ import java.util.Set; import lombok.Getter; import lombok.Setter; import lombok.ToString; +import org.hibernate.annotations.GenericGenerator; /** * 组织 @@ -31,7 +33,8 @@ import lombok.ToString; @Include public class Department { @Id - @SnowflakeId.Generator + @GeneratedValue(generator = "snowflakeId") + @GenericGenerator(name = "snowflakeId", type = SnowflakeId.IdGenerator.class) private Long departmentId; private String departmentName; @@ -44,6 +47,7 @@ public class Department { private Set users; @ManyToOne + @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private Department parent; @OneToMany(fetch = FetchType.LAZY, mappedBy = "parent") @ToString.Exclude diff --git a/src/main/java/com/lanyuanxiaoyao/server/entity/Organization.java b/src/main/java/com/lanyuanxiaoyao/server/entity/Organization.java index c919362..0f58c2b 100644 --- a/src/main/java/com/lanyuanxiaoyao/server/entity/Organization.java +++ b/src/main/java/com/lanyuanxiaoyao/server/entity/Organization.java @@ -5,6 +5,7 @@ import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId; import com.yahoo.elide.annotation.Include; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; @@ -12,6 +13,7 @@ import java.util.Set; import lombok.Getter; import lombok.Setter; import lombok.ToString; +import org.hibernate.annotations.GenericGenerator; /** * 组织 @@ -27,7 +29,8 @@ import lombok.ToString; @Include public class Organization { @Id - @SnowflakeId.Generator + @GeneratedValue(generator = "snowflakeId") + @GenericGenerator(name = "snowflakeId", type = SnowflakeId.IdGenerator.class) private Long organizationId; private String organizationName; diff --git a/src/main/java/com/lanyuanxiaoyao/server/entity/User.java b/src/main/java/com/lanyuanxiaoyao/server/entity/User.java index af24799..b92eac8 100644 --- a/src/main/java/com/lanyuanxiaoyao/server/entity/User.java +++ b/src/main/java/com/lanyuanxiaoyao/server/entity/User.java @@ -6,14 +6,15 @@ import com.yahoo.elide.annotation.Include; import jakarta.persistence.ConstraintMode; import jakarta.persistence.Entity; import jakarta.persistence.ForeignKey; +import jakarta.persistence.GeneratedValue; 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; +import org.hibernate.annotations.GenericGenerator; /** * 用户 @@ -29,7 +30,8 @@ import lombok.ToString; @Include public class User { @Id - @SnowflakeId.Generator + @GeneratedValue(generator = "snowflakeId") + @GenericGenerator(name = "snowflakeId", type = SnowflakeId.IdGenerator.class) private Long userId; private String userCode; private String userNickname; diff --git a/src/test/resources/organization.http b/src/test/resources/organization.http index 563b0ca..262e0db 100644 --- a/src/test/resources/organization.http +++ b/src/test/resources/organization.http @@ -1,10 +1,20 @@ ### Create POST http://localhost:8080/jsonapi/organization +Content-Type: application/vnd.api+json + +{ + "data": { + "type": "organization", + "attributes": { + "organizationName": "苹果公司" + } + } +} + +### Create +POST http://localhost:8080/graphql Content-Type: application/json { - "type": "organization", - "attributes": { - "organizationName": "苹果公司" - } + "query": "mutation {organization(op: UPSERT, data: {organizationName: \"苹果\"}) {edges {node {organizationId organizationName}}}}" } \ No newline at end of file