feat: 企标个人权限导入

This commit is contained in:
2023-11-30 10:21:05 +08:00
parent 05ce07cc37
commit 222a03d6ed
2 changed files with 47 additions and 24 deletions
@@ -17,30 +17,34 @@ import org.jeecgframework.poi.excel.annotation.Excel;
@AllArgsConstructor
public class ESAuthUser {
@Excel(name = "标准ID")
@Excel(name = "标准ID", width = 15, orderNum = "1")
@ApiModelProperty(value = "标准ID")
private String standardId;
@Excel(name = "标准号")
@Excel(name = "标准号", width = 15, orderNum = "2")
@ApiModelProperty(value = "标准号")
private String standardNumber;
@Excel(name = "标准名称")
@Excel(name = "标准名称", width = 15, orderNum = "3")
@ApiModelProperty(value = "标准名称")
private String standardName;
@Excel(name = "标准分类")
@Excel(name = "标准分类", width = 15, orderNum = "4")
@ApiModelProperty(value = "标准分类")
private String standardType;
@Excel(name = "工号")
@Excel(name = "工号", width = 15, orderNum = "5")
@ApiModelProperty(value = "工号")
private String workNumber;
@Excel(name = "姓名")
@Excel(name = "姓名", width = 15, orderNum = "6")
@ApiModelProperty(value = "姓名")
private String realName;
@Excel(name = "错误信息", width = 35, orderNum = "7")
@ApiModelProperty(value = "错误信息")
private String errorInfo;
public boolean isEmptyRow() {
return standardId == null &&
standardNumber == null &&
@@ -290,11 +290,12 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
log.info("导入失败数据条数:{}", errImportList.size());
this.exportWithExcel(response, errImportList, "ESAuthAllErrorData.xls");
}
log.info("企标所有人权限全部导入成功");
log.info("企标所有人权限导入结束");
}
@Override
public void importOldESAuthUserExcel(MultipartFile file, HttpServletResponse response) {
List<ESAuthUser> errImportList = new ArrayList<>();
// 验证文件是否为压缩格式file.getContentType()).contains("xls")
if (!Objects.requireNonNull(file.getOriginalFilename()).contains("xls")) {
throw new JeroBootException("文件格式不正确,请上传Excel。");
@@ -319,7 +320,13 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
i--;
}
}
log.info("获取数据成功,数据条数:{}", datalist.size());
// 只取用企标数据
// 区分数据
log.info("获取数据成功,总数据条数:{}", datalist.size());
// 删选标准分类不为空且是企标的数据
datalist = datalist.stream().filter(data -> StrUtil.isNotBlank(data.getStandardType()))
.filter(data -> data.getStandardType().startsWith("企业标准")).collect(Collectors.toList());
log.info("企标相关数据条数:{}", datalist.size());
// 获取当前时间戳(毫秒)
long endTime = System.currentTimeMillis();
// 计算执行时间(毫秒)
@@ -332,7 +339,7 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
Map<String, LawsEnterpriseStandard> esMap = esList.stream().collect(Collectors.toMap(LawsEnterpriseStandard::getOldSystemId, o -> o));
Map<String, List<ESAuthUser>> auMap = datalist.stream().collect(Collectors.groupingBy(ESAuthUser::getStandardId));
List<SysUser> userlist = sysUserService.list();
Map<String, SysUser> userMap = userlist.stream().collect(Collectors.toMap(SysUser::getUsername, o -> o));
Map<String, SysUser> userMap = userlist.stream().collect(Collectors.toMap(u -> u.getRealname() + u.getUsername(), o -> o));
// 构造一个2099-12-31的Date时间
Calendar calendar = Calendar.getInstance();
@@ -348,28 +355,40 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
// 获取Date对象
Date date = calendar.getTime();
List<EnterpriseStandardAuthUser> authUserList = new ArrayList<>();
// 遍历esMap
for (Map.Entry<String, LawsEnterpriseStandard> entry : esMap.entrySet()) {
LawsEnterpriseStandard es = entry.getValue();
String standardId = es.getId();
List<ESAuthUser> auList = auMap.get(standardId);
if (auList != null) {
for (ESAuthUser au : auList) {
EnterpriseStandardAuthUser authUser = new EnterpriseStandardAuthUser();
authUser.setStandardId(es.getId());
String userId = userMap.get(au.getWorkNumber()).getId();
authUser.setAuthUser(userId);
authUser.setAuthExpireDate(date);
authUserList.add(authUser);
// 遍历dataList 并且构造save语句
for (ESAuthUser au : datalist) {
try {
String oldStandardId = au.getStandardId();
LawsEnterpriseStandard es = esMap.get(oldStandardId);
if (es == null) {
throw new JeroBootException("未找到该企标,老标准编号:" + au.getStandardNumber() + ",标准名称:" + au.getStandardName());
}
String standardId = es.getId();
// 获取用户
SysUser user = userMap.get(au.getRealName() + au.getWorkNumber());
if (user == null) {
throw new JeroBootException("未找到该用户,姓名:" + au.getRealName() + ",工号:" + au.getWorkNumber() + "老标准编号:" + au.getStandardNumber());
}
EnterpriseStandardAuthUser esAu = new EnterpriseStandardAuthUser();
esAu.setStandardId(standardId);
esAu.setAuthUser(user.getId());
esAu.setAuthExpireDate(date);
authUserList.add(esAu);
} catch (Exception e) {
au.setErrorInfo(e.getMessage());
errImportList.add(au);
}
}
esAuthUserService.saveBatch(authUserList, authUserList.size());
log.info("企标个人权限导入成功");
log.info("企标个人权限导入成功,成功条数{}", authUserList.size());
} catch (Exception e) {
log.error("导入失败;{}", e.getMessage());
}
if (!errImportList.isEmpty()) {
log.info("导入失败数据条数:{}", errImportList.size());
this.exportWithExcel(response, errImportList, "ESAuthUserErrorData.xls");
}
log.info("企标个人权限导入结束");
}
@Override