|  | @@ -61,7 +61,7 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  |       * 导入数据错误信息最大长度
 |  |       * 导入数据错误信息最大长度
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  | -    private static final int IMPORT_ERR_MSG_MAX_LEN = 1000;
 |  | 
 | 
											
												
													
														|  | 
 |  | +    private static final int IMPORT_ERR_MSG_MAX_LEN = 50;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      private static final String TENANT_ID = "tenantId";
 |  |      private static final String TENANT_ID = "tenantId";
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -243,28 +243,28 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |          List<Organization> allOrgans = organizationDao.findAllOrgans(courseSchedule.getTenantId());
 |  |          List<Organization> allOrgans = organizationDao.findAllOrgans(courseSchedule.getTenantId());
 | 
											
												
													
														|  |          Set<String> orgNames = allOrgans.stream().map(Organization::getName).collect(Collectors.toSet());
 |  |          Set<String> orgNames = allOrgans.stream().map(Organization::getName).collect(Collectors.toSet());
 | 
											
												
													
														|  | -        StringBuilder sb = new StringBuilder();
 |  | 
 | 
											
												
													
														|  |          List<Student> studentList = new ArrayList<>();
 |  |          List<Student> studentList = new ArrayList<>();
 | 
											
												
													
														|  |          Set<String> phoneNos = new HashSet<>();
 |  |          Set<String> phoneNos = new HashSet<>();
 | 
											
												
													
														|  | 
 |  | +        HashMap<Integer, String> rowIndexMsg = new LinkedHashMap<>();
 | 
											
												
													
														|  |          for (int index = 0; index < students.size(); index++) {
 |  |          for (int index = 0; index < students.size(); index++) {
 | 
											
												
													
														|  |              Map<String, Object> row = students.get(index);
 |  |              Map<String, Object> row = students.get(index);
 | 
											
												
													
														|  | -            Student student = checkExcelData(sb, orgNames, phoneNos, index, row);
 |  | 
 | 
											
												
													
														|  | 
 |  | +            Student student = checkExcelData(rowIndexMsg, orgNames, phoneNos, index, row);
 | 
											
												
													
														|  |              if (student == null) {
 |  |              if (student == null) {
 | 
											
												
													
														|  |                  // 空行过滤
 |  |                  // 空行过滤
 | 
											
												
													
														|  |                  continue;
 |  |                  continue;
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |              // 避免导入数据存在大量错误数据,出现长时间等待
 |  |              // 避免导入数据存在大量错误数据,出现长时间等待
 | 
											
												
													
														|  | -            if (sb.length() > IMPORT_ERR_MSG_MAX_LEN) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if (rowIndexMsg.keySet().size() > IMPORT_ERR_MSG_MAX_LEN) {
 | 
											
												
													
														|  |                  break;
 |  |                  break;
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |              studentList.add(student);
 |  |              studentList.add(student);
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -        if (sb.length() > 0) {
 |  | 
 | 
											
												
													
														|  | -            throw new BizException(sb.toString());
 |  | 
 | 
											
												
													
														|  | 
 |  | +        if (!rowIndexMsg.keySet().isEmpty()) {
 | 
											
												
													
														|  | 
 |  | +            List<String> msgList = new ArrayList<>(rowIndexMsg.values());
 | 
											
												
													
														|  | 
 |  | +            throw new BizException(String.join("\n", msgList));
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          // 判断导入的学生数据是否在库中匹配到,过滤非法的学生数据
 |  |          // 判断导入的学生数据是否在库中匹配到,过滤非法的学生数据
 | 
											
												
													
														|  | -        SysUser sysUser = userService.getUser();
 |  | 
 | 
											
												
													
														|  |          Map<Integer, String> orgIdNameMap = allOrgans.stream()
 |  |          Map<Integer, String> orgIdNameMap = allOrgans.stream()
 | 
											
												
													
														|  |                  .collect(Collectors.toMap(Organization::getId, Organization::getName));
 |  |                  .collect(Collectors.toMap(Organization::getId, Organization::getName));
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -295,33 +295,45 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
 | 
											
												
													
														|  |                      next.setUserId(legalStudentMap.get(key).getUserId());
 |  |                      next.setUserId(legalStudentMap.get(key).getUserId());
 | 
											
												
													
														|  |                      return false;
 |  |                      return false;
 | 
											
												
													
														|  |                  }
 |  |                  }
 | 
											
												
													
														|  | 
 |  | +                rowIndexMsg.put(next.getUserId(), String.format("错误的学生姓名:%s,手机号:%s", next.getUsername(),
 | 
											
												
													
														|  | 
 |  | +                        next.getPhone()));
 | 
											
												
													
														|  |                  return true;
 |  |                  return true;
 | 
											
												
													
														|  |              });
 |  |              });
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        if (!rowIndexMsg.keySet().isEmpty()) {
 | 
											
												
													
														|  | 
 |  | +            List<String> msgList = new ArrayList<>(rowIndexMsg.values());
 | 
											
												
													
														|  | 
 |  | +            throw new BizException(String.join("\n", msgList));
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  |          List<Student> legalStudents = studentGroupByOrg.values().stream()
 |  |          List<Student> legalStudents = studentGroupByOrg.values().stream()
 | 
											
												
													
														|  |                  .flatMap(Collection::stream).collect(Collectors.toList());
 |  |                  .flatMap(Collection::stream).collect(Collectors.toList());
 | 
											
												
													
														|  | -        if (CollectionUtils.isEmpty(legalStudents)) {
 |  | 
 | 
											
												
													
														|  | -            throw new BizException("未解析到合法的学生");
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          // 处理导入数据中存在已经分享的数据再次入库
 |  |          // 处理导入数据中存在已经分享的数据再次入库
 | 
											
												
													
														|  |          List<CourseShare> existShares = courseShareDao.selectByCourseId(courseId);
 |  |          List<CourseShare> existShares = courseShareDao.selectByCourseId(courseId);
 | 
											
												
													
														|  |          if (CollectionUtils.isNotEmpty(existShares)) {
 |  |          if (CollectionUtils.isNotEmpty(existShares)) {
 | 
											
												
													
														|  |              Set<String> existShareKeys = existShares.stream()
 |  |              Set<String> existShareKeys = existShares.stream()
 | 
											
												
													
														|  |                      .map(next -> (next.getCourseId() + "_" + next.getUserId())).collect(Collectors.toSet());
 |  |                      .map(next -> (next.getCourseId() + "_" + next.getUserId())).collect(Collectors.toSet());
 | 
											
												
													
														|  | -            legalStudents.removeIf(next -> existShareKeys.contains(courseId + "_" + next.getUserId()));
 |  | 
 | 
											
												
													
														|  | 
 |  | +            legalStudents.removeIf(next -> {
 | 
											
												
													
														|  | 
 |  | +                if (existShareKeys.contains(courseId + "_" + next.getUserId())) {
 | 
											
												
													
														|  | 
 |  | +                    rowIndexMsg.put(next.getUserId(), "数据重复");
 | 
											
												
													
														|  | 
 |  | +                    return true;
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +                return false;
 | 
											
												
													
														|  | 
 |  | +            });
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | 
 |  | +        SysUser sysUser = userService.getUser();
 | 
											
												
													
														|  | 
 |  | +        Integer tenantId = TenantIdThreadLocal.get();
 | 
											
												
													
														|  |          List<CourseShare> courseShares = legalStudents.stream().map(next -> {
 |  |          List<CourseShare> courseShares = legalStudents.stream().map(next -> {
 | 
											
												
													
														|  |              CourseShare courseShare = new CourseShare();
 |  |              CourseShare courseShare = new CourseShare();
 | 
											
												
													
														|  |              courseShare.setUserId(next.getUserId());
 |  |              courseShare.setUserId(next.getUserId());
 | 
											
												
													
														|  | -            courseShare.setTenantId(TenantIdThreadLocal.get());
 |  | 
 | 
											
												
													
														|  | 
 |  | +            courseShare.setTenantId(tenantId);
 | 
											
												
													
														|  |              courseShare.setCourseId(courseId);
 |  |              courseShare.setCourseId(courseId);
 | 
											
												
													
														|  |              courseShare.setCreateTime(new Date());
 |  |              courseShare.setCreateTime(new Date());
 | 
											
												
													
														|  |              courseShare.setCreateBy(sysUser.getId());
 |  |              courseShare.setCreateBy(sysUser.getId());
 | 
											
												
													
														|  |              return courseShare;
 |  |              return courseShare;
 | 
											
												
													
														|  |          }).collect(Collectors.toList());
 |  |          }).collect(Collectors.toList());
 | 
											
												
													
														|  |          batchInsert(courseShares);
 |  |          batchInsert(courseShares);
 | 
											
												
													
														|  | -        return String.format("成功导入%s条数据", courseShares.size());
 |  | 
 | 
											
												
													
														|  | 
 |  | +        return String.format("成功导入数据%s条%n重复数据%s条", courseShares.size(), rowIndexMsg.keySet().size());
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @Override
 |  |      @Override
 | 
											
										
											
												
													
														|  | @@ -330,15 +342,18 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
 | 
											
												
													
														|  |          return true;
 |  |          return true;
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    private Student checkExcelData(StringBuilder sb, Set<String> orgNames, Set<String> phoneNos, int i, Map<String,
 |  | 
 | 
											
												
													
														|  | -            Object> row) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    private Student checkExcelData(HashMap<Integer, String> rowIndexMsg, Set<String> orgNames, Set<String> phoneNos,
 | 
											
												
													
														|  | 
 |  | +                                   int rowIndex, Map<String, Object> row) {
 | 
											
												
													
														|  |          Student student = new Student();
 |  |          Student student = new Student();
 | 
											
												
													
														|  | 
 |  | +        // 临时用作记录导入数据的行号
 | 
											
												
													
														|  | 
 |  | +        int currentRowIndex = rowIndex + 2;
 | 
											
												
													
														|  | 
 |  | +        student.setUserId(currentRowIndex);
 | 
											
												
													
														|  |          if (row.size() == 0) {
 |  |          if (row.size() == 0) {
 | 
											
												
													
														|  |              return null;
 |  |              return null;
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |          Object orgName = row.get(STUDENT_TEMPLATE_FIELDS.get(0));
 |  |          Object orgName = row.get(STUDENT_TEMPLATE_FIELDS.get(0));
 | 
											
												
													
														|  |          if (Objects.isNull(orgName) || !orgNames.contains(orgName.toString().trim())) {
 |  |          if (Objects.isNull(orgName) || !orgNames.contains(orgName.toString().trim())) {
 | 
											
												
													
														|  | -            sb.append(String.format("第%s行分部数据格式错误或者所属分部不存在%n", (i + 2)));
 |  | 
 | 
											
												
													
														|  | 
 |  | +            rowIndexMsg.put(currentRowIndex, String.format("第%s行分部数据格式错误或者所属分部不存在%n", currentRowIndex));
 | 
											
												
													
														|  |          } else {
 |  |          } else {
 | 
											
												
													
														|  |              student.setOrganName(orgName.toString().trim());
 |  |              student.setOrganName(orgName.toString().trim());
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
										
											
												
													
														|  | @@ -346,19 +361,19 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
 | 
											
												
													
														|  |          if (Objects.nonNull(studentName)) {
 |  |          if (Objects.nonNull(studentName)) {
 | 
											
												
													
														|  |              student.setUsername(studentName.toString().trim());
 |  |              student.setUsername(studentName.toString().trim());
 | 
											
												
													
														|  |          } else {
 |  |          } else {
 | 
											
												
													
														|  | -            sb.append(String.format("第%s行学生姓名数据格式错误%n", (i + 2)));
 |  | 
 | 
											
												
													
														|  | 
 |  | +            rowIndexMsg.put(currentRowIndex, String.format("第%s行学生姓名数据格式错误%n", currentRowIndex));
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |          Object phoneNo = row.get(STUDENT_TEMPLATE_FIELDS.get(2));
 |  |          Object phoneNo = row.get(STUDENT_TEMPLATE_FIELDS.get(2));
 | 
											
												
													
														|  |          if (Objects.nonNull(phoneNo)) {
 |  |          if (Objects.nonNull(phoneNo)) {
 | 
											
												
													
														|  |              String phone = phoneNo.toString().trim();
 |  |              String phone = phoneNo.toString().trim();
 | 
											
												
													
														|  |              if (phoneNos.contains(phone)) {
 |  |              if (phoneNos.contains(phone)) {
 | 
											
												
													
														|  | -                sb.append(String.format("第%s行手机号重复%n", (i + 2)));
 |  | 
 | 
											
												
													
														|  | 
 |  | +                rowIndexMsg.put(currentRowIndex, String.format("第%s行手机号重复%n", currentRowIndex));
 | 
											
												
													
														|  |                  return null;
 |  |                  return null;
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |              student.setPhone(phone);
 |  |              student.setPhone(phone);
 | 
											
												
													
														|  |              phoneNos.add(phone);
 |  |              phoneNos.add(phone);
 | 
											
												
													
														|  |          } else {
 |  |          } else {
 | 
											
												
													
														|  | -            sb.append(String.format("第%s行手机号数据格式错误%n", (i + 2)));
 |  | 
 | 
											
												
													
														|  | 
 |  | +            rowIndexMsg.put(currentRowIndex, String.format("第%s行手机号数据格式错误%n", currentRowIndex));
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |          return student;
 |  |          return student;
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
										
											
												
													
														|  | @@ -378,6 +393,7 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |          return courseSchedule;
 |  |          return courseSchedule;
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  |       * 根据用户id和课程id查询是否已经私有分享当前课程
 |  |       * 根据用户id和课程id查询是否已经私有分享当前课程
 | 
											
												
													
														|  |       *
 |  |       *
 |