Ver Fonte

question_todo

westt há 1 ano atrás
pai
commit
a5b42ae11e

+ 17 - 0
src/main/java/com/example/onlinejudge/model/VO/UserVO.java

@@ -1,5 +1,7 @@
 package com.example.onlinejudge.model.VO;
 
+import cn.hutool.core.bean.BeanUtil;
+import com.example.onlinejudge.model.entity.User;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -30,4 +32,19 @@ public class UserVO implements Serializable {
     private Date createTime;
 
     private static final long serialVersionUID = 1L;
+
+    /** TODO: 没有对userProfile和userAvatar、createTime属性进行处理
+     * User对象转UserVO包装类
+     * @param user User对象
+     * @return UserVo
+     */
+    public static UserVO objToVo(User user) {
+        if (user == null)
+            return null;
+        UserVO userVO = new UserVO();
+        userVO.setUserName(user.getUsername());
+        userVO.setUserRole(user.getRole());
+        userVO.setId(user.getId());
+        return userVO;
+    }
 }

+ 5 - 0
src/main/java/com/example/onlinejudge/service/UserService.java

@@ -1,6 +1,7 @@
 package com.example.onlinejudge.service;
 
 import cn.dev33.satoken.util.SaResult;
+import com.example.onlinejudge.model.VO.UserVO;
 import com.example.onlinejudge.model.entity.User;
 import com.example.onlinejudge.model.entity.result.Result;
 
@@ -14,4 +15,8 @@ public interface UserService {
     Boolean isAdmin(Long userId);
 
     Long getLoginUserId();
+
+    User getUserById(Long id);
+
+    UserVO getUserVO(User user);
 }

+ 4 - 3
src/main/java/com/example/onlinejudge/service/impl/QuestionServiceImpl.java

@@ -140,12 +140,13 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question>
         List<QuestionVO> questionVOList = questionList.stream().map(question -> {
             QuestionVO questionVO = QuestionVO.objToVo(question);
             Long userId = question.getUserId();
-            User user = null;
-            //TODO 填充userID
+            User user = userService.getUserById(userId);
+            //TODO 填充userID Done
+
 //            if (userIdUserListMap.containsKey(userId)) {
 //                user = userIdUserListMap.get(userId).get(0);
 //            }
-//            questionVO.setUserVO(userService.getUserVO(user));
+            questionVO.setUserVO(userService.getUserVO(user));
             return questionVO;
         }).collect(Collectors.toList());
         questionVOPage.setRecords(questionVOList);

+ 10 - 0
src/main/java/com/example/onlinejudge/service/impl/UserServiceImpl.java

@@ -6,6 +6,7 @@ import cn.dev33.satoken.stp.StpUtil;
 import cn.dev33.satoken.util.SaResult;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.example.onlinejudge.model.VO.UserVO;
 import com.example.onlinejudge.model.entity.User;
 import com.example.onlinejudge.mapper.UserMapper;
 import com.example.onlinejudge.model.entity.result.Result;
@@ -60,4 +61,13 @@ public class UserServiceImpl implements UserService {
         return userMapper.selectById(StpUtil.getLoginIdAsLong());
     }
 
+    @Override
+    public User getUserById(Long id) {
+        return userMapper.selectById(id);
+    }
+
+    @Override
+    public UserVO getUserVO(User user) {
+        return null;
+    }
 }