From f7e9fa6c5d686585c7d522fe76d88e9961a1a55e Mon Sep 17 00:00:00 2001 From: mio <2190266250@qq.com> Date: Tue, 12 Dec 2023 15:21:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E5=B7=B2=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E7=9A=84=E6=B4=BB=E5=8A=A8=E5=88=97=E8=A1=A8=20?= =?UTF-8?q?=E5=92=8C=20=E5=B7=B2=E6=8A=A5=E5=90=8D=E7=9A=84=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=E5=88=97=E8=A1=A8=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../evento/controller/UserController.java | 2 ++ .../sast/evento/mapper/EventModelMapper.java | 12 ++++++---- .../sast/evento/service/EventService.java | 4 ++-- .../evento/service/impl/EventServiceImpl.java | 23 +++++++++++++++--- .../resources/mapper/eventModelMapper.xml | 24 ++++++++++++++----- 5 files changed, 50 insertions(+), 15 deletions(-) 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