refactor: 修改用户导入代码格式和注释
This commit is contained in:
@@ -38,10 +38,10 @@ import java.util.stream.Collectors;
|
|||||||
public class UserImportListener extends AnalysisEventListener<UserImportDTO> {
|
public class UserImportListener extends AnalysisEventListener<UserImportDTO> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* excel导入结果实体
|
* Excel 导入结果
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
private ExcelResult excelResult;
|
private final ExcelResult excelResult;
|
||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
@@ -50,7 +50,7 @@ public class UserImportListener extends AnalysisEventListener<UserImportDTO> {
|
|||||||
|
|
||||||
private final List<Role> roleList;
|
private final List<Role> roleList;
|
||||||
private final List<Dept> deptList;
|
private final List<Dept> deptList;
|
||||||
private final List<DictData> genderDataList;
|
private final List<DictData> genderList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前行
|
* 当前行
|
||||||
@@ -71,7 +71,7 @@ public class UserImportListener extends AnalysisEventListener<UserImportDTO> {
|
|||||||
.select(Role::getId, Role::getCode));
|
.select(Role::getId, Role::getCode));
|
||||||
this.deptList = SpringUtil.getBean(DeptService.class)
|
this.deptList = SpringUtil.getBean(DeptService.class)
|
||||||
.list(new LambdaQueryWrapper<Dept>().select(Dept::getId, Dept::getCode));
|
.list(new LambdaQueryWrapper<Dept>().select(Dept::getId, Dept::getCode));
|
||||||
this.genderDataList = SpringUtil.getBean(DictDataService.class)
|
this.genderList = SpringUtil.getBean(DictDataService.class)
|
||||||
.list(new LambdaQueryWrapper<DictData>().eq(DictData::getDictCode, DictCodeEnum.GENDER.getValue()));
|
.list(new LambdaQueryWrapper<DictData>().eq(DictData::getDictCode, DictCodeEnum.GENDER.getValue()));
|
||||||
this.excelResult = new ExcelResult();
|
this.excelResult = new ExcelResult();
|
||||||
}
|
}
|
||||||
@@ -92,29 +92,29 @@ public class UserImportListener extends AnalysisEventListener<UserImportDTO> {
|
|||||||
String errorMsg = "第" + currentRow + "行数据校验失败:";
|
String errorMsg = "第" + currentRow + "行数据校验失败:";
|
||||||
String username = userImportDTO.getUsername();
|
String username = userImportDTO.getUsername();
|
||||||
if (StrUtil.isBlank(username)) {
|
if (StrUtil.isBlank(username)) {
|
||||||
errorMsg +="用户名为空;";
|
errorMsg += "用户名为空;";
|
||||||
validation = false;
|
validation = false;
|
||||||
} else {
|
} else {
|
||||||
long count = userService.count(new LambdaQueryWrapper<User>().eq(User::getUsername, username));
|
long count = userService.count(new LambdaQueryWrapper<User>().eq(User::getUsername, username));
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
errorMsg +="用户名已存在;";
|
errorMsg += "用户名已存在;";
|
||||||
validation = false;
|
validation = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String nickname = userImportDTO.getNickname();
|
String nickname = userImportDTO.getNickname();
|
||||||
if (StrUtil.isBlank(nickname)) {
|
if (StrUtil.isBlank(nickname)) {
|
||||||
errorMsg +="用户昵称为空;";
|
errorMsg += "用户昵称为空;";
|
||||||
validation = false;
|
validation = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String mobile = userImportDTO.getMobile();
|
String mobile = userImportDTO.getMobile();
|
||||||
if (StrUtil.isBlank(mobile)) {
|
if (StrUtil.isBlank(mobile)) {
|
||||||
errorMsg +="手机号码为空;";
|
errorMsg += "手机号码为空;";
|
||||||
validation = false;
|
validation = false;
|
||||||
} else {
|
} else {
|
||||||
if (!Validator.isMobile(mobile)) {
|
if (!Validator.isMobile(mobile)) {
|
||||||
errorMsg +="手机号码不正确;";
|
errorMsg += "手机号码不正确;";
|
||||||
validation = false;
|
validation = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,7 +133,6 @@ public class UserImportListener extends AnalysisEventListener<UserImportDTO> {
|
|||||||
String deptCode = userImportDTO.getDeptCode();
|
String deptCode = userImportDTO.getDeptCode();
|
||||||
entity.setDeptId(getDeptId(deptCode));
|
entity.setDeptId(getDeptId(deptCode));
|
||||||
|
|
||||||
|
|
||||||
boolean saveResult = userService.save(entity);
|
boolean saveResult = userService.save(entity);
|
||||||
if (saveResult) {
|
if (saveResult) {
|
||||||
excelResult.setValidCount(excelResult.getValidCount() + 1);
|
excelResult.setValidCount(excelResult.getValidCount() + 1);
|
||||||
@@ -200,8 +199,12 @@ public class UserImportListener extends AnalysisEventListener<UserImportDTO> {
|
|||||||
*/
|
*/
|
||||||
private Integer getGenderValue(String genderLabel) {
|
private Integer getGenderValue(String genderLabel) {
|
||||||
if (StrUtil.isNotBlank(genderLabel)) {
|
if (StrUtil.isNotBlank(genderLabel)) {
|
||||||
return this.genderDataList.stream().filter(r -> r.getLabel().equals(genderLabel))
|
return this.genderList.stream()
|
||||||
.findFirst().map(DictData::getValue).map(Convert::toInt).orElse(null);
|
.filter(r -> r.getLabel().equals(genderLabel))
|
||||||
|
.findFirst()
|
||||||
|
.map(DictData::getValue)
|
||||||
|
.map(Convert::toInt)
|
||||||
|
.orElse(null);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user