|
|
@@ -113,7 +113,6 @@ public class UserServiceImpl implements UserService {
|
|
|
|
|
|
/**
|
|
|
* 解析文件,批量创建用户。其中,文件必须包含姓名、邮箱、学号。
|
|
|
- * TODO 完善邮箱服务(需要公邮和stmp秘钥)
|
|
|
* @param file
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -146,6 +145,7 @@ public class UserServiceImpl implements UserService {
|
|
|
|
|
|
int res = userMapper.batchInsert(users);
|
|
|
if (res == 0) throw new MyException(500, "批量创建失败");
|
|
|
+
|
|
|
processUsers(users);
|
|
|
}
|
|
|
|
|
|
@@ -175,9 +175,16 @@ public class UserServiceImpl implements UserService {
|
|
|
|
|
|
int res = userMapper.batchInsert(users);
|
|
|
if (res == 0) throw new MyException(500, "批量创建失败");
|
|
|
+
|
|
|
processUsers(users);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 在指定Excel Cell中找到具体列名的索引值
|
|
|
+ * @param headerRow
|
|
|
+ * @param columnName
|
|
|
+ * @return
|
|
|
+ */
|
|
|
private int findColumnIndex(Row headerRow, String columnName) {
|
|
|
for (Cell cell : headerRow) {
|
|
|
if (cell.getStringCellValue().trim().equalsIgnoreCase(columnName)) {
|
|
|
@@ -187,6 +194,12 @@ public class UserServiceImpl implements UserService {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 在csv文件的header中找到具体列的索引值
|
|
|
+ * @param header
|
|
|
+ * @param columnName
|
|
|
+ * @return
|
|
|
+ */
|
|
|
private int findColumnIndex(String[] header, String columnName) {
|
|
|
for (int i = 0; i < header.length; i++) {
|
|
|
if (header[i].trim().equalsIgnoreCase(columnName)) {
|
|
|
@@ -196,6 +209,11 @@ public class UserServiceImpl implements UserService {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * TODO 通过邮箱服务,将初始密码发送给指定邮箱
|
|
|
+ * @param users
|
|
|
+ * @throws MessagingException
|
|
|
+ */
|
|
|
private void processUsers(List<User> users) throws MessagingException {
|
|
|
List<String> passwordStage = new ArrayList<>();
|
|
|
for(User user: users) {
|
|
|
@@ -207,7 +225,7 @@ public class UserServiceImpl implements UserService {
|
|
|
}
|
|
|
int res = userMapper.batchInsert(users);
|
|
|
if (res == 0) throw new MyException(500, "批量创建失败");
|
|
|
- // TODO 通过邮箱服务,将初始密码发送给指定邮箱
|
|
|
+
|
|
|
for (int i = 0; i < users.size(); i++) {
|
|
|
emailService.sendPasswordEmail(users.get(i).getOfficialEmail(), users.get(i).getName(), passwordStage.get(i));
|
|
|
}
|