Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableJpaAuditing
@EnableFeignClients
@EnableScheduling
public class HelloworldMvcApplication {

public static void main(String[] args) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/example/helloworldmvc/domain/Center.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ public class Center {
@OneToOne(mappedBy = "center", cascade = CascadeType.ALL)
private File file;

public void setStatus(CenterStatus status) {
this.status = status;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public interface CenterService {
Center getCenter(String userId, Long centerId);

Page<Center> getCenterListByDistance(double latitude, double longitude, Integer page, Integer size);

public void updateCenterStatus();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
import com.example.helloworldmvc.domain.Counselor;
import com.example.helloworldmvc.domain.Language;
import com.example.helloworldmvc.domain.User;
import com.example.helloworldmvc.domain.enums.CenterStatus;
import com.example.helloworldmvc.domain.mapping.UserLanguage;
import com.example.helloworldmvc.repository.*;
import com.example.helloworldmvc.web.dto.CenterRequestDTO;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -35,7 +39,6 @@ public Page<Center> getCenterListByDistance(double latitude, double longitude, I
return centerRepository.findAllOrderByDistance(latitude, longitude, PageRequest.of(page, size));
}


@Override
public Page<Counselor> getCounselorList(String userId, Long centerId, Integer page, Integer size) {
User user = userRepository.findByEmail(userId).orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND));
Expand Down Expand Up @@ -64,4 +67,19 @@ public Center getCenter(String userId, Long centerId) {
userRepository.findByEmail(userId).orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND));
return centerRepository.findById(centerId).orElseThrow(() -> new GeneralException(ErrorStatus.CENTER_NOT_FOUND));
}

@Override
/* 2시간마다 스케쥴링 */
@Scheduled(cron = "0 0 0/2 * * ?", zone = "Asia/Seoul")
public void updateCenterStatus() {
List<Center> centerList = centerRepository.findAll();
LocalTime now = LocalTime.now();
centerList.stream().map(center -> {
if(now.isAfter(center.getOpened()) && now.isBefore(center.getClosed()) ){
center.setStatus(CenterStatus.OPEN);
}
center.setStatus(CenterStatus.CLOSED);
return centerRepository.save(center);
});
}
}
Loading