From feec1923649cfabd0a0a19aabcbc96600f589d88 Mon Sep 17 00:00:00 2001 From: Haixing Hu Date: Mon, 24 Feb 2025 10:11:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=B7=B2=E5=AE=8C=E6=88=90=E8=B0=83=E6=9F=A5=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84=E6=8E=A5=E5=8F=A3=201.=20=E5=9C=A8?= =?UTF-8?q?=20UserController=20=E4=B8=AD=E6=B7=BB=E5=8A=A0=20/user/complet?= =?UTF-8?q?ed=20=E6=8E=A5=E5=8F=A3=202.=20=E5=9C=A8=20UserService=20?= =?UTF-8?q?=E4=B8=AD=E6=B7=BB=E5=8A=A0=20findCompletedUsers=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95=203.=20=E5=9C=A8=20UserDao=20=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20findByIds=20=E6=96=B9=E6=B3=95=204.=20=E5=9C=A8=20S?= =?UTF-8?q?urveyResponseDao=20=E4=B8=AD=E6=B7=BB=E5=8A=A0=20findDistinctUs?= =?UTF-8?q?erIds=20=E6=96=B9=E6=B3=95=205.=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=BB=93=E6=9E=84=EF=BC=8C=E7=A7=BB=E9=99=A4=20Survey?= =?UTF-8?q?ResponseService=20=E4=B8=AD=E4=B8=8D=E5=BF=85=E8=A6=81=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qubit/survey/controller/UserController.java | 12 ++++++++++++ .../ltd/qubit/survey/dao/SurveyResponseDao.java | 7 +++++++ .../main/java/ltd/qubit/survey/dao/UserDao.java | 8 ++++++++ .../java/ltd/qubit/survey/service/UserService.java | 7 +++++++ .../qubit/survey/service/impl/UserServiceImpl.java | 14 ++++++++++++++ .../mybatis/mapper/SurveyResponseMapper.xml | 7 +++++++ .../main/resources/mybatis/mapper/UserMapper.xml | 11 +++++++++++ 7 files changed, 66 insertions(+) diff --git a/backend/src/main/java/ltd/qubit/survey/controller/UserController.java b/backend/src/main/java/ltd/qubit/survey/controller/UserController.java index f7d3fbe..13c08d7 100644 --- a/backend/src/main/java/ltd/qubit/survey/controller/UserController.java +++ b/backend/src/main/java/ltd/qubit/survey/controller/UserController.java @@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + /** * 用户控制器 */ @@ -82,4 +84,14 @@ public class UserController { public boolean checkPhone(@PathVariable String phone) { return userService.findByPhone(phone).isPresent(); } + + /** + * 获取已完成调查的用户列表 + * + * @return 用户列表 + */ + @GetMapping("/user/completed") + public List findCompletedUsers() { + return userService.findCompletedUsers(); + } } \ No newline at end of file diff --git a/backend/src/main/java/ltd/qubit/survey/dao/SurveyResponseDao.java b/backend/src/main/java/ltd/qubit/survey/dao/SurveyResponseDao.java index dab5d09..33a5330 100644 --- a/backend/src/main/java/ltd/qubit/survey/dao/SurveyResponseDao.java +++ b/backend/src/main/java/ltd/qubit/survey/dao/SurveyResponseDao.java @@ -48,4 +48,11 @@ public interface SurveyResponseDao extends BaseDao { * @return 影响的行数 */ int deleteByUserId(Long userId); + + /** + * 获取所有已提交答案的用户ID列表 + * + * @return 用户ID列表 + */ + List findDistinctUserIds(); } \ No newline at end of file diff --git a/backend/src/main/java/ltd/qubit/survey/dao/UserDao.java b/backend/src/main/java/ltd/qubit/survey/dao/UserDao.java index 37e95c9..fae6e7f 100644 --- a/backend/src/main/java/ltd/qubit/survey/dao/UserDao.java +++ b/backend/src/main/java/ltd/qubit/survey/dao/UserDao.java @@ -18,4 +18,12 @@ public interface UserDao extends BaseDao { * @return 用户信息 */ Optional findByPhone(@Param("phone") String phone); + + /** + * 根据ID列表查询用户 + * + * @param ids 用户ID列表 + * @return 用户列表 + */ + List findByIds(@Param("ids") List ids); } \ No newline at end of file diff --git a/backend/src/main/java/ltd/qubit/survey/service/UserService.java b/backend/src/main/java/ltd/qubit/survey/service/UserService.java index 6e55942..251a2c6 100644 --- a/backend/src/main/java/ltd/qubit/survey/service/UserService.java +++ b/backend/src/main/java/ltd/qubit/survey/service/UserService.java @@ -69,4 +69,11 @@ public interface UserService { * @return 登录或注册成功的用户信息 */ User loginOrRegister(User user); + + /** + * 获取已完成调查的用户列表 + * + * @return 用户列表 + */ + List findCompletedUsers(); } \ No newline at end of file diff --git a/backend/src/main/java/ltd/qubit/survey/service/impl/UserServiceImpl.java b/backend/src/main/java/ltd/qubit/survey/service/impl/UserServiceImpl.java index edcb7f2..9297793 100644 --- a/backend/src/main/java/ltd/qubit/survey/service/impl/UserServiceImpl.java +++ b/backend/src/main/java/ltd/qubit/survey/service/impl/UserServiceImpl.java @@ -1,10 +1,12 @@ package ltd.qubit.survey.service.impl; import java.time.Instant; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; import ltd.qubit.survey.dao.UserDao; +import ltd.qubit.survey.dao.SurveyResponseDao; import ltd.qubit.survey.model.User; import ltd.qubit.survey.service.UserService; import org.springframework.stereotype.Service; @@ -17,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor public class UserServiceImpl implements UserService { private final UserDao userDao; + private final SurveyResponseDao surveyResponseDao; @Override @Transactional @@ -80,4 +83,15 @@ public class UserServiceImpl implements UserService { } return register(user); } + + @Override + public List findCompletedUsers() { + // 获取所有已提交答案的用户ID + List userIds = surveyResponseDao.findDistinctUserIds(); + if (userIds.isEmpty()) { + return new ArrayList<>(); + } + // 获取这些用户的详细信息 + return userDao.findByIds(userIds); + } } \ No newline at end of file diff --git a/backend/src/main/resources/mybatis/mapper/SurveyResponseMapper.xml b/backend/src/main/resources/mybatis/mapper/SurveyResponseMapper.xml index bce6ae1..8c5f411 100644 --- a/backend/src/main/resources/mybatis/mapper/SurveyResponseMapper.xml +++ b/backend/src/main/resources/mybatis/mapper/SurveyResponseMapper.xml @@ -92,4 +92,11 @@ WHERE `user_id` = #{userId} AND `question_id` = #{questionId} + + + \ No newline at end of file diff --git a/backend/src/main/resources/mybatis/mapper/UserMapper.xml b/backend/src/main/resources/mybatis/mapper/UserMapper.xml index 4f1f787..83ce7f9 100644 --- a/backend/src/main/resources/mybatis/mapper/UserMapper.xml +++ b/backend/src/main/resources/mybatis/mapper/UserMapper.xml @@ -54,4 +54,15 @@ FROM user WHERE phone = #{phone} + + + \ No newline at end of file