|  | @@ -1,23 +1,20 @@
 | 
	
		
			
				|  |  |  package com.ym.mec.biz.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
	
		
			
				|  |  |  import com.google.common.collect.Lists;
 | 
	
		
			
				|  |  |  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.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;
 | 
	
	
		
			
				|  | @@ -26,11 +23,11 @@ import com.ym.mec.common.dal.BaseDAO;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.exception.BizException;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.filters.TenantIdThreadLocal;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.page.PageInfo;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.page.PageUtil;
 | 
	
		
			
				|  |  |  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;
 | 
	
	
		
			
				|  | @@ -83,12 +80,6 @@ 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
 | 
	
	
		
			
				|  | @@ -105,11 +96,11 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
 | 
	
		
			
				|  |  |          MapUtil.populateMap(params, courseShareDto);
 | 
	
		
			
				|  |  |          List<Integer> userIds = courseShareDto.getUserIds();
 | 
	
		
			
				|  |  |          if (params.keySet().isEmpty() && CollectionUtils.isEmpty(userIds)) {
 | 
	
		
			
				|  |  | -            throw new BizException("未选择参数");
 | 
	
		
			
				|  |  | +            throw new BizException("未选择搜索条件");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        List<SysUserDto> studentList = imLiveRoomPurviewDao.selectRoomPurviewStudent(params);
 | 
	
		
			
				|  |  | +        List<StudentManageListDto> studentList = courseShareDao.selectStudentByParam(params);
 | 
	
		
			
				|  |  |          List<Integer> userIdList = studentList.stream()
 | 
	
		
			
				|  |  | -                .map(SysUserDto::getUserId).map(Long::intValue).distinct().collect(Collectors.toList());
 | 
	
		
			
				|  |  | +                .map(StudentManageListDto::getUserId).distinct().collect(Collectors.toList());
 | 
	
		
			
				|  |  |          if (CollectionUtils.isNotEmpty(userIds)) {
 | 
	
		
			
				|  |  |              userIds.forEach(next -> {
 | 
	
		
			
				|  |  |                  if (!userIdList.contains(next)) {
 | 
	
	
		
			
				|  | @@ -150,46 +141,24 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public PageInfo<StudentManageListDto> queryCourseSharedStudent(CourseShareQueryInfo shareQueryInfo) {
 | 
	
		
			
				|  |  |          CourseSchedule courseSchedule = getCourseScheduleById(shareQueryInfo.getCourseId());
 | 
	
		
			
				|  |  | -        PageInfo<StudentManageListDto> pageInfo = new PageInfo<>(shareQueryInfo.getPage(), shareQueryInfo.getRows());
 | 
	
		
			
				|  |  |          // 查询该课程已经分享的学生列表
 | 
	
		
			
				|  |  | -        Map<String, Object> courseParam = new HashMap<>(2);
 | 
	
		
			
				|  |  | -        courseParam.put("courseId", shareQueryInfo.getCourseId());
 | 
	
		
			
				|  |  | -        courseParam.put(TENANT_ID, courseSchedule.getTenantId());
 | 
	
		
			
				|  |  | -        List<CourseShare> courseShareRecords = courseShareDao.findAll(courseParam);
 | 
	
		
			
				|  |  | -        if (CollectionUtils.isEmpty(courseShareRecords)) {
 | 
	
		
			
				|  |  | -            pageInfo.setTotal(0);
 | 
	
		
			
				|  |  | -            pageInfo.setRows(new ArrayList<>());
 | 
	
		
			
				|  |  | -            return pageInfo;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        // 查询学生列表
 | 
	
		
			
				|  |  | -        Map<String, Object> param = new HashMap<>(2);
 | 
	
		
			
				|  |  | +        Map<String, Object> param = new HashMap<>();
 | 
	
		
			
				|  |  | +        MapUtil.populateMap(param, shareQueryInfo);
 | 
	
		
			
				|  |  |          param.put(TENANT_ID, courseSchedule.getTenantId());
 | 
	
		
			
				|  |  | +        param.put("inExist", 1);
 | 
	
		
			
				|  |  | +        Page<StudentManageListDto> pageInfo = PageUtil.getPageInfo(param);
 | 
	
		
			
				|  |  | +        return PageUtil.pageInfo(courseShareDao.selectStudentByParam(pageInfo, param));
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public PageInfo<StudentManageListDto> queryAllCourseShareStudent(CourseShareQueryInfo shareQueryInfo) {
 | 
	
		
			
				|  |  | +        CourseSchedule courseSchedule = getCourseScheduleById(shareQueryInfo.getCourseId());
 | 
	
		
			
				|  |  | +        // 查询所有未分享的学生
 | 
	
		
			
				|  |  | +        Map<String, Object> param = new HashMap<>();
 | 
	
		
			
				|  |  |          MapUtil.populateMap(param, shareQueryInfo);
 | 
	
		
			
				|  |  | -        param.put("userIds", courseShareRecords.stream().map(CourseShare::getUserId).toArray());
 | 
	
		
			
				|  |  | -        int count = studentManageDao.countStudentByOrganId(param);
 | 
	
		
			
				|  |  | -        pageInfo.setTotal(count);
 | 
	
		
			
				|  |  | -        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;
 | 
	
		
			
				|  |  | +        param.put(TENANT_ID, courseSchedule.getTenantId());
 | 
	
		
			
				|  |  | +        Page<StudentManageListDto> pageInfo = PageUtil.getPageInfo(param);
 | 
	
		
			
				|  |  | +        return PageUtil.pageInfo(courseShareDao.selectStudentByParam(pageInfo, param));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
	
		
			
				|  | @@ -353,7 +322,7 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          Object orgName = row.get(STUDENT_TEMPLATE_FIELDS.get(0));
 | 
	
		
			
				|  |  |          if (Objects.isNull(orgName) || !orgNames.contains(orgName.toString().trim())) {
 | 
	
		
			
				|  |  | -            rowIndexMsg.put(currentRowIndex, String.format("第%s行分部数据格式错误或者所属分部不存在%n", currentRowIndex));
 | 
	
		
			
				|  |  | +            rowIndexMsg.put(currentRowIndex, String.format("第%s行分部数据格式错误或者所属分部不存在", currentRowIndex));
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  |              student.setOrganName(orgName.toString().trim());
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -361,19 +330,19 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
 | 
	
		
			
				|  |  |          if (Objects.nonNull(studentName)) {
 | 
	
		
			
				|  |  |              student.setUsername(studentName.toString().trim());
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  | -            rowIndexMsg.put(currentRowIndex, String.format("第%s行学生姓名数据格式错误%n", currentRowIndex));
 | 
	
		
			
				|  |  | +            rowIndexMsg.put(currentRowIndex, String.format("第%s行学生姓名数据格式错误", currentRowIndex));
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          Object phoneNo = row.get(STUDENT_TEMPLATE_FIELDS.get(2));
 | 
	
		
			
				|  |  |          if (Objects.nonNull(phoneNo)) {
 | 
	
		
			
				|  |  |              String phone = phoneNo.toString().trim();
 | 
	
		
			
				|  |  |              if (phoneNos.contains(phone)) {
 | 
	
		
			
				|  |  | -                rowIndexMsg.put(currentRowIndex, String.format("第%s行手机号重复%n", currentRowIndex));
 | 
	
		
			
				|  |  | +                rowIndexMsg.put(currentRowIndex, String.format("第%s行手机号重复", currentRowIndex));
 | 
	
		
			
				|  |  |                  return null;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              student.setPhone(phone);
 | 
	
		
			
				|  |  |              phoneNos.add(phone);
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  | -            rowIndexMsg.put(currentRowIndex, String.format("第%s行手机号数据格式错误%n", currentRowIndex));
 | 
	
		
			
				|  |  | +            rowIndexMsg.put(currentRowIndex, String.format("第%s行手机号数据格式错误", currentRowIndex));
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return student;
 | 
	
		
			
				|  |  |      }
 |