ソースを参照

feat:更新学员默认声部、指导老师定时任务

Joburgess 4 年 前
コミット
1b1bf4bcbd

+ 8 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentDao.java

@@ -194,4 +194,12 @@ public interface StudentDao extends com.ym.mec.common.dal.BaseDAO<Integer, Stude
      * @return
      */
     int updateGrade();
+
+    /**
+     * @describe
+     * @author Joburgess
+     * @date 2021/3/29 0029
+     * @return java.util.List<com.ym.mec.biz.dal.entity.Student>
+     */
+    List<Student> getNoTeacherOrNoSubjectStudent();
 }

+ 3 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentRegistrationDao.java

@@ -489,4 +489,7 @@ public interface StudentRegistrationDao extends BaseDAO<Long, StudentRegistratio
 
     List<NoClassMusicStudentDto> queryNoClassMusicStudents(Map<String, Object> params);
     int countNoClassMusicStudents(Map<String, Object> params);
+
+
+    List<StudentClassInfoDto> getStudentClassInfo(@Param("studentIds") List<Integer> studentIds);
 }

+ 58 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/StudentClassInfoDto.java

@@ -0,0 +1,58 @@
+package com.ym.mec.biz.dal.dto;
+
+/**
+ * @Author Joburgess
+ * @Date 2021/3/29 0029
+ */
+public class StudentClassInfoDto {
+
+    private Integer studentId;
+
+    private String musicGroupId;
+
+    private Integer subjectId;
+
+    private Long classGroupId;
+
+    private Integer mainTeacherId;
+
+    public Integer getStudentId() {
+        return studentId;
+    }
+
+    public void setStudentId(Integer studentId) {
+        this.studentId = studentId;
+    }
+
+    public String getMusicGroupId() {
+        return musicGroupId;
+    }
+
+    public void setMusicGroupId(String musicGroupId) {
+        this.musicGroupId = musicGroupId;
+    }
+
+    public Integer getSubjectId() {
+        return subjectId;
+    }
+
+    public void setSubjectId(Integer subjectId) {
+        this.subjectId = subjectId;
+    }
+
+    public Long getClassGroupId() {
+        return classGroupId;
+    }
+
+    public void setClassGroupId(Long classGroupId) {
+        this.classGroupId = classGroupId;
+    }
+
+    public Integer getMainTeacherId() {
+        return mainTeacherId;
+    }
+
+    public void setMainTeacherId(Integer mainTeacherId) {
+        this.mainTeacherId = mainTeacherId;
+    }
+}

+ 8 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/StudentService.java

@@ -49,4 +49,12 @@ public interface StudentService extends BaseService<Integer, Student> {
      * @return
      */
     String getStudentGrade(GradeTypeEnum gradeType,Integer gradeNum);
+
+    /**
+     * @describe 更新学员指导老师和声部信息
+     * @author Joburgess
+     * @date 2021/3/29 0029
+     * @return void
+     */
+    void updateStudentTeacherAndSubject();
 }

+ 39 - 6
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentServiceImpl.java

@@ -1,18 +1,16 @@
 package com.ym.mec.biz.service.impl;
 
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 import com.ym.mec.biz.dal.dao.CourseScheduleDao;
+import com.ym.mec.biz.dal.dao.StudentRegistrationDao;
+import com.ym.mec.biz.dal.dto.StudentClassInfoDto;
 import com.ym.mec.biz.dal.enums.FivePlusGradeEnum;
 import com.ym.mec.biz.dal.enums.GradeTypeEnum;
 import com.ym.mec.biz.dal.enums.SixPlusGradeEnum;
 import com.ym.mec.common.page.QueryInfo;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
@@ -43,6 +41,9 @@ public class StudentServiceImpl extends BaseServiceImpl<Integer, Student> implem
     @Autowired
     private CourseScheduleStudentPaymentDao courseScheduleStudentPaymentDao;
 
+    @Autowired
+    private StudentRegistrationDao studentRegistrationDao;
+
     @Override
     public BaseDAO<Integer, Student> getDAO() {
         return studentDao;
@@ -200,4 +201,36 @@ public class StudentServiceImpl extends BaseServiceImpl<Integer, Student> implem
         }
         return grade;
     }
+
+    @Override
+    public void updateStudentTeacherAndSubject() {
+        List<Student> noTeacherOrNoSubjectStudent = studentDao.getNoTeacherOrNoSubjectStudent();
+        if(CollectionUtils.isEmpty(noTeacherOrNoSubjectStudent)){
+            return;
+        }
+        List<Integer> studentIds = noTeacherOrNoSubjectStudent.stream().map(Student::getUserId).collect(Collectors.toList());
+        List<StudentClassInfoDto> studentClassInfo = studentRegistrationDao.getStudentClassInfo(studentIds);
+        if(CollectionUtils.isEmpty(studentClassInfo)){
+            return;
+        }
+        List<Student> needUpdateStudents = new ArrayList<>();
+        Map<Integer, List<StudentClassInfoDto>> scm = studentClassInfo.stream().collect(Collectors.groupingBy(StudentClassInfoDto::getStudentId));
+        for (Student student : noTeacherOrNoSubjectStudent) {
+            if(!scm.containsKey(student.getUserId())){
+                continue;
+            }
+            List<StudentClassInfoDto> studentClassInfoDtos = scm.get(student.getUserId());
+            StudentClassInfoDto studentClassInfoDto = studentClassInfoDtos.stream().max(Comparator.comparing(StudentClassInfoDto::getClassGroupId)).get();
+            if(Objects.isNull(student.getTeacherId())){
+                student.setTeacherId(studentClassInfoDto.getMainTeacherId());
+            }
+            if(StringUtils.isBlank(student.getSubjectIdList())){
+                student.setSubjectIdList(studentClassInfoDto.getSubjectId().toString());
+            }
+            needUpdateStudents.add(student);
+        }
+        if(!CollectionUtils.isEmpty(needUpdateStudents)){
+            studentDao.batchUpdate(needUpdateStudents);
+        }
+    }
 }

+ 3 - 0
mec-biz/src/main/resources/config/mybatis/StudentMapper.xml

@@ -671,6 +671,9 @@
             #{studentId}
         </foreach>
     </select>
+    <select id="getNoTeacherOrNoSubjectStudent" resultMap="Student">
+        SELECT * FROM student WHERE teacher_id_ IS NULL OR subject_id_list_ IS NULL;
+    </select>
 
     <update id="updateGrade"><![CDATA[
         UPDATE student SET current_grade_num_=current_grade_num_+1

+ 21 - 0
mec-biz/src/main/resources/config/mybatis/StudentRegistrationMapper.xml

@@ -923,4 +923,25 @@
             LEFT JOIN sys_user stu ON stu.id_ = sr.user_id_
         <include refid="queryNoClassMusicStudentsCondition" />
     </select>
+
+    <select id="getStudentClassInfo" resultType="com.ym.mec.biz.dal.dto.StudentClassInfoDto">
+        SELECT
+               sr.user_id_ studentId,
+               sr.music_group_id_ musicGroupId,
+               sr.actual_subject_id_ subjectId,
+               cgsm.class_group_id_ classGroupId,
+               cgtm.user_id_ mainTeacherId
+        FROM student_registration sr
+             LEFT JOIN music_group mg ON sr.music_group_id_=mg.id_
+             LEFT JOIN class_group_student_mapper cgsm ON cgsm.group_type_='MUSIC' AND cgsm.music_group_id_=sr.music_group_id_ AND cgsm.user_id_=sr.user_id_
+             LEFT JOIN class_group cg ON cgsm.class_group_id_=cg.id_
+             LEFT JOIN class_group_teacher_mapper cgtm ON cgsm.class_group_id_=cgtm.class_group_id_ AND cgtm.teacher_role_='BISHOP'
+        WHERE sr.music_group_status_='NORMAL' AND mg.status_='PROGRESS' AND cgsm.status_='NORMAL' AND cg.type_='NORMAL' AND cg.del_flag_=0 AND cg.lock_flag_=0
+        <if test="studentIds!=null and studentIds.size()>0">
+            AND sr.user_id_ IN
+            <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
+                #{studentId}
+            </foreach>
+        </if>
+    </select>
 </mapper>

+ 4 - 0
mec-client-api/src/main/java/com/ym/mec/task/TaskRemoteService.java

@@ -173,4 +173,8 @@ public interface TaskRemoteService {
 	//乐保历史数据处理
 	@GetMapping("task/maintenanceOldDateAdd")
 	void maintenanceOldDateAdd();
+
+	//更新学员指导老师和声部信息
+	@GetMapping("/updateStudentTeacherAndSubject")
+	void updateStudentTeacherAndSubject();
 }

+ 5 - 0
mec-client-api/src/main/java/com/ym/mec/task/fallback/TaskRemoteServiceFallback.java

@@ -215,4 +215,9 @@ public class TaskRemoteServiceFallback implements TaskRemoteService {
     public void maintenanceOldDateAdd() {
 		logger.info("乐保历史数据处理失败");
     }
+
+	@Override
+	public void updateStudentTeacherAndSubject() {
+		logger.error("更新学员指导老师和声部信息失败");
+	}
 }

+ 19 - 0
mec-task/src/main/java/com/ym/mec/task/jobs/UpdateStudentTeacherAndSubjectTask.java

@@ -0,0 +1,19 @@
+package com.ym.mec.task.jobs;
+
+import com.ym.mec.task.TaskRemoteService;
+import com.ym.mec.task.core.BaseTask;
+import com.ym.mec.task.core.TaskException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class UpdateStudentTeacherAndSubjectTask extends BaseTask {
+
+    @Autowired
+    private TaskRemoteService taskRemoteService;
+
+    @Override
+    public void execute() throws TaskException {
+        taskRemoteService.updateStudentTeacherAndSubject();
+    }
+}

+ 6 - 0
mec-web/src/main/java/com/ym/mec/web/controller/TaskController.java

@@ -360,4 +360,10 @@ public class TaskController extends BaseController {
 	public void maintenanceOldDateAdd(){
 		studentInstrumentService.addOldStudentInstrument();
 	}
+
+	//更新学员指导老师和声部信息
+	@GetMapping("/updateStudentTeacherAndSubject")
+	public void updateStudentTeacherAndSubject(){
+		studentService.updateStudentTeacherAndSubject();
+	}
 }