提交 bb0382c1 authored 作者: ww1xhqc's avatar ww1xhqc

[数据模型] 修改校验bug

上级 3d71175a
......@@ -60,23 +60,5 @@ public class QuoteController {
public ResponseEntity saveQuote(@RequestBody Quote quote) {
return ResultUtil.success(quoteService.saveQuote(quote) ,"保存成功!");
}
// @ApiModelProperty("查找所有引用如果没有引用的话就全部的值")
// @PostMapping("/getAllQuoteIf")
// public ResponseEntity getAllQuoteOr(@RequestBody SearchQuoteVO searchQuoteVO) {
// List<Quote> allQuote = quoteService.getAllQuote(searchQuoteVO);
// if (searchQuoteVO.getColumnIds().length!=1){
// throw new ApiException("查询字段补正确");
// }
// if (allQuote.size()<=0){
// Optional<ColumnInfo> byId = columnInfoDao.findById(searchQuoteVO.getColumnIds()[0]);
// ColumnInfo columnInfo = byId.get();
// List diaoyan = model.complexQuery("diaoyan", Arrays.asList(columnInfo.getFieldName()), Arrays.asList(new QueryCondition(columnInfo.getFieldName(),"!=","null", ConnectionType.AND)), columnInfo.getFieldName());
// for (Object str : diaoyan) {
// allQuote.add(new Quote(searchQuoteVO.getColumnIds()[0],str+""));
// }
// }
// return ResultUtil.success(allQuote, "查询成功!");
// }
}
......@@ -21,5 +21,4 @@ public interface QuoteDao extends JpaRepository<Quote, Integer>, JpaSpecificatio
*/
List<Quote> findAllByColumnId(Integer id);
List<Quote> findByColumnIdIn(List<Integer> ids);
}
......@@ -11,9 +11,12 @@ import java.util.List;
* @Author WWW
* @Date 2021/6/29 11:01
*/
public interface RuleDao extends JpaRepository<Rule,Integer>, JpaSpecificationExecutor<Rule> {
public interface RuleDao extends JpaRepository<Rule, Integer>, JpaSpecificationExecutor<Rule> {
/**
* 根据columnId查询
* @param id
* @return
*/
Rule findByColumnId(Integer id);
}
......@@ -257,14 +257,6 @@ public class ModelImpl implements ModelService {
**/
public void insertValue(String tableName, Map map, SessionImpl session) {
TableInfo tableInfo = tableInfoDao.findByModelName(tableName);
// List<ColumnInfo> columnInfos = columnInfoDao.findAllByDbId(tableInfo.getId());
// //所有columnID
// List<Integer> columnIds = columnInfos.stream().map(ColumnInfo::getId).collect(Collectors.toList());
// //所有引用值
// List<String> quoteValues = quoteDao.findByColumnIdIn(columnIds).stream().map(Quote::getValue).collect(Collectors.toList());
//
// validationQuote(quoteValues,"");
EntityPersister entityPersister = session.getEntityPersister(tableName, map);
//主键类型推断
......@@ -648,13 +640,17 @@ public class ModelImpl implements ModelService {
//引用校验
if (!isNull(quoteDao.findAllByColumnId(columnInfo.getId()))){
List<String> quotes = quoteDao.findAllByColumnId(columnInfo.getId()).stream().map(Quote::getValue).collect(Collectors.toList());
validationQuote(quotes, (String) value);
if (!validationQuote(quotes, (String) value)){
throw new ApiException("引用校验不通过!");
}
//规则校验
if (!isNull( ruleDao.findByColumnId(columnInfo.getId()))){
String regular = ruleDao.findByColumnId(columnInfo.getId()).getRegular();
validationRule(regular, (String) value);
}
//规则校验
// if (!isNull( ruleDao.findByColumnId(columnInfo.getId()))){
// String regular = ruleDao.findByColumnId(columnInfo.getId()).getRegular();
// if (!validationRule(regular, (String) value)){
// throw new ApiException("正则校验不通过!");
// }
// }
}
}
......
......@@ -76,10 +76,10 @@ public class QuoteServiceImpl implements QuoteService {
.map(Quote::getValue)
.collect(Collectors.toList());
if (collect.contains(value)) {
return true;
}
return false;
}
return true;
}
}
......@@ -23,13 +23,10 @@ public class CheckUtils {
* @return
*/
public static Boolean validationRule(String regx, String val) {
//加入没有规则就默认不需要校验
if (StringUtils.isNotEmpty(regx) || isNull(regx)) {
return true;
}
//假如规则不为空,值为空默认通过校验
if (!StringUtils.isEmpty(regx)) {
if (StringUtils.isNotEmpty(val) || isNull(val)) {
if (StringUtils.isEmpty(val) || isNull(val)) {
return true;
} else {
Pattern pattern = Pattern.compile(regx);
......
......@@ -55,13 +55,13 @@ public class CreateTableUtil {
" \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n" +
" \"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd\">\n" +
"<hibernate-mapping>\n" +
" <class entity-name=\"" + tableVO.getModelName().toUpperCase() + "\" table=\"" + tableVO.getModelName().toUpperCase() + "\">\n";
" <class entity-name=\"" + tableVO.getModelName().toLowerCase().toUpperCase() + "\" table=\"" + tableVO.getModelName().toLowerCase().toUpperCase() + "\">\n";
xmlMapping += " <id name=\"ID\" type=\"java.lang.Integer\" length=\"11\" unsaved-value=\"null\" >\n" +
" <generator class=\"com.tykj.datawarehouse.base.entity.XMQGenerator\" >" +
"<param name=\"sequence\">SEQUENCE_"+tableVO.getModelName().toUpperCase()+"</param>"+
" <generator class=\"com.tykj.datawarehouse.base.entity.XMQGenerator\" >\n" +
"<param name=\"sequence\">SEQUENCE_" + tableVO.getModelName().toLowerCase().toUpperCase() + "</param>" +
"</generator>" +
" </id>";
" </id>\n";
for (ColumnVO columnVO : dataList) {
......@@ -70,8 +70,8 @@ public class CreateTableUtil {
"\n <property type=\"" + columnVO.getFieldType() + "\" name=\"" + columnVO.getFieldName().toUpperCase() + "\" length=\"" + columnVO.getFieldLength() +
"\" column=\"" + columnVO.getFieldName().toUpperCase() + "\"/>\n";
} catch (Exception e){
throw new ApiException("列名转为大写错误");
} catch (Exception e) {
throw new ApiException("名称不合法!");
}
}
......@@ -140,4 +140,16 @@ public class CreateTableUtil {
String class_ = aClass.replace("class ", "");
return TYPE_MAP.get(class_);
}
/**
*小写
*/
String lowerCaseReg = "^[a-z]+$";
/**
*大写
*/
String upperCaseReg = "^[A-Z]+$";
}
package com.tykj.datawarehouse;
import com.tykj.datawarehouse.model.dao.RuleDao;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import javax.xml.soap.SAAJResult;
......@@ -11,6 +13,8 @@ import java.util.regex.Pattern;
@SpringBootTest
class DataTestApplicationTests {
@Autowired
RuleDao ruleDao;
@Test
void contextLoads() {
......@@ -23,7 +27,7 @@ class DataTestApplicationTests {
// boolean matches = pattern.matcher(str).matches();
//
// System.out.println(matches);
System.out.println(ruleDao.findByColumnId(2));
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论