派生自 projectDept/qhighschool

EricsHu
2023-11-23 bef4f6d51bff03c0512a75f43e79699b7296f1fa
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 {
@@ -47,6 +47,9 @@
    @Autowired
    StudentDAO dao;
    @Autowired
    CommonDAO commonDAO;
    @Override
    public Result insertStudent(String classId, String name, String studentNo, boolean sex, String phoneNo, String orgId) {
@@ -83,7 +86,7 @@
    public Result insertStudent(String classId, String name, String studentNo, boolean sex, String phoneNo, String orgId,String comName) {
        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 +95,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());
@@ -124,11 +129,11 @@
    public Result updateStudent(String studentId, String name,String password, String studentNo, boolean sex, String phoneNo) {
        //根据学学员ID,获取用户信息
        StuStudent stu = this.read(StuStudent.class, studentId);
        if (!stu.getStudentNo().equals(studentNo) && dao.exists(studentNo,ClientUtils.getOrgId())) {
            return new Result(false, "学号已存在");
        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);
@@ -140,8 +145,14 @@
        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);
@@ -155,7 +166,7 @@
        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,
                        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))
@@ -172,6 +183,7 @@
                    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));
                    return map;
                }).collect(Collectors.toList());
@@ -221,6 +233,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 +242,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 +276,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);