|
@@ -13,6 +13,7 @@ import cn.com.qmth.examcloud.tool.utils.JsonMapper;
|
|
|
import cn.com.qmth.examcloud.tool.utils.StatusException;
|
|
|
import cn.com.qmth.examcloud.tool.vo.user.User;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
@@ -38,27 +39,25 @@ public class BatchCreateUserTask implements TaskService {
|
|
|
|
|
|
@Override
|
|
|
public void start(TaskEntity task) {
|
|
|
- User user = LoginSessionManager.getLoginSession(task.getUserToken());
|
|
|
- if (user == null) {
|
|
|
+ User loginUser = LoginSessionManager.getLoginSession(task.getUserToken());
|
|
|
+ if (loginUser == null) {
|
|
|
throw new StatusException("用户未登录!");
|
|
|
}
|
|
|
|
|
|
- List<UserInfo> userList = new ArrayList<>();
|
|
|
- //todo
|
|
|
- this.execute(user, userList, task);
|
|
|
+ this.execute(loginUser, task);
|
|
|
}
|
|
|
|
|
|
- public void start(User user) {
|
|
|
- final String filePath = "C:/Users/deason/Desktop/用户账号批量创建模板.xlsx";
|
|
|
+ private void execute(User loginUser, TaskEntity task) {
|
|
|
+ JsonNode jsonParams = new JsonMapper().getNode(task.getParams());
|
|
|
+ if (jsonParams == null) {
|
|
|
+ throw new StatusException("任务参数解析错误!");
|
|
|
+ }
|
|
|
|
|
|
+ String filePath = jsonParams.get("filePath").asText("");
|
|
|
UserInfoListener dataListener = new UserInfoListener();
|
|
|
EasyExcel.read(filePath, UserInfo.class, dataListener).sheet().doRead();
|
|
|
+ List<UserInfo> userList = dataListener.getList();
|
|
|
|
|
|
- TaskEntity task = new TaskEntity();
|
|
|
- this.execute(user, dataListener.getList(), task);
|
|
|
- }
|
|
|
-
|
|
|
- private void execute(User loginUser, List<UserInfo> userList, TaskEntity task) {
|
|
|
Map<String, Long> roleMaps = this.queryRoles(loginUser);
|
|
|
|
|
|
int total = userList.size();
|
|
@@ -114,7 +113,9 @@ public class BatchCreateUserTask implements TaskService {
|
|
|
log.info("共{}条 第{}条 已执行!{}", total, i + 1, user.getLoginName());
|
|
|
}
|
|
|
|
|
|
- log.info("共{}条 成功{}条 失败{}条!", total, total - failCount, failCount);
|
|
|
+ String msg = String.format("共%s条 成功%s条 失败%s条!", total, total - failCount, failCount);
|
|
|
+ log.info(msg);
|
|
|
+ task.setDescription(msg);
|
|
|
}
|
|
|
|
|
|
private Map<String, Long> queryRoles(User loginUser) {
|