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

[数据模型] 增加方法

上级 810ec6ba
...@@ -53,8 +53,8 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter { ...@@ -53,8 +53,8 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
private ApiInfo apiInfo() { private ApiInfo apiInfo() {
return new ApiInfoBuilder() return new ApiInfoBuilder()
.title("excel->表") .title("swagger")
.description("excel 转化的实体类") .description("swagger")
.version("1.0") .version("1.0")
.build(); .build();
} }
......
package com.tykj.datawarehouse.base.entity; package com.tykj.datawarehouse.base.entity;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentityGenerator; import org.hibernate.id.SequenceGenerator;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
...@@ -12,7 +12,7 @@ import java.util.HashMap; ...@@ -12,7 +12,7 @@ import java.util.HashMap;
* @class UUIDHexGenerator * @class UUIDHexGenerator
* @packageName com.tykj.base.entity * @packageName com.tykj.base.entity
**/ **/
public class XMQGenerator extends IdentityGenerator { public class XMQGenerator extends SequenceGenerator {
public XMQGenerator () { public XMQGenerator () {
super(); super();
...@@ -28,4 +28,5 @@ public class XMQGenerator extends IdentityGenerator { ...@@ -28,4 +28,5 @@ public class XMQGenerator extends IdentityGenerator {
} }
return super.generate(s, obj); return super.generate(s, obj);
} }
} }
...@@ -17,6 +17,9 @@ import org.springframework.http.ResponseEntity; ...@@ -17,6 +17,9 @@ 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.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -206,5 +209,22 @@ public class ModelController { ...@@ -206,5 +209,22 @@ public class ModelController {
return ResultUtil.failed("模型类型不支持删除数据!"); return ResultUtil.failed("模型类型不支持删除数据!");
} }
@ApiOperation("字段类型")
@GetMapping("/type")
public ResponseEntity type() {
//这代码狗都不改
List<ColumnTypeVO> list = new ArrayList<>();
ColumnTypeVO c1 = new ColumnTypeVO("数字","java.lang.Integer", "11");
ColumnTypeVO c2 = new ColumnTypeVO("浮点数","java.lang.Double", "11");
ColumnTypeVO c3 = new ColumnTypeVO("单/多行文本","java.lang.String", "255");
ColumnTypeVO c4 = new ColumnTypeVO("布尔值","java.lang.Boolean", "1");
list.add(c1);
list.add(c2);
list.add(c3);
list.add(c4);
return ResultUtil.success(list, "查询成功!");
}
} }
package com.tykj.datawarehouse.model.controller;
import com.tykj.datawarehouse.base.result.ApiException;
import com.tykj.datawarehouse.base.result.ResultUtil;
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.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.UpdateQuoteVO;
import com.tykj.datawarehouse.model.service.QuoteService;
import com.tykj.datawarehouse.model.service.impl.ModelImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* @Description TODO
* @Author WWW
* @Date 2021/5/17 15:57
*/
@Api(tags = "引用接口")
@RestController
@RequestMapping("/quote")
public class QuoteController {
@Autowired
private QuoteService quoteService;
@Autowired
ModelImpl model;
@Autowired
ColumnInfoDao columnInfoDao;
@ApiModelProperty("引用删除")
@GetMapping("/delete")
public ResponseEntity deleteQuote(Integer id) {
return ResultUtil.success(quoteService.delQuote(id), "删除成功!");
}
@ApiModelProperty("引用更新")
@PostMapping("/update")
public ResponseEntity UpdateQuote(@RequestBody UpdateQuoteVO updateQuoteVO) {
return ResultUtil.success(quoteService.updateQuote(updateQuoteVO), "更新成功!");
}
@ApiModelProperty("查找所有引用")
@PostMapping("/getAllQuote")
public ResponseEntity getAllQuote(@RequestBody SearchQuoteVO searchQuoteVO) {
return ResultUtil.success(quoteService.getAllQuote(searchQuoteVO), "查询成功!");
}
@ApiModelProperty("保存引用")
@PostMapping("/saveQuote")
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, "查询成功!");
// }
}
package com.tykj.datawarehouse.model.controller;
import com.tykj.datawarehouse.base.result.ResultUtil;
import com.tykj.datawarehouse.model.entity.vo.RuleVo;
import com.tykj.datawarehouse.model.service.RuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* @Description TODO
* @Author WWW
* @Date 2021/6/29 16:39
*/
@Api(tags = "规则接口")
@RestController
@RequestMapping("/rule")
public class RuleController {
@Autowired
RuleService ruleService;
@ApiModelProperty("规则删除")
@GetMapping("/delete")
public ResponseEntity deleteRule(Integer id) {
try {
ruleService.del(id);
return ResultUtil.success("删除成功!");
} catch (Exception e) {
}
return ResultUtil.failed("删除失败!");
}
@ApiModelProperty("规则新增")
@PostMapping("/save")
public ResponseEntity add(@RequestBody RuleVo ruleVo) {
try {
ruleService.add(ruleVo);
return ResultUtil.success("保存成功!");
} catch (Exception e) {
}
return ResultUtil.failed("保存失败!");
}
@ApiModelProperty("规则修改")
@PostMapping("/update")
public ResponseEntity update(@RequestBody RuleVo ruleVo) {
try {
ruleService.add(ruleVo);
return ResultUtil.success("修改成功!");
} catch (Exception ignored) {
}
return ResultUtil.failed("修改失败!");
}
@ApiModelProperty("规则修改")
@PostMapping("/getAll")
public ResponseEntity get() {
return ResultUtil.success(ruleService.getAll(), "查询成功");
}
}
...@@ -31,4 +31,12 @@ public interface ColumnInfoDao extends JpaRepository<ColumnInfo, Integer>, JpaSp ...@@ -31,4 +31,12 @@ public interface ColumnInfoDao extends JpaRepository<ColumnInfo, Integer>, JpaSp
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Modifying @Modifying
void deleteAllByDbId(Integer id); void deleteAllByDbId(Integer id);
/**
* @param id
* @param columnName
* @return
*/
ColumnInfo findByDbIdAndFieldName(Integer id,String columnName);
} }
...@@ -20,4 +20,6 @@ public interface QuoteDao extends JpaRepository<Quote, Integer>, JpaSpecificatio ...@@ -20,4 +20,6 @@ public interface QuoteDao extends JpaRepository<Quote, Integer>, JpaSpecificatio
* @return * @return
*/ */
List<Quote> findAllByColumnId(Integer id); List<Quote> findAllByColumnId(Integer id);
List<Quote> findByColumnIdIn(List<Integer> ids);
} }
package com.tykj.datawarehouse.model.dao;
import com.tykj.datawarehouse.model.entity.Rule;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List;
/**
* @Description TODO
* @Author WWW
* @Date 2021/6/29 11:01
*/
public interface RuleDao extends JpaRepository<Rule,Integer>, JpaSpecificationExecutor<Rule> {
Rule findByColumnId(Integer id);
}
...@@ -24,21 +24,5 @@ public interface TableInfoDao extends JpaRepository<TableInfo, Integer>, JpaSpec ...@@ -24,21 +24,5 @@ public interface TableInfoDao extends JpaRepository<TableInfo, Integer>, JpaSpec
* @return * @return
*/ */
TableInfo findByModelName(String name); TableInfo findByModelName(String name);
/**
* 删除modelType是0的数据
* @param type
* @return
*/
@Transactional(rollbackFor = Exception.class)
@Modifying
List<TableInfo> deleteAllByModelType(Integer type);
/**
* 根据模型类型查找
* @param modeType
* @return
*/
List<TableInfo> findAllByModelType(Integer modeType);
} }
...@@ -10,6 +10,7 @@ import lombok.NoArgsConstructor; ...@@ -10,6 +10,7 @@ import lombok.NoArgsConstructor;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
...@@ -50,7 +51,7 @@ public class ColumnInfo extends BaseEntity { ...@@ -50,7 +51,7 @@ public class ColumnInfo extends BaseEntity {
@ApiModelProperty("引用对象") @ApiModelProperty("引用对象")
@Transient @Transient
private List<Quote> quoteList; private List<Quote> quoteList =new ArrayList<>();
public ColumnInfo(Integer primaryKey, String fieldName, String fieldTitle, String fieldType, Integer fieldLength, String dbName, Integer dbId, String description) { public ColumnInfo(Integer primaryKey, String fieldName, String fieldTitle, String fieldType, Integer fieldLength, String dbName, Integer dbId, String description) {
this.primaryKey = primaryKey; this.primaryKey = primaryKey;
......
...@@ -10,6 +10,9 @@ import lombok.NoArgsConstructor; ...@@ -10,6 +10,9 @@ import lombok.NoArgsConstructor;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
/**
* @author HASEE
*/
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Data @Data
...@@ -17,18 +20,13 @@ import javax.persistence.Table; ...@@ -17,18 +20,13 @@ import javax.persistence.Table;
@Table @Table
@ApiModel("规则表") @ApiModel("规则表")
public class Rule extends BaseEntity { public class Rule extends BaseEntity {
@ApiModelProperty("规则key,不能为空")
private String ruleKey;
@ApiModelProperty("key中文") @ApiModelProperty("表id")
private String name; private Integer tableId;
@ApiModelProperty("key数据类型") @ApiModelProperty("字段id")
private String type; private Integer columnId;
@ApiModelProperty("规则") @ApiModelProperty("规则")
private String rule; private String regular;
@ApiModelProperty("等级,1 返回修改,2 直接删除")
private String level;
@ApiModelProperty("对比结果")
private String result;
@ApiModelProperty("是否需要对比多个sheet数据, 0不用,1需要对比所有sheet的name是否相同,2 唯一值")
private Integer compare;
} }
...@@ -41,32 +41,8 @@ public class TableInfo extends BaseEntity { ...@@ -41,32 +41,8 @@ public class TableInfo extends BaseEntity {
@ApiModelProperty("详细描述") @ApiModelProperty("详细描述")
private String description; private String description;
/**
*0是扫描,1是自建,2基础对象转变的业务对象
*/
@ApiModelProperty("建表类型")
private Integer modelType;
@ApiModelProperty("执行人(保留字段)")
private String reviser;
@ApiModelProperty("父表名称")
private String parentTable;
/**
* 聚合对象主表id
*/
@ApiModelProperty("主表id")
private Integer mainTableId;
@Lob @Lob
@ApiModelProperty("表对应hbm.xml") @ApiModelProperty("表对应hbm.xml")
private String xml; private String xml;
@ApiModelProperty("备份表")
private String backName;
@Lob
@ApiModelProperty("备份表XML")
private String backXml;
} }
package com.tykj.datawarehouse.model.entity.vo; package com.tykj.datawarehouse.model.entity.vo;
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;
...@@ -8,16 +9,17 @@ import lombok.NoArgsConstructor; ...@@ -8,16 +9,17 @@ import lombok.NoArgsConstructor;
/** /**
* @Description TODO * @Description TODO
* @Author WWW * @Author WWW
* @Date 2021/5/19 15:53 * @Date 2021/6/30 9:51
*/ */
@ApiModel("列类型VO")
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class IndexVO { public class ColumnTypeVO {
@ApiModelProperty("tableId") @ApiModelProperty("中文名")
private Integer dbId; private String lab;
@ApiModelProperty("版本") @ApiModelProperty("类型")
private String versionId; private String value;
@ApiModelProperty("索引") @ApiModelProperty("长度")
private String ids; private String lengths;
} }
package com.tykj.datawarehouse.model.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class ExcelErrorVo {
private String fileName;//文件名字
private String uintName;//本单位名字
private String tel;//本单位联系方式
private String buildTel;//承建单位联系方式
List<String> result;//预览有问题的文件结果
}
package com.tykj.datawarehouse.model.entity.vo;
import com.tykj.datawarehouse.base.page.JpaCustomPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("查询规则信息VO")
public class ExcelLogVo extends JpaCustomPage {
@ApiModelProperty("成功")
private String result;
}
package com.tykj.datawarehouse.model.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ExcelVo {
private int total;
private int successNum;
private int errorNum;
private int importNum;
private Date date;
private List<ExcelErrorVo> list;
}
package com.tykj.datawarehouse.model.entity.vo;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
import java.util.Map;
/**
* @author HuangXiahao
* @version V1.0
* @class InsertListVo
* @packageName com.tykj.model_layer.entity.vo
**/
@AllArgsConstructor
@NoArgsConstructor
@Data
@ApiModel("删除VO类")
public class InsertListVo {
List<Map<String, Object>> mapList;
}
package com.tykj.datawarehouse.model.entity.vo; package com.tykj.datawarehouse.model.entity.vo;
import com.tykj.datawarehouse.base.page.JpaCustomPage;
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;
/**
* @author HASEE
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@ApiModel("查询规则信息VO") @ApiModel("查询规则信息VO")
public class RuleVo extends JpaCustomPage { public class RuleVo{
@ApiModelProperty("规则key") @ApiModelProperty
private String key; private Integer id;
@ApiModelProperty("表id")
private Integer tableId;
@ApiModelProperty("字段id")
private Integer columnId;
@ApiModelProperty("规则")
private String regular;
} }
...@@ -5,6 +5,7 @@ import com.tykj.datawarehouse.model.entity.ColumnInfo; ...@@ -5,6 +5,7 @@ import com.tykj.datawarehouse.model.entity.ColumnInfo;
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 org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
...@@ -114,6 +115,7 @@ public interface ModelService { ...@@ -114,6 +115,7 @@ public interface ModelService {
* @param delTableVO * @param delTableVO
* @return * @return
*/ */
@Transactional(rollbackFor = Exception.class)
int delTable(DelTableVO delTableVO); int delTable(DelTableVO delTableVO);
......
package com.tykj.datawarehouse.model.service;
import com.tykj.datawarehouse.model.entity.Rule;
import com.tykj.datawarehouse.model.entity.vo.RuleVo;
import java.util.List;
/**
* @Description TODO
* @Author WWW
* @Date 2021/6/29 11:04
*/
public interface RuleService {
/**
* 新增
* @param ruleVo
*/
void add(RuleVo ruleVo);
/**
* 修改
* @param ruleVo
*/
void update(RuleVo ruleVo);
/**
* 删除
* @param id
*/
void del(Integer id);
/**
* 查询
* @return
*/
List<Rule> getAll();
}
...@@ -5,6 +5,7 @@ import com.github.wenhao.jpa.Specifications; ...@@ -5,6 +5,7 @@ import com.github.wenhao.jpa.Specifications;
import com.tykj.datawarehouse.base.result.ApiException; import com.tykj.datawarehouse.base.result.ApiException;
import com.tykj.datawarehouse.model.dao.ColumnInfoDao; import com.tykj.datawarehouse.model.dao.ColumnInfoDao;
import com.tykj.datawarehouse.model.dao.QuoteDao; import com.tykj.datawarehouse.model.dao.QuoteDao;
import com.tykj.datawarehouse.model.dao.RuleDao;
import com.tykj.datawarehouse.model.dao.TableInfoDao; import com.tykj.datawarehouse.model.dao.TableInfoDao;
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.Quote;
...@@ -37,6 +38,8 @@ import java.time.ZoneId; ...@@ -37,6 +38,8 @@ import java.time.ZoneId;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.tykj.datawarehouse.model.utils.CheckUtils.validationQuote;
import static com.tykj.datawarehouse.model.utils.CheckUtils.validationRule;
import static com.tykj.datawarehouse.model.utils.CreateTableUtil.createTable; import static com.tykj.datawarehouse.model.utils.CreateTableUtil.createTable;
import static com.tykj.datawarehouse.model.utils.HqlUtil.createQuery; import static com.tykj.datawarehouse.model.utils.HqlUtil.createQuery;
import static java.util.Objects.isNull; import static java.util.Objects.isNull;
...@@ -73,6 +76,9 @@ public class ModelImpl implements ModelService { ...@@ -73,6 +76,9 @@ public class ModelImpl implements ModelService {
@Autowired @Autowired
private QuoteDao quoteDao; private QuoteDao quoteDao;
@Autowired
private RuleDao ruleDao;
/** /**
* @param * @param
* @return java.util.List<com.tykj.workflowcore.model_layer.model.TableInfo> * @return java.util.List<com.tykj.workflowcore.model_layer.model.TableInfo>
...@@ -138,10 +144,10 @@ public class ModelImpl implements ModelService { ...@@ -138,10 +144,10 @@ public class ModelImpl implements ModelService {
List<ColumnVO> dataList = tableVO.getDataList(); List<ColumnVO> dataList = tableVO.getDataList();
//构建TableInfo //构建TableInfo
TableInfo tableInfo = new TableInfo(); TableInfo tableInfo = new TableInfo();
tableInfo.setModelName(tableVO.getModelName()); tableInfo.setModelName(tableVO.getModelName().toUpperCase());
tableInfo.setModelTitle(tableVO.getModelTitle()); tableInfo.setModelTitle(tableVO.getModelTitle());
tableInfo.setXml(xmlMapping); tableInfo.setXml(xmlMapping);
tableInfo.setModelType(tableVO.getModelType());
tableInfo.setDescription(tableVO.getDescription()); tableInfo.setDescription(tableVO.getDescription());
tableInfoDao.save(tableInfo); tableInfoDao.save(tableInfo);
//构建字段 //构建字段
...@@ -151,11 +157,11 @@ public class ModelImpl implements ModelService { ...@@ -151,11 +157,11 @@ public class ModelImpl implements ModelService {
for (ColumnVO columnVO : dataList) { for (ColumnVO columnVO : dataList) {
ColumnInfo columnInfo = new ColumnInfo( ColumnInfo columnInfo = new ColumnInfo(
columnVO.getPrimaryKey() columnVO.getPrimaryKey()
, columnVO.getFieldName() , columnVO.getFieldName().toUpperCase()
, columnVO.getFieldTitle() , columnVO.getFieldTitle()
, columnVO.getFieldType() , columnVO.getFieldType()
, columnVO.getFieldLength() , columnVO.getFieldLength()
, columnVO.getDescription() , tableInfo.getModelName().toUpperCase()
, tableInfo.getId() , tableInfo.getId()
, columnVO.getDescription()); , columnVO.getDescription());
ColumnInfo save = columnInfoDao.save(columnInfo); ColumnInfo save = columnInfoDao.save(columnInfo);
...@@ -249,6 +255,16 @@ public class ModelImpl implements ModelService { ...@@ -249,6 +255,16 @@ public class ModelImpl implements ModelService {
* @Date 16:17 2021/3/5 * @Date 16:17 2021/3/5
**/ **/
public void insertValue(String tableName, Map map, SessionImpl session) { 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); EntityPersister entityPersister = session.getEntityPersister(tableName, map);
//主键类型推断 //主键类型推断
String identifierPropertyName = entityPersister.getIdentifierPropertyName(); String identifierPropertyName = entityPersister.getIdentifierPropertyName();
...@@ -257,13 +273,18 @@ public class ModelImpl implements ModelService { ...@@ -257,13 +273,18 @@ public class ModelImpl implements ModelService {
} }
//类型推断 根据目标值的类型强转目标值的目标类型 //类型推断 根据目标值的类型强转目标值的目标类型
Type[] propertyTypes = entityPersister.getPropertyTypes(); Type[] propertyTypes = entityPersister.getPropertyTypes();
//这个是列名 数组
String[] propertyNames = entityPersister.getEntityPersister().getPropertyNames(); String[] propertyNames = entityPersister.getEntityPersister().getPropertyNames();
//这个是插入的值 数组
Object[] propertyValuesToInsert = entityPersister.getPropertyValuesToInsert(map, null, session); Object[] propertyValuesToInsert = entityPersister.getPropertyValuesToInsert(map, null, session);
for (int i = 0; i < propertyValuesToInsert.length; i++) { for (int i = 0; i < propertyValuesToInsert.length; i++) {
Object value = propertyValuesToInsert[i]; Object value = propertyValuesToInsert[i];
Type propertyType = propertyTypes[i]; Type propertyType = propertyTypes[i];
//根据目标Type转换 //根据目标Type转换
changeValueToTargetType(map, value, propertyType, propertyNames[i]); changeValueToTargetType(map, value, propertyType, propertyNames[i]);
//todo
// 通过 tableInfo 的 Id + columnName 为查询条件 查出 columnInfo
validationAllRuleAndQuote(tableInfo, value, propertyType, propertyNames[i]);
} }
session.saveOrUpdate(tableName, map); session.saveOrUpdate(tableName, map);
} }
...@@ -358,7 +379,7 @@ public class ModelImpl implements ModelService { ...@@ -358,7 +379,7 @@ public class ModelImpl implements ModelService {
tableInfo.setUpdatedTime(new Date()); tableInfo.setUpdatedTime(new Date());
tableInfo.setDescription(tableVO.getDescription()); tableInfo.setDescription(tableVO.getDescription());
tableInfo.setModelTitle(tableVO.getModelTitle()); tableInfo.setModelTitle(tableVO.getModelTitle());
tableInfo.setModelType(tableVO.getModelType());
String xml = createTable(tableVO); String xml = createTable(tableVO);
tableInfo.setXml(xml); tableInfo.setXml(xml);
...@@ -372,7 +393,11 @@ public class ModelImpl implements ModelService { ...@@ -372,7 +393,11 @@ public class ModelImpl implements ModelService {
List<String> sqls = getTableSqls(tableInfo.getModelName(), originalColumnInfos, currentColumnInfos); List<String> sqls = getTableSqls(tableInfo.getModelName(), originalColumnInfos, currentColumnInfos);
//执行sql语句 //执行sql语句
for (String sql : sqls) { for (String sql : sqls) {
jdbcTemplate.execute(sql); try {
jdbcTemplate.execute(sql);
} catch (Exception e) {
throw new ApiException("sql执行错误" + e.getMessage());
}
} }
...@@ -454,7 +479,7 @@ public class ModelImpl implements ModelService { ...@@ -454,7 +479,7 @@ public class ModelImpl implements ModelService {
} }
//遍历获取删除列的情况 //遍历获取删除列的情况
for (ColumnInfo originColumnInfo : origin) { for (ColumnInfo originColumnInfo : origin) {
if (!originColumnInfo.getFieldName().equals("id")) { if (!"id".equals(originColumnInfo.getFieldName())) {
boolean noneMatch = current.stream() boolean noneMatch = current.stream()
.noneMatch(columnInfo1 -> Objects.equals(originColumnInfo.getId(), columnInfo1.getId())); .noneMatch(columnInfo1 -> Objects.equals(originColumnInfo.getId(), columnInfo1.getId()));
if (noneMatch) { if (noneMatch) {
...@@ -517,10 +542,17 @@ public class ModelImpl implements ModelService { ...@@ -517,10 +542,17 @@ public class ModelImpl implements ModelService {
try { try {
tableInfoDao.deleteById(delTableVO.getId()); tableInfoDao.deleteById(delTableVO.getId());
List<ColumnInfo> allByDbId = columnInfoDao.findAllByDbId(delTableVO.getId()); List<ColumnInfo> allByDbId = columnInfoDao.findAllByDbId(delTableVO.getId());
columnInfoDao.deleteInBatch(allByDbId); columnInfoDao.deleteAll(allByDbId);
jdbcTemplate.execute("drop table " + tableInfo.getModelName()); String sql1 = "DROP TABLE " + tableInfo.getModelName().toUpperCase();
log.info(sql1);
jdbcTemplate.execute(sql1);
if ("com.oscar.Driver".equals(env.getProperty("spring.datasource.driver-class-name"))) {
String sql = "DROP SEQUENCE " + "SEQUENCE_" + tableInfo.getModelName().toUpperCase() + " CASCADE;";
log.info(sql);
jdbcTemplate.execute(sql);
}
} catch (Exception e) { } catch (Exception e) {
throw new ApiException("删除出现错误!"); throw new ApiException("删除表时出现错误!");
} }
return 1; return 1;
} }
...@@ -556,6 +588,9 @@ public class ModelImpl implements ModelService { ...@@ -556,6 +588,9 @@ public class ModelImpl implements ModelService {
void changeValueToTargetType(Map map, Object value, Type propertyType, String propertyName) { void changeValueToTargetType(Map map, Object value, Type propertyType, String propertyName) {
// TimestampType // TimestampType
if ("UPDATE_TIME".equals(propertyName)) {
map.put(propertyName, new Date());
}
if (propertyType instanceof TimestampType) { if (propertyType instanceof TimestampType) {
if (value instanceof String) { if (value instanceof String) {
if (StringUtils.isNotEmpty((String) value)) { if (StringUtils.isNotEmpty((String) value)) {
...@@ -586,7 +621,14 @@ public class ModelImpl implements ModelService { ...@@ -586,7 +621,14 @@ public class ModelImpl implements ModelService {
if (propertyType instanceof StringType) { if (propertyType instanceof StringType) {
//然后调用强转方法 //然后调用强转方法
map.put(propertyName, value + ""); map.put(propertyName, value + "");
//
} }
if (propertyType instanceof BooleanType) {
map.put(propertyName, value);
}
if (propertyType instanceof DoubleType) { if (propertyType instanceof DoubleType) {
try { try {
Double i1 = Double.valueOf(value + ""); Double i1 = Double.valueOf(value + "");
...@@ -597,6 +639,20 @@ public class ModelImpl implements ModelService { ...@@ -597,6 +639,20 @@ public class ModelImpl implements ModelService {
} }
} }
void validationAllRuleAndQuote(TableInfo tableInfo, Object value, Type propertyType, String propertyNames) {
if (propertyType instanceof StringType) {
ColumnInfo columnInfo = columnInfoDao.findByDbIdAndFieldName(tableInfo.getId(), propertyNames);
//引用校验
List<String> quotes = quoteDao.findAllByColumnId(columnInfo.getId()).stream().map(Quote::getValue).collect(Collectors.toList());
validationQuote(quotes, (String) value);
//规则校验
String regular = ruleDao.findByColumnId(columnInfo.getId()).getRegular();
validationRule(regular, (String) value);
}
}
private Boolean isNotEmpty(String str) { private Boolean isNotEmpty(String str) {
return StringUtils.isNotEmpty(str); return StringUtils.isNotEmpty(str);
} }
......
...@@ -18,6 +18,8 @@ import java.util.ArrayList; ...@@ -18,6 +18,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static java.util.Objects.isNull;
/** /**
* @Description TODO * @Description TODO
* @Author WWW * @Author WWW
...@@ -40,15 +42,15 @@ public class QuoteServiceImpl implements QuoteService { ...@@ -40,15 +42,15 @@ public class QuoteServiceImpl implements QuoteService {
} }
@Override @Override
public List<Quote> getAllQuote(SearchQuoteVO searchQuoteVO) { public List<Quote> getAllQuote(SearchQuoteVO sqv) {
PredicateBuilder<Quote> and = Specifications.and(); PredicateBuilder<Quote> and = Specifications.and();
if (searchQuoteVO!=null){ if (sqv!=null){
and.like(searchQuoteVO.getValue() != null && StringUtils.isNotEmpty(searchQuoteVO.getValue()), and.like(!isNull(sqv.getValue() ) && StringUtils.isNotEmpty(sqv.getValue()),
"value", "%" + searchQuoteVO.getValue() + "%"); "value", "%" + sqv.getValue() + "%");
and.in(searchQuoteVO.getColumnIds()!=null && searchQuoteVO.getColumnIds().length>0, and.in(sqv.getColumnIds()!=null && sqv.getColumnIds().length>0,
"columnId",searchQuoteVO.getColumnIds()); "columnId",sqv.getColumnIds());
and.in(searchQuoteVO.getValues()!=null && searchQuoteVO.getValues().length>0, and.in(sqv.getValues()!=null && sqv.getValues().length>0,
"value", searchQuoteVO.getValues()); "value", sqv.getValues());
} }
return quoteDao.findAll(and.build()); return quoteDao.findAll(and.build());
} }
......
package com.tykj.datawarehouse.model.service.impl;
import com.tykj.datawarehouse.model.dao.RuleDao;
import com.tykj.datawarehouse.model.entity.Rule;
import com.tykj.datawarehouse.model.entity.vo.RuleVo;
import com.tykj.datawarehouse.model.service.RuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* @Description TODO
* @Author WWW
* @Date 2021/6/29 11:05
*/
@Service
public class RuleServiceImpl implements RuleService {
@Autowired
RuleDao ruleDao;
/**
* @param ruleVo
*/
@Override
public void add(RuleVo ruleVo) {
Rule rule = new Rule(
ruleVo.getTableId(),
ruleVo.getColumnId(),
ruleVo.getRegular()
);
ruleDao.save(rule);
}
/**
* 修改
*
* @param ruleVo
*/
@Override
public void update(RuleVo ruleVo) {
Rule rule = new Rule();
rule.setId(ruleVo.getId());
rule.setColumnId(ruleVo.getColumnId());
rule.setRegular(ruleVo.getRegular());
rule.setTableId(ruleVo.getTableId());
rule.setUpdatedTime(new Date());
ruleDao.save(rule);
}
/**
* 删除
*
* @param id
*/
@Override
public void del(Integer id) {
ruleDao.deleteById(id);
}
/**
* 查询
*
* @return
*/
@Override
public List<Rule> getAll() {
return ruleDao.findAll();
}
}
package com.tykj.datawarehouse.model.utils;
import com.tykj.datawarehouse.base.result.ApiException;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
import java.util.regex.Pattern;
import static java.util.Objects.isNull;
/**
* @Description TODO
* @Author WWW
* @Date 2021/6/29 11:19
*/
public class CheckUtils {
/**
* 正则校验
*
* @param regx
* @param val
* @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)) {
return true;
} else {
Pattern pattern = Pattern.compile(regx);
return pattern.matcher(val).matches();
}
}
throw new ApiException("校验不通过!");
}
public static Boolean validationQuote(List<String> quotes, String val) {
//如果没有引用就通过
if (quotes.size() == 0) {
return true;
}
//如果引用存在则通过
if (quotes.contains(val)) {
return true;
}
throw new ApiException("引用不通过!");
}
}
...@@ -7,7 +7,6 @@ import com.tykj.datawarehouse.model.entity.vo.TableVO; ...@@ -7,7 +7,6 @@ import com.tykj.datawarehouse.model.entity.vo.TableVO;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
/** /**
...@@ -56,10 +55,12 @@ public class CreateTableUtil { ...@@ -56,10 +55,12 @@ public class CreateTableUtil {
" \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n" + " \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n" +
" \"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd\">\n" + " \"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd\">\n" +
"<hibernate-mapping>\n" + "<hibernate-mapping>\n" +
" <class entity-name=\"" + tableVO.getModelName() + "\" table=\"" + tableVO.getModelName() + "\">\n"; " <class entity-name=\"" + tableVO.getModelName().toUpperCase() + "\" table=\"" + tableVO.getModelName().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.base.entity.XMQGenerator\" />" + " <generator class=\"com.tykj.datawarehouse.base.entity.XMQGenerator\" >" +
"<param name=\"sequence\">SEQUENCE_"+tableVO.getModelName().toUpperCase()+"</param>"+
"</generator>" +
" </id>"; " </id>";
...@@ -82,10 +83,10 @@ public class CreateTableUtil { ...@@ -82,10 +83,10 @@ public class CreateTableUtil {
// "<column name=\"UPDATE_TIME\" not-null=\"true\" default=\"CURRENT_TIMESTAMP\" />\n"+ // "<column name=\"UPDATE_TIME\" not-null=\"true\" default=\"CURRENT_TIMESTAMP\" />\n"+
// "</property> " ; // "</property> " ;
; ;
xmlMapping += " <property name = \"CREATE_TIME\" type =\"calendar\" generated=\"always\" > \n" + xmlMapping += " <property name = \"CREATE_TIME\" type =\"java.util.Date\" generated=\"always\" > \n" +
" <column name = \"CREATE_TIME\" default = \"CURRENT_TIMESTAMP\" /> \n" + " <column name = \"CREATE_TIME\" default = \"CURRENT_TIMESTAMP\" /> \n" +
" </property> \n" + " </property> \n" +
" <property name = \"UPDATE_TIME\" type =\"calendar\" > \n" + " <property name = \"UPDATE_TIME\" type =\"java.util.Date\" > \n" +
" <column name = \"UPDATE_TIME\" default = \"CURRENT_TIMESTAMP\" /> \n" + " <column name = \"UPDATE_TIME\" default = \"CURRENT_TIMESTAMP\" /> \n" +
" </property> "; " </property> ";
xmlMapping += " </class>\n" + xmlMapping += " </class>\n" +
......
...@@ -3,11 +3,28 @@ package com.tykj.datawarehouse; ...@@ -3,11 +3,28 @@ package com.tykj.datawarehouse;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
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 {
@Test @Test
void contextLoads() { void contextLoads() {
// String user="user_2$21name2";
// System.out.println(user.toUpperCase());
// String regx= "^((ht|f)tps?)://\\w+(.\\w+)*([\\w-.@?^=%&:/~+#]*[\\w-.@?^=%&:/~+#])?$";
// Pattern pattern = Pattern.compile(regx);//规则
// String str = "http://127.0.0.1:8888/";//待验字符
// boolean matches = pattern.matcher(str).matches();
//
// System.out.println(matches);
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论