Compare commits

..

1 Commits

@ -1,383 +1,367 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.coproject</groupId>
<artifactId>math-learning</artifactId>
<version>0.1.4</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<javafx.version>21.0.3</javafx.version>
<!-- 允许通过 -DskipJlink=true 跳过 jlink避免 javafx:run 时误触发 -->
<skipJlink>false</skipJlink>
</properties>
<dependencies>
<!-- JavaFX UI -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
<classifier>win</classifier>
</dependency>
<!-- JSON storage -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.17.1</version>
</dependency>
<!-- Mail sending (Jakarta Mail implementation) -->
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>2.0.1</version>
</dependency>
<!-- Commons Lang for utilities -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<!-- Enable `mvn javafx:run` for local development -->
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>com.coproject.MainApp</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jlink-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<image>${project.build.directory}/jlink-image</image>
<jlinkExecutable>${env.JAVA_HOME}/bin/jlink</jlinkExecutable>
<modulePaths>
<modulePath>${env.JAVA_HOME}/jmods</modulePath>
<modulePath>${project.basedir}/lib/javafx-jmods-21.0.8/javafx-jmods-21.0.8</modulePath>
</modulePaths>
<!-- 仅包含 JDK 与 JavaFX 模块,第三方库不参与 jlink -->
<addModules>javafx.base,javafx.graphics,javafx.controls,javafx.fxml</addModules>
<noHeaderFiles>true</noHeaderFiles>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<skip>${skipJlink}</skip>
</configuration>
<executions>
<execution>
<id>make-jlink-image</id>
<phase>package</phase>
<goals>
<goal>jlink</goal>
</goals>
<configuration>
<!-- 在 execution 级别也应用 skip确保 -DskipJlink=true 生效 -->
<skip>${skipJlink}</skip>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<outputDirectory>${project.build.directory}/dist</outputDirectory>
<archive>
<!-- 使用我们在 antrun 中生成的 manifest 文件,显式包含 lib 下所有依赖 -->
<manifestFile>${project.build.directory}/dist/manifest.mf</manifestFile>
</archive>
</configuration>
<executions>
<execution>
<id>force-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 备用方案:生成 jar-with-dependencies胖包 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<archive>
<manifest>
<mainClass>com.coproject.MainApp</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}-${project.version}</finalName>
<appendAssemblyId>true</appendAssemblyId>
<outputDirectory>${project.build.directory}/dist</outputDirectory>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 生成包含所有依赖的可运行 JAR避免安装版缺失类路径导致启动失败 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<skip>true</skip>
<!-- 将产物写入 dist 并与 finalName 保持一致 -->
<outputFile>${project.build.directory}/dist/${project.build.finalName}.jar</outputFile>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>false</createDependencyReducedPom>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.coproject.MainApp</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.1</version>
<executions>
<execution>
<id>copy-runtime-deps</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dist/lib</outputDirectory>
<includeScope>runtime</includeScope>
<!-- 复制全部运行时依赖,包含 JavaFX win JAR 到 dist/lib -->
</configuration>
</execution>
</executions>
</plugin>
<!-- Prepare external config file: copy and rename smtp.env.example -> data/smtp.env into dist -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>generate-manifest-with-classpath</id>
<phase>prepare-package</phase>
<configuration>
<target>
<!-- 确保 dist 与 dist/lib 目录存在 -->
<mkdir dir="${project.build.directory}/dist"/>
<mkdir dir="${project.build.directory}/dist/lib"/>
<property name="dist.lib" value="${project.build.directory}/dist/lib"/>
<path id="deps.jars">
<fileset dir="${dist.lib}" includes="*.jar"/>
</path>
<pathconvert refid="deps.jars" property="deps.cp" pathsep=" ">
<map from="${project.build.directory}/dist/lib/" to="lib/"/>
<map from="${project.build.directory}/dist/lib\" to="lib/"/>
</pathconvert>
<echo file="${project.build.directory}/dist/manifest.mf">
Manifest-Version: 1.0
Main-Class: com.coproject.MainApp
Class-Path: ${deps.cp}
</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>prepare-smtp-env</id>
<phase>package</phase>
<configuration>
<target>
<mkdir dir="${project.build.directory}/dist/data"/>
<copy file="${project.basedir}/smtp.env.example" tofile="${project.build.directory}/dist/data/smtp.env" overwrite="true"/>
<mkdir dir="${project.build.directory}/dist/data/papers"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>cleanup-dist-jars</id>
<phase>post-package</phase>
<configuration>
<target>
<delete>
<fileset dir="${project.build.directory}/dist" includes="math-learning-*.jar" excludes="${project.build.finalName}.jar"/>
</delete>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>copy-javafx-win</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dist/lib</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/lib/javafx-win</directory>
<includes>
<include>javafx-*-win.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-app-README</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dist</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}</directory>
<includes>
<include>README.md</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-config-guides</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dist</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}</directory>
<includes>
<include>configure_smtp_qq.ps1</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.panteleyev</groupId>
<artifactId>jpackage-maven-plugin</artifactId>
<version>1.7.1</version>
<configuration>
<input>${project.build.directory}/dist</input>
<resourceDir>${project.build.directory}/dist</resourceDir>
<destination>${project.build.directory}/jpackage</destination>
<type>msi</type>
<name>数学学习软件</name>
<vendor>Coproject</vendor>
<appVersion>0.1.4</appVersion>
<winConsole>true</winConsole>
<winDirChooser>true</winDirChooser>
<winMenu>true</winMenu>
<winShortcut>true</winShortcut>
<verbose>true</verbose>
<!-- 与 maven-jar-plugin 输出一致:固定为 artifactId.jar -->
<mainJar>${project.artifactId}.jar</mainJar>
<mainClass>com.coproject.MainApp</mainClass>
<!-- 让启动器包含 dist/lib 下所有依赖 -->
<classPath>lib/*</classPath>
<!-- JavaFX 模块所在路径 -->
<modulePath>app/lib</modulePath>
<!-- 类路径由主 JAR 的 MANIFEST.MF 提供antrun 生成 Class-Path -->
<removeDestination>true</removeDestination>
<!-- 显式添加 JavaFX 模块,避免运行期缺失导致退出码 1 -->
<javaOptions>
<javaOption>--module-path</javaOption>
<javaOption>app/lib</javaOption>
<javaOption>--add-modules</javaOption>
<javaOption>javafx.controls,javafx.fxml</javaOption>
</javaOptions>
<!-- 不强制使用 jlink 镜像,默认使用当前 JDK 的 jpackage -->
</configuration>
<executions>
<execution>
<id>make-installer</id>
<phase>package</phase>
<goals>
<goal>jpackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<!-- 使用 -P no-jlink 强制跳过 jlink某些环境下 -DskipJlink=true 未被采纳) -->
<profile>
<id>no-jlink</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<skipJlink>true</skipJlink>
</properties>
</profile>
</profiles>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.coproject</groupId>
<artifactId>math-learning</artifactId>
<version>0.1.2</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
<javafx.version>21.0.3</javafx.version>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
</properties>
<dependencies>
<!-- JavaFX UI -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
<classifier>win</classifier>
</dependency>
<!-- JSON storage -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.17.1</version>
</dependency>
<!-- Mail sending (Jakarta Mail implementation) -->
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>2.0.1</version>
</dependency>
<!-- Commons Lang for utilities -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
</dependencies>
<build>
<finalName>${artifactId}-${version}</finalName>
<plugins>
<!-- 编译器插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<!-- Enable `mvn javafx:run` for local development -->
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>com.coproject.MainApp</mainClass>
</configuration>
</plugin>
<!-- 生成主 JAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<outputDirectory>${project.build.directory}/dist</outputDirectory>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.coproject.MainApp</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- 复制依赖到 lib 目录 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dist/lib</outputDirectory>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<!-- 复制 JavaFX Windows JAR 和配置文件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>copy-javafx-win</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dist/lib</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/lib/javafx-win</directory>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-config-files</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dist</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}</directory>
<includes>
<include>smtp.env.example</include>
<include>README.md</include>
<include>configure_smtp_qq.ps1</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- 创建数据目录 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>create-data-directories</id>
<phase>package</phase>
<configuration>
<target>
<mkdir dir="${project.build.directory}/dist/data"/>
<mkdir dir="${project.build.directory}/dist/data/papers"/>
<copy file="${project.basedir}/smtp.env.example"
tofile="${project.build.directory}/dist/data/smtp.env"
overwrite="true"/>
<echo file="${project.build.directory}/dist/data/papers/README.txt">试卷存储目录
将生成的试卷PDF文件保存在此目录中。
</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<!-- 自动生成分发包 -->
<execution>
<id>create-distribution</id>
<phase>package</phase>
<configuration>
<target>
<echo>=== 开始生成分发包 ===</echo>
<!-- 创建分发目录 -->
<mkdir dir="${project.build.directory}/数学学习软件-${project.version}"/>
<!-- 生成正确的启动脚本 -->
<echo file="${project.build.directory}/数学学习软件-${project.version}/run.bat">@echo off
chcp 65001 >nul
title 数学学习软件
echo 启动数学学习软件...
REM 检查JAR文件是否存在
if not exist "math-learning-0.1.2.jar" (
echo 错误: 找不到主程序文件 math-learning-0.1.2.jar
echo 请确保所有文件在同一个目录下
pause
exit /b 1
)
REM 检查lib目录是否存在
if not exist "lib" (
echo 错误: 找不到依赖库目录 lib
echo 请确保lib目录存在且完整
pause
exit /b 1
)
REM 运行程序
echo 正在启动程序...
java --module-path "lib" --add-modules javafx.controls,javafx.fxml -jar "math-learning-0.1.2.jar"
REM 如果程序退出,暂停窗口
echo.
echo 程序已退出。
pause
</echo>
<!-- 生成简化版启动脚本 -->
<echo file="${project.build.directory}/数学学习软件-${project.version}/start.bat">@echo off
chcp 65001 >nul
cd /d %~dp0
java --module-path "lib" --add-modules javafx.controls,javafx.fxml -jar "math-learning-0.1.2.jar"
</echo>
<!-- 生成测试脚本 -->
<echo file="${project.build.directory}/数学学习软件-${project.version}/测试运行.bat">@echo off
echo 正在测试程序是否能正常运行...
cd /d %~dp0
if exist "math-learning-0.1.2.jar" (
echo ✓ 找到主程序文件
) else (
echo ✗ 找不到主程序文件
pause
exit /b 1
)
if exist "lib" (
echo ✓ 找到依赖库目录
) else (
echo ✗ 找不到依赖库目录
pause
exit /b 1
)
echo 正在启动程序...
start start.bat
</echo>
<!-- 复制主程序 JAR -->
<copy todir="${project.build.directory}/数学学习软件-${project.version}">
<fileset dir="${project.build.directory}/dist">
<include name="math-learning-${project.version}.jar"/>
<include name="README.md"/>
<include name="smtp.env.example"/>
<include name="configure_smtp_qq.ps1"/>
</fileset>
</copy>
<!-- 复制依赖库 -->
<copy todir="${project.build.directory}/数学学习软件-${project.version}/lib">
<fileset dir="${project.build.directory}/dist/lib"/>
</copy>
<!-- 复制数据目录 -->
<copy todir="${project.build.directory}/数学学习软件-${project.version}/data">
<fileset dir="${project.build.directory}/dist/data"/>
</copy>
<!-- 生成详细使用说明 -->
<echo file="${project.build.directory}/数学学习软件-${project.version}/使用说明.txt">数学学习软件 v${project.version}
=== 基本信息 ===
版本号: ${project.version}
生成时间: ${maven.build.timestamp}
开发者: Coproject 团队
=== 系统要求 ===
- 操作系统: Windows 7/10/11
- Java版本: Java 17 或更高版本
- 内存: 至少 2GB 可用内存
=== 启动方法 ===
推荐使用以下方式启动:
1. 双击运行 run.bat (推荐,有错误提示)
2. 双击 start.bat (简洁版)
3. 双击 测试运行.bat (先检查环境再启动)
=== 功能特点 ===
✓ 小学数学题目生成
✓ 初中数学题目生成(含平方根号)
✓ 高中数学题目生成(含三角函数)
✓ 选择题答题系统
✓ 邮件发送验证码功能
✓ 试卷PDF导出功能
=== 目录说明 ===
math-learning-0.1.2.jar - 主程序文件
lib/ - 程序依赖库(请勿删除或移动)
data/ - 数据存储目录
├── smtp.env - 邮箱配置文件
└── papers/ - 试卷存储目录
run.bat - Windows启动脚本(详细版)
start.bat - Windows启动脚本(简洁版)
测试运行.bat - 环境测试脚本
README.md - 项目说明文档
=== 配置说明 ===
1. 首次运行会自动创建配置文件
2. 邮箱配置请参考 smtp.env.example
3. 生成的试卷保存在 data/papers/ 目录
=== 常见问题 ===
Q: 启动时提示"缺少JavaFX运行时组件"
A: 请确保使用 .bat 文件启动不要直接双击JAR文件
Q: 邮件发送失败
A: 请检查 data/smtp.env 中的邮箱配置
Q: 程序无法启动
A: 请先运行"测试运行.bat"检查环境
=== 技术支持 ===
如有问题请联系开发团队。
注意:请保持所有文件在同一个目录下,不要单独移动文件!
</echo>
<!-- 创建ZIP压缩包 -->
<zip destfile="${project.build.directory}/数学学习软件-${project.version}.zip"
basedir="${project.build.directory}/数学学习软件-${project.version}"/>
<echo>=== 分发包生成完成 ===</echo>
<echo>分发包位置: ${project.build.directory}/数学学习软件-${project.version}.zip</echo>
<echo>目录位置: ${project.build.directory}/数学学习软件-${project.version}/</echo>
<echo> </echo>
<echo>用户运行说明:</echo>
<echo>- 解压ZIP文件到任意位置</echo>
<echo>- 进入"数学学习软件-0.1.2"文件夹</echo>
<echo>- 双击 run.bat 启动程序</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -282,7 +282,7 @@ public class UnifiedQuestionEngine {
static class Elementary extends Base {
public Elementary(Random random, DecimalFormat df) { super(random, df); }
@Override public MathProblem generate() {
int operandCount = random.nextInt(3) + 3; // 3-5
int operandCount = random.nextInt(5) + 1; // 1-5
int[] operands = new int[operandCount];
String[] operators = new String[operandCount - 1];
for (int i = 0; i < operandCount; i++) operands[i] = random.nextInt(100) + 1;
@ -302,54 +302,85 @@ public class UnifiedQuestionEngine {
// ---------- 初中题目生成器 ----------
static class Middle extends Base {
public Middle(Random random, DecimalFormat df) { super(random, df); }
@Override public MathProblem generate() {
// 始终生成 3-5 个操作数;当包含根号时,根号为其中一个或两个项
int operandCount = random.nextInt(3) + 3; // 3-5
boolean includeSqrt = random.nextDouble() < 0.5; // 约半数题含根号
int sqrtCount = includeSqrt ? (1 + random.nextInt(2)) : 0; // 1-2 个根号项
if (sqrtCount > operandCount) sqrtCount = operandCount; // 不超过操作数数量
@Override
public MathProblem generate() {
int operandCount = random.nextInt(5) + 1;
int sqrtCount = 1 + random.nextInt(2); // 1-2个平方/根号项
if (sqrtCount > operandCount) sqrtCount = operandCount;
return buildMathProblem(operandCount, sqrtCount);
}
private MathProblem buildMathProblem(int operandCount, int sqrtCount) {
double[] operands = new double[operandCount];
String[] operators = new String[operandCount - 1];
String[] termTexts = new String[operandCount];
// 随机选择根号项位置
Set<Integer> sqrtPos = new HashSet<>();
while (sqrtPos.size() < sqrtCount) {
sqrtPos.add(random.nextInt(operandCount));
Set<Integer> sqrtPositions = selectSqrtPositions(operandCount, sqrtCount);
buildOperandsAndTerms(operands, termTexts, sqrtPositions);
buildOperators(operators);
String expression = buildExpression(termTexts, operators);
double result = evaluateWithPrecedenceDouble(operands, operators);
return new MathProblem(expression, df.format(result), "初中");
}
private Set<Integer> selectSqrtPositions(int operandCount, int sqrtCount) {
Set<Integer> positions = new HashSet<>();
while (positions.size() < sqrtCount) {
positions.add(random.nextInt(operandCount));
}
return positions;
}
// 构造各项
for (int i = 0; i < operandCount; i++) {
if (sqrtPos.contains(i)) {
// 使用完全平方数,确保计算结果为整数,便于初中题目
int base = random.nextInt(9) + 2; // 2-10确保 √n 的 n ≤ 100
int square = base * base;
operands[i] = Math.sqrt(square); // = base
termTexts[i] = "√" + square;
private void buildOperandsAndTerms(double[] operands, String[] termTexts, Set<Integer> sqrtPositions) {
for (int i = 0; i < operands.length; i++) {
if (sqrtPositions.contains(i)) {
buildPowerOrSqrtTerm(operands, termTexts, i);
} else {
int val = random.nextInt(100) + 1; // 1-100 的常数
operands[i] = val;
termTexts[i] = String.valueOf(val);
buildNormalTerm(operands, termTexts, i);
}
}
}
private void buildPowerOrSqrtTerm(double[] operands, String[] termTexts, int index) {
boolean useSquare = random.nextBoolean();
int base = random.nextInt(9) + 2; // 2-10
// 构造运算符(保持简单四则)
if (useSquare) {
operands[index] = base * base;
termTexts[index] = base + "²";
} else {
int square = base * base;
operands[index] = base;
termTexts[index] = "√" + square;
}
}
private void buildNormalTerm(double[] operands, String[] termTexts, int index) {
int val = random.nextInt(100) + 1;
operands[index] = val;
termTexts[index] = String.valueOf(val);
}
private void buildOperators(String[] operators) {
String[] ops = {"+", "-", "*", "/"};
for (int i = 0; i < operandCount - 1; i++) {
for (int i = 0; i < operators.length; i++) {
operators[i] = ops[random.nextInt(ops.length)];
}
}
// 拼接表达式文本
private String buildExpression(String[] termTexts, String[] operators) {
StringBuilder expr = new StringBuilder();
for (int i = 0; i < operandCount; i++) {
for (int i = 0; i < termTexts.length; i++) {
expr.append(termTexts[i]);
if (i < operandCount - 1) expr.append(" ").append(operators[i]).append(" ");
if (i < operators.length) {
expr.append(" ").append(operators[i]).append(" ");
}
}
double result = evaluateWithPrecedenceDouble(operands, operators);
return new MathProblem(expr.toString(), df.format(result), "初中");
return expr.toString();
}
}
@ -357,8 +388,8 @@ public class UnifiedQuestionEngine {
static class High extends Base {
public High(Random random, DecimalFormat df) { super(random, df); }
@Override public MathProblem generate() {
// 生成包含三角函数与常数混合运算的表达式(3-5个操作数至少包含一个三角函数
int operandCount = random.nextInt(3) + 3; // 3-5
// 生成包含三角函数与常数混合运算的表达式(1-5个操作数至少包含一个三角函数
int operandCount = random.nextInt(5) + 1; // 1-5
int trigIndex = random.nextInt(operandCount);
double[] operands = new double[operandCount];
@ -413,6 +444,9 @@ public class UnifiedQuestionEngine {
// 混合三角表达式(包含常数与一个三角项)选项符号化
private ChoiceQuestion toMixedTrigSumChoice(MathProblem p) {
String expr = p.getExpression();
if (isPureTrigFunction(expr)) {
return createPureTrigChoiceQuestion(expr, p);
}
String[] tokens = expr.split(" ");
// 解析操作数与运算符
@ -522,6 +556,44 @@ public class UnifiedQuestionEngine {
int correctIndex = options.indexOf(correct);
return new ChoiceQuestion(p.getExpression() + " = ?", options, correctIndex);
}
// 判断是否为纯三角函数题目
private boolean isPureTrigFunction(String expr) {
return expr.matches("^(sin|cos|tan)\\d+$");
}
// 创建纯三角函数选择题
// 创建纯三角函数选择题
private ChoiceQuestion createPureTrigChoiceQuestion(String expr, MathProblem p) {
String func = expr.substring(0, 3);
int angle = Integer.parseInt(expr.substring(3));
String trigSym = getSymbolicTrig(func, angle);
// 正确答案
String correct = trigSym;
// 生成干扰项 - 只使用符号形式,避免数值
Set<String> optionsSet = new LinkedHashSet<>();
optionsSet.add(correct);
String[] symPool = {"0", "1/2", "√2/2", "√3/2", "1", "1/√3", "√3"};
for (String sym : symPool) {
if (optionsSet.size() >= 4) break;
if (!sym.equals(trigSym)) {
optionsSet.add(sym);
}
}
// 确保选项数量为4个
while (optionsSet.size() < 4) {
optionsSet.add("1"); // 或其他默认值
}
List<String> options = new ArrayList<>(optionsSet);
Collections.shuffle(options, random);
int correctIndex = options.indexOf(correct);
return new ChoiceQuestion(expr + " = ?", options, correctIndex);
}
// 解析常见符号三角值为数值(仅用于没有根号的情况)
private double parseSymbolicToDouble(String s) {

@ -1,3 +0,0 @@
Manifest-Version: 1.0
Main-Class: com.coproject.MainApp
Class-Path: lib/commons-lang3-3.14.0.jar lib/jackson-annotations-2.17.1.jar lib/jackson-core-2.17.1.jar lib/jackson-databind-2.17.1.jar lib/jakarta.activation-2.0.1.jar lib/jakarta.mail-2.0.1.jar lib/javafx-base-21.0.3-win.jar lib/javafx-base-21.0.3.jar lib/javafx-controls-21.0.3-win.jar lib/javafx-controls-21.0.3.jar lib/javafx-fxml-21.0.3-win.jar lib/javafx-graphics-21.0.3-win.jar lib/javafx-graphics-21.0.3.jar

Binary file not shown.

@ -1,65 +0,0 @@
大模型修改代码一览表
项目:数学学习软件
日期2025-10-12
概述
- 本表记录使用大模型协助完成的代码修改,包含目的、文件位置、变更摘要、影响范围与验证方式,便于作业提交与审阅。
1) 声明 java.desktop 模块
- 文件src/main/java/module-info.java
- 目的:使 `java.awt.Desktop` 可见,修复编译错误
- 变更:添加 `requires java.desktop;`
- 验证:`mvn -q javafx:run` 执行成功,应用可正常运行
2) 后端长方法重构(保证功能不变)
- MailService.send约60行 → 精简至40行以内
- 文件src/main/java/com/coproject/service/MailService.java
- 变更摘要:提取为 `trySendViaSmtp()`、`buildSmtpProperties()`、`buildMessage()` 三个私有方法;保持 SMTP 发送与失败时写入 `outbox.txt` 的回退逻辑不变
- 验证:`mvn -q -DskipTests compile` 成功
- JsonStorage 构造器约51行 → 精简至40行以内
- 文件src/main/java/com/coproject/storage/JsonStorage.java
- 变更摘要:拆分为 `initUserDir()`、`migrateLegacyData()`、`initUserJson()`、`initPapersJson()`、`initPapersTextFile()`、`initPapersDirs()`、`initUserMapCsv()` 等私有方法;保持初始化与迁移行为一致
- 验证:编译成功
- JsonStorage.appendPaperText约48行 → 精简至40行以内
- 文件src/main/java/com/coproject/storage/JsonStorage.java
- 变更摘要:提取 `buildPaperText()` 与 `appendQuestionBlock()`;严格保留文本输出格式
- 验证:编译成功
- JsonStorage.exportPaperTextFile>40行 → 精简至40行以内
- 文件src/main/java/com/coproject/storage/JsonStorage.java
- 变更摘要:提取 `buildExportFileName()`、`buildExportText()`、`appendExportQuestionBlock()`;严格保留导出文本格式
- 验证:编译成功
3) 题目生成规则统一(各学段操作数与取值范围)
- 文件src/main/java/com/coproject/service/UnifiedQuestionEngine.java
- 目的:统一各学段题目复杂度与范围,满足作业要求
- 变更摘要:
- 小学:操作数数量统一为 15各操作数值在 1100
- 初中:操作数数量统一为 15常数在 1100根号项使用完全平方数且 `n ≤ 100`(基数 210
- 高中:操作数数量统一为 15常数在 1100保留三角函数题干选项构造逻辑
- 移除旧过滤:删除对“仅根号项”题干的拦截(`UnifiedQuestionEngine.generateChoiceQuestion` 与 `QuestionService.generate`)以符合 15 操作数的新规则
- 影响:题干与选项构造更一致,边界值更安全
- 验证:`mvn -q -DskipTests compile` 成功
4) UI 校验与提示(题量必须为 1030 的正整数)
- 文件src/main/resources/fxml/grade_select.fxml
- 变更输入框占位改为“输入10-30的正整数”新增可见提示“范围10-30”
- 文件src/main/java/com/coproject/controller/GradeSelectController.java
- 变更:初始化时设置 Tooltip 与提示文案;`onStart()` 中新增严格区间校验(非法输入直接提示并阻止进入答题)
- 调整移除旧的“超过50自动设为50”的上限保护改为必须满足 1030 区间
- 验证:编译成功
5) 运行与打包(说明未改动)
- 运行:`mvn -q javafx:run`
- 编译:`mvn -q -DskipTests compile`
- 打包:`mvn -q -DskipTests package`(如需 MSI 打包,参见 README 与 jpackage 配置)
影响范围与收益
- 统一题目生成规则,提升一致性与可控性
- 强化 UI 输入校验,降低错误操作与异常风险
- 重构后端长方法,提高可读性与可维护性,便于后续扩展
回滚与兼容
- 所有变更均为向后兼容的内部重构或参数范围调整;如需回滚,可逐文件恢复变更前版本即可(不涉及数据库结构变更)。
备注
- 非后端的测试/演示方法(如 SimpleLauncher、ConsoleTest、TestApp 中的调试方法)未纳入本次重构范围。
Loading…
Cancel
Save