mirror of
				https://github.com/vran-dev/databasir.git
				synced 2025-10-31 04:29:20 +08:00 
			
		
		
		
	refactor: rename pojo class name (#225)
* refactor: rename pojo class name * fix: compile error
This commit is contained in:
		| @@ -39,7 +39,7 @@ public class DocumentDescriptionController { | ||||
|         DatabasirUserDetails principal = (DatabasirUserDetails) SecurityContextHolder.getContext() | ||||
|                 .getAuthentication() | ||||
|                 .getPrincipal(); | ||||
|         Integer userId = principal.getUserPojo().getId(); | ||||
|         Integer userId = principal.getUser().getId(); | ||||
|         documentDescriptionService.save(groupId, projectId, userId, request); | ||||
|         return JsonData.ok(); | ||||
|     } | ||||
|   | ||||
| @@ -68,7 +68,7 @@ public class DocumentDiscussionController { | ||||
|         DatabasirUserDetails principal = (DatabasirUserDetails) SecurityContextHolder.getContext() | ||||
|                 .getAuthentication() | ||||
|                 .getPrincipal(); | ||||
|         Integer userId = principal.getUserPojo().getId(); | ||||
|         Integer userId = principal.getUser().getId(); | ||||
|         documentDiscussionService.create(groupId, projectId, userId, request); | ||||
|         return JsonData.ok(); | ||||
|     } | ||||
|   | ||||
| @@ -64,7 +64,7 @@ public class LoginController { | ||||
|         DatabasirUserDetails user = (DatabasirUserDetails) SecurityContextHolder.getContext() | ||||
|                 .getAuthentication() | ||||
|                 .getPrincipal(); | ||||
|         Integer userId = user.getUserPojo().getId(); | ||||
|         Integer userId = user.getUser().getId(); | ||||
|         return JsonData.ok(loginService.getUserLoginData(userId)); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -87,7 +87,7 @@ public class ProjectController { | ||||
|         DatabasirUserDetails user = (DatabasirUserDetails) SecurityContextHolder.getContext() | ||||
|                 .getAuthentication() | ||||
|                 .getPrincipal(); | ||||
|         Integer userId = user.getUserPojo().getId(); | ||||
|         Integer userId = user.getUser().getId(); | ||||
|         return JsonData.ok(projectService.list(userId, page, condition)); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -34,7 +34,7 @@ public class UserProjectController { | ||||
|         DatabasirUserDetails user = (DatabasirUserDetails) SecurityContextHolder.getContext() | ||||
|                 .getAuthentication() | ||||
|                 .getPrincipal(); | ||||
|         Integer userId = user.getUserPojo().getId(); | ||||
|         Integer userId = user.getUser().getId(); | ||||
|         return JsonData.ok(userProjectService.listFavorites(pageable, userId, condition)); | ||||
|     } | ||||
|  | ||||
| @@ -47,7 +47,7 @@ public class UserProjectController { | ||||
|         DatabasirUserDetails user = (DatabasirUserDetails) SecurityContextHolder.getContext() | ||||
|                 .getAuthentication() | ||||
|                 .getPrincipal(); | ||||
|         Integer userId = user.getUserPojo().getId(); | ||||
|         Integer userId = user.getUser().getId(); | ||||
|         userProjectService.addFavorites(projectId, userId); | ||||
|         return JsonData.ok(); | ||||
|     } | ||||
| @@ -61,7 +61,7 @@ public class UserProjectController { | ||||
|         DatabasirUserDetails user = (DatabasirUserDetails) SecurityContextHolder.getContext() | ||||
|                 .getAuthentication() | ||||
|                 .getPrincipal(); | ||||
|         Integer userId = user.getUserPojo().getId(); | ||||
|         Integer userId = user.getUser().getId(); | ||||
|         userProjectService.removeFavorites(projectId, userId); | ||||
|         return JsonData.ok(); | ||||
|     } | ||||
|   | ||||
| @@ -6,7 +6,7 @@ import com.databasir.core.domain.log.annotation.AuditLog; | ||||
| import com.databasir.core.domain.log.data.OperationLogRequest; | ||||
| import com.databasir.core.domain.log.service.OperationLogService; | ||||
| import com.databasir.dao.impl.ProjectDao; | ||||
| import com.databasir.dao.tables.pojos.ProjectPojo; | ||||
| import com.databasir.dao.tables.pojos.Project; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.aspectj.lang.JoinPoint; | ||||
| @@ -75,12 +75,12 @@ public class OperationLogAspect { | ||||
|                 && operation.retrieveInvolvedGroupId() | ||||
|                 && involvedProjectId != null) { | ||||
|             involvedGroupId = projectDao.selectOptionalById(involvedProjectId) | ||||
|                     .map(ProjectPojo::getGroupId) | ||||
|                     .map(Project::getGroupId) | ||||
|                     .orElse(null); | ||||
|         } | ||||
|         int userId = userId(); | ||||
|         String username = principal.getUserPojo().getUsername(); | ||||
|         String nickname = principal.getUserPojo().getNickname(); | ||||
|         String username = principal.getUser().getUsername(); | ||||
|         String nickname = principal.getUser().getNickname(); | ||||
|         if (userId == AuditLog.Types.SYSTEM_USER_ID) { | ||||
|             username = "system"; | ||||
|             nickname = "system"; | ||||
| @@ -105,7 +105,7 @@ public class OperationLogAspect { | ||||
|         DatabasirUserDetails principal = (DatabasirUserDetails) SecurityContextHolder.getContext() | ||||
|                 .getAuthentication() | ||||
|                 .getPrincipal(); | ||||
|         return principal.getUserPojo().getId(); | ||||
|         return principal.getUser().getId(); | ||||
|     } | ||||
|  | ||||
|     private <T> Optional<T> getValueBySPEL(Method method, | ||||
|   | ||||
| @@ -9,6 +9,6 @@ public class LoginUserContext { | ||||
|         DatabasirUserDetails principal = (DatabasirUserDetails) SecurityContextHolder.getContext() | ||||
|                 .getAuthentication() | ||||
|                 .getPrincipal(); | ||||
|         return principal.getUserPojo().getId(); | ||||
|         return principal.getUser().getId(); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -36,16 +36,16 @@ public class OAuth2AuthenticationSuccessHandler implements AuthenticationSuccess | ||||
|                                         HttpServletResponse response, | ||||
|                                         Authentication authentication) throws IOException, ServletException { | ||||
|         DatabasirUserDetails details = (DatabasirUserDetails) authentication.getPrincipal(); | ||||
|         loginService.generate(details.getUserPojo().getId()); | ||||
|         UserLoginResponse data = loginService.getUserLoginData(details.getUserPojo().getId()) | ||||
|         loginService.generate(details.getUser().getId()); | ||||
|         UserLoginResponse data = loginService.getUserLoginData(details.getUser().getId()) | ||||
|                 .orElseThrow(() -> { | ||||
|                     operationLogService.saveLoginLog(details.getUserPojo(), false, null); | ||||
|                     operationLogService.saveLoginLog(details.getUser(), false, null); | ||||
|                     return new CredentialsExpiredException("请重新登陆"); | ||||
|                 }); | ||||
|         response.setCharacterEncoding(StandardCharsets.UTF_8.name()); | ||||
|         response.setContentType(MediaType.APPLICATION_JSON_VALUE); | ||||
|         objectMapper.writeValue(response.getWriter(), JsonData.ok(data)); | ||||
|         operationLogService.saveLoginLog(details.getUserPojo(), true, null); | ||||
|         operationLogService.saveLoginLog(details.getUser(), true, null); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -38,13 +38,13 @@ public class DatabasirAuthenticationSuccessHandler implements AuthenticationSucc | ||||
|         response.setCharacterEncoding(StandardCharsets.UTF_8.name()); | ||||
|         response.setContentType(MediaType.APPLICATION_JSON_VALUE); | ||||
|  | ||||
|         loginService.generate(user.getUserPojo().getId()); | ||||
|         UserLoginResponse data = loginService.getUserLoginData(user.getUserPojo().getId()) | ||||
|         loginService.generate(user.getUser().getId()); | ||||
|         UserLoginResponse data = loginService.getUserLoginData(user.getUser().getId()) | ||||
|                 .orElseThrow(() -> { | ||||
|                     operationLogService.saveLoginLog(user.getUserPojo(), false, null); | ||||
|                     operationLogService.saveLoginLog(user.getUser(), false, null); | ||||
|                     return new CredentialsExpiredException("请重新登陆"); | ||||
|                 }); | ||||
|         operationLogService.saveLoginLog(user.getUserPojo(), true, null); | ||||
|         operationLogService.saveLoginLog(user.getUser(), true, null); | ||||
|         objectMapper.writeValue(response.getWriter(), JsonData.ok(data)); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -3,8 +3,8 @@ package com.databasir.api.config.security; | ||||
| import com.databasir.core.domain.log.service.OperationLogService; | ||||
| import com.databasir.dao.impl.UserDao; | ||||
| import com.databasir.dao.impl.UserRoleDao; | ||||
| import com.databasir.dao.tables.pojos.UserPojo; | ||||
| import com.databasir.dao.tables.pojos.UserRolePojo; | ||||
| import com.databasir.dao.tables.pojos.User; | ||||
| import com.databasir.dao.tables.pojos.UserRole; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.security.core.userdetails.UserDetails; | ||||
| @@ -28,12 +28,12 @@ public class DatabasirUserDetailService implements UserDetailsService { | ||||
|  | ||||
|     @Override | ||||
|     public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { | ||||
|         UserPojo user = userDao.selectByEmailOrUsername(username) | ||||
|         User user = userDao.selectByEmailOrUsername(username) | ||||
|                 .orElseThrow(() -> { | ||||
|                     operationLogService.saveLoginFailedLog(username, "用户名不存在"); | ||||
|                     return new UsernameNotFoundException("用户名或密码错误"); | ||||
|                 }); | ||||
|         List<UserRolePojo> roles = userRoleDao.selectByUserIds(Collections.singletonList(user.getId())); | ||||
|         List<UserRole> roles = userRoleDao.selectByUserIds(Collections.singletonList(user.getId())); | ||||
|         return new DatabasirUserDetails(user, roles); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| package com.databasir.api.config.security; | ||||
|  | ||||
| import com.databasir.dao.tables.pojos.UserPojo; | ||||
| import com.databasir.dao.tables.pojos.UserRolePojo; | ||||
| import com.databasir.dao.tables.pojos.User; | ||||
| import com.databasir.dao.tables.pojos.UserRole; | ||||
| import lombok.Getter; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| import org.springframework.security.core.GrantedAuthority; | ||||
| @@ -16,10 +16,10 @@ import java.util.stream.Collectors; | ||||
| public class DatabasirUserDetails implements UserDetails { | ||||
|  | ||||
|     @Getter | ||||
|     private final UserPojo userPojo; | ||||
|     private final User user; | ||||
|  | ||||
|     @Getter | ||||
|     private final List<UserRolePojo> roles; | ||||
|     private final List<UserRole> roles; | ||||
|  | ||||
|     @Override | ||||
|     public Collection<? extends GrantedAuthority> getAuthorities() { | ||||
| @@ -36,12 +36,12 @@ public class DatabasirUserDetails implements UserDetails { | ||||
|  | ||||
|     @Override | ||||
|     public String getPassword() { | ||||
|         return userPojo.getPassword(); | ||||
|         return user.getPassword(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String getUsername() { | ||||
|         return userPojo.getEmail(); | ||||
|         return user.getEmail(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
| @@ -61,6 +61,6 @@ public class DatabasirUserDetails implements UserDetails { | ||||
|  | ||||
|     @Override | ||||
|     public boolean isEnabled() { | ||||
|         return userPojo.getEnabled(); | ||||
|         return user.getEnabled(); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -12,7 +12,7 @@ public class UserOperationValidator { | ||||
|         DatabasirUserDetails principal = (DatabasirUserDetails) SecurityContextHolder.getContext() | ||||
|                 .getAuthentication() | ||||
|                 .getPrincipal(); | ||||
|         if (principal.getUserPojo().getId().equals(userId)) { | ||||
|         if (principal.getUser().getId().equals(userId)) { | ||||
|             throw DomainErrors.CANNOT_UPDATE_SELF_ROLE.exception(); | ||||
|         } | ||||
|     } | ||||
| @@ -21,7 +21,7 @@ public class UserOperationValidator { | ||||
|         DatabasirUserDetails principal = (DatabasirUserDetails) SecurityContextHolder.getContext() | ||||
|                 .getAuthentication() | ||||
|                 .getPrincipal(); | ||||
|         return principal.getUserPojo().getId().equals(userId); | ||||
|         return principal.getUser().getId().equals(userId); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -2,7 +2,7 @@ package com.databasir.job; | ||||
|  | ||||
| import com.databasir.core.domain.document.service.DocumentService; | ||||
| import com.databasir.dao.impl.ProjectSyncRuleDao; | ||||
| import com.databasir.dao.tables.pojos.ProjectSyncRulePojo; | ||||
| import com.databasir.dao.tables.pojos.ProjectSyncRule; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.quartz.*; | ||||
| @@ -135,7 +135,7 @@ public class ProjectSyncJobScheduler { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private Pair<JobDetail, Trigger> jobAndTriggers(ProjectSyncRulePojo rule) { | ||||
|     private Pair<JobDetail, Trigger> jobAndTriggers(ProjectSyncRule rule) { | ||||
|         JobDataMap dataMap = new JobDataMap(); | ||||
|         Integer projectId = rule.getProjectId(); | ||||
|         Integer ruleId = rule.getId(); | ||||
|   | ||||
| @@ -8,8 +8,8 @@ import com.databasir.dao.enums.ProjectSyncTaskStatus; | ||||
| import com.databasir.dao.impl.ProjectDao; | ||||
| import com.databasir.dao.impl.ProjectSyncTaskDao; | ||||
| import com.databasir.dao.impl.UserDao; | ||||
| import com.databasir.dao.tables.pojos.ProjectSyncTaskPojo; | ||||
| import com.databasir.dao.tables.pojos.UserPojo; | ||||
| import com.databasir.dao.tables.pojos.ProjectSyncTask; | ||||
| import com.databasir.dao.tables.pojos.User; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.scheduling.annotation.Scheduled; | ||||
| @@ -44,9 +44,9 @@ public class ProjectSyncTaskScheduler { | ||||
|     @Scheduled(fixedRate = 5000L) | ||||
|     public void startSyncTask() { | ||||
|         final int size = 10; | ||||
|         List<ProjectSyncTaskPojo> tasks = projectSyncTaskDao.listNewTasks(size); | ||||
|         List<ProjectSyncTask> tasks = projectSyncTaskDao.listNewTasks(size); | ||||
|         List<Integer> projectIds = tasks.stream() | ||||
|                 .map(ProjectSyncTaskPojo::getProjectId) | ||||
|                 .map(ProjectSyncTask::getProjectId) | ||||
|                 .distinct() | ||||
|                 .collect(Collectors.toList()); | ||||
|         Map<Integer, Integer> groupIdAndProjectIdMap = projectDao.selectGroupIdsByProjectIdIn(projectIds); | ||||
| @@ -88,7 +88,7 @@ public class ProjectSyncTaskScheduler { | ||||
|             operatorUsername = "system"; | ||||
|             operationName = "定时同步"; | ||||
|         } else { | ||||
|             UserPojo user = userDao.selectById(userId); | ||||
|             User user = userDao.selectById(userId); | ||||
|             operatorNickName = user.getNickname(); | ||||
|             operatorUsername = user.getUsername(); | ||||
|             operationName = "手动同步"; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user