源码获取:博客首页 "资源" 里下载!
管理员和教师登陆此账号就进入后台,学生登陆此账号就进入前端做题。
老师发布了考试,学生才可以在主页面看到相应的考试信息。 有考试安排表以后,才能给该次考试添加题目,对应数据表是exammanage。 该表保存该次考试,课程名称,考试时间,所属专业,学院等等信息。
题库表设计和普通数据表设计有所区别。分别是选择题题库表,填空题题库表,判断题题库表, 每个表保存相应类型的题库,通过一张中间表,将题库和试题关联起来。 这样就组成了一张完整的试卷。
管理员的功能:
考试管理、题库管理、成绩查询、学生管理、教师管理
首先需要增加考试,才能在这个考试下,添加题目。题目可以在题库中自由组题。
学生功能:
查看可以做的试卷、已经做的试卷练习、自己每次考试的分数、给管理员留言等。
统一管理学生 教师 管理员信息控制层:
/**
* 统一管理学生 教师 管理员信息
*/
@RestController
public class UserController {
@Resource(name = "userService")
private IUserService userService;
/**
* 查询用户信息
* 先判断用户类型 在查询用户信息
*/
@RequestMapping(value = "/user/qryUserInfo", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public Result<User> qryUserInfo() {
return userService.qryUserInfo();
}
/**
* 更新用户信息
*/
@RequestMapping(value = "/user/update", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public Result<User> update(HttpRequest request) {
User user = new User();
user.setUserId(request.getString("user_id"));
user.setName(request.getString("name"));
user.setSex(request.getInteger("sex"));
user.setType(User.UserType.get(request.getInteger("type")));
return userService.update(user, ImageUtil.stringToBytes(request.getString("user_image")));
}
/**
* 更新用户密码
*/
@RequestMapping(value = "/user/updatePwd", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public Result<User> updatePwd(HttpRequest request) {
return userService.updatePwd(request.getString("old_pwd"), request.getString("pwd"));
}
}
用户登陆控制层:
@RestController
public class LoginController {
@Resource(name = "loginService")
private ILoginService loginService;
/**
* 用户登录调用 在登陆成功生成两个token 同时返回各自首页
* * 学生 student/student
* * 老师 teacher/teacher
* * 管理员 admin/admin
*/
@RequestMapping(value = "/login/login", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public Result<Token> login(HttpRequest request) {
return loginService.login(request.getString("login_name"), request.getString("pwd"));
}
/**
* 登录检查
*/
@RequestMapping(value = "/login/check", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public Result<Token> check() {
return new Result<>();
}
/**
* token 续约
*/
@RequestMapping(value = "/login/refresh", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public Result<Token> refresh(HttpRequest request) {
String refreshToken = request.getString("refresh_token");
String urlId = request.getString("url_id");
Token token = TokenCache.getInstance().get(urlId);
if(token == null){
ExceptionHelper.error(ErrorCode.ERROR_CODE_0003);
}
try {
Claims claims = TokenUtils.parseToken(refreshToken);
if (StringUtils.isNotEmpty((String.valueOf(claims.getOrDefault("student_id", ""))))) {
claims.put("student_id", SessionContext.get("student_id"));
}
if (StringUtils.isNotEmpty((String.valueOf(claims.getOrDefault("teacher_id", ""))))) {
claims.put("teacher_id", SessionContext.get("teacher_id"));
}
if (StringUtils.isNotEmpty((String.valueOf(claims.getOrDefault("login_name", ""))))) {
claims.put("login_name", SessionContext.get("login_name"));
}
claims.put("name", claims.get("name"));
token.setToken(TokenUtils.createToken(claims, TokenUtils.expireTime));
token.setRefreshToken(TokenUtils.createToken(claims, TokenUtils.long_expireTime));
TokenCache.getInstance().add(token);
} catch (Exception e) {
ExceptionHelper.error(ErrorCode.ERROR_CODE_0003);
}
return new Result<>(token);
}
/**
* 退出系统
*/
@RequestMapping(value = "/login/exit", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public Result<Token> exit(HttpRequest request) {
String urlId = request.getString("url_id");
if (StringUtils.isNotEmpty(urlId)) {
TokenCache.getInstance().remove(urlId);
}
return new Result<>();
}
}
管理员控制器:
/**
* 管理员控制器
*/
@RestController
public class AdminController {
@Resource(name = "adminService")
private IAdminService adminService;
/**
* 管理员 查询管理员列表
*/
@RequestMapping(value = "/admin/qryPage", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.admin})
public ListResult<Admin> qryPage(HttpRequest request) {
Map<String, Object> param = new HashMap<>();
int pageNo = request.containsKey("page_no") ? request.getInteger("page_no") : 1;
int pageSize = request.containsKey("page_size") ? request.getInteger("page_size") : 20;
if (request.containsKey("login_name")) {
param.put("login_name", request.getString("login_name"));
}
if (request.containsKey("name")) {
param.put("name", request.getString("name"));
}
return adminService.qryPage(param, pageNo, pageSize);
}
/**
* 管理员 添加管理员
*/
@RequestMapping(value = "/admin/add", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.admin})
public Result<Admin> insert(HttpRequest request) {
Admin admin = new Admin();
admin.setLoginName(request.getString("login_name"));
admin.setName(request.getString("admin_name"));
admin.setPwd(request.getString("login_name"));
admin.setSex(request.getInteger("sex"));
admin.setUpdateTime(new Date());
return adminService.insert(admin, ImageUtil.stringToBytes(request.getString("admin_image")));
}
/**
* 管理员 更新管理员
*/
@RequestMapping(value = "/admin/update", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.admin})
public Result<Admin> update(HttpRequest request) {
Admin admin = new Admin();
admin.setLoginName(request.getString("login_name"));
admin.setName(request.getString("admin_name"));
admin.setPwd(request.getString("login_name"));
admin.setSex(request.getInteger("sex"));
admin.setUpdateTime(new Date());
return adminService.update(admin, ImageUtil.stringToBytes(request.getString("admin_image")));
}
/**
* 管理员 删除管理员
*/
@RequestMapping(value = "/admin/del", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.admin})
public Result<Admin> del(HttpRequest request) {
List<String> adminIdList = new ArrayList<>();
JSONArray array = request.getJSONArray("admin_id_list");
for (int i = 0; i < array.size(); i++) {
adminIdList.add(array.getString(i));
}
return adminService.del(adminIdList);
}
}
源码获取:博客首页 "资源" 里下载!