学生端加入班级模块完成
This commit is contained in:
parent
4bafdd2dc0
commit
a196deecb9
|
|
@ -18,4 +18,6 @@ export default {
|
|||
updateUserInfo: (data) => request.post('/user/editUserInfo', data),
|
||||
updateUserPwd: (data) => request.post('/user/editUserPassword', data),
|
||||
signUser: (data) => request.post('/user/signUser', data, { noNeedToken: true }),
|
||||
|
||||
takeClassByInviteCode: (data) => request.post('/classes/takeClassByInviteCode', data), //¼ÓÈë°à¼¶
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.example.aes.user.controller;
|
|||
|
||||
import com.example.aes.global.model.DecodeToken;
|
||||
import com.example.aes.global.model.RespBean;
|
||||
import com.example.aes.user.model.Json;
|
||||
import com.example.aes.user.model.PMClasses;
|
||||
import com.example.aes.user.service.ClassesServiceI;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -54,4 +55,16 @@ public class ClassesController{
|
|||
}
|
||||
}
|
||||
|
||||
@PostMapping("/takeClassByInviteCode") //学生加入班级
|
||||
public RespBean takeClassByInviteCode(@RequestBody PMClasses pmclasses, HttpServletRequest request) {
|
||||
DecodeToken decodeToken = new DecodeToken(request);
|
||||
String userId = decodeToken.getUserId();
|
||||
Json j = new Json();
|
||||
j=classesServiceI.takeOneClass(pmclasses.getInviteCode(), Integer.parseInt(userId));
|
||||
if(j.isSuccess())
|
||||
return RespBean.ok(j.getMsg(), j.getObj());
|
||||
else
|
||||
return RespBean.error(j.getMsg(), j.getObj());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,16 @@ public class ClassstudentsDaoImpl extends BaseDaoImpl<Classstudents> implements
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean findClassInviteCode(String inviteCode){
|
||||
String hql = "from Classstudents where inviteCode=" + inviteCode;
|
||||
List<Classstudents> classstudents = this.find(hql);
|
||||
if(classstudents.size()>0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getClassStudentsNum(int classId) { // 获取班级学生的总数
|
||||
// TODO Auto-generated method stub
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ import java.util.List;
|
|||
public interface ClassesServiceI {
|
||||
public List<PMClasses> findClassesByCondition(int teacherId);
|
||||
public List<PMClasses> findClassesByCondition(PMClasses pmclasses);
|
||||
|
||||
public Json takeOneClass(String inviteCode, int studentID);
|
||||
|
||||
// public List<Classes> findAllClass();
|
||||
//
|
||||
// public DataGrid findClassesByConditionPage(int teacherId, String role, int pageNum, int pageSize);
|
||||
|
|
|
|||
|
|
@ -2,21 +2,22 @@ package com.example.aes.user.service.impl;
|
|||
|
||||
import com.example.aes.user.dao.ClassesDaoI;
|
||||
import com.example.aes.user.dao.ClassstudentsDaoI;
|
||||
import com.example.aes.user.model.Classes;
|
||||
import com.example.aes.user.model.Json;
|
||||
import com.example.aes.user.model.PMClasses;
|
||||
import com.example.aes.user.service.ClassesServiceI;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class ClassesServiceImpl implements ClassesServiceI {
|
||||
|
||||
private ClassesDaoI classesDao;
|
||||
// private ClassstudentsDaoI classstudentsDao;
|
||||
private ClassstudentsDaoI classstudentsDao;
|
||||
|
||||
// private AttendenceDaoI attendenceDao;
|
||||
// private StudentAttendenceDaoI studentattendenceDao;
|
||||
// private ExamClassesDaoI examClassesDao;
|
||||
|
|
@ -24,6 +25,10 @@ public class ClassesServiceImpl implements ClassesServiceI {
|
|||
public void setClassesDao(ClassesDaoI classesDao) {
|
||||
this.classesDao = classesDao;
|
||||
}
|
||||
@Autowired
|
||||
public void setclassstudentsDao(ClassstudentsDaoI classstudentsDao) {
|
||||
this.classstudentsDao = classstudentsDao;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
|
@ -37,5 +42,26 @@ public void setClassesDao(ClassesDaoI classesDao) {
|
|||
return classesDao.findClassesByCondition(pmclasses);
|
||||
}
|
||||
|
||||
public Json takeOneClass(String inviteCode, int studentID) {
|
||||
Json json = new Json();
|
||||
Classes classes = classesDao.getClassesByCode(inviteCode);// 先检查是否有该班级
|
||||
if (classes != null) {
|
||||
boolean result = classstudentsDao.findClassStudentByUserId(studentID, classes.getId());
|
||||
if (result == false) {
|
||||
result = classstudentsDao.insertClassStudent(studentID, classes.getId());
|
||||
int studentsNum = classstudentsDao.getClassStudentsNum(classes.getId());
|
||||
boolean results = classesDao.updateClassStudentsNum(classes.getId(), studentsNum);
|
||||
json.setSuccess(true);
|
||||
json.setMsg("加入班级成功");
|
||||
} else {
|
||||
json.setSuccess(false);
|
||||
json.setMsg("已经在班级中");
|
||||
}
|
||||
} else {
|
||||
json.setSuccess(false);
|
||||
json.setMsg("没有找到该班级");
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue