diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/service/impl/FunctionXTestServiceImpl.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/service/impl/FunctionXTestServiceImpl.java index 896db75..1ea2434 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/service/impl/FunctionXTestServiceImpl.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/service/impl/FunctionXTestServiceImpl.java @@ -65,563 +65,590 @@ public class FunctionXTestServiceImpl extends ServiceImpl listVo = new ArrayList<>(); - for (int i = 1; i <= lastRowIndex; i++) { - Row row = sheet.getRow(i); // 行 - if (row == null ) { - continue; - } else { - short lastCellNum = row.getLastCellNum(); - List list = new ArrayList<>(); - for (int j = 0; j < lastCellNum; j++) { - Cell cell = row.getCell(j); // 单元格 - if (cell == null) { - list.add(null); - } else { - FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); - DataFormatter formatter = new DataFormatter(); - //单元格不设置数字格式 - cell.setCellStyle(null); + List listVo = new ArrayList<>(); + for (int i = 1; i <= rowNum; i++) { + Row row = sheet.getRow(i); // 行 + if (row == null ) { + continue; + } else { + short lastCellNum = row.getLastCellNum(); + List list = new ArrayList<>(); + for (int j = 0; j < lastCellNum; j++) { + Cell cell = row.getCell(j); // 单元格 + if (cell == null) { + list.add(null); + } else { + FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); + DataFormatter formatter = new DataFormatter(); + //单元格不设置数字格式 + cell.setCellStyle(null); + + String cellValue = formatter.formatCellValue(cell,evaluator); + list.add(cellValue); + } + } - String cellValue = formatter.formatCellValue(cell,evaluator); - list.add(cellValue); + if(!funCheck(list)){ + continue; } + //------------接收------------- + FunctionxTest fun = new FunctionxTest(); + fun.setPModuleName(list.get(0)); + fun.setModuleName(list.get(1)); // 对应模块 + fun.setFunctionName(list.get(2)); // 中文名称 + fun.setFunctionEnName(list.get(3)); // 英文名称 + fun.setFunctionCode(list.get(4)); // 功能编码 + fun.setFunctionType(list.get(5)); // 功能类型 + fun.setPmDescribe(list.get(6)); // 功能描述 + fun.setUserRole(list.get(7)); // 用户角色 + fun.setManagerUsers(list.get(8)); // 责任人 + fun.setWorkLevel(list.get(9)); // 任务等级 + fun.setWorkStatus(list.get(10)); // 任务状态 + fun.setPublishTime(list.get(11)); // 发布时间 + fun.setStartTime(list.get(12)); // 开始时间 + fun.setDuration(list.get(13)); // 任务时长 + fun.setSubmitTime(list.get(14)); // 提交时间 + fun.setRealDuration(list.get(15)); // 实际时长 + fun.setStatus(list.get(16)); // 功能状态 + fun.setVerisonStatus(list.get(17)); // 版本状态 + fun.setVerison(list.get(18)); // 版本号 + fun.setCreatName(username); + + listVo.add(fun); } - //------------接收------------- - FunctionxTest fun = new FunctionxTest(); - fun.setPModuleName(list.get(0)); - fun.setModuleName(list.get(1)); // 对应模块 - fun.setFunctionName(list.get(2)); // 中文名称 - fun.setFunctionEnName(list.get(3)); // 英文名称 - fun.setFunctionCode(list.get(4)); // 功能编码 - fun.setFunctionType(list.get(5)); // 功能类型 - fun.setPmDescribe(list.get(6)); // 功能描述 - fun.setUserRole(list.get(7)); // 用户角色 - fun.setManagerUsers(list.get(8)); // 责任人 - fun.setWorkLevel(list.get(9)); // 任务等级 - fun.setWorkStatus(list.get(10)); // 任务状态 - fun.setPublishTime(list.get(11)); // 发布时间 - fun.setStartTime(list.get(12)); // 开始时间 - fun.setDuration(list.get(13)); // 任务时长 - fun.setSubmitTime(list.get(14)); // 提交时间 - fun.setRealDuration(list.get(15)); // 实际时长 - fun.setStatus(list.get(16)); // 功能状态 - fun.setVerisonStatus(list.get(17)); // 版本状态 - fun.setVerison(list.get(18)); // 版本号 - fun.setCreatName(username); - - listVo.add(fun); } - } - boolean isSuccessSave = this.saveBatch(listVo); - if (!isSuccessSave) { - message.put("isError", "true"); - message.put("status", "文件读入失败"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("文件读入失败"); - } + boolean isSuccessSave = this.saveBatch(listVo); + if (!isSuccessSave) { + message.put("isError", "true"); + message.put("status", "文件读入失败"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("文件读入失败"); + } - message.put("status", "数据校验"); - webSocketUtils.sendMessage(loginUser.getId(), message); + message.put("status", "数据校验"); + webSocketUtils.sendMessage(loginUser.getId(), message); - //************************具体字段校验****************************** - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(username != null, FunctionxTest::getCreatName, username); - List list = this.list(queryWrapper); + //************************具体字段校验****************************** + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(username != null, FunctionxTest::getCreatName, username); + List list = this.list(queryWrapper); - boolean remove = this.remove(queryWrapper); - if (!remove) { - log.error("临时表删除错误!"); - } + boolean remove = this.remove(queryWrapper); + if (!remove) { + log.error("临时表删除错误!"); + } - // 对应模块校验 - List modulexList = modulexService.list(); - - List listInsert = new ArrayList<>(); // 正式插入 - String pattern = "yyyy-MM-dd HH:mm:ss"; - SimpleDateFormat dateFormat = new SimpleDateFormat(pattern); - - for (int i = 0; i < list.size(); i++) { - FunctionxTest function = list.get(i); - Functionx functionx = new Functionx(); - String pModuleId = function.getPModuleName(); - String moduleId = function.getModuleName(); - String functionName = function.getFunctionName(); - String functionEnName = function.getFunctionEnName(); - String functionCode = function.getFunctionCode(); - String functionType = function.getFunctionType(); - String pmDescribe = function.getPmDescribe(); - String userRole = function.getUserRole(); - String managerUsers = function.getManagerUsers(); - String workLevel = function.getWorkLevel(); - String workStatus = function.getWorkStatus(); - String publishTime = function.getPublishTime(); - String startTime = function.getStartTime(); - String duration = function.getDuration(); - String submitTime = function.getSubmitTime(); - String realDuration = function.getRealDuration(); - String status = function.getStatus(); - String verisonStatus = function.getVerisonStatus(); - String verison = function.getVerison(); - - String moduleName = ""; // 模块编码 - functionx.setCreateBy(username); // 创建人 - functionx.setCreateTime(new Date()); //创建日期 - if (StringUtils.isBlank(moduleId)) { - message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行对应模块不能为空"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("对应模块不能为空"); - } else { - if (pModuleId != null && pModuleId.length()>0) { - String pid = ""; - for (Modulex modulex : modulexList) { - if (modulex.getModuleName().equals(pModuleId)) { - pid = modulex.getId(); - break; + // 对应模块校验 + List modulexList = modulexService.list(); + + List listInsert = new ArrayList<>(); // 正式插入 + String pattern = "yyyy-MM-dd HH:mm:ss"; + SimpleDateFormat dateFormat = new SimpleDateFormat(pattern); + + for (int i = 0; i < list.size(); i++) { + FunctionxTest function = list.get(i); + Functionx functionx = new Functionx(); + String pModuleId = function.getPModuleName(); + String moduleId = function.getModuleName(); + String functionName = function.getFunctionName(); + String functionEnName = function.getFunctionEnName(); + String functionCode = function.getFunctionCode(); + String functionType = function.getFunctionType(); + String pmDescribe = function.getPmDescribe(); + String userRole = function.getUserRole(); + String managerUsers = function.getManagerUsers(); + String workLevel = function.getWorkLevel(); + String workStatus = function.getWorkStatus(); + String publishTime = function.getPublishTime(); + String startTime = function.getStartTime(); + String duration = function.getDuration(); + String submitTime = function.getSubmitTime(); + String realDuration = function.getRealDuration(); + String status = function.getStatus(); + String verisonStatus = function.getVerisonStatus(); + String verison = function.getVerison(); + + String moduleName = ""; // 模块编码 + functionx.setCreateBy(username); // 创建人 + functionx.setCreateTime(new Date()); //创建日期 + if (StringUtils.isBlank(moduleId)) { + message.put("isError", "true"); + message.put("status", "第" + i + "行数据对应模块不能为空"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("对应模块不能为空"); + } else { + if (pModuleId != null && pModuleId.length()>0) { + String pid = ""; + for (Modulex modulex : modulexList) { + if (modulex.getModuleName().equals(pModuleId)) { + pid = modulex.getId(); + break; + } } - } - for (Modulex modulex : modulexList) { - if (modulex.getModuleName().equals(moduleId) && modulex.getPid().equals(pid)) { - functionx.setModuleId(modulex.getId()); - moduleId = modulex.getId(); - moduleName = modulex.getModuleName(); - break; + for (Modulex modulex : modulexList) { + if (modulex.getModuleName().equals(moduleId) && modulex.getPid().equals(pid)) { + functionx.setModuleId(modulex.getId()); + moduleId = modulex.getId(); + moduleName = modulex.getModuleName(); + break; + } } - } - } else { - for (Modulex modulex : modulexList) { - if (modulex.getModuleName().equals(moduleId) && modulex.getPid() == null) { - functionx.setModuleId(modulex.getId()); - moduleId = modulex.getId(); - moduleName = modulex.getModuleName(); - break; + } else { + for (Modulex modulex : modulexList) { + if (modulex.getModuleName().equals(moduleId) && modulex.getPid() == null) { + functionx.setModuleId(modulex.getId()); + moduleId = modulex.getId(); + moduleName = modulex.getModuleName(); + break; + } } } + if (functionx.getModuleId() == null) { + message.put("isError", "true"); + message.put("status", "第" + (i+1) + "行数据数据对应模块有错误"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("请输入正确的对应模块"); + } } - if (functionx.getModuleId() == null) { - message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行对应模块有错误"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("请输入正确的对应模块"); - } - } - if (StringUtils.isBlank(functionName)) { - message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行中文名称不能为空"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("中文名称不能为空"); - } else { - LambdaQueryWrapper queryWrapper1 = new LambdaQueryWrapper<>(); - queryWrapper1.eq(moduleId != null, Functionx::getModuleId, moduleId); - queryWrapper1.eq(Functionx::getFunctionName, functionName); - int count = functionxService.count(queryWrapper1); - if (count > 0) { + 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("中文名称在模块下重复"); + return Result.error("中文名称不能为空"); + } else { + LambdaQueryWrapper queryWrapper1 = new LambdaQueryWrapper<>(); + queryWrapper1.eq(moduleId != null, Functionx::getModuleId, moduleId); + queryWrapper1.eq(Functionx::getFunctionName, functionName); + int count = functionxService.count(queryWrapper1); + if (count > 0) { + message.put("isError", "true"); + message.put("status", "第" + (i+1) + "行数据数据中文名称在模块下重复"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("中文名称在模块下重复"); + } + functionx.setFunctionName(functionName); } - functionx.setFunctionName(functionName); - } - if (StringUtils.isBlank(functionEnName)) { - message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行英文名称不能为空"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("英文名称不能为空"); - } else { - LambdaQueryWrapper queryWrapper2 = new LambdaQueryWrapper<>(); - queryWrapper2.eq(moduleId != null, Functionx::getModuleId, moduleId); - queryWrapper2.eq(Functionx::getFunctionEnName, functionEnName); - int count = functionxService.count(queryWrapper2); - if (count > 0) { + 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("英文名称在模块下重复"); - } - - functionx.setFunctionEnName(functionEnName); - } - // 列表0、增加1、删除2、修改3、查看4、导入5、导出6、其它99;默认99 - int type; - if (StringUtils.isBlank(functionType)) { // 空和null - message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行功能类型不能为空"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("功能类型不能为空"); - } else { - switch (functionType) { - case "列表": - type = 0; - break; - case "增加": - type = 1; - break; - case "删除": - type = 2; - break; - case "修改": - type = 3; - break; - case "查看": - type = 4; - break; - case "导入": - type = 5; - break; - case "导出": - type = 6; - break; - case "其它": - type = 99; - break; - default: + return Result.error("英文名称不能为空"); + } else { + LambdaQueryWrapper queryWrapper2 = new LambdaQueryWrapper<>(); + queryWrapper2.eq(moduleId != null, Functionx::getModuleId, moduleId); + queryWrapper2.eq(Functionx::getFunctionEnName, functionEnName); + 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("功能类型错误"); + return Result.error("英文名称在模块下重复"); + } + + functionx.setFunctionEnName(functionEnName); } - functionx.setFunctionType(type); - } - // 模块编码+功能缩写;自动填充+手动修改 - if (StringUtils.isBlank(functionCode)) { - message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行功能编码不能为空"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("功能编码不能为空"); - } else { - LambdaQueryWrapper queryWrapperModulex = new LambdaQueryWrapper<>(); - queryWrapperModulex.eq(Modulex::getModuleName, moduleName); - Modulex modulex = modulexService.getOne(queryWrapperModulex); - String moduleCode = modulex.getModuleCode(); - String firstChar = toFirstChar(functionType); - String str = moduleCode + firstChar; - if (!str.equals(functionCode)) { + // 列表0、增加1、删除2、修改3、查看4、导入5、导出6、其它99;默认99 + 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("功能编码错误"); + return Result.error("功能类型不能为空"); + } else { + switch (functionType) { + case "列表": + type = 0; + break; + case "增加": + type = 1; + break; + case "删除": + type = 2; + break; + case "修改": + type = 3; + break; + case "查看": + type = 4; + break; + case "导入": + type = 5; + break; + case "导出": + type = 6; + break; + case "其它": + type = 99; + break; + default: + message.put("isError", "true"); + message.put("status", "第" + (i+1) + "行数据数据功能类型错误"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("功能类型错误"); + } + functionx.setFunctionType(type); } - - functionx.setFunctionCode(functionCode); - } - - if (StringUtils.isNotBlank(pmDescribe)) { // 功能描述 - functionx.setPmDescribe(pmDescribe); - } - if (StringUtils.isNotBlank(userRole)) { // 用户角色 - LambdaQueryWrapper queryWrapperUser = new LambdaQueryWrapper<>(); - queryWrapperUser.eq(ProjectUserRole::getUserRole, userRole); // 是否匹配项目id? - int count = projectUserRoleService.count(queryWrapperUser); - if (count > 0) - functionx.setUserRole(userRole); - else { + // 模块编码+功能缩写;自动填充+手动修改 + 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("请输入正确的用户角色"); + return Result.error("功能编码不能为空"); + } else { + LambdaQueryWrapper queryWrapperModulex = new LambdaQueryWrapper<>(); + queryWrapperModulex.eq(Modulex::getModuleName, moduleName); + Modulex modulex = modulexService.getOne(queryWrapperModulex); + String moduleCode = modulex.getModuleCode(); + String firstChar = toFirstChar(functionType); + String str = moduleCode + firstChar; + if (!str.equals(functionCode)) { + message.put("isError", "true"); + message.put("status", "第" + (i+1) + "行数据数据功能编码错误"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("功能编码错误"); + } + + functionx.setFunctionCode(functionCode); } - } - if (StringUtils.isNotBlank(managerUsers)) { // 责任人 - String[] splitManager = managerUsers.split("\\s+|,|;|、"); - - int count = 0; - for (String manager : splitManager) { - LambdaQueryWrapper queryWrapperUserName = new LambdaQueryWrapper<>(); - queryWrapperUserName.eq(!manager.isEmpty(), SysUser::getUsername, manager); - count = sysUserService.count(queryWrapperUserName); - if (count == 0) { - break; + if (StringUtils.isNotBlank(pmDescribe)) { // 功能描述 + functionx.setPmDescribe(pmDescribe); + } + if (StringUtils.isNotBlank(userRole)) { // 用户角色 + LambdaQueryWrapper queryWrapperUser = new LambdaQueryWrapper<>(); + queryWrapperUser.eq(ProjectUserRole::getUserRole, userRole); // 是否匹配项目id? + List list1 = projectUserRoleService.list(queryWrapperUser); + if (list1.size() > 0) + functionx.setUserRole(list1.get(0).getId()); + else { + message.put("isError", "true"); + message.put("status", "第" + (i+1) + "行数据数据请输入正确的用户角色"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("请输入正确的用户角色"); + } + + } + if (StringUtils.isNotBlank(managerUsers)) { // 责任人 + String[] splitManager = managerUsers.split("\\s+|,|;|、"); + + int count = 1; + String idManager = ""; + for (String manager : splitManager) { + LambdaQueryWrapper queryWrapperUserName = new LambdaQueryWrapper<>(); + queryWrapperUserName.eq(!manager.isEmpty(), SysUser::getUsername, manager); + List list1 = sysUserService.list(queryWrapperUserName); + if (list1.isEmpty()) { + count=0; + break; + } + idManager = idManager+list1.get(0).getId()+","; + } + if (count > 0){ + functionx.setManagerUsers(idManager); + } + else { + message.put("isError", "true"); + message.put("status", "第" + (i+1) + "行数据数据请输入正确的责任人,并确保多个责任人之间用空格或者逗号、分号隔开"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("请输入正确的责任人,并确保多个责任人之间用空格或者逗号、分号隔开"); } + } - if (count > 0) - functionx.setManagerUsers(managerUsers); - else { + // 值: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("请输入正确的责任人,并确保多个责任人之间用空格或者逗号、分号隔开"); + return Result.error("任务等级不能为空"); + } else { + int integer = Integer.parseInt(workLevel); + if (integer < 1 || integer > 5) { + message.put("isError", "true"); + message.put("status", "第" + (i+1) + "行数据数据任务等级错误"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("任务等级错误"); + } + functionx.setWorkLevel(integer); } - } - // 值:1、2、3、4、5,默认2 - if (StringUtils.isBlank(workLevel)) { // 任务等级 - message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行任务等级不能为空"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("任务等级不能为空"); - } else { - int integer = Integer.parseInt(workLevel); - if (integer < 1 || integer > 5) { + 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("任务等级错误"); + return Result.error("任务状态不能为空"); + } else { + // 值:未发布0、已发布1、开发中2、已完成3、已撤回4、已取消9;默认0 + switch (workStatus) { + case "未发布": + type = 0; + break; + case "已发布": + type = 1; + break; + case "开发中": + type = 2; + break; + case "已完成": + type = 3; + break; + case "已撤回": + type = 4; + break; + case "已取消": + type = 9; + break; + default: + message.put("isError", "true"); + message.put("status", "第" + (i+1) + "行数据数据任务状态错误"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("任务状态错误"); + } + functionx.setWorkStatus(type); } - functionx.setWorkLevel(integer); - } - if (StringUtils.isBlank(workStatus)) { - message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行任务状态不能为空"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("任务状态不能为空"); - } else { - // 值:未发布0、已发布1、开发中2、已完成3、已撤回4、已取消9;默认0 - switch (workStatus) { - case "未发布": - type = 0; - break; - case "已发布": - type = 1; - break; - case "开发中": - type = 2; - break; - case "已完成": - type = 3; - break; - case "已撤回": - type = 4; - break; - case "已取消": - type = 9; - break; - default: + if (StringUtils.isNotBlank(publishTime)) { + Date date; + Boolean isTime = checkTime(publishTime); + if (!isTime) { + message.put("isError", "true"); + message.put("status", "第" + (i+1) + "行数据数据发布时间格式错误"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("发布时间错误,应为" + pattern + "类型"); + } + try { + 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("任务状态错误"); + return Result.error("发布时间错误,应为" + pattern + "类型"); + } + functionx.setPublishTime(date); } - functionx.setWorkStatus(type); - } - if (StringUtils.isNotBlank(publishTime)) { - Date date; - Boolean isTime = checkTime(publishTime); - if (!isTime) { - message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行发布时间格式错误"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("发布时间错误,应为" + pattern + "类型"); - } - try { - date = dateFormat.parse(publishTime); - } catch (Exception e) { - message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行发布时间错误"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("发布时间错误,应为" + pattern + "类型"); + if (StringUtils.isNotBlank(startTime)) { + Date date; + Boolean isTime = checkTime(startTime); + if (!isTime) { + message.put("isError", "true"); + message.put("status", "第" + (i+1) + "行数据数据开始时间格式错误"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("开始时间错误,应为" + pattern + "类型"); + } + try { + date = dateFormat.parse(startTime); + } catch (Exception e) { + message.put("isError", "true"); + message.put("status", "第" + (i+1) + "行数据数据开始时间错误"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("开始时间错误,应为" + pattern + "类型"); + } + functionx.setStartTime(date); } - functionx.setPublishTime(date); - } - if (StringUtils.isNotBlank(startTime)) { - Date date; - Boolean isTime = checkTime(startTime); - if (!isTime) { - message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行开始时间格式错误"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("开始时间错误,应为" + pattern + "类型"); + if (StringUtils.isNotBlank(duration)) { + Double aDouble = Double.valueOf(duration); + functionx.setDuration(aDouble); } - try { - date = dateFormat.parse(startTime); - } catch (Exception e) { - message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行开始时间错误"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("开始时间错误,应为" + pattern + "类型"); - } - functionx.setStartTime(date); - } - if (StringUtils.isNotBlank(duration)) { - Double aDouble = Double.valueOf(duration); - functionx.setDuration(aDouble); - } + if (StringUtils.isNotBlank(submitTime)) { + Date date; + Boolean isTime = checkTime(submitTime); + if (!isTime) { + message.put("isError", "true"); + message.put("status", "第" + (i+1) + "行数据数据提交时间格式错误"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("提交时间格式错误,应为" + pattern + "类型"); + } + try { + date = dateFormat.parse(submitTime); + } catch (Exception e) { + message.put("isError", "true"); + message.put("status", "第" + (i+1) + "行数据数据提交时间时间错误"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("提交时间时间错误,应为" + pattern + "类型"); + } + functionx.setSubmitTime(date); + } + if (StringUtils.isNotBlank(realDuration)) { + Double aDouble = Double.valueOf(realDuration); + if (aDouble < 0.1) { + message.put("isError", "true"); + message.put("status", "第" + (i+1) + "行数据数据实际时长错误"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("实际时长错误"); + } - if (StringUtils.isNotBlank(submitTime)) { - Date date; - Boolean isTime = checkTime(submitTime); - if (!isTime) { + functionx.setDuration(aDouble); + } + 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("提交时间格式错误,应为" + pattern + "类型"); + return Result.error("功能状态不能为空"); + } else { + // 值:正常1、停用0、废弃9;默认1 + switch (status) { + case "正常": + type = 1; + break; + case "停用": + type = 0; + break; + case "废弃": + type = 9; + break; + default: + message.put("isError", "true"); + message.put("status", "第" + (i+1) + "行数据数据任务状态错误"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("任务状态错误"); + } + functionx.setStatus(type); } - try { - date = dateFormat.parse(submitTime); - } catch (Exception e) { + 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("提交时间时间错误,应为" + pattern + "类型"); + return Result.error("版本状态不能为空"); + } else { + // 值:当前1、历史0;默认1 + switch (verisonStatus) { + case "当前": + type = 1; + break; + case "历史": + type = 0; + break; + default: + message.put("isError", "true"); + message.put("status", "第" + (i+1) + "行数据数据版本状态错误"); + message.put("closeable", "true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("版本状态错误"); + } + functionx.setStatus(type); } - functionx.setSubmitTime(date); - } - if (StringUtils.isNotBlank(realDuration)) { - Double aDouble = Double.valueOf(realDuration); - if (aDouble < 0.1) { + 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("实际时长错误"); + return Result.error("版本号不能为空"); + } else { + Integer integer = Integer.valueOf(verison); + functionx.setStatus(integer); } - functionx.setDuration(aDouble); + listInsert.add(functionx); } - if (StringUtils.isBlank(status)) { // 空和null - message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行功能状态不能为空"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("功能状态不能为空"); - } else { - // 值:正常1、停用0、废弃9;默认1 - switch (status) { - case "正常": - type = 1; - break; - case "停用": - type = 0; - break; - case "废弃": - type = 9; - break; - default: - message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行任务状态错误"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("任务状态错误"); - } - functionx.setStatus(type); - } - if (StringUtils.isBlank(verisonStatus)) { // 空和null - message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行版本状态不能为空"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("版本状态不能为空"); - } else { - // 值:当前1、历史0;默认1 - switch (verisonStatus) { - case "当前": - type = 1; - break; - case "历史": - type = 0; - break; - default: - message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行版本状态错误"); - message.put("closeable", "true"); - webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("版本状态错误"); - } - functionx.setStatus(type); - } - if (StringUtils.isBlank(verison)) { + + //**************************校验结束****************************** + boolean isSuccessInsert = isSuccessInsert(loginUser, message, listInsert); + if (!isSuccessInsert) { message.put("isError", "true"); - message.put("status", "第" + (i + 2) + "行版本号不能为空"); + message.put("status", "导入失败"); message.put("closeable", "true"); webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("版本号不能为空"); - } else { - Integer integer = Integer.valueOf(verison); - functionx.setStatus(integer); + return Result.error("导入失败"); } - listInsert.add(functionx); - } - //**************************校验结束****************************** - boolean isSuccessInsert = isSuccessInsert(loginUser, message, listInsert); - if (!isSuccessInsert) { + } catch (Exception e) { message.put("isError", "true"); - message.put("status", "导入失败"); + 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 list) { + for (int i=0;i0){ + return true; + } + } + return false; + } + + private boolean isSuccessInsert(LoginUser loginUser, Map message, List listInsert) { message.put("status", "导入数据中"); message.put("records", String.valueOf(listInsert.size()));