package cn.wisdsoft.api;
import cn.wisdsoft.pojo.*;
import cn.wisdsoft.util.ElectiveResult;
import cn.wisdsoft.util.MD5Util;
import cn.wisdsoft.feign.StudentFeign;
import cn.wisdsoft.service.StudentService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.UUID;
/**
* @ Author :高伟萌.
* @ Date :Created in 2019-03-26 14:17
* @ Description:
*/
@RestController
@RequestMapping("/student")
public class StudentApi {
private final StudentFeign studentFeign;
private final StudentService studentService;
public StudentApi(StudentFeign studentFeign, StudentService studentService) {
this.studentFeign = studentFeign;
this.studentService = studentService;
}
/**
* 学生登录
*
* @param username 学号
* @param password 密码
* @param session session
* @return JSON数据
*/
@PostMapping("/slogin")
public ElectiveResult login(String username, String password, HttpSession session) {
//缺少学期,远程调用接口 TODO
String term = "2018-2019第一学期";
Integer termId = 1;
//自定义返回数据
StudentVo studentVo = new StudentVo();
//将输入的密码加密
String md5Encryption = MD5Util.MD5Encryption(password);
//查询本地表内是否有该学生
ElectiveResult result = studentService.login(username, md5Encryption);
//生成token
String token = UUID.randomUUID().toString().replaceAll("-", "");
StudentEntity student;
//如果没有,则去ddms查询,之后插入本地数据库;如果有,则返回
if (result.getData() == null) {
//调用DDMS的查询学生方法
ElectiveResult electiveResult = studentFeign.selectOne(username, password);
if (electiveResult.getStatus() == 200 && electiveResult.getData() == null) {
return ElectiveResult.build(410, "用户名或密码错误!");
} else if (electiveResult.getStatus() == 510) {
return ElectiveResult.build(510, electiveResult.getMsg());
} else {
StudentDo studentDo = JSONObject.parseObject(JSON.toJSONString(electiveResult.getData()), StudentDo.class);
//将DDMS的学生密码加密
String encryption = MD5Util.MD5Encryption(studentDo.getStuPassword());
StudentEntity student1 = new StudentEntity();
student1.setStudentId(studentDo.getId()).setStudentPassword(encryption)
.setStudentName(studentDo.getStuName()).setCollegeName(studentDo.getCollegeName())
.setGrade(Short.valueOf(studentDo.getId().substring(0, 2)));
//插入本地数据库
studentService.insert(student1);
studentVo.setUsername(student1.getStudentId()).setName(student1.getStudentName())
.setCollege(student1.getCollegeName()).setTermId(termId).setTerm(term).setToken(token);
}
} else {
student = JSONObject.parseObject(JSON.toJSONString(result.getData()), StudentEntity.class);
studentVo.setUsername(student.getStudentId()).setName(student.getStudentName())
.setCollege(student.getCollegeName()).setTermId(termId).setTerm(term).setToken(token);
}
//将用户信息存到Session中
session.setAttribute(token, studentVo);
//自定义返回实体类
return ElectiveResult.ok(studentVo);
}
/**
* 选择课程
*
* @param token 用户令牌
* @param electiveCourseId 选课ID
* @param courseGroupName 课组名称
* @param session session
* @return JSON数据
*/
@PostMapping("/getcourse")
public ElectiveResult getCourse(String token, Long electiveCourseId, String courseGroupName, HttpSession session) {
StudentVo studentVo = (StudentVo) session.getAttribute(token);
if (studentVo == null) {
return ElectiveResult.build(410, "token失效");
}
StudentElectiveEntity entity = new StudentElectiveEntity();
entity.setElectiveCourseId(electiveCourseId).setStudentId(studentVo.getUsername()).setStudentName(studentVo.getName())
.setCourseFlag("learning").setTimeStamp(new Date());
return studentService.insertStudentElective(entity, studentVo.getCollege(), courseGroupName);
}
/**
* 退课
*
* @param token 用户令牌
* @param electiveCourseId 选课ID
* @param session session
* @return JSON数据
*/
@PostMapping("/dropcourse")
public ElectiveResult dropCourse(String token, Long electiveCourseId, HttpSession session) {
StudentVo studentVo = (StudentVo) session.getAttribute(token);
if (studentVo == null) {
return ElectiveResult.build(410, "token失效");
}
studentService.deleteCourse(studentVo.getUsername(), electiveCourseId);
return ElectiveResult.ok();
}
/**
* 我的选课
*
* @param token 用户令牌
* @param courseFlag 是否正在学习
* @param session session
* @return JSON数据
*/
@GetMapping("/mycourse")
public ElectiveResult myCourse(String token, String courseFlag, HttpSession session) {
StudentVo myToken = (StudentVo) session.getAttribute(token);
if (myToken == null) {
return ElectiveResult.build(410, "token失效");
}
String studentId = myToken.getUsername();
return studentService.selectElectiveCourse(courseFlag, studentId);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 3、本资源作为“参考资料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。 蓝桥杯选课系统源码.zip
资源推荐
资源详情
资源评论
收起资源包目录
蓝桥杯选课系统源码.zip (97个子文件)
code_20105
pom.xml 3KB
ddms-interface
pom.xml 2KB
src
test
java
cn
wisdsoft
DdmsInterfaceApplicationTests.java 344B
main
resources
application.yml 815B
java
cn
wisdsoft
DdmsInterfaceApplication.java 518B
mapper
TeacherMapper.java 530B
StudentMapper.java 593B
api
TeacherLoginApi.java 930B
StudentLoginApi.java 930B
pojo
Teacher.java 2KB
Student.java 936B
service
StudentService.java 276B
TeacherService.java 276B
impl
TeacherServiceImpl.java 714B
StudentServiceImpl.java 714B
.gitignore 303B
config-server
pom.xml 1011B
src
main
resources
application.yml 349B
java
cn
wisdsoft
ConfigServerApplication.java 503B
.gitignore 303B
eureka-server
pom.xml 848B
src
test
java
cn
wisdsoft
EurekaServerApplicationTests.java 343B
main
resources
application.yml 275B
java
cn
wisdsoft
EurekaServerApplication.java 423B
.gitignore 295B
common
pom.xml 3KB
src
test
java
cn
wisdsoft
AppTest.java 283B
main
java
cn
wisdsoft
CommonApplication.java 419B
pojo
StudentEntity.java 2KB
InformationEntity.java 2KB
CourseLibraryEntity.java 2KB
TermEntity.java 1KB
ElectiveCourseEntity.java 6KB
TermRuleEntity.java 2KB
PerformanceEntity.java 3KB
StudentElectiveEntity.java 2KB
PerformanceRuleEntity.java 2KB
util
ElectiveResult.java 4KB
PageResult.java 1KB
MD5Util.java 1KB
workers-view
pom.xml 1KB
src
test
java
cn
wisdsoft
WorkersViewApplicationTests.java 342B
main
resources
application.yml 260B
java
cn
wisdsoft
WorkersViewApplication.java 422B
.gitignore 303B
api-gateway
pom.xml 1KB
src
test
java
cn
wisdsoft
ApiGatewayApplicationTests.java 341B
main
resources
bootstrap.yml 321B
java
cn
wisdsoft
controller
IndexController.java 610B
ApiGatewayApplication.java 492B
.gitignore 303B
student-view
pom.xml 1KB
src
test
java
cn
wisdsoft
StudentViewApplicationTests.java 342B
main
resources
application.yml 297B
java
cn
wisdsoft
fallback
StudentFallBack.java 1KB
api
StudentViewController.java 2KB
StudentViewApplication.java 501B
feign
StudentFeign.java 3KB
.gitignore 303B
teacher
pom.xml 2KB
src
test
java
cn
wisdsoft
TeacherApplicationTests.java 338B
main
resources
application.yml 745B
java
cn
wisdsoft
TeacherApplication.java 406B
controller
IndexController.java 487B
.gitignore 303B
student
pom.xml 2KB
src
test
java
cn
wisdsoft
StudentApplicationTests.java 788B
main
resources
application.yml 888B
java
cn
wisdsoft
fallback
StudentFallBack.java 503B
mapper
CourseMapper.java 2KB
SQL
SQLUtil.java 4KB
StudentMapper.java 5KB
AchievementMapper.java 614B
StudentApplication.java 589B
api
StudentApi.java 6KB
AchievementApi.java 1KB
CourseApi.java 3KB
feign
StudentFeign.java 854B
pojo
ElectiveCourseVo.java 925B
StudentVo.java 2KB
AchievementVo.java 4KB
StudentDo.java 960B
StudentElectiveVo.java 3KB
ElectiveCourseDo.java 3KB
service
AchievementService.java 446B
StudentService.java 1KB
impl
AchievementServiceImpl.java 842B
CourseServiceImpl.java 2KB
StudentServiceImpl.java 4KB
CourseService.java 1KB
.gitignore 303B
administrator
pom.xml 2KB
src
test
java
cn
wisdsoft
AdministratorApplicationTests.java 344B
main
resources
application.yml 750B
java
cn
wisdsoft
AdministratorApplication.java 418B
controller
IndexController.java 491B
.gitignore 295B
共 97 条
- 1
资源评论
土豆片片
- 粉丝: 1516
- 资源: 5642
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功