feat(lessonplan): 实现基于AI的学案自动生成与管理功能

- 新增DifyArticleClient工具类,实现基于Dify API的对话与文本生成功能
- 创建LessonPlansService接口及其实现,实现学案按天生成及存储
- 设计LessonPlansDO和StudentLessonPlansDO数据对象及对应MyBatis映射和数据库操作
- 扩展VocabularyBankDO实体及Mapper,支持查询单元词汇和学生未掌握词汇
- 利用deepoove-poi模板技术生成Word格式的学习计划文档,包含词汇、复习和练习
- 开发StringToPlanMapUtil工具类,解析AI返回结果为结构化学案内容
- 新增JUnit测试用例验证AI对话功能及学案生成逻辑正确性
- 更新Spring Boot配置,添加AI接口地址及密钥等参数
- 在前端Vue项目中新建学案页面,路由配置及导航菜单支持学案访问
This commit is contained in:
lbw
2025-12-16 19:08:58 +08:00
parent d027c9c7e6
commit 7f41036193
26 changed files with 831 additions and 5 deletions

View File

@@ -0,0 +1,50 @@
package com.yinlihupo.enlish.service.ai;
import com.yinlihupo.enlish.service.utils.DifyArticleClient;
import com.yinlihupo.enlish.service.utils.StringToPlanMapUtil;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.IOException;
import java.util.Map;
@SpringBootTest
public class AITest {
@Resource
private DifyArticleClient client;
@Test
public void test1() throws IOException {
try {
// 2. 第一轮对话 (没有 conversation_id)
System.out.println("--- Round 1 ---");
String userId = "user-1001";
DifyArticleClient.DifyResponse response1 = client.sendChat("ruler, pencil, eraser, crayon, bag, pen, book, red, green, yellow, blue, face, ear, eye, nose, mouth, duck, pig, cat, bear, dog, elephant, monkey, bird, tiger, panda, bread, juice, egg, milk", userId, null);
//System.out.println("AI 回复: " + response1.getAnswer());
System.out.println("当前会话ID: " + response1.getConversationId());
// // 3. 第二轮对话 (传入上一轮的 conversation_id 以保持记忆)
// System.out.println("\n--- Round 2 ---");
// // 注意这里传入了 response1.getConversationId()
// DifyClient.DifyResponse response2 = client.sendChat("我刚才说了我叫什么?", userId, response1.getConversationId());
//
// System.out.println("AI 回复: " + response2.getAnswer());
System.out.println("\n--- Round 2 ---");
Map<String, String> stringStringMap = StringToPlanMapUtil.parseTextToMap(response1.getAnswer());
System.out.println(stringStringMap.get("Title"));
System.out.println(stringStringMap.get("The Passage"));
System.out.println(stringStringMap.get("Quiz"));
System.out.println(stringStringMap.get("Answer Key & Explanation"));
System.out.println(stringStringMap.get("Full Translation"));
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,28 @@
package com.yinlihupo.enlish.service.mapper;
import com.yinlihupo.enlish.service.domain.dataobject.LessonPlansDO;
import com.yinlihupo.enlish.service.domain.mapper.LessonPlansDOMapper;
import com.yinlihupo.framework.common.util.JsonUtils;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.Map;
@SpringBootTest
public class PlanTest {
@Resource
private LessonPlansDOMapper lessonPlansDOMapper;
@Test
public void test() throws Exception {
LessonPlansDO lessonPlansDO = lessonPlansDOMapper.selectById(21);
Map<String, Object> stringObjectMap = JsonUtils.parseMap(lessonPlansDO.getContentDetails(), String.class, Object.class);
for (Map.Entry<String, Object> entry : stringObjectMap.entrySet()) {
System.out.println(entry.getKey());
System.out.println(entry.getValue());
System.out.println("------------------------");
}
}
}

View File

@@ -0,0 +1,18 @@
package com.yinlihupo.enlish.service.service.plan;
import com.yinlihupo.enlish.service.service.LessonPlansService;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class PlanTest {
@Resource
private LessonPlansService lessonPlansService;
@Test
public void test() {
lessonPlansService.generateLessonPlans(2, 146);
}
}