新增改为增加,单元格格式校验

dev^2
guilongma 1 year ago
parent 476e56d02b
commit 9290f843b5
  1. 412
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/functionx/service/impl/FunctionXTestServiceImpl.java

@ -9,10 +9,7 @@ import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination; import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
@ -65,31 +62,31 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
message.put("uploaded", "0"); message.put("uploaded", "0");
message.put("status", "判断文件结构"); message.put("status", "判断文件结构");
message.put("isError", "false"); message.put("isError", "false");
message.put("closeable","false"); message.put("closeable", "false");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
//创建输出流对象 //创建输出流对象
Workbook wb; Workbook wb;
/*判断文件是xlsx结尾还是xls结尾 声明XSSF或HSSF对象*/ /*判断文件是xlsx结尾还是xls结尾 声明XSSF或HSSF对象*/
String[] split = file.getOriginalFilename().split("\\."); String[] split = file.getOriginalFilename().split("\\.");
try { try {
if(split[1].equals("xlsx")){ if (split[1].equals("xlsx")) {
wb= new XSSFWorkbook(file.getInputStream()); wb = new XSSFWorkbook(file.getInputStream());
}else if(split[1].equals("xls")){ } else if (split[1].equals("xls")) {
wb= new HSSFWorkbook(file.getInputStream()); wb = new HSSFWorkbook(file.getInputStream());
} else { } else {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","上传失败,请上传Excel文件"); message.put("status", "上传失败,请上传Excel文件");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件格式错误,请上传Excel文件"); return Result.error("文件格式错误,请上传Excel文件");
} }
} catch (IOException e) { } catch (IOException e) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","请上传正确格式文件"); message.put("status", "请上传正确格式文件");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("请上传正确格式文件"); return Result.error("请上传正确格式文件");
} }
@ -97,14 +94,14 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
//获取工作表页数据 //获取工作表页数据
//读取第1页的数据 //读取第1页的数据
Sheet sheet=wb.getSheetAt(0); Sheet sheet = wb.getSheetAt(0);
//获取工作表页中行数据 //获取工作表页中行数据
//读取的总的行数 //读取的总的行数
int lastRowIndex=sheet.getLastRowNum(); int lastRowIndex = sheet.getLastRowNum();
if(lastRowIndex < 1) { if (lastRowIndex < 1) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","文件无内容或格式错误"); message.put("status", "文件无内容或格式错误");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件无内容或格式错误"); return Result.error("文件无内容或格式错误");
} }
@ -112,17 +109,24 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
List<FunctionxTest> listVo = new ArrayList<>(); List<FunctionxTest> listVo = new ArrayList<>();
for (int i=1;i<=lastRowIndex;i++) { for (int i = 1; i <= lastRowIndex; i++) {
Row row = sheet.getRow(i); // 行 Row row = sheet.getRow(i); // 行
if(row!=null){ if (row == null ) {
continue;
} else {
short lastCellNum = row.getLastCellNum(); short lastCellNum = row.getLastCellNum();
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
for (int j=0;j<lastCellNum;j++){ for (int j = 0; j < lastCellNum; j++) {
Cell cell = row.getCell(j); // 单元格 Cell cell = row.getCell(j); // 单元格
if (cell == null){ if (cell == null) {
list.add(null); list.add(null);
} else { } else {
String cellValue = cell.getStringCellValue(); FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
DataFormatter formatter = new DataFormatter();
//单元格不设置数字格式
cell.setCellStyle(null);
String cellValue = formatter.formatCellValue(cell,evaluator);
list.add(cellValue); list.add(cellValue);
} }
} }
@ -153,10 +157,10 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
} }
} }
boolean isSuccessSave = this.saveBatch(listVo); boolean isSuccessSave = this.saveBatch(listVo);
if (!isSuccessSave){ if (!isSuccessSave) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","文件读入失败"); message.put("status", "文件读入失败");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件读入失败"); return Result.error("文件读入失败");
} }
@ -166,11 +170,11 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
//************************具体字段校验****************************** //************************具体字段校验******************************
LambdaQueryWrapper<FunctionxTest> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<FunctionxTest> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(username!=null, FunctionxTest::getCreatName,username); queryWrapper.eq(username != null, FunctionxTest::getCreatName, username);
List<FunctionxTest> list = this.list(queryWrapper); List<FunctionxTest> list = this.list(queryWrapper);
boolean remove = this.remove(queryWrapper); boolean remove = this.remove(queryWrapper);
if (!remove){ if (!remove) {
log.error("临时表删除错误!"); log.error("临时表删除错误!");
} }
@ -204,86 +208,86 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
String verisonStatus = function.getVerisonStatus(); String verisonStatus = function.getVerisonStatus();
String verison = function.getVerison(); String verison = function.getVerison();
String moduleName=""; // 模块编码 String moduleName = ""; // 模块编码
functionx.setCreateBy(username); // 创建人 functionx.setCreateBy(username); // 创建人
functionx.setCreateTime(new Date()); //创建日期 functionx.setCreateTime(new Date()); //创建日期
if(StringUtils.isBlank(moduleId)){ if (StringUtils.isBlank(moduleId)) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行对应模块不能为空"); message.put("status", "第" + (i + 2) + "行对应模块不能为空");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("对应模块不能为空"); return Result.error("对应模块不能为空");
} else{ } else {
if (pModuleId != null){ if (pModuleId != null && pModuleId.length()>0) {
String pid=""; String pid = "";
for(Modulex modulex : modulexList){ for (Modulex modulex : modulexList) {
if (modulex.getModuleName().equals(pModuleId)){ if (modulex.getModuleName().equals(pModuleId)) {
pid = modulex.getId(); pid = modulex.getId();
break; break;
} }
} }
for(Modulex modulex : modulexList){ for (Modulex modulex : modulexList) {
if (modulex.getModuleName().equals(moduleId) && modulex.getPid().equals(pid)){ if (modulex.getModuleName().equals(moduleId) && modulex.getPid().equals(pid)) {
functionx.setModuleId(modulex.getId()); functionx.setModuleId(modulex.getId());
moduleId = modulex.getId(); moduleId = modulex.getId();
moduleName=modulex.getModuleName(); moduleName = modulex.getModuleName();
break; break;
} }
} }
}else { } else {
for(Modulex modulex : modulexList){ for (Modulex modulex : modulexList) {
if (modulex.getModuleName().equals(moduleId) && modulex.getPid()==null){ if (modulex.getModuleName().equals(moduleId) && modulex.getPid() == null) {
functionx.setModuleId(modulex.getId()); functionx.setModuleId(modulex.getId());
moduleId = modulex.getId(); moduleId = modulex.getId();
moduleName=modulex.getModuleName(); moduleName = modulex.getModuleName();
break; break;
} }
} }
} }
if(functionx.getModuleId() == null){ if (functionx.getModuleId() == null) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行对应模块有错误"); message.put("status", "第" + (i + 2) + "行对应模块有错误");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("请输入正确的对应模块"); return Result.error("请输入正确的对应模块");
} }
} }
if(StringUtils.isBlank(functionName)){ if (StringUtils.isBlank(functionName)) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行中文名称不能为空"); message.put("status", "第" + (i + 2) + "行中文名称不能为空");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("中文名称不能为空"); return Result.error("中文名称不能为空");
} else{ } else {
LambdaQueryWrapper<Functionx> queryWrapper1 = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Functionx> queryWrapper1 = new LambdaQueryWrapper<>();
queryWrapper1.eq(moduleId!=null,Functionx::getModuleId,moduleId); queryWrapper1.eq(moduleId != null, Functionx::getModuleId, moduleId);
queryWrapper1.eq(Functionx::getFunctionName,functionName); queryWrapper1.eq(Functionx::getFunctionName, functionName);
int count = functionxService.count(queryWrapper1); int count = functionxService.count(queryWrapper1);
if(count>0){ if (count > 0) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行中文名称在模块下重复"); message.put("status", "第" + (i + 2) + "行中文名称在模块下重复");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("中文名称在模块下重复"); return Result.error("中文名称在模块下重复");
} }
functionx.setFunctionName(functionName); functionx.setFunctionName(functionName);
} }
if(StringUtils.isBlank(functionEnName)){ if (StringUtils.isBlank(functionEnName)) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行英文名称不能为空"); message.put("status", "第" + (i + 2) + "行英文名称不能为空");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("英文名称不能为空"); return Result.error("英文名称不能为空");
} else{ } else {
LambdaQueryWrapper<Functionx> queryWrapper2 = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Functionx> queryWrapper2 = new LambdaQueryWrapper<>();
queryWrapper2.eq(moduleId!=null,Functionx::getModuleId,moduleId); queryWrapper2.eq(moduleId != null, Functionx::getModuleId, moduleId);
queryWrapper2.eq(Functionx::getFunctionEnName,functionEnName); queryWrapper2.eq(Functionx::getFunctionEnName, functionEnName);
int count = functionxService.count(queryWrapper2); int count = functionxService.count(queryWrapper2);
if(count>0){ if (count > 0) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行英文名称在模块下重复"); message.put("status", "第" + (i + 2) + "行英文名称在模块下重复");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("英文名称在模块下重复"); return Result.error("英文名称在模块下重复");
} }
@ -292,49 +296,65 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
} }
// 列表0、增加1、删除2、修改3、查看4、导入5、导出6、其它99;默认99 // 列表0、增加1、删除2、修改3、查看4、导入5、导出6、其它99;默认99
int type; int type;
if(StringUtils.isBlank(functionType)){ // 空和null if (StringUtils.isBlank(functionType)) { // 空和null
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行功能类型不能为空"); message.put("status", "第" + (i + 2) + "行功能类型不能为空");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能类型不能为空"); return Result.error("功能类型不能为空");
} else{ } else {
switch (functionType){ switch (functionType) {
case "列表": type=0; break; case "列表":
case "新增": type=1; break; type = 0;
case "删除": type=2; break; break;
case "修改": type=3; break; case "增加":
case "查看": type=4; break; type = 1;
case "导入": type=5; break; break;
case "导出": type=6; break; case "删除":
case "其它": type=99; break; type = 2;
break;
case "修改":
type = 3;
break;
case "查看":
type = 4;
break;
case "导入":
type = 5;
break;
case "导出":
type = 6;
break;
case "其它":
type = 99;
break;
default: default:
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行功能类型错误"); message.put("status", "第" + (i + 2) + "行功能类型错误");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能类型错误"); return Result.error("功能类型错误");
} }
functionx.setFunctionType(type); functionx.setFunctionType(type);
} }
// 模块编码+功能缩写;自动填充+手动修改 // 模块编码+功能缩写;自动填充+手动修改
if(StringUtils.isBlank(functionCode)){ if (StringUtils.isBlank(functionCode)) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行功能编码不能为空"); message.put("status", "第" + (i + 2) + "行功能编码不能为空");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能编码不能为空"); return Result.error("功能编码不能为空");
} else{ } else {
LambdaQueryWrapper<Modulex> queryWrapperModulex = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Modulex> queryWrapperModulex = new LambdaQueryWrapper<>();
queryWrapperModulex.eq(Modulex::getModuleName,moduleName); queryWrapperModulex.eq(Modulex::getModuleName, moduleName);
Modulex modulex = modulexService.getOne(queryWrapperModulex); Modulex modulex = modulexService.getOne(queryWrapperModulex);
String moduleCode = modulex.getModuleCode(); String moduleCode = modulex.getModuleCode();
String firstChar = toFirstChar(functionType); String firstChar = toFirstChar(functionType);
String str = moduleCode+firstChar; String str = moduleCode + firstChar;
if(!str.equals(functionCode)){ if (!str.equals(functionCode)) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行功能编码错误"); message.put("status", "第" + (i + 2) + "行功能编码错误");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能编码错误"); return Result.error("功能编码错误");
} }
@ -342,221 +362,243 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
functionx.setFunctionCode(functionCode); functionx.setFunctionCode(functionCode);
} }
if(StringUtils.isNotBlank(pmDescribe)){ // 功能描述 if (StringUtils.isNotBlank(pmDescribe)) { // 功能描述
functionx.setPmDescribe(pmDescribe); functionx.setPmDescribe(pmDescribe);
} }
if(StringUtils.isNotBlank(userRole)){ // 用户角色 if (StringUtils.isNotBlank(userRole)) { // 用户角色
LambdaQueryWrapper<ProjectUserRole> queryWrapperUser = new LambdaQueryWrapper<>(); LambdaQueryWrapper<ProjectUserRole> queryWrapperUser = new LambdaQueryWrapper<>();
queryWrapperUser.eq(ProjectUserRole::getUserRole,userRole); // 是否匹配项目id? queryWrapperUser.eq(ProjectUserRole::getUserRole, userRole); // 是否匹配项目id?
int count = projectUserRoleService.count(queryWrapperUser); int count = projectUserRoleService.count(queryWrapperUser);
if(count>0) if (count > 0)
functionx.setUserRole(userRole); functionx.setUserRole(userRole);
else{ else {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行请输入正确的用户角色"); message.put("status", "第" + (i + 2) + "行请输入正确的用户角色");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("请输入正确的用户角色"); return Result.error("请输入正确的用户角色");
} }
} }
if(StringUtils.isNotBlank(managerUsers)){ // 责任人 if (StringUtils.isNotBlank(managerUsers)) { // 责任人
String[] splitManager = managerUsers.split("\\s+|,|;|、"); String[] splitManager = managerUsers.split("\\s+|,|;|、");
int count = 0; int count = 0;
for (String manager : splitManager){ for (String manager : splitManager) {
LambdaQueryWrapper<SysUser> queryWrapperUserName = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysUser> queryWrapperUserName = new LambdaQueryWrapper<>();
queryWrapperUserName.eq(!manager.isEmpty(),SysUser::getUsername,manager); queryWrapperUserName.eq(!manager.isEmpty(), SysUser::getUsername, manager);
count = sysUserService.count(queryWrapperUserName); count = sysUserService.count(queryWrapperUserName);
if(count == 0) { if (count == 0) {
break; break;
} }
} }
if(count>0) if (count > 0)
functionx.setManagerUsers(managerUsers); functionx.setManagerUsers(managerUsers);
else{ else {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行请输入正确的责任人,并确保多个责任人之间用空格或者逗号、分号隔开"); message.put("status", "第" + (i + 2) + "行请输入正确的责任人,并确保多个责任人之间用空格或者逗号、分号隔开");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("请输入正确的责任人,并确保多个责任人之间用空格或者逗号、分号隔开"); return Result.error("请输入正确的责任人,并确保多个责任人之间用空格或者逗号、分号隔开");
} }
} }
// 值:1、2、3、4、5,默认2 // 值:1、2、3、4、5,默认2
if(StringUtils.isBlank(workLevel)){ // 任务等级 if (StringUtils.isBlank(workLevel)) { // 任务等级
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行任务等级不能为空"); message.put("status", "第" + (i + 2) + "行任务等级不能为空");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("任务等级不能为空"); return Result.error("任务等级不能为空");
} else{ } else {
int integer = Integer.parseInt(workLevel); int integer = Integer.parseInt(workLevel);
if (integer<1 || integer>5){ if (integer < 1 || integer > 5) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行任务等级错误"); message.put("status", "第" + (i + 2) + "行任务等级错误");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("任务等级错误"); return Result.error("任务等级错误");
} }
functionx.setWorkLevel(integer); functionx.setWorkLevel(integer);
} }
if(StringUtils.isBlank(workStatus)){ if (StringUtils.isBlank(workStatus)) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行任务状态不能为空"); message.put("status", "第" + (i + 2) + "行任务状态不能为空");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("任务状态不能为空"); return Result.error("任务状态不能为空");
} else { } else {
// 值:未发布0、已发布1、开发中2、已完成3、已撤回4、已取消9;默认0 // 值:未发布0、已发布1、开发中2、已完成3、已撤回4、已取消9;默认0
switch (workStatus){ switch (workStatus) {
case "未发布": type=0; break; case "未发布":
case "已发布": type=1; break; type = 0;
case "开发中": type=2; break; break;
case "已完成": type=3; break; case "已发布":
case "已撤回": type=4; break; type = 1;
case "已取消": type=9; break; break;
case "开发中":
type = 2;
break;
case "已完成":
type = 3;
break;
case "已撤回":
type = 4;
break;
case "已取消":
type = 9;
break;
default: default:
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行任务状态错误"); message.put("status", "第" + (i + 2) + "行任务状态错误");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("任务状态错误"); return Result.error("任务状态错误");
} }
functionx.setWorkStatus(type); functionx.setWorkStatus(type);
} }
if(StringUtils.isNotBlank(publishTime)){ if (StringUtils.isNotBlank(publishTime)) {
Date date; Date date;
Boolean isTime = checkTime(publishTime); Boolean isTime = checkTime(publishTime);
if (!isTime){ if (!isTime) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行发布时间格式错误"); message.put("status", "第" + (i + 2) + "行发布时间格式错误");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("发布时间错误,应为"+pattern+"类型"); return Result.error("发布时间错误,应为" + pattern + "类型");
} }
try { try {
date = dateFormat.parse(publishTime); date = dateFormat.parse(publishTime);
} catch (Exception e) { } catch (Exception e) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行发布时间错误"); message.put("status", "第" + (i + 2) + "行发布时间错误");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("发布时间错误,应为"+pattern+"类型"); return Result.error("发布时间错误,应为" + pattern + "类型");
} }
functionx.setPublishTime(date); functionx.setPublishTime(date);
} }
if(StringUtils.isNotBlank(startTime)){ if (StringUtils.isNotBlank(startTime)) {
Date date; Date date;
Boolean isTime = checkTime(startTime); Boolean isTime = checkTime(startTime);
if (!isTime){ if (!isTime) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行开始时间格式错误"); message.put("status", "第" + (i + 2) + "行开始时间格式错误");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("开始时间错误,应为"+pattern+"类型"); return Result.error("开始时间错误,应为" + pattern + "类型");
} }
try { try {
date = dateFormat.parse(startTime); date = dateFormat.parse(startTime);
} catch (Exception e) { } catch (Exception e) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行开始时间错误"); message.put("status", "第" + (i + 2) + "行开始时间错误");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("开始时间错误,应为"+pattern+"类型"); return Result.error("开始时间错误,应为" + pattern + "类型");
} }
functionx.setStartTime(date); functionx.setStartTime(date);
} }
if(StringUtils.isNotBlank(duration)){ if (StringUtils.isNotBlank(duration)) {
Double aDouble = Double.valueOf(duration); Double aDouble = Double.valueOf(duration);
functionx.setDuration(aDouble); functionx.setDuration(aDouble);
} }
if(StringUtils.isNotBlank(submitTime)){ if (StringUtils.isNotBlank(submitTime)) {
Date date; Date date;
Boolean isTime = checkTime(submitTime); Boolean isTime = checkTime(submitTime);
if (!isTime){ if (!isTime) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行提交时间格式错误"); message.put("status", "第" + (i + 2) + "行提交时间格式错误");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("提交时间格式错误,应为"+pattern+"类型"); return Result.error("提交时间格式错误,应为" + pattern + "类型");
} }
try { try {
date = dateFormat.parse(submitTime); date = dateFormat.parse(submitTime);
} catch (Exception e) { } catch (Exception e) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行提交时间时间错误"); message.put("status", "第" + (i + 2) + "行提交时间时间错误");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("提交时间时间错误,应为"+pattern+"类型"); return Result.error("提交时间时间错误,应为" + pattern + "类型");
} }
functionx.setSubmitTime(date); functionx.setSubmitTime(date);
} }
if(StringUtils.isNotBlank(realDuration)){ if (StringUtils.isNotBlank(realDuration)) {
Double aDouble = Double.valueOf(realDuration); Double aDouble = Double.valueOf(realDuration);
if (aDouble<0.1){ if (aDouble < 0.1) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行实际时长错误"); message.put("status", "第" + (i + 2) + "行实际时长错误");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("实际时长错误"); return Result.error("实际时长错误");
} }
functionx.setDuration(aDouble); functionx.setDuration(aDouble);
} }
if(StringUtils.isBlank(status)){ // 空和null if (StringUtils.isBlank(status)) { // 空和null
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行功能状态不能为空"); message.put("status", "第" + (i + 2) + "行功能状态不能为空");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能状态不能为空"); return Result.error("功能状态不能为空");
} else{ } else {
// 值:正常1、停用0、废弃9;默认1 // 值:正常1、停用0、废弃9;默认1
switch (status){ switch (status) {
case "正常": type=1; break; case "正常":
case "停用": type=0; break; type = 1;
case "废弃": type=9; break; break;
case "停用":
type = 0;
break;
case "废弃":
type = 9;
break;
default: default:
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行任务状态错误"); message.put("status", "第" + (i + 2) + "行任务状态错误");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("任务状态错误"); return Result.error("任务状态错误");
} }
functionx.setStatus(type); functionx.setStatus(type);
} }
if(StringUtils.isBlank(verisonStatus)){ // 空和null if (StringUtils.isBlank(verisonStatus)) { // 空和null
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行版本状态不能为空"); message.put("status", "第" + (i + 2) + "行版本状态不能为空");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("版本状态不能为空"); return Result.error("版本状态不能为空");
} else{ } else {
// 值:当前1、历史0;默认1 // 值:当前1、历史0;默认1
switch (verisonStatus){ switch (verisonStatus) {
case "当前": type=1; break; case "当前":
case "历史": type=0; break; type = 1;
break;
case "历史":
type = 0;
break;
default: default:
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行版本状态错误"); message.put("status", "第" + (i + 2) + "行版本状态错误");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("版本状态错误"); return Result.error("版本状态错误");
} }
functionx.setStatus(type); functionx.setStatus(type);
} }
if(StringUtils.isBlank(verison)){ if (StringUtils.isBlank(verison)) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","第"+(i+2)+"行版本号不能为空"); message.put("status", "第" + (i + 2) + "行版本号不能为空");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("版本号不能为空"); return Result.error("版本号不能为空");
} else{ } else {
Integer integer = Integer.valueOf(verison); Integer integer = Integer.valueOf(verison);
functionx.setStatus(integer); functionx.setStatus(integer);
} }
@ -566,16 +608,16 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
//**************************校验结束****************************** //**************************校验结束******************************
boolean isSuccessInsert = isSuccessInsert(loginUser, message, listInsert); boolean isSuccessInsert = isSuccessInsert(loginUser, message, listInsert);
if(!isSuccessInsert){ if (!isSuccessInsert) {
message.put("isError", "true"); message.put("isError", "true");
message.put("status","导入失败"); message.put("status", "导入失败");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("导入失败"); return Result.error("导入失败");
} }
message.put("status", "上传成功"); message.put("status", "上传成功");
message.put("closeable","true"); message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.OK("导入成功"); return Result.OK("导入成功");
} }
@ -584,12 +626,12 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
message.put("status", "导入数据中"); message.put("status", "导入数据中");
message.put("records", String.valueOf(listInsert.size())); message.put("records", String.valueOf(listInsert.size()));
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
for (int i = 0; i < listInsert.size(); i++){ for (int i = 0; i < listInsert.size(); i++) {
try { try {
Thread.sleep(1000L); Thread.sleep(1000L);
message.put("uploaded", String.valueOf(i + 1)); message.put("uploaded", String.valueOf(i + 1));
boolean isSuccessInsert = functionxService.save(listInsert.get(i)); boolean isSuccessInsert = functionxService.save(listInsert.get(i));
if (!isSuccessInsert){ if (!isSuccessInsert) {
return false; return false;
} }
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
@ -603,7 +645,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
/** /**
* 检查时间格式是否有效 * 检查时间格式是否有效
*/ */
private Boolean checkTime(String date){ private Boolean checkTime(String date) {
// 使用日期解析方式校验日期逻辑有效性 // 使用日期解析方式校验日期逻辑有效性
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try { try {
@ -633,7 +675,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
/** /**
* 名称缩写 * 名称缩写
*/ */
public static String toFirstChar(String chinese){ public static String toFirstChar(String chinese) {
String pinyinStr = ""; String pinyinStr = "";
char[] newChar = chinese.toCharArray(); //转为单个字符 char[] newChar = chinese.toCharArray(); //转为单个字符
HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
@ -646,7 +688,7 @@ public class FunctionXTestServiceImpl extends ServiceImpl<FunctionxTestMapper, F
} catch (BadHanyuPinyinOutputFormatCombination e) { } catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace(); e.printStackTrace();
} }
}else{ } else {
pinyinStr += newChar[i]; pinyinStr += newChar[i];
} }
} }

Loading…
Cancel
Save