导入规则修改

dev^2
zjh 1 year ago
parent 1941280f92
commit 1094c16868
  1. 562
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/rulex/controller/RulexController.java
  2. 2
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/rulex/service/IRulexService.java
  3. 42
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/rulex/service/impl/RulexServiceImpl.java

@ -247,8 +247,14 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
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);
//判断文件是否为空
if (file == null) {
message.put("isError", "true");
message.put("closeable","true");
message.put("status","文件上传失败,请重新上传");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件上传失败,请重新上传");
}
// 判断文件是否是表格 // 判断文件是否是表格
String originalFilename = file.getOriginalFilename(); String originalFilename = file.getOriginalFilename();
if (StringUtils.isBlank(originalFilename) || if (StringUtils.isBlank(originalFilename) ||
@ -262,33 +268,29 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
} }
//校验时间 //校验时间
final DateValidator validator = new DateValidatorUsingDateFormat("yyyy-MM-dd hh:mm:ss"); final DateValidator validator = new DateValidatorUsingDateFormat("yyyy-MM-dd hh:mm:ss");
if (file == null) {
message.put("isError", "true");
message.put("closeable","true");
message.put("status","文件上传失败,请重新上传");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件上传失败,请重新上传");
}
ImportParams params = new ImportParams(); ImportParams params = new ImportParams();
params.setTitleRows(2);//表格标题行数,默认0 params.setTitleRows(2);//表格标题行数,默认0
params.setHeadRows(1);//表头行数,默认1 params.setHeadRows(1);//表头行数,默认1
params.setNeedSave(true);//是否需要保存上传的Excel,默认为false params.setNeedSave(true);//是否需要保存上传的Excel,默认为false
try {
message.put("status", "数据预读入"); message.put("status", "数据预读入");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
List<RuleVo> list = ExcelImportUtil.importExcel(file.getInputStream(), RuleVo.class, params); List<RuleVo> list = null;
if (list == null || list.size() <= 0) { try {
list = ExcelImportUtil.importExcel(file.getInputStream(), RuleVo.class, params);
} catch (Exception e) {
e.printStackTrace();
}
if (list == null || list.size() <= 0) {
message.put("isError", "true"); message.put("isError", "true");
message.put("closeable","true"); message.put("closeable","true");
message.put("status","文件导入失败:模板中暂无数据"); message.put("status","文件导入失败:模板中暂无数据");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件导入失败:模板中暂无数据"); return Result.error("文件导入失败:模板中暂无数据");
} }
int num = 0; //必要字段判断空值
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
if ( if (
//excel出现必要值未填该行直接跳过
list.get(i).getRuleNo() == null || list.get(i).getRuleNo() == null ||
list.get(i).getRuleCode() == null || list.get(i).getRuleCode() == null ||
// list.get(i).getPmDescribe() == null && // list.get(i).getPmDescribe() == null &&
@ -308,301 +310,277 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
list.get(i).getStatus() == null || list.get(i).getStatus() == null ||
list.get(i).getVerisonStatus() == null || list.get(i).getVerisonStatus() == null ||
list.get(i).getVerison() == null) { list.get(i).getVerison() == null) {
continue;
}
num++;
if (num == 0) {
message.put("isError", "true"); message.put("isError", "true");
message.put("closeable","true"); message.put("closeable","true");
message.put("status","文件导入失败:导入模板不匹配"); message.put("status","文件导入失败:"+"第"+(i + 1) + "条存在必填数据为空,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件导入失败:导入模板不匹配"); return Result.error("文件导入失败:"+"第"+(i + 1) + "条不能为空,请核对");
// } else if (num!=list.size()) {
// return Result.error("文件导入失败:请检查填写文字");
} }
//存入预存表
iRuleVoService.save(list.get(i)); iRuleVoService.save(list.get(i));
} }
} catch (Exception e) { List<Rulex> rulexList;
//update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示 try {
String msg = e.getMessage(); //取出预存表校验字段
log.error(msg, e); List<RuleVo> ruleVoList = iRuleVoService.list();
//if(msg!=null && msg.contains("Duplicate entry"))
if (msg != null && msg.indexOf("Duplicate entry") >= 0) { if (ruleVoList.size() <= 0 || ruleVoList == null) {
message.put("isError", "true"); message.put("isError", "true");
message.put("closeable","true"); message.put("closeable","true");
message.put("status","文件导入失败:有重复数据"); message.put("status","文件导入失败,模板不匹配有空值");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件导入失败:有重复数据!"); return Result.error("文件导入失败,模板不匹配有空值");
} else {
return Result.error("文件导入失败:" + e.getMessage());
}
//update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
} }
} // 将总的记录数传递给前端
message.put("records", String.valueOf(ruleVoList.size()));
List<RuleVo> ruleVoList = iRuleVoService.list();
if (ruleVoList.size() <= 0 || ruleVoList == null) {
message.put("isError", "true");
message.put("closeable","true");
message.put("status","文件导入失败,模板不匹配有空值");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件导入失败,模板不匹配有空值"); rulexList = new ArrayList<>();
}
// 将总的记录数传递给前端 for (int i = 0; i < ruleVoList.size(); i++) {
message.put("records", String.valueOf(ruleVoList.size())); Rulex rulex = new Rulex();
webSocketUtils.sendMessage(loginUser.getId(), message); RuleVo ruleVo = ruleVoList.get(i);
//对应字段
String fieldId = ruleVo.getFieldId();
LambdaQueryWrapper<Fieldx> rulexLambdaQueryWrapper = new LambdaQueryWrapper<>();
rulexLambdaQueryWrapper.eq(Fieldx::getFieldName, fieldId);
Fieldx byId = iFieldxService.getOne(rulexLambdaQueryWrapper);
if (byId == null) {
iRuleVoService.remove(null);
message.put("isError", "true");
message.put("closeable","true");
message.put("status","第"+(i + 1) + "条数据,对应字段输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第"+(i + 1) +"条数据,对应字段输入错误,请核对");
}
rulex.setFieldId(byId.getId());
//对应功能
String functionName = ruleVo.getFunctionId();
LambdaQueryWrapper<Functionx> functionxLambdaQueryWrapper = new LambdaQueryWrapper<Functionx>();
functionxLambdaQueryWrapper.eq(Functionx::getFunctionName, functionName);
Functionx byId1 = functionxService.getOne(functionxLambdaQueryWrapper);
if (byId1 == null) {
iRuleVoService.remove(null);
message.put("isError", "true");
message.put("closeable","true");
message.put("status","第"+(i + 1) +"条数据,对应功能输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第"+(i + 1) +"条数据,对应功能输入错误,请核对");
}
rulex.setFunctionId(byId1.getId());
//对应模块
String moduleName = ruleVo.getModuleId();
LambdaQueryWrapper<Modulex> modulexLambdaQueryWrapper = new LambdaQueryWrapper<>();
modulexLambdaQueryWrapper.eq(Modulex::getModuleName, moduleName);
Modulex byId2 = iModulexService.getOne(modulexLambdaQueryWrapper);
if (byId2 == null) {
iRuleVoService.remove(null);
message.put("isError", "true");
message.put("closeable","true");
message.put("status","第"+(i + 1) +"条数据,对应模块输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第"+(i + 1) +"条数据,对应模块输入错误,请核对");
}
rulex.setModuleId(byId2.getId());
//对应实体
String tableId = ruleVo.getTableId();
LambdaQueryWrapper<Tablex> tableLambdaQueryWrapper = new LambdaQueryWrapper<>();
tableLambdaQueryWrapper.eq(Tablex::getTableName, tableId);
Tablex byId3 = iTablexService.getOne(tableLambdaQueryWrapper);
if (byId3 == null) {
iRuleVoService.remove(null);
message.put("isError", "true");
message.put("closeable","true");
message.put("status","第"+(i + 1) +"条数据,对应实体输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第"+(i + 1) +"条数据,对应实体输入错误,请核对");
}
rulex.setTableId(byId3.getId());
Double aDouble = null;
try {
if (aDouble != null)
aDouble = Double.valueOf(ruleVo.getDuration());
rulex.setDuration(aDouble);
} catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
message.put("isError", "true");
message.put("closeable","true");
message.put("status","第"+(i + 1) +"条数据,任务时长输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第"+(i + 1) +"条数据,任务时长输入错误,请核对");
}
for (int i = 0; i < ruleVoList.size(); i++) { Double d;
Rulex rulex = new Rulex(); try {
RuleVo ruleVo = ruleVoList.get(i); d = Double.valueOf(ruleVo.getRealDuration());
//对应字段 } catch (Exception e) {
String fieldId = ruleVo.getFieldId(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
LambdaQueryWrapper<Fieldx> rulexLambdaQueryWrapper = new LambdaQueryWrapper<>(); message.put("isError", "true");
rulexLambdaQueryWrapper.eq(Fieldx::getFieldName, fieldId); message.put("closeable","true");
Fieldx byId = iFieldxService.getOne(rulexLambdaQueryWrapper); message.put("status","第"+(i + 1) +"条数据,实际时长输入错误,请核对");
if (byId == null) { webSocketUtils.sendMessage(loginUser.getId(), message);
iRuleVoService.remove(null); return Result.error("第"+(i + 1) +"条数据,实际时长输入错误,请核对");
message.put("isError", "true"); }
message.put("closeable","true"); rulex.setRealDuration(d);
message.put("status","字段输入错误,请核对"); Integer integer;
webSocketUtils.sendMessage(loginUser.getId(), message); try {
return Result.error("字段输入错误,请核对"); integer = Integer.valueOf(ruleVo.getWorkLevel());
} } catch (Exception e) {
rulex.setFieldId(byId.getId()); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
//对应功能 message.put("isError", "true");
String functionName = ruleVo.getFunctionId(); message.put("closeable","true");
LambdaQueryWrapper<Functionx> functionxLambdaQueryWrapper = new LambdaQueryWrapper<Functionx>(); message.put("status","第"+(i + 1) +"条数据,任务等级输入错误,请核对");
functionxLambdaQueryWrapper.eq(Functionx::getFunctionName, functionName); webSocketUtils.sendMessage(loginUser.getId(), message);
Functionx byId1 = functionxService.getOne(functionxLambdaQueryWrapper); return Result.error("第"+(i + 1) +"条数据,任务等级输入错误,请核对");
if (byId1 == null) { }
iRuleVoService.remove(null); rulex.setWorkLevel(integer);
message.put("isError", "true"); String workStatus = ruleVo.getWorkStatus();
message.put("closeable","true"); // LambdaQueryWrapper<SysDictItem> sysDictItemLambdaQueryWrapper = new LambdaQueryWrapper<>();
message.put("status","功能输入错误,请核对"); // sysDictItemLambdaQueryWrapper.eq(SysDictItem::getItemText, workStatus).eq(SysDictItem::getDictId, "1645268542514421762");
webSocketUtils.sendMessage(loginUser.getId(), message); // SysDictItem sysDictItem = sysDictItemMapper.selectOne(sysDictItemLambdaQueryWrapper);
return Result.error("功能输入错误,请核对");
} if (workStatus.equals("未发布"))
rulex.setFunctionId(byId1.getId()); rulex.setWorkStatus(0);
//对应模块 else if (workStatus.equals("已发布"))
String moduleName = ruleVo.getModuleId(); rulex.setWorkStatus(1);
LambdaQueryWrapper<Modulex> modulexLambdaQueryWrapper = new LambdaQueryWrapper<>(); else if (workStatus.equals("开发中"))
modulexLambdaQueryWrapper.eq(Modulex::getModuleName, moduleName); rulex.setWorkStatus(2);
Modulex byId2 = iModulexService.getOne(modulexLambdaQueryWrapper); else if (workStatus.equals("已完成"))
if (byId2 == null) { rulex.setWorkStatus(3);
else if (workStatus.equals("已撤回"))
iRuleVoService.remove(null); rulex.setWorkStatus(4);
message.put("isError", "true"); else if (workStatus.equals("DEBUG"))
message.put("closeable","true"); rulex.setWorkStatus(9);
message.put("status","模块输入错误,请核对"); else {
webSocketUtils.sendMessage(loginUser.getId(), message); iRuleVoService.remove(null);
return Result.error("模块输入错误,请核对"); message.put("isError", "true");
} message.put("closeable","true");
rulex.setModuleId(byId2.getId()); message.put("status","第"+(i + 1) +"条数据,任务状态输入错误,请核对");
//对应实体 webSocketUtils.sendMessage(loginUser.getId(), message);
String tableId = ruleVo.getTableId(); return Result.error("第"+(i + 1) +"条数据,任务状态输入错误,请核对");
LambdaQueryWrapper<Tablex> tableLambdaQueryWrapper = new LambdaQueryWrapper<>(); }
tableLambdaQueryWrapper.eq(Tablex::getTableName, tableId); String status = ruleVo.getStatus();
Tablex byId3 = iTablexService.getOne(tableLambdaQueryWrapper); // LambdaQueryWrapper<SysDictItem> sysDictItemLambdaQueryWrapper2 = new LambdaQueryWrapper<>();
if (byId3 == null) { // sysDictItemLambdaQueryWrapper2.eq(SysDictItem::getItemText, status).eq(SysDictItem::getDictId, "1645264493205491713");
// SysDictItem sysDictItem2 = sysDictItemMapper.selectOne(sysDictItemLambdaQueryWrapper2);
iRuleVoService.remove(null); if (status.equals("正常"))
message.put("isError", "true"); rulex.setStatus(1);
message.put("closeable","true"); else if (status.equals("停用"))
message.put("status","实体输入错误,请核对"); rulex.setStatus(0);
webSocketUtils.sendMessage(loginUser.getId(), message); else if (status.equals("废弃"))
return Result.error("实体输入错误,请核对"); rulex.setStatus(9);
} else {
rulex.setTableId(byId3.getId()); iRuleVoService.remove(null);
Double aDouble = null; message.put("isError", "true");
try { message.put("closeable","true");
if (aDouble != null) message.put("status","第"+(i + 1) +"条数据,规则状态输入错误,请核对");
aDouble = Double.valueOf(ruleVo.getDuration()); webSocketUtils.sendMessage(loginUser.getId(), message);
rulex.setDuration(aDouble); return Result.error("第"+(i + 1) +"条数据,规则状态输入错误,请核对");
} catch (Exception e) { }
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了 String verisonStatus = ruleVo.getVerisonStatus();
message.put("isError", "true"); LambdaQueryWrapper<SysDictItem> sysDictItemLambdaQueryWrapper3 = new LambdaQueryWrapper<>();
message.put("closeable","true"); sysDictItemLambdaQueryWrapper3.eq(SysDictItem::getItemText, verisonStatus);
message.put("status","任务时长输入错误,请核对"); SysDictItem sysDictItem3 = sysDictItemMapper.selectOne(sysDictItemLambdaQueryWrapper3);
webSocketUtils.sendMessage(loginUser.getId(), message); if (sysDictItem3 == null) {
return Result.error("任务时长输入错误,请核对"); iRuleVoService.remove(null);
} message.put("isError", "true");
message.put("closeable","true");
message.put("status","第"+(i + 1) +"条数据,版本状态输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第"+(i + 1) +"条数据,版本状态输入错误,请核对");
}
Double d; rulex.setVerisonStatus(Integer.valueOf(sysDictItem3.getItemValue()));
try {
d = Double.valueOf(ruleVo.getRealDuration()); //String转Date
} catch (Exception e) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
message.put("isError", "true"); try {
message.put("closeable","true"); String startTime = ruleVo.getStartTime();
message.put("status","实际时长输入错误,请核对"); if (startTime != null)
webSocketUtils.sendMessage(loginUser.getId(), message); if (!validator.isValid(startTime)) {
return Result.error("实际时长输入错误,请核对"); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
} message.put("isError", "true");
rulex.setRealDuration(d); message.put("closeable","true");
Integer integer; message.put("status","第"+(i + 1) +"条数据,开始时间输入错误");
try { webSocketUtils.sendMessage(loginUser.getId(), message);
integer = Integer.valueOf(ruleVo.getWorkLevel()); return Result.error("第"+(i + 1) +"条数据,开始时间输入错误");
} catch (Exception e) { } else {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了 Date date = simpleDateFormat.parse(startTime);
message.put("isError", "true"); rulex.setStartTime(date);
message.put("closeable","true"); }
message.put("status","任务等级输入错误,请核对"); String submitTime = ruleVo.getSubmitTime();
webSocketUtils.sendMessage(loginUser.getId(), message); if (submitTime != null)
return Result.error("任务等级输入错误,请核对"); if (!validator.isValid(submitTime)) {
} TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
rulex.setWorkLevel(integer); message.put("isError", "true");
String workStatus = ruleVo.getWorkStatus(); message.put("closeable","true");
// LambdaQueryWrapper<SysDictItem> sysDictItemLambdaQueryWrapper = new LambdaQueryWrapper<>(); message.put("status","第"+(i + 1) +"条数据,提交时间输入错误");
// sysDictItemLambdaQueryWrapper.eq(SysDictItem::getItemText, workStatus).eq(SysDictItem::getDictId, "1645268542514421762"); webSocketUtils.sendMessage(loginUser.getId(), message);
// SysDictItem sysDictItem = sysDictItemMapper.selectOne(sysDictItemLambdaQueryWrapper); return Result.error("第"+(i + 1) +"条数据,提交时间输入错误");
} else {
if (workStatus.equals("未发布")) Date date1 = simpleDateFormat.parse(submitTime);
rulex.setWorkStatus(0); rulex.setSubmitTime(date1);
else if (workStatus.equals("已发布")) }
rulex.setWorkStatus(1); } catch (ParseException e) {
else if (workStatus.equals("开发中")) e.printStackTrace();
rulex.setWorkStatus(2); }
else if (workStatus.equals("已完成")) rulex.setRuleNo(ruleVo.getRuleNo());
rulex.setWorkStatus(3); //规则编码
else if (workStatus.equals("已撤回")) String ruleCode = ruleVo.getRuleCode();
rulex.setWorkStatus(4); Functionx functionxServiceById = functionxService.getById(byId1.getId());
else if (workStatus.equals("DEBUG")) String functionCode = functionxServiceById.getFunctionCode();
rulex.setWorkStatus(9); // if (!ruleCode.matches(functionCode))
else { // return Result.error("规则编码错误");
iRuleVoService.remove(null); rulex.setRuleCode(functionCode);
message.put("isError", "true"); //规则描述
message.put("closeable","true"); String pmDescribe = ruleVo.getPmDescribe();
message.put("status","任务状态输入错误,请核对"); if (pmDescribe != null)
webSocketUtils.sendMessage(loginUser.getId(), message); rulex.setPmDescribe(pmDescribe);
return Result.error("任务状态输入错误,请核对"); //分析图
} String diagrams = ruleVo.getDiagrams();
String status = ruleVo.getStatus(); if (diagrams != null)
// LambdaQueryWrapper<SysDictItem> sysDictItemLambdaQueryWrapper2 = new LambdaQueryWrapper<>(); rulex.setDiagrams(diagrams);
// sysDictItemLambdaQueryWrapper2.eq(SysDictItem::getItemText, status).eq(SysDictItem::getDictId, "1645264493205491713"); //版本号
// SysDictItem sysDictItem2 = sysDictItemMapper.selectOne(sysDictItemLambdaQueryWrapper2); Integer integer1;
if (status.equals("正常")) try {
rulex.setStatus(1); integer1 = Integer.valueOf(ruleVo.getVerison());
else if (status.equals("停用")) } catch (Exception e) {
rulex.setStatus(0); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
else if (status.equals("废弃")) message.put("isError", "true");
rulex.setStatus(9); message.put("closeable","true");
else { message.put("status","第"+(i + 1) +"条数据,版本号输入错误,请核对");
iRuleVoService.remove(null); webSocketUtils.sendMessage(loginUser.getId(), message);
message.put("isError", "true"); return Result.error("第"+(i + 1) +"条数据,版本号输入错误,请核对");
message.put("closeable","true"); }
message.put("status","规则状态输入错误,请核对"); rulex.setVerison(String.valueOf(integer1));
webSocketUtils.sendMessage(loginUser.getId(), message); //责任人
return Result.error("规则状态输入错误,请核对"); String managerUsers = ruleVo.getManagerUsers();
} if (managerUsers != null)
String verisonStatus = ruleVo.getVerisonStatus(); rulex.setManagerUsers(managerUsers);
LambdaQueryWrapper<SysDictItem> sysDictItemLambdaQueryWrapper3 = new LambdaQueryWrapper<>(); message.put("status", "正在读取数据");
sysDictItemLambdaQueryWrapper3.eq(SysDictItem::getItemText, verisonStatus);
SysDictItem sysDictItem3 = sysDictItemMapper.selectOne(sysDictItemLambdaQueryWrapper3);
if (sysDictItem3 == null) {
iRuleVoService.remove(null);
message.put("isError", "true");
message.put("closeable","true");
message.put("status","版本状态输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("版本状态输入错误,请核对"); //存入集合待存真实表
} rulexList.add(rulex);
rulex.setVerisonStatus(Integer.valueOf(sysDictItem3.getItemValue()));
//String转Date
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
String startTime = ruleVo.getStartTime();
if (startTime != null)
if (!validator.isValid(startTime)) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
message.put("isError", "true");
message.put("closeable","true");
message.put("status","开始时间输入错误");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("开始时间输入错误");
} else {
Date date = simpleDateFormat.parse(startTime);
rulex.setStartTime(date);
}
String submitTime = ruleVo.getSubmitTime();
if (submitTime != null)
if (!validator.isValid(submitTime)) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
message.put("isError", "true");
message.put("closeable","true");
message.put("status","提交时间输入错误");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("提交时间输入错误");
} else {
Date date1 = simpleDateFormat.parse(submitTime);
rulex.setSubmitTime(date1);
}
} catch (ParseException e) {
e.printStackTrace();
} }
} finally {
//清理预存表
iRuleVoService.remove(null);
}
//存入真实表
Boolean aBoolean = rulexService.saveRule(rulexList, loginUser, message);
//规则序号 if (aBoolean) {
String ruleNo = ruleVo.getRuleNo(); message.put("status", "导入成功");
List<String> list = rulexMapper.checkRuleNo(byId1.getId()); message.put("closeable", "true");
if (list.contains(ruleNo)) {
iRuleVoService.remove(null);
message.put("isError", "true");
message.put("closeable","true");
message.put("status","规则序号已存在");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("规则序号已存在");
}
rulex.setRuleNo(ruleNo);
//规则编码
String ruleCode = ruleVo.getRuleCode();
Functionx functionxServiceById = functionxService.getById(byId1.getId());
String functionCode = functionxServiceById.getFunctionCode();
// if (!ruleCode.matches(functionCode))
// return Result.error("规则编码错误");
rulex.setRuleCode(functionCode);
//规则描述
String pmDescribe = ruleVo.getPmDescribe();
if (pmDescribe != null)
rulex.setPmDescribe(pmDescribe);
//分析图
String diagrams = ruleVo.getDiagrams();
if (diagrams != null)
rulex.setDiagrams(diagrams);
//版本号
Integer integer1;
try {
integer1 = Integer.valueOf(ruleVo.getVerison());
} catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
message.put("isError", "true");
message.put("closeable","true");
message.put("status","版本号输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("版本号输入错误,请核对");
}
rulex.setVerison(String.valueOf(integer1));
//责任人、
String managerUsers = ruleVo.getManagerUsers();
if (managerUsers != null)
rulex.setManagerUsers(managerUsers);
message.put("status", "正在读取数据");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
//存入真实表 return Result.ok("文件导入成功!");
rulexService.saveRule(rulex, loginUser, message, i + 1); }else {
iRuleVoService.remove(null); return Result.error("文件导入失败!");
} }
message.put("status", "导入成功");
message.put("closeable","true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.ok("文件导入成功!");
} }
@GetMapping(value = "/sort") @GetMapping(value = "/sort")

@ -22,7 +22,7 @@ public interface IRulexService extends IService<Rulex> {
List<Rulex> queryRuleListByFunctionId(Functionx functionx); List<Rulex> queryRuleListByFunctionId(Functionx functionx);
void saveRule(Rulex rulex, LoginUser loginUser, Map<String, String> message,int i); Boolean saveRule(List<Rulex> rulexList, LoginUser loginUser, Map<String, String> message);
void saveRulex(Functionx functionx); void saveRulex(Functionx functionx);
} }

@ -18,6 +18,7 @@ import org.jeecg.modules.tablex.service.ITablexService;
import org.jeecg.modules.tablex.ws.WebSocketUtils; import org.jeecg.modules.tablex.ws.WebSocketUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.Date; import java.util.Date;
@ -78,24 +79,39 @@ public class RulexServiceImpl extends ServiceImpl<RulexMapper, Rulex> implements
} }
@Override @Override
public void saveRule(Rulex rulex, LoginUser loginUser, Map<String, String> message,int i) { public Boolean saveRule(List<Rulex> rulexList, LoginUser loginUser, Map<String, String> message) {
try { for (int i = 0; i < rulexList.size(); i++) {
//规则序号
String ruleNo = rulexList.get(i).getRuleNo();
List<String> checkRuleNo = rulexMapper.checkRuleNo(rulexList.get(i).getFunctionId());
if (checkRuleNo.contains(ruleNo)) {
message.put("isError", "true");
message.put("closeable","true");
message.put("status","第"+(i + 1) +"条数据,规则序号已存在");
webSocketUtils.sendMessage(loginUser.getId(), message);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
return false;
}else {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
boolean save = this.save(rulexList.get(i));
Thread.sleep(1000L); message.put("uploaded", String.valueOf(i+1));
this.save(rulex); webSocketUtils.sendMessage(loginUser.getId(), message);
message.put("uploaded", String.valueOf(i )); }
webSocketUtils.sendMessage(loginUser.getId(), message);
} catch (InterruptedException e) {
message.put("isError", "true");
message.put("closeable","true");
message.put("status","导入失败");
webSocketUtils.sendMessage(loginUser.getId(), message);
} }
return true;
}
}
/** /**

Loading…
Cancel
Save