Compare commits

..

2 Commits

  1. 105
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/service/impl/FunctionXTestServiceImpl.java

@ -65,6 +65,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
message.put("closeable", "false");
webSocketUtils.sendMessage(loginUser.getId(), message);
try {
//创建输出流对象
Workbook wb;
/*判断文件是xlsx结尾还是xls结尾 声明XSSF或HSSF对象*/
@ -97,8 +98,8 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
Sheet sheet = wb.getSheetAt(0);
//获取工作表页中行数据
//读取的总的行数
int lastRowIndex = sheet.getLastRowNum();
if (lastRowIndex < 1) {
int rowNum = sheet.getPhysicalNumberOfRows();
if (rowNum < 1) {
message.put("isError", "true");
message.put("status", "文件无内容或格式错误");
message.put("closeable", "true");
@ -109,7 +110,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
webSocketUtils.sendMessage(loginUser.getId(), message);
List<FunctionxTest> listVo = new ArrayList<>();
for (int i = 1; i <= lastRowIndex; i++) {
for (int i = 1; i <= rowNum; i++) {
Row row = sheet.getRow(i); // 行
if (row == null ) {
continue;
@ -130,6 +131,10 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
list.add(cellValue);
}
}
if(!funCheck(list)){
continue;
}
//------------接收-------------
FunctionxTest fun = new FunctionxTest();
fun.setPModuleName(list.get(0));
@ -213,7 +218,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
functionx.setCreateTime(new Date()); //创建日期
if (StringUtils.isBlank(moduleId)) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行对应模块不能为空");
message.put("status", "第" + i + "行数据对应模块不能为空");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("对应模块不能为空");
@ -246,7 +251,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
}
if (functionx.getModuleId() == null) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行对应模块有错误");
message.put("status", "第" + (i+1) + "行数据数据对应模块有错误");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("请输入正确的对应模块");
@ -255,7 +260,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
if (StringUtils.isBlank(functionName)) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行中文名称不能为空");
message.put("status", "第" + (i+1) + "行数据数据中文名称不能为空");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("中文名称不能为空");
@ -266,7 +271,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
int count = functionxService.count(queryWrapper1);
if (count > 0) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行中文名称在模块下重复");
message.put("status", "第" + (i+1) + "行数据数据中文名称在模块下重复");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("中文名称在模块下重复");
@ -275,7 +280,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
}
if (StringUtils.isBlank(functionEnName)) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行英文名称不能为空");
message.put("status", "第" + (i+1) + "行数据数据英文名称不能为空");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("英文名称不能为空");
@ -286,7 +291,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
int count = functionxService.count(queryWrapper2);
if (count > 0) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行英文名称在模块下重复");
message.put("status", "第" + (i+1) + "行数据数据英文名称在模块下重复");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("英文名称在模块下重复");
@ -298,7 +303,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
int type;
if (StringUtils.isBlank(functionType)) { // 空和null
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行功能类型不能为空");
message.put("status", "第" + (i+1) + "行数据数据功能类型不能为空");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能类型不能为空");
@ -330,7 +335,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
break;
default:
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行功能类型错误");
message.put("status", "第" + (i+1) + "行数据数据功能类型错误");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能类型错误");
@ -340,7 +345,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
// 模块编码+功能缩写;自动填充+手动修改
if (StringUtils.isBlank(functionCode)) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行功能编码不能为空");
message.put("status", "第" + (i+1) + "行数据数据功能编码不能为空");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能编码不能为空");
@ -353,7 +358,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
String str = moduleCode + firstChar;
if (!str.equals(functionCode)) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行功能编码错误");
message.put("status", "第" + (i+1) + "行数据数据功能编码错误");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能编码错误");
@ -368,12 +373,12 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
if (StringUtils.isNotBlank(userRole)) { // 用户角色
LambdaQueryWrapper<ProjectUserRole> queryWrapperUser = new LambdaQueryWrapper<>();
queryWrapperUser.eq(ProjectUserRole::getUserRole, userRole); // 是否匹配项目id?
int count = projectUserRoleService.count(queryWrapperUser);
if (count > 0)
functionx.setUserRole(userRole);
List<ProjectUserRole> list1 = projectUserRoleService.list(queryWrapperUser);
if (list1.size() > 0)
functionx.setUserRole(list1.get(0).getId());
else {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行请输入正确的用户角色");
message.put("status", "第" + (i+1) + "行数据数据请输入正确的用户角色");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("请输入正确的用户角色");
@ -383,20 +388,24 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
if (StringUtils.isNotBlank(managerUsers)) { // 责任人
String[] splitManager = managerUsers.split("\\s+|,|;|、");
int count = 0;
int count = 1;
String idManager = "";
for (String manager : splitManager) {
LambdaQueryWrapper<SysUser> queryWrapperUserName = new LambdaQueryWrapper<>();
queryWrapperUserName.eq(!manager.isEmpty(), SysUser::getUsername, manager);
count = sysUserService.count(queryWrapperUserName);
if (count == 0) {
List<SysUser> list1 = sysUserService.list(queryWrapperUserName);
if (list1.isEmpty()) {
count=0;
break;
}
idManager = idManager+list1.get(0).getId()+",";
}
if (count > 0){
functionx.setManagerUsers(idManager);
}
if (count > 0)
functionx.setManagerUsers(managerUsers);
else {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行请输入正确的责任人,并确保多个责任人之间用空格或者逗号、分号隔开");
message.put("status", "第" + (i+1) + "行数据数据请输入正确的责任人,并确保多个责任人之间用空格或者逗号、分号隔开");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("请输入正确的责任人,并确保多个责任人之间用空格或者逗号、分号隔开");
@ -406,7 +415,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
// 值:1、2、3、4、5,默认2
if (StringUtils.isBlank(workLevel)) { // 任务等级
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行任务等级不能为空");
message.put("status", "第" + (i+1) + "行数据数据任务等级不能为空");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("任务等级不能为空");
@ -414,7 +423,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
int integer = Integer.parseInt(workLevel);
if (integer < 1 || integer > 5) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行任务等级错误");
message.put("status", "第" + (i+1) + "行数据数据任务等级错误");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("任务等级错误");
@ -424,7 +433,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
if (StringUtils.isBlank(workStatus)) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行任务状态不能为空");
message.put("status", "第" + (i+1) + "行数据数据任务状态不能为空");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("任务状态不能为空");
@ -451,7 +460,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
break;
default:
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行任务状态错误");
message.put("status", "第" + (i+1) + "行数据数据任务状态错误");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("任务状态错误");
@ -464,7 +473,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
Boolean isTime = checkTime(publishTime);
if (!isTime) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行发布时间格式错误");
message.put("status", "第" + (i+1) + "行数据数据发布时间格式错误");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("发布时间错误,应为" + pattern + "类型");
@ -473,7 +482,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
date = dateFormat.parse(publishTime);
} catch (Exception e) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行发布时间错误");
message.put("status", "第" + (i+1) + "行数据数据发布时间错误");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("发布时间错误,应为" + pattern + "类型");
@ -486,7 +495,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
Boolean isTime = checkTime(startTime);
if (!isTime) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行开始时间格式错误");
message.put("status", "第" + (i+1) + "行数据数据开始时间格式错误");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("开始时间错误,应为" + pattern + "类型");
@ -495,7 +504,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
date = dateFormat.parse(startTime);
} catch (Exception e) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行开始时间错误");
message.put("status", "第" + (i+1) + "行数据数据开始时间错误");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("开始时间错误,应为" + pattern + "类型");
@ -513,7 +522,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
Boolean isTime = checkTime(submitTime);
if (!isTime) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行提交时间格式错误");
message.put("status", "第" + (i+1) + "行数据数据提交时间格式错误");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("提交时间格式错误,应为" + pattern + "类型");
@ -522,7 +531,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
date = dateFormat.parse(submitTime);
} catch (Exception e) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行提交时间时间错误");
message.put("status", "第" + (i+1) + "行数据数据提交时间时间错误");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("提交时间时间错误,应为" + pattern + "类型");
@ -533,7 +542,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
Double aDouble = Double.valueOf(realDuration);
if (aDouble < 0.1) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行实际时长错误");
message.put("status", "第" + (i+1) + "行数据数据实际时长错误");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("实际时长错误");
@ -543,7 +552,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
}
if (StringUtils.isBlank(status)) { // 空和null
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行功能状态不能为空");
message.put("status", "第" + (i+1) + "行数据数据功能状态不能为空");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能状态不能为空");
@ -561,7 +570,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
break;
default:
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行任务状态错误");
message.put("status", "第" + (i+1) + "行数据数据任务状态错误");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("任务状态错误");
@ -570,7 +579,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
}
if (StringUtils.isBlank(verisonStatus)) { // 空和null
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行版本状态不能为空");
message.put("status", "第" + (i+1) + "行数据数据版本状态不能为空");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("版本状态不能为空");
@ -585,7 +594,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
break;
default:
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行版本状态错误");
message.put("status", "第" + (i+1) + "行数据数据版本状态错误");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("版本状态错误");
@ -594,7 +603,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
}
if (StringUtils.isBlank(verison)) {
message.put("isError", "true");
message.put("status", "第" + (i + 2) + "行版本号不能为空");
message.put("status", "第" + (i+1) + "行数据数据版本号不能为空");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("版本号不能为空");
@ -616,12 +625,30 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
return Result.error("导入失败");
}
} catch (Exception e) {
message.put("isError", "true");
message.put("status", "导入失败,请重新检查上传文件内容和格式");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败");
}
message.put("status", "上传成功");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.OK("导入成功");
}
private boolean funCheck(List<String> list) {
for (int i=0;i<list.size();i++){
if(list.get(i)!=null && list.get(i).length()>0){
return true;
}
}
return false;
}
private boolean isSuccessInsert(LoginUser loginUser, Map<String, String> message, List<Functionx> listInsert) {
message.put("status", "导入数据中");
message.put("records", String.valueOf(listInsert.size()));

Loading…
Cancel
Save