feat: 企标个人权限导入
This commit is contained in:
@@ -17,30 +17,34 @@ import org.jeecgframework.poi.excel.annotation.Excel;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ESAuthUser {
|
public class ESAuthUser {
|
||||||
|
|
||||||
@Excel(name = "标准ID")
|
@Excel(name = "标准ID", width = 15, orderNum = "1")
|
||||||
@ApiModelProperty(value = "标准ID")
|
@ApiModelProperty(value = "标准ID")
|
||||||
private String standardId;
|
private String standardId;
|
||||||
|
|
||||||
@Excel(name = "标准号")
|
@Excel(name = "标准号", width = 15, orderNum = "2")
|
||||||
@ApiModelProperty(value = "标准号")
|
@ApiModelProperty(value = "标准号")
|
||||||
private String standardNumber;
|
private String standardNumber;
|
||||||
|
|
||||||
@Excel(name = "标准名称")
|
@Excel(name = "标准名称", width = 15, orderNum = "3")
|
||||||
@ApiModelProperty(value = "标准名称")
|
@ApiModelProperty(value = "标准名称")
|
||||||
private String standardName;
|
private String standardName;
|
||||||
|
|
||||||
@Excel(name = "标准分类")
|
@Excel(name = "标准分类", width = 15, orderNum = "4")
|
||||||
@ApiModelProperty(value = "标准分类")
|
@ApiModelProperty(value = "标准分类")
|
||||||
private String standardType;
|
private String standardType;
|
||||||
|
|
||||||
@Excel(name = "工号")
|
@Excel(name = "工号", width = 15, orderNum = "5")
|
||||||
@ApiModelProperty(value = "工号")
|
@ApiModelProperty(value = "工号")
|
||||||
private String workNumber;
|
private String workNumber;
|
||||||
|
|
||||||
@Excel(name = "姓名")
|
@Excel(name = "姓名", width = 15, orderNum = "6")
|
||||||
@ApiModelProperty(value = "姓名")
|
@ApiModelProperty(value = "姓名")
|
||||||
private String realName;
|
private String realName;
|
||||||
|
|
||||||
|
@Excel(name = "错误信息", width = 35, orderNum = "7")
|
||||||
|
@ApiModelProperty(value = "错误信息")
|
||||||
|
private String errorInfo;
|
||||||
|
|
||||||
public boolean isEmptyRow() {
|
public boolean isEmptyRow() {
|
||||||
return standardId == null &&
|
return standardId == null &&
|
||||||
standardNumber == null &&
|
standardNumber == null &&
|
||||||
|
|||||||
+37
-18
@@ -290,11 +290,12 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
log.info("导入失败数据条数:{}", errImportList.size());
|
log.info("导入失败数据条数:{}", errImportList.size());
|
||||||
this.exportWithExcel(response, errImportList, "ESAuthAllErrorData.xls");
|
this.exportWithExcel(response, errImportList, "ESAuthAllErrorData.xls");
|
||||||
}
|
}
|
||||||
log.info("企标所有人权限全部导入成功");
|
log.info("企标所有人权限导入结束");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void importOldESAuthUserExcel(MultipartFile file, HttpServletResponse response) {
|
public void importOldESAuthUserExcel(MultipartFile file, HttpServletResponse response) {
|
||||||
|
List<ESAuthUser> errImportList = new ArrayList<>();
|
||||||
// 验证文件是否为压缩格式file.getContentType()).contains("xls")
|
// 验证文件是否为压缩格式file.getContentType()).contains("xls")
|
||||||
if (!Objects.requireNonNull(file.getOriginalFilename()).contains("xls")) {
|
if (!Objects.requireNonNull(file.getOriginalFilename()).contains("xls")) {
|
||||||
throw new JeroBootException("文件格式不正确,请上传Excel。");
|
throw new JeroBootException("文件格式不正确,请上传Excel。");
|
||||||
@@ -319,7 +320,13 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
i--;
|
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();
|
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, LawsEnterpriseStandard> esMap = esList.stream().collect(Collectors.toMap(LawsEnterpriseStandard::getOldSystemId, o -> o));
|
||||||
Map<String, List<ESAuthUser>> auMap = datalist.stream().collect(Collectors.groupingBy(ESAuthUser::getStandardId));
|
Map<String, List<ESAuthUser>> auMap = datalist.stream().collect(Collectors.groupingBy(ESAuthUser::getStandardId));
|
||||||
List<SysUser> userlist = sysUserService.list();
|
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时间
|
// 构造一个2099-12-31的Date时间
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
@@ -348,28 +355,40 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
// 获取Date对象
|
// 获取Date对象
|
||||||
Date date = calendar.getTime();
|
Date date = calendar.getTime();
|
||||||
List<EnterpriseStandardAuthUser> authUserList = new ArrayList<>();
|
List<EnterpriseStandardAuthUser> authUserList = new ArrayList<>();
|
||||||
// 遍历esMap
|
// 遍历dataList 并且构造save语句
|
||||||
for (Map.Entry<String, LawsEnterpriseStandard> entry : esMap.entrySet()) {
|
for (ESAuthUser au : datalist) {
|
||||||
LawsEnterpriseStandard es = entry.getValue();
|
try {
|
||||||
String standardId = es.getId();
|
String oldStandardId = au.getStandardId();
|
||||||
List<ESAuthUser> auList = auMap.get(standardId);
|
LawsEnterpriseStandard es = esMap.get(oldStandardId);
|
||||||
if (auList != null) {
|
if (es == null) {
|
||||||
for (ESAuthUser au : auList) {
|
throw new JeroBootException("未找到该企标,老标准编号:" + au.getStandardNumber() + ",标准名称:" + au.getStandardName());
|
||||||
EnterpriseStandardAuthUser authUser = new EnterpriseStandardAuthUser();
|
|
||||||
authUser.setStandardId(es.getId());
|
|
||||||
String userId = userMap.get(au.getWorkNumber()).getId();
|
|
||||||
authUser.setAuthUser(userId);
|
|
||||||
authUser.setAuthExpireDate(date);
|
|
||||||
authUserList.add(authUser);
|
|
||||||
}
|
}
|
||||||
|
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());
|
esAuthUserService.saveBatch(authUserList, authUserList.size());
|
||||||
|
log.info("企标个人权限导入成功,成功条数{}", authUserList.size());
|
||||||
log.info("企标个人权限导入成功");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("导入失败;{}", e.getMessage());
|
log.error("导入失败;{}", e.getMessage());
|
||||||
}
|
}
|
||||||
|
if (!errImportList.isEmpty()) {
|
||||||
|
log.info("导入失败数据条数:{}", errImportList.size());
|
||||||
|
this.exportWithExcel(response, errImportList, "ESAuthUserErrorData.xls");
|
||||||
|
}
|
||||||
|
log.info("企标个人权限导入结束");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user