From f17cc0ddee11b6922d7e3ce1a9c8fcb36df9dda7 Mon Sep 17 00:00:00 2001 From: mio <2190266250@qq.com> Date: Tue, 29 Aug 2023 13:57:06 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E6=8A=A5=E5=90=8D=E5=8A=9F=E8=83=BD=E3=80=822.=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BA=86=20=E8=AE=A2=E9=98=85=E6=B4=BB=E5=8A=A8/?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E8=AE=A2=E9=98=85=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E3=80=823.=E4=BC=98=E5=8C=96=E4=BA=86=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../evento/controller/EventController.java | 10 --- .../evento/controller/FeedbackController.java | 17 ++--- .../evento/controller/UserController.java | 24 ++---- .../evento/interceptor/HttpInterceptor.java | 5 +- .../sast/evento/mapper/ParticipateMapper.java | 5 -- .../evento/service/ParticipateService.java | 4 +- .../service/impl/FeedbackServiceImpl.java | 8 +- .../service/impl/ParticipateServiceImpl.java | 76 ++++++++++++++++--- .../resources/mapper/participateMapper.xml | 14 +--- 9 files changed, 88 insertions(+), 75 deletions(-) diff --git a/src/main/java/sast/evento/controller/EventController.java b/src/main/java/sast/evento/controller/EventController.java index 7b52693..85f092d 100644 --- a/src/main/java/sast/evento/controller/EventController.java +++ b/src/main/java/sast/evento/controller/EventController.java @@ -43,8 +43,6 @@ public BufferedImage eventQrcodeGet(@RequestParam @EventId Integer eventId) { return null; } - /** - */ @OperateLog("查看所有正在进行的活动列表") @DefaultActionState(ActionState.PUBLIC) @GetMapping("/conducting") @@ -52,8 +50,6 @@ public List getConducting() { return eventService.getConducting(); } - /** - */ @OperateLog("查看最新活动列表(按开始时间正序排列未开始的活动)") @DefaultActionState(ActionState.PUBLIC) @GetMapping("/newest") @@ -61,8 +57,6 @@ public List getNewest() { return eventService.getNewest(); } - /** - */ @OperateLog("查看用户历史活动列表(参加过已结束)") @DefaultActionState(ActionState.LOGIN) @GetMapping("/history") @@ -83,8 +77,6 @@ public String deleteEvent(@RequestParam @EventId Integer eventId) { return null; } - /** - */ @OperateLog("获取活动详情") @DefaultActionState(ActionState.PUBLIC)/* 这里为public,eventId注解没什么用 */ @GetMapping("/info") @@ -121,8 +113,6 @@ public String putEvent(@RequestParam @EventId Integer eventId, return null; } - /** - */ @OperateLog("获取活动列表") @DefaultActionState(ActionState.PUBLIC) @GetMapping("/list") diff --git a/src/main/java/sast/evento/controller/FeedbackController.java b/src/main/java/sast/evento/controller/FeedbackController.java index 7a5a66f..03dc855 100644 --- a/src/main/java/sast/evento/controller/FeedbackController.java +++ b/src/main/java/sast/evento/controller/FeedbackController.java @@ -38,8 +38,6 @@ public Map getFeedbackEvents() { return null; } - /** - */ @OperateLog("用户添加反馈") @DefaultActionState(ActionState.LOGIN) @PostMapping("/info") @@ -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") @@ -65,13 +62,12 @@ public List getListByUserId() { if (userProFile == null) { return null; } + String userIdStr = userProFile.getUserId(); Integer userIdInt = Integer.valueOf(userIdStr); return feedbackService.getListByUserId(userIdInt); } - /** - */ // 如果返回的是 null,那么表示用户没有反馈这个活动。 @OperateLog("用户获取自己写的某活动的反馈详情(可判断是否反馈)") @DefaultActionState(ActionState.LOGIN) @@ -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("用户修改反馈") @@ -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") @@ -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") diff --git a/src/main/java/sast/evento/controller/UserController.java b/src/main/java/sast/evento/controller/UserController.java index 24c10ae..56ce322 100644 --- a/src/main/java/sast/evento/controller/UserController.java +++ b/src/main/java/sast/evento/controller/UserController.java @@ -25,8 +25,6 @@ public class UserController { @Resource private ParticipateService participateService; - /** - */ @OperateLog("获取个人信息") @DefaultActionState(ActionState.LOGIN) @GetMapping("/info") @@ -35,8 +33,6 @@ public UserProFile getUser(@RequestParam String userId) { return null; } - /** - */ @OperateLog("更改个人信息") @DefaultActionState(ActionState.LOGIN) @PutMapping("/info") @@ -48,8 +44,6 @@ public String putUser(@RequestParam String userId, return null; } - /** - */ @OperateLog("订阅活动 / 取消订阅") @DefaultActionState(ActionState.LOGIN) @GetMapping("/subscribe") @@ -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") @@ -74,28 +67,27 @@ public List 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") @@ -104,13 +96,12 @@ public List getRegistered() { if (userProFile == null) { return null; } + String userIdStr = userProFile.getUserId(); Integer userIdInt = Integer.valueOf(userIdStr); return eventService.getRegistered(userIdInt); } - /** - */ // 查询用户自己是否报名、订阅、参加(即签到)活动 // 若无结果,则表示用户没有报名、没有订阅、更没有签到。 @OperateLog("获取个人的活动的状态") @@ -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); diff --git a/src/main/java/sast/evento/interceptor/HttpInterceptor.java b/src/main/java/sast/evento/interceptor/HttpInterceptor.java index 04f0fa0..0a33fd7 100644 --- a/src/main/java/sast/evento/interceptor/HttpInterceptor.java +++ b/src/main/java/sast/evento/interceptor/HttpInterceptor.java @@ -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; } diff --git a/src/main/java/sast/evento/mapper/ParticipateMapper.java b/src/main/java/sast/evento/mapper/ParticipateMapper.java index 0ca3843..365e648 100644 --- a/src/main/java/sast/evento/mapper/ParticipateMapper.java +++ b/src/main/java/sast/evento/mapper/ParticipateMapper.java @@ -13,9 +13,4 @@ public interface ParticipateMapper extends BaseMapper { List 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); } diff --git a/src/main/java/sast/evento/service/ParticipateService.java b/src/main/java/sast/evento/service/ParticipateService.java index 6c37e9f..dabdee0 100644 --- a/src/main/java/sast/evento/service/ParticipateService.java +++ b/src/main/java/sast/evento/service/ParticipateService.java @@ -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); diff --git a/src/main/java/sast/evento/service/impl/FeedbackServiceImpl.java b/src/main/java/sast/evento/service/impl/FeedbackServiceImpl.java index 9559012..be26726 100644 --- a/src/main/java/sast/evento/service/impl/FeedbackServiceImpl.java +++ b/src/main/java/sast/evento/service/impl/FeedbackServiceImpl.java @@ -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 ? "修改反馈成功" : "修改反馈失败"; } // 用户删除反馈 @@ -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 ? "删除反馈成功" : "删除反馈失败"; } // 获取活动反馈列表(该活动的所有人的反馈) diff --git a/src/main/java/sast/evento/service/impl/ParticipateServiceImpl.java b/src/main/java/sast/evento/service/impl/ParticipateServiceImpl.java index 1410961..a4c959d 100644 --- a/src/main/java/sast/evento/service/impl/ParticipateServiceImpl.java +++ b/src/main/java/sast/evento/service/impl/ParticipateServiceImpl.java @@ -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; @@ -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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("user_id", userId); + queryWrapper.eq("event_id", eventId); + Participate participate = participateMapper.selectOne(queryWrapper); + + if (participate != null) { + UpdateWrapper 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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("user_id", userId); + queryWrapper.eq("event_id", eventId); + Participate participate = participateMapper.selectOne(queryWrapper); + + if (participate != null) { + UpdateWrapper 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 ? "取消报名成功" : "取消报名失败"; + } + } } // 获取个人的活动的状态 diff --git a/src/main/resources/mapper/participateMapper.xml b/src/main/resources/mapper/participateMapper.xml index 1811848..73b7f20 100644 --- a/src/main/resources/mapper/participateMapper.xml +++ b/src/main/resources/mapper/participateMapper.xml @@ -11,19 +11,7 @@ where event_id = #{event_id} - - - INSERT INTO participate (is_registration, is_participate, is_subscribe, event_id, user_id) - SELECT true, false, false, #{eventId}, #{userId} - FROM dual - WHERE NOT EXISTS ( - SELECT 1 - FROM participate - WHERE event_id = #{eventId} AND user_id = #{userId} - ) - - - + UPDATE participate SET is_subscribe = #{isSubscribe}