导入规则修改

dev^2
zjh 1 year ago
parent 37dfa02311
commit 65a5b17237
  1. 207
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/rulex/controller/RulexController.java
  2. 11
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/rulex/entity/RuleVo.java

@ -53,9 +53,12 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -99,6 +102,8 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
@Autowired @Autowired
private ISysUserService iSysUserService; private ISysUserService iSysUserService;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/** /**
* 分页列表查询 * 分页列表查询
* *
@ -275,7 +280,6 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
return Result.error("文件格式不正确"); return Result.error("文件格式不正确");
} }
//校验时间 //校验时间
final DateValidator validator = new DateValidatorUsingDateFormat("yyyy-MM-dd hh:mm:ss");
ImportParams params = new ImportParams(); ImportParams params = new ImportParams();
params.setTitleRows(2);//表格标题行数,默认0 params.setTitleRows(2);//表格标题行数,默认0
params.setHeadRows(1);//表头行数,默认1 params.setHeadRows(1);//表头行数,默认1
@ -345,32 +349,77 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
rulexList = new ArrayList<>(); rulexList = new ArrayList<>();
//判断模块输入是否错误
List<Modulex> modulexList = iModulexService.list();
for (int i = 0; i < ruleVoList.size(); i++) { for (int i = 0; i < ruleVoList.size(); i++) {
Rulex rulex = new Rulex(); Rulex rulex = new Rulex();
RuleVo ruleVo = ruleVoList.get(i); RuleVo ruleVo = ruleVoList.get(i);
//对应字段
String fieldId = ruleVo.getFieldId(); String pModuleId = ruleVo.getModulePid();
if(fieldId!=null){ String moduleId = ruleVo.getModuleId();
LambdaQueryWrapper<Fieldx> rulexLambdaQueryWrapper = new LambdaQueryWrapper<>(); //对应模块
rulexLambdaQueryWrapper.eq(Fieldx::getFieldName, fieldId); //判断上级模块是否存在
Fieldx byId = iFieldxService.getOne(rulexLambdaQueryWrapper); int n = 0;
if (byId == null) { if (pModuleId != null) {
iRuleVoService.remove(null); //存在
String pid = "";
for (Modulex modulex : modulexList) {
//判断表中是否存在
if (modulex.getModuleName().equals(pModuleId)) {
pid = modulex.getId();
break;
}
n++;
if (n == modulexList.size()) {
message.put("isError", "true"); message.put("isError", "true");
message.put("closeable", "true"); message.put("closeable", "true");
message.put("status","第"+(i + 1) + "条数据,对应字段输入错误,请核对"); message.put("status", "第" + (i + 1) + "条数据,上级模块输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第"+(i + 1) +"条数据,对应字段输入错误,请核对"); return Result.error("第" + (i + 1) + "条数据,上级模块输入错误,请核对");
}
}
//判断上级模块+模块是否存在
for (Modulex modulex : modulexList) {
if (modulex.getModuleName().equals(moduleId) && modulex.getPid().equals(pid)) {
rulex.setModuleId(modulex.getId());
break;
}
n++;
if (n == modulexList.size()) {
message.put("isError", "true");
message.put("closeable", "true");
message.put("status", "第" + (i + 1) + "条数据,模块输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第" + (i + 1) + "条数据,模块输入错误,请核对");
}
}
} else {
n = 0;
//判断模块是否存在
for (Modulex modulex : modulexList) {
if (modulex.getModuleName().equals(moduleId) && modulex.getPid() == null) {
rulex.setModuleId(modulex.getId());
break;
}
n++;
if (n == modulexList.size()) {
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(); String functionName = ruleVo.getFunctionId();
LambdaQueryWrapper<Functionx> functionxLambdaQueryWrapper = new LambdaQueryWrapper<Functionx>(); LambdaQueryWrapper<Functionx> functionxLambdaQueryWrapper = new LambdaQueryWrapper<Functionx>();
functionxLambdaQueryWrapper.eq(Functionx::getFunctionName, functionName); functionxLambdaQueryWrapper.eq(Functionx::getFunctionName, functionName).eq(Functionx::getModuleId, rulex.getModuleId());
Functionx byId1 = functionxService.getOne(functionxLambdaQueryWrapper); Functionx functionx = functionxService.getOne(functionxLambdaQueryWrapper);
if (byId1 == null) { if (functionx == null) {
iRuleVoService.remove(null); iRuleVoService.remove(null);
message.put("isError", "true"); message.put("isError", "true");
message.put("closeable", "true"); message.put("closeable", "true");
@ -378,37 +427,41 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第" + (i + 1) + "条数据,对应功能输入错误,请核对"); return Result.error("第" + (i + 1) + "条数据,对应功能输入错误,请核对");
} }
rulex.setFunctionId(byId1.getId()); rulex.setFunctionId(functionx.getId());
//对应模块 //
String moduleName = ruleVo.getModuleId(); //对应实体
LambdaQueryWrapper<Modulex> modulexLambdaQueryWrapper = new LambdaQueryWrapper<>(); String tableId = ruleVo.getTableId();
modulexLambdaQueryWrapper.eq(Modulex::getModuleName, moduleName); LambdaQueryWrapper<Tablex> tableLambdaQueryWrapper = new LambdaQueryWrapper<>();
Modulex byId2 = iModulexService.getOne(modulexLambdaQueryWrapper); tableLambdaQueryWrapper.eq(Tablex::getTableName, tableId).eq(Tablex::getModuleId, rulex.getModuleId());
if (byId2 == null) { Tablex tablex = iTablexService.getOne(tableLambdaQueryWrapper);
if (tablex == null) {
iRuleVoService.remove(null); iRuleVoService.remove(null);
message.put("isError", "true"); message.put("isError", "true");
message.put("closeable", "true"); message.put("closeable", "true");
message.put("status","第"+(i + 1) +"条数据,对应模块输入错误,请核对"); message.put("status", "第" + (i + 1) + "条数据,对应实体输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第"+(i + 1) +"条数据,对应模块输入错误,请核对"); return Result.error("第" + (i + 1) + "条数据,对应实体输入错误,请核对");
} }
rulex.setModuleId(byId2.getId()); rulex.setTableId(tablex.getId());
//对应实体
String tableId = ruleVo.getTableId();
LambdaQueryWrapper<Tablex> tableLambdaQueryWrapper = new LambdaQueryWrapper<>();
tableLambdaQueryWrapper.eq(Tablex::getTableName, tableId);
Tablex byId3 = iTablexService.getOne(tableLambdaQueryWrapper);
if (byId3 == null) {
//对应字段
String fieldId = ruleVo.getFieldId();
String tableId1 = rulex.getTableId();
if (fieldId != null) {
LambdaQueryWrapper<Fieldx> rulexLambdaQueryWrapper = new LambdaQueryWrapper<>();
rulexLambdaQueryWrapper.eq(Fieldx::getFieldName, fieldId).eq(Fieldx::getTableId, tableId1);
Fieldx fieldx = iFieldxService.getOne(rulexLambdaQueryWrapper);
if (fieldx == null) {
iRuleVoService.remove(null); iRuleVoService.remove(null);
message.put("isError", "true"); message.put("isError", "true");
message.put("closeable", "true"); message.put("closeable", "true");
message.put("status","第"+(i + 1) +"条数据,对应实体输入错误,请核对"); message.put("status", "第" + (i + 1) + "条数据,对应字段输入错误,请核对");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第"+(i + 1) +"条数据,对应实体输入错误,请核对"); return Result.error("第" + (i + 1) + "条数据,对应字段输入错误,请核对");
}
rulex.setFieldId(fieldx.getId());
} }
rulex.setTableId(byId3.getId());
Double aDouble = null; Double aDouble = null;
try { try {
if (aDouble != null) if (aDouble != null)
@ -504,44 +557,46 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
} }
rulex.setVerisonStatus(Integer.valueOf(sysDictItem3.getItemValue())); rulex.setVerisonStatus(Integer.valueOf(sysDictItem3.getItemValue()));
Date date;
//String转Date //String转Date
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String startTime = ruleVo.getStartTime();
if (!StringUtils.isBlank(startTime)) {
String time = getTime(startTime);
try { try {
String startTime = ruleVo.getStartTime(); date = simpleDateFormat.parse(time);
if (startTime != null) rulex.setStartTime(date);
if (!validator.isValid(startTime)) { } catch (ParseException e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
message.put("isError", "true"); message.put("isError", "true");
message.put("closeable", "true"); message.put("closeable", "true");
message.put("status", "第" + (i + 1) + "条数据,开始时间输入错误"); message.put("status", "第" + (i + 1) + "条数据,开始时间输入错误");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第" + (i + 1) + "条数据,开始时间输入错误"); return Result.error("第" + (i + 1) + "条数据,开始时间输入错误");
} else { }
Date date = simpleDateFormat.parse(startTime);
rulex.setStartTime(date);
} }
String submitTime = ruleVo.getSubmitTime(); String submitTime = ruleVo.getSubmitTime();
if (submitTime != null) if (!StringUtils.isBlank(submitTime)){
if (!validator.isValid(submitTime)) { String submitTimeT = getTime(submitTime);
try {
date = simpleDateFormat.parse(submitTimeT);
rulex.setSubmitTime(date);
} catch (ParseException e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚,这样上层就无需去处理异常了
message.put("isError", "true"); message.put("isError", "true");
message.put("closeable", "true"); message.put("closeable", "true");
message.put("status","第"+(i + 1) +"条数据,提交时间输入错误"); message.put("status", "第" + (i + 1) + "条数据,开始时间输入错误");
webSocketUtils.sendMessage(loginUser.getId(), message); webSocketUtils.sendMessage(loginUser.getId(), message);
return Result.error("第"+(i + 1) +"条数据,提交时间输入错误"); return Result.error("第" + (i + 1) + "条数据,开始时间输入错误");
} else {
Date date1 = simpleDateFormat.parse(submitTime);
rulex.setSubmitTime(date1);
} }
} catch (ParseException e) {
e.printStackTrace();
} }
rulex.setRuleNo(ruleVo.getRuleNo());
//规则序号
String ruleNo = ruleVo.getRuleNo();
rulex.setRuleNo(ruleNo);
//规则编码 //规则编码
String ruleCode = ruleVo.getRuleCode(); String ruleCode = ruleVo.getRuleCode();
String functionCode1 = byId1.getFunctionCode(); String functionCode1 = functionx.getFunctionCode();
if (ruleCode == null) { if (ruleCode == null) {
message.put("isError", "true"); message.put("isError", "true");
message.put("closeable", "true"); message.put("closeable", "true");
@ -698,5 +753,51 @@ public class RulexController extends JeecgController<Rulex, IRulexService> {
} }
return null; return null;
} }
/**
* 将日期数字转为时间格式
* daysDuration = 44745
*
* @param daysDuration
* @return
*/
public String getTime(String daysDuration) {
//如果不是数字
if(!isNumeric(daysDuration)){
return daysDuration;
}
//如果是数字
BigDecimal bd = new BigDecimal(daysDuration);
int days = bd.intValue();//天数
int mills = (int) Math.round(bd.subtract(new BigDecimal(days)).doubleValue() * 24 * 3600);
//获取时间
Calendar c = Calendar.getInstance();
c.set(1900, 0, 1);
c.add(Calendar.DATE, days);
int hour = mills / 3600;
int minute = (mills - hour * 3600) / 60;
int second = mills - hour * 3600 - minute * 60;
c.set(Calendar.HOUR_OF_DAY, hour);
c.set(Calendar.MINUTE, minute);
c.set(Calendar.SECOND, second);
return simpleDateFormat.format(c.getTime());
}
/**
* 校验是否数据含小数点
*
* @param str
* @return
*/
private static boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]+\\.*[0-9]*");
Matcher isNum = pattern.matcher(str);
if(!isNum.matches()){
return false;
}
return true;
}
} }

@ -1,7 +1,10 @@
package org.jeecg.modules.demo.rulex.entity; package org.jeecg.modules.demo.rulex.entity;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
@ -59,6 +62,14 @@ public class RuleVo implements Serializable {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新日期") @ApiModelProperty(value = "更新日期")
private String updateTime; private String updateTime;
/**
* 对应模块父id
*/
@TableField(exist = false)
@Excel(name = "对应模块父模块", width = 15)
@ApiModelProperty(value = "对应模块")
private java.lang.String modulePid;
/** /**
* 对应模块id * 对应模块id
*/ */

Loading…
Cancel
Save