feat: 添加获取已完成调查用户列表的接口 1. 在 UserController 中添加 /user/completed 接口 2. 在 UserService 中添加 findCompletedUsers 方法 3. 在 UserDao 中添加 findByIds 方法 4. 在 SurveyResponseDao 中添加 findDistinctUserIds 方法 5. 优化代码结构,移除 SurveyResponseService 中不必要的接口方法
This commit is contained in:
parent
d3adab8adc
commit
feec192364
@ -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<User> findCompletedUsers() {
|
||||
return userService.findCompletedUsers();
|
||||
}
|
||||
}
|
||||
@ -48,4 +48,11 @@ public interface SurveyResponseDao extends BaseDao<SurveyResponse, Long> {
|
||||
* @return 影响的行数
|
||||
*/
|
||||
int deleteByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 获取所有已提交答案的用户ID列表
|
||||
*
|
||||
* @return 用户ID列表
|
||||
*/
|
||||
List<Long> findDistinctUserIds();
|
||||
}
|
||||
@ -18,4 +18,12 @@ public interface UserDao extends BaseDao<User, Long> {
|
||||
* @return 用户信息
|
||||
*/
|
||||
Optional<User> findByPhone(@Param("phone") String phone);
|
||||
|
||||
/**
|
||||
* 根据ID列表查询用户
|
||||
*
|
||||
* @param ids 用户ID列表
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<User> findByIds(@Param("ids") List<Long> ids);
|
||||
}
|
||||
@ -69,4 +69,11 @@ public interface UserService {
|
||||
* @return 登录或注册成功的用户信息
|
||||
*/
|
||||
User loginOrRegister(User user);
|
||||
|
||||
/**
|
||||
* 获取已完成调查的用户列表
|
||||
*
|
||||
* @return 用户列表
|
||||
*/
|
||||
List<User> findCompletedUsers();
|
||||
}
|
||||
@ -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<User> findCompletedUsers() {
|
||||
// 获取所有已提交答案的用户ID
|
||||
List<Long> userIds = surveyResponseDao.findDistinctUserIds();
|
||||
if (userIds.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
// 获取这些用户的详细信息
|
||||
return userDao.findByIds(userIds);
|
||||
}
|
||||
}
|
||||
@ -92,4 +92,11 @@
|
||||
WHERE `user_id` = #{userId}
|
||||
AND `question_id` = #{questionId}
|
||||
</select>
|
||||
|
||||
<!-- 获取所有已提交答案的用户ID列表 -->
|
||||
<select id="findDistinctUserIds" resultType="long">
|
||||
SELECT DISTINCT `user_id`
|
||||
FROM `survey_response`
|
||||
ORDER BY `user_id`
|
||||
</select>
|
||||
</mapper>
|
||||
@ -54,4 +54,15 @@
|
||||
FROM user
|
||||
WHERE phone = #{phone}
|
||||
</select>
|
||||
|
||||
<!-- 根据ID列表查询 -->
|
||||
<select id="findByIds" resultMap="userMap">
|
||||
SELECT <include refid="columns"/>
|
||||
FROM user
|
||||
WHERE id IN
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
ORDER BY created_at DESC
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue
Block a user