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

[数据模型] 引用和规则接口

上级 aa84c38c
package com.tykj.datawarehouse.model.controller; package com.tykj.datawarehouse.model.controller;
import com.tykj.datawarehouse.base.result.ApiException;
import com.tykj.datawarehouse.base.result.ResultUtil; import com.tykj.datawarehouse.base.result.ResultUtil;
import com.tykj.datawarehouse.model.dao.QuoteDao;
import com.tykj.datawarehouse.model.dao.RuleDao;
import com.tykj.datawarehouse.model.entity.ColumnInfo; import com.tykj.datawarehouse.model.entity.ColumnInfo;
import com.tykj.datawarehouse.model.entity.Quote;
import com.tykj.datawarehouse.model.entity.Rule;
import com.tykj.datawarehouse.model.entity.TableInfo; import com.tykj.datawarehouse.model.entity.TableInfo;
import com.tykj.datawarehouse.model.entity.vo.*; import com.tykj.datawarehouse.model.entity.vo.*;
import com.tykj.datawarehouse.model.service.ModelService; import com.tykj.datawarehouse.model.service.ModelService;
...@@ -17,9 +22,7 @@ import org.springframework.http.ResponseEntity; ...@@ -17,9 +22,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -41,6 +44,10 @@ public class ModelController { ...@@ -41,6 +44,10 @@ public class ModelController {
@Autowired @Autowired
private ModelHelper modelHelper; private ModelHelper modelHelper;
@Autowired
private QuoteDao quoteDao;
@Autowired
private RuleDao ruleDao;
/** /**
* @param * @param
...@@ -68,6 +75,18 @@ public class ModelController { ...@@ -68,6 +75,18 @@ public class ModelController {
@PostMapping("/getAllField") @PostMapping("/getAllField")
public ResponseEntity getFields(@RequestBody SearchColumnInfoVo searchColumnInfoVo) { public ResponseEntity getFields(@RequestBody SearchColumnInfoVo searchColumnInfoVo) {
List<ColumnInfo> columnInfos = modelService.showModelFields(searchColumnInfoVo); List<ColumnInfo> columnInfos = modelService.showModelFields(searchColumnInfoVo);
for (ColumnInfo columnInfo : columnInfos) {
List<Quote> allQuote = quoteDao.findAllByColumnId(columnInfo.getId());
Rule rule;
try {
rule = ruleDao.findAllByColumnId(columnInfo.getId());
}
catch (Exception e){
throw new ApiException("规则不唯一!");
}
columnInfo.setRule(rule);
columnInfo.setQuoteList(allQuote);
}
return ResultUtil.success(columnInfos, "数据查询成功!"); return ResultUtil.success(columnInfos, "数据查询成功!");
} }
...@@ -209,10 +228,10 @@ public class ModelController { ...@@ -209,10 +228,10 @@ public class ModelController {
public ResponseEntity type() { public ResponseEntity type() {
//这代码狗都不改 //这代码狗都不改
List<ColumnTypeVO> list = new ArrayList<>(); List<ColumnTypeVO> list = new ArrayList<>();
ColumnTypeVO c1 = new ColumnTypeVO("数字","java.lang.Integer", "11"); ColumnTypeVO c1 = new ColumnTypeVO("数字", "java.lang.Integer", "11");
ColumnTypeVO c2 = new ColumnTypeVO("浮点数","java.lang.Double", "11"); ColumnTypeVO c2 = new ColumnTypeVO("浮点数", "java.lang.Double", "11");
ColumnTypeVO c3 = new ColumnTypeVO("单/多行文本","java.lang.String", "255"); ColumnTypeVO c3 = new ColumnTypeVO("单/多行文本", "java.lang.String", "255");
ColumnTypeVO c4 = new ColumnTypeVO("布尔值","java.lang.Boolean", "1"); ColumnTypeVO c4 = new ColumnTypeVO("布尔值", "java.lang.Boolean", "1");
list.add(c1); list.add(c1);
list.add(c2); list.add(c2);
......
package com.tykj.datawarehouse.model.controller; package com.tykj.datawarehouse.model.controller;
import com.tykj.datawarehouse.base.result.ApiException;
import com.tykj.datawarehouse.base.result.ResultUtil; import com.tykj.datawarehouse.base.result.ResultUtil;
import com.tykj.datawarehouse.model.dao.ColumnInfoDao; import com.tykj.datawarehouse.model.dao.ColumnInfoDao;
import com.tykj.datawarehouse.model.entity.ColumnInfo;
import com.tykj.datawarehouse.model.entity.Quote; import com.tykj.datawarehouse.model.entity.Quote;
import com.tykj.datawarehouse.model.entity.customEnums.ConnectionType;
import com.tykj.datawarehouse.model.entity.vo.QueryCondition;
import com.tykj.datawarehouse.model.entity.vo.SearchQuoteVO; import com.tykj.datawarehouse.model.entity.vo.SearchQuoteVO;
import com.tykj.datawarehouse.model.entity.vo.UpdateQuoteVO; import com.tykj.datawarehouse.model.entity.vo.UpdateQuoteVO;
import com.tykj.datawarehouse.model.service.QuoteService; import com.tykj.datawarehouse.model.service.QuoteService;
import com.tykj.datawarehouse.model.service.impl.ModelImpl; import com.tykj.datawarehouse.model.service.impl.ModelImpl;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -38,24 +33,24 @@ public class QuoteController { ...@@ -38,24 +33,24 @@ public class QuoteController {
@Autowired @Autowired
ColumnInfoDao columnInfoDao; ColumnInfoDao columnInfoDao;
@ApiModelProperty("引用删除") @ApiOperation("引用删除")
@GetMapping("/delete") @GetMapping("/delete")
public ResponseEntity deleteQuote(Integer id) { public ResponseEntity deleteQuote(Integer id) {
return ResultUtil.success(quoteService.delQuote(id), "删除成功!"); return ResultUtil.success(quoteService.delQuote(id), "删除成功!");
} }
@ApiModelProperty("引用更新") @ApiOperation("引用更新")
@PostMapping("/update") @PostMapping("/update")
public ResponseEntity UpdateQuote(@RequestBody UpdateQuoteVO updateQuoteVO) { public ResponseEntity UpdateQuote(@RequestBody UpdateQuoteVO updateQuoteVO) {
return ResultUtil.success(quoteService.updateQuote(updateQuoteVO), "更新成功!"); return ResultUtil.success(quoteService.updateQuote(updateQuoteVO), "更新成功!");
} }
@ApiModelProperty("查找所有引用") @ApiOperation("查找所有引用")
@PostMapping("/getAllQuote") @PostMapping("/getAllQuote")
public ResponseEntity getAllQuote(@RequestBody SearchQuoteVO searchQuoteVO) { public ResponseEntity getAllQuote(@RequestBody SearchQuoteVO searchQuoteVO) {
return ResultUtil.success(quoteService.getAllQuote(searchQuoteVO), "查询成功!"); return ResultUtil.success(quoteService.getAllQuote(searchQuoteVO), "查询成功!");
} }
@ApiModelProperty("保存引用") @ApiOperation("保存引用")
@PostMapping("/saveQuote") @PostMapping("/saveQuote")
public ResponseEntity saveQuote(@RequestBody Quote quote) { public ResponseEntity saveQuote(@RequestBody Quote quote) {
return ResultUtil.success(quoteService.saveQuote(quote) ,"保存成功!"); return ResultUtil.success(quoteService.saveQuote(quote) ,"保存成功!");
......
...@@ -5,6 +5,7 @@ import com.tykj.datawarehouse.model.entity.vo.RuleVo; ...@@ -5,6 +5,7 @@ import com.tykj.datawarehouse.model.entity.vo.RuleVo;
import com.tykj.datawarehouse.model.service.RuleService; import com.tykj.datawarehouse.model.service.RuleService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -22,7 +23,7 @@ public class RuleController { ...@@ -22,7 +23,7 @@ public class RuleController {
@Autowired @Autowired
RuleService ruleService; RuleService ruleService;
@ApiModelProperty("规则删除") @ApiOperation("规则删除")
@GetMapping("/delete") @GetMapping("/delete")
public ResponseEntity deleteRule(Integer id) { public ResponseEntity deleteRule(Integer id) {
try { try {
...@@ -31,10 +32,10 @@ public class RuleController { ...@@ -31,10 +32,10 @@ public class RuleController {
} catch (Exception e) { } catch (Exception e) {
} }
return ResultUtil.failed("删除失败!"); return ResultUtil.failed("此id已经被删除!");
} }
@ApiModelProperty("规则新增") @ApiOperation("规则新增")
@PostMapping("/save") @PostMapping("/save")
public ResponseEntity add(@RequestBody RuleVo ruleVo) { public ResponseEntity add(@RequestBody RuleVo ruleVo) {
try { try {
...@@ -46,19 +47,19 @@ public class RuleController { ...@@ -46,19 +47,19 @@ public class RuleController {
return ResultUtil.failed("保存失败!"); return ResultUtil.failed("保存失败!");
} }
@ApiModelProperty("规则修改") @ApiOperation("规则修改")
@PostMapping("/update") @PostMapping("/update")
public ResponseEntity update(@RequestBody RuleVo ruleVo) { public ResponseEntity update(@RequestBody RuleVo ruleVo) {
try { try {
ruleService.add(ruleVo); ruleService.update(ruleVo);
return ResultUtil.success("修改成功!"); return ResultUtil.success("操作成功!");
} catch (Exception ignored) { } catch (Exception ignored) {
} }
return ResultUtil.failed("修改失败!"); return ResultUtil.failed("操作失败!");
} }
@ApiModelProperty("规则修改") @ApiOperation("查询全部")
@PostMapping("/getAll") @PostMapping("/getAll")
public ResponseEntity get() { public ResponseEntity get() {
......
...@@ -18,5 +18,5 @@ public interface RuleDao extends JpaRepository<Rule, Integer>, JpaSpecificationE ...@@ -18,5 +18,5 @@ public interface RuleDao extends JpaRepository<Rule, Integer>, JpaSpecificationE
* @param id * @param id
* @return * @return
*/ */
Rule findByColumnId(Integer id); Rule findAllByColumnId(Integer id);
} }
...@@ -49,6 +49,10 @@ public class ColumnInfo extends BaseEntity { ...@@ -49,6 +49,10 @@ public class ColumnInfo extends BaseEntity {
@ApiModelProperty("详细描述") @ApiModelProperty("详细描述")
private String description; private String description;
@ApiModelProperty("规则")
@Transient
private Rule rule =new Rule();
@ApiModelProperty("引用对象") @ApiModelProperty("引用对象")
@Transient @Transient
private List<Quote> quoteList =new ArrayList<>(); private List<Quote> quoteList =new ArrayList<>();
...@@ -62,6 +66,7 @@ public class ColumnInfo extends BaseEntity { ...@@ -62,6 +66,7 @@ public class ColumnInfo extends BaseEntity {
this.dbName = dbName; this.dbName = dbName;
this.dbId = dbId; this.dbId = dbId;
this.description = description; this.description = description;
} }
......
package com.tykj.datawarehouse.model.entity.vo; package com.tykj.datawarehouse.model.entity.vo;
import com.tykj.datawarehouse.model.entity.Quote; import com.tykj.datawarehouse.model.entity.Quote;
import com.tykj.datawarehouse.model.entity.Rule;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List; import java.util.List;
/** /**
...@@ -34,6 +36,8 @@ public class ColumnVO { ...@@ -34,6 +36,8 @@ public class ColumnVO {
private String fieldTitle; private String fieldTitle;
@ApiModelProperty("字段长度,有默认值") @ApiModelProperty("字段长度,有默认值")
private Integer fieldLength; private Integer fieldLength;
@ApiModelProperty("规则")
private Rule rule;
@ApiModelProperty("详细描述") @ApiModelProperty("详细描述")
private String description; private String description;
@ApiModelProperty("引用数组") @ApiModelProperty("引用数组")
......
...@@ -56,8 +56,8 @@ public interface ModelService { ...@@ -56,8 +56,8 @@ public interface ModelService {
TableInfo newTable(TableVO tableVO); TableInfo newTable(TableVO tableVO);
/** /**
* 根据表名插入数据
* *
*根据表名插入数据
* @param map * @param map
* @return * @return
*/ */
...@@ -65,7 +65,6 @@ public interface ModelService { ...@@ -65,7 +65,6 @@ public interface ModelService {
/** /**
* 插入一组数据 * 插入一组数据
*
* @param mapList * @param mapList
* @return * @return
*/ */
......
...@@ -31,7 +31,6 @@ import org.springframework.data.domain.Page; ...@@ -31,7 +31,6 @@ import org.springframework.data.domain.Page;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -164,7 +163,8 @@ public class ModelImpl implements ModelService { ...@@ -164,7 +163,8 @@ public class ModelImpl implements ModelService {
, columnVO.getFieldLength() , columnVO.getFieldLength()
, tableInfo.getModelName().toUpperCase() , tableInfo.getModelName().toUpperCase()
, tableInfo.getId() , tableInfo.getId()
, columnVO.getDescription()); , columnVO.getDescription()
);
ColumnInfo save = columnInfoDao.save(columnInfo); ColumnInfo save = columnInfoDao.save(columnInfo);
/***/ /***/
List<Quote> quoteList = columnVO.getQuoteList(); List<Quote> quoteList = columnVO.getQuoteList();
...@@ -275,7 +275,7 @@ public class ModelImpl implements ModelService { ...@@ -275,7 +275,7 @@ public class ModelImpl implements ModelService {
Type propertyType = propertyTypes[i]; Type propertyType = propertyTypes[i];
//根据目标Type转换 //根据目标Type转换
changeValueToTargetType(map, value, propertyType, propertyNames[i]); changeValueToTargetType(map, value, propertyType, propertyNames[i]);
//验证 //验证
validationAllRuleAndQuote(tableInfo, value, propertyType, propertyNames[i]); validationAllRuleAndQuote(tableInfo, value, propertyType, propertyNames[i]);
} }
session.saveOrUpdate(tableName, map); session.saveOrUpdate(tableName, map);
...@@ -538,13 +538,14 @@ public class ModelImpl implements ModelService { ...@@ -538,13 +538,14 @@ public class ModelImpl implements ModelService {
String sql1 = "DROP TABLE " + tableInfo.getModelName().toUpperCase(); String sql1 = "DROP TABLE " + tableInfo.getModelName().toUpperCase();
log.info(sql1); log.info(sql1);
jdbcTemplate.execute(sql1); jdbcTemplate.execute(sql1);
//删除SEQUENCE
if ("com.oscar.Driver".equals(env.getProperty("spring.datasource.driver-class-name"))) { if ("com.oscar.Driver".equals(env.getProperty("spring.datasource.driver-class-name"))) {
String sql = "DROP SEQUENCE " + "SEQUENCE_" + tableInfo.getModelName().toUpperCase() + " CASCADE;"; String sql = "DROP SEQUENCE " + "SEQUENCE_" + tableInfo.getModelName().toUpperCase() + " CASCADE;";
log.info(sql); log.info(sql);
jdbcTemplate.execute(sql); jdbcTemplate.execute(sql);
//重新加载metaSource
sessionUtil.init();
} }
//删除此session
sessionUtil.deleteTableInMeteData(tableInfo.getModelName());
} catch (Exception e) { } catch (Exception e) {
throw new ApiException("删除表时出现错误!"); throw new ApiException("删除表时出现错误!");
} }
...@@ -638,16 +639,16 @@ public class ModelImpl implements ModelService { ...@@ -638,16 +639,16 @@ public class ModelImpl implements ModelService {
// 通过 tableInfo 的 Id + columnName 为查询条件 查出 columnInfo // 通过 tableInfo 的 Id + columnName 为查询条件 查出 columnInfo
ColumnInfo columnInfo = columnInfoDao.findByDbIdAndFieldName(tableInfo.getId(), propertyNames); ColumnInfo columnInfo = columnInfoDao.findByDbIdAndFieldName(tableInfo.getId(), propertyNames);
//引用校验 //引用校验
if (!isNull(quoteDao.findAllByColumnId(columnInfo.getId()))){ if (!isNull(quoteDao.findAllByColumnId(columnInfo.getId()))) {
List<String> quotes = quoteDao.findAllByColumnId(columnInfo.getId()).stream().map(Quote::getValue).collect(Collectors.toList()); List<String> quotes = quoteDao.findAllByColumnId(columnInfo.getId()).stream().map(Quote::getValue).collect(Collectors.toList());
if (!validationQuote(quotes, (String) value)){ if (!validationQuote(quotes, (String) value)) {
throw new ApiException("引用校验不通过!"); throw new ApiException("引用校验不通过!");
} }
} }
//规则校验 //规则校验
if (!isNull( ruleDao.findByColumnId(columnInfo.getId()))){ if (!isNull(ruleDao.findAllByColumnId(columnInfo.getId()))) {
String regular = ruleDao.findByColumnId(columnInfo.getId()).getRegular(); String regular = ruleDao.findAllByColumnId(columnInfo.getId()).getRegular();
if (!validationRule(regular, (String) value)){ if (!validationRule(regular, (String) value)) {
throw new ApiException("正则校验不通过!"); throw new ApiException("正则校验不通过!");
} }
} }
......
...@@ -57,7 +57,7 @@ public class CreateTableUtil { ...@@ -57,7 +57,7 @@ public class CreateTableUtil {
"<hibernate-mapping>\n" + "<hibernate-mapping>\n" +
" <class entity-name=\"" + tableVO.getModelName().toLowerCase().toUpperCase() + "\" table=\"" + tableVO.getModelName().toLowerCase().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" + xmlMapping += " <id name=\"id\" type=\"java.lang.Integer\" length=\"11\" unsaved-value=\"null\" >\n" +
" <generator class=\"com.tykj.datawarehouse.base.entity.XMQGenerator\" >\n" + " <generator class=\"com.tykj.datawarehouse.base.entity.XMQGenerator\" >\n" +
"<param name=\"sequence\">SEQUENCE_" + tableVO.getModelName().toLowerCase().toUpperCase() + "</param>" + "<param name=\"sequence\">SEQUENCE_" + tableVO.getModelName().toLowerCase().toUpperCase() + "</param>" +
"</generator>" + "</generator>" +
...@@ -130,17 +130,6 @@ public class CreateTableUtil { ...@@ -130,17 +130,6 @@ public class CreateTableUtil {
} }
public static String getClassName(String aClass) {
int i = aClass.lastIndexOf(".");
String substring = aClass.substring(i + 1);
return substring;
}
public static String getTypeName(String aClass) {
String class_ = aClass.replace("class ", "");
return TYPE_MAP.get(class_);
}
/** /**
*小写 *小写
......
...@@ -52,7 +52,6 @@ public class SessionUtil { ...@@ -52,7 +52,6 @@ public class SessionUtil {
List<TableInfo> all = tableInfoDao.findAll(); List<TableInfo> all = tableInfoDao.findAll();
for (TableInfo tableInfo : all) { for (TableInfo tableInfo : all) {
String xml = tableInfo.getXml(); String xml = tableInfo.getXml();
if (!Strings.isNullOrEmpty(xml)){ if (!Strings.isNullOrEmpty(xml)){
addXml(xml); addXml(xml);
} }
......
...@@ -5,11 +5,6 @@ import org.junit.jupiter.api.Test; ...@@ -5,11 +5,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import javax.xml.soap.SAAJResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@SpringBootTest @SpringBootTest
class DataTestApplicationTests { class DataTestApplicationTests {
...@@ -27,7 +22,8 @@ class DataTestApplicationTests { ...@@ -27,7 +22,8 @@ class DataTestApplicationTests {
// boolean matches = pattern.matcher(str).matches(); // boolean matches = pattern.matcher(str).matches();
// //
// System.out.println(matches); // System.out.println(matches);
System.out.println(ruleDao.findByColumnId(2)); System.out.println(ruleDao.findAllByColumnId(71));
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论