Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改 已订阅的活动列表 和 已报名的活动列表 接口 #104

Merged
merged 1 commit into from
Dec 12, 2023
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
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>