提交 881e0b39 作者: 方治民

fix: 阿里规约代码问题修复

上级 f264075a
...@@ -11,13 +11,15 @@ import io.hypersistence.utils.hibernate.type.json.JsonType; ...@@ -11,13 +11,15 @@ import io.hypersistence.utils.hibernate.type.json.JsonType;
import jakarta.persistence.*; import jakarta.persistence.*;
import java.io.Serial; import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import lombok.*; import lombok.*;
import lombok.experimental.FieldDefaults; import lombok.experimental.FieldDefaults;
import lombok.experimental.FieldNameConstants; import lombok.experimental.FieldNameConstants;
import lombok.experimental.SuperBuilder; import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where; import org.hibernate.annotations.SQLRestriction;
import org.hibernate.proxy.HibernateProxy;
/** /**
* 权限 * 权限
...@@ -35,7 +37,7 @@ import org.hibernate.annotations.Where; ...@@ -35,7 +37,7 @@ import org.hibernate.annotations.Where;
@FieldDefaults(level = AccessLevel.PRIVATE) @FieldDefaults(level = AccessLevel.PRIVATE)
@SQLDelete(sql = DELETE_SQL + BasicEntity.Where.WHERE_ID) @SQLDelete(sql = DELETE_SQL + BasicEntity.Where.WHERE_ID)
//@SQLDeleteAll(sql = DELETE_SQL) //@SQLDeleteAll(sql = DELETE_SQL)
@Where(clause = BasicEntity.Where.EXIST) @SQLRestriction(BasicEntity.Where.EXIST)
@Entity @Entity
@Table( @Table(
name = TABLE_NAME, name = TABLE_NAME,
...@@ -154,4 +156,32 @@ public class Permission extends BasicEntity implements Serializable { ...@@ -154,4 +156,32 @@ public class Permission extends BasicEntity implements Serializable {
} }
return meta; return meta;
} }
@Override
public final boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null) {
return false;
}
Class<?> oEffectiveClass = o instanceof HibernateProxy
? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass()
: o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy
? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass()
: this.getClass();
if (thisEffectiveClass != oEffectiveClass) {
return false;
}
Permission that = (Permission) o;
return getId() != null && Objects.equals(getId(), that.getId());
}
@Override
public final int hashCode() {
return this instanceof HibernateProxy
? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode()
: getClass().hashCode();
}
} }
...@@ -11,6 +11,7 @@ import jakarta.persistence.*; ...@@ -11,6 +11,7 @@ import jakarta.persistence.*;
import java.io.Serial; import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashSet; import java.util.HashSet;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import lombok.*; import lombok.*;
import lombok.experimental.FieldDefaults; import lombok.experimental.FieldDefaults;
...@@ -18,7 +19,8 @@ import lombok.experimental.FieldNameConstants; ...@@ -18,7 +19,8 @@ import lombok.experimental.FieldNameConstants;
import lombok.experimental.SuperBuilder; import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where; import org.hibernate.annotations.SQLRestriction;
import org.hibernate.proxy.HibernateProxy;
/** /**
* 角色 * 角色
...@@ -36,7 +38,7 @@ import org.hibernate.annotations.Where; ...@@ -36,7 +38,7 @@ import org.hibernate.annotations.Where;
@FieldDefaults(level = AccessLevel.PRIVATE) @FieldDefaults(level = AccessLevel.PRIVATE)
@SQLDelete(sql = Permission.DELETE_SQL + BasicEntity.Where.WHERE_ID) @SQLDelete(sql = Permission.DELETE_SQL + BasicEntity.Where.WHERE_ID)
//@SQLDeleteAll(sql = Permission.DELETE_SQL) //@SQLDeleteAll(sql = Permission.DELETE_SQL)
@Where(clause = BasicEntity.Where.EXIST) @SQLRestriction(BasicEntity.Where.EXIST)
@Entity @Entity
@Table( @Table(
name = TABLE_NAME, name = TABLE_NAME,
...@@ -83,4 +85,32 @@ public class Role extends BasicEntity implements Serializable { ...@@ -83,4 +85,32 @@ public class Role extends BasicEntity implements Serializable {
inverseJoinColumns = { @JoinColumn(name = "user_id") } inverseJoinColumns = { @JoinColumn(name = "user_id") }
) )
Set<User> users = new HashSet<>(); Set<User> users = new HashSet<>();
@Override
public final boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null) {
return false;
}
Class<?> oEffectiveClass = o instanceof HibernateProxy
? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass()
: o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy
? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass()
: this.getClass();
if (thisEffectiveClass != oEffectiveClass) {
return false;
}
Role role = (Role) o;
return getId() != null && Objects.equals(getId(), role.getId());
}
@Override
public final int hashCode() {
return this instanceof HibernateProxy
? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode()
: getClass().hashCode();
}
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
package com.yiring.auth.domain.user; package com.yiring.auth.domain.user;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.yiring.auth.domain.permission.Permission;
import com.yiring.auth.domain.role.Role; import com.yiring.auth.domain.role.Role;
import com.yiring.common.domain.BasicEntity; import com.yiring.common.domain.BasicEntity;
import jakarta.persistence.*; import jakarta.persistence.*;
...@@ -10,6 +9,7 @@ import java.io.Serial; ...@@ -10,6 +9,7 @@ import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashSet; import java.util.HashSet;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import lombok.*; import lombok.*;
import lombok.experimental.FieldDefaults; import lombok.experimental.FieldDefaults;
...@@ -17,6 +17,8 @@ import lombok.experimental.FieldNameConstants; ...@@ -17,6 +17,8 @@ import lombok.experimental.FieldNameConstants;
import lombok.experimental.SuperBuilder; import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.Comment; import org.hibernate.annotations.Comment;
import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.proxy.HibernateProxy;
/** /**
* 用户 * 用户
...@@ -32,8 +34,9 @@ import org.hibernate.annotations.SQLDelete; ...@@ -32,8 +34,9 @@ import org.hibernate.annotations.SQLDelete;
@AllArgsConstructor @AllArgsConstructor
@FieldNameConstants @FieldNameConstants
@FieldDefaults(level = AccessLevel.PRIVATE) @FieldDefaults(level = AccessLevel.PRIVATE)
@SQLDelete(sql = Permission.DELETE_SQL + BasicEntity.Where.WHERE_ID) @SQLDelete(sql = User.DELETE_SQL + BasicEntity.Where.WHERE_ID)
//@SQLDeleteAll(sql = Permission.DELETE_SQL) //@SQLDeleteAll(sql = Permission.DELETE_SQL)
@SQLRestriction(BasicEntity.Where.EXIST)
@Entity @Entity
@Table( @Table(
name = User.TABLE_NAME, name = User.TABLE_NAME,
...@@ -90,4 +93,32 @@ public class User extends BasicEntity implements Serializable { ...@@ -90,4 +93,32 @@ public class User extends BasicEntity implements Serializable {
@Comment("最后登录时间") @Comment("最后登录时间")
LocalDateTime lastLoginTime; LocalDateTime lastLoginTime;
@Override
public final boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null) {
return false;
}
Class<?> oEffectiveClass = o instanceof HibernateProxy
? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass()
: o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy
? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass()
: this.getClass();
if (thisEffectiveClass != oEffectiveClass) {
return false;
}
User user = (User) o;
return getId() != null && Objects.equals(getId(), user.getId());
}
@Override
public final int hashCode() {
return this instanceof HibernateProxy
? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode()
: getClass().hashCode();
}
} }
...@@ -26,6 +26,7 @@ import org.springframework.context.annotation.Profile; ...@@ -26,6 +26,7 @@ import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.method.HandlerMethod;
/** /**
* Swagger Config * Swagger Config
...@@ -53,7 +54,7 @@ public class SwaggerConfig implements CommandLineRunner { ...@@ -53,7 +54,7 @@ public class SwaggerConfig implements CommandLineRunner {
final I18n i18n; final I18n i18n;
@Bean @Bean
public OpenAPI openAPI() { public OpenAPI api() {
Info info = new Info() Info info = new Info()
.title("API Doc") .title("API Doc")
.description(applicationName) .description(applicationName)
...@@ -132,17 +133,7 @@ public class SwaggerConfig implements CommandLineRunner { ...@@ -132,17 +133,7 @@ public class SwaggerConfig implements CommandLineRunner {
return (operation, handlerMethod) -> { return (operation, handlerMethod) -> {
Class<?> superClazz = handlerMethod.getBeanType().getSuperclass(); Class<?> superClazz = handlerMethod.getBeanType().getSuperclass();
if (Objects.nonNull(superClazz)) { if (Objects.nonNull(superClazz)) {
Annotation[] annotations = handlerMethod.getMethod().getAnnotations(); String methodType = getType(handlerMethod);
String methodType = "GET";
for (Annotation annotation : annotations) {
if (annotation instanceof PostMapping) {
methodType = "POST";
} else if (annotation instanceof PutMapping) {
methodType = "PUT";
} else if (annotation instanceof DeleteMapping) {
methodType = "DELETE";
}
}
String beanName = handlerMethod.getBeanType().getSimpleName(); String beanName = handlerMethod.getBeanType().getSimpleName();
String methodName = handlerMethod.getMethod().getName(); String methodName = handlerMethod.getMethod().getName();
...@@ -152,6 +143,21 @@ public class SwaggerConfig implements CommandLineRunner { ...@@ -152,6 +143,21 @@ public class SwaggerConfig implements CommandLineRunner {
}; };
} }
private static String getType(HandlerMethod handlerMethod) {
Annotation[] annotations = handlerMethod.getMethod().getAnnotations();
String methodType = "GET";
for (Annotation annotation : annotations) {
if (annotation instanceof PostMapping) {
methodType = "POST";
} else if (annotation instanceof PutMapping) {
methodType = "PUT";
} else if (annotation instanceof DeleteMapping) {
methodType = "DELETE";
}
}
return methodType;
}
private GroupedOpenApi api( private GroupedOpenApi api(
String group, String group,
List<String> basePackages, List<String> basePackages,
...@@ -171,10 +177,11 @@ public class SwaggerConfig implements CommandLineRunner { ...@@ -171,10 +177,11 @@ public class SwaggerConfig implements CommandLineRunner {
@Override @Override
public void run(String... args) { public void run(String... args) {
String protocol = "http";
String link = NetUtil String link = NetUtil
.localIpv4s() .localIpv4s()
.stream() .stream()
.map(host -> "> http://" + host + ":" + port + path + "/doc.html") .map(host -> "> " + protocol + "://" + host + ":" + port + path + "/doc.html")
.collect(Collectors.joining("\n\t\t")); .collect(Collectors.joining("\n\t\t"));
Console.log("\n\t📖 API Doc (OpenAPI 3): \n\t\t{}\n", link); Console.log("\n\t📖 API Doc (OpenAPI 3): \n\t\t{}\n", link);
} }
......
...@@ -37,7 +37,9 @@ public class SmReloadableResourceBundleMessageSource extends ReloadableResourceB ...@@ -37,7 +37,9 @@ public class SmReloadableResourceBundleMessageSource extends ReloadableResourceB
String sourcePath = resource.getURI().toString().replace(PROPERTIES_SUFFIX, ""); String sourcePath = resource.getURI().toString().replace(PROPERTIES_SUFFIX, "");
PropertiesHolder holder = super.refreshProperties(sourcePath, propHolder); PropertiesHolder holder = super.refreshProperties(sourcePath, propHolder);
properties.putAll(holder.getProperties()); properties.putAll(holder.getProperties());
if (lastModified < resource.lastModified()) lastModified = resource.lastModified(); if (lastModified < resource.lastModified()) {
lastModified = resource.lastModified();
}
} }
} catch (IOException ignored) {} } catch (IOException ignored) {}
return new PropertiesHolder(properties, lastModified); return new PropertiesHolder(properties, lastModified);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论