派生自 projectDept/qhighschool

EricsHu
2023-11-25 79ab2cbd31c022916a8e696903d5eb34b70aa403
src/main/java/com/qxueyou/scc/teach/student/service/impl/StudentService.java
@@ -1,16 +1,15 @@
package com.qxueyou.scc.teach.student.service.impl;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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;
@@ -32,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 {
@@ -48,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);
@@ -71,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);
@@ -80,10 +83,17 @@
    @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) {
        User user1 = userService.getUserByAccount(studentNo,orgId);
        if(user1 != null){
            return new Result(false, "身份证已存在");
        }
        if (dao.exists(studentNo, orgId)) {
            return new Result(false, "学号已存在");
            return new Result(false, "身份证已存在");
        }
        User user = userService.insertUser(name, studentNo, phoneNo, "000000", sex, orgId);
@@ -92,7 +102,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());
@@ -101,47 +113,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){
        //根据学学员ID,获取用户信息
        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) {
        //根据学学员ID,获取用户信息
        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);
@@ -151,42 +195,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 + "%" ));
@@ -205,14 +265,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);
    }
@@ -221,6 +281,7 @@
    public Result doActivateStudent(String[] studentIds) {
        for (String studentId : studentIds) {
            activateStudent(studentId, StuStudent.STATUS_ACTIVE);
            ModeUpdate(studentId,StuStudent.STATUS_ACTIVE);
        }
        return new Result(true);
    }
@@ -229,6 +290,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);
    }
@@ -241,13 +324,13 @@
        }
        TraceUtils.setUpdateTrace(student);
        String currentTime = LocalDateTimeUtil.format(LocalDateTime.now(), "yyMMddHHmmssSSS");
        String examCardNo = currentTime.concat(RandomUtil.randomNumbers(1));
        student.setStudentNumber(examCardNo);
//        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);
@@ -259,7 +342,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",
@@ -275,15 +358,21 @@
    public StuStudent getStudentByNo(String studentNo) {
        return this.findUnique("from StuStudent where studentNo=? ", CollectionUtils.newList(studentNo), StuStudent.class);
    }
    @Override
    public StuStudent getStudentDetails(String userId) {
          return this.findUnique("from StuStudent where  deleteFlag is false and userId=?  ", CollectionUtils.newList(userId), StuStudent.class);
    }
    @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());
    }
@@ -293,45 +382,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));
        }
    }