|  | @@ -5,17 +5,19 @@ import com.ym.mec.auth.api.entity.SysUser;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.CourseScheduleDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.CourseScheduleStudentPaymentDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.CourseShareDao;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dao.ImLiveRoomPurviewDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.OrganizationDao;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.dao.StudentDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.StudentManageDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.SubjectDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.CourseShareDto;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.StudentManageListDto;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dto.SysUserDto;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.CourseSchedule;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.CourseScheduleStudentPayment;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.CourseShare;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.Organization;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.Student;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.entity.Subject;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.JoinCourseType;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.page.CourseShareQueryInfo;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.CourseShareService;
 | 
	
	
		
			
				|  | @@ -28,6 +30,7 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.collection.MapUtil;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.excel.POIUtil;
 | 
	
		
			
				|  |  |  import org.apache.commons.collections.CollectionUtils;
 | 
	
		
			
				|  |  | +import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
		
			
				|  |  |  import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
	
		
			
				|  | @@ -69,9 +72,6 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
 | 
	
		
			
				|  |  |      private StudentManageDao studentManageDao;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  | -    private StudentDao studentDao;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    @Autowired
 | 
	
		
			
				|  |  |      private SysUserService userService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
	
		
			
				|  | @@ -83,6 +83,12 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private OrganizationDao organizationDao;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private ImLiveRoomPurviewDao imLiveRoomPurviewDao;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private SubjectDao subjectDao;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      private static final List<String> STUDENT_TEMPLATE_FIELDS = Arrays.asList("分部", "学生姓名", "手机号");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -92,38 +98,53 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    public List<CourseShare> saveCourseShare(CourseShareDto courseShareDto) {
 | 
	
		
			
				|  |  | +    public Boolean saveCourseShare(CourseShareDto courseShareDto) {
 | 
	
		
			
				|  |  |          CourseSchedule courseSchedule = getCourseScheduleById(courseShareDto.getCourseId());
 | 
	
		
			
				|  |  | -        Integer userId = userService.getUserId();
 | 
	
		
			
				|  |  | -        if (CollectionUtils.isEmpty(courseShareDto.getUserIds())) {
 | 
	
		
			
				|  |  | -            // 不分享,清理数据并返回
 | 
	
		
			
				|  |  | -            courseShareDao.deleteByCourseId(courseShareDto.getCourseId());
 | 
	
		
			
				|  |  | -            return new ArrayList<>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        HashMap<String, Object> params = new HashMap<>();
 | 
	
		
			
				|  |  | +        MapUtil.populateMap(params, courseShareDto);
 | 
	
		
			
				|  |  | +        List<Integer> userIds = courseShareDto.getUserIds();
 | 
	
		
			
				|  |  | +        if (params.keySet().isEmpty() && CollectionUtils.isEmpty(userIds)) {
 | 
	
		
			
				|  |  | +            throw new BizException("未选择参数");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        List<SysUserDto> studentList = imLiveRoomPurviewDao.selectRoomPurviewStudent(params);
 | 
	
		
			
				|  |  | +        List<Integer> userIdList = studentList.stream()
 | 
	
		
			
				|  |  | +                .map(SysUserDto::getUserId).map(Long::intValue).distinct().collect(Collectors.toList());
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isNotEmpty(userIds)) {
 | 
	
		
			
				|  |  | +            userIds.forEach(next -> {
 | 
	
		
			
				|  |  | +                if (!userIdList.contains(next)) {
 | 
	
		
			
				|  |  | +                    userIdList.add(next);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // 处理已经分享过的数据
 | 
	
		
			
				|  |  | +        List<CourseShare> existShares = courseShareDao.selectByCourseId(courseShareDto.getCourseId());
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isNotEmpty(existShares)) {
 | 
	
		
			
				|  |  | +            List<Integer> sharedHistoryRecords = existShares.stream()
 | 
	
		
			
				|  |  | +                    .map(CourseShare::getUserId)
 | 
	
		
			
				|  |  | +                    .collect(Collectors.toList());
 | 
	
		
			
				|  |  | +            // 已经存在的数据不需要重复录入
 | 
	
		
			
				|  |  | +            userIdList.removeIf(sharedHistoryRecords::contains);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isEmpty(userIdList)) {
 | 
	
		
			
				|  |  | +            // 没有新加入的数据
 | 
	
		
			
				|  |  | +            return true;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        List<Student> students = studentDao.findByStudentIds(courseShareDto.getUserIds());
 | 
	
		
			
				|  |  | -        List<CourseShare> courseShares = students.stream().map(next -> {
 | 
	
		
			
				|  |  | +        Integer userId = userService.getUserId();
 | 
	
		
			
				|  |  | +        List<CourseShare> courseShares = userIdList.stream().map(next -> {
 | 
	
		
			
				|  |  |              CourseShare courseShare = new CourseShare();
 | 
	
		
			
				|  |  |              courseShare.setCourseId(courseShareDto.getCourseId());
 | 
	
		
			
				|  |  |              courseShare.setTenantId(courseSchedule.getTenantId());
 | 
	
		
			
				|  |  | -            courseShare.setUserId(next.getUserId());
 | 
	
		
			
				|  |  | +            courseShare.setUserId(next);
 | 
	
		
			
				|  |  |              courseShare.setCreateTime(new Date());
 | 
	
		
			
				|  |  |              courseShare.setCreateBy(userId);
 | 
	
		
			
				|  |  |              return courseShare;
 | 
	
		
			
				|  |  |          }).collect(Collectors.toList());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        // 处理已经分享过的数据
 | 
	
		
			
				|  |  | -        List<CourseShare> existShares = courseShareDao.selectByCourseId(courseShareDto.getCourseId());
 | 
	
		
			
				|  |  | -        if (CollectionUtils.isNotEmpty(existShares)) {
 | 
	
		
			
				|  |  | -            // 私有分享,删除历史数据
 | 
	
		
			
				|  |  | -            List<Integer> sharedHistoryRecords = existShares.stream()
 | 
	
		
			
				|  |  | -                    .map(CourseShare::getId)
 | 
	
		
			
				|  |  | -                    .collect(Collectors.toList());
 | 
	
		
			
				|  |  | -            courseShareDao.deleteByIds(sharedHistoryRecords);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  |          // 数据入库
 | 
	
		
			
				|  |  |          batchInsert(courseShares);
 | 
	
		
			
				|  |  | -        return courseShareDao.selectByCourseId(courseShareDto.getCourseId());
 | 
	
		
			
				|  |  | +        return true;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -146,12 +167,28 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
 | 
	
		
			
				|  |  |          param.put(TENANT_ID, courseSchedule.getTenantId());
 | 
	
		
			
				|  |  |          MapUtil.populateMap(param, shareQueryInfo);
 | 
	
		
			
				|  |  |          param.put("userIds", courseShareRecords.stream().map(CourseShare::getUserId).toArray());
 | 
	
		
			
				|  |  | -        int count = studentManageDao.countStudentAttendances(param);
 | 
	
		
			
				|  |  | +        int count = studentManageDao.countStudentByOrganId(param);
 | 
	
		
			
				|  |  |          pageInfo.setTotal(count);
 | 
	
		
			
				|  |  | -        if (count > 0) {
 | 
	
		
			
				|  |  | -            param.put("offset", pageInfo.getOffset());
 | 
	
		
			
				|  |  | -            pageInfo.setRows(studentManageDao.findStudentsByOrganId(param));
 | 
	
		
			
				|  |  | +        if (count == 0) {
 | 
	
		
			
				|  |  | +            pageInfo.setRows(new ArrayList<>());
 | 
	
		
			
				|  |  | +            return pageInfo;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        param.put("offset", pageInfo.getOffset());
 | 
	
		
			
				|  |  | +        List<StudentManageListDto> studentManageListDtos = studentManageDao.findStudentsByOrganId(param);
 | 
	
		
			
				|  |  | +        List<Subject> subjects = subjectDao.findAll(new HashMap<>());
 | 
	
		
			
				|  |  | +        Map<Integer, String> subjectIdNameMap = subjects.stream()
 | 
	
		
			
				|  |  | +                .collect(Collectors.toMap(Subject::getId, Subject::getName));
 | 
	
		
			
				|  |  | +        for (StudentManageListDto next : studentManageListDtos) {
 | 
	
		
			
				|  |  | +            String subjectIdList = next.getSubjectIdList();
 | 
	
		
			
				|  |  | +            if (StringUtils.isEmpty(subjectIdList)) {
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            List<String> subjectNames = Arrays.stream(subjectIdList.split(","))
 | 
	
		
			
				|  |  | +                    .map(id -> subjectIdNameMap.getOrDefault(Integer.valueOf(id), "")).distinct()
 | 
	
		
			
				|  |  | +                    .collect(Collectors.toList());
 | 
	
		
			
				|  |  | +            next.setSubjectName(String.join(",", subjectNames));
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        pageInfo.setRows(studentManageListDtos);
 | 
	
		
			
				|  |  |          return pageInfo;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -202,7 +239,7 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
 | 
	
		
			
				|  |  |              throw new BizException("文件格式错误,无法获取[student]页签数据");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          if (!students.get(0).keySet().containsAll(STUDENT_TEMPLATE_FIELDS)) {
 | 
	
		
			
				|  |  | -            throw new BizException("页签必须包含[分部/学生姓名/手机号]");
 | 
	
		
			
				|  |  | +            throw new BizException("首行标题必须包含[分部/学生姓名/手机号]字段");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          List<Organization> allOrgans = organizationDao.findAllOrgans(courseSchedule.getTenantId());
 | 
	
		
			
				|  |  |          Set<String> orgNames = allOrgans.stream().map(Organization::getName).collect(Collectors.toSet());
 |