chore: 调整项目结构
diff --git a/admin-sa/base/domain/.gitignore b/admin-sa/base/domain/.gitignore
new file mode 100644
index 0000000..b83d222
--- /dev/null
+++ b/admin-sa/base/domain/.gitignore
@@ -0,0 +1 @@
+/target/
diff --git a/admin-sa/base/domain/pom.xml b/admin-sa/base/domain/pom.xml
new file mode 100644
index 0000000..a3e258b
--- /dev/null
+++ b/admin-sa/base/domain/pom.xml
@@ -0,0 +1,99 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>com.supwisdom.institute</groupId>
+ <artifactId>sw-backend-admin-sa-parent</artifactId>
+ <version>0.0.2-SNAPSHOT</version>
+ <relativePath>../../</relativePath>
+ </parent>
+
+ <groupId>com.supwisdom.institute</groupId>
+ <artifactId>sw-backend-admin-base-domain</artifactId>
+ <version>0.0.2-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>Supwisdom Backend Framework Admin Base Domain</name>
+ <description>Supwisdom Backend Framework Admin Base Domain project</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ </dependency>
+
+
+ <dependency>
+ <groupId>com.supwisdom.institute</groupId>
+ <artifactId>sw-backend-common-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.supwisdom.institute</groupId>
+ <artifactId>sw-backend-common-utils</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.supwisdom.institute</groupId>
+ <artifactId>sw-backend-common-framework</artifactId>
+ </dependency>
+
+
+ <dependency>
+ <groupId>com.supwisdom.infras</groupId>
+ <artifactId>infras-data-jpa</artifactId>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/.gitkeep b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/.gitkeep
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Account.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Account.java
new file mode 100644
index 0000000..6cca9f9
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Account.java
@@ -0,0 +1,164 @@
+package com.supwisdom.institute.backend.base.domain.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import com.supwisdom.institute.backend.common.framework.entity.ABaseEntity;
+
+@Entity
+@Table(name = "TB_BASE_ACCOUNT")
+public class Account extends ABaseEntity {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7955624268022038897L;
+
+ public static final String STATUS_ENABLED = "1";
+ public static final String STATUS_DISABLED = "0";
+
+
+ /**
+ * 用户名
+ */
+ @Column(name = "USERNAME", unique = true)
+ private String username;
+
+ /**
+ * 密码
+ */
+ @Column(name = "PASSWORD")
+ private String password;
+
+ /**
+ * 是否可用,1 可用,0 不可用,默认:1
+ */
+ @Column(name = "ENABLED")
+ private Boolean enabled;
+ /**
+ * 账号未过期,1 未过期,0 过期,默认:1
+ */
+ @Column(name = "ACCOUNT_NON_EXPIRED")
+ private Boolean accountNonExpired;
+ /**
+ * 账号未锁定,1 未锁定,0 锁定,默认:1
+ */
+ @Column(name = "ACCOUNT_NON_LOCKED")
+ private Boolean accountNonLocked;
+ /**
+ * 密码未过期,1 未过期,0 过期,默认:1
+ */
+ @Column(name = "CREDENTIALS_NON_EXPIRED")
+ private Boolean credentialsNonExpired;
+
+ /**
+ * 姓名
+ */
+ @Column(name = "NAME")
+ private String name;
+
+ /**
+ * 备注
+ */
+ @Column(name = "MEMO")
+ private String memo;
+
+ /**
+ * 状态(1 启用,0 停用)
+ */
+ @Column(name = "STATUS")
+ private String status;
+
+ /**
+ * 登录手机
+ */
+ @Column(name = "MOBILE", nullable = true)
+ private String mobile;
+ /**
+ * 登录邮箱
+ */
+ @Column(name = "EMAIL", nullable = true)
+ private String email;
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public Boolean getEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(Boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public Boolean getAccountNonExpired() {
+ return accountNonExpired;
+ }
+
+ public void setAccountNonExpired(Boolean accountNonExpired) {
+ this.accountNonExpired = accountNonExpired;
+ }
+
+ public Boolean getAccountNonLocked() {
+ return accountNonLocked;
+ }
+
+ public void setAccountNonLocked(Boolean accountNonLocked) {
+ this.accountNonLocked = accountNonLocked;
+ }
+
+ public Boolean getCredentialsNonExpired() {
+ return credentialsNonExpired;
+ }
+
+ public void setCredentialsNonExpired(Boolean credentialsNonExpired) {
+ this.credentialsNonExpired = credentialsNonExpired;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getMobile() {
+ return mobile;
+ }
+
+ public void setMobile(String mobile) {
+ this.mobile = mobile;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/AccountGroup.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/AccountGroup.java
new file mode 100644
index 0000000..f46767b
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/AccountGroup.java
@@ -0,0 +1,46 @@
+package com.supwisdom.institute.backend.base.domain.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import com.supwisdom.institute.backend.common.framework.entity.ABaseEntity;
+
+@Entity
+@Table(name = "TB_BASE_ACCOUNT_GROUP")
+public class AccountGroup extends ABaseEntity {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -4239845385965871983L;
+
+ /**
+ * 帐号ID
+ */
+ @Column(name = "ACCOUNT_ID")
+ private String accountId;
+
+ /**
+ * 用户组ID
+ */
+ @Column(name = "GROUP_ID")
+ private String groupId;
+
+ public String getAccountId() {
+ return accountId;
+ }
+
+ public void setAccountId(String accountId) {
+ this.accountId = accountId;
+ }
+
+ public String getGroupId() {
+ return groupId;
+ }
+
+ public void setGroupId(String groupId) {
+ this.groupId = groupId;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/AccountRole.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/AccountRole.java
new file mode 100644
index 0000000..b08506a
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/AccountRole.java
@@ -0,0 +1,46 @@
+package com.supwisdom.institute.backend.base.domain.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import com.supwisdom.institute.backend.common.framework.entity.ABaseEntity;
+
+@Entity
+@Table(name = "TB_BASE_ACCOUNT_ROLE")
+public class AccountRole extends ABaseEntity {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -6158470486381850942L;
+
+ /**
+ * 帐号ID
+ */
+ @Column(name = "ACCOUNT_ID")
+ private String accountId;
+
+ /**
+ * 角色ID
+ */
+ @Column(name = "ROLE_ID")
+ private String roleId;
+
+ public String getAccountId() {
+ return accountId;
+ }
+
+ public void setAccountId(String accountId) {
+ this.accountId = accountId;
+ }
+
+ public String getRoleId() {
+ return roleId;
+ }
+
+ public void setRoleId(String roleId) {
+ this.roleId = roleId;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Application.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Application.java
new file mode 100644
index 0000000..b68fd38
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Application.java
@@ -0,0 +1,69 @@
+package com.supwisdom.institute.backend.base.domain.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import com.supwisdom.institute.backend.common.framework.entity.ABaseEntity;
+
+@Entity
+@Table(name = "TB_BASE_APPLICATION")
+public class Application extends ABaseEntity {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -1874484930838884168L;
+
+ /**
+ * 代码
+ */
+ @Column(name = "CODE")
+ @Getter
+ @Setter
+ private String code;
+
+ /**
+ * 名称
+ */
+ @Column(name = "NAME")
+ @Getter
+ @Setter
+ private String name;
+
+ /**
+ * 备注
+ */
+ @Column(name = "MEMO")
+ @Getter
+ @Setter
+ private String memo;
+
+ /**
+ * 状态(1 启用,0 停用)
+ */
+ @Column(name = "STATUS")
+ @Getter
+ @Setter
+ private String status;
+
+ /**
+ * 系统访问地址
+ */
+ @Column(name = "URL", nullable = true)
+ @Getter
+ @Setter
+ private String url;
+
+ /**
+ * SPI接口地址前缀
+ */
+ @Column(name = "SPI_URL_PREFIX", nullable = true)
+ @Getter
+ @Setter
+ private String spiUrlPrefix;
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Config.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Config.java
new file mode 100644
index 0000000..ee78348
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Config.java
@@ -0,0 +1,80 @@
+package com.supwisdom.institute.backend.base.domain.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import com.supwisdom.institute.backend.common.framework.entity.ABaseEntity;
+
+/**
+ * @author loie
+ */
+@Entity
+@Table(name = "TB_CONFIG")
+public class Config extends ABaseEntity {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -2721844710909809785L;
+
+ /**
+ * 分类代码
+ */
+ @Getter
+ @Setter
+ @Column(name = "CATEGORY_CODE")
+ private String categoryCode;
+
+ /**
+ * 分类名称
+ */
+ @Getter
+ @Setter
+ @Column(name = "CATEGORY_NAME")
+ private String categoryName;
+
+ /**
+ * 名称
+ */
+ @Getter
+ @Setter
+ @Column(name = "NAME")
+ private String name;
+
+ /**
+ * 描述
+ */
+ @Getter
+ @Setter
+ @Column(name = "DESCRIPTION")
+ private String description;
+
+ /**
+ * 配置键
+ */
+ @Getter
+ @Setter
+ @Column(name = "CONFIG_KEY")
+ private String configKey;
+
+ /**
+ * 配置值
+ */
+ @Getter
+ @Setter
+ @Column(name = "CONFIG_VALUE")
+ private String configValue;
+
+ /**
+ * 是否可修改
+ */
+ @Getter
+ @Setter
+ @Column(name = "EDITABLE")
+ private Boolean editable;
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Group.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Group.java
new file mode 100644
index 0000000..5e1de9a
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Group.java
@@ -0,0 +1,74 @@
+package com.supwisdom.institute.backend.base.domain.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import com.supwisdom.institute.backend.common.framework.entity.ABaseEntity;
+
+@Entity(name = "Group_")
+@Table(name = "TB_BASE_GROUP")
+public class Group extends ABaseEntity {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4260326816456622523L;
+
+ /**
+ * 代码
+ */
+ @Column(name = "CODE")
+ private String code;
+
+ /**
+ * 名称
+ */
+ @Column(name = "NAME")
+ private String name;
+
+ /**
+ * 备注
+ */
+ @Column(name = "MEMO")
+ private String memo;
+
+ /**
+ * 状态(1 启用,0 停用)
+ */
+ @Column(name = "STATUS")
+ private String status;
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getMemo() {
+ return memo;
+ }
+
+ public void setMemo(String memo) {
+ this.memo = memo;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/GroupRole.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/GroupRole.java
new file mode 100644
index 0000000..dafbcb5
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/GroupRole.java
@@ -0,0 +1,46 @@
+package com.supwisdom.institute.backend.base.domain.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import com.supwisdom.institute.backend.common.framework.entity.ABaseEntity;
+
+@Entity
+@Table(name = "TB_BASE_GROUP_ROLE")
+public class GroupRole extends ABaseEntity {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -3141266845902556712L;
+
+ /**
+ * 用户组ID
+ */
+ @Column(name = "GROUP_ID")
+ private String groupId;
+
+ /**
+ * 角色ID
+ */
+ @Column(name = "ROLE_ID")
+ private String roleId;
+
+ public String getGroupId() {
+ return groupId;
+ }
+
+ public void setGroupId(String groupId) {
+ this.groupId = groupId;
+ }
+
+ public String getRoleId() {
+ return roleId;
+ }
+
+ public void setRoleId(String roleId) {
+ this.roleId = roleId;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Permission.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Permission.java
new file mode 100644
index 0000000..df33e6e
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Permission.java
@@ -0,0 +1,210 @@
+package com.supwisdom.institute.backend.base.domain.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import com.supwisdom.institute.backend.common.framework.entity.ABaseEntity;
+
+@Entity
+@Table(name = "TB_BASE_PERMISSION")
+public class Permission extends ABaseEntity {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -8834200833972243635L;
+
+ public static final String ROOT_PARENT_ID = "0";
+
+ public static final String APPLICATION_ID = "1";
+
+ public static final String TYPE_APPLICATION = "1";
+ public static final String TYPE_MENU = "2";
+ public static final String TYPE_OPERATION = "3";
+
+ public static final Integer DEFAULT_ORDER = 0;
+
+ /**
+ * 代码
+ */
+ @Column(name = "CODE")
+ private String code;
+
+ /**
+ * 名称
+ */
+ @Column(name = "NAME")
+ private String name;
+
+ /**
+ * 备注
+ */
+ @Column(name = "MEMO", nullable = true)
+ private String memo;
+
+ /**
+ * 状态(1 启用,0 停用)
+ */
+ @Column(name = "STATUS")
+ private String status;
+
+ /**
+ * 系统ID
+ */
+ @Column(name = "APPLICATION_ID", nullable = true)
+ private String applicationId;
+
+ /**
+ * 父级ID
+ */
+ @Column(name = "PARENT_ID")
+ private String parentId;
+
+ /**
+ * 类型(1 应用,2 菜单,3 操作)
+ */
+ @Column(name = "TYPE_")
+ private String type;
+
+ /**
+ * 菜单图标
+ */
+ @Column(name = "ICON", nullable = true)
+ private String icon;
+
+ /**
+ * URL地址
+ */
+ @Column(name = "URL", nullable = true)
+ private String url;
+
+ /**
+ * 排序
+ */
+ @Column(name = "ORDER_")
+ private Integer order;
+
+ /**
+ * 层次
+ */
+ @Column(name = "LEVEL_")
+ private Integer level;
+
+ /**
+ * 左序
+ */
+ @Column(name = "LFT")
+ private Integer lft;
+
+ /**
+ * 右序
+ */
+ @Column(name = "RGT")
+ private Integer rgt;
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getMemo() {
+ return memo;
+ }
+
+ public void setMemo(String memo) {
+ this.memo = memo;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getIcon() {
+ return icon;
+ }
+
+ public void setIcon(String icon) {
+ this.icon = icon;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getApplicationId() {
+ return applicationId;
+ }
+
+ public void setApplicationId(String applicationId) {
+ this.applicationId = applicationId;
+ }
+
+ public String getParentId() {
+ return parentId;
+ }
+
+ public void setParentId(String parentId) {
+ this.parentId = parentId;
+ }
+
+ public Integer getOrder() {
+ return order;
+ }
+
+ public void setOrder(Integer order) {
+ this.order = order;
+ }
+
+ public Integer getLevel() {
+ return level;
+ }
+
+ public void setLevel(Integer level) {
+ this.level = level;
+ }
+
+ public Integer getLft() {
+ return lft;
+ }
+
+ public void setLft(Integer lft) {
+ this.lft = lft;
+ }
+
+ public Integer getRgt() {
+ return rgt;
+ }
+
+ public void setRgt(Integer rgt) {
+ this.rgt = rgt;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/PermissionResource.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/PermissionResource.java
new file mode 100644
index 0000000..7ec0413
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/PermissionResource.java
@@ -0,0 +1,46 @@
+package com.supwisdom.institute.backend.base.domain.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import com.supwisdom.institute.backend.common.framework.entity.ABaseEntity;
+
+@Entity
+@Table(name = "TB_BASE_PERMISSION_RESOURCE")
+public class PermissionResource extends ABaseEntity {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4224037561100974979L;
+
+ /**
+ * 权限ID
+ */
+ @Column(name = "PERMISSION_ID")
+ private String permissionId;
+
+ /**
+ * 资源ID
+ */
+ @Column(name = "RESOURCE_ID")
+ private String resourceId;
+
+ public String getPermissionId() {
+ return permissionId;
+ }
+
+ public void setPermissionId(String permissionId) {
+ this.permissionId = permissionId;
+ }
+
+ public String getResourceId() {
+ return resourceId;
+ }
+
+ public void setResourceId(String resourceId) {
+ this.resourceId = resourceId;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Resource.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Resource.java
new file mode 100644
index 0000000..8f8f8a4
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Resource.java
@@ -0,0 +1,83 @@
+package com.supwisdom.institute.backend.base.domain.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import com.supwisdom.institute.backend.common.framework.entity.ABaseEntity;
+
+@Entity
+@Table(name = "TB_BASE_RESOURCE")
+public class Resource extends ABaseEntity {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4288268877209267453L;
+
+ public static final String ACCESS_ANONYMOUS = "anonymous"; // 匿名访问anonymous
+ public static final String ACCESS_AUTHENTICATE = "authenticate"; // 认证访问authenticate
+ public static final String ACCESS_AUTHORIZE = "authorize"; // 授权访问authorize
+ public static final String ACCESS_PERMIT_ALL = "permitAll"; // 允许所有permitAll
+ public static final String ACCESS_DENY_ALL = "denyAll"; // 拒绝所有denyAll
+
+ /**
+ * 代码
+ */
+ @Getter
+ @Setter
+ @Column(name = "CODE")
+ private String code;
+
+ /**
+ * 名称
+ */
+ @Getter
+ @Setter
+ @Column(name = "NAME")
+ private String name;
+
+ /**
+ * 备注
+ */
+ @Getter
+ @Setter
+ @Column(name = "MEMO", nullable = true)
+ private String memo;
+
+ /**
+ * 状态(1 启用,0 停用)
+ */
+ @Getter
+ @Setter
+ @Column(name = "STATUS")
+ private String status;
+
+ /**
+ * 请求方式
+ */
+ @Getter
+ @Setter
+ @Column(name = "METHOD")
+ private String method;
+
+ /**
+ * 请求路径
+ */
+ @Getter
+ @Setter
+ @Column(name = "PATH")
+ private String path;
+
+ /**
+ * 访问规则(匿名访问anonymous、认证访问authenticate、授权访问authorize、允许所有permitAll、拒绝所有denyAll)
+ */
+ @Getter
+ @Setter
+ @Column(name = "ACCESS")
+ private String access;
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Role.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Role.java
new file mode 100644
index 0000000..c75cbe9
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Role.java
@@ -0,0 +1,74 @@
+package com.supwisdom.institute.backend.base.domain.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import com.supwisdom.institute.backend.common.framework.entity.ABaseEntity;
+
+@Entity
+@Table(name = "TB_BASE_ROLE")
+public class Role extends ABaseEntity {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5470129732727732514L;
+
+ /**
+ * 代码
+ */
+ @Column(name = "CODE")
+ private String code;
+
+ /**
+ * 名称
+ */
+ @Column(name = "NAME")
+ private String name;
+
+ /**
+ * 备注
+ */
+ @Column(name = "MEMO")
+ private String memo;
+
+ /**
+ * 状态(1 启用,0 停用)
+ */
+ @Column(name = "STATUS")
+ private String status;
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getMemo() {
+ return memo;
+ }
+
+ public void setMemo(String memo) {
+ this.memo = memo;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/RolePermission.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/RolePermission.java
new file mode 100644
index 0000000..19ba5b4
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/RolePermission.java
@@ -0,0 +1,46 @@
+package com.supwisdom.institute.backend.base.domain.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import com.supwisdom.institute.backend.common.framework.entity.ABaseEntity;
+
+@Entity
+@Table(name = "TB_BASE_ROLE_PERMISSION")
+public class RolePermission extends ABaseEntity {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5293251541687343949L;
+
+ /**
+ * 角色ID
+ */
+ @Column(name = "ROLE_ID")
+ private String roleId;
+
+ /**
+ * 权限ID
+ */
+ @Column(name = "PERMISSION_ID")
+ private String permissionId;
+
+ public String getRoleId() {
+ return roleId;
+ }
+
+ public void setRoleId(String roleId) {
+ this.roleId = roleId;
+ }
+
+ public String getPermissionId() {
+ return permissionId;
+ }
+
+ public void setPermissionId(String permissionId) {
+ this.permissionId = permissionId;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Route.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Route.java
new file mode 100644
index 0000000..6a58e92
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/entity/Route.java
@@ -0,0 +1,77 @@
+package com.supwisdom.institute.backend.base.domain.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import com.supwisdom.institute.backend.common.framework.entity.ABaseEntity;
+
+@Entity
+@Table(name = "TB_BASE_ROUTE")
+public class Route extends ABaseEntity {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -7435404154376360786L;
+
+ /**
+ * 代码
+ */
+ @Column(name = "CODE")
+ @Getter
+ @Setter
+ private String code;
+
+ /**
+ * 名称
+ */
+ @Column(name = "NAME")
+ @Getter
+ @Setter
+ private String name;
+
+ /**
+ * 备注
+ */
+ @Column(name = "MEMO")
+ @Getter
+ @Setter
+ private String memo;
+
+ /**
+ * 状态(1 启用,0 停用)
+ */
+ @Column(name = "STATUS")
+ @Getter
+ @Setter
+ private String status;
+
+ /**
+ * 路径前缀
+ */
+ @Column(name = "PATH_PREFIX")
+ @Getter
+ @Setter
+ private String pathPrefix;
+
+ /**
+ * 路由地址
+ */
+ @Column(name = "URL")
+ @Getter
+ @Setter
+ private String url;
+
+ /**
+ * 是否排除前缀
+ */
+ @Column(name = "STRIP_PREFIX")
+ @Getter
+ @Setter
+ private Boolean stripPrefix;
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/exception/.gitkeep b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/exception/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/exception/.gitkeep
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/exception/ConfigException.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/exception/ConfigException.java
new file mode 100644
index 0000000..77fee05
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/exception/ConfigException.java
@@ -0,0 +1,12 @@
+package com.supwisdom.institute.backend.base.domain.exception;
+
+import com.supwisdom.institute.backend.common.framework.exception.BaseException;
+
+public class ConfigException extends BaseException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 8112079911386045865L;
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/model/.gitkeep b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/model/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/model/.gitkeep
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/model/PermissionRoleSet.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/model/PermissionRoleSet.java
new file mode 100644
index 0000000..a95a0f7
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/model/PermissionRoleSet.java
@@ -0,0 +1,31 @@
+package com.supwisdom.institute.backend.base.domain.model;
+
+import java.util.Collection;
+
+import com.supwisdom.institute.backend.base.domain.entity.Permission;
+import com.supwisdom.institute.backend.base.domain.entity.Role;
+import com.supwisdom.institute.backend.common.framework.entity.EntityUtils;
+import com.supwisdom.institute.backend.common.framework.model.IModel;
+
+import lombok.Getter;
+import lombok.Setter;
+
+public class PermissionRoleSet extends Permission implements IModel {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -1823157193945264156L;
+
+ @Getter
+ @Setter
+ Collection<Role> roles;
+
+ public PermissionRoleSet(Permission permission, Collection<Role> roles) {
+
+ EntityUtils.copy(permission, this);
+
+ this.roles = roles;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/model/PermissionTreeNode.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/model/PermissionTreeNode.java
new file mode 100644
index 0000000..233de5f
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/model/PermissionTreeNode.java
@@ -0,0 +1,24 @@
+package com.supwisdom.institute.backend.base.domain.model;
+
+import java.util.List;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+import com.supwisdom.institute.backend.base.domain.entity.Permission;
+import com.supwisdom.institute.backend.common.framework.model.IModel;
+
+@ToString
+public class PermissionTreeNode extends Permission implements IModel {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6984458902464386215L;
+
+ @Getter
+ @Setter
+ List<PermissionTreeNode> children;
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/model/ResourceRoleSet.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/model/ResourceRoleSet.java
new file mode 100644
index 0000000..598b30d
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/model/ResourceRoleSet.java
@@ -0,0 +1,31 @@
+package com.supwisdom.institute.backend.base.domain.model;
+
+import java.util.Collection;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import com.supwisdom.institute.backend.base.domain.entity.Resource;
+import com.supwisdom.institute.backend.base.domain.entity.Role;
+import com.supwisdom.institute.backend.common.framework.entity.EntityUtils;
+import com.supwisdom.institute.backend.common.framework.model.IModel;
+
+public class ResourceRoleSet extends Resource implements IModel {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 2220390504237330816L;
+
+ @Getter
+ @Setter
+ Collection<Role> roles;
+
+ public ResourceRoleSet(Resource resource, Collection<Role> roles) {
+
+ EntityUtils.copy(resource, this);
+
+ this.roles = roles;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/.gitkeep b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/.gitkeep
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/AccountGroupRepository.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/AccountGroupRepository.java
new file mode 100644
index 0000000..be61930
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/AccountGroupRepository.java
@@ -0,0 +1,191 @@
+package com.supwisdom.institute.backend.base.domain.repo;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Repository;
+
+import com.supwisdom.institute.backend.base.domain.entity.Account;
+import com.supwisdom.institute.backend.base.domain.entity.AccountGroup;
+import com.supwisdom.institute.backend.base.domain.entity.Group;
+import com.supwisdom.institute.backend.common.framework.repo.BaseJpaRepository;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+@Repository
+public interface AccountGroupRepository extends BaseJpaRepository<AccountGroup> {
+
+ public default Page<AccountGroup> selectPageList(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+ AccountGroup probe = new AccountGroup();
+ if (mapBean != null) {
+ probe.setGroupId(MapBeanUtils.getString(mapBean, "groupId"));
+ probe.setAccountId(MapBeanUtils.getString(mapBean, "accountId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("groupId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("accountId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<AccountGroup> example = Example.of(probe, matcher);
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+
+ Page<AccountGroup> page = this.findAll(example, pageRequest);
+
+ return page;
+ }
+
+ public default Page<AccountGroup> selectAccountGroups(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+
+ AccountGroup probe = new AccountGroup();
+ if (mapBean != null) {
+ probe.setGroupId(MapBeanUtils.getString(mapBean, "groupId"));
+ probe.setAccountId(MapBeanUtils.getString(mapBean, "accountId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("groupId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("accountId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<AccountGroup> example = Example.of(probe, matcher);
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+
+ Page<AccountGroup> page = this.findAll(example, pageRequest); // FIXME: 多表关联查询
+
+ return page;
+ }
+
+ public default void relateAccountGroups(Account account, List<AccountGroup> accountGroups) {
+
+ List<AccountGroup> existAccountGroups = this.selectListByAccountId(account.getId());
+
+ Map<String, AccountGroup> existMapAccountGroups = new LinkedHashMap<String, AccountGroup>();
+ for (AccountGroup accountGroup : existAccountGroups) {
+ String k = String.format("%s", accountGroup.getGroupId());
+ existMapAccountGroups.put(k, accountGroup);
+ }
+
+ for (AccountGroup accountGroup : accountGroups) {
+ String k = String.format("%s", accountGroup.getGroupId());
+
+ if (existMapAccountGroups.containsKey(k)) {
+ existMapAccountGroups.remove(k);
+ } else {
+ accountGroup.setCompanyId(account.getCompanyId());
+ accountGroup.setAccountId(account.getId());
+
+ this.insert(accountGroup);
+ }
+ }
+
+ for (AccountGroup accountGroup : existMapAccountGroups.values()) {
+ this.deleteById(accountGroup.getId());
+ }
+ }
+
+ public default List<AccountGroup> selectListByAccountId(String accountId) {
+
+ AccountGroup probe = new AccountGroup();
+ probe.setAccountId(accountId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("accountId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<AccountGroup> example = Example.of(probe, matcher);
+
+ List<AccountGroup> accountGroups = this.findAll(example);
+
+ return accountGroups;
+ }
+
+ public default void relateGroupAccounts(Group group, List<AccountGroup> accountGroups) {
+
+ List<AccountGroup> existGroupAccounts = this.selectListByGroupId(group.getId());
+
+ Map<String, AccountGroup> existMapGroupAccounts = new LinkedHashMap<String, AccountGroup>();
+ for (AccountGroup accountGroup : existGroupAccounts) {
+ String k = String.format("%s", accountGroup.getAccountId());
+ existMapGroupAccounts.put(k, accountGroup);
+ }
+
+ for (AccountGroup accountGroup : accountGroups) {
+ String k = String.format("%s", accountGroup.getAccountId());
+
+ if (existMapGroupAccounts.containsKey(k)) {
+ existMapGroupAccounts.remove(k);
+ } else {
+ accountGroup.setCompanyId(group.getCompanyId());
+ accountGroup.setGroupId(group.getId());
+
+ this.insert(accountGroup);
+ }
+ }
+
+ for (AccountGroup accountGroup : existMapGroupAccounts.values()) {
+ this.deleteById(accountGroup.getId());
+ }
+ }
+
+ public default List<AccountGroup> selectListByGroupId(String groupId) {
+
+ AccountGroup probe = new AccountGroup();
+ probe.setGroupId(groupId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("groupId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<AccountGroup> example = Example.of(probe, matcher);
+
+ List<AccountGroup> accountGroups = this.findAll(example);
+
+ return accountGroups;
+ }
+
+ public default AccountGroup selectOneByAccountGroup(String accountId, String groupId) {
+
+ AccountGroup probe = new AccountGroup();
+ probe.setAccountId(accountId);
+ probe.setGroupId(groupId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("accountId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("groupId", ExampleMatcher.GenericPropertyMatchers.exact())
+ ;
+
+ Example<AccountGroup> example = Example.of(probe, matcher);
+
+ Optional<AccountGroup> o = this.findOne(example);
+
+ return o.isPresent() ? o.get() : null;
+ }
+
+ public default void addAccountGroup(String accountId, String groupId) {
+
+ AccountGroup accountGroup = this.selectOneByAccountGroup(accountId, groupId);
+
+ if (accountGroup == null) {
+ accountGroup = new AccountGroup();
+ //accountGroup.setCompanyId(companyId);
+ accountGroup.setAccountId(accountId);
+ accountGroup.setGroupId(groupId);
+
+ this.insert(accountGroup);
+ }
+ }
+
+ public default void removeAccountGroup(String accountId, String groupId) {
+
+ AccountGroup accountGroup = this.selectOneByAccountGroup(accountId, groupId);
+
+ if (accountGroup != null) {
+ this.deleteById(accountGroup.getId());
+ }
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/AccountRepository.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/AccountRepository.java
new file mode 100644
index 0000000..e4d9e07
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/AccountRepository.java
@@ -0,0 +1,199 @@
+package com.supwisdom.institute.backend.base.domain.repo;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Repository;
+import org.springframework.util.StringUtils;
+
+import com.supwisdom.institute.backend.base.domain.entity.Account;
+import com.supwisdom.institute.backend.common.framework.repo.BaseJpaRepository;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+@Repository
+public interface AccountRepository extends BaseJpaRepository<Account> {
+
+// public default Page<Account> selectPageList(int pageIndex, int pageSize, Account probe) {
+//
+// ExampleMatcher matcher = ExampleMatcher.matching()
+// .withMatcher("username", ExampleMatcher.GenericPropertyMatchers.contains())
+// .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains())
+// .withMatcher("status", ExampleMatcher.GenericPropertyMatchers.exact());
+//
+// PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+// Example<Account> example = Example.of(probe, matcher);
+//
+// Page<Account> page = this.findAll(example, pageRequest);
+//
+// return page;
+// }
+
+
+ @Override
+ public default Specification<Account> convertToSpec(Map<String, Object> mapBean) {
+
+ Specification<Account> spec = new Specification<Account>() {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 9071470982419099273L;
+
+ @Override
+ public Predicate toPredicate(Root<Account> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
+ List<Predicate> predicates = new ArrayList<>();
+
+ if (mapBean != null) {
+
+ if (MapBeanUtils.getBoolean(mapBean, "deleted") != null) {
+ predicates.add(criteriaBuilder.equal(root.get("deleted"), MapBeanUtils.getBoolean(mapBean, "deleted")));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "username"))) {
+ predicates.add(criteriaBuilder.like(root.get("username"), "%" + MapBeanUtils.getString(mapBean, "username") + "%"));
+ }
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "name"))) {
+ predicates.add(criteriaBuilder.like(root.get("name"), "%" + MapBeanUtils.getString(mapBean, "name") + "%"));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "status"))) {
+ predicates.add(criteriaBuilder.equal(root.get("status"), MapBeanUtils.getString(mapBean, "status")));
+ }
+
+// if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "grantTimeBegin"))) {
+// String grantTimeBegin = MapBeanUtils.getString(mapBean, "grantTimeBegin");
+// Date d = DateUtil.parseDate(grantTimeBegin+" 00:00:00", "yyyy-MM-dd HH:mm:ss");
+//
+// if (d != null) {
+// predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("grantTime"), d));
+// }
+// }
+//
+// if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "grantTimeEnd"))) {
+// String grantTimeEnd = MapBeanUtils.getString(mapBean, "grantTimeEnd");
+// Date d = DateUtil.parseDate(grantTimeEnd+" 23:59:59", "yyyy-MM-dd HH:mm:ss");
+//
+// if (d != null) {
+// predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get("grantTime"), d));
+// }
+// }
+
+ List<Predicate> predicatesKeyword = new ArrayList<>();
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "keyword"))) {
+ predicatesKeyword.add(criteriaBuilder.like(root.get("username"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+ predicatesKeyword.add(criteriaBuilder.like(root.get("name"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+ predicatesKeyword.add(criteriaBuilder.like(root.get("memo"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+
+ predicates.add(criteriaBuilder.or(predicatesKeyword.toArray(new Predicate[predicatesKeyword.size()])));
+ }
+ }
+
+ return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
+ }
+
+ };
+
+ return spec;
+ }
+
+
+// @Override
+// public default Page<Account> selectPageList(boolean loadAll, int pageIndex, int pageSize, Map<String, Object> mapBean, Map<String, String> orderBy) {
+// if (loadAll) {
+// pageIndex = 0;
+// pageSize = Integer.MAX_VALUE;
+// }
+//
+// Account probe = new Account();
+// if (mapBean != null) {
+// probe.setDeleted(MapBeanUtils.getBoolean(mapBean, "deleted"));
+// probe.setUsername(MapBeanUtils.getString(mapBean, "username"));
+// probe.setName(MapBeanUtils.getString(mapBean, "name"));
+// probe.setStatus(MapBeanUtils.getString(mapBean, "status"));
+// }
+//
+// ExampleMatcher matcher = ExampleMatcher.matching()
+// .withMatcher("deleted", ExampleMatcher.GenericPropertyMatchers.exact())
+// .withMatcher("username", ExampleMatcher.GenericPropertyMatchers.contains())
+// .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains())
+// .withMatcher("status", ExampleMatcher.GenericPropertyMatchers.exact());
+//
+// PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+// Example<Account> example = Example.of(probe, matcher);
+//
+// Page<Account> page = this.findAll(example, pageRequest);
+//
+// return page;
+// }
+
+ /*
+ public default User selectById(String id) {
+
+ try {
+ Optional<User> entity = this.findById(id);
+
+ return entity.get();
+ } catch(RuntimeException e) {
+ System.out.println("RuntimeException:"+e.getMessage());
+ } catch(Exception e) {
+ System.out.println("Exception:"+e.getMessage());
+ }
+
+ return null;
+ }
+
+ public default User insert(User entity) {
+
+ if (entity.getCompanyId() == null || entity.getCompanyId().isEmpty()) {
+ entity.setCompanyId("1");
+ }
+
+ entity.setDeleted(false);
+ //entity.setAddAccount(AuthUtil.getRemoteUser());
+ entity.setAddTime(Calendar.getInstance().getTime());
+
+ User e = this.save(entity);
+
+ return e;
+ }
+
+ public default User update(User entity) {
+
+ //entity.setEditAccount(AuthUtil.getRemoteUser());
+ entity.setEditTime(Calendar.getInstance().getTime());
+
+ User e = this.save(entity);
+
+ return e;
+ }
+ */
+
+ public default Account selectByUsername(String username) {
+ Account probe = new Account();
+ probe.setUsername(username);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("username", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<Account> example = Example.of(probe, matcher);
+
+ Optional<Account> u = this.findOne(example);
+
+ if (u.isPresent()) {
+ return u.get();
+ }
+
+ return null;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/AccountRoleRepository.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/AccountRoleRepository.java
new file mode 100644
index 0000000..503f3b5
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/AccountRoleRepository.java
@@ -0,0 +1,191 @@
+package com.supwisdom.institute.backend.base.domain.repo;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Repository;
+
+import com.supwisdom.institute.backend.base.domain.entity.Account;
+import com.supwisdom.institute.backend.base.domain.entity.AccountRole;
+import com.supwisdom.institute.backend.base.domain.entity.Role;
+import com.supwisdom.institute.backend.common.framework.repo.BaseJpaRepository;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+@Repository
+public interface AccountRoleRepository extends BaseJpaRepository<AccountRole> {
+
+ public default Page<AccountRole> selectPageList(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+
+ AccountRole probe = new AccountRole();
+ if (mapBean != null) {
+ probe.setAccountId(MapBeanUtils.getString(mapBean, "accountId"));
+ probe.setRoleId(MapBeanUtils.getString(mapBean, "roleId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("accountId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+ Example<AccountRole> example = Example.of(probe, matcher);
+
+ Page<AccountRole> page = this.findAll(example, pageRequest);
+
+ return page;
+ }
+
+ public default Page<AccountRole> selectAccountRoles(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+
+ AccountRole probe = new AccountRole();
+ if (mapBean != null) {
+ probe.setAccountId(MapBeanUtils.getString(mapBean, "accountId"));
+ probe.setRoleId(MapBeanUtils.getString(mapBean, "roleId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("accountId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<AccountRole> example = Example.of(probe, matcher);
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+
+ Page<AccountRole> page = this.findAll(example, pageRequest); // FIXME: 多表关联查询
+
+ return page;
+ }
+
+ public default void relateAccountRoles(Account account, List<AccountRole> accountRoles) {
+
+ List<AccountRole> existAccountRoles = this.selectListByAccountId(account.getId());
+
+ Map<String, AccountRole> existMapAccountRoles = new LinkedHashMap<String, AccountRole>();
+ for (AccountRole accountRole : existAccountRoles) {
+ String k = String.format("%s", accountRole.getRoleId());
+ existMapAccountRoles.put(k, accountRole);
+ }
+
+ for (AccountRole accountRole : accountRoles) {
+ String k = String.format("%s", accountRole.getRoleId());
+
+ if (existMapAccountRoles.containsKey(k)) {
+ existMapAccountRoles.remove(k);
+ } else {
+ accountRole.setCompanyId(account.getCompanyId());
+ accountRole.setAccountId(account.getId());
+
+ this.insert(accountRole);
+ }
+ }
+
+ for (AccountRole accountRole : existMapAccountRoles.values()) {
+ this.deleteById(accountRole.getId());
+ }
+ }
+
+ public default List<AccountRole> selectListByAccountId(String accountId) {
+
+ AccountRole probe = new AccountRole();
+ probe.setAccountId(accountId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("accountId",
+ ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<AccountRole> example = Example.of(probe, matcher);
+
+ List<AccountRole> accountRoles = this.findAll(example);
+
+ return accountRoles;
+ }
+
+ public default void relateRoleAccounts(Role role, List<AccountRole> accountRoles) {
+
+ List<AccountRole> existRoleAccounts = this.selectListByRoleId(role.getId());
+
+ Map<String, AccountRole> existMapRoleAccounts = new LinkedHashMap<String, AccountRole>();
+ for (AccountRole accountRole : existRoleAccounts) {
+ String k = String.format("%s", accountRole.getAccountId());
+ existMapRoleAccounts.put(k, accountRole);
+ }
+
+ for (AccountRole accountRole : accountRoles) {
+ String k = String.format("%s", accountRole.getAccountId());
+
+ if (existMapRoleAccounts.containsKey(k)) {
+ existMapRoleAccounts.remove(k);
+ } else {
+ accountRole.setCompanyId(role.getCompanyId());
+ accountRole.setRoleId(role.getId());
+
+ this.insert(accountRole);
+ }
+ }
+
+ for (AccountRole accountRole : existMapRoleAccounts.values()) {
+ this.deleteById(accountRole.getId());
+ }
+ }
+
+ public default List<AccountRole> selectListByRoleId(String roleId) {
+
+ AccountRole probe = new AccountRole();
+ probe.setRoleId(roleId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("roleId",
+ ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<AccountRole> example = Example.of(probe, matcher);
+
+ List<AccountRole> accountRoles = this.findAll(example);
+
+ return accountRoles;
+ }
+
+ public default AccountRole selectOneByAccountRole(String accountId, String roleId) {
+
+ AccountRole probe = new AccountRole();
+ probe.setAccountId(accountId);
+ probe.setRoleId(roleId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("accountId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact())
+ ;
+
+ Example<AccountRole> example = Example.of(probe, matcher);
+
+ Optional<AccountRole> o = this.findOne(example);
+
+ return o.isPresent() ? o.get() : null;
+ }
+
+ public default void addAccountRole(String accountId, String roleId) {
+
+ AccountRole accountRole = this.selectOneByAccountRole(accountId, roleId);
+
+ if (accountRole == null) {
+ accountRole = new AccountRole();
+ //accountRole.setCompanyId(companyId);
+ accountRole.setAccountId(accountId);
+ accountRole.setRoleId(roleId);
+
+ this.insert(accountRole);
+ }
+ }
+
+ public default void removeAccountRole(String accountId, String roleId) {
+
+ AccountRole accountRole = this.selectOneByAccountRole(accountId, roleId);
+
+ if (accountRole != null) {
+ this.deleteById(accountRole.getId());
+ }
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/ApplicationRepository.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/ApplicationRepository.java
new file mode 100644
index 0000000..3e1b6ea
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/ApplicationRepository.java
@@ -0,0 +1,76 @@
+package com.supwisdom.institute.backend.base.domain.repo;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Repository;
+import org.springframework.util.StringUtils;
+
+import com.supwisdom.institute.backend.base.domain.entity.Application;
+import com.supwisdom.institute.backend.common.framework.repo.BaseJpaRepository;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+@Repository
+public interface ApplicationRepository extends BaseJpaRepository<Application> {
+
+ @Override
+ public default Specification<Application> convertToSpec(Map<String, Object> mapBean) {
+
+ Specification<Application> spec = new Specification<Application>() {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -263282246904382286L;
+
+ @Override
+ public Predicate toPredicate(Root<Application> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
+ List<Predicate> predicates = new ArrayList<>();
+
+ if (mapBean != null) {
+
+ if (MapBeanUtils.getBoolean(mapBean, "deleted") != null) {
+ predicates.add(criteriaBuilder.equal(root.get("deleted"), MapBeanUtils.getBoolean(mapBean, "deleted")));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "code"))) {
+ predicates.add(criteriaBuilder.like(root.get("code"), "%" + MapBeanUtils.getString(mapBean, "code") + "%"));
+ }
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "name"))) {
+ predicates.add(criteriaBuilder.like(root.get("name"), "%" + MapBeanUtils.getString(mapBean, "name") + "%"));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "status"))) {
+ predicates.add(criteriaBuilder.equal(root.get("status"), MapBeanUtils.getString(mapBean, "status")));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "url"))) {
+ predicates.add(criteriaBuilder.like(root.get("url"), "%" + MapBeanUtils.getString(mapBean, "url") + "%"));
+ }
+
+ List<Predicate> predicatesKeyword = new ArrayList<>();
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "keyword"))) {
+ predicatesKeyword.add(criteriaBuilder.like(root.get("code"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+ predicatesKeyword.add(criteriaBuilder.like(root.get("name"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+ predicatesKeyword.add(criteriaBuilder.like(root.get("memo"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+
+ predicates.add(criteriaBuilder.or(predicatesKeyword.toArray(new Predicate[predicatesKeyword.size()])));
+ }
+ }
+
+ return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
+ }
+
+ };
+
+ return spec;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/ConfigRepository.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/ConfigRepository.java
new file mode 100644
index 0000000..052115e
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/ConfigRepository.java
@@ -0,0 +1,77 @@
+package com.supwisdom.institute.backend.base.domain.repo;
+
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Repository;
+
+import com.supwisdom.institute.backend.base.domain.entity.Config;
+import com.supwisdom.institute.backend.common.framework.repo.BaseJpaRepository;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * @author loie
+ */
+@Repository
+public interface ConfigRepository extends BaseJpaRepository<Config> {
+
+ public default Page<Config> selectPageList(boolean loadAll, int pageIndex, int pageSize, Map<String, Object> mapBean, Map<String, String> orderBy) {
+ Config probe = new Config();
+ if (mapBean != null) {
+ probe.setDeleted(MapBeanUtils.getBoolean(mapBean, "deleted"));
+ probe.setCategoryCode(MapBeanUtils.getString(mapBean, "categoryCode"));
+ probe.setCategoryName(MapBeanUtils.getString(mapBean, "categoryName"));
+ probe.setName(MapBeanUtils.getString(mapBean, "name"));
+ probe.setDescription(MapBeanUtils.getString(mapBean, "description"));
+ probe.setConfigKey(MapBeanUtils.getString(mapBean, "configKey"));
+ probe.setEditable(MapBeanUtils.getBoolean(mapBean, "editable"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("deleted", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("categoryCode", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("categoryName", ExampleMatcher.GenericPropertyMatchers.contains())
+ .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains())
+ .withMatcher("description", ExampleMatcher.GenericPropertyMatchers.contains())
+ .withMatcher("configKey", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("editable", ExampleMatcher.GenericPropertyMatchers.exact())
+ ;
+
+ if (loadAll) {
+ pageIndex = 0;
+ pageSize = Integer.MAX_VALUE;
+ }
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+ Example<Config> example = Example.of(probe, matcher);
+
+ Page<Config> page = this.findAll(example, pageRequest);
+
+ return page;
+ }
+
+ public default Config selectByCategoryKey(String categoryCode, String configKey) {
+ Config probe = new Config();
+
+ probe.setDeleted(false);
+ probe.setCategoryCode(categoryCode);
+ probe.setConfigKey(configKey);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("deleted", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("categoryCode", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("configKey", ExampleMatcher.GenericPropertyMatchers.exact())
+ ;
+
+ Example<Config> example = Example.of(probe, matcher);
+
+ Optional<Config> config = this.findOne(example);
+
+ return config.isPresent() ? config.get() : null;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/GroupRepository.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/GroupRepository.java
new file mode 100644
index 0000000..75ad2b4
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/GroupRepository.java
@@ -0,0 +1,107 @@
+package com.supwisdom.institute.backend.base.domain.repo;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Repository;
+import org.springframework.util.StringUtils;
+
+import com.supwisdom.institute.backend.base.domain.entity.Group;
+import com.supwisdom.institute.backend.common.framework.repo.BaseJpaRepository;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+@Repository
+public interface GroupRepository extends BaseJpaRepository<Group> {
+
+
+ @Override
+ public default Specification<Group> convertToSpec(Map<String, Object> mapBean) {
+
+ Specification<Group> spec = new Specification<Group>() {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5467747850605022253L;
+
+ @Override
+ public Predicate toPredicate(Root<Group> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
+ List<Predicate> predicates = new ArrayList<>();
+
+ if (mapBean != null) {
+
+ if (MapBeanUtils.getBoolean(mapBean, "deleted") != null) {
+ predicates.add(criteriaBuilder.equal(root.get("deleted"), MapBeanUtils.getBoolean(mapBean, "deleted")));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "code"))) {
+ predicates.add(criteriaBuilder.like(root.get("code"), "%" + MapBeanUtils.getString(mapBean, "code") + "%"));
+ }
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "name"))) {
+ predicates.add(criteriaBuilder.like(root.get("name"), "%" + MapBeanUtils.getString(mapBean, "name") + "%"));
+ }
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "memo"))) {
+ predicates.add(criteriaBuilder.like(root.get("memo"), "%" + MapBeanUtils.getString(mapBean, "memo") + "%"));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "status"))) {
+ predicates.add(criteriaBuilder.equal(root.get("status"), MapBeanUtils.getString(mapBean, "status")));
+ }
+
+ List<Predicate> predicatesKeyword = new ArrayList<>();
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "keyword"))) {
+ predicatesKeyword.add(criteriaBuilder.like(root.get("code"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+ predicatesKeyword.add(criteriaBuilder.like(root.get("name"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+ predicatesKeyword.add(criteriaBuilder.like(root.get("memo"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+
+ predicates.add(criteriaBuilder.or(predicatesKeyword.toArray(new Predicate[predicatesKeyword.size()])));
+ }
+ }
+
+ return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
+ }
+
+ };
+
+ return spec;
+ }
+
+// @Override
+// public default Page<Group> selectPageList(boolean loadAll, int pageIndex, int pageSize, Map<String, Object> mapBean, Map<String, String> orderBy) {
+// if (loadAll) {
+// pageIndex = 0;
+// pageSize = Integer.MAX_VALUE;
+// }
+//
+// Group probe = new Group();
+// if (mapBean != null) {
+// probe.setDeleted(MapBeanUtils.getBoolean(mapBean, "deleted"));
+// probe.setCode(MapBeanUtils.getString(mapBean, "code"));
+// probe.setName(MapBeanUtils.getString(mapBean, "name"));
+// probe.setMemo(MapBeanUtils.getString(mapBean, "memo"));
+// probe.setStatus(MapBeanUtils.getString(mapBean, "status"));
+// }
+//
+// ExampleMatcher matcher = ExampleMatcher.matching()
+// .withMatcher("deleted", ExampleMatcher.GenericPropertyMatchers.exact())
+// .withMatcher("code", ExampleMatcher.GenericPropertyMatchers.contains())
+// .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains())
+// .withMatcher("memo", ExampleMatcher.GenericPropertyMatchers.contains())
+// .withMatcher("status", ExampleMatcher.GenericPropertyMatchers.exact());
+//
+// PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+// Example<Group> example = Example.of(probe, matcher);
+//
+// Page<Group> page = this.findAll(example, pageRequest);
+//
+// return page;
+// }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/GroupRoleRepository.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/GroupRoleRepository.java
new file mode 100644
index 0000000..35bd4d5
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/GroupRoleRepository.java
@@ -0,0 +1,191 @@
+package com.supwisdom.institute.backend.base.domain.repo;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Repository;
+
+import com.supwisdom.institute.backend.base.domain.entity.Group;
+import com.supwisdom.institute.backend.base.domain.entity.GroupRole;
+import com.supwisdom.institute.backend.base.domain.entity.Role;
+import com.supwisdom.institute.backend.common.framework.repo.BaseJpaRepository;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+@Repository
+public interface GroupRoleRepository extends BaseJpaRepository<GroupRole> {
+
+ public default Page<GroupRole> selectPageList(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+ GroupRole probe = new GroupRole();
+ if (mapBean != null) {
+ probe.setGroupId(MapBeanUtils.getString(mapBean, "groupId"));
+ probe.setRoleId(MapBeanUtils.getString(mapBean, "roleId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("groupId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+ Example<GroupRole> example = Example.of(probe, matcher);
+
+ Page<GroupRole> page = this.findAll(example, pageRequest);
+
+ return page;
+ }
+
+ public default Page<GroupRole> selectGroupRoles(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+
+ GroupRole probe = new GroupRole();
+ if (mapBean != null) {
+ probe.setGroupId(MapBeanUtils.getString(mapBean, "groupId"));
+ probe.setRoleId(MapBeanUtils.getString(mapBean, "roleId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("groupId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<GroupRole> example = Example.of(probe, matcher);
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+
+ Page<GroupRole> page = this.findAll(example, pageRequest); // FIXME: 多表关联查询
+
+ return page;
+ }
+
+ public default void relateGroupRoles(Group group, List<GroupRole> groupRoles) {
+
+ List<GroupRole> existGroupRoles = this.selectListByGroupId(group.getId());
+
+ Map<String, GroupRole> existMapGroupRoles = new LinkedHashMap<String, GroupRole>();
+ for (GroupRole groupRole : existGroupRoles) {
+ String k = String.format("%s", groupRole.getRoleId());
+ existMapGroupRoles.put(k, groupRole);
+ }
+
+ for (GroupRole groupRole : groupRoles) {
+ String k = String.format("%s", groupRole.getRoleId());
+
+ if (existMapGroupRoles.containsKey(k)) {
+ existMapGroupRoles.remove(k);
+ } else {
+ groupRole.setCompanyId(group.getCompanyId());
+ groupRole.setGroupId(group.getId());
+
+ this.insert(groupRole);
+ }
+ }
+
+ for (GroupRole groupRole : existMapGroupRoles.values()) {
+ this.deleteById(groupRole.getId());
+ }
+ }
+
+ public default List<GroupRole> selectListByGroupId(String groupId) {
+
+ GroupRole probe = new GroupRole();
+ probe.setGroupId(groupId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("groupId",
+ ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<GroupRole> example = Example.of(probe, matcher);
+
+ List<GroupRole> groupRoles = this.findAll(example);
+
+ return groupRoles;
+ }
+
+
+ public default void relateRoleGroups(Role role, List<GroupRole> groupRoles) {
+
+ List<GroupRole> existRoleGroups = this.selectListByRoleId(role.getCode());
+
+ Map<String, GroupRole> existMapRoleGroups = new LinkedHashMap<String, GroupRole>();
+ for (GroupRole groupRole : existRoleGroups) {
+ String k = String.format("%s", groupRole.getGroupId());
+ existMapRoleGroups.put(k, groupRole);
+ }
+
+ for (GroupRole groupRole : groupRoles) {
+ String k = String.format("%s", groupRole.getGroupId());
+
+ if (existMapRoleGroups.containsKey(k)) {
+ existMapRoleGroups.remove(k);
+ } else {
+ groupRole.setCompanyId(role.getCompanyId());
+ groupRole.setRoleId(role.getId());
+
+ this.insert(groupRole);
+ }
+ }
+
+ for (GroupRole groupRole : existMapRoleGroups.values()) {
+ this.deleteById(groupRole.getId());
+ }
+ }
+
+ public default List<GroupRole> selectListByRoleId(String roleId) {
+
+ GroupRole probe = new GroupRole();
+ probe.setRoleId(roleId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<GroupRole> example = Example.of(probe, matcher);
+
+ List<GroupRole> groupRoles = this.findAll(example);
+
+ return groupRoles;
+ }
+
+ public default GroupRole selectOneByGroupRole(String groupId, String roleId) {
+
+ GroupRole probe = new GroupRole();
+ probe.setGroupId(groupId);
+ probe.setRoleId(roleId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("groupId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact())
+ ;
+
+ Example<GroupRole> example = Example.of(probe, matcher);
+
+ Optional<GroupRole> o = this.findOne(example);
+
+ return o.isPresent() ? o.get() : null;
+ }
+
+ public default void addGroupRole(String groupId, String roleId) {
+
+ GroupRole groupRole = this.selectOneByGroupRole(groupId, roleId);
+
+ if (groupRole == null) {
+ groupRole = new GroupRole();
+ //groupRole.setCompanyId(companyId);
+ groupRole.setGroupId(groupId);
+ groupRole.setRoleId(roleId);
+
+ this.insert(groupRole);
+ }
+ }
+
+ public default void removeGroupRole(String groupId, String roleId) {
+
+ GroupRole groupRole = this.selectOneByGroupRole(groupId, roleId);
+
+ if (groupRole != null) {
+ this.deleteById(groupRole.getId());
+ }
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/PermissionRepository.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/PermissionRepository.java
new file mode 100644
index 0000000..aaa0214
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/PermissionRepository.java
@@ -0,0 +1,419 @@
+package com.supwisdom.institute.backend.base.domain.repo;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+import javax.transaction.Transactional;
+
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Repository;
+import org.springframework.util.StringUtils;
+
+import com.supwisdom.institute.backend.base.domain.entity.Permission;
+import com.supwisdom.institute.backend.common.framework.repo.BaseJpaRepository;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+@Repository
+@Transactional
+public interface PermissionRepository extends BaseJpaRepository<Permission> {
+
+
+ @Override
+ public default Specification<Permission> convertToSpec(Map<String, Object> mapBean) {
+
+ Specification<Permission> spec = new Specification<Permission>() {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6195601104797641573L;
+
+ @Override
+ public Predicate toPredicate(Root<Permission> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
+ List<Predicate> predicates = new ArrayList<>();
+
+ if (mapBean != null) {
+
+ if (MapBeanUtils.getBoolean(mapBean, "deleted") != null) {
+ predicates.add(criteriaBuilder.equal(root.get("deleted"), MapBeanUtils.getBoolean(mapBean, "deleted")));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "code"))) {
+ predicates.add(criteriaBuilder.like(root.get("code"), "%" + MapBeanUtils.getString(mapBean, "code") + "%"));
+ }
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "name"))) {
+ predicates.add(criteriaBuilder.like(root.get("name"), "%" + MapBeanUtils.getString(mapBean, "name") + "%"));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "status"))) {
+ predicates.add(criteriaBuilder.equal(root.get("status"), MapBeanUtils.getString(mapBean, "status")));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "type"))) {
+ predicates.add(criteriaBuilder.equal(root.get("type"), MapBeanUtils.getString(mapBean, "type")));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "url"))) {
+ predicates.add(criteriaBuilder.like(root.get("url"), "%" + MapBeanUtils.getString(mapBean, "url") + "%"));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "applicationId"))) {
+ predicates.add(criteriaBuilder.equal(root.get("applicationId"), MapBeanUtils.getString(mapBean, "applicationId")));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "parentId"))) {
+ predicates.add(criteriaBuilder.equal(root.get("parentId"), MapBeanUtils.getString(mapBean, "parentId")));
+ }
+
+// if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "grantTimeBegin"))) {
+// String grantTimeBegin = MapBeanUtils.getString(mapBean, "grantTimeBegin");
+// Date d = DateUtil.parseDate(grantTimeBegin+" 00:00:00", "yyyy-MM-dd HH:mm:ss");
+//
+// if (d != null) {
+// predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("grantTime"), d));
+// }
+// }
+//
+// if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "grantTimeEnd"))) {
+// String grantTimeEnd = MapBeanUtils.getString(mapBean, "grantTimeEnd");
+// Date d = DateUtil.parseDate(grantTimeEnd+" 23:59:59", "yyyy-MM-dd HH:mm:ss");
+//
+// if (d != null) {
+// predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get("grantTime"), d));
+// }
+// }
+
+ List<Predicate> predicatesKeyword = new ArrayList<>();
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "keyword"))) {
+ predicatesKeyword.add(criteriaBuilder.like(root.get("code"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+ predicatesKeyword.add(criteriaBuilder.like(root.get("name"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+ predicatesKeyword.add(criteriaBuilder.like(root.get("memo"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+
+ predicates.add(criteriaBuilder.or(predicatesKeyword.toArray(new Predicate[predicatesKeyword.size()])));
+ }
+ }
+
+ return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
+ }
+
+ };
+
+ return spec;
+ }
+
+ @Override
+ public default Page<Permission> selectPageList(boolean loadAll, int pageIndex, int pageSize, Map<String, Object> mapBean, Map<String, String> orderBy) {
+ if (loadAll) {
+ pageIndex = 0;
+ pageSize = Integer.MAX_VALUE;
+ }
+
+ Permission probe = new Permission();
+ if (mapBean != null) {
+ probe.setDeleted(MapBeanUtils.getBoolean(mapBean, "deleted"));
+ probe.setCode(MapBeanUtils.getString(mapBean, "code"));
+ probe.setName(MapBeanUtils.getString(mapBean, "name"));
+ probe.setMemo(MapBeanUtils.getString(mapBean, "memo"));
+ probe.setStatus(MapBeanUtils.getString(mapBean, "status"));
+ probe.setType(MapBeanUtils.getString(mapBean, "type"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("deleted", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("code", ExampleMatcher.GenericPropertyMatchers.contains())
+ .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains())
+ .withMatcher("memo", ExampleMatcher.GenericPropertyMatchers.contains())
+ .withMatcher("status", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("type", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+ Example<Permission> example = Example.of(probe, matcher);
+
+ Page<Permission> page = this.findAll(example, pageRequest);
+
+ return page;
+ }
+
+
+
+ @Query(value = "select max(p.rgt) from Permission p")
+ public int selectMaxRgt();
+
+ @Query(value = "select p from Permission p where p.lft>:lft and p.rgt<:rgt order by p.lft")
+ public List<Permission> selectBetweenLftRgt(@Param("lft") int lft, @Param("rgt") int rgt);
+
+ @Modifying
+ @Query(value = "update TB_BASE_PERMISSION "
+ + "set "
+ + " LFT = (case when LFT >= :rgt then LFT + :offset else LFT end), "
+ + " RGT = RGT + :offset "
+ + "where RGT >= :rgt", nativeQuery = true)
+ public int updateLftRgtWhenInsert(@Param("rgt") int rgt, @Param("offset") int offset);
+
+ @Modifying
+ @Query(value = "update TB_BASE_PERMISSION "
+ + "set "
+ + " LFT = (case when LFT >= :rgt then LFT - :offset else LFT end), "
+ + " RGT = RGT - :offset "
+ + "where RGT >= :rgt", nativeQuery = true)
+ public int updateLftRgtWhenDelete(@Param("rgt") int rgt, @Param("offset") int offset);
+
+
+ @Override
+ public default Permission insert(Permission entity) {
+
+ if (entity.getParentId() == null) {
+ entity.setParentId(Permission.ROOT_PARENT_ID);
+ }
+
+ if (entity.getParentId() == null || entity.getParentId().isEmpty() || Permission.ROOT_PARENT_ID.equals(entity.getParentId())) {
+ int maxRgt = selectMaxRgt();
+ entity.setLft((maxRgt+1));
+ entity.setRgt((maxRgt+1) + 1);
+
+ entity.setLevel(1);
+ } else {
+ Permission parentEntity = this.selectById(entity.getParentId());
+ if (parentEntity == null) {
+ throw new RuntimeException(String.format("父级对象不存在!"));
+ } else {
+ // 将 lft或rgt 大于等于父级对象 rgt 的记录的 lft、rgt +offset
+ int rgt = parentEntity.getRgt();
+ int offset = 2;
+ updateLftRgtWhenInsert(rgt, offset);
+
+ entity.setLft(rgt);
+ entity.setRgt(rgt + 1);
+
+ entity.setLevel(parentEntity.getLevel() + 1);
+ }
+ }
+
+ return BaseJpaRepository.super.insert(entity);
+ }
+
+ @Override
+ public default Permission update(Permission entity) {
+
+ Permission originEntity = this.selectById(entity.getId());
+ if (originEntity == null) {
+ return null;
+ }
+
+ //if (!this.checkFieldExists("code", entity.getCode(), entity.getId())) {
+ // throw new RuntimeException(String.format("代码重复!"));
+ //}
+
+ if (originEntity.getParentId() == null) {
+ originEntity.setParentId(Permission.ROOT_PARENT_ID);
+ }
+
+ if (entity.getParentId() == null) {
+ entity.setParentId(Permission.ROOT_PARENT_ID);
+ }
+
+ if (!originEntity.getParentId().equals(entity.getParentId()) ) {
+
+ int lft = originEntity.getLft();
+ int rgt = originEntity.getRgt();
+ int level = originEntity.getLevel();
+ int offset = rgt - lft +1;
+
+ List<Permission> childEntities = this.selectBetweenLftRgt(lft, rgt);
+
+ if (entity.getParentId() == null || entity.getParentId().isEmpty() || Permission.ROOT_PARENT_ID.equals(entity.getParentId())) {
+ // 将 lft或rgt 大于等于该对象 rgt 的记录的 lft、rgt -offset
+ updateLftRgtWhenDelete(rgt, offset);
+
+ int maxRgt = selectMaxRgt();
+ entity.setLft((maxRgt+1));
+ entity.setRgt((maxRgt+1) + 1 +offset-2);
+
+ entity.setLevel(1);
+ } else {
+ // 将 lft或rgt 大于等于该对象 rgt 的记录的 lft、rgt -offset
+ updateLftRgtWhenDelete(rgt, offset);
+
+ Permission parentEntity = this.selectById(entity.getParentId());
+ if (parentEntity == null) {
+ throw new RuntimeException(String.format("父级对象不存在!"));
+ }
+ //System.out.println(String.format("pLft %s, pRgt %s", parentEntity.getLft(), parentEntity.getRgt()));
+ if (parentEntity.getLft() >= originEntity.getLft() && parentEntity.getRgt() <= originEntity.getRgt()) {
+ throw new RuntimeException(String.format("不能设置自身或自身的子节点作为父级!"));
+ }
+
+ //parentEntity = this.selectById(entity.getParentId()); System.out.println(String.format("pLft %s, pRgt %s", parentEntity.getLft(), parentEntity.getRgt()));
+ // 将 lft或rgt 大于等于父级对象 rgt 的记录的 lft、rgt +offset
+ //int pLft = parentEntity.getLft();
+ int pRgt = parentEntity.getRgt();
+ updateLftRgtWhenInsert(pRgt, offset);
+
+ entity.setLft(pRgt);
+ entity.setRgt(pRgt + 1 + offset-2);
+
+ entity.setLevel(parentEntity.getLevel() + 1);
+ }
+
+ int newLft = entity.getLft();
+ int newRgt = entity.getRgt();
+ int newLevel = entity.getLevel();
+ //System.out.println(String.format("newLft %s, newRgt %s, newLevel %s", newLft, newRgt, newLevel));
+ //System.out.println(String.format("lft %s, rgt %s, level %s", lft, rgt, level));
+ for (Permission childEntity : childEntities) {
+ //Permission pEntity = this.selectById(childEntity.getParentId());
+
+ int cLft = childEntity.getLft();
+ int cRgt = childEntity.getRgt();
+ int cLevel = childEntity.getLevel();
+
+ childEntity.setLft(cLft + (newLft - lft));
+ childEntity.setRgt(cRgt + (newRgt - rgt));
+
+ childEntity.setLevel(cLevel + (newLevel - level));
+
+ BaseJpaRepository.super.update(childEntity);
+ }
+
+ }
+
+ return BaseJpaRepository.super.update(entity);
+ }
+
+ @Override
+ public default void delete(String id) {
+
+ Permission originEntity = this.selectById(id);
+ if (originEntity == null) {
+ return;
+ }
+
+ int lft = originEntity.getLft();
+ int rgt = originEntity.getRgt();
+ int offset = rgt - lft +1;
+
+ // FIXME: 判断是否有子节点
+ //if (lft + 1 != rgt) {
+ // return;
+ //}
+
+ List<Permission> childEntities = this.selectBetweenLftRgt(lft, rgt);
+ for (Permission childEntity : childEntities) {
+ BaseJpaRepository.super.delete(childEntity.getId());
+ }
+
+ // 将 lft或rgt 大于等于该对象 rgt 的记录的 lft、rgt -offset
+ updateLftRgtWhenDelete(rgt, offset);
+
+ BaseJpaRepository.super.delete(id);
+ }
+
+
+
+
+ public default List<Permission> selectList(boolean loadAll, int pageIndex, int pageSize, Map<String, Object> mapBean, Map<String, String> orderBy) {
+
+ Specification<Permission> spec = convertToSpec(mapBean);
+
+ if (loadAll) {
+ pageIndex = 0;
+ pageSize = Integer.MAX_VALUE;
+ }
+
+ Sort sort = convertToSort(orderBy);
+
+ if (sort == null) {
+ return this.findAll(spec);
+ } else {
+ return this.findAll(spec, sort);
+ }
+ }
+
+
+
+ @Query(value = "select p from Permission p "
+ + "inner join RolePermission rp on p.id=rp.permissionId "
+ + "inner join Role r on rp.roleId=r.id "
+ + "inner join AccountRole ar on r.id=ar.roleId "
+ + "inner join Account a on ar.accountId=a.id "
+ + "where a.username=:username "
+ + "and p.lft >= :lft and p.rgt <= :rgt "
+ + "and (:type is null or p.type=:type) "
+ + "and p.status='1' and r.status='1' and a.status='1' and a.enabled=1 ")
+ public List<Permission> selectAccountRolePermissionByUsername(@Param("username") String username, @Param("lft") int lft, @Param("rgt") int rgt, @Param("type") String type);
+
+ @Query(value = "select p from Permission p "
+ + "inner join RolePermission rp on p.id=rp.permissionId "
+ + "inner join Role r on rp.roleId=r.id "
+ + "inner join GroupRole gr on r.id=gr.roleId "
+ + "inner join Group_ g on gr.groupId=g.id "
+ + "inner join AccountGroup ag on g.id=ag.groupId "
+ + "inner join Account a on ag.accountId=a.id "
+ + "where a.username=:username "
+ + "and p.lft >= :lft and p.rgt <= :rgt "
+ + "and (:type is null or p.type=:type) "
+ + "and p.status='1' and r.status='1' and g.status='1' and a.status='1' and a.enabled=1 ")
+ public List<Permission> selectAccountGroupRolePermissionByUsername(@Param("username") String username, @Param("lft") int lft, @Param("rgt") int rgt, @Param("type") String type);
+
+
+ @Query(value = "select p from Permission p "
+ + "inner join RolePermission rp on p.id=rp.permissionId "
+ + "inner join Role r on rp.roleId=r.id "
+ + "inner join AccountRole ar on r.id=ar.roleId "
+ + "inner join Account a on ar.accountId=a.id "
+ + "where a.username=:username "
+ + "and p.applicationId = :applicationId "
+ + "and (:type is null or p.type=:type) "
+ + "and p.status='1' and r.status='1' and a.status='1' and a.enabled=1 ")
+ public List<Permission> selectAccountRolePermissionByUsername(@Param("username") String username, @Param("applicationId") String applicationId, @Param("type") String type);
+
+ @Query(value = "select p from Permission p "
+ + "inner join RolePermission rp on p.id=rp.permissionId "
+ + "inner join Role r on rp.roleId=r.id "
+ + "inner join GroupRole gr on r.id=gr.roleId "
+ + "inner join Group_ g on gr.groupId=g.id "
+ + "inner join AccountGroup ag on g.id=ag.groupId "
+ + "inner join Account a on ag.accountId=a.id "
+ + "where a.username=:username "
+ + "and p.applicationId = :applicationId "
+ + "and (:type is null or p.type=:type) "
+ + "and p.status='1' and r.status='1' and g.status='1' and a.status='1' and a.enabled=1 ")
+ public List<Permission> selectAccountGroupRolePermissionByUsername(@Param("username") String username, @Param("applicationId") String applicationId, @Param("type") String type);
+
+
+ @Query(value = "select p from Permission p "
+ + "inner join RolePermission rp on p.id=rp.permissionId "
+ + "inner join Role r on rp.roleId=r.id "
+ + "inner join AccountRole ar on r.id=ar.roleId "
+ + "inner join Account a on ar.accountId=a.id "
+ + "where a.username=:username "
+ + "and (:type is null or p.type=:type) "
+ + "and p.status='1' and r.status='1' and a.status='1' and a.enabled=1 ")
+ public List<Permission> selectAccountRolePermissionByUsername(@Param("username") String username, @Param("type") String type);
+
+ @Query(value = "select p from Permission p "
+ + "inner join RolePermission rp on p.id=rp.permissionId "
+ + "inner join Role r on rp.roleId=r.id "
+ + "inner join GroupRole gr on r.id=gr.roleId "
+ + "inner join Group_ g on gr.groupId=g.id "
+ + "inner join AccountGroup ag on g.id=ag.groupId "
+ + "inner join Account a on ag.accountId=a.id "
+ + "where a.username=:username "
+ + "and (:type is null or p.type=:type) "
+ + "and p.status='1' and r.status='1' and g.status='1' and a.status='1' and a.enabled=1 ")
+ public List<Permission> selectAccountGroupRolePermissionByUsername(@Param("username") String username, @Param("type") String type);
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/PermissionResourceRepository.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/PermissionResourceRepository.java
new file mode 100644
index 0000000..c40aef7
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/PermissionResourceRepository.java
@@ -0,0 +1,194 @@
+package com.supwisdom.institute.backend.base.domain.repo;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Repository;
+
+import com.supwisdom.institute.backend.base.domain.entity.Permission;
+import com.supwisdom.institute.backend.base.domain.entity.PermissionResource;
+import com.supwisdom.institute.backend.base.domain.entity.Resource;
+import com.supwisdom.institute.backend.common.framework.repo.BaseJpaRepository;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+@Repository
+public interface PermissionResourceRepository extends BaseJpaRepository<PermissionResource> {
+
+ public default Page<PermissionResource> selectPageList(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+ PermissionResource probe = new PermissionResource();
+ if (mapBean != null) {
+ probe.setPermissionId(MapBeanUtils.getString(mapBean, "permissionId"));
+ probe.setResourceId(MapBeanUtils.getString(mapBean, "resourceId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("permissionId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("resourceId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+ Example<PermissionResource> example = Example.of(probe, matcher);
+
+ Page<PermissionResource> page = this.findAll(example, pageRequest);
+
+ return page;
+ }
+
+ public default Page<PermissionResource> selectPermissionResources(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+
+ PermissionResource probe = new PermissionResource();
+ if (mapBean != null) {
+ probe.setPermissionId(MapBeanUtils.getString(mapBean, "permissionId"));
+ probe.setResourceId(MapBeanUtils.getString(mapBean, "resourceId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("permissionId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("resourceId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<PermissionResource> example = Example.of(probe, matcher);
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+
+ Page<PermissionResource> page = this.findAll(example, pageRequest); // FIXME: 多表关联查询
+
+ return page;
+ }
+
+ public default void relatePermissionResources(Permission permission, List<PermissionResource> relateResources) {
+
+ List<PermissionResource> existPermissionResources = this.selectListByPermissionId(permission.getId());
+
+ Map<String, PermissionResource> existMapPermissionResources = new LinkedHashMap<String, PermissionResource>();
+ for (PermissionResource permissionResource : existPermissionResources) {
+ String k = String.format("%s", permissionResource.getResourceId());
+ existMapPermissionResources.put(k, permissionResource);
+ }
+
+ for (PermissionResource permissionResource : relateResources) {
+ String k = String.format("%s", permissionResource.getResourceId());
+
+ if (existMapPermissionResources.containsKey(k)) {
+ existMapPermissionResources.remove(k);
+ } else {
+ permissionResource.setCompanyId(permission.getCompanyId());
+ permissionResource.setPermissionId(permission.getId());
+
+ this.insert(permissionResource);
+ }
+ }
+
+ for (PermissionResource rolePermission : existMapPermissionResources.values()) {
+ this.deleteById(rolePermission.getId());
+ }
+ }
+
+ public default List<PermissionResource> selectListByPermissionId(String permissionId) {
+
+ PermissionResource probe = new PermissionResource();
+ probe.setPermissionId(permissionId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("permissionId",
+ ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<PermissionResource> example = Example.of(probe, matcher);
+
+ List<PermissionResource> rolePermissions = this.findAll(example);
+
+ return rolePermissions;
+ }
+
+
+ public default void relateResourcePermissions(Resource resource, List<PermissionResource> relatePermissions) {
+
+ // 获取权限已关联的角色
+ List<PermissionResource> existResourcePermissions = this.selectListByResourceId(resource.getId());
+
+ Map<String, PermissionResource> existMapResourcePermissions = new LinkedHashMap<String, PermissionResource>();
+ for (PermissionResource permissionResource : existResourcePermissions) {
+ String k = String.format("%s", permissionResource.getPermissionId());
+ existMapResourcePermissions.put(k, permissionResource);
+ }
+
+ // 保存未关联的角色
+ for (PermissionResource permissionResource : relatePermissions) {
+ String k = String.format("%s", permissionResource.getPermissionId());
+
+ if (existMapResourcePermissions.containsKey(k)) {
+ existMapResourcePermissions.remove(k);
+ } else {
+ permissionResource.setCompanyId(resource.getCompanyId());
+ permissionResource.setResourceId(resource.getId());
+
+ this.insert(permissionResource);
+ }
+ }
+
+ // 删除移除关联的角色
+ for (PermissionResource rolePermission : existMapResourcePermissions.values()) {
+ this.deleteById(rolePermission.getId());
+ }
+ }
+ public default List<PermissionResource> selectListByResourceId(String resourceId) {
+
+ PermissionResource probe = new PermissionResource();
+ probe.setResourceId(resourceId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("resourceId",
+ ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<PermissionResource> example = Example.of(probe, matcher);
+
+ List<PermissionResource> rolePermissions = this.findAll(example);
+
+ return rolePermissions;
+ }
+
+
+ public default PermissionResource selectOneByPermissionResource(String permissionId, String resourceId) {
+
+ PermissionResource probe = new PermissionResource();
+ probe.setPermissionId(permissionId);
+ probe.setResourceId(resourceId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("permissionId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("resourceId", ExampleMatcher.GenericPropertyMatchers.exact())
+ ;
+
+ Example<PermissionResource> example = Example.of(probe, matcher);
+
+ Optional<PermissionResource> o = this.findOne(example);
+
+ return o.isPresent() ? o.get() : null;
+ }
+
+ public default void addPermissionResource(String permissionId, String resourceId) {
+
+ PermissionResource rolePermission = this.selectOneByPermissionResource(permissionId, resourceId);
+
+ if (rolePermission == null) {
+ rolePermission = new PermissionResource();
+ //rolePermission.setCompanyId(companyId);
+ rolePermission.setPermissionId(permissionId);
+ rolePermission.setResourceId(resourceId);
+
+ this.insert(rolePermission);
+ }
+ }
+
+ public default void removePermissionResource(String permissionId, String resourceId) {
+
+ PermissionResource rolePermission = this.selectOneByPermissionResource(permissionId, resourceId);
+
+ if (rolePermission != null) {
+ this.deleteById(rolePermission.getId());
+ }
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/ResourceRepository.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/ResourceRepository.java
new file mode 100644
index 0000000..a037866
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/ResourceRepository.java
@@ -0,0 +1,127 @@
+package com.supwisdom.institute.backend.base.domain.repo;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Repository;
+import org.springframework.util.StringUtils;
+
+import com.supwisdom.institute.backend.base.domain.entity.Resource;
+import com.supwisdom.institute.backend.common.framework.repo.BaseJpaRepository;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+@Repository
+public interface ResourceRepository extends BaseJpaRepository<Resource> {
+
+ @Override
+ public default Specification<Resource> convertToSpec(Map<String, Object> mapBean) {
+
+ Specification<Resource> spec = new Specification<Resource>() {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7690039558726467041L;
+
+ @Override
+ public Predicate toPredicate(Root<Resource> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
+ List<Predicate> predicates = new ArrayList<>();
+
+ if (mapBean != null) {
+
+ if (MapBeanUtils.getBoolean(mapBean, "deleted") != null) {
+ predicates.add(criteriaBuilder.equal(root.get("deleted"), MapBeanUtils.getBoolean(mapBean, "deleted")));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "code"))) {
+ predicates.add(criteriaBuilder.like(root.get("code"), "%" + MapBeanUtils.getString(mapBean, "code") + "%"));
+ }
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "name"))) {
+ predicates.add(criteriaBuilder.like(root.get("name"), "%" + MapBeanUtils.getString(mapBean, "name") + "%"));
+ }
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "memo"))) {
+ predicates.add(criteriaBuilder.like(root.get("memo"), "%" + MapBeanUtils.getString(mapBean, "memo") + "%"));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "status"))) {
+ predicates.add(criteriaBuilder.equal(root.get("status"), MapBeanUtils.getString(mapBean, "status")));
+ }
+
+ List<Predicate> predicatesKeyword = new ArrayList<>();
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "keyword"))) {
+ predicatesKeyword.add(criteriaBuilder.like(root.get("code"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+ predicatesKeyword.add(criteriaBuilder.like(root.get("name"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+ predicatesKeyword.add(criteriaBuilder.like(root.get("memo"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+
+ predicates.add(criteriaBuilder.or(predicatesKeyword.toArray(new Predicate[predicatesKeyword.size()])));
+ }
+ }
+
+ return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
+ }
+
+ };
+
+ return spec;
+ }
+
+// @Override
+// public default Page<Resource> selectPageList(boolean loadAll, int pageIndex, int pageSize, Map<String, Object> mapBean, Map<String, String> orderBy) {
+// if (loadAll) {
+// pageIndex = 0;
+// pageSize = Integer.MAX_VALUE;
+// }
+//
+// Resource probe = new Resource();
+// if (mapBean != null) {
+// probe.setDeleted(MapBeanUtils.getBoolean(mapBean, "deleted"));
+// probe.setCode(MapBeanUtils.getString(mapBean, "code"));
+// probe.setName(MapBeanUtils.getString(mapBean, "name"));
+// probe.setMemo(MapBeanUtils.getString(mapBean, "memo"));
+// probe.setStatus(MapBeanUtils.getString(mapBean, "status"));
+// }
+//
+// ExampleMatcher matcher = ExampleMatcher.matching()
+// .withMatcher("deleted", ExampleMatcher.GenericPropertyMatchers.exact())
+// .withMatcher("code", ExampleMatcher.GenericPropertyMatchers.contains())
+// .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains())
+// .withMatcher("memo", ExampleMatcher.GenericPropertyMatchers.contains())
+// .withMatcher("status", ExampleMatcher.GenericPropertyMatchers.exact());
+//
+// PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+// Example<Resource> example = Example.of(probe, matcher);
+//
+// Page<Resource> page = this.findAll(example, pageRequest);
+//
+// return page;
+// }
+
+ public default Resource selectByCode(String code) {
+ Resource probe = new Resource();
+ probe.setCode(code);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("code", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<Resource> example = Example.of(probe, matcher);
+
+ Optional<Resource> o = this.findOne(example);
+
+ if (o.isPresent()) {
+ return o.get();
+ }
+
+ return null;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/RolePermissionRepository.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/RolePermissionRepository.java
new file mode 100644
index 0000000..95f2814
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/RolePermissionRepository.java
@@ -0,0 +1,193 @@
+package com.supwisdom.institute.backend.base.domain.repo;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Repository;
+
+import com.supwisdom.institute.backend.base.domain.entity.Permission;
+import com.supwisdom.institute.backend.base.domain.entity.Role;
+import com.supwisdom.institute.backend.base.domain.entity.RolePermission;
+import com.supwisdom.institute.backend.common.framework.repo.BaseJpaRepository;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+@Repository
+public interface RolePermissionRepository extends BaseJpaRepository<RolePermission> {
+
+ public default Page<RolePermission> selectPageList(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+ RolePermission probe = new RolePermission();
+ if (mapBean != null) {
+ probe.setRoleId(MapBeanUtils.getString(mapBean, "roleId"));
+ probe.setPermissionId(MapBeanUtils.getString(mapBean, "permissionId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("permissionId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+ Example<RolePermission> example = Example.of(probe, matcher);
+
+ Page<RolePermission> page = this.findAll(example, pageRequest);
+
+ return page;
+ }
+
+ public default Page<RolePermission> selectRolePermissions(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+
+ RolePermission probe = new RolePermission();
+ if (mapBean != null) {
+ probe.setRoleId(MapBeanUtils.getString(mapBean, "roleId"));
+ probe.setPermissionId(MapBeanUtils.getString(mapBean, "permissionId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("permissionId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<RolePermission> example = Example.of(probe, matcher);
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+
+ Page<RolePermission> page = this.findAll(example, pageRequest); // FIXME: 多表关联查询
+
+ return page;
+ }
+
+ public default void relateRolePermissions(Role role, List<RolePermission> rolePermissions) {
+
+ List<RolePermission> existRolePermissions = this.selectListByRoleId(role.getId());
+
+ Map<String, RolePermission> existMapRolePermissions = new LinkedHashMap<String, RolePermission>();
+ for (RolePermission rolePermission : existRolePermissions) {
+ String k = String.format("%s", rolePermission.getPermissionId());
+ existMapRolePermissions.put(k, rolePermission);
+ }
+
+ for (RolePermission rolePermission : rolePermissions) {
+ String k = String.format("%s", rolePermission.getPermissionId());
+
+ if (existMapRolePermissions.containsKey(k)) {
+ existMapRolePermissions.remove(k);
+ } else {
+ rolePermission.setCompanyId(role.getCompanyId());
+ rolePermission.setRoleId(role.getId());
+
+ this.insert(rolePermission);
+ }
+ }
+
+ for (RolePermission rolePermission : existMapRolePermissions.values()) {
+ this.deleteById(rolePermission.getId());
+ }
+ }
+
+ public default List<RolePermission> selectListByRoleId(String roleId) {
+
+ RolePermission probe = new RolePermission();
+ probe.setRoleId(roleId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("roleId",
+ ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<RolePermission> example = Example.of(probe, matcher);
+
+ List<RolePermission> rolePermissions = this.findAll(example);
+
+ return rolePermissions;
+ }
+
+ public default void relatePermissionRoles(Permission permission, List<RolePermission> rolePermissions) {
+
+ // 获取权限已关联的角色
+ List<RolePermission> existPermissionRoles = this.selectListByPermissionId(permission.getId());
+
+ Map<String, RolePermission> existMapPermissionRoles = new LinkedHashMap<String, RolePermission>();
+ for (RolePermission rolePermission : existPermissionRoles) {
+ String k = String.format("%s", rolePermission.getRoleId());
+ existMapPermissionRoles.put(k, rolePermission);
+ }
+
+ // 保存未关联的角色
+ for (RolePermission rolePermission : rolePermissions) {
+ String k = String.format("%s", rolePermission.getRoleId());
+
+ if (existMapPermissionRoles.containsKey(k)) {
+ existMapPermissionRoles.remove(k);
+ } else {
+ rolePermission.setCompanyId(permission.getCompanyId());
+ rolePermission.setPermissionId(permission.getId());
+
+ this.insert(rolePermission);
+ }
+ }
+
+ // 删除移除关联的角色
+ for (RolePermission rolePermission : existMapPermissionRoles.values()) {
+ this.deleteById(rolePermission.getId());
+ }
+ }
+
+ public default List<RolePermission> selectListByPermissionId(String permissionId) {
+
+ RolePermission probe = new RolePermission();
+ probe.setPermissionId(permissionId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("permissionId",
+ ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<RolePermission> example = Example.of(probe, matcher);
+
+ List<RolePermission> rolePermissions = this.findAll(example);
+
+ return rolePermissions;
+ }
+
+ public default RolePermission selectOneByRolePermission(String roleId, String permissionId) {
+
+ RolePermission probe = new RolePermission();
+ probe.setRoleId(roleId);
+ probe.setPermissionId(permissionId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("permissionId", ExampleMatcher.GenericPropertyMatchers.exact())
+ ;
+
+ Example<RolePermission> example = Example.of(probe, matcher);
+
+ Optional<RolePermission> o = this.findOne(example);
+
+ return o.isPresent() ? o.get() : null;
+ }
+
+ public default void addRolePermission(String roleId, String permissionId) {
+
+ RolePermission rolePermission = this.selectOneByRolePermission(roleId, permissionId);
+
+ if (rolePermission == null) {
+ rolePermission = new RolePermission();
+ //rolePermission.setCompanyId(companyId);
+ rolePermission.setRoleId(roleId);
+ rolePermission.setPermissionId(permissionId);
+
+ this.insert(rolePermission);
+ }
+ }
+
+ public default void removeRolePermission(String roleId, String permissionId) {
+
+ RolePermission rolePermission = this.selectOneByRolePermission(roleId, permissionId);
+
+ if (rolePermission != null) {
+ this.deleteById(rolePermission.getId());
+ }
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/RoleRepository.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/RoleRepository.java
new file mode 100644
index 0000000..00c3ee6
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/RoleRepository.java
@@ -0,0 +1,164 @@
+package com.supwisdom.institute.backend.base.domain.repo;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Repository;
+import org.springframework.util.StringUtils;
+
+import com.supwisdom.institute.backend.base.domain.entity.Role;
+import com.supwisdom.institute.backend.common.framework.repo.BaseJpaRepository;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+@Repository
+public interface RoleRepository extends BaseJpaRepository<Role> {
+
+ @Override
+ public default Specification<Role> convertToSpec(Map<String, Object> mapBean) {
+
+ Specification<Role> spec = new Specification<Role>() {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -263282246904382286L;
+
+ @Override
+ public Predicate toPredicate(Root<Role> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
+ List<Predicate> predicates = new ArrayList<>();
+
+ if (mapBean != null) {
+
+ if (MapBeanUtils.getBoolean(mapBean, "deleted") != null) {
+ predicates.add(criteriaBuilder.equal(root.get("deleted"), MapBeanUtils.getBoolean(mapBean, "deleted")));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "code"))) {
+ predicates.add(criteriaBuilder.like(root.get("code"), "%" + MapBeanUtils.getString(mapBean, "code") + "%"));
+ }
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "name"))) {
+ predicates.add(criteriaBuilder.like(root.get("name"), "%" + MapBeanUtils.getString(mapBean, "name") + "%"));
+ }
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "memo"))) {
+ predicates.add(criteriaBuilder.like(root.get("memo"), "%" + MapBeanUtils.getString(mapBean, "memo") + "%"));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "status"))) {
+ predicates.add(criteriaBuilder.equal(root.get("status"), MapBeanUtils.getString(mapBean, "status")));
+ }
+
+ List<Predicate> predicatesKeyword = new ArrayList<>();
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "keyword"))) {
+ predicatesKeyword.add(criteriaBuilder.like(root.get("code"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+ predicatesKeyword.add(criteriaBuilder.like(root.get("name"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+ predicatesKeyword.add(criteriaBuilder.like(root.get("memo"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+
+ predicates.add(criteriaBuilder.or(predicatesKeyword.toArray(new Predicate[predicatesKeyword.size()])));
+ }
+ }
+
+ return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
+ }
+
+ };
+
+ return spec;
+ }
+
+// @Override
+// public default Page<Role> selectPageList(boolean loadAll, int pageIndex, int pageSize, Map<String, Object> mapBean, Map<String, String> orderBy) {
+// if (loadAll) {
+// pageIndex = 0;
+// pageSize = Integer.MAX_VALUE;
+// }
+//
+// Role probe = new Role();
+// if (mapBean != null) {
+// probe.setDeleted(MapBeanUtils.getBoolean(mapBean, "deleted"));
+// probe.setCode(MapBeanUtils.getString(mapBean, "code"));
+// probe.setName(MapBeanUtils.getString(mapBean, "name"));
+// probe.setMemo(MapBeanUtils.getString(mapBean, "memo"));
+// probe.setStatus(MapBeanUtils.getString(mapBean, "status"));
+// }
+//
+// ExampleMatcher matcher = ExampleMatcher.matching()
+// .withMatcher("deleted", ExampleMatcher.GenericPropertyMatchers.exact())
+// .withMatcher("code", ExampleMatcher.GenericPropertyMatchers.contains())
+// .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains())
+// .withMatcher("memo", ExampleMatcher.GenericPropertyMatchers.contains())
+// .withMatcher("status", ExampleMatcher.GenericPropertyMatchers.exact());
+//
+// PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+// Example<Role> example = Example.of(probe, matcher);
+//
+// Page<Role> page = this.findAll(example, pageRequest);
+//
+// return page;
+// }
+
+
+ public default Role selectByCode(String code) {
+ Role probe = new Role();
+ probe.setCode(code);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("code", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<Role> example = Example.of(probe, matcher);
+
+ Optional<Role> o = this.findOne(example);
+
+ if (o.isPresent()) {
+ return o.get();
+ }
+
+ return null;
+ }
+
+ @Query(value = "select r from Role r "
+ + "inner join AccountRole ar on r.id=ar.roleId "
+ + "inner join Account a on ar.accountId=a.id "
+ + "where a.username=:username "
+ + "and r.status='1' and a.status='1' and a.enabled=1 ")
+ public List<Role> selectAccountRoleByUsername(@Param("username") String username);
+
+ @Query(value = "select r from Role r "
+ + "inner join GroupRole gr on r.id=gr.roleId "
+ + "inner join Group_ g on gr.groupId=g.id "
+ + "inner join AccountGroup ag on g.id=ag.groupId "
+ + "inner join Account a on ag.accountId=a.id "
+ + "where a.username=:username "
+ + "and r.status='1' and g.status='1' and a.status='1' and a.enabled=1 ")
+ public List<Role> selectAccountGroupRoleByUsername(@Param("username") String username);
+
+
+ @Query(value = "select r from Role r "
+ + "inner join RolePermission rp on r.id=rp.roleId "
+ + "inner join Permission p on rp.permissionId=p.id "
+ + "where p.id=:permissionId "
+ + "and r.status='1' and p.status='1' ")
+ public List<Role> selectPermissionRolesByPermission(@Param("permissionId") String permissionId);
+
+
+ @Query(value = "select r from Role r "
+ + "inner join RolePermission rp on r.id=rp.roleId "
+ + "inner join Permission p on rp.permissionId=p.id "
+ + "inner join PermissionResource pres on p.id=pres.permissionId "
+ + "inner join Resource res on pres.resourceId=res.id "
+ + "where res.id=:resourceId "
+ + "and r.status='1' and p.status='1' and res.status='1' ")
+ public List<Role> selectResourceRolesByResource(@Param("resourceId") String resourceId);
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/RouteRepository.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/RouteRepository.java
new file mode 100644
index 0000000..425138b
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/repo/RouteRepository.java
@@ -0,0 +1,76 @@
+package com.supwisdom.institute.backend.base.domain.repo;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Repository;
+import org.springframework.util.StringUtils;
+
+import com.supwisdom.institute.backend.base.domain.entity.Route;
+import com.supwisdom.institute.backend.common.framework.repo.BaseJpaRepository;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+@Repository
+public interface RouteRepository extends BaseJpaRepository<Route> {
+
+ @Override
+ public default Specification<Route> convertToSpec(Map<String, Object> mapBean) {
+
+ Specification<Route> spec = new Specification<Route>() {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 9131799274128286026L;
+
+ @Override
+ public Predicate toPredicate(Root<Route> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
+ List<Predicate> predicates = new ArrayList<>();
+
+ if (mapBean != null) {
+
+ if (MapBeanUtils.getBoolean(mapBean, "deleted") != null) {
+ predicates.add(criteriaBuilder.equal(root.get("deleted"), MapBeanUtils.getBoolean(mapBean, "deleted")));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "code"))) {
+ predicates.add(criteriaBuilder.like(root.get("code"), "%" + MapBeanUtils.getString(mapBean, "code") + "%"));
+ }
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "name"))) {
+ predicates.add(criteriaBuilder.like(root.get("name"), "%" + MapBeanUtils.getString(mapBean, "name") + "%"));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "status"))) {
+ predicates.add(criteriaBuilder.equal(root.get("status"), MapBeanUtils.getString(mapBean, "status")));
+ }
+
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "url"))) {
+ predicates.add(criteriaBuilder.like(root.get("url"), "%" + MapBeanUtils.getString(mapBean, "url") + "%"));
+ }
+
+ List<Predicate> predicatesKeyword = new ArrayList<>();
+ if (!StringUtils.isEmpty(MapBeanUtils.getString(mapBean, "keyword"))) {
+ predicatesKeyword.add(criteriaBuilder.like(root.get("code"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+ predicatesKeyword.add(criteriaBuilder.like(root.get("name"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+ predicatesKeyword.add(criteriaBuilder.like(root.get("memo"), "%" + MapBeanUtils.getString(mapBean, "keyword") + "%"));
+
+ predicates.add(criteriaBuilder.or(predicatesKeyword.toArray(new Predicate[predicatesKeyword.size()])));
+ }
+ }
+
+ return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
+ }
+
+ };
+
+ return spec;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/.gitkeep b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/.gitkeep
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/AccountService.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/AccountService.java
new file mode 100644
index 0000000..b0cad6c
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/AccountService.java
@@ -0,0 +1,203 @@
+package com.supwisdom.institute.backend.base.domain.service;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Service;
+
+import com.supwisdom.institute.backend.base.domain.entity.Account;
+import com.supwisdom.institute.backend.base.domain.entity.AccountGroup;
+import com.supwisdom.institute.backend.base.domain.entity.AccountRole;
+import com.supwisdom.institute.backend.base.domain.repo.AccountGroupRepository;
+import com.supwisdom.institute.backend.base.domain.repo.AccountRepository;
+import com.supwisdom.institute.backend.base.domain.repo.AccountRoleRepository;
+import com.supwisdom.institute.backend.common.framework.service.ABaseService;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+@Service
+public class AccountService extends ABaseService<Account, AccountRepository> {
+
+ @Override
+ public AccountRepository getRepo() {
+ return accountRepository;
+ }
+
+ @Autowired
+ private AccountRepository accountRepository;
+
+ @Autowired
+ private AccountGroupRepository accountGroupRepository;
+
+ @Autowired
+ private AccountRoleRepository accountRoleRepository;
+
+
+ @Override
+ public Account insert(Account entity) {
+
+ entity.setEnabled(Account.STATUS_ENABLED.equals(entity.getStatus()));
+ entity.setAccountNonExpired(true);
+ entity.setAccountNonLocked(true);
+ entity.setCredentialsNonExpired(true);
+
+ return super.insert(entity);
+ }
+
+ @Override
+ public Account update(Account entity) {
+
+ entity.setEnabled(Account.STATUS_ENABLED.equals(entity.getStatus()));
+
+ return super.update(entity);
+ }
+
+
+ public void deleteBatch(List<String> ids) {
+
+ ids.stream().forEach(id -> {
+ this.deleteById(id);
+ });
+ }
+
+
+ public Page<AccountGroup> selectAccountGroups(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+
+ AccountGroup probe = new AccountGroup();
+ if (mapBean != null) {
+ probe.setGroupId(MapBeanUtils.getString(mapBean, "groupId"));
+ probe.setAccountId(MapBeanUtils.getString(mapBean, "accountId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("groupId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("accountId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<AccountGroup> example = Example.of(probe, matcher);
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+
+ Page<AccountGroup> page = accountGroupRepository.findAll(example, pageRequest); // FIXME: 多表关联查询
+
+ return page;
+ }
+
+ public void relateAccountGroups(Account account, List<AccountGroup> accountGroups) {
+
+ List<AccountGroup> existAccountGroups = this.selectAccountGroupsByAccountId(account.getId());
+
+ Map<String, AccountGroup> existMapAccountGroups = new LinkedHashMap<String, AccountGroup>();
+ for (AccountGroup accountGroup : existAccountGroups) {
+ String k = String.format("%s", accountGroup.getGroupId());
+ existMapAccountGroups.put(k, accountGroup);
+ }
+
+ for (AccountGroup accountGroup : accountGroups) {
+ String k = String.format("%s", accountGroup.getGroupId());
+
+ if (existMapAccountGroups.containsKey(k)) {
+ existMapAccountGroups.remove(k);
+ } else {
+ accountGroup.setCompanyId(account.getCompanyId());
+ accountGroup.setAccountId(account.getId());
+
+ accountGroupRepository.insert(accountGroup);
+ }
+ }
+
+ for (AccountGroup accountGroup : existMapAccountGroups.values()) {
+ accountGroupRepository.deleteById(accountGroup.getId());
+ }
+ }
+
+ public List<AccountGroup> selectAccountGroupsByAccountId(String accountId) {
+
+ AccountGroup probe = new AccountGroup();
+ probe.setAccountId(accountId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("accountId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<AccountGroup> example = Example.of(probe, matcher);
+
+ List<AccountGroup> accountGroups = accountGroupRepository.findAll(example);
+
+ return accountGroups;
+ }
+
+
+
+ public Page<AccountRole> selectAccountRoles(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+
+ AccountRole probe = new AccountRole();
+ if (mapBean != null) {
+ probe.setAccountId(MapBeanUtils.getString(mapBean, "accountId"));
+ probe.setRoleId(MapBeanUtils.getString(mapBean, "roleId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("accountId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<AccountRole> example = Example.of(probe, matcher);
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+
+ Page<AccountRole> page = accountRoleRepository.findAll(example, pageRequest); // FIXME: 多表关联查询
+
+ return page;
+ }
+
+ public void relateAccountRoles(Account account, List<AccountRole> accountRoles) {
+
+ List<AccountRole> existAccountRoles = this.selectAccountRolesByAccountId(account.getId());
+
+ Map<String, AccountRole> existMapAccountRoles = new LinkedHashMap<String, AccountRole>();
+ for (AccountRole accountRole : existAccountRoles) {
+ String k = String.format("%s", accountRole.getRoleId());
+ existMapAccountRoles.put(k, accountRole);
+ }
+
+ for (AccountRole accountRole : accountRoles) {
+ String k = String.format("%s", accountRole.getRoleId());
+
+ if (existMapAccountRoles.containsKey(k)) {
+ existMapAccountRoles.remove(k);
+ } else {
+ accountRole.setCompanyId(account.getCompanyId());
+ accountRole.setAccountId(account.getId());
+
+ accountRoleRepository.insert(accountRole);
+ }
+ }
+
+ for (AccountRole accountRole : existMapAccountRoles.values()) {
+ accountRoleRepository.deleteById(accountRole.getId());
+ }
+ }
+
+ public List<AccountRole> selectAccountRolesByAccountId(String accountId) {
+
+ AccountRole probe = new AccountRole();
+ probe.setAccountId(accountId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("accountId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<AccountRole> example = Example.of(probe, matcher);
+
+ List<AccountRole> accountRoles = accountRoleRepository.findAll(example);
+
+ return accountRoles;
+ }
+
+
+ public Account selectByUsername(String username) {
+ return accountRepository.selectByUsername(username);
+ }
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/ApplicationService.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/ApplicationService.java
new file mode 100644
index 0000000..17e7503
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/ApplicationService.java
@@ -0,0 +1,91 @@
+package com.supwisdom.institute.backend.base.domain.service;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.supwisdom.institute.backend.base.domain.entity.Application;
+import com.supwisdom.institute.backend.base.domain.entity.Permission;
+import com.supwisdom.institute.backend.base.domain.repo.ApplicationRepository;
+import com.supwisdom.institute.backend.base.domain.repo.PermissionRepository;
+import com.supwisdom.institute.backend.common.framework.service.ABaseService;
+
+@Service
+public class ApplicationService extends ABaseService<Application, ApplicationRepository> {
+
+ @Override
+ public ApplicationRepository getRepo() {
+ return applicationRepository;
+ }
+
+ @Autowired
+ private ApplicationRepository applicationRepository;
+
+ @Autowired
+ private PermissionRepository permissionRepository;
+
+ @Override
+ public Application insert(Application entity) {
+ entity = super.insert(entity);
+
+ Permission p = new Permission();
+ p.setId(entity.getId());
+ p.setCode(entity.getCode());
+ p.setName(entity.getName());
+ p.setMemo(entity.getMemo());
+ p.setStatus(entity.getStatus());
+ p.setType(Permission.TYPE_APPLICATION);
+ p.setApplicationId(entity.getId());
+ p.setParentId(Permission.ROOT_PARENT_ID);
+ p.setOrder(Permission.DEFAULT_ORDER);
+
+ permissionRepository.insert(p);
+
+ return entity;
+ }
+
+ @Override
+ public Application update(Application entity) {
+ entity = super.update(entity);
+
+ Permission p = permissionRepository.selectById(entity.getId());
+ if (p != null) {
+ p = new Permission();
+ p.setCode(entity.getCode());
+ p.setName(entity.getName());
+ p.setMemo(entity.getMemo());
+ p.setStatus(entity.getStatus());
+ p.setType(Permission.TYPE_APPLICATION);
+ p.setApplicationId(entity.getId());
+ p.setParentId(Permission.ROOT_PARENT_ID);
+ p.setOrder(Permission.DEFAULT_ORDER);
+
+ permissionRepository.update(p);
+ } else {
+ p = new Permission();
+ p.setId(entity.getId());
+ p.setCode(entity.getCode());
+ p.setName(entity.getName());
+ p.setMemo(entity.getMemo());
+ p.setStatus(entity.getStatus());
+ p.setType(Permission.TYPE_APPLICATION);
+ p.setApplicationId(entity.getId());
+ p.setParentId(Permission.ROOT_PARENT_ID);
+ p.setOrder(Permission.DEFAULT_ORDER);
+
+ permissionRepository.insert(p);
+ }
+
+ return entity;
+ }
+
+ public void deleteBatch(List<String> ids) {
+
+ ids.stream().forEach(id -> {
+ this.deleteById(id);
+ });
+ }
+
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/ConfigService.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/ConfigService.java
new file mode 100644
index 0000000..d41e362
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/ConfigService.java
@@ -0,0 +1,26 @@
+package com.supwisdom.institute.backend.base.domain.service;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.supwisdom.institute.backend.base.domain.entity.Config;
+import com.supwisdom.institute.backend.base.domain.repo.ConfigRepository;
+import com.supwisdom.institute.backend.common.framework.service.ABaseService;
+
+@Service
+public class ConfigService extends ABaseService<Config, ConfigRepository> {
+
+ @Override
+ public ConfigRepository getRepo() {
+ return configRepository;
+ }
+
+ @Autowired
+ private ConfigRepository configRepository;
+
+ public Config selectByCategoryKey(String categoryCode, String configKey) {
+
+ return configRepository.selectByCategoryKey(categoryCode, configKey);
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/GroupService.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/GroupService.java
new file mode 100644
index 0000000..9951b3a
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/GroupService.java
@@ -0,0 +1,182 @@
+package com.supwisdom.institute.backend.base.domain.service;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Service;
+
+import com.supwisdom.institute.backend.base.domain.entity.AccountGroup;
+import com.supwisdom.institute.backend.base.domain.entity.Group;
+import com.supwisdom.institute.backend.base.domain.entity.GroupRole;
+import com.supwisdom.institute.backend.base.domain.repo.AccountGroupRepository;
+import com.supwisdom.institute.backend.base.domain.repo.GroupRepository;
+import com.supwisdom.institute.backend.base.domain.repo.GroupRoleRepository;
+import com.supwisdom.institute.backend.common.framework.service.ABaseService;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+@Service
+public class GroupService extends ABaseService<Group, GroupRepository> {
+
+ @Override
+ public GroupRepository getRepo() {
+ return groupRepository;
+ }
+
+ @Autowired
+ private GroupRepository groupRepository;
+
+ @Autowired
+ private AccountGroupRepository accountGroupRepository;
+
+ @Autowired
+ private GroupRoleRepository groupRoleRepository;
+
+
+ public void deleteBatch(List<String> ids) {
+
+ ids.stream().forEach(id -> {
+ this.deleteById(id);
+ });
+ }
+
+
+ public Page<AccountGroup> selectGroupAccounts(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+
+ AccountGroup probe = new AccountGroup();
+ if (mapBean != null) {
+ probe.setAccountId(MapBeanUtils.getString(mapBean, "accountId"));
+ probe.setGroupId(MapBeanUtils.getString(mapBean, "groupId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("accountId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("groupId", ExampleMatcher.GenericPropertyMatchers.exact())
+ ;
+
+ Example<AccountGroup> example = Example.of(probe, matcher);
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+
+ Page<AccountGroup> page = accountGroupRepository.findAll(example, pageRequest); // FIXME: 多表关联查询
+
+ return page;
+ }
+
+ public void relateGroupAccounts(Group group, List<AccountGroup> accountGroups) {
+
+ List<AccountGroup> existGroupAccounts = this.selectGroupAccountsByGroupId(group.getId());
+
+ Map<String, AccountGroup> existMapGroupAccounts = new LinkedHashMap<String, AccountGroup>();
+ for (AccountGroup accountGroup : existGroupAccounts) {
+ String k = String.format("%s", accountGroup.getAccountId());
+ existMapGroupAccounts.put(k, accountGroup);
+ }
+
+ for (AccountGroup accountGroup : accountGroups) {
+ String k = String.format("%s", accountGroup.getAccountId());
+
+ if (existMapGroupAccounts.containsKey(k)) {
+ existMapGroupAccounts.remove(k);
+ } else {
+ accountGroup.setCompanyId(group.getCompanyId());
+ accountGroup.setGroupId(group.getId());
+
+ accountGroupRepository.insert(accountGroup);
+ }
+ }
+
+ for (AccountGroup accountGroup : existMapGroupAccounts.values()) {
+ accountGroupRepository.deleteById(accountGroup.getId());
+ }
+ }
+
+ public List<AccountGroup> selectGroupAccountsByGroupId(String groupId) {
+
+ AccountGroup probe = new AccountGroup();
+ probe.setGroupId(groupId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("groupId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<AccountGroup> example = Example.of(probe, matcher);
+
+ List<AccountGroup> accountGroups = accountGroupRepository.findAll(example);
+
+ return accountGroups;
+ }
+
+
+
+
+ public Page<GroupRole> selectGroupRoles(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+
+ GroupRole probe = new GroupRole();
+ if (mapBean != null) {
+ probe.setGroupId(MapBeanUtils.getString(mapBean, "groupId"));
+ probe.setRoleId(MapBeanUtils.getString(mapBean, "roleId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("groupId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<GroupRole> example = Example.of(probe, matcher);
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+
+ Page<GroupRole> page = groupRoleRepository.findAll(example, pageRequest); // FIXME: 多表关联查询
+
+ return page;
+ }
+
+ public void relateGroupRoles(Group group, List<GroupRole> groupRoles) {
+
+ List<GroupRole> existGroupRoles = this.selectGroupRolesByGroupId(group.getId());
+
+ Map<String, GroupRole> existMapGroupRoles = new LinkedHashMap<String, GroupRole>();
+ for (GroupRole groupRole : existGroupRoles) {
+ String k = String.format("%s", groupRole.getRoleId());
+ existMapGroupRoles.put(k, groupRole);
+ }
+
+ for (GroupRole groupRole : groupRoles) {
+ String k = String.format("%s", groupRole.getRoleId());
+
+ if (existMapGroupRoles.containsKey(k)) {
+ existMapGroupRoles.remove(k);
+ } else {
+ groupRole.setCompanyId(group.getCompanyId());
+ groupRole.setGroupId(group.getId());
+
+ groupRoleRepository.insert(groupRole);
+ }
+ }
+
+ for (GroupRole groupRole : existMapGroupRoles.values()) {
+ groupRoleRepository.deleteById(groupRole.getId());
+ }
+ }
+
+ public List<GroupRole> selectGroupRolesByGroupId(String groupId) {
+
+ GroupRole probe = new GroupRole();
+ probe.setGroupId(groupId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("groupId",
+ ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<GroupRole> example = Example.of(probe, matcher);
+
+ List<GroupRole> groupRoles = groupRoleRepository.findAll(example);
+
+ return groupRoles;
+ }
+
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/PermissionService.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/PermissionService.java
new file mode 100644
index 0000000..c546400
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/PermissionService.java
@@ -0,0 +1,319 @@
+package com.supwisdom.institute.backend.base.domain.service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Service;
+
+import com.supwisdom.institute.backend.base.domain.entity.Permission;
+import com.supwisdom.institute.backend.base.domain.entity.PermissionResource;
+import com.supwisdom.institute.backend.base.domain.entity.Role;
+import com.supwisdom.institute.backend.base.domain.model.PermissionRoleSet;
+import com.supwisdom.institute.backend.base.domain.model.PermissionTreeNode;
+import com.supwisdom.institute.backend.base.domain.repo.PermissionRepository;
+import com.supwisdom.institute.backend.base.domain.repo.PermissionResourceRepository;
+import com.supwisdom.institute.backend.base.domain.repo.RoleRepository;
+import com.supwisdom.institute.backend.common.framework.entity.EntityUtils;
+import com.supwisdom.institute.backend.common.framework.service.ABaseService;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+@Slf4j
+@Service
+public class PermissionService extends ABaseService<Permission, PermissionRepository> {
+
+ @Override
+ public PermissionRepository getRepo() {
+ return permissionRepository;
+ }
+
+ @Autowired
+ private PermissionRepository permissionRepository;
+
+ @Autowired
+ private PermissionResourceRepository permissionResourceRepository;
+
+ @Autowired
+ private RoleRepository roleRepository;
+
+ @Override
+ public Permission insert(Permission entity) {
+ Permission parentPermission = permissionRepository.selectById(entity.getParentId());
+ if (parentPermission != null) {
+ entity.setApplicationId(parentPermission.getApplicationId());
+ }
+
+ return super.insert(entity);
+ }
+
+ public void deleteBatch(List<String> ids) {
+
+ ids.stream().forEach(id -> {
+ this.deleteById(id);
+ });
+ }
+
+
+
+ public Page<PermissionResource> selectPermissionResources(boolean loadAll, int pageIndex, int pageSize, Map<String, Object> mapBean) {
+
+ if (loadAll) {
+ pageIndex = 0;
+ pageSize = Integer.MAX_VALUE;
+ }
+
+ PermissionResource probe = new PermissionResource();
+ if (mapBean != null) {
+ probe.setPermissionId(MapBeanUtils.getString(mapBean, "permissionId"));
+ probe.setResourceId(MapBeanUtils.getString(mapBean, "resourceId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("permissionId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("resourceId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<PermissionResource> example = Example.of(probe, matcher);
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+
+ Page<PermissionResource> page = permissionResourceRepository.findAll(example, pageRequest); // FIXME: 多表关联查询
+
+ return page;
+ }
+
+ public void relatePermissionResources(Permission permission, List<PermissionResource> permissionResources) {
+
+ List<PermissionResource> existPermissionResources = this.selectPermissionResourcesByPermissionId(permission.getId());
+
+ Map<String, PermissionResource> existMapPermissionResources = new LinkedHashMap<String, PermissionResource>();
+ for (PermissionResource permissionResource : existPermissionResources) {
+ String k = String.format("%s", permissionResource.getPermissionId());
+ existMapPermissionResources.put(k, permissionResource);
+ }
+
+ for (PermissionResource permissionResource : permissionResources) {
+ String k = String.format("%s", permissionResource.getPermissionId());
+
+ if (existMapPermissionResources.containsKey(k)) {
+ existMapPermissionResources.remove(k);
+ } else {
+ permissionResource.setCompanyId(permission.getCompanyId());
+ permissionResource.setPermissionId(permission.getId());
+
+ permissionResourceRepository.insert(permissionResource);
+ }
+ }
+
+ for (PermissionResource permissionResource : existMapPermissionResources.values()) {
+ permissionResourceRepository.deleteById(permissionResource.getId());
+ }
+ }
+
+ public List<PermissionResource> selectPermissionResourcesByPermissionId(String permissionId) {
+
+ PermissionResource probe = new PermissionResource();
+ probe.setPermissionId(permissionId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("permissionId",
+ ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<PermissionResource> example = Example.of(probe, matcher);
+
+ List<PermissionResource> permissionResources = permissionResourceRepository.findAll(example);
+
+ return permissionResources;
+ }
+
+
+ private Permission selectApplicationPermission() {
+ Permission permission = permissionRepository.selectById(Permission.APPLICATION_ID);
+
+ return permission;
+ }
+
+ private List<Permission> selectApplicationPermissionList() {
+ Map<String, Object> mapBean = new HashMap<String, Object>();
+ mapBean.put("type", Permission.TYPE_APPLICATION);
+
+ return permissionRepository.selectList(true, -1, -1, mapBean, null);
+ }
+
+ public PermissionTreeNode selectPermissionTree(String applicationId, String type) {
+
+ Map<String, Object> mapBean = new HashMap<String, Object>();
+ if (StringUtils.isNotBlank(type)) {
+ mapBean.put("type", type);
+ }
+
+ String rootTreeNodeId = "0";
+
+ List<Permission> permissions = new ArrayList<Permission>();
+
+ if (StringUtils.isBlank(applicationId)) {
+ Permission rootPermission = new Permission();
+ rootPermission.setId(Permission.ROOT_PARENT_ID);
+ rootPermission.setCode("root");
+ rootPermission.setName("根");
+
+ permissions.add(rootPermission);
+ rootTreeNodeId = rootPermission.getId();
+
+ List<Permission> applicationPermissions = this.selectApplicationPermissionList();
+ permissions.addAll(applicationPermissions);
+ } else {
+ Permission applicationPermission = permissionRepository.selectById(applicationId); // this.selectApplicationPermissionByCode(applicationCode);
+ if (applicationPermission == null) {
+ return null;
+ }
+
+ permissions.add(applicationPermission);
+ rootTreeNodeId = applicationPermission.getId();
+ }
+
+ List<Permission> menuPermissions = permissionRepository.selectList(true, -1, -1, mapBean, null);
+ permissions.addAll(menuPermissions);
+
+ return convertPermissionTree(permissions, rootTreeNodeId);
+ }
+
+ private PermissionTreeNode convertPermissionTree(List<Permission> permissions, String rootTreeNodeId) {
+ if (permissions == null || permissions.size() == 0) {
+ return null;
+ }
+
+ Map<String, PermissionTreeNode> parentTreeNode = new LinkedHashMap<String, PermissionTreeNode>();
+
+ for (Permission permission : permissions) {
+ PermissionTreeNode treeNode = EntityUtils.copy(permission, new PermissionTreeNode());
+ treeNode.setChildren(new ArrayList<PermissionTreeNode>());
+
+ if (parentTreeNode.containsKey(treeNode.getId())) {
+ continue;
+ }
+ parentTreeNode.put(treeNode.getId(), treeNode);
+ }
+
+ for (PermissionTreeNode treeNode : parentTreeNode.values()) {
+ if (!parentTreeNode.containsKey(treeNode.getParentId())) {
+ continue;
+ }
+
+ parentTreeNode.get(treeNode.getParentId()).getChildren().add(treeNode);
+ }
+
+ return parentTreeNode.get(rootTreeNodeId);
+ }
+
+
+
+// public Permission selectApplicationPermissionByCode(String code) {
+// Permission probe = new Permission();
+// probe.setCode(code);
+// probe.setType("1");
+//
+// ExampleMatcher matcher = ExampleMatcher.matching()
+// .withMatcher("code", ExampleMatcher.GenericPropertyMatchers.exact())
+// .withMatcher("type", ExampleMatcher.GenericPropertyMatchers.exact());
+//
+// Example<Permission> example = Example.of(probe, matcher);
+//
+// Optional<Permission> o = permissionRepository.findOne(example);
+//
+// if (o.isPresent()) {
+// return o.get();
+// }
+//
+// return null;
+// }
+
+
+ public List<Permission> selectByUsername(String username, String applicationId, String type) {
+ List<Permission> permissions = new ArrayList<Permission>();
+
+// Permission applicationPermission = permissionRepository.selectById(applicationId);
+// if (applicationPermission == null) {
+// return permissions;
+// }
+//
+// int lft = applicationPermission.getLft();
+// int rgt = applicationPermission.getRgt();
+
+ if (StringUtils.isBlank(applicationId)) {
+ List<Permission> accountRolePermissions = permissionRepository.selectAccountRolePermissionByUsername(username, type);
+ permissions.addAll(accountRolePermissions);
+
+ List<Permission> accountGroupRolePermissions = permissionRepository.selectAccountGroupRolePermissionByUsername(username, type);
+ permissions.addAll(accountGroupRolePermissions);
+ } else {
+ List<Permission> accountRolePermissions = permissionRepository.selectAccountRolePermissionByUsername(username, applicationId, type);
+ permissions.addAll(accountRolePermissions);
+
+ List<Permission> accountGroupRolePermissions = permissionRepository.selectAccountGroupRolePermissionByUsername(username, applicationId, type);
+ permissions.addAll(accountGroupRolePermissions);
+ }
+
+ return EntityUtils.distinctList(permissions);
+ }
+
+ @Deprecated
+ public PermissionTreeNode selectPermissionTreeByUsername(String username, String applicationId, String type) {
+ String rootTreeNodeId = "0";
+
+ List<Permission> permissions = new ArrayList<Permission>();
+
+ if (StringUtils.isBlank(applicationId)) {
+ Permission rootPermission = new Permission();
+ rootPermission.setId(Permission.ROOT_PARENT_ID);
+ rootPermission.setCode("root");
+ rootPermission.setName("根");
+
+ permissions.add(rootPermission);
+ rootTreeNodeId = rootPermission.getId();
+
+ List<Permission> applicationPermissions = this.selectApplicationPermissionList();
+ permissions.addAll(applicationPermissions);
+ } else {
+ Permission applicationPermission = permissionRepository.selectById(applicationId); // this.selectApplicationPermissionByCode(applicationCode);
+ if (applicationPermission == null) {
+ return null;
+ }
+
+ permissions.add(applicationPermission);
+ rootTreeNodeId = applicationPermission.getId();
+ }
+
+ List<Permission> menuPermissions = this.selectByUsername(username, applicationId, type);
+ permissions.addAll(menuPermissions);
+
+ return convertPermissionTree(permissions, rootTreeNodeId);
+ }
+
+ public List<PermissionRoleSet> selectPermissionRoleSet(Map<String, Object> mapBean) {
+
+ List<PermissionRoleSet> prsList = new ArrayList<>();
+
+ List<Permission> resourceList = permissionRepository.selectList(mapBean, null);
+
+ for (Permission permission : resourceList) {
+
+ List<Role> roleList = roleRepository.selectPermissionRolesByPermission(permission.getId());
+
+ PermissionRoleSet prs = new PermissionRoleSet(permission, roleList);
+
+ prsList.add(prs);
+ }
+
+ return prsList;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/ResourceService.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/ResourceService.java
new file mode 100644
index 0000000..eea0422
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/ResourceService.java
@@ -0,0 +1,58 @@
+package com.supwisdom.institute.backend.base.domain.service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.supwisdom.institute.backend.base.domain.entity.Resource;
+import com.supwisdom.institute.backend.base.domain.entity.Role;
+import com.supwisdom.institute.backend.base.domain.model.ResourceRoleSet;
+import com.supwisdom.institute.backend.base.domain.repo.ResourceRepository;
+import com.supwisdom.institute.backend.base.domain.repo.RoleRepository;
+import com.supwisdom.institute.backend.common.framework.service.ABaseService;
+
+@Service
+public class ResourceService extends ABaseService<Resource, ResourceRepository> {
+
+ @Override
+ public ResourceRepository getRepo() {
+ return resourceRepository;
+ }
+
+ @Autowired
+ private ResourceRepository resourceRepository;
+
+ @Autowired
+ private RoleRepository roleRepository;
+
+
+ public void deleteBatch(List<String> ids) {
+
+ ids.stream().forEach(id -> {
+ this.deleteById(id);
+ });
+ }
+
+
+ public List<ResourceRoleSet> selectResourceRoleSet(Map<String, Object> mapBean) {
+
+ List<ResourceRoleSet> rrsList = new ArrayList<>();
+
+ List<Resource> resourceList = resourceRepository.selectList(mapBean, null);
+
+ for (Resource resource : resourceList) {
+
+ List<Role> roleList = roleRepository.selectResourceRolesByResource(resource.getId());
+
+ ResourceRoleSet rrs = new ResourceRoleSet(resource, roleList);
+
+ rrsList.add(rrs);
+ }
+
+ return rrsList;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/RoleService.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/RoleService.java
new file mode 100644
index 0000000..c66e3ff
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/RoleService.java
@@ -0,0 +1,268 @@
+package com.supwisdom.institute.backend.base.domain.service;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Service;
+
+import com.supwisdom.institute.backend.base.domain.entity.AccountRole;
+import com.supwisdom.institute.backend.base.domain.entity.GroupRole;
+import com.supwisdom.institute.backend.base.domain.entity.Role;
+import com.supwisdom.institute.backend.base.domain.entity.RolePermission;
+import com.supwisdom.institute.backend.base.domain.repo.AccountRoleRepository;
+import com.supwisdom.institute.backend.base.domain.repo.GroupRoleRepository;
+import com.supwisdom.institute.backend.base.domain.repo.RolePermissionRepository;
+import com.supwisdom.institute.backend.base.domain.repo.RoleRepository;
+import com.supwisdom.institute.backend.common.framework.entity.EntityUtils;
+import com.supwisdom.institute.backend.common.framework.service.ABaseService;
+import com.supwisdom.institute.backend.common.util.MapBeanUtils;
+
+@Service
+public class RoleService extends ABaseService<Role, RoleRepository> {
+
+ @Override
+ public RoleRepository getRepo() {
+ return roleRepository;
+ }
+
+ @Autowired
+ private RoleRepository roleRepository;
+
+ @Autowired
+ private AccountRoleRepository accountRoleRepository;
+
+ @Autowired
+ private GroupRoleRepository groupRoleRepository;
+
+ @Autowired
+ private RolePermissionRepository rolePermissionRepository;
+
+
+ public void deleteBatch(List<String> ids) {
+
+ ids.stream().forEach(id -> {
+ this.deleteById(id);
+ });
+ }
+
+
+ public Page<AccountRole> selectRoleAccounts(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+
+ AccountRole probe = new AccountRole();
+ if (mapBean != null) {
+ probe.setAccountId(MapBeanUtils.getString(mapBean, "accountId"));
+ probe.setRoleId(MapBeanUtils.getString(mapBean, "roleId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("accountId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<AccountRole> example = Example.of(probe, matcher);
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+
+ Page<AccountRole> page = accountRoleRepository.findAll(example, pageRequest); // FIXME: 多表关联查询
+
+ return page;
+ }
+
+ public void relateRoleAccounts(Role role, List<AccountRole> roleAccounts) {
+
+ List<AccountRole> existRoleAccounts = this.selectRoleAccountsByRoleId(role.getId());
+
+ Map<String, AccountRole> existMapRoleAccounts = new LinkedHashMap<String, AccountRole>();
+ for (AccountRole accountRole : existRoleAccounts) {
+ String k = String.format("%s", accountRole.getAccountId());
+ existMapRoleAccounts.put(k, accountRole);
+ }
+
+ for (AccountRole accountRole : roleAccounts) {
+ String k = String.format("%s", accountRole.getAccountId());
+
+ if (existMapRoleAccounts.containsKey(k)) {
+ existMapRoleAccounts.remove(k);
+ } else {
+ accountRole.setCompanyId(role.getCompanyId());
+ accountRole.setRoleId(role.getId());
+
+ accountRoleRepository.insert(accountRole);
+ }
+ }
+
+ for (AccountRole accountRole : existMapRoleAccounts.values()) {
+ accountRoleRepository.deleteById(accountRole.getId());
+ }
+ }
+
+ public List<AccountRole> selectRoleAccountsByRoleId(String roleId) {
+
+ AccountRole probe = new AccountRole();
+ probe.setRoleId(roleId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<AccountRole> example = Example.of(probe, matcher);
+
+ List<AccountRole> accountRoles = accountRoleRepository.findAll(example);
+
+ return accountRoles;
+ }
+
+
+
+ public Page<GroupRole> selectRoleGroups(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+
+ GroupRole probe = new GroupRole();
+ if (mapBean != null) {
+ probe.setGroupId(MapBeanUtils.getString(mapBean, "groupId"));
+ probe.setRoleId(MapBeanUtils.getString(mapBean, "roleId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("groupId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<GroupRole> example = Example.of(probe, matcher);
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+
+ Page<GroupRole> page = groupRoleRepository.findAll(example, pageRequest); // FIXME: 多表关联查询
+
+ return page;
+ }
+
+ public void relateRoleGroups(Role role, List<GroupRole> groupRoles) {
+
+ List<GroupRole> existRoleGroups = this.selectRoleGroupsByRoleId(role.getCode());
+
+ Map<String, GroupRole> existMapRoleGroups = new LinkedHashMap<String, GroupRole>();
+ for (GroupRole groupRole : existRoleGroups) {
+ String k = String.format("%s", groupRole.getGroupId());
+ existMapRoleGroups.put(k, groupRole);
+ }
+
+ for (GroupRole groupRole : groupRoles) {
+ String k = String.format("%s", groupRole.getGroupId());
+
+ if (existMapRoleGroups.containsKey(k)) {
+ existMapRoleGroups.remove(k);
+ } else {
+ groupRole.setCompanyId(role.getCompanyId());
+ groupRole.setRoleId(role.getId());
+
+ groupRoleRepository.insert(groupRole);
+ }
+ }
+
+ for (GroupRole groupRole : existMapRoleGroups.values()) {
+ groupRoleRepository.deleteById(groupRole.getId());
+ }
+ }
+
+ public List<GroupRole> selectRoleGroupsByRoleId(String roleId) {
+
+ GroupRole probe = new GroupRole();
+ probe.setRoleId(roleId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<GroupRole> example = Example.of(probe, matcher);
+
+ List<GroupRole> groupRoles = groupRoleRepository.findAll(example);
+
+ return groupRoles;
+ }
+
+
+ public Page<RolePermission> selectRolePermissions(int pageIndex, int pageSize, Map<String, Object> mapBean) {
+
+ RolePermission probe = new RolePermission();
+ if (mapBean != null) {
+ probe.setRoleId(MapBeanUtils.getString(mapBean, "roleId"));
+ probe.setPermissionId(MapBeanUtils.getString(mapBean, "permissionId"));
+ }
+
+ ExampleMatcher matcher = ExampleMatcher.matching()
+ .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.exact())
+ .withMatcher("permissionId", ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<RolePermission> example = Example.of(probe, matcher);
+
+ PageRequest pageRequest = PageRequest.of(pageIndex, pageSize);
+
+ Page<RolePermission> page = rolePermissionRepository.findAll(example, pageRequest); // FIXME: 多表关联查询
+
+ return page;
+ }
+
+ public void relateRolePermissions(Role role, List<RolePermission> rolePermissions) {
+
+ List<RolePermission> existRolePermissions = this.selectRolePermissionsByRoleId(role.getId());
+
+ Map<String, RolePermission> existMapRolePermissions = new LinkedHashMap<String, RolePermission>();
+ for (RolePermission rolePermission : existRolePermissions) {
+ String k = String.format("%s", rolePermission.getPermissionId());
+ existMapRolePermissions.put(k, rolePermission);
+ }
+
+ for (RolePermission rolePermission : rolePermissions) {
+ String k = String.format("%s", rolePermission.getPermissionId());
+
+ if (existMapRolePermissions.containsKey(k)) {
+ existMapRolePermissions.remove(k);
+ } else {
+ rolePermission.setCompanyId(role.getCompanyId());
+ rolePermission.setRoleId(role.getId());
+
+ rolePermissionRepository.insert(rolePermission);
+ }
+ }
+
+ for (RolePermission rolePermission : existMapRolePermissions.values()) {
+ rolePermissionRepository.deleteById(rolePermission.getId());
+ }
+ }
+
+ public List<RolePermission> selectRolePermissionsByRoleId(String roleId) {
+
+ RolePermission probe = new RolePermission();
+ probe.setRoleId(roleId);
+
+ ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("roleId",
+ ExampleMatcher.GenericPropertyMatchers.exact());
+
+ Example<RolePermission> example = Example.of(probe, matcher);
+
+ List<RolePermission> rolePermissions = rolePermissionRepository.findAll(example);
+
+ return rolePermissions;
+ }
+
+
+
+
+ public List<Role> selectByUsername(String username) {
+ List<Role> roles = new ArrayList<Role>();
+
+ List<Role> userRoles = roleRepository.selectAccountRoleByUsername(username);
+ roles.addAll(userRoles);
+
+ List<Role> userGroupRoles = roleRepository.selectAccountGroupRoleByUsername(username);
+ roles.addAll(userGroupRoles);
+
+ roles = EntityUtils.distinctList(roles);
+
+ return roles;
+ }
+
+}
diff --git a/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/RouteService.java b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/RouteService.java
new file mode 100644
index 0000000..f93595f
--- /dev/null
+++ b/admin-sa/base/domain/src/main/java/com/supwisdom/institute/backend/base/domain/service/RouteService.java
@@ -0,0 +1,32 @@
+package com.supwisdom.institute.backend.base.domain.service;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.supwisdom.institute.backend.base.domain.entity.Route;
+import com.supwisdom.institute.backend.base.domain.repo.RouteRepository;
+import com.supwisdom.institute.backend.common.framework.service.ABaseService;
+
+@Service
+public class RouteService extends ABaseService<Route, RouteRepository> {
+
+ @Override
+ public RouteRepository getRepo() {
+ return routeRepository;
+ }
+
+ @Autowired
+ private RouteRepository routeRepository;
+
+
+ public void deleteBatch(List<String> ids) {
+
+ ids.stream().forEach(id -> {
+ this.deleteById(id);
+ });
+ }
+
+
+}