diff --git a/src/main/java/sast/evento/controller/UserController.java b/src/main/java/sast/evento/controller/UserController.java index 5a42da7..c905c6f 100644 --- a/src/main/java/sast/evento/controller/UserController.java +++ b/src/main/java/sast/evento/controller/UserController.java @@ -57,6 +57,7 @@ public String subscribe(@RequestParam Integer eventId, return participateService.subscribe(user.getId(), eventId, isSubscribe); } + // 本周和未来的活动 @OperateLog("获取已订阅的活动列表") @DefaultActionState(ActionState.LOGIN) @GetMapping("/subscribed") @@ -74,6 +75,7 @@ public String register(@RequestParam Integer eventId, return participateService.register(user.getId(), eventId, isRegister); } + // 本周和未来的活动 @OperateLog("获取已报名的活动列表") @DefaultActionState(ActionState.LOGIN) @GetMapping("/registered") diff --git a/src/main/java/sast/evento/mapper/EventModelMapper.java b/src/main/java/sast/evento/mapper/EventModelMapper.java index b85fee5..79a3bd6 100644 --- a/src/main/java/sast/evento/mapper/EventModelMapper.java +++ b/src/main/java/sast/evento/mapper/EventModelMapper.java @@ -77,10 +77,14 @@ List postForEventsByAll(@Param("type_id") List typeId, @Param("next_monday") Date nextMonday); - // 获取已订阅的活动列表 - List getSubscribed(@Param("userId") String userId); + // 获取已订阅的活动列表(本周和未来的活动) + List getSubscribed(@Param("userId") String userId, + @Param("monday") Date monday, + @Param("next_monday") Date nextMonday); - // 获取已报名的活动列表 - List getRegistered(@Param("userId") String userId); + // 获取已报名的活动列表(本周和未来的活动) + List getRegistered(@Param("userId") String userId, + @Param("monday") Date monday, + @Param("next_monday") Date nextMonday); } \ No newline at end of file diff --git a/src/main/java/sast/evento/service/EventService.java b/src/main/java/sast/evento/service/EventService.java index 822d49f..deae79e 100644 --- a/src/main/java/sast/evento/service/EventService.java +++ b/src/main/java/sast/evento/service/EventService.java @@ -28,10 +28,10 @@ public interface EventService { // 获取活动列表 PageModel getEvents(Integer page, Integer size); - // 获取已订阅的活动列表 + // 获取已订阅的活动列表(本周和未来的活动) List getSubscribed(String userId); - // 获取已报名的活动列表 + // 获取已报名的活动列表(本周和未来的活动) List getRegistered(String userId); // 发起活动(添加活动) diff --git a/src/main/java/sast/evento/service/impl/EventServiceImpl.java b/src/main/java/sast/evento/service/impl/EventServiceImpl.java index 27d211d..2b5c692 100644 --- a/src/main/java/sast/evento/service/impl/EventServiceImpl.java +++ b/src/main/java/sast/evento/service/impl/EventServiceImpl.java @@ -127,13 +127,21 @@ public PageModel getEvents(Integer page, Integer size) { return res; } - // 获取已订阅的活动列表 + // 获取已订阅的活动列表(本周和未来的活动) @Override public List getSubscribed(String userId) { if (userId == null) { throw new LocalRunTimeException(ErrorEnum.PARAM_ERROR); } - return eventModelMapper.getSubscribed(userId); + String time = timeUtil.getTime(); + List dates = timeUtil.getDateOfMonday(time); + if(dates == null || dates.isEmpty()) { + throw new LocalRunTimeException(ErrorEnum.TIME_ERROR); + } + // 结束日期设为无限大,获取的不是Date最大时间而是MySQL中datetime最大时间 + final Date FINAL_DATE = timeUtil.validTime("9999-12-31").getTime(); + dates.set(1, FINAL_DATE); + return eventModelMapper.getSubscribed(userId, dates.get(0), dates.get(1)); } @Transactional(rollbackFor = Exception.class) @@ -401,12 +409,21 @@ public List postForEvents(List typeId, List depart return eventModelMapper.postForEventsByAll(typeId, departmentId, date.get(0), date.get(1)); } + // 获取已报名的活动列表(本周和未来的活动) @Override public List getRegistered(String userId) { if (userId == null) { throw new LocalRunTimeException(ErrorEnum.PARAM_ERROR); } - return eventModelMapper.getRegistered(userId); + String time = timeUtil.getTime(); + List dates = timeUtil.getDateOfMonday(time); + if(dates == null || dates.isEmpty()) { + throw new LocalRunTimeException(ErrorEnum.TIME_ERROR); + } + // 结束日期设为无限大,获取的不是Date最大时间而是MySQL中datetime最大时间 + final Date FINAL_DATE = timeUtil.validTime("9999-12-31").getTime(); + dates.set(1, FINAL_DATE); + return eventModelMapper.getRegistered(userId, dates.get(0), dates.get(1)); } private EventState getMatchState(Date registrationStart, Date registrationEnd, Date eventStart, Date eventEnd) { diff --git a/src/main/resources/mapper/eventModelMapper.xml b/src/main/resources/mapper/eventModelMapper.xml index 7300675..21c7dfe 100644 --- a/src/main/resources/mapper/eventModelMapper.xml +++ b/src/main/resources/mapper/eventModelMapper.xml @@ -196,19 +196,31 @@ - + - + \ No newline at end of file