|
@@ -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;
|
|
@@ -58,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";
|
|
|
|
|
@@ -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,32 +239,32 @@ 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());
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
List<Student> studentList = new ArrayList<>();
|
|
|
Set<String> phoneNos = new HashSet<>();
|
|
|
+ HashMap<Integer, String> rowIndexMsg = new LinkedHashMap<>();
|
|
|
for (int index = 0; index < students.size(); 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) {
|
|
|
// 空行过滤
|
|
|
continue;
|
|
|
}
|
|
|
// 避免导入数据存在大量错误数据,出现长时间等待
|
|
|
- if (sb.length() > IMPORT_ERR_MSG_MAX_LEN) {
|
|
|
+ if (rowIndexMsg.keySet().size() > IMPORT_ERR_MSG_MAX_LEN) {
|
|
|
break;
|
|
|
}
|
|
|
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()
|
|
|
.collect(Collectors.toMap(Organization::getId, Organization::getName));
|
|
|
|
|
@@ -258,33 +295,45 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
|
|
|
next.setUserId(legalStudentMap.get(key).getUserId());
|
|
|
return false;
|
|
|
}
|
|
|
+ rowIndexMsg.put(next.getUserId(), String.format("错误的学生姓名:%s,手机号:%s", next.getUsername(),
|
|
|
+ next.getPhone()));
|
|
|
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()
|
|
|
.flatMap(Collection::stream).collect(Collectors.toList());
|
|
|
- if (CollectionUtils.isEmpty(legalStudents)) {
|
|
|
- throw new BizException("未解析到合法的学生");
|
|
|
- }
|
|
|
|
|
|
// 处理导入数据中存在已经分享的数据再次入库
|
|
|
List<CourseShare> existShares = courseShareDao.selectByCourseId(courseId);
|
|
|
if (CollectionUtils.isNotEmpty(existShares)) {
|
|
|
Set<String> existShareKeys = existShares.stream()
|
|
|
.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 -> {
|
|
|
CourseShare courseShare = new CourseShare();
|
|
|
courseShare.setUserId(next.getUserId());
|
|
|
- courseShare.setTenantId(TenantIdThreadLocal.get());
|
|
|
+ courseShare.setTenantId(tenantId);
|
|
|
courseShare.setCourseId(courseId);
|
|
|
courseShare.setCreateTime(new Date());
|
|
|
courseShare.setCreateBy(sysUser.getId());
|
|
|
return courseShare;
|
|
|
}).collect(Collectors.toList());
|
|
|
batchInsert(courseShares);
|
|
|
- return String.format("成功导入%s条数据", courseShares.size());
|
|
|
+ return String.format("成功导入数据%s条%n重复数据%s条", courseShares.size(), rowIndexMsg.keySet().size());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -293,15 +342,18 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
|
|
|
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();
|
|
|
+ // 临时用作记录导入数据的行号
|
|
|
+ int currentRowIndex = rowIndex + 2;
|
|
|
+ student.setUserId(currentRowIndex);
|
|
|
if (row.size() == 0) {
|
|
|
return null;
|
|
|
}
|
|
|
Object orgName = row.get(STUDENT_TEMPLATE_FIELDS.get(0));
|
|
|
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 {
|
|
|
student.setOrganName(orgName.toString().trim());
|
|
|
}
|
|
@@ -309,19 +361,19 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
|
|
|
if (Objects.nonNull(studentName)) {
|
|
|
student.setUsername(studentName.toString().trim());
|
|
|
} 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));
|
|
|
if (Objects.nonNull(phoneNo)) {
|
|
|
String phone = phoneNo.toString().trim();
|
|
|
if (phoneNos.contains(phone)) {
|
|
|
- sb.append(String.format("第%s行手机号重复%n", (i + 2)));
|
|
|
+ rowIndexMsg.put(currentRowIndex, String.format("第%s行手机号重复%n", currentRowIndex));
|
|
|
return null;
|
|
|
}
|
|
|
student.setPhone(phone);
|
|
|
phoneNos.add(phone);
|
|
|
} else {
|
|
|
- sb.append(String.format("第%s行手机号数据格式错误%n", (i + 2)));
|
|
|
+ rowIndexMsg.put(currentRowIndex, String.format("第%s行手机号数据格式错误%n", currentRowIndex));
|
|
|
}
|
|
|
return student;
|
|
|
}
|
|
@@ -341,6 +393,7 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
|
|
|
}
|
|
|
return courseSchedule;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 根据用户id和课程id查询是否已经私有分享当前课程
|
|
|
*
|