提交 9ba8f039 authored 作者: 黄承天's avatar 黄承天

[模型模块]新增接口以及字段

上级 31d907d8
......@@ -41,4 +41,11 @@ public class TableInfoController {
return ResponseEntity.ok(ImmutableMap.of("data", tableInfos));
}
@ApiOperation(value = "根据名称删除基础模型")
@DeleteMapping("/{name}")
public ResponseEntity deleteByName(@PathVariable String name) {
tableInfoService.deleteByName(name);
return ResponseEntity.ok(ImmutableMap.of("message", "删除成功"));
}
}
......@@ -56,4 +56,11 @@ public class TableInfoExController {
return ResponseEntity.ok(ImmutableMap.of("data",tableInfoExes));
}
@ApiOperation(value = "根据名称删除聚合模型")
@DeleteMapping("/{name}")
public ResponseEntity deleteByName(@PathVariable String name) {
tableInfoExService.deleteByName(name);
return ResponseEntity.ok(ImmutableMap.of("message", "删除成功"));
}
}
......@@ -18,7 +18,6 @@ import java.util.List;
public class Bind {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@JsonIgnore
private Integer id;
......@@ -28,7 +27,13 @@ public class Bind {
@ApiModelProperty(value = "绑定的基础对象的版本号", readOnly = true, position = 2)
private Integer version;
@ApiModelProperty(value = "是否为复数 true/false", position = 3)
@ApiModelProperty(value = "绑定的基础对象的别名", position = 3)
private String alias;
@ApiModelProperty(value = "绑定的基础对象的描述", position = 4)
private String description;
@ApiModelProperty(value = "是否为复数 true/false", position = 5)
private Boolean isComplex;
@JsonIgnore
......
package com.tykj.workflowcore.model.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
......@@ -9,6 +8,7 @@ import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import javax.persistence.*;
import java.util.List;
@Accessors(chain = true)
@Data
......@@ -18,29 +18,35 @@ import javax.persistence.*;
public class ColumnInfo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty("主键")
@JsonIgnore
private Integer id;
//-----------------------------//
@ApiModelProperty(value = "是否是主键 true/false",position = 1)
@ApiModelProperty(value = "是否是主键 true/false", position = 1)
private Boolean isPrimary;
@ApiModelProperty(value = "列名",position = 1)
@ApiModelProperty(value = "列名", position = 2)
private String name;
@ApiModelProperty(value = "列类型",position = 1)
@ApiModelProperty(value = "列类型", position = 3)
private String type;
@ApiModelProperty(value = "长度",position = 1)
@ApiModelProperty(value = "长度", position = 4)
private Integer length;
@ApiModelProperty(value = "所属表id",position = 1)
private Integer tableInfoId;
@ApiModelProperty(value = "匹配表达式", position = 5)
private String pattern;
@ApiModelProperty(value = "描述",position = 1)
@ApiModelProperty(value = "描述", position = 6)
private String description;
@ApiModelProperty(value = "引用", position = 7)
@Transient
private List<Quote> quotes;
@JsonIgnore
private Integer tableInfoId;
}
package com.tykj.workflowcore.model.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import javax.persistence.Id;
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
public class Quote {
@Id
@ApiModelProperty("主键")
@JsonIgnore
private Integer id;
@ApiModelProperty(value = "值")
private String value;
@JsonIgnore
private Integer columnInfoId;
}
......@@ -20,38 +20,39 @@ import java.util.List;
public class TableInfo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("创建时间")
@ApiModelProperty(value = "创建时间", position = 1)
@Temporal(TemporalType.TIMESTAMP)
@JsonFormat(pattern = "yyyy-MM-dd hh:mm")
@JsonIgnore
private Date createdTime;
@ApiModelProperty("修改时间")
@ApiModelProperty(value = "修改时间", position = 2)
@Temporal(TemporalType.TIMESTAMP)
@JsonFormat(pattern = "yyyy-MM-dd hh:mm")
@JsonIgnore
private Date updatedTime;
//------------------------------//
@ApiModelProperty(value = "基础对象名", position = 1)
@ApiModelProperty(value = "基础对象名", position = 3)
private String name;
@ApiModelProperty(value = "描述", position = 2)
@ApiModelProperty(value = "别名", position = 4)
private String alias;
@ApiModelProperty(value = "描述", position = 5)
private String description;
@ApiModelProperty(value = "工作流预留字段", position = 3)
@ApiModelProperty(value = "工作流预留字段", position = 6)
private String processKey;
@ApiModelProperty(value = "版本号", readOnly = true, position = 4)
@ApiModelProperty(value = "版本号", readOnly = true, position = 7)
private Integer version;
@Transient
@ApiModelProperty(value = "字段信息", position = 5)
@ApiModelProperty(value = "字段信息", position = 8)
private List<ColumnInfo> columnInfos;
}
......
package com.tykj.workflowcore.model.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
......@@ -20,35 +19,35 @@ import java.util.List;
public class TableInfoEx {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("创建时间")
@ApiModelProperty(value = "创建时间", position = 1)
@Temporal(TemporalType.TIMESTAMP)
@JsonFormat(pattern = "yyyy-MM-dd hh:mm")
@JsonIgnore
private Date createdTime;
@ApiModelProperty("修改时间")
@ApiModelProperty(value = "修改时间",position = 2)
@Temporal(TemporalType.TIMESTAMP)
@JsonFormat(pattern = "yyyy-MM-dd hh:mm")
@JsonIgnore
private Date updatedTime;
@ApiModelProperty(value = "聚合对象名", position = 1)
@ApiModelProperty(value = "聚合对象名", position = 3)
private String name;
@ApiModelProperty(value = "描述", position = 2)
@ApiModelProperty(value = "别名", position = 4)
private String alias;
@ApiModelProperty(value = "描述", position = 5)
private String description;
@ApiModelProperty(value = "工作流用预留字段", position = 3)
@ApiModelProperty(value = "工作流用预留字段", position = 6)
private String processKey;
@ApiModelProperty(value = "版本号", readOnly = true, position = 4)
@ApiModelProperty(value = "版本号", readOnly = true, position = 7)
private Integer version;
@ApiModelProperty(value = "绑定信息", position = 5)
@ApiModelProperty(value = "绑定信息", position = 8)
@Transient
private List<Bind> binds;
......
......@@ -13,4 +13,5 @@ public interface BindRepository extends JpaRepository<Bind, Integer> {
List<Bind> findByName(String name);
void deleteByTableInfoExId(Integer tableInfoExId);
}
......@@ -9,4 +9,6 @@ public interface ColumnInfoRepository extends JpaRepository<ColumnInfo, Integer>
List<ColumnInfo> findByTableInfoId(Integer tableInfoId);
void deleteAllByTableInfoId(Integer tableInfoId);
}
package com.tykj.workflowcore.model.repository;
import com.tykj.workflowcore.model.entity.Quote;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface QuoteRepository extends JpaRepository<Quote, Integer> {
List<Quote> findByColumnInfoId(Integer columnInfoId);
void deleteAllByColumnInfoId(Integer columnInfoId);
}
package com.tykj.workflowcore.model.repository;
import com.tykj.workflowcore.model.entity.TableInfo;
import com.tykj.workflowcore.model.entity.TableInfoEx;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface TableInfoRepository extends JpaRepository<TableInfo, Integer> {
......@@ -12,6 +15,8 @@ public interface TableInfoRepository extends JpaRepository<TableInfo, Integer> {
TableInfo findByNameAndVersion(String name, Integer version);
List<TableInfo> findByName(String name);
void deleteAllByName(String name);
void deleteAllByNameAndVersion(String name, Integer version);
......
......@@ -76,13 +76,24 @@ public class TableInfoExService {
}
}
public List<TableInfoEx> findAll() {
return tableInfoExRepository.findAll().stream()
.map(TableInfoEx::getName)
.distinct()
.map(this::findLastVersion)
.map(this::getBinds)
.collect(Collectors.toList());
}
public void deleteByName(String name) {
List<TableInfoEx> tableInfoExes = tableInfoExRepository.findByName(name);
for (TableInfoEx tableInfoEx : tableInfoExes) {
Integer tableInfoExId = tableInfoEx.getId();
bindRepository.deleteByTableInfoExId(tableInfoExId);
tableInfoExRepository.deleteById(tableInfoExId);
}
}
public List<TableInfoEx> findByProcessKey(String processKey) {
return tableInfoExRepository.findByProcessKey(processKey).stream()
.map(this::getBinds)
......@@ -218,5 +229,9 @@ public class TableInfoExService {
return result;
}
private TableInfoEx findLastVersion(String name) {
return tableInfoExRepository.findByName(name).stream()
.max(Comparator.comparingInt(TableInfoEx::getVersion))
.orElseThrow(() -> new RuntimeException("查询失败"));
}
}
package com.tykj.workflowcore.model.service;
import com.tykj.workflowcore.model.entity.ColumnInfo;
import com.tykj.workflowcore.model.entity.Quote;
import com.tykj.workflowcore.model.entity.TableInfo;
import com.tykj.workflowcore.model.repository.ColumnInfoRepository;
import com.tykj.workflowcore.model.repository.QuoteRepository;
import com.tykj.workflowcore.model.repository.TableInfoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
......@@ -25,6 +28,8 @@ public class TableInfoService {
private TableInfoRepository tableInfoRepository;
@Autowired
private ColumnInfoRepository columnInfoRepository;
@Autowired
private QuoteRepository quoteRepository;
public void save(TableInfo tableInfo) {
//数据检查
......@@ -42,11 +47,10 @@ public class TableInfoService {
//设置版本号
tableInfo.setVersion(1);
//保存数据
Integer id = tableInfoRepository.save(tableInfo).getId();
List<ColumnInfo> columnInfosForSave = tableInfo.getColumnInfos().stream()
.map(columnInfo -> columnInfo.setTableInfoId(id))
.collect(Collectors.toList());
columnInfosForSave.forEach(columnInfoRepository::save);
Integer tableInfoId = tableInfoRepository.save(tableInfo).getId();
if (nonNull(tableInfo.getColumnInfos())) {
tableInfo.getColumnInfos().forEach(columnInfo -> saveColumnInfo(columnInfo, tableInfoId));
}
}
public void update(TableInfo tableInfo) {
......@@ -65,11 +69,10 @@ public class TableInfoService {
tableInfo.setUpdatedTime(date);
tableInfo.setVersion(count + 1);
//保存数据
Integer id = tableInfoRepository.save(tableInfo).getId();
List<ColumnInfo> columnInfosForSave = tableInfo.getColumnInfos().stream()
.map(columnInfo -> columnInfo.setTableInfoId(id))
.collect(Collectors.toList());
columnInfosForSave.forEach(columnInfoRepository::save);
Integer tableInfoId = tableInfoRepository.save(tableInfo).getId();
if (nonNull(tableInfo.getColumnInfos())) {
tableInfo.getColumnInfos().forEach(columnInfo -> saveColumnInfo(columnInfo, tableInfoId));
}
//更新有关联的聚合对象
tableInfoExService.updateRelatedTableInfoEx(tableInfo);
}
......@@ -86,16 +89,60 @@ public class TableInfoService {
public List<TableInfo> findAll() {
return tableInfoRepository.findAll().stream()
.map(TableInfo::getName)
.distinct()
.map(this::findLastVersion)
.map(this::getColumnInfos)
.collect(Collectors.toList());
}
public void deleteByName(String name) {
List<TableInfo> tableInfos = tableInfoRepository.findByName(name);
for (TableInfo tableInfo : tableInfos) {
Integer tableInfoId = tableInfo.getId();
List<ColumnInfo> columnInfos = columnInfoRepository.findByTableInfoId(tableInfoId);
for (ColumnInfo columnInfo : columnInfos) {
Integer columnInfoId = columnInfo.getId();
quoteRepository.deleteAllByColumnInfoId(columnInfoId);
columnInfoRepository.deleteById(columnInfoId);
}
tableInfoRepository.deleteById(tableInfoId);
}
}
//-----------------------------------------------------------------------------//
private void saveColumnInfo(ColumnInfo columnInfo, Integer tableInfoId) {
columnInfo.setTableInfoId(tableInfoId);
Integer columnInfoId = columnInfoRepository.save(columnInfo).getId();
if (nonNull(columnInfo.getQuotes())) {
columnInfo.getQuotes().forEach(quote -> saveQuote(quote, columnInfoId));
}
}
private void saveQuote(Quote quote, Integer columnInfoId) {
quote.setColumnInfoId(columnInfoId);
quoteRepository.save(quote);
}
private TableInfo getColumnInfos(TableInfo tableInfo) {
List<ColumnInfo> columnInfos = columnInfoRepository.findByTableInfoId(tableInfo.getId());
List<ColumnInfo> columnInfos = columnInfoRepository.findByTableInfoId(tableInfo.getId()).stream()
.map(this::getQuotes)
.collect(Collectors.toList());
tableInfo.setColumnInfos(columnInfos);
return tableInfo;
}
private TableInfo findLastVersion(String name) {
return tableInfoRepository.findByName(name).stream()
.max(Comparator.comparingInt(TableInfo::getVersion))
.orElseThrow(() -> new RuntimeException("查询失败"));
}
private ColumnInfo getQuotes(ColumnInfo columnInfo) {
List<Quote> quotes = quoteRepository.findByColumnInfoId(columnInfo.getId());
columnInfo.setQuotes(quotes);
return columnInfo;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论