可正常运行,尝试修改convert到service
This commit is contained in:
parent
a157e66e38
commit
06dc11c39b
@ -21,7 +21,7 @@ public class TenantFilter implements Filter {
|
||||
HttpServletRequest req = (HttpServletRequest) request;
|
||||
try {
|
||||
// 从请求头中获取租户ID
|
||||
String tenantId = req.getHeader("X-Tenant-ID");
|
||||
String tenantId = req.getHeader("X-Devops-Tenant-Id");
|
||||
if (tenantId != null) {
|
||||
TenantContext.setTenantId(tenantId);
|
||||
}
|
||||
|
||||
@ -53,12 +53,4 @@ public class Department extends Entity<Long> {
|
||||
@Column(name = "leader_name")
|
||||
private String leaderName;
|
||||
|
||||
@Transient // 不映射到数据库
|
||||
private List<Department> children = new ArrayList<>();
|
||||
|
||||
// 修改关联关系,通过UserDepartment关联
|
||||
@OneToMany(mappedBy = "department")
|
||||
@JsonIgnore
|
||||
@ToString.Exclude
|
||||
private Set<UserDepartment> userDepartments = new HashSet<>();
|
||||
}
|
||||
@ -53,10 +53,4 @@ public class Menu extends Entity<Long> {
|
||||
@Column(nullable = false)
|
||||
private Boolean enabled = true;
|
||||
|
||||
// 通过RoleMenu关联到Role
|
||||
@OneToMany(mappedBy = "menu")
|
||||
@JsonIgnore
|
||||
@ToString.Exclude
|
||||
private Set<RoleMenu> roleMenus = new HashSet<>();
|
||||
|
||||
}
|
||||
@ -38,13 +38,4 @@ public class Role extends Entity<Long> {
|
||||
@Column(nullable = false)
|
||||
private Integer sort = 0;
|
||||
|
||||
@OneToMany(mappedBy = "role", cascade = CascadeType.ALL)
|
||||
@JsonIgnore
|
||||
@ToString.Exclude
|
||||
private Set<UserRole> userRoles = new HashSet<>();
|
||||
|
||||
@OneToMany(mappedBy = "role", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JsonIgnore
|
||||
@ToString.Exclude
|
||||
private Set<RoleMenu> roleMenus = new HashSet<>();
|
||||
}
|
||||
@ -23,23 +23,17 @@ import java.util.Set;
|
||||
@LogicDelete
|
||||
public class RoleMenu extends Entity<Long> {
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "role_id")
|
||||
@JsonIgnore
|
||||
@ToString.Exclude
|
||||
private Role role;
|
||||
@Column(name = "role_id")
|
||||
private Long roleId;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "menu_id")
|
||||
@JsonIgnore
|
||||
@ToString.Exclude
|
||||
private Menu menu;
|
||||
@Column(name = "menu_id")
|
||||
private Long menuId;
|
||||
|
||||
protected RoleMenu() {
|
||||
}
|
||||
|
||||
public RoleMenu(Role role, Menu menu) {
|
||||
this.role = role;
|
||||
this.menu = menu;
|
||||
public RoleMenu(Long roleId, Long menuId) {
|
||||
this.roleId = roleId;
|
||||
this.menuId = menuId;
|
||||
}
|
||||
}
|
||||
@ -43,106 +43,4 @@ public class User extends Entity<Long> {
|
||||
@Column(nullable = false)
|
||||
private Boolean enabled = true;
|
||||
|
||||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JsonIgnore
|
||||
@ToString.Exclude
|
||||
private Set<UserRole> userRoles = new HashSet<>();
|
||||
|
||||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JsonIgnore
|
||||
@ToString.Exclude
|
||||
private Set<UserDepartment> userDepartments = new HashSet<>();
|
||||
|
||||
// public void addRole(Role role) {
|
||||
// UserRole userRole = new UserRole(this, role);
|
||||
// userRoles.add(userRole);
|
||||
// registerDomainEvent(new UserRoleChangedEvent(this.getId(), role.getId(), "ADD"));
|
||||
// validateState();
|
||||
// }
|
||||
//
|
||||
// public void removeRole(Role role) {
|
||||
// boolean removed = userRoles.removeIf(ur -> ur.getRole().equals(role));
|
||||
// if (removed) {
|
||||
// registerDomainEvent(new UserRoleChangedEvent(this.getId(), role.getId(), "REMOVE"));
|
||||
// validateState();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void changePassword(String oldPassword, String newPassword) {
|
||||
// if (!this.password.equals(oldPassword)) {
|
||||
// throw new IllegalArgumentException("Old password is incorrect");
|
||||
// }
|
||||
// this.password = newPassword;
|
||||
// registerDomainEvent(new PasswordChangedEvent(this.getId()));
|
||||
// validateState();
|
||||
// }
|
||||
//
|
||||
// public void setEnabled(boolean enabled) {
|
||||
// if (this.enabled != enabled) {
|
||||
// this.enabled = enabled;
|
||||
// registerDomainEvent(new UserStatusChangedEvent(this.getId(), enabled));
|
||||
// validateState();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void updateBasicInfo(String nickname, String phone, String email) {
|
||||
// boolean changed = false;
|
||||
//
|
||||
// if (!Objects.equals(this.nickname, nickname)) {
|
||||
// this.nickname = nickname;
|
||||
// changed = true;
|
||||
// }
|
||||
//
|
||||
// if (!Objects.equals(this.phone, phone)) {
|
||||
// this.phone = phone;
|
||||
// changed = true;
|
||||
// }
|
||||
//
|
||||
// if (!Objects.equals(this.email, email)) {
|
||||
// this.email = email;
|
||||
// changed = true;
|
||||
// }
|
||||
//
|
||||
// if (changed) {
|
||||
// registerDomainEvent(new UserUpdatedEvent(this.getId()));
|
||||
// validateState();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public boolean hasRole(String roleCode) {
|
||||
// return userRoles.stream()
|
||||
// .map(UserRole::getRole)
|
||||
// .anyMatch(role -> role.getCode().equals(roleCode));
|
||||
// }
|
||||
//
|
||||
// public Set<String> getRoleCodes() {
|
||||
// return userRoles.stream()
|
||||
// .map(UserRole::getRole)
|
||||
// .map(Role::getCode)
|
||||
// .collect(Collectors.toSet());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void validateState() {
|
||||
// if (username == null || username.trim().isEmpty()) {
|
||||
// throw new IllegalStateException("Username cannot be empty");
|
||||
// }
|
||||
// if (email == null || !email.matches("^[A-Za-z0-9+_.-]+@(.+)$")) {
|
||||
// throw new IllegalStateException("Invalid email format");
|
||||
// }
|
||||
// if (password == null || password.length() < 6) {
|
||||
// throw new IllegalStateException("Password must be at least 6 characters");
|
||||
// }
|
||||
// if (phone != null && !phone.matches("^\\d{11}$")) {
|
||||
// throw new IllegalStateException("Invalid phone number format");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void validateBeforeDelete() {
|
||||
// if (!userRoles.isEmpty()) {
|
||||
// throw new IllegalStateException("Cannot delete user with assigned roles");
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
@ -24,25 +24,18 @@ import java.util.Set;
|
||||
@LogicDelete
|
||||
public class UserDepartment extends Entity<Long> {
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id", unique = true)
|
||||
@JsonIgnore
|
||||
@ToString.Exclude
|
||||
private User user;
|
||||
@Column(name = "user_id")
|
||||
private Long userId;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "department_id")
|
||||
@JsonIgnore
|
||||
@ToString.Exclude
|
||||
private Department department;
|
||||
@Column(name = "dept_id")
|
||||
private Long deptId;
|
||||
|
||||
protected UserDepartment() {
|
||||
// JPA需要无参构造函数
|
||||
}
|
||||
|
||||
public UserDepartment(User user, Department department) {
|
||||
this.user = user;
|
||||
this.department = department;
|
||||
public UserDepartment(Long userId, Long deptId) {
|
||||
this.userId = userId;
|
||||
this.deptId = deptId;
|
||||
}
|
||||
|
||||
}
|
||||
@ -21,41 +21,19 @@ import lombok.ToString;
|
||||
@LogicDelete
|
||||
public class UserRole extends Entity<Long> {
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id")
|
||||
@JsonIgnore
|
||||
@ToString.Exclude
|
||||
private User user;
|
||||
@Column(name = "user_id")
|
||||
private Long userId;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "role_id")
|
||||
@JsonIgnore
|
||||
@ToString.Exclude
|
||||
private Role role;
|
||||
@Column(name = "role_id")
|
||||
private Long roleId;
|
||||
|
||||
// 添加构造方法
|
||||
protected UserRole() {
|
||||
// JPA需要无参构造方法
|
||||
}
|
||||
|
||||
public UserRole(User user, Role role) {
|
||||
this.user = user;
|
||||
this.role = role;
|
||||
public UserRole(Long userId, Long roleId) {
|
||||
this.userId = userId;
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
// 重写equals和hashCode方法,避免无限递归
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof UserRole)) return false;
|
||||
UserRole userRole = (UserRole) o;
|
||||
return getId() != null && getId().equals(userRole.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getClass().hashCode();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -11,8 +11,8 @@ import java.util.List;
|
||||
@Repository
|
||||
public interface IRoleMenuRepository extends IBaseRepository<RoleMenu, Long> {
|
||||
|
||||
@Query("SELECT rm.role FROM RoleMenu rm where rm.role.id = :roleId")
|
||||
List<RoleMenu> findByRoleId(Long roleId);
|
||||
@Query("SELECT rm.roleId FROM RoleMenu rm where rm.roleId = :roleId")
|
||||
List<Long> findByRoleId(Long roleId);
|
||||
//
|
||||
// void deleteByRoleId(Long roleId);
|
||||
//
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.qqchen.deploy.backend.repository;
|
||||
|
||||
|
||||
import com.qqchen.deploy.backend.common.repository.IBaseRepository;
|
||||
import com.qqchen.deploy.backend.entity.User;
|
||||
import org.springframework.stereotype.Repository;
|
||||
@ -13,14 +12,6 @@ public interface IUserRepository extends IBaseRepository<User, Long> {
|
||||
|
||||
Optional<User> findByUsernameAndDeletedFalse(String username);
|
||||
|
||||
boolean existsByUsernameAndDeletedFalse(String username);
|
||||
|
||||
boolean existsByEmailAndDeletedFalse(String email);
|
||||
|
||||
boolean existsByPhoneAndDeletedFalse(String phone);
|
||||
|
||||
List<User> findByDeletedFalseOrderById();
|
||||
|
||||
boolean existsByUsername(String username);
|
||||
|
||||
boolean existsByEmail(String email);
|
||||
|
||||
@ -13,15 +13,15 @@ import java.util.Set;
|
||||
@Repository
|
||||
public interface IUserRoleRepository extends IBaseRepository<UserRole, Long> {
|
||||
|
||||
@Query("SELECT ur FROM UserRole ur WHERE ur.user.id = :userId")
|
||||
@Query("SELECT ur FROM UserRole ur WHERE ur.userId = :userId")
|
||||
Set<UserRole> findByUserId(@Param("userId") Long userId);
|
||||
|
||||
@Modifying
|
||||
@Query("DELETE FROM UserRole ur WHERE ur.user.id = :userId AND ur.role.id = :roleId")
|
||||
@Query("DELETE FROM UserRole ur WHERE ur.userId = :userId AND ur.roleId = :roleId")
|
||||
void deleteByUserIdAndRoleId(@Param("userId") Long userId, @Param("roleId") Long roleId);
|
||||
|
||||
|
||||
@Query("SELECT COUNT(ur) > 0 FROM UserRole ur WHERE ur.user.id = :userId AND ur.role.id = :roleId")
|
||||
@Query("SELECT COUNT(ur) > 0 FROM UserRole ur WHERE ur.userId = :userId AND ur.roleId = :roleId")
|
||||
boolean existsByUserIdAndRoleId(@Param("userId") Long userId, @Param("roleId") Long roleId);
|
||||
|
||||
}
|
||||
@ -95,8 +95,8 @@ public class DepartmentServiceImpl extends BaseServiceImpl<Department, Long> imp
|
||||
List<Department> children = parentIdMap.get(parentId);
|
||||
if (children != null) {
|
||||
for (Department child : children) {
|
||||
child.setChildren(buildTreeNodes(child.getId(), parentIdMap));
|
||||
nodes.add(child);
|
||||
// child.setChildren(buildTreeNodes(child.getId(), parentIdMap));
|
||||
// nodes.add(child);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -39,6 +39,7 @@ logging:
|
||||
org.hibernate.type.descriptor.sql.BasicBinder: TRACE
|
||||
org.hibernate.type.descriptor.sql: TRACE
|
||||
com.qqchen.deploy.backend.common.utils.EntityPathResolver: DEBUG
|
||||
com.qqchen.deploy.backend: DEBUG
|
||||
jwt:
|
||||
secret: 'thisIsAVeryVerySecretKeyForJwtTokenGenerationAndValidation123456789'
|
||||
expiration: 86400
|
||||
|
||||
Loading…
Reference in New Issue
Block a user