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

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

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