package com.example.controller;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.example.common.Result;
import com.example.common.ResultCode;
import com.example.entity.Account;
import com.example.entity.AuthorityInfo;
import com.example.exception.CustomException;
import com.example.entity.AdminInfo;
import com.example.entity.TeacherInfo;
import com.example.entity.StudentInfo;
import com.example.service.AdminInfoService;
import com.example.service.TeacherInfoService;
import com.example.service.StudentInfoService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import cn.hutool.json.JSONUtil;
import java.util.*;
import java.util.stream.Collectors;
@RestController
public class AccountController {
@Value("${authority.info}")
private String authorityStr;
@Resource
private AdminInfoService adminInfoService;
@Resource
private TeacherInfoService teacherInfoService;
@Resource
private StudentInfoService studentInfoService;
@PostMapping("/login")
public Result<Account> login(@RequestBody Account account, HttpServletRequest request) {
if (StrUtil.isBlank(account.getName()) || StrUtil.isBlank(account.getPassword()) || account.getLevel() == null) {
throw new CustomException(ResultCode.PARAM_LOST_ERROR);
}
Integer level = account.getLevel();
Account login = new Account();
if (1 == level) {
login = adminInfoService.login(account.getName(), account.getPassword());
}
if (2 == level) {
login = teacherInfoService.login(account.getName(), account.getPassword());
}
if (3 == level) {
login = studentInfoService.login(account.getName(), account.getPassword());
}
request.getSession().setAttribute("user", login);
return Result.success(login);
}
@PostMapping("/register")
public Result<Account> register(@RequestBody Account account) {
Integer level = account.getLevel();
Account login = new Account();
if (1 == level) {
AdminInfo info = new AdminInfo();
BeanUtils.copyProperties(account, info);
login = adminInfoService.add(info);
}
if (2 == level) {
TeacherInfo info = new TeacherInfo();
BeanUtils.copyProperties(account, info);
login = teacherInfoService.add(info);
}
if (3 == level) {
StudentInfo info = new StudentInfo();
BeanUtils.copyProperties(account, info);
login = studentInfoService.add(info);
}
return Result.success(login);
}
@GetMapping("/logout")
public Result logout(HttpServletRequest request) {
request.getSession().setAttribute("user", null);
return Result.success();
}
@GetMapping("/auth")
public Result getAuth(HttpServletRequest request) {
Object user = request.getSession().getAttribute("user");
if(user == null) {
return Result.error("401", "未登录");
}
return Result.success(user);
}
@GetMapping("/getAccountInfo")
public Result<Object> getAccountInfo(HttpServletRequest request) {
Account account = (Account) request.getSession().getAttribute("user");
if (account == null) {
return Result.success(new Object());
}
Integer level = account.getLevel();
if (1 == level) {
return Result.success(adminInfoService.findById(account.getId()));
}
if (2 == level) {
return Result.success(teacherInfoService.findById(account.getId()));
}
if (3 == level) {
return Result.success(studentInfoService.findById(account.getId()));
}
return Result.success(new Object());
}
@GetMapping("/getSession")
public Result<Map<String, String>> getSession(HttpServletRequest request) {
Account account = (Account) request.getSession().getAttribute("user");
if (account == null) {
return Result.success(new HashMap<>(1));
}
Map<String, String> map = new HashMap<>(1);
map.put("username", account.getName());
return Result.success(map);
}
@GetMapping("/getAuthority")
public Result<List<AuthorityInfo>> getAuthorityInfo() {
List<AuthorityInfo> authorityInfoList = JSONUtil.toList(JSONUtil.parseArray(authorityStr), AuthorityInfo.class);
return Result.success(authorityInfoList);
}
/**
* 获取当前用户所能看到的模块信息
* @param request
* @return
*/
@GetMapping("/authority")
public Result<List<Integer>> getAuthorityInfo(HttpServletRequest request) {
Account user = (Account) request.getSession().getAttribute("user");
if (user == null) {
return Result.success(new ArrayList<>());
}
JSONArray objects = JSONUtil.parseArray(authorityStr);
for (Object object : objects) {
JSONObject jsonObject = (JSONObject) object;
if (user.getLevel().equals(jsonObject.getInt("level"))) {
JSONArray array = JSONUtil.parseArray(jsonObject.getStr("models"));
List<Integer> modelIdList = array.stream().map((o -> {
JSONObject obj = (JSONObject) o;
return obj.getInt("modelId");
})).collect(Collectors.toList());
return Result.success(modelIdList);
}
}
return Result.success(new ArrayList<>());
}
@GetMapping("/permission/{modelId}")
public Result<List<Integer>> getPermission(@PathVariable Integer modelId, HttpServletRequest request) {
List<AuthorityInfo> authorityInfoList = JSONUtil.toList(JSONUtil.parseArray(authorityStr), AuthorityInfo.class);
Account user = (Account) request.getSession().getAttribute("user");
if (user == null) {
return Result.success(new ArrayList<>());
}
Optional<AuthorityInfo> optional = authorityInfoList.stream().filter(x -> x.getLevel().equals(user.getLevel())).findFirst();
if (optional.isPresent()) {
Optional<AuthorityInfo.Model> firstOption = optional.get().getModels().stream().filter(x -> x.getModelId().equals(modelId)).findFirst();
if (firstOption.isPresent()) {
List<Integer> info = firstOption.get().getOperation();
return Result.success(info);
}
}
return Result.success(new ArrayList<>());
}
@PutMapping("/updatePassword")
public Result updatePassword(@RequestBody Account info, HttpServletRequest request) {
Account account = (Account) request.getSession().getAttribute("user");
if (account == null) {
return Result.error(ResultCode.USER_NOT_EXIST_ERROR.code, ResultCode.USER_NOT_EXIST_ERROR.msg);
}
String oldPassword = SecureUtil.md5(info.getPassword());
if (!oldPassword.equals(account.getPassword())) {
return Result.error(ResultCode.PARAM_PASSWORD_ERROR.code, ResultCode.PARAM_PASSWORD_ERROR.msg);
}
info.setPassword(SecureUtil.md5(info.getNewPassword()));
Integer level = account.getLevel();
if (1 == level) {
AdminInfo adminInfo = new AdminInfo();
BeanUtils.copyProperties(info, adminInfo);
adminInfoService.update(adminInfo);
}
if (2 == level) {
TeacherInfo teacherInfo = new TeacherInfo();
BeanUtils.copyProperties(info, teacherInfo);
teacherInfoService.update(teacherInfo);
}
if (3 == level) {
StudentInfo studentInfo = new StudentInfo();
BeanUtils.copyProperties(info, studentInfo);
studentInfoService.update(studentInfo);
}
info.setLevel(level);
info.setName(account.getName());
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
为了能够优化实验室的资源,及学生能根据自己的学习时间自由安排实验时间,现需要开发实验室的预约系统,该预约系统的功能主要有:信息的发布、实验时间的预约、预约信息的查询、预约课时间的即时提醒、预约课上课的签到、预约上课时间的统计、学生预约信息的导出等。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java的高校实验室网上预约系统设计与实现(毕业论文) (383个子文件)
$PRODUCT_WORKSPACE_FILE$ 489B
AccountController.class 12KB
EchartsController.class 9KB
StudentInfoController.class 9KB
TeacherInfoController.class 9KB
AdminInfoController.class 8KB
NxSystemFileController.class 8KB
ShiyanshiInfoController.class 8KB
AdvertiserInfoController.class 8KB
ShiyanshiInfo.class 5KB
KebiaoInfoController.class 5KB
MenuController.class 5KB
KebiaoInfoCommentService.class 4KB
ShiyanshiInfoService.class 4KB
TeacherInfoService.class 4KB
StudentInfoService.class 4KB
AdminInfoService.class 4KB
KebiaoInfoCommentController.class 4KB
AdminInfo.class 3KB
AdvertiserInfoService.class 3KB
StudentInfo.class 3KB
TeacherInfo.class 3KB
Account.class 3KB
NxSystemFileInfoService.class 3KB
KebiaoInfoService.class 3KB
Result.class 2KB
KebiaoInfo.class 2KB
EchartsData.class 2KB
ResultCode.class 2KB
KebiaoInfoComment.class 2KB
MyInterceptor.class 2KB
GlobalExceptionHandler.class 2KB
EchartsData$Data.class 2KB
WebMvcConfig.class 2KB
AdvertiserInfo.class 2KB
EchartsData$Series.class 1KB
AuthorityInfo.class 1KB
MyInterceptorConfig.class 1KB
NxSystemFileInfo.class 1KB
AuthorityInfo$Model.class 1KB
KebiaoInfoCommentVo.class 1KB
CustomException.class 1KB
ShiyanshiInfoDao.class 1008B
TeacherInfoDao.class 930B
StudentInfoDao.class 930B
AdminInfoDao.class 920B
KebiaoInfoCommentDao.class 898B
Application.class 793B
NxSystemFileInfoDao.class 773B
KebiaoInfoDao.class 690B
AdvertiserInfoDao.class 649B
AdvertiserInfoVo.class 320B
ShiyanshiInfoVo.class 316B
StudentInfoVo.class 308B
TeacherInfoVo.class 308B
KebiaoInfoVo.class 304B
AdminInfoVo.class 300B
index.css 227KB
index.css 227KB
bootstrap.min.css 119KB
bootstrap.min.css 119KB
bootstrap.min.css 119KB
bootstrap.min.css 119KB
font-awesome.css 26KB
font-awesome.css 26KB
font-awesome.css 26KB
font-awesome.css 26KB
quill.snow.css 24KB
quill.snow.css 24KB
swiper.min.css 13KB
swiper.min.css 13KB
nav.css 3KB
nav.css 3KB
my.css 1KB
my.css 1KB
my.css 1KB
my.css 1KB
index.css 480B
index.css 480B
common.css 476B
common.css 476B
notice.css 475B
notice.css 475B
nav.css 331B
nav.css 331B
fontawesome-webfont.eot 55KB
fontawesome-webfont.eot 55KB
fontawesome-webfont.eot 55KB
fontawesome-webfont.eot 55KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.eot 20KB
file-info 0B
file-info 0B
shiyanshiInfo.html 42KB
shiyanshiInfo.html 42KB
kebiaoInfo.html 21KB
kebiaoInfo.html 21KB
adminInfo.html 20KB
共 383 条
- 1
- 2
- 3
- 4
资源评论
code.song
- 粉丝: 391
- 资源: 919
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 目标检测-零售食品LOGO检测数据集-40000张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本
- 目标检测-零售食品LOGO检测数据集-30000张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本
- 目标检测-零售食品LOGO检测数据集-20000张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本
- 目标检测-零售食品LOGO检测数据集-10000张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本
- 基于GUI+MYSQL+JAVA图书管理系统文档说明+源码(高分大作业项目).zip
- 基于Qt使用C++实现图书管理系统源码+数据库(95分以上).zip
- 基于GUI+MYSQL+JAVA票务管理系统文档介绍+源码+数据库(高分大作业).zip
- 基于MC1496应用电路Multisim仿真源文件,Multisim10以上版本可打开运行.zip
- 基于LM386应用电路Multisim仿真源文件,Multisim10以上版本可打开运行.zip
- 优先编码器除法电微分运算电路 全加器函数发生电路等电路经典Multisim仿真实验源文件合集(25个).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功