yangfeng před 1 rokem
rodič
revize
79bb8365ea

+ 15 - 0
web/src/main/java/com/ynfy/app/api/v1/controller/ApiIndexController.java

@@ -8,6 +8,7 @@ import com.ynfy.buss.banner.service.IBannerService;
 import com.ynfy.buss.course.course.service.ICourseService;
 import com.ynfy.buss.exam.exam.entity.Exam;
 import com.ynfy.buss.exam.exam.service.IExamService;
+import com.ynfy.buss.practice.userpractice.service.IUserPracticeService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.jeecg.common.api.vo.Result;
@@ -47,6 +48,9 @@ public class ApiIndexController extends ApiBaseController {
     @Autowired
     private IArticleService articleService;
 
+    @Autowired
+    private IUserPracticeService userPracticeService;
+
     @IgnoreAuth
     @PostMapping("/banner/list")
     public Result<?> list() {
@@ -168,4 +172,15 @@ public class ApiIndexController extends ApiBaseController {
         return Result.OK(articleService.getById(id));
     }
 
+    /**
+     * 最近练习
+     *
+     * @return
+     */
+    @IgnoreAuth
+    @GetMapping("/listLatestPractice")
+    public Result<?> listLatestPractice(Integer limit) {
+        return Result.OK(userPracticeService.listLatestPractice(limit, TokenUtil.getUserId(TokenUtil.getToken(request))));
+    }
+
 }

+ 2 - 1
web/src/main/java/com/ynfy/buss/practice/userpractice/controller/UserPracticeController.java

@@ -167,7 +167,8 @@ public class UserPracticeController extends JeecgController<UserPractice, IUserP
     @ApiOperation(value = "获取用户最近的练习", notes = "获取用户最近的练习")
     @GetMapping(value = "/getRecentPractice")
     public Result<?> getRecentPractice(@RequestParam String repositoryId) {
-        return Result.OK(userPracticeService.getRecentPractice(repositoryId));
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        return Result.OK(userPracticeService.getRecentPractice(repositoryId, user.getId()));
     }
 
 

+ 10 - 1
web/src/main/java/com/ynfy/buss/practice/userpractice/service/IUserPracticeService.java

@@ -23,7 +23,7 @@ public interface IUserPracticeService extends IService<UserPractice> {
      *
      * @return
      */
-    List<UserPractice> getRecentPractice(String repositoryId);
+    List<UserPractice> getRecentPractice(String repositoryId, String userId);
 
     String submitPractice(UserPracticeDTO dto);
 
@@ -36,4 +36,13 @@ public interface IUserPracticeService extends IService<UserPractice> {
     UserPracticeResultDTO getPracticeResult(String id);
 
     IPage<UserPractice> selectPageList(IPage<UserPractice> page, UserPractice userPractice);
+
+    /**
+     * 最近练习
+     *
+     * @param limit
+     * @param userId
+     * @return
+     */
+    List<UserPractice> listLatestPractice(Integer limit, String userId);
 }

+ 18 - 7
web/src/main/java/com/ynfy/buss/practice/userpractice/service/impl/UserPracticeServiceImpl.java

@@ -19,9 +19,7 @@ import com.ynfy.buss.practice.userpractice.mapper.UserPracticeMapper;
 import com.ynfy.buss.practice.userpractice.service.IUserPracticeService;
 import com.ynfy.buss.practice.userpracticequestion.entity.UserPracticeQuestion;
 import com.ynfy.buss.practice.userpracticequestion.service.IUserPracticeQuestionService;
-import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.exception.JeecgBootException;
-import org.jeecg.common.system.vo.LoginUser;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -51,13 +49,10 @@ public class UserPracticeServiceImpl extends ServiceImpl<UserPracticeMapper, Use
      * @return
      */
     @Override
-    public List<UserPractice> getRecentPractice(String repositoryId) {
-        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
-
+    public List<UserPractice> getRecentPractice(String repositoryId, String userId) {
         Page<UserPractice> page = new Page<UserPractice>(1, 5);
-
         LambdaQueryWrapper<UserPractice> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(UserPractice::getUserId, user.getId()).eq(UserPractice::getRepositoryId, repositoryId)
+        wrapper.eq(UserPractice::getUserId, userId).eq(UserPractice::getRepositoryId, repositoryId)
                 .orderByDesc(UserPractice::getCommitTime);
         IPage<UserPractice> pageList = page(page, wrapper);
         return pageList.getRecords();
@@ -157,4 +152,20 @@ public class UserPracticeServiceImpl extends ServiceImpl<UserPracticeMapper, Use
     public IPage<UserPractice> selectPageList(IPage<UserPractice> page, UserPractice userPractice) {
         return userPracticeMapper.selectPageList(page, userPractice);
     }
+
+
+    /**
+     * 最近练习
+     *
+     * @param limit
+     * @param userId
+     * @return
+     */
+    @Override
+    public List<UserPractice> listLatestPractice(Integer limit, String userId) {
+        LambdaQueryWrapper<UserPractice> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(UserPractice::getUserId, userId).last("LIMIT " + limit)
+                .orderByDesc(UserPractice::getCommitTime);
+        return list(wrapper);
+    }
 }