Skip to content

Commit

Permalink
Merge pull request #8 from besscroft/dev
Browse files Browse the repository at this point in the history
✨新增错题复习功能
  • Loading branch information
besscroft authored Sep 13, 2023
2 parents 454ad36 + 59a44c3 commit 3320b78
Show file tree
Hide file tree
Showing 25 changed files with 527 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public CommonResult<Book> getWord() {
return CommonResult.success(bookService.getWord());
}

@GetMapping("/getWorkWord")
@Operation(summary = "获取错题本单个单词")
public CommonResult<Book> getWorkWord() {
return CommonResult.success(bookService.getWorkWord());
}

@GetMapping("/getWordList")
@Operation(summary = "获取单词列表")
public CommonResult<List<Book>> getWordList() {
Expand All @@ -53,4 +59,11 @@ public CommonResult<Void> actions(@RequestBody @Valid ActionsParam param) {
return CommonResult.success(MessageConstants.SUCCESS);
}

@PostMapping("/failActions")
@Operation(summary = "错题本单词反馈接口")
public CommonResult<Void> failActions(@RequestBody @Valid ActionsParam param) {
bookService.failActions(param);
return CommonResult.success(MessageConstants.SUCCESS);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ UserWrongWord selectByUserIdAndBookIdAndWordId(@Param("userId") Long userId,
@Param("bookId") String bookId,
@Param("wordId") Long wordId);

/**
* 查询用户错题本单个单词 id
* @param userId 用户 id
* @param bookId 词典 id
* @return 单词 id
*/
Long selectWordIdByUserIdAndBookId(@Param("userId") Long userId,
@Param("bookId") String bookId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public interface BookService {
*/
Book getWord();

/**
* 获取当前用户活动词典对应的错题本的下一个单词信息
* @return 单词信息
*/
Book getWorkWord();

/**
* 获取当前用户活动词典的单词学习列表
* @return 单词信息列表
Expand All @@ -38,4 +44,10 @@ public interface BookService {
*/
void actions(ActionsParam param);

/**
* 错题本行为处理
* @param param 参数
*/
void failActions(ActionsParam param);

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import dev.heming.enstudy.mongo.service.BookService;
import dev.heming.enstudy.common.param.book.GetBookParam;
import dev.heming.enstudy.service.UserBookDictService;
import dev.heming.enstudy.service.WordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.MongoTemplate;
Expand Down Expand Up @@ -43,6 +44,7 @@ public class BookServiceImpl implements BookService {
private final UserBookDictService userBookDictService;
private final UserWorkActionsMapper userWorkActionsMapper;
private final WordMapper wordMapper;
private final WordService wordService;
private final UserBookDictMapper userBookDictMapper;
private final UserWrongWordMapper userWrongWordMapper;
private final RedisTemplate<String, Object> redisTemplate;
Expand All @@ -61,22 +63,22 @@ public Book getBook(GetBookParam param) {

@Override
public Book getWord() {
// TODO 优化
long userId = StpUtil.getLoginIdAsLong();
UserBookDictVo userDict = userBookDictService.getUserDict();
Assert.notNull(userDict, "还未选择词典!");
UserWorkActions actions = userWorkActionsMapper.selectByUserIdAndBookId(userId, userDict.getBookId());
Assert.notNull(actions, "未生成学习数据,请联系管理员!");
Word word = wordMapper.selectById(actions.getWordId());
Assert.notNull(word, "单词数据不存在,请联系管理员!");
Query query = new Query(
Criteria
.where("bookId").is(userDict.getBookId())
.and("wordRank").is(word.getWordRank())
.and("headWord").is(word.getHeadWord())
);
Book result = mongoTemplate.findOne(query, Book.class);
return result;
return wordService.getWordByWordIdAndBookId(actions.getWordId(), userDict.getBookId());
}

@Override
public Book getWorkWord() {
long userId = StpUtil.getLoginIdAsLong();
UserBookDictVo userDict = userBookDictService.getUserDict();
Assert.notNull(userDict, "还未选择词典!");
Long wordId = userWrongWordMapper.selectWordIdByUserIdAndBookId(userId, userDict.getBookId());
Assert.notNull(wordId, "当前错题本暂无错题!");
return wordService.getWordByWordIdAndBookId(wordId, userDict.getBookId());
}

@Override
Expand Down Expand Up @@ -121,7 +123,7 @@ public void actions(ActionsParam param) {
userWrongWord.setUserId(userId);
userWrongWord.setBookId(param.getBookId());
userWrongWord.setWordId(word.getId());
userWrongWord.setFailCount(0);
userWrongWord.setFailCount(1);
userWrongWordMapper.insert(userWrongWord);
} else {
wrongWord.setFailCount(wrongWord.getFailCount() + 1);
Expand All @@ -136,4 +138,17 @@ public void actions(ActionsParam param) {
redisTemplate.delete(CacheConstants.TODAY + userId);
}

@Override
@Transactional(rollbackFor = Exception.class)
public void failActions(ActionsParam param) {
long userId = StpUtil.getLoginIdAsLong();
Word word = wordMapper.selectByWordJsonId(param.getWordJsonId());
UserWrongWord wrongWord = userWrongWordMapper.selectByUserIdAndBookIdAndWordId(userId, param.getBookId(), word.getId());
if (Objects.equals(param.getState(), 0)) {
wrongWord.setFailCount(wrongWord.getFailCount() + 1);
}
wrongWord.setUpdateTime(LocalDateTime.now());
userWrongWordMapper.updateById(wrongWord);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.heming.enstudy.service;

import com.baomidou.mybatisplus.extension.service.IService;
import dev.heming.enstudy.common.entity.Book;
import dev.heming.enstudy.common.entity.Word;
import dev.heming.enstudy.common.vo.console.ConsoleVo;

Expand Down Expand Up @@ -34,4 +35,12 @@ public interface WordService extends IService<Word> {
*/
ConsoleVo getConsoleInfo();

/**
* 获取单词
* @param wordId 单词表 id
* @param bookId 词典 id
* @return 单词数据
*/
Book getWordByWordIdAndBookId(Long wordId, String bookId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import dev.heming.enstudy.common.constant.CacheConstants;
import dev.heming.enstudy.common.entity.Book;
import dev.heming.enstudy.common.entity.Word;
import dev.heming.enstudy.common.vo.console.ConsoleVo;
import dev.heming.enstudy.mapper.BookDictMapper;
Expand All @@ -11,8 +12,12 @@
import dev.heming.enstudy.service.WordService;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;
import java.util.Optional;
Expand All @@ -27,6 +32,7 @@
@RequiredArgsConstructor
public class WordServiceImpl extends ServiceImpl<WordMapper, Word> implements WordService {

private final MongoTemplate mongoTemplate;
private final UserMapper userMapper;
private final BookDictMapper bookDictMapper;
private final RedisTemplate<String, Object> redisTemplate;
Expand Down Expand Up @@ -58,4 +64,18 @@ public ConsoleVo getConsoleInfo() {
);
}

@Override
public Book getWordByWordIdAndBookId(Long wordId, String bookId) {
// TODO 优化
Word word = this.baseMapper.selectById(wordId);
Assert.notNull(word, "单词数据不存在,请联系管理员!");
Query query = new Query(
Criteria
.where("bookId").is(bookId)
.and("wordRank").is(word.getWordRank())
.and("headWord").is(word.getHeadWord())
);
return mongoTemplate.findOne(query, Book.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
user_id = #{userId}
AND
book_id = #{bookId}
AND
state = 0
ORDER BY state, update_time
LIMIT 1
</select>

Expand Down
15 changes: 15 additions & 0 deletions heming-system/src/main/resources/mapper/UserWrongWordMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,19 @@
word_id =#{wordId}
</select>

<select id="selectWordIdByUserIdAndBookId" resultType="java.lang.Long">
SELECT
word_id
FROM
enstudy_user_wrong_word
WHERE
del = 1
AND
user_id = #{userId}
AND
book_id = #{bookId}
ORDER BY update_time, create_time
LIMIT 1
</select>

</mapper>
10 changes: 10 additions & 0 deletions heming-web/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,14 @@ html.dark {
font-style: normal;
font-display: swap;
}
.page-enter-active,
.page-leave-active {
transition: all 0.4s;
}
.page-enter-from,
.page-leave-to {
opacity: 0;
filter: blur(1rem);
}
</style>
3 changes: 2 additions & 1 deletion heming-web/components/Work.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
const nuxtApp = useNuxtApp()
const router = useRouter()
const wrongBook = ref({})
Expand Down Expand Up @@ -34,7 +35,7 @@ onMounted(async () => {

<v-card-text flex items-center>
<p w-full>{{ wrongBook.count || 0 }} 题</p>
<v-btn>
<v-btn @click="router.push('/practise')">
复习
</v-btn>
</v-card-text>
Expand Down
2 changes: 1 addition & 1 deletion heming-web/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
</script>

<template>
<div>
<div h-full>
<slot />
</div>
</template>
71 changes: 38 additions & 33 deletions heming-web/layouts/learn.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { breakpointsTailwind, useBreakpoints } from '@vueuse/core'
const router = useRouter()
const breakpoints = useBreakpoints(breakpointsTailwind)
const smAndLarger = breakpoints.greaterOrEqual('sm')
const choiceLoading = ref<boolean>(false)
Expand All @@ -12,39 +13,43 @@ const handleChoiceLoading = (val: boolean) => {
</script>

<template>
<Header />
<div v-if="smAndLarger" p2 grid sm:px16 md:px20 lg:24 grid-cols-1 gap-4 lg:grid-cols-3 lg:gap-8>
<Today />
<Dictionary :choiceLoading="choiceLoading" @handleChoiceLoading="handleChoiceLoading" />
<Work />
</div>
<div sm:hidden p2>
<v-card>
<v-tabs
v-model="tab"
color="deep-purple-accent-4"
align-tabs="center"
>
<v-tab :value="1">今日概览</v-tab>
<v-tab :value="2">单词进度</v-tab>
<v-tab :value="3">错题本</v-tab>
</v-tabs>
<v-window v-model="tab">
<v-window-item :value="1">
<Today />
</v-window-item>
<v-window-item :value="2">
<Dictionary :choiceLoading="choiceLoading" @handleChoiceLoading="handleChoiceLoading" />
</v-window-item>
<v-window-item :value="3">
<Work />
</v-window-item>
</v-window>
</v-card>
</div>
<div p-2 w-full v-if="!choiceLoading">
<slot />
</div>
<v-app>
<div v-if="router.currentRoute.value.path === '/learn'">
<Header />
<div v-if="smAndLarger" p2 grid sm:px16 md:px20 lg:24 grid-cols-1 gap-4 lg:grid-cols-3 lg:gap-8>
<Today />
<Dictionary :choiceLoading="choiceLoading" @handleChoiceLoading="handleChoiceLoading" />
<Work />
</div>
<div sm:hidden p2>
<v-card>
<v-tabs
v-model="tab"
color="deep-purple-accent-4"
align-tabs="center"
>
<v-tab :value="1">今日概览</v-tab>
<v-tab :value="2">单词进度</v-tab>
<v-tab :value="3">错题本</v-tab>
</v-tabs>
<v-window v-model="tab">
<v-window-item :value="1">
<Today />
</v-window-item>
<v-window-item :value="2">
<Dictionary :choiceLoading="choiceLoading" @handleChoiceLoading="handleChoiceLoading" />
</v-window-item>
<v-window-item :value="3">
<Work />
</v-window-item>
</v-window>
</v-card>
</div>
</div>
<div w-full v-if="!choiceLoading">
<slot />
</div>
</v-app>
</template>

<style scoped>
Expand Down
1 change: 1 addition & 0 deletions heming-web/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export default defineNuxtConfig({
{ name: 'apple-mobile-web-app-status-bar-style', content: 'black-translucent' },
],
},
pageTransition: { name: 'page', mode: 'out-in' },
},

pwa,
Expand Down
1 change: 1 addition & 0 deletions heming-web/pages/[...all].vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const router = useRouter()
definePageMeta({
layout: 'layout',
pageTransition: false,
})
</script>

Expand Down
Loading

0 comments on commit 3320b78

Please sign in to comment.