diff --git a/backend/src/main/java/com/qqchen/deploy/backend/common/filter/TenantFilter.java b/backend/src/main/java/com/qqchen/deploy/backend/common/filter/TenantFilter.java index 6bc77fe6..787aa8de 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/common/filter/TenantFilter.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/common/filter/TenantFilter.java @@ -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); } diff --git a/backend/src/main/java/com/qqchen/deploy/backend/entity/Department.java b/backend/src/main/java/com/qqchen/deploy/backend/entity/Department.java index 89a62859..a9b14f13 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/entity/Department.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/entity/Department.java @@ -53,12 +53,4 @@ public class Department extends Entity { @Column(name = "leader_name") private String leaderName; - @Transient // 不映射到数据库 - private List children = new ArrayList<>(); - - // 修改关联关系,通过UserDepartment关联 - @OneToMany(mappedBy = "department") - @JsonIgnore - @ToString.Exclude - private Set userDepartments = new HashSet<>(); -} \ No newline at end of file +} \ No newline at end of file diff --git a/backend/src/main/java/com/qqchen/deploy/backend/entity/Menu.java b/backend/src/main/java/com/qqchen/deploy/backend/entity/Menu.java index 31b92654..70cfbe6e 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/entity/Menu.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/entity/Menu.java @@ -53,10 +53,4 @@ public class Menu extends Entity { @Column(nullable = false) private Boolean enabled = true; - // 通过RoleMenu关联到Role - @OneToMany(mappedBy = "menu") - @JsonIgnore - @ToString.Exclude - private Set roleMenus = new HashSet<>(); - } \ No newline at end of file diff --git a/backend/src/main/java/com/qqchen/deploy/backend/entity/Role.java b/backend/src/main/java/com/qqchen/deploy/backend/entity/Role.java index 9ce32ffa..b52395a1 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/entity/Role.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/entity/Role.java @@ -37,14 +37,5 @@ public class Role extends Entity { @Column(nullable = false) private Integer sort = 0; - - @OneToMany(mappedBy = "role", cascade = CascadeType.ALL) - @JsonIgnore - @ToString.Exclude - private Set userRoles = new HashSet<>(); - - @OneToMany(mappedBy = "role", cascade = CascadeType.ALL, orphanRemoval = true) - @JsonIgnore - @ToString.Exclude - private Set roleMenus = new HashSet<>(); -} \ No newline at end of file + +} \ No newline at end of file diff --git a/backend/src/main/java/com/qqchen/deploy/backend/entity/RoleMenu.java b/backend/src/main/java/com/qqchen/deploy/backend/entity/RoleMenu.java index 1ccd9830..7f0ffd92 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/entity/RoleMenu.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/entity/RoleMenu.java @@ -23,23 +23,17 @@ import java.util.Set; @LogicDelete public class RoleMenu extends Entity { - @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; } -} \ No newline at end of file +} \ No newline at end of file diff --git a/backend/src/main/java/com/qqchen/deploy/backend/entity/User.java b/backend/src/main/java/com/qqchen/deploy/backend/entity/User.java index 4ea482a5..a1885608 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/entity/User.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/entity/User.java @@ -43,106 +43,4 @@ public class User extends Entity { @Column(nullable = false) private Boolean enabled = true; - @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) - @JsonIgnore - @ToString.Exclude - private Set userRoles = new HashSet<>(); - - @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) - @JsonIgnore - @ToString.Exclude - private Set 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 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"); -// } -// } - -} \ No newline at end of file +} \ No newline at end of file diff --git a/backend/src/main/java/com/qqchen/deploy/backend/entity/UserDepartment.java b/backend/src/main/java/com/qqchen/deploy/backend/entity/UserDepartment.java index 9936e541..0ddad3a6 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/entity/UserDepartment.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/entity/UserDepartment.java @@ -24,25 +24,18 @@ import java.util.Set; @LogicDelete public class UserDepartment extends Entity { - @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; } - -} \ No newline at end of file +} \ No newline at end of file diff --git a/backend/src/main/java/com/qqchen/deploy/backend/entity/UserRole.java b/backend/src/main/java/com/qqchen/deploy/backend/entity/UserRole.java index 96550464..d03b17a5 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/entity/UserRole.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/entity/UserRole.java @@ -21,41 +21,19 @@ import lombok.ToString; @LogicDelete public class UserRole extends Entity { - @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(); - } - - } \ No newline at end of file diff --git a/backend/src/main/java/com/qqchen/deploy/backend/repository/IRoleMenuRepository.java b/backend/src/main/java/com/qqchen/deploy/backend/repository/IRoleMenuRepository.java index 1cf012c2..363a20d8 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/repository/IRoleMenuRepository.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/repository/IRoleMenuRepository.java @@ -11,8 +11,8 @@ import java.util.List; @Repository public interface IRoleMenuRepository extends IBaseRepository { - @Query("SELECT rm.role FROM RoleMenu rm where rm.role.id = :roleId") - List findByRoleId(Long roleId); + @Query("SELECT rm.roleId FROM RoleMenu rm where rm.roleId = :roleId") + List findByRoleId(Long roleId); // // void deleteByRoleId(Long roleId); // diff --git a/backend/src/main/java/com/qqchen/deploy/backend/repository/IUserRepository.java b/backend/src/main/java/com/qqchen/deploy/backend/repository/IUserRepository.java index 86729bba..b7e1fa60 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/repository/IUserRepository.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/repository/IUserRepository.java @@ -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; @@ -12,14 +11,6 @@ import java.util.Optional; public interface IUserRepository extends IBaseRepository { Optional findByUsernameAndDeletedFalse(String username); - - boolean existsByUsernameAndDeletedFalse(String username); - - boolean existsByEmailAndDeletedFalse(String email); - - boolean existsByPhoneAndDeletedFalse(String phone); - - List findByDeletedFalseOrderById(); boolean existsByUsername(String username); diff --git a/backend/src/main/java/com/qqchen/deploy/backend/repository/IUserRoleRepository.java b/backend/src/main/java/com/qqchen/deploy/backend/repository/IUserRoleRepository.java index b657d3f8..6de868f2 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/repository/IUserRoleRepository.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/repository/IUserRoleRepository.java @@ -13,15 +13,15 @@ import java.util.Set; @Repository public interface IUserRoleRepository extends IBaseRepository { - @Query("SELECT ur FROM UserRole ur WHERE ur.user.id = :userId") + @Query("SELECT ur FROM UserRole ur WHERE ur.userId = :userId") Set 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); } \ No newline at end of file diff --git a/backend/src/main/java/com/qqchen/deploy/backend/service/impl/DepartmentServiceImpl.java b/backend/src/main/java/com/qqchen/deploy/backend/service/impl/DepartmentServiceImpl.java index 14ad6b5e..3c2f7b93 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/service/impl/DepartmentServiceImpl.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/service/impl/DepartmentServiceImpl.java @@ -95,8 +95,8 @@ public class DepartmentServiceImpl extends BaseServiceImpl imp List 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); } } diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 3818fc7f..4dde7958 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -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