Compare commits

...

2 Commits

  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("closeable","false");
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();
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");
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();
params.setTitleRows(2);//表格标题行数,默认0
params.setHeadRows(1);//表头行数,默认1
params.setNeedSave(true);//是否需要保存上传的Excel,默认为false
try {
message.put("status", "数据预读入");
webSocketUtils.sendMessage(loginUser.getId(), message);
List<RuleVo> list = ExcelImportUtil.importExcel(file.getInputStream(), RuleVo.class, params);
if (list == null || list.size() <= 0) {
List<RuleVo> list = null;
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("closeable","true");
message.put("status","文件导入失败:模板中暂无数据");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件导入失败:模板中暂无数据");
}
int num = 0;
//必要字段判断空值
for (int i = 0; i < list.size(); i++) {
if (
//excel出现必要值未填该行直接跳过
list.get(i).getRuleNo() == null ||
list.get(i).getRuleCode() == 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).getVerisonStatus() == null ||
list.get(i).getVerison() == null) {
continue;
}
num++;
if (num == 0) {
message.put("isError", "true");
message.put("closeable","true");
message.put("status","文件导入失败:导入模板不匹配");
message.put("status","文件导入失败:"+"第"+(i + 1) + "条存在必填数据为空,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件导入失败:导入模板不匹配");
// } else if (num!=list.size()) {
// return Result.error("文件导入失败:请检查填写文字");
return Result.error("文件导入失败:"+"第"+(i + 1) + "条不能为空,请核对");
}
//存入预存表
iRuleVoService.save(list.get(i));
}
} catch (Exception e) {
//update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
String msg = e.getMessage();
log.error(msg, e);
//if(msg!=null && msg.contains("Duplicate entry"))
if (msg != null && msg.indexOf("Duplicate entry") >= 0) {
List<Rulex> rulexList;
try {
//取出预存表校验字段
List<RuleVo> ruleVoList = iRuleVoService.list();
if (ruleVoList.size() <= 0 || ruleVoList == null) {
message.put("isError", "true");
message.put("closeable","true");
message.put("status","文件导入失败:有重复数据");
message.put("status","文件导入失败,模板不匹配有空值");
webSocketUtils.sendMessage(loginUser.getId(), message);
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();
return Result.error("文件导入失败,模板不匹配有空值");
}
}
List<RuleVo> ruleVoList = iRuleVoService.list();
if (ruleVoList.size() <= 0 || ruleVoList == null) {
message.put("isError", "true");
message.put("closeable","true");
message.put("status","文件导入失败,模板不匹配有空值");
// 将总的记录数传递给前端
message.put("records", String.valueOf(ruleVoList.size()));
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("文件导入失败,模板不匹配有空值");
}
// 将总的记录数传递给前端
message.put("records", String.valueOf(ruleVoList.size()));
webSocketUtils.sendMessage(loginUser.getId(), message);
rulexList = new ArrayList<>();
for (int i = 0; i < ruleVoList.size(); i++) {
Rulex rulex = new Rulex();
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++) {
Rulex rulex = new Rulex();
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","字段输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("字段输入错误,请核对");
}
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","功能输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("功能输入错误,请核对");
}
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","模块输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("模块输入错误,请核对");
}
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","实体输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("实体输入错误,请核对");
}
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","任务时长输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("任务时长输入错误,请核对");
}
Double d;
try {
d = Double.valueOf(ruleVo.getRealDuration());
} 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) +"条数据,实际时长输入错误,请核对");
}
rulex.setRealDuration(d);
Integer integer;
try {
integer = Integer.valueOf(ruleVo.getWorkLevel());
} 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) +"条数据,任务等级输入错误,请核对");
}
rulex.setWorkLevel(integer);
String workStatus = ruleVo.getWorkStatus();
// LambdaQueryWrapper<SysDictItem> sysDictItemLambdaQueryWrapper = new LambdaQueryWrapper<>();
// sysDictItemLambdaQueryWrapper.eq(SysDictItem::getItemText, workStatus).eq(SysDictItem::getDictId, "1645268542514421762");
// SysDictItem sysDictItem = sysDictItemMapper.selectOne(sysDictItemLambdaQueryWrapper);
if (workStatus.equals("未发布"))
rulex.setWorkStatus(0);
else if (workStatus.equals("已发布"))
rulex.setWorkStatus(1);
else if (workStatus.equals("开发中"))
rulex.setWorkStatus(2);
else if (workStatus.equals("已完成"))
rulex.setWorkStatus(3);
else if (workStatus.equals("已撤回"))
rulex.setWorkStatus(4);
else if (workStatus.equals("DEBUG"))
rulex.setWorkStatus(9);
else {
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) +"条数据,任务状态输入错误,请核对");
}
String status = ruleVo.getStatus();
// LambdaQueryWrapper<SysDictItem> sysDictItemLambdaQueryWrapper2 = new LambdaQueryWrapper<>();
// sysDictItemLambdaQueryWrapper2.eq(SysDictItem::getItemText, status).eq(SysDictItem::getDictId, "1645264493205491713");
// SysDictItem sysDictItem2 = sysDictItemMapper.selectOne(sysDictItemLambdaQueryWrapper2);
if (status.equals("正常"))
rulex.setStatus(1);
else if (status.equals("停用"))
rulex.setStatus(0);
else if (status.equals("废弃"))
rulex.setStatus(9);
else {
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) +"条数据,规则状态输入错误,请核对");
}
String verisonStatus = ruleVo.getVerisonStatus();
LambdaQueryWrapper<SysDictItem> sysDictItemLambdaQueryWrapper3 = new LambdaQueryWrapper<>();
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","第"+(i + 1) +"条数据,版本状态输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第"+(i + 1) +"条数据,版本状态输入错误,请核对");
}
Double d;
try {
d = Double.valueOf(ruleVo.getRealDuration());
} 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.setRealDuration(d);
Integer integer;
try {
integer = Integer.valueOf(ruleVo.getWorkLevel());
} 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.setWorkLevel(integer);
String workStatus = ruleVo.getWorkStatus();
// LambdaQueryWrapper<SysDictItem> sysDictItemLambdaQueryWrapper = new LambdaQueryWrapper<>();
// sysDictItemLambdaQueryWrapper.eq(SysDictItem::getItemText, workStatus).eq(SysDictItem::getDictId, "1645268542514421762");
// SysDictItem sysDictItem = sysDictItemMapper.selectOne(sysDictItemLambdaQueryWrapper);
if (workStatus.equals("未发布"))
rulex.setWorkStatus(0);
else if (workStatus.equals("已发布"))
rulex.setWorkStatus(1);
else if (workStatus.equals("开发中"))
rulex.setWorkStatus(2);
else if (workStatus.equals("已完成"))
rulex.setWorkStatus(3);
else if (workStatus.equals("已撤回"))
rulex.setWorkStatus(4);
else if (workStatus.equals("DEBUG"))
rulex.setWorkStatus(9);
else {
iRuleVoService.remove(null);
message.put("isError", "true");
message.put("closeable","true");
message.put("status","任务状态输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("任务状态输入错误,请核对");
}
String status = ruleVo.getStatus();
// LambdaQueryWrapper<SysDictItem> sysDictItemLambdaQueryWrapper2 = new LambdaQueryWrapper<>();
// sysDictItemLambdaQueryWrapper2.eq(SysDictItem::getItemText, status).eq(SysDictItem::getDictId, "1645264493205491713");
// SysDictItem sysDictItem2 = sysDictItemMapper.selectOne(sysDictItemLambdaQueryWrapper2);
if (status.equals("正常"))
rulex.setStatus(1);
else if (status.equals("停用"))
rulex.setStatus(0);
else if (status.equals("废弃"))
rulex.setStatus(9);
else {
iRuleVoService.remove(null);
message.put("isError", "true");
message.put("closeable","true");
message.put("status","规则状态输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("规则状态输入错误,请核对");
}
String verisonStatus = ruleVo.getVerisonStatus();
LambdaQueryWrapper<SysDictItem> sysDictItemLambdaQueryWrapper3 = new LambdaQueryWrapper<>();
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","版本状态输入错误,请核对");
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","第"+(i + 1) +"条数据,开始时间输入错误");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第"+(i + 1) +"条数据,开始时间输入错误");
} 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","第"+(i + 1) +"条数据,提交时间输入错误");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第"+(i + 1) +"条数据,提交时间输入错误");
} else {
Date date1 = simpleDateFormat.parse(submitTime);
rulex.setSubmitTime(date1);
}
} catch (ParseException e) {
e.printStackTrace();
}
rulex.setRuleNo(ruleVo.getRuleNo());
//规则编码
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","第"+(i + 1) +"条数据,版本号输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第"+(i + 1) +"条数据,版本号输入错误,请核对");
}
rulex.setVerison(String.valueOf(integer1));
//责任人
String managerUsers = ruleVo.getManagerUsers();
if (managerUsers != null)
rulex.setManagerUsers(managerUsers);
message.put("status", "正在读取数据");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("版本状态输入错误,请核对");
}
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();
//存入集合待存真实表
rulexList.add(rulex);
}
} finally {
//清理预存表
iRuleVoService.remove(null);
}
//存入真实表
Boolean aBoolean = rulexService.saveRule(rulexList, loginUser, message);
//规则序号
String ruleNo = ruleVo.getRuleNo();
List<String> list = rulexMapper.checkRuleNo(byId1.getId());
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", "正在读取数据");
if (aBoolean) {
message.put("status", "导入成功");
message.put("closeable", "true");
webSocketUtils.sendMessage(loginUser.getId(), message);
//存入真实表
rulexService.saveRule(rulex, loginUser, message, i + 1);
iRuleVoService.remove(null);
return Result.ok("文件导入成功!");
}else {
return Result.error("文件导入失败!");
}
message.put("status", "导入成功");
message.put("closeable","true");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.ok("文件导入成功!");
}
@GetMapping(value = "/sort")

@ -22,7 +22,7 @@ public interface IRulexService extends IService<Rulex> {
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);
}

@ -18,6 +18,7 @@ import org.jeecg.modules.tablex.service.ITablexService;
import org.jeecg.modules.tablex.ws.WebSocketUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.ObjectUtils;
import java.util.Date;
@ -78,24 +79,39 @@ public class RulexServiceImpl extends ServiceImpl<RulexMapper, Rulex> implements
}
@Override
public void saveRule(Rulex rulex, LoginUser loginUser, Map<String, String> message,int i) {
try {
public Boolean saveRule(List<Rulex> rulexList, LoginUser loginUser, Map<String, String> message) {
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);
this.save(rulex);
message.put("uploaded", String.valueOf(i ));
message.put("uploaded", String.valueOf(i+1));
webSocketUtils.sendMessage(loginUser.getId(), message);
}
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