|  | @@ -2,15 +2,11 @@ package com.ym.mec.biz.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.io.IOException;
 | 
	
		
			
				|  |  |  import java.math.BigDecimal;
 | 
	
		
			
				|  |  | -import java.util.ArrayList;
 | 
	
		
			
				|  |  | -import java.util.Arrays;
 | 
	
		
			
				|  |  | -import java.util.Date;
 | 
	
		
			
				|  |  | -import java.util.HashSet;
 | 
	
		
			
				|  |  | -import java.util.Iterator;
 | 
	
		
			
				|  |  | -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 org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
	
		
			
				|  | @@ -49,6 +45,7 @@ import com.ym.mec.common.exception.BizException;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.service.impl.BaseServiceImpl;
 | 
	
		
			
				|  |  |  import com.ym.mec.im.ImFeignService;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.http.HttpUtil;
 | 
	
		
			
				|  |  | +import org.springframework.util.CollectionUtils;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @Service
 | 
	
		
			
				|  |  |  public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, ClassGroupStudentMapper> implements ClassGroupStudentMapperService {
 | 
	
	
		
			
				|  | @@ -78,6 +75,8 @@ public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, Cl
 | 
	
		
			
				|  |  |      private TeacherDefaultMusicGroupSalaryService teacherDefaultMusicGroupSalaryService;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private StudentDao studentDao;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private CourseScheduleDao courseScheduleDao;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private static String holidayUrl = "http://tool.bitefu.net/jiari/?d=";
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -357,11 +356,77 @@ public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, Cl
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    public void updateClassGroupStudents(Long classGroupId, String studentIds) {
 | 
	
		
			
				|  |  | +    public void updateClassGroupStudents(Long classGroupId, Set<Integer> studentIds) {
 | 
	
		
			
				|  |  | +        ClassGroup classGroup = classGroupService.get(classGroupId.intValue());
 | 
	
		
			
				|  |  | +        if(Objects.isNull(classGroup)){
 | 
	
		
			
				|  |  | +            throw new BizException("班级信息错误");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          List<ClassGroupStudentMapper> classGroupStudents = classGroupStudentMapperDao.findAllByClassGroup(classGroupId);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        List<Integer> allStudentIds = new ArrayList<>();
 | 
	
		
			
				|  |  | -        List<Integer> addStudentIds = new ArrayList<>();
 | 
	
		
			
				|  |  | -        List<Integer> removeStudentIds = new ArrayList<>();
 | 
	
		
			
				|  |  | +        Set<Integer> allStudentIds = new HashSet<>();
 | 
	
		
			
				|  |  | +        Set<Integer> oldStudentIds = new HashSet<>();
 | 
	
		
			
				|  |  | +        Set<Integer> oldNormalStudentIds = new HashSet<>();
 | 
	
		
			
				|  |  | +        Set<Integer> addStudentIds;
 | 
	
		
			
				|  |  | +        Set<Integer> removeStudentIds;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if(!CollectionUtils.isEmpty(studentIds)){
 | 
	
		
			
				|  |  | +            allStudentIds = studentIds;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if(!CollectionUtils.isEmpty(classGroupStudents)){
 | 
	
		
			
				|  |  | +            oldStudentIds = classGroupStudents.stream().map(ClassGroupStudentMapper::getUserId).collect(Collectors.toSet());
 | 
	
		
			
				|  |  | +            oldNormalStudentIds = classGroupStudents.stream().filter(s -> ClassGroupStudentStatusEnum.NORMAL.equals(s.getStatus())).map(ClassGroupStudentMapper::getUserId).collect(Collectors.toSet());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Set<Integer> repeatStudentIds = allStudentIds.stream().filter(oldNormalStudentIds::contains).collect(Collectors.toSet());
 | 
	
		
			
				|  |  | +        addStudentIds = allStudentIds.stream().filter(id -> !repeatStudentIds.contains(id)).collect(Collectors.toSet());
 | 
	
		
			
				|  |  | +        removeStudentIds = oldNormalStudentIds.stream().filter(id -> !repeatStudentIds.contains(id)).collect(Collectors.toSet());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        for (ClassGroupStudentMapper classGroupStudent : classGroupStudents) {
 | 
	
		
			
				|  |  | +            if(addStudentIds.contains(classGroupStudent.getUserId())){
 | 
	
		
			
				|  |  | +                classGroupStudent.setStatus(ClassGroupStudentStatusEnum.NORMAL);
 | 
	
		
			
				|  |  | +            }else if(removeStudentIds.contains(classGroupStudent.getUserId())){
 | 
	
		
			
				|  |  | +                classGroupStudent.setStatus(ClassGroupStudentStatusEnum.QUIT);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        classGroupStudentMapperDao.batchUpdate(classGroupStudents);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Date now = new Date();
 | 
	
		
			
				|  |  | +        List<ClassGroupStudentMapper> classGroupStudentMappers = new ArrayList<>();
 | 
	
		
			
				|  |  | +        for (Integer addStudentId : addStudentIds) {
 | 
	
		
			
				|  |  | +            if(oldStudentIds.contains(addStudentId)){
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            ClassGroupStudentMapper classGroupStudentMapper = new ClassGroupStudentMapper();
 | 
	
		
			
				|  |  | +            classGroupStudentMapper.setMusicGroupId(classGroup.getMusicGroupId());
 | 
	
		
			
				|  |  | +            classGroupStudentMapper.setClassGroupId(classGroupId.intValue());
 | 
	
		
			
				|  |  | +            classGroupStudentMapper.setUserId(addStudentId);
 | 
	
		
			
				|  |  | +            classGroupStudentMapper.setCreateTime(now);
 | 
	
		
			
				|  |  | +            classGroupStudentMapper.setStatus(ClassGroupStudentStatusEnum.NORMAL);
 | 
	
		
			
				|  |  | +            classGroupStudentMapper.setGroupType(GroupType.MUSIC);
 | 
	
		
			
				|  |  | +            classGroupStudentMappers.add(classGroupStudentMapper);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (classGroupStudentMappers.size() > 0) {
 | 
	
		
			
				|  |  | +            classGroupStudentMapperDao.classGroupStudentsInsert(classGroupStudentMappers);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        classGroupService.updateClassStudentNum(classGroupId.intValue(), allStudentIds.size());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<CourseSchedule> classGroupNotStartCourse = courseScheduleDao.getClassGroupNotStartCourse(classGroupId);
 | 
	
		
			
				|  |  | +        if(CollectionUtils.isEmpty(classGroupNotStartCourse)){
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<Long> courseIds = classGroupNotStartCourse.stream().map(CourseSchedule::getId).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if(!CollectionUtils.isEmpty(removeStudentIds)){
 | 
	
		
			
				|  |  | +            courseScheduleDao.deleteMusicGroupCourseSchedulesWithStudents(courseIds, new ArrayList<>(removeStudentIds));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if(!CollectionUtils.isEmpty(addStudentIds)){
 | 
	
		
			
				|  |  | +            courseScheduleStudentPaymentService.createForMusicGroup(classGroup.getMusicGroupId(), classGroupNotStartCourse, new ArrayList<>(addStudentIds));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 |