发卷 2025年4月18日15:48:40
parent
36e31ee2d8
commit
b2e4912fce
|
|
@ -1,6 +1,8 @@
|
|||
package com.zhangmeng.online.exam.ui.api;
|
||||
|
||||
import com.zhangmeng.online.exam.ui.utils.ApiUtils;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import javafx.stage.Stage;
|
||||
|
|
@ -32,4 +34,5 @@ public interface DataLoad {
|
|||
List<MenuItem> getContextMenu();
|
||||
|
||||
ApiUtils.DataView searchData(Map<String, Object> searchText, int pageNum, int pageSize);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,180 @@
|
|||
package com.zhangmeng.online.exam.ui.api.model;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.zhangmeng.online.exam.ui.api.DataLoad;
|
||||
import com.zhangmeng.online.exam.ui.utils.AlertUtils;
|
||||
import com.zhangmeng.online.exam.ui.utils.ApiUtils;
|
||||
import com.zhangmeng.online.exam.ui.utils.HttpUtils;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author zm
|
||||
* @date 2025/3/20 16:31
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class ExamDataLoad {
|
||||
public class ExamDataLoad implements DataLoad {
|
||||
|
||||
@Override
|
||||
public ApiUtils.DataView loadData(Integer pageNum, Integer pageSize) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setForm(Parent view) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parent getForm() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> saveForm(Map<String, Object> map) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteData(String id) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editData(String s, Stage stage) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateData(String id, String name, String oldValue, String newValue) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuItem> getContextMenu() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiUtils.DataView searchData(Map<String, Object> searchText, int pageNum, int pageSize) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ApiUtils.DataView loadPaperData(int pageNum, int pageSize){
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("pageNum", pageNum);
|
||||
params.put("pageSize", pageSize);
|
||||
|
||||
String userListData = HttpUtils.GET(ApiUtils.API_URL + "/exam/user/list", params);
|
||||
JSONObject jsonObject = JSON.parseObject(userListData);
|
||||
JSONArray data = jsonObject.getJSONArray("data");
|
||||
int total = jsonObject.getIntValue("total");
|
||||
List<Map<String, SimpleStringProperty>> userMapList = new ArrayList<>();
|
||||
|
||||
for (Object datum : data) {
|
||||
JSONObject user = (JSONObject) datum;
|
||||
Map<String, SimpleStringProperty> userMap = new HashMap<>();
|
||||
userMap.put("序号", new SimpleStringProperty(user.getString("id")));
|
||||
userMap.put("用户名", new SimpleStringProperty(user.getString("username")));
|
||||
userMap.put("手机号码", new SimpleStringProperty(user.getString("phone")));
|
||||
userMap.put("电子邮箱", new SimpleStringProperty(user.getString("email")));
|
||||
userMap.put("角色", new SimpleStringProperty(user.getString("type")));
|
||||
userMap.put("id", new SimpleStringProperty(user.getString("id")));
|
||||
userMapList.add(userMap);
|
||||
}
|
||||
|
||||
ApiUtils.DataView dataView = new ApiUtils.DataView(Arrays.asList("序号", "用户名", "手机号码", "电子邮箱", "角色"), userMapList).setDataLoad(this).setPageNum(pageNum).setPageSize(pageSize).setTotal(total);
|
||||
dataView.setDataLoad(this);
|
||||
|
||||
return dataView;
|
||||
}
|
||||
|
||||
public ApiUtils.DataView loadPaperData(Map<String, Object> context, int pageNum, int pageSize){
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("pageNum", pageNum);
|
||||
params.put("pageSize", pageSize);
|
||||
params.put("paperId", context.get("id"));
|
||||
String userListData = HttpUtils.GET(ApiUtils.API_URL + "/exam/user/list", params);
|
||||
JSONObject jsonObject = JSON.parseObject(userListData);
|
||||
JSONArray data = jsonObject.getJSONArray("data");
|
||||
int total = jsonObject.getIntValue("total");
|
||||
List<Map<String, SimpleStringProperty>> userMapList = new ArrayList<>();
|
||||
|
||||
for (Object datum : data) {
|
||||
JSONObject user = (JSONObject) datum;
|
||||
Map<String, SimpleStringProperty> userMap = new HashMap<>();
|
||||
userMap.put("序号", new SimpleStringProperty(user.getString("id")));
|
||||
userMap.put("用户名", new SimpleStringProperty(user.getString("username")));
|
||||
userMap.put("手机号码", new SimpleStringProperty(user.getString("phone")));
|
||||
userMap.put("电子邮箱", new SimpleStringProperty(user.getString("email")));
|
||||
userMap.put("角色", new SimpleStringProperty(user.getString("type")));
|
||||
userMap.put("id", new SimpleStringProperty(user.getString("id")));
|
||||
userMapList.add(userMap);
|
||||
}
|
||||
|
||||
ApiUtils.DataView dataView = new ApiUtils.DataView(Arrays.asList("序号", "用户名", "手机号码", "电子邮箱", "角色"), userMapList).setDataLoad(this).setPageNum(pageNum).setPageSize(pageSize).setTotal(total);
|
||||
dataView.setDataLoad(this);
|
||||
|
||||
return dataView;
|
||||
}
|
||||
|
||||
public ApiUtils.DataView searchPaperData(String searchText, int pageNum, int pageSize){
|
||||
return null;
|
||||
}
|
||||
|
||||
public ApiUtils.DataView loadChoosePaperData(Map<String, Object> context, Integer pageNum, Integer pageSize){
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("pageNum", pageNum.toString());
|
||||
params.put("pageSize", pageSize.toString());
|
||||
params.put("paperId", context.get("id"));
|
||||
String userListData = HttpUtils.GET(ApiUtils.API_URL + "/exam/user/choose/list", params);
|
||||
JSONObject jsonObject = JSON.parseObject(userListData);
|
||||
JSONArray data = jsonObject.getJSONArray("data");
|
||||
int total = jsonObject.getIntValue("total");
|
||||
List<Map<String, SimpleStringProperty>> userMapList = new ArrayList<>();
|
||||
for (Object datum : data) {
|
||||
JSONObject user = (JSONObject) datum;
|
||||
Map<String, SimpleStringProperty> userMap = new HashMap<>();
|
||||
|
||||
userMap.put("序号", new SimpleStringProperty(user.getString("id")));
|
||||
userMap.put("用户名", new SimpleStringProperty(user.getString("username")));
|
||||
userMap.put("手机号码", new SimpleStringProperty(user.getString("phone")));
|
||||
userMap.put("电子邮箱", new SimpleStringProperty(user.getString("email")));
|
||||
userMap.put("角色", new SimpleStringProperty(user.getString("type")));
|
||||
userMap.put("id", new SimpleStringProperty(user.getString("id")));
|
||||
|
||||
userMapList.add(userMap);
|
||||
}
|
||||
|
||||
ApiUtils.DataView dataView = new ApiUtils.DataView(Arrays.asList("序号", "用户名", "手机号码", "电子邮箱", "角色"), userMapList).setDataLoad(this).setPageNum(pageNum).setPageSize(pageSize).setTotal(total);
|
||||
dataView.setDataLoad(this);
|
||||
|
||||
return dataView;
|
||||
|
||||
}
|
||||
|
||||
public void commitChoosePaper(Map<String, Object> context, ObservableList<Map<String, SimpleStringProperty>> chooseTableData){
|
||||
|
||||
String id = context.get("id").toString();
|
||||
List<String> ids = chooseTableData.stream().map(chooseTableDatum -> chooseTableDatum.get("id").get()).toList();
|
||||
Map<String, Object> map = Map.of("id", id, "ids", JSONObject.toJSONString(ids));
|
||||
String result = HttpUtils.POST(ApiUtils.API_URL + "/exam/choosePaper/save", map);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
if (jsonObject.getIntValue("code") == 200) {
|
||||
AlertUtils.alert_msg("保存成功!");
|
||||
} else {
|
||||
AlertUtils.alert_warning("保存失败!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
package com.zhangmeng.online.exam.ui.components;
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.Region;
|
||||
|
||||
/**
|
||||
* @author zm
|
||||
* @date 2025/3/20 11:26
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class ExamResultHeaderComponent extends HBox {
|
||||
|
||||
private SimpleStringProperty examCount = new SimpleStringProperty("试题数量:0");//试题数量
|
||||
|
||||
private Button commitBtn;//提交按钮
|
||||
|
||||
public ExamResultHeaderComponent(double spacing) {
|
||||
super();
|
||||
this.setSpacing(spacing);
|
||||
Label label = new Label("");
|
||||
label.setPadding(new Insets(5, 0, 0, 0));
|
||||
label.textProperty().bindBidirectional(examCount);
|
||||
|
||||
commitBtn = new Button("提交");
|
||||
this.setPadding(new Insets(0, 20, 0, 0));
|
||||
|
||||
// 创建一个占位填充区域(关键修改)
|
||||
Region spacer = new Region();
|
||||
HBox.setHgrow(spacer, Priority.ALWAYS); // 允许区域横向扩展
|
||||
|
||||
this.getChildren().add(label);
|
||||
this.getChildren().add(spacer);
|
||||
this.getChildren().add(commitBtn);
|
||||
|
||||
}
|
||||
|
||||
public Button getCommitBtn() {
|
||||
return commitBtn;
|
||||
}
|
||||
|
||||
public void setCommitBtn(Button commitBtn) {
|
||||
this.commitBtn = commitBtn;
|
||||
}
|
||||
|
||||
public String getExamCount() {
|
||||
return examCount.get();
|
||||
}
|
||||
|
||||
public SimpleStringProperty examCountProperty() {
|
||||
return examCount;
|
||||
}
|
||||
|
||||
public void setExamCount(String examCount) {
|
||||
this.examCount.set(examCount);
|
||||
}
|
||||
}
|
||||
|
|
@ -60,20 +60,9 @@ public class SendPaperComponent extends SplitPane {
|
|||
//已选题目列表
|
||||
private final ObservableList<Map<String, SimpleStringProperty>> chooseTable_data = FXCollections.observableArrayList();
|
||||
|
||||
private SimpleIntegerProperty SINGLE_CHOICE_SCORE = new SimpleIntegerProperty();//单选题分数
|
||||
private SimpleIntegerProperty examCount = new SimpleIntegerProperty();//试题数
|
||||
|
||||
private SimpleIntegerProperty MULTIPLE_CHOICE_SCORE = new SimpleIntegerProperty();//多选题分数
|
||||
|
||||
private SimpleIntegerProperty JUDGMENT_SCORE = new SimpleIntegerProperty();//判断题分数
|
||||
|
||||
private SimpleIntegerProperty NUMERICAL_SCORE = new SimpleIntegerProperty();//计算题分数
|
||||
|
||||
private SimpleIntegerProperty SHORT_ANSWER_SCORE = new SimpleIntegerProperty();//简答题分数
|
||||
private SimpleIntegerProperty Fill_IN_THE_BLANKS = new SimpleIntegerProperty();//填空题分数
|
||||
|
||||
private SimpleIntegerProperty ANSWER_SCORE = new SimpleIntegerProperty();//答题总分
|
||||
|
||||
private PaperResultHeaderComponent hBox;
|
||||
private ExamResultHeaderComponent hBox;
|
||||
|
||||
public SendPaperComponent(SendPaperComponentCallBack callBack) {
|
||||
super();
|
||||
|
|
@ -111,7 +100,7 @@ public class SendPaperComponent extends SplitPane {
|
|||
vbox.prefHeightProperty().bind(this.heightProperty().divide(2));
|
||||
vbox.prefWidthProperty().bind(this.widthProperty());
|
||||
|
||||
ApiUtils.DataView dataView = callBack.loadPaperData(ApiUtils.PAGE_NUM, ApiUtils.PAGE_SIZE);
|
||||
ApiUtils.DataView dataView = callBack.loadPaperData(context, ApiUtils.PAGE_NUM, ApiUtils.PAGE_SIZE);
|
||||
|
||||
questionTable = new TableView<>();
|
||||
questionTable.setItems(questionTable_data);
|
||||
|
|
@ -309,7 +298,7 @@ public class SendPaperComponent extends SplitPane {
|
|||
}
|
||||
});
|
||||
|
||||
hBox = new PaperResultHeaderComponent(15);
|
||||
hBox = new ExamResultHeaderComponent(15);
|
||||
hBox.getCommitBtn().setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
|
|
@ -345,55 +334,16 @@ public class SendPaperComponent extends SplitPane {
|
|||
private void scoreFlush(ObservableList<Map<String, SimpleStringProperty>> changeList) {
|
||||
|
||||
//初始化分值
|
||||
SINGLE_CHOICE_SCORE.set(0);
|
||||
MULTIPLE_CHOICE_SCORE.set(0);
|
||||
JUDGMENT_SCORE.set(0);
|
||||
NUMERICAL_SCORE.set(0);
|
||||
SHORT_ANSWER_SCORE.set(0);
|
||||
Fill_IN_THE_BLANKS.set(0);
|
||||
|
||||
examCount.set(0);
|
||||
reloadData(changeList);
|
||||
}
|
||||
|
||||
private void reloadData(List<Map<String, SimpleStringProperty>> changeList) {
|
||||
for (Map<String, SimpleStringProperty> chooseTableDatum : changeList) {
|
||||
int score = 0;
|
||||
|
||||
if (chooseTableDatum.get("score").get() != null){
|
||||
score = Integer.parseInt(chooseTableDatum.get("score").get());
|
||||
}
|
||||
|
||||
SimpleStringProperty type = chooseTableDatum.get("type");
|
||||
|
||||
switch (type.get()) {
|
||||
case "单选题" -> SINGLE_CHOICE_SCORE.set(SINGLE_CHOICE_SCORE.get() + score);
|
||||
case "多选题" -> MULTIPLE_CHOICE_SCORE.set(MULTIPLE_CHOICE_SCORE.get() + score);
|
||||
case "判断题" -> JUDGMENT_SCORE.set(JUDGMENT_SCORE.get() + score);
|
||||
case "计算题" -> NUMERICAL_SCORE.set(NUMERICAL_SCORE.get() + score);
|
||||
case "填空题" -> Fill_IN_THE_BLANKS.set(Fill_IN_THE_BLANKS.get() + score);
|
||||
case "简答题" -> SHORT_ANSWER_SCORE.set(SHORT_ANSWER_SCORE.get() + score);
|
||||
default -> throw new IllegalStateException("Unexpected value: " + type.get());
|
||||
}
|
||||
examCount.set(examCount.get() + 1);
|
||||
}
|
||||
|
||||
//计算总分
|
||||
ANSWER_SCORE.set(
|
||||
SINGLE_CHOICE_SCORE.get()
|
||||
+ MULTIPLE_CHOICE_SCORE.get()
|
||||
+ JUDGMENT_SCORE.get()
|
||||
+ NUMERICAL_SCORE.get()
|
||||
+ SHORT_ANSWER_SCORE.get()
|
||||
+ Fill_IN_THE_BLANKS.get()
|
||||
|
||||
);
|
||||
|
||||
hBox.setSINGLE_CHOICE_SCORE("单选题分数:" + SINGLE_CHOICE_SCORE.get());
|
||||
hBox.setMULTIPLE_CHOICE_SCORE("多选题分数:" + MULTIPLE_CHOICE_SCORE.get());
|
||||
hBox.setJUDGMENT_SCORE("判断题分数:" + JUDGMENT_SCORE.get());
|
||||
hBox.setNUMERICAL_SCORE("计算题分数:" + NUMERICAL_SCORE.get());
|
||||
hBox.setSHORT_ANSWER_SCORE("简答题分数:" + SHORT_ANSWER_SCORE.get());
|
||||
hBox.setFill_IN_THE_BLANKS("填空题分数:" + Fill_IN_THE_BLANKS.get());
|
||||
hBox.setANSWER_SCORE("答题总分:" + ANSWER_SCORE.get());
|
||||
hBox.setExamCount("试题数量:" + examCount.get());
|
||||
}
|
||||
|
||||
private void initScore() {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import java.util.Map;
|
|||
public interface SendPaperComponentCallBack {
|
||||
ApiUtils.DataView loadPaperData(int pageNum, int pageSize);
|
||||
|
||||
ApiUtils.DataView loadPaperData(Map<String, Object> context, int pageNum, int pageSize);
|
||||
|
||||
ApiUtils.DataView searchPaperData(String searchText, int currentPage, int pageSize);
|
||||
|
||||
ApiUtils.DataView loadChoosePaperData(Map<String, Object> context, int pageNum, int pageSize);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.zhangmeng.online.exam.ui.components.callBack;
|
||||
|
||||
import com.zhangmeng.online.exam.ui.api.DataLoad;
|
||||
import com.zhangmeng.online.exam.ui.api.model.ExamDataLoad;
|
||||
import com.zhangmeng.online.exam.ui.utils.ApiUtils;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
|
|
@ -16,21 +18,31 @@ public class SendPaperComponentCallBackImpl implements SendPaperComponentCallBac
|
|||
|
||||
@Override
|
||||
public ApiUtils.DataView loadPaperData(int pageNum, int pageSize) {
|
||||
return null;
|
||||
ExamDataLoad dataLoad = new ExamDataLoad();
|
||||
return dataLoad.loadPaperData(pageNum, pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiUtils.DataView searchPaperData(String searchText, int currentPage, int pageSize) {
|
||||
return null;
|
||||
public ApiUtils.DataView loadPaperData(Map<String, Object> context, int pageNum, int pageSize) {
|
||||
ExamDataLoad dataLoad = new ExamDataLoad();
|
||||
return dataLoad.loadPaperData(context,pageNum, pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiUtils.DataView searchPaperData(String searchText, int pageNum, int pageSize) {
|
||||
ExamDataLoad dataLoad = new ExamDataLoad();
|
||||
return dataLoad.searchPaperData(searchText, pageNum, pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiUtils.DataView loadChoosePaperData(Map<String, Object> context, int pageNum, int pageSize) {
|
||||
return null;
|
||||
ExamDataLoad dataLoad = new ExamDataLoad();
|
||||
return dataLoad.loadChoosePaperData(context, pageNum, pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commitChoosePaper(Map<String, Object> context, ObservableList<Map<String, SimpleStringProperty>> chooseTableData) {
|
||||
|
||||
ExamDataLoad dataLoad = new ExamDataLoad();
|
||||
dataLoad.commitChoosePaper(context, chooseTableData);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue