From 0ad2f07a292895eeb3b9618eb1e275568c63a59e Mon Sep 17 00:00:00 2001 From: EricsHu <hrr145632> Date: 星期五, 24 十一月 2023 18:09:23 +0800 Subject: [PATCH] 优化直播、添加班级 --- src/main/java/com/qxueyou/scc/teach/student/service/impl/StudentService.java | 285 +++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 186 insertions(+), 99 deletions(-) diff --git a/src/main/java/com/qxueyou/scc/teach/student/service/impl/StudentService.java b/src/main/java/com/qxueyou/scc/teach/student/service/impl/StudentService.java index 5222a92..6c2b654 100644 --- a/src/main/java/com/qxueyou/scc/teach/student/service/impl/StudentService.java +++ b/src/main/java/com/qxueyou/scc/teach/student/service/impl/StudentService.java @@ -1,13 +1,15 @@ package com.qxueyou.scc.teach.student.service.impl; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.time.LocalDateTime; +import java.util.*; import java.util.stream.Collectors; +import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.util.RandomUtil; import com.qxueyou.scc.admin.classes.model.ClsClass; +import com.qxueyou.scc.base.dao.CommonDAO; import com.qxueyou.scc.exam.model.ExamResultV; +import com.qxueyou.scc.exercise.model.ExerciseCompleteInfo; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +31,7 @@ import com.qxueyou.scc.user.model.QUser; import com.qxueyou.scc.user.model.User; import com.qxueyou.scc.user.service.IUserService; +import org.springframework.util.DigestUtils; @Service public class StudentService extends CommonAppService implements IStudentService { @@ -45,11 +48,14 @@ @Autowired StudentDAO dao; + @Autowired + CommonDAO commonDAO; + @Override public Result insertStudent(String classId, String name, String studentNo, boolean sex, String phoneNo, String orgId) { if (dao.exists(studentNo, orgId)) { - return new Result(false, "学号已存在"); + return new Result(false, "瀛﹀彿宸插瓨鍦�"); } User user = userService.insertUser(name, studentNo, phoneNo, "000000", sex, orgId); @@ -68,7 +74,7 @@ student.setUserId(user.getUserId()); student.setMobilePhone(phoneNo); if(StringUtils.isNoneBlank(classId)) { - bulkUpdate("update ClsClass set studentCount = studentCount + 1 where deleteFlag is false and classId = ?", new Object[]{classId}); + bulkUpdate("update ClsClass set studentCount = studentCount + 1 where deleteFlag is false and classId = ?", new Object[]{classId}); } save(student); @@ -77,10 +83,13 @@ @Override - public Result insertStudent(String classId, String name, String studentNo, boolean sex, String phoneNo, String orgId,String comName) { + public Result insertStudent(String classId, String name, String studentNo, boolean sex, String phoneNo, String orgId, String comName, + String photo, String passporName, String nationality, String ancestralHome, String birthday, String birthplace, + String chinaStatus, String registeredAddress, String homeAddress, String religiousBelief, String email, + String workUnit) { if (dao.exists(studentNo, orgId)) { - return new Result(false, "学号已存在"); + return new Result(false, "韬唤璇佸凡瀛樺湪"); } User user = userService.insertUser(name, studentNo, phoneNo, "000000", sex, orgId); @@ -89,7 +98,9 @@ StuStudent student = new StuStudent(); TraceUtils.setCreateTrace(student); - + String currentTime = LocalDateTimeUtil.format(LocalDateTime.now(), "yyMMddHHmmssSSS"); + String examCardNo = currentTime.concat(RandomUtil.randomNumbers(1)); + student.setStudentNumber(examCardNo); student.setStatus(StuStudent.STATUS_ACTIVE); student.setClassId(classId); //student.setSubjectId(cls.getSubjects().get(0).getSubjectId()); @@ -98,47 +109,79 @@ student.setSex(sex); student.setUserId(user.getUserId()); student.setMobilePhone(phoneNo); - //公司名称 + //鍏徃鍚嶇О student.setSubjectId(comName); - + student.setPhoto(photo); + student.setPassporName(passporName); + student.setNationality(nationality); + student.setAncestralHome(ancestralHome); + student.setBirthday(birthday); + student.setBirthplace(birthplace); + student.setChinaStatus(chinaStatus); + student.setRegisteredAddress(registeredAddress); + student.setHomeAddress(homeAddress); + student.setReligiousBelief(religiousBelief); + student.setEmail(email); + student.setWorkUnit(workUnit); if(StringUtils.isNoneBlank(classId)) { - bulkUpdate("update ClsClass set studentCount = studentCount + 1 where deleteFlag is false and classId = ?", new Object[]{classId}); + bulkUpdate("update ClsClass set studentCount = studentCount + 1 where deleteFlag is false and classId = ?", new Object[]{classId}); } save(student); return new Result(true, "success", CollectionUtils.newStringMap("studentId", student.getStudentId(), "password", user.getPassword())); } - @Override - public Result updateImgStudent(String studentId){ - //根据学学员ID,获取用户信息 - StuStudent stu = this.read(StuStudent.class, studentId); - stu.setTenantId("1"); - save(stu); - return new Result(true, "success"); - } - @Override - public Result updateStudent(String studentId, String name,String password, String studentNo, boolean sex, String phoneNo) { - //根据学学员ID,获取用户信息 + @Override + public Result updateImgStudent(String studentId){ + //鏍规嵁瀛﹀鍛業D锛岃幏鍙栫敤鎴蜂俊鎭� StuStudent stu = this.read(StuStudent.class, studentId); - - if (!stu.getStudentNo().equals(studentNo) && dao.exists(studentNo,ClientUtils.getOrgId())) { - return new Result(false, "学号已存在"); + stu.setTenantId("1"); + save(stu); + return new Result(true, "success"); + } + @Override + public Result updateStudent(String studentId, String name,String password, String studentNo, boolean sex, String phoneNo + , String photo, String passporName, String nationality, String ancestralHome, String birthday, String birthplace, + String chinaStatus, String registeredAddress, String homeAddress, String religiousBelief, String email, + String workUnit, String graduationDestination) { + //鏍规嵁瀛﹀鍛業D锛岃幏鍙栫敤鎴蜂俊鎭� + StuStudent stu = this.read(StuStudent.class, studentId); + if(stu.getStudentNo() != null){ + if (!stu.getStudentNo().equals(studentNo) && dao.exists(studentNo,ClientUtils.getOrgId())) { + return new Result(false, "瀛﹀彿宸插瓨鍦�"); + } } - stu.setName(name); stu.setSex(sex); stu.setStudentNo(studentNo); stu.setMobilePhone(phoneNo); TraceUtils.setUpdateTrace(stu); + stu.setPhoto(photo); + stu.setPassporName(passporName); + stu.setNationality(nationality); + stu.setAncestralHome(ancestralHome); + stu.setBirthday(birthday); + stu.setBirthplace(birthplace); + stu.setChinaStatus(chinaStatus); + stu.setRegisteredAddress(registeredAddress); + stu.setHomeAddress(homeAddress); + stu.setReligiousBelief(religiousBelief); + stu.setEmail(email); + stu.setWorkUnit(workUnit); save(stu); User user = this.read(User.class, stu.getUserId()); user.setAccount(studentNo); user.setSex(sex); user.setMobilePhone(phoneNo); - if(!StringUtils.isEmpty(password)){ - user.setPassword(password); + //闅忔満瀛楃涓� + String salt= UUID.randomUUID().toString(); + //鐩愬�� + user.setSalt(salt); + //瀵瑰瘑鐮佽繘琛屽姞瀵嗗鐞� + String newPassword= DigestUtils.md5DigestAsHex((salt+password).getBytes()); + if(!StringUtils.isEmpty(newPassword)){ + user.setPassword(newPassword); } user.setName(name); save(user); @@ -148,42 +191,58 @@ @Override public List<Map<String, Object>> getStudentLst(String classId, String keyword, Pager pager) { - QUser qUser = QUser.user; - QStuStudent qStuStudent = QStuStudent.stuStudent; - return this.getQueryFactory() - .select(qStuStudent.studentId, qStuStudent.name, qStuStudent.studentNo, qStuStudent.sex, - qStuStudent.mobilePhone, qStuStudent.status, qStuStudent.studyDuration, qStuStudent.tenantId, qStuStudent.score, - qUser.imgPath) - .from(qUser, qStuStudent) - .where(qUser.deleteFlag.isFalse().and(qUser.userId.eq(qStuStudent.userId)) - .and(qStuStudent.classId.eq(classId)).and(qStuStudent.name.like("%" + keyword + "%")).and(qStuStudent.deleteFlag.isFalse())) - .limit(pager.getPageSize()).offset(pager.getOffset()).orderBy(qStuStudent.createTime.desc()).fetch().stream().map(tuple -> { - Map<String, Object> map = new HashMap<String, Object>(); - map.put("studentId", tuple.get(qStuStudent.studentId)); - map.put("name", tuple.get(qStuStudent.name)); - map.put("studentNo", tuple.get(qStuStudent.studentNo)); - map.put("studentNumber", tuple.get(qStuStudent.studentNo)); - map.put("sex", tuple.get(qStuStudent.sex)); - map.put("mobilePhone", tuple.get(qStuStudent.mobilePhone)); - map.put("status", tuple.get(qStuStudent.status)); - map.put("studyDuration", tuple.get(qStuStudent.studyDuration)); - map.put("tenantId", tuple.get(qStuStudent.tenantId)); - map.put("score", tuple.get(qStuStudent.score)); - map.put("imgPath", tuple.get(qUser.imgPath)); - return map; - }).collect(Collectors.toList()); + QUser qUser = QUser.user; + QStuStudent qStuStudent = QStuStudent.stuStudent; + return this.getQueryFactory() + .select(qStuStudent.photo,qStuStudent.passporName,qStuStudent.nationality,qStuStudent.ancestralHome,qStuStudent.birthday,qStuStudent.birthplace,qStuStudent.chinaStatus, + qStuStudent.registeredAddress,qStuStudent.homeAddress,qStuStudent.religiousBelief,qStuStudent.email,qStuStudent.workUnit,qStuStudent.graduationDestination, + qStuStudent.studentId, qStuStudent.name, qStuStudent.studentNo, qStuStudent.sex, + qStuStudent.mobilePhone, qStuStudent.status, qStuStudent.studyDuration, qStuStudent.tenantId, qStuStudent.score, qStuStudent.graduationText, + qUser.imgPath) + .from(qUser, qStuStudent) + .where(qUser.deleteFlag.isFalse().and(qUser.userId.eq(qStuStudent.userId)) + .and(qStuStudent.classId.eq(classId)).and(qStuStudent.name.like("%" + keyword + "%")).and(qStuStudent.deleteFlag.isFalse())) + .limit(pager.getPageSize()).offset(pager.getOffset()).orderBy(qStuStudent.createTime.desc()).fetch().stream().map(tuple -> { + Map<String, Object> map = new HashMap<String, Object>(); + map.put("studentId", tuple.get(qStuStudent.studentId)); + map.put("name", tuple.get(qStuStudent.name)); + map.put("studentNo", tuple.get(qStuStudent.studentNo)); + map.put("studentNumber", tuple.get(qStuStudent.studentNo)); + map.put("sex", tuple.get(qStuStudent.sex)); + map.put("mobilePhone", tuple.get(qStuStudent.mobilePhone)); + map.put("status", tuple.get(qStuStudent.status)); + map.put("studyDuration", tuple.get(qStuStudent.studyDuration)); + map.put("tenantId", tuple.get(qStuStudent.tenantId)); + map.put("score", tuple.get(qStuStudent.score)); + map.put("graduationText", tuple.get(qStuStudent.graduationText)); + map.put("imgPath", tuple.get(qUser.imgPath)); + map.put("photo", tuple.get(qStuStudent.photo)); + map.put("passporName", tuple.get(qStuStudent.passporName)); + map.put("nationality", tuple.get(qStuStudent.nationality)); + map.put("ancestralHome", tuple.get(qStuStudent.ancestralHome)); + map.put("birthday", tuple.get(qStuStudent.birthday)); + map.put("birthplace", tuple.get(qStuStudent.birthplace)); + map.put("chinaStatus", tuple.get(qStuStudent.chinaStatus)); + map.put("registeredAddress", tuple.get(qStuStudent.registeredAddress)); + map.put("homeAddress", tuple.get(qStuStudent.homeAddress)); + map.put("religiousBelief", tuple.get(qStuStudent.religiousBelief)); + map.put("email", tuple.get(qStuStudent.email)); + map.put("workUnit", tuple.get(qStuStudent.workUnit)); + map.put("graduationDestination", tuple.get(qStuStudent.graduationDestination)); + return map; + }).collect(Collectors.toList()); } @Override public int getStudentsCount(String classId, String keyword) { -// //TODO 判断是否为补考分组 +// //TODO 鍒ゆ柇鏄惁涓鸿ˉ鑰冨垎缁� // ClsClass cls = clsService.read(classId); // String hql=null; // if(cls!=null && cls.getClassTypes()!=null && "1".equals(cls.getClassTypes())){ -// //TODO 补考分组需要另一种查询学员 stu.tenantId = class.classId +// //TODO 琛ヨ�冨垎缁勯渶瑕佸彟涓�绉嶆煡璇㈠鍛� stu.tenantId = class.classId // hql = "from StuStudent where tenantId=:classId and name like :keyword and deleteFlag is false"; // }else { - String hql = "from StuStudent where classId=:classId and name like :keyword and deleteFlag is false"; + String hql = "from StuStudent where classId=:classId and name like :keyword and deleteFlag is false"; // } return findCountByComplexHql(hql, CollectionUtils.newObjectMap("classId", classId, "keyword", "%" + keyword + "%" )); @@ -202,14 +261,14 @@ private Result deleteStudent(String classId, String studentId) { StuStudent student = read(StuStudent.class, studentId); - User user = read(User.class, student.getUserId()); + User user = read(User.class, student.getUserId()); if (StuStudent.STATUS_ACTIVE.equals(student.getStatus())) { - return new Result(false, "已激活学员不能移除"); + return new Result(false, "宸叉縺娲诲鍛樹笉鑳界Щ闄�"); } TraceUtils.setUpdateTrace(student); student.setDeleteFlag(true); save(student); - deleteTrace(user); + deleteTrace(user); return new Result(true); } @@ -218,6 +277,7 @@ public Result doActivateStudent(String[] studentIds) { for (String studentId : studentIds) { activateStudent(studentId, StuStudent.STATUS_ACTIVE); + ModeUpdate(studentId,StuStudent.STATUS_ACTIVE); } return new Result(true); } @@ -226,6 +286,28 @@ public Result doDeActivateStudent(String[] studentIds) { for (String studentId : studentIds) { activateStudent(studentId, StuStudent.STATUS_DEACTIVE); + ModeUpdate(studentId,StuStudent.STATUS_DEACTIVE); + } + return new Result(true); + } + + private Result ModeUpdate(String studentId,String status){ + if(status.equals(StuStudent.STATUS_ACTIVE)){ + String hql = "from ExerciseCompleteInfo where studentId=? and deleteFlag is false"; + List<Object> Params = CollectionUtils.newList(studentId); + ExerciseCompleteInfo unique = findUnique(hql, Params, ExerciseCompleteInfo.class); + if(unique!=null) { + unique.setDeleteFlag(false); + commonDAO.update(unique); + } + }else { + String hql = "from ExerciseCompleteInfo where studentId=? and deleteFlag is false"; + List<Object> Params = CollectionUtils.newList(studentId); + ExerciseCompleteInfo unique = findUnique(hql, Params, ExerciseCompleteInfo.class); + if(unique!=null){ + unique.setDeleteFlag(true); + commonDAO.update(unique); + } } return new Result(true); } @@ -238,8 +320,13 @@ } TraceUtils.setUpdateTrace(student); +// String currentTime = LocalDateTimeUtil.format(LocalDateTime.now(), "yyMMddHHmmssSSS"); +// +// String examCardNo = currentTime.concat(RandomUtil.randomNumbers(1)); +// +// student.setStudentNumber(examCardNo); student.setStatus(status); - save(student); + commonDAO.update(student); clsService.addStudent(student.getClassId(), StuStudent.STATUS_DEACTIVE.equals(status) ? -1 : 1); @@ -251,7 +338,7 @@ StuStudent student = read(StuStudent.class, studentId); if(student == null) { - return new Result(false, "未查询到学员信息"); + return new Result(false, "鏈煡璇㈠埌瀛﹀憳淇℃伅"); } return new Result(true, "success", CollectionUtils.newObjectMap("studentId", student.getStudentId(), "name", student.getName(), "status", @@ -269,13 +356,13 @@ } @Override public List<StuStudent> getStudentByclassId(String classId) { - QStuStudent qClassStudent=QStuStudent.stuStudent; - return new ArrayList<>(this.getQueryFactory() - .select(qClassStudent - ) - .from(qClassStudent) - .where(qClassStudent.classId.eq(classId)) - .fetch()); + QStuStudent qClassStudent=QStuStudent.stuStudent; + return new ArrayList<>(this.getQueryFactory() + .select(qClassStudent + ) + .from(qClassStudent) + .where(qClassStudent.classId.eq(classId)) + .fetch()); } @@ -285,45 +372,45 @@ @Override public Result studentProgress(String classId, String studentId) { - StuStudent student = read(StuStudent.class, studentId); - if(student == null) { - return new Result(false, "未查询到学员信息"); - } + StuStudent student = read(StuStudent.class, studentId); + if(student == null) { + return new Result(false, "鏈煡璇㈠埌瀛﹀憳淇℃伅"); + } - String userId = student.getUserId(); + String userId = student.getUserId(); - User u = this.read(User.class, userId); - if(u == null) { - return new Result(false, "未查询到用户信息"); - } + User u = this.read(User.class, userId); + if(u == null) { + return new Result(false, "鏈煡璇㈠埌鐢ㄦ埛淇℃伅"); + } - QSubjectProgressTreeV qSubjectProgressTreeV = QSubjectProgressTreeV.subjectProgressTreeV; + QSubjectProgressTreeV qSubjectProgressTreeV = QSubjectProgressTreeV.subjectProgressTreeV; - //班级进度 - SubjectProgressTreeV objSubjectProgressTreeV = this.getQueryFactory().selectFrom(qSubjectProgressTreeV).where(qSubjectProgressTreeV.id.nodeId.eq(classId).and(qSubjectProgressTreeV.id.userId.eq(userId))).fetchOne(); + //鐝骇杩涘害 + SubjectProgressTreeV objSubjectProgressTreeV = this.getQueryFactory().selectFrom(qSubjectProgressTreeV).where(qSubjectProgressTreeV.id.nodeId.eq(classId).and(qSubjectProgressTreeV.id.userId.eq(userId))).fetchOne(); - if(objSubjectProgressTreeV != null) { - //学员总数 - long studentCount = this.getQueryFactory().selectFrom(qSubjectProgressTreeV).where(qSubjectProgressTreeV.id.nodeId.eq(classId)).fetchCount(); + if(objSubjectProgressTreeV != null) { + //瀛﹀憳鎬绘暟 + long studentCount = this.getQueryFactory().selectFrom(qSubjectProgressTreeV).where(qSubjectProgressTreeV.id.nodeId.eq(classId)).fetchCount(); - // 当前学员排行 - long studentIndex = this - .getQueryFactory().selectFrom(qSubjectProgressTreeV).where(qSubjectProgressTreeV.id.nodeId - .eq(classId).and(qSubjectProgressTreeV.percent.gt(objSubjectProgressTreeV.getPercent()) - .or(qSubjectProgressTreeV.percent.eq(objSubjectProgressTreeV.getPercent())))) - .fetchCount(); + // 褰撳墠瀛﹀憳鎺掕 + long studentIndex = this + .getQueryFactory().selectFrom(qSubjectProgressTreeV).where(qSubjectProgressTreeV.id.nodeId + .eq(classId).and(qSubjectProgressTreeV.percent.gt(objSubjectProgressTreeV.getPercent()) + .or(qSubjectProgressTreeV.percent.eq(objSubjectProgressTreeV.getPercent())))) + .fetchCount(); - //学员的课程 - List<Map<String, Object>> lstSubject = this.subjectService.myClsSubjectlist(classId, userId, new Pager(Integer.MAX_VALUE, 0)); + //瀛﹀憳鐨勮绋� + List<Map<String, Object>> lstSubject = this.subjectService.myClsSubjectlist(classId, userId, new Pager(Integer.MAX_VALUE, 0)); - return new Result(true, "success", CollectionUtils.newObjectMap("studentId", student.getStudentId(), "name", student.getName(), "imgPath", u.getImgPath(), - "status", student.getStatus(), "studentNumber", student.getStudentNo(), "sex", student.getSex(), "mobilePhone", - student.getMobilePhone(), "subjectList", lstSubject, "studentCount", studentCount, "studentIndex", studentIndex, "studyDuration", objSubjectProgressTreeV.getProgressValue())); - }{ - return new Result(true, "success", CollectionUtils.newObjectMap("studentId", student.getStudentId(), "name", student.getName(), "imgPath", u.getImgPath(), - "status", student.getStatus(), "studentNumber", student.getStudentNo(), "sex", student.getSex(), "mobilePhone", - student.getMobilePhone(), "subjectList", new ArrayList<Map<String, Object>>(), "studentCount", 0, "studentIndex", 1, "studyDuration", 0)); - } + return new Result(true, "success", CollectionUtils.newObjectMap("studentId", student.getStudentId(), "name", student.getName(), "imgPath", u.getImgPath(), + "status", student.getStatus(), "studentNumber", student.getStudentNo(), "sex", student.getSex(), "mobilePhone", + student.getMobilePhone(), "subjectList", lstSubject, "studentCount", studentCount, "studentIndex", studentIndex, "studyDuration", objSubjectProgressTreeV.getProgressValue())); + }{ + return new Result(true, "success", CollectionUtils.newObjectMap("studentId", student.getStudentId(), "name", student.getName(), "imgPath", u.getImgPath(), + "status", student.getStatus(), "studentNumber", student.getStudentNo(), "sex", student.getSex(), "mobilePhone", + student.getMobilePhone(), "subjectList", new ArrayList<Map<String, Object>>(), "studentCount", 0, "studentIndex", 1, "studyDuration", 0)); + } } -- Gitblit v1.8.0