Skip to content

Commit

Permalink
Merge pull request #104 from NJUPT-SAST/dev-mio
Browse files Browse the repository at this point in the history
修改 已订阅的活动列表 和 已报名的活动列表 接口
  • Loading branch information
Akiyama-Mio-a authored Dec 12, 2023
2 parents fc9d3f7 + f7e9fa6 commit a79df47
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/main/java/sast/evento/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public String subscribe(@RequestParam Integer eventId,
return participateService.subscribe(user.getId(), eventId, isSubscribe);
}

// 本周和未来的活动
@OperateLog("获取已订阅的活动列表")
@DefaultActionState(ActionState.LOGIN)
@GetMapping("/subscribed")
Expand All @@ -74,6 +75,7 @@ public String register(@RequestParam Integer eventId,
return participateService.register(user.getId(), eventId, isRegister);
}

// 本周和未来的活动
@OperateLog("获取已报名的活动列表")
@DefaultActionState(ActionState.LOGIN)
@GetMapping("/registered")
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/sast/evento/mapper/EventModelMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ List<EventModel> postForEventsByAll(@Param("type_id") List<Integer> typeId,
@Param("next_monday") Date nextMonday);


// 获取已订阅的活动列表
List<EventModel> getSubscribed(@Param("userId") String userId);
// 获取已订阅的活动列表(本周和未来的活动)
List<EventModel> getSubscribed(@Param("userId") String userId,
@Param("monday") Date monday,
@Param("next_monday") Date nextMonday);

// 获取已报名的活动列表
List<EventModel> getRegistered(@Param("userId") String userId);
// 获取已报名的活动列表(本周和未来的活动)
List<EventModel> getRegistered(@Param("userId") String userId,
@Param("monday") Date monday,
@Param("next_monday") Date nextMonday);

}
4 changes: 2 additions & 2 deletions src/main/java/sast/evento/service/EventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public interface EventService {
// 获取活动列表
PageModel<EventModel> getEvents(Integer page, Integer size);

// 获取已订阅的活动列表
// 获取已订阅的活动列表(本周和未来的活动)
List<EventModel> getSubscribed(String userId);

// 获取已报名的活动列表
// 获取已报名的活动列表(本周和未来的活动)
List<EventModel> getRegistered(String userId);

// 发起活动(添加活动)
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/sast/evento/service/impl/EventServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,21 @@ public PageModel<EventModel> getEvents(Integer page, Integer size) {
return res;
}

// 获取已订阅的活动列表
// 获取已订阅的活动列表(本周和未来的活动)
@Override
public List<EventModel> getSubscribed(String userId) {
if (userId == null) {
throw new LocalRunTimeException(ErrorEnum.PARAM_ERROR);
}
return eventModelMapper.getSubscribed(userId);
String time = timeUtil.getTime();
List<Date> 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)
Expand Down Expand Up @@ -401,12 +409,21 @@ public List<EventModel> postForEvents(List<Integer> typeId, List<Integer> depart
return eventModelMapper.postForEventsByAll(typeId, departmentId, date.get(0), date.get(1));
}

// 获取已报名的活动列表(本周和未来的活动)
@Override
public List<EventModel> getRegistered(String userId) {
if (userId == null) {
throw new LocalRunTimeException(ErrorEnum.PARAM_ERROR);
}
return eventModelMapper.getRegistered(userId);
String time = timeUtil.getTime();
List<Date> 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) {
Expand Down
24 changes: 18 additions & 6 deletions src/main/resources/mapper/eventModelMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,31 @@
<include refid="byDepartmentId"/>
</select>

<!-- 获取已订阅的活动列表-->
<!-- 获取已订阅的活动列表(本周和未来的活动)-->
<select id="getSubscribed" resultMap="eventModelMap">
<include refid="selectFrom" />
<include refid="selectFrom"/>
LEFT JOIN
participate AS p ON e.id = p.event_id
WHERE p.user_id = #{userId} AND p.is_subscribe = 1
WHERE
p.user_id = #{userId}
AND
p.is_subscribe = 1
AND
<include refid="byTime"/>
ORDER BY e.gmt_event_start DESC
</select>

<!-- 获取已报名的活动列表-->
<!-- 获取已报名的活动列表(本周和未来的活动)-->
<select id="getRegistered" resultMap="eventModelMap">
<include refid="selectFrom" />
<include refid="selectFrom"/>
LEFT JOIN
participate AS p ON e.id = p.event_id
WHERE p.user_id = #{userId} AND p.is_registration = 1
WHERE
p.user_id = #{userId}
AND
p.is_registration = 1
AND
<include refid="byTime"/>
ORDER BY e.gmt_event_start DESC
</select>
</mapper>

0 comments on commit a79df47

Please sign in to comment.