|
@@ -55,7 +55,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.text.MessageFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -362,7 +364,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public Boolean save(StudentWrapper.Student studentInfo) {
|
|
|
- if (studentInfo.getId() != null) {
|
|
|
+ if (studentInfo.getId() == null) {
|
|
|
return createStudent(studentInfo);
|
|
|
} else {
|
|
|
return updateStudent(studentInfo);
|
|
@@ -371,7 +373,8 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public void importStudentExcel(List<ExcelDataReaderProperty<StudentWrapper.StudentExport>> dataList, Long id) {
|
|
|
+ public void importStudentExcel(List<ExcelDataReaderProperty<StudentWrapper.StudentExport>> dataList,
|
|
|
+ Long tenantId, Long userId) {
|
|
|
if (dataList.isEmpty()) {
|
|
|
throw new BizException("导入数据不能为空");
|
|
|
}
|
|
@@ -384,12 +387,13 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
|
|
|
Integer rowIndex = next.getRowIndex();
|
|
|
StudentWrapper.StudentExport student = next.getClazz();
|
|
|
|
|
|
- student.checkValid().forEach(err -> errMsg.add(String.format("第%s行%s", rowIndex, err)));
|
|
|
+ int msgRowNo = rowIndex + 1;
|
|
|
+ student.checkValid().forEach(err -> errMsg.add(String.format("第%s行%s", msgRowNo, err)));
|
|
|
|
|
|
if (phoneMap.containsKey(student.getPhone().trim())) {
|
|
|
- errMsg.add(String.format("第%s行手机号重复", rowIndex));
|
|
|
+ errMsg.add(String.format("第%s行手机号重复", msgRowNo));
|
|
|
} else {
|
|
|
- phoneMap.put(student.getPhone().trim(), rowIndex);
|
|
|
+ phoneMap.put(student.getPhone().trim(), msgRowNo);
|
|
|
}
|
|
|
|
|
|
if (errMsg.size() > 100) {
|
|
@@ -397,7 +401,11 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- int row = 100;
|
|
|
+ if (!errMsg.isEmpty()) {
|
|
|
+ throw new BizException(String.join(",", errMsg));
|
|
|
+ }
|
|
|
+
|
|
|
+ int row = 50;
|
|
|
int page = 1;
|
|
|
List<List<String>> phonePartition = Lists.partition(new ArrayList<>(phoneMap.keySet()), row);
|
|
|
|
|
@@ -411,13 +419,30 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
|
|
|
|
|
|
if (!studentVos.isEmpty()) {
|
|
|
List<String> existPhoneList = studentVos.stream().map(StudentVo::getPhone).collect(Collectors.toList());
|
|
|
- existPhoneList.forEach(phone -> errMsg.add(String.format("第%s行手机号已经注册学生", phoneMap.get(phone))));
|
|
|
+ existPhoneList.forEach(phone -> {
|
|
|
+ if (phoneMap.containsKey(phone)) {
|
|
|
+ errMsg.add(String.format("第%s行手机号已经注册学生", phoneMap.get(phone)));
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!errMsg.isEmpty()) {
|
|
|
throw new BizException(String.join(",", errMsg));
|
|
|
}
|
|
|
+
|
|
|
+ for (ExcelDataReaderProperty<StudentWrapper.StudentExport> next : dataList) {
|
|
|
+ StudentWrapper.StudentExport studentExport = next.getClazz();
|
|
|
+ StudentWrapper.Student student = new StudentWrapper.Student();
|
|
|
+ student.setTenantId(tenantId);
|
|
|
+ student.setName(studentExport.getUserName());
|
|
|
+ student.setGender("1".equals(studentExport.getGender()) ? 1 : 0);
|
|
|
+ student.setSubjectId(studentExport.getSubjectId());
|
|
|
+
|
|
|
+ LocalDate birthday = LocalDate.parse(studentExport.getBirthday(), DateTimeFormatter.ISO_LOCAL_DATE);
|
|
|
+ student.setBirthdate(birthday);
|
|
|
+ save(student);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private Boolean updateStudent(StudentWrapper.Student studentInfo) {
|
|
@@ -426,14 +451,14 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
|
|
|
throw new BizException("学生信息不存在");
|
|
|
}
|
|
|
// 解绑
|
|
|
- if (!studentInfo.getBindTenant()) {
|
|
|
+ if (Boolean.FALSE.equals(studentInfo.getBindTenant())) {
|
|
|
studentInfo.setTenantId(-1L);
|
|
|
// 退群,删除好友
|
|
|
imUserFriendService.delFriendByTenantId(student.getTenantId(), student.getUserId());
|
|
|
}
|
|
|
// 手机号码修改
|
|
|
+ com.yonge.cooleshow.biz.dal.entity.SysUser sysUser = getOrCreateAccount(studentInfo);
|
|
|
if (!student.getPhone().equals(studentInfo.getPhone())) {
|
|
|
- com.yonge.cooleshow.biz.dal.entity.SysUser sysUser = getOrCreateAccount(studentInfo);
|
|
|
this.lambdaUpdate().set(Student::getSubjectId, studentInfo.getSubjectId())
|
|
|
.set(Student::getTenantId, studentInfo.getTenantId())
|
|
|
.set(Student::getUserId, sysUser.getId())
|
|
@@ -470,10 +495,12 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
|
|
|
com.yonge.cooleshow.biz.dal.entity.SysUser sysUser;
|
|
|
if (!sysUsers.isEmpty()) {
|
|
|
sysUser = sysUsers.get(0);
|
|
|
- if (this.getBaseMapper().selectById(sysUser.getId()) != null) {
|
|
|
+ if (!sysUser.getId().equals(studentInfo.getId()) &&
|
|
|
+ this.getBaseMapper().selectById(sysUser.getId()) != null) {
|
|
|
throw new BizException("手机号已经注册学生账号");
|
|
|
}
|
|
|
sysUser.setGender(studentInfo.getGender());
|
|
|
+ sysUser.setUsername(studentInfo.getName());
|
|
|
sysUser.setBirthdate(studentInfo.getBirthdate());
|
|
|
String userType = sysUser.getUserType();
|
|
|
String studentUserType = "STUDENT";
|
|
@@ -491,6 +518,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
|
|
|
sysUser.setGender(studentInfo.getGender());
|
|
|
sysUser.setUserType("STUDENT");
|
|
|
sysUser.setBirthdate(studentInfo.getBirthdate());
|
|
|
+ sysUser.setUsername(studentInfo.getName());
|
|
|
|
|
|
String newPassword = MessageFormat.format("klxjg{0}", studentInfo.getPhone().substring(7));
|
|
|
String password = new BCryptPasswordEncoder().encode(newPassword);
|