77import com .example .helloworldmvc .domain .Counselor ;
88import com .example .helloworldmvc .domain .Language ;
99import com .example .helloworldmvc .domain .User ;
10+ import com .example .helloworldmvc .domain .enums .CenterStatus ;
1011import com .example .helloworldmvc .domain .mapping .UserLanguage ;
1112import com .example .helloworldmvc .repository .*;
1213import com .example .helloworldmvc .web .dto .CenterRequestDTO ;
1314import jakarta .transaction .Transactional ;
1415import lombok .RequiredArgsConstructor ;
1516import org .springframework .data .domain .Page ;
1617import org .springframework .data .domain .PageRequest ;
18+ import org .springframework .scheduling .annotation .Scheduled ;
1719import org .springframework .stereotype .Service ;
1820
21+ import java .time .LocalDateTime ;
22+ import java .time .LocalTime ;
1923import java .util .List ;
2024import java .util .stream .Collectors ;
2125
@@ -35,7 +39,6 @@ public Page<Center> getCenterListByDistance(double latitude, double longitude, I
3539 return centerRepository .findAllOrderByDistance (latitude , longitude , PageRequest .of (page , size ));
3640 }
3741
38-
3942 @ Override
4043 public Page <Counselor > getCounselorList (String userId , Long centerId , Integer page , Integer size ) {
4144 User user = userRepository .findByEmail (userId ).orElseThrow (() -> new GeneralException (ErrorStatus .USER_NOT_FOUND ));
@@ -64,4 +67,19 @@ public Center getCenter(String userId, Long centerId) {
6467 userRepository .findByEmail (userId ).orElseThrow (() -> new GeneralException (ErrorStatus .USER_NOT_FOUND ));
6568 return centerRepository .findById (centerId ).orElseThrow (() -> new GeneralException (ErrorStatus .CENTER_NOT_FOUND ));
6669 }
70+
71+ @ Override
72+ /* 2시간마다 스케쥴링 */
73+ @ Scheduled (cron = "0 0 0/2 * * ?" , zone = "Asia/Seoul" )
74+ public void updateCenterStatus () {
75+ List <Center > centerList = centerRepository .findAll ();
76+ LocalTime now = LocalTime .now ();
77+ centerList .stream ().map (center -> {
78+ if (now .isAfter (center .getOpened ()) && now .isBefore (center .getClosed ()) ){
79+ center .setStatus (CenterStatus .OPEN );
80+ }
81+ center .setStatus (CenterStatus .CLOSED );
82+ return centerRepository .save (center );
83+ });
84+ }
6785}
0 commit comments