2025年3月18日17:31:41

master
qmstyle 2025-03-18 17:31:47 +08:00
parent c597ae17df
commit 7e9e164d91
4 changed files with 274 additions and 0 deletions

View File

@ -91,6 +91,16 @@ public class ApiUtils {
return dataLoad.loadData(PAGE_NUM,PAGE_SIZE);
}
public static DataView getAnswerList() {
DataLoad dataLoad = new AnswerDataLoad();
return dataLoad.loadData(PAGE_NUM,PAGE_SIZE);
}
public static DataView getExamPaper() {
DataLoad dataLoad = new PaperDataLoad();
return dataLoad.loadData(PAGE_NUM,PAGE_SIZE);
}
public static class DataView {
private List<String> keys;

View File

@ -0,0 +1,131 @@
package com.zhangmeng.online.exam.ui.api.model;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zhangmeng.online.exam.ui.api.ApiUtils;
import com.zhangmeng.online.exam.ui.api.DataLoad;
import com.zhangmeng.online.exam.ui.api.form.UserForm;
import com.zhangmeng.online.exam.ui.utils.AlertUtils;
import com.zhangmeng.online.exam.ui.utils.HttpUtils;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.Parent;
import javafx.stage.Stage;
import java.util.*;
/**
* @author zm
* @date 2025/3/18 17:04
* @version: 1.0
*/
public class AnswerDataLoad implements DataLoad {
private Parent form;
@Override
public ApiUtils.DataView loadData(Integer pageNum, Integer pageSize) {
Map<String, Object> params = new HashMap<>();
params.put("pageNum", pageNum.toString());
params.put("pageSize", pageSize.toString());
String userListData = HttpUtils.GET(ApiUtils.API_URL + "/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("用户名_username", new SimpleStringProperty(user.getString("username")));
userMap.put("手机号码_phone", new SimpleStringProperty(user.getString("phone")));
userMap.put("电子邮箱_email", new SimpleStringProperty(user.getString("email")));
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;
}
@Override
public void setForm(Parent view) {
this.form = view;
}
@Override
public Parent getForm() {
return this.form;
}
@Override
public Map<String, Object> saveForm(Map<String, Object> map) {
String result = HttpUtils.POST(ApiUtils.API_URL + "/user/save", map);
JSONObject jsonObject = JSON.parseObject(result);
if (jsonObject.getIntValue("code") == 200){
AlertUtils.alert_msg("保存成功!");
}else {
AlertUtils.alert_warning("保存失败!");
}
return null;
}
@Override
public void deleteData(String id) {
Map<String, Object> map = new HashMap<>();
map.put("id", id);
String result = HttpUtils.POST(ApiUtils.API_URL + "/user/delete", map);
JSONObject jsonObject = JSON.parseObject(result);
if (jsonObject.getIntValue("code") == 200){
AlertUtils.alert_msg("删除成功!");
}else {
AlertUtils.alert_warning("删除失败!");
}
}
@Override
public void editData(String id, Stage stage) {
UserForm userForm = new UserForm();
Map<String, Object> map = new HashMap<>();
map.put("id", id);
String result = HttpUtils.GET(ApiUtils.API_URL + "/user/getUser", map);
JSONObject jsonObject = JSON.parseObject(result);
JSONObject data = jsonObject.getJSONObject("data");
String username = data.getString("username");
userForm.getUsername_field().setText(username);
String email = data.getString("email");
userForm.getEmail_field().setText(email);
String phone = data.getString("phone");
userForm.getPhone_field().setText(phone);
String password = data.getString("password");
userForm.getPassword_field().setText(password);
AlertUtils.alert("编辑用户信息", (Parent) userForm, stage);
}
@Override
public void updateData(String id, String name, String oldValue, String newValue) {
// System.out.println("修改前:" + oldValue + ",修改后:" + newValue);
Map<String, Object> map = new HashMap<>();
map.put("id", id);
map.put("fieldName", name);
map.put("oldValue", oldValue);
map.put("newValue", newValue);
String result = HttpUtils.POST(ApiUtils.API_URL + "/user/update", map);
JSONObject jsonObject = JSON.parseObject(result);
if (jsonObject.getIntValue("code") == 200){
AlertUtils.alert_msg("更新成功!");
}else {
AlertUtils.alert_warning("更新失败!");
}
}
}

View File

@ -0,0 +1,131 @@
package com.zhangmeng.online.exam.ui.api.model;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zhangmeng.online.exam.ui.api.ApiUtils;
import com.zhangmeng.online.exam.ui.api.DataLoad;
import com.zhangmeng.online.exam.ui.api.form.UserForm;
import com.zhangmeng.online.exam.ui.utils.AlertUtils;
import com.zhangmeng.online.exam.ui.utils.HttpUtils;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.Parent;
import javafx.stage.Stage;
import java.util.*;
/**
* @author zm
* @date 2025/3/18 17:04
* @version: 1.0
*/
public class PaperDataLoad implements DataLoad {
private Parent form;
@Override
public ApiUtils.DataView loadData(Integer pageNum, Integer pageSize) {
Map<String, Object> params = new HashMap<>();
params.put("pageNum", pageNum.toString());
params.put("pageSize", pageSize.toString());
String userListData = HttpUtils.GET(ApiUtils.API_URL + "/paper/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("用户名_username", new SimpleStringProperty(user.getString("username")));
userMap.put("手机号码_phone", new SimpleStringProperty(user.getString("phone")));
userMap.put("电子邮箱_email", new SimpleStringProperty(user.getString("email")));
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;
}
@Override
public void setForm(Parent view) {
this.form = view;
}
@Override
public Parent getForm() {
return this.form;
}
@Override
public Map<String, Object> saveForm(Map<String, Object> map) {
String result = HttpUtils.POST(ApiUtils.API_URL + "/user/save", map);
JSONObject jsonObject = JSON.parseObject(result);
if (jsonObject.getIntValue("code") == 200){
AlertUtils.alert_msg("保存成功!");
}else {
AlertUtils.alert_warning("保存失败!");
}
return null;
}
@Override
public void deleteData(String id) {
Map<String, Object> map = new HashMap<>();
map.put("id", id);
String result = HttpUtils.POST(ApiUtils.API_URL + "/user/delete", map);
JSONObject jsonObject = JSON.parseObject(result);
if (jsonObject.getIntValue("code") == 200){
AlertUtils.alert_msg("删除成功!");
}else {
AlertUtils.alert_warning("删除失败!");
}
}
@Override
public void editData(String id, Stage stage) {
UserForm userForm = new UserForm();
Map<String, Object> map = new HashMap<>();
map.put("id", id);
String result = HttpUtils.GET(ApiUtils.API_URL + "/user/getUser", map);
JSONObject jsonObject = JSON.parseObject(result);
JSONObject data = jsonObject.getJSONObject("data");
String username = data.getString("username");
userForm.getUsername_field().setText(username);
String email = data.getString("email");
userForm.getEmail_field().setText(email);
String phone = data.getString("phone");
userForm.getPhone_field().setText(phone);
String password = data.getString("password");
userForm.getPassword_field().setText(password);
AlertUtils.alert("编辑用户信息", (Parent) userForm, stage);
}
@Override
public void updateData(String id, String name, String oldValue, String newValue) {
// System.out.println("修改前:" + oldValue + ",修改后:" + newValue);
Map<String, Object> map = new HashMap<>();
map.put("id", id);
map.put("fieldName", name);
map.put("oldValue", oldValue);
map.put("newValue", newValue);
String result = HttpUtils.POST(ApiUtils.API_URL + "/user/update", map);
JSONObject jsonObject = JSON.parseObject(result);
if (jsonObject.getIntValue("code") == 200){
AlertUtils.alert_msg("更新成功!");
}else {
AlertUtils.alert_warning("更新失败!");
}
}
}

View File

@ -131,6 +131,8 @@ public class SideMenu extends VBox {
case "/question/list" -> init_table(hbox, ApiUtils.getQuestionList());
case "/subject/list" -> init_table(hbox, ApiUtils.getSubjectList());
case "/option/list" -> init_table(hbox, ApiUtils.getQuestionOptionList());
case "/answer/list" -> init_table(hbox, ApiUtils.getAnswerList());
case "/exam/paper" -> init_table(hbox, ApiUtils.getExamPaper());
}
});