Skip to content

Commit

Permalink
1.添加了取消报名功能。2.修改了 订阅活动/取消订阅 接口。3.优化了部分代码。
Browse files Browse the repository at this point in the history
  • Loading branch information
Akiyama-Mio-a committed Aug 29, 2023
1 parent 30f08a3 commit f17cc0d
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 75 deletions.
10 changes: 0 additions & 10 deletions src/main/java/sast/evento/controller/EventController.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,20 @@ public BufferedImage eventQrcodeGet(@RequestParam @EventId Integer eventId) {
return null;
}

/**
*/
@OperateLog("查看所有正在进行的活动列表")
@DefaultActionState(ActionState.PUBLIC)
@GetMapping("/conducting")
public List<EventModel> getConducting() {
return eventService.getConducting();
}

/**
*/
@OperateLog("查看最新活动列表(按开始时间正序排列未开始的活动)")
@DefaultActionState(ActionState.PUBLIC)
@GetMapping("/newest")
public List<EventModel> getNewest() {
return eventService.getNewest();
}

/**
*/
@OperateLog("查看用户历史活动列表(参加过已结束)")
@DefaultActionState(ActionState.LOGIN)
@GetMapping("/history")
Expand All @@ -83,8 +77,6 @@ public String deleteEvent(@RequestParam @EventId Integer eventId) {
return null;
}

/**
*/
@OperateLog("获取活动详情")
@DefaultActionState(ActionState.PUBLIC)/* 这里为public,eventId注解没什么用 */
@GetMapping("/info")
Expand Down Expand Up @@ -121,8 +113,6 @@ public String putEvent(@RequestParam @EventId Integer eventId,
return null;
}

/**
*/
@OperateLog("获取活动列表")
@DefaultActionState(ActionState.PUBLIC)
@GetMapping("/list")
Expand Down
17 changes: 5 additions & 12 deletions src/main/java/sast/evento/controller/FeedbackController.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public Map<Integer, Integer> getFeedbackEvents() {
return null;
}

/**
*/
@OperateLog("用户添加反馈")
@DefaultActionState(ActionState.LOGIN)
@PostMapping("/info")
Expand All @@ -50,13 +48,12 @@ public String addFeedback(@RequestParam(required = false) String content,
if (userProFile == null) {
return null;
}

String userIdStr = userProFile.getUserId();
Integer userIdInt = Integer.valueOf(userIdStr);
return feedbackService.addFeedback(userIdInt, content, score, eventId);
}

/**
*/
@OperateLog("用户获取自己的反馈列表")
@DefaultActionState(ActionState.LOGIN)
@GetMapping("/user/list")
Expand All @@ -65,13 +62,12 @@ public List<FeedbackModel> getListByUserId() {
if (userProFile == null) {
return null;
}

String userIdStr = userProFile.getUserId();
Integer userIdInt = Integer.valueOf(userIdStr);
return feedbackService.getListByUserId(userIdInt);
}

/**
*/
// 如果返回的是 null,那么表示用户没有反馈这个活动。
@OperateLog("用户获取自己写的某活动的反馈详情(可判断是否反馈)")
@DefaultActionState(ActionState.LOGIN)
Expand All @@ -81,13 +77,12 @@ public FeedbackModel getFeedback(@RequestParam Integer eventId) {
if (userProFile == null) {
return null;
}

String userIdStr = userProFile.getUserId();
Integer userIdInt = Integer.valueOf(userIdStr);
return feedbackService.getFeedback(userIdInt, eventId);
}

/**
*/
// 如果传进来的 content 为空,则清空数据库的 content 字段。(考虑到有人可能想清空反馈内容,所以这样设计)
// score 为五分制,一位小数。如果传进来的为空,则不做修改。
@OperateLog("用户修改反馈")
Expand All @@ -100,13 +95,12 @@ public String patchFeedback(@RequestParam(required = false) String content,
if (userProFile == null) {
return null;
}

String userIdStr = userProFile.getUserId();
Integer userIdInt = Integer.valueOf(userIdStr);
return feedbackService.patchFeedback(userIdInt, feedbackId, content, score);
}

/**
*/
@OperateLog("用户删除反馈")
@DefaultActionState(ActionState.LOGIN)
@DeleteMapping("/info")
Expand All @@ -115,13 +109,12 @@ public String deleteFeedback(@RequestParam Integer feedbackId) {
if (userProFile == null) {
return null;
}

String userIdStr = userProFile.getUserId();
Integer userIdInt = Integer.valueOf(userIdStr);
return feedbackService.deleteFeedback(userIdInt, feedbackId);
}

/**
*/
@OperateLog("获取活动反馈列表(该活动的所有人的反馈)")
@DefaultActionState(ActionState.LOGIN)
@GetMapping("/list")
Expand Down
24 changes: 8 additions & 16 deletions src/main/java/sast/evento/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public class UserController {
@Resource
private ParticipateService participateService;

/**
*/
@OperateLog("获取个人信息")
@DefaultActionState(ActionState.LOGIN)
@GetMapping("/info")
Expand All @@ -35,8 +33,6 @@ public UserProFile getUser(@RequestParam String userId) {
return null;
}

/**
*/
@OperateLog("更改个人信息")
@DefaultActionState(ActionState.LOGIN)
@PutMapping("/info")
Expand All @@ -48,8 +44,6 @@ public String putUser(@RequestParam String userId,
return null;
}

/**
*/
@OperateLog("订阅活动 / 取消订阅")
@DefaultActionState(ActionState.LOGIN)
@GetMapping("/subscribe")
Expand All @@ -59,13 +53,12 @@ public String subscribe(@RequestParam Integer eventId,
if (userProFile == null) {
return null;
}

String userIdStr = userProFile.getUserId();
Integer userIdInt = Integer.valueOf(userIdStr);
return participateService.subscribe(userIdInt, eventId, isSubscribe);
}

/**
*/
@OperateLog("获取已订阅的活动列表")
@DefaultActionState(ActionState.LOGIN)
@GetMapping("/subscribed")
Expand All @@ -74,28 +67,27 @@ public List<EventModel> getSubscribed() {
if (userProFile == null) {
return null;
}

String userIdStr = userProFile.getUserId();
Integer userIdInt = Integer.valueOf(userIdStr);
return eventService.getSubscribed(userIdInt);
}

/**
*/
@OperateLog("报名活动")
@DefaultActionState(ActionState.LOGIN)
@GetMapping("/register")
public String register(@RequestParam Integer eventId) {
public String register(@RequestParam Integer eventId,
@RequestParam Boolean isRegister) {
UserProFile userProFile = HttpInterceptor.userProFileHolder.get();
if (userProFile == null) {
return null;
}

String userIdStr = userProFile.getUserId();
Integer userIdInt = Integer.valueOf(userIdStr);
return participateService.register(userIdInt, eventId);
return participateService.register(userIdInt, eventId, isRegister);
}

/**
*/
@OperateLog("获取已报名的活动列表")
@DefaultActionState(ActionState.LOGIN)
@GetMapping("/registered")
Expand All @@ -104,13 +96,12 @@ public List<EventModel> getRegistered() {
if (userProFile == null) {
return null;
}

String userIdStr = userProFile.getUserId();
Integer userIdInt = Integer.valueOf(userIdStr);
return eventService.getRegistered(userIdInt);
}

/**
*/
// 查询用户自己是否报名、订阅、参加(即签到)活动
// 若无结果,则表示用户没有报名、没有订阅、更没有签到。
@OperateLog("获取个人的活动的状态")
Expand All @@ -121,6 +112,7 @@ public Participate getParticipation(@RequestParam Integer eventId) {
if (userProFile == null) {
return null;
}

String userIdStr = userProFile.getUserId();
Integer userIdInt = Integer.valueOf(userIdStr);
return participateService.getParticipation(userIdInt, eventId);
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/sast/evento/interceptor/HttpInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
}
}
}
// UserProFile userProFile = sastLinkServiceCacheAble.getUserProFile(userId);//todo 等待对接sastLink
// 临时用,以便测试
UserProFile userProFile = new UserProFile();
userProFile.setUserId("2");
UserProFile userProFile = sastLinkServiceCacheAble.getUserProFile(userId);//todo 等待对接sastLink
userProFileHolder.set(userProFile);
return true;
}
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/sast/evento/mapper/ParticipateMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,4 @@
public interface ParticipateMapper extends BaseMapper<Participate> {
List<String> selectSubscribeOpenIds(@Param("event_id") Integer eventId);

// 订阅活动 / 取消订阅
Integer subscribe(@Param("userId") Integer userId, @Param("eventId") Integer eventId, @Param("isSubscribe") Boolean isSubscribe);

// 报名活动
Integer register(@Param("userId") Integer userId, @Param("eventId") Integer eventId);
}
4 changes: 2 additions & 2 deletions src/main/java/sast/evento/service/ParticipateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public interface ParticipateService {
// 订阅活动 / 取消订阅
String subscribe(Integer userId, Integer eventId, Boolean isSubscribe);

// 报名活动
String register(Integer userId, Integer eventId);
// 报名活动 / 取消报名
String register(Integer userId, Integer eventId, Boolean isRegister);

// 获取个人的活动的状态
Participate getParticipation(Integer userId, Integer eventId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public String patchFeedback(Integer userId, Integer feedbackId, String content,
queryWrapper.eq("user_id", userId);
queryWrapper.eq("id", feedbackId);

Integer updateResult = feedbackMapper.update(feedback, queryWrapper);
return updateResult != null && updateResult > 0 ? "修改反馈成功" : "修改反馈失败";
int updateResult = feedbackMapper.update(feedback, queryWrapper);
return updateResult > 0 ? "修改反馈成功" : "修改反馈失败";
}

// 用户删除反馈
Expand All @@ -100,8 +100,8 @@ public String deleteFeedback(Integer userId, Integer feedbackId) {
queryWrapper.eq("user_id", userId);
queryWrapper.eq("id", feedbackId);

Integer deleteResult = feedbackMapper.delete(queryWrapper);
return deleteResult != null && deleteResult > 0 ? "删除反馈成功" : "删除反馈失败";
int deleteResult = feedbackMapper.delete(queryWrapper);
return deleteResult > 0 ? "删除反馈成功" : "删除反馈失败";
}

// 获取活动反馈列表(该活动的所有人的反馈)
Expand Down
76 changes: 67 additions & 9 deletions src/main/java/sast/evento/service/impl/ParticipateServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sast.evento.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import sast.evento.common.enums.ErrorEnum;
Expand All @@ -26,22 +27,79 @@ public String subscribe(Integer userId, Integer eventId, Boolean isSubscribe) {
throw new LocalRunTimeException(ErrorEnum.PARAM_ERROR);
}

Integer updateResult = participateMapper.subscribe(userId, eventId, isSubscribe);
if (isSubscribe == true) {
return updateResult != null && updateResult > 0 ? "订阅成功" : "订阅失败";
QueryWrapper<Participate> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id", userId);
queryWrapper.eq("event_id", eventId);
Participate participate = participateMapper.selectOne(queryWrapper);

if (participate != null) {
UpdateWrapper<Participate> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("user_id", userId);
updateWrapper.eq("event_id", eventId);
updateWrapper.set("is_subscribe", isSubscribe);

int updateResult = participateMapper.update(null, updateWrapper);
if (isSubscribe) {
return updateResult > 0 ? "订阅成功" : "订阅失败";
} else {
return updateResult > 0 ? "取消订阅成功" : "取消订阅失败";
}
} else {
return updateResult != null && updateResult > 0 ? "取消订阅成功": "取消订阅失败";
participate = new Participate();
participate.setUserId(String.valueOf(userId));
participate.setEventId(eventId);
participate.setIsRegistration(false);
participate.setIsParticipate(false);
participate.setIsSubscribe(isSubscribe);

int insertResult = participateMapper.insert(participate);
if (isSubscribe) {
return insertResult > 0 ? "订阅成功" : "订阅失败";
} else {
return insertResult > 0 ? "取消订阅成功" : "取消订阅失败";
}
}
}

// 报名活动
// 报名活动 / 取消报名
@Override
public String register(Integer userId, Integer eventId) {
if (userId == null || eventId == null) {
public String register(Integer userId, Integer eventId, Boolean isRegister) {
if (userId == null || eventId == null || isRegister == null) {
throw new LocalRunTimeException(ErrorEnum.PARAM_ERROR);
}
Integer insertResult = participateMapper.register(userId, eventId);
return insertResult != null && insertResult > 0 ? "报名成功" : "报名失败";

QueryWrapper<Participate> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id", userId);
queryWrapper.eq("event_id", eventId);
Participate participate = participateMapper.selectOne(queryWrapper);

if (participate != null) {
UpdateWrapper<Participate> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("user_id", userId);
updateWrapper.eq("event_id", eventId);
updateWrapper.set("is_registration", isRegister);

int updateResult = participateMapper.update(null, updateWrapper);
if (isRegister) {
return updateResult > 0 ? "报名成功" : "报名失败";
} else {
return updateResult > 0 ? "取消报名成功" : "取消报名失败";
}
} else {
participate = new Participate();
participate.setUserId(String.valueOf(userId));
participate.setEventId(eventId);
participate.setIsRegistration(isRegister);
participate.setIsParticipate(false);
participate.setIsSubscribe(false);

int insertResult = participateMapper.insert(participate);
if (isRegister) {
return insertResult > 0 ? "报名成功" : "报名失败";
} else {
return insertResult > 0 ? "取消报名成功" : "取消报名失败";
}
}
}

// 获取个人的活动的状态
Expand Down
Loading

0 comments on commit f17cc0d

Please sign in to comment.