Skip to content

Commit

Permalink
Feat : 직위 추가 ddl 수정, 교직원 스크랩 로직 및 주기 변경 (#224)
Browse files Browse the repository at this point in the history
* fix : ddl default 값 변경

* fix : 성공 학과 구분 없이 전체 학과 대상으로 업데이트하도록 수정

* test: 교직원 스크랩코드 변경에 따른 테스트 코드 수정

* remove : 불필요 출력문 제거
  • Loading branch information
rlagkswn00 authored Dec 21, 2024
1 parent a73c120 commit 595d7d4
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ out/
### API docs ###
**/src/main/resources/static/docs/*

**/ku-stack-firebase-adminsdk-87nwq-5ba04dfc12.json
**/ku-stack-firebase-adminsdk-87nwq-ae6a2df931.json
**/src/main/generated/
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ configurations.all {
}
}

test.onlyIf { System.getenv('DEPLOY_ENV') == 'dev' }
//test.onlyIf { System.getenv('DEPLOY_ENV') == 'dev' }

test {
jacoco {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import com.kustacks.kuring.staff.domain.Staff;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface StaffRepository extends JpaRepository<Staff, Long>, StaffQueryRepository {

List<Staff> findByDeptContaining(String deptName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand All @@ -29,7 +28,7 @@ public void compareAndUpdateDb(StaffScrapResults scrapResults) {
}

private StaffCompareResults compare(StaffScrapResults scrapResults) {
Map<String, Staff> originStaffStorage = findByDeptContainingMap(scrapResults.successDepartmentNames());
Map<String, Staff> originStaffStorage = findAllOriginStaffs();
return staffCompareSupport.compareAllDepartmentsAndUpdateExistStaff(scrapResults.kuStaffDTOMap(), originStaffStorage);
}

Expand All @@ -38,11 +37,9 @@ private void synchronizationWithDb(StaffCompareResults compareResults) {
staffRepository.saveAll(compareResults.newStaffs());
}

private Map<String, Staff> findByDeptContainingMap(List<String> scrapSuccessDepartmentNames) {
return scrapSuccessDepartmentNames.stream()
.flatMap(
deptName -> staffRepository.findByDeptContaining(deptName).stream()
).collect(
private Map<String, Staff> findAllOriginStaffs() {
return staffRepository.findAll().stream()
.collect(
Collectors.toMap(
Staff::identifier,
Function.identity(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand All @@ -26,7 +25,7 @@ public class StaffUpdater {
private final StaffScraper staffScraper;
private final List<DeptInfo> deptInfos;

@Scheduled(fixedRate = 1, timeUnit = TimeUnit.DAYS)
@Scheduled(fixedRate = 30, timeUnit = TimeUnit.DAYS)
public void update() {
log.info("========== 교직원 업데이트 시작 ==========");

Expand All @@ -38,19 +37,17 @@ public void update() {

private StaffScrapResults scrapAllDepartmentsStaffs() {
Map<String, StaffDto> kuStaffDtoMap = new HashMap<>();
List<String> successDepartmentNames = new LinkedList<>();

deptInfos.stream()
.filter(DeptInfo::isSupportStaffScrap)
.forEach(deptInfo -> scrapSingleDepartmentsStaffs(kuStaffDtoMap, successDepartmentNames, deptInfo));
return new StaffScrapResults(kuStaffDtoMap, successDepartmentNames);
.forEach(deptInfo -> scrapSingleDepartmentsStaffs(kuStaffDtoMap, deptInfo));
return new StaffScrapResults(kuStaffDtoMap);
}

private void scrapSingleDepartmentsStaffs(Map<String, StaffDto> kuStaffDtoMap, List<String> successDepartmentNames, DeptInfo deptInfo) {
private void scrapSingleDepartmentsStaffs(Map<String, StaffDto> kuStaffDtoMap, DeptInfo deptInfo) {
try {
Map<String, StaffDto> staffScrapResultMap = scrapStaffByDepartment(deptInfo);
mergeForMultipleDepartmentsStaff(kuStaffDtoMap, staffScrapResultMap);
successDepartmentNames.add(deptInfo.getDeptName());
} catch (InternalLogicException e) {
log.error("[StaffScraperException] {}학과 교직원 스크래핑 문제 발생.", deptInfo.getDeptName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import java.util.Map;

public record StaffScrapResults(
Map<String, StaffDto> kuStaffDTOMap,
List<String> successDepartmentNames
Map<String, StaffDto> kuStaffDTOMap
) {

public List<StaffDto> getStaffDtos() {
return kuStaffDTOMap.values().stream().toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ALTER TABLE staff
ADD column position varchar(64) default false;
ADD column position varchar(64);
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ void compareAndUpdateDb() {
kuStaffDtoMap.put(dto1.identifier(), dto1);
kuStaffDtoMap.put(dto2.identifier(), dto2);

List<String> successDepartmentNames = List.of("컴퓨터공학과", "생명과학부");
StaffScrapResults staffScrapResults = new StaffScrapResults(kuStaffDtoMap, successDepartmentNames);
StaffScrapResults staffScrapResults = new StaffScrapResults(kuStaffDtoMap);

// when
staffDataSynchronizer.compareAndUpdateDb(staffScrapResults);
Expand Down

0 comments on commit 595d7d4

Please sign in to comment.