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

[模型模块]新增根据processKey查询接口

上级 b67a2fe1
package com.tykj.workflowcore.model.controller; package com.tykj.workflowcore.model.controller;
import com.tykj.workflowcore.base.result.ResultObj; import com.google.common.collect.ImmutableMap;
import com.tykj.workflowcore.base.result.ResultUtil;
import com.tykj.workflowcore.model.entity.TableInfo; import com.tykj.workflowcore.model.entity.TableInfo;
import com.tykj.workflowcore.model.service.TableInfoService; import com.tykj.workflowcore.model.service.TableInfoService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -23,23 +22,23 @@ public class TableInfoController { ...@@ -23,23 +22,23 @@ public class TableInfoController {
@ApiOperation(value = "新增基础模型") @ApiOperation(value = "新增基础模型")
@PostMapping @PostMapping
public ResponseEntity save(@RequestBody TableInfo tableInfo){ public ResponseEntity save(@RequestBody TableInfo tableInfo) {
tableInfoService.save(tableInfo); tableInfoService.save(tableInfo);
return ResponseEntity.ok("新增成功"); return ResponseEntity.ok(ImmutableMap.of("message", "新增成功"));
} }
@ApiOperation(value = "修改基础模型") @ApiOperation(value = "修改基础模型")
@PutMapping @PutMapping
public ResponseEntity update(@RequestBody TableInfo tableInfo){ public ResponseEntity update(@RequestBody TableInfo tableInfo) {
tableInfoService.update(tableInfo); tableInfoService.update(tableInfo);
return ResponseEntity.ok("修改成功"); return ResponseEntity.ok(ImmutableMap.of("message", "修改成功"));
} }
@ApiOperation(value = "查询所有基础模型") @ApiOperation(value = "查询所有基础模型")
@GetMapping @GetMapping
public ResponseEntity<List<TableInfo>> findAll(){ public ResponseEntity findAll() {
List<TableInfo> tableInfos = tableInfoService.findAll(); List<TableInfo> tableInfos = tableInfoService.findAll();
return ResponseEntity.ok(tableInfos); return ResponseEntity.ok(ImmutableMap.of("data", tableInfos));
} }
} }
package com.tykj.workflowcore.model.controller; package com.tykj.workflowcore.model.controller;
import com.google.common.collect.ImmutableMap;
import com.tykj.workflowcore.model.entity.TableInfoEx; import com.tykj.workflowcore.model.entity.TableInfoEx;
import com.tykj.workflowcore.model.service.TableInfoExService; import com.tykj.workflowcore.model.service.TableInfoExService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -9,10 +10,11 @@ import org.springframework.http.ResponseEntity; ...@@ -9,10 +10,11 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
import java.util.Map;
@Api(tags = "聚合模型接口") @Api(tags = "聚合模型接口")
@CrossOrigin @CrossOrigin
@RequestMapping("/tableinfoex") @RequestMapping("/tableinfo/ex")
@RestController @RestController
public class TableInfoExController { public class TableInfoExController {
...@@ -21,23 +23,37 @@ public class TableInfoExController { ...@@ -21,23 +23,37 @@ public class TableInfoExController {
@ApiOperation(value = "新增聚合模型") @ApiOperation(value = "新增聚合模型")
@PostMapping @PostMapping
public ResponseEntity save(@RequestBody TableInfoEx tableInfoEx){ public ResponseEntity save(@RequestBody TableInfoEx tableInfoEx) {
tableInfoExService.save(tableInfoEx); tableInfoExService.save(tableInfoEx);
return ResponseEntity.ok("新增成功"); return ResponseEntity.ok(ImmutableMap.of("message","新增成功"));
} }
@ApiOperation(value = "修改聚合模型") @ApiOperation(value = "修改聚合模型")
@PutMapping @PutMapping
public ResponseEntity update(@RequestBody TableInfoEx tableInfoEx){ public ResponseEntity update(@RequestBody TableInfoEx tableInfoEx) {
tableInfoExService.update(tableInfoEx); tableInfoExService.update(tableInfoEx);
return ResponseEntity.ok("修改成功"); return ResponseEntity.ok(ImmutableMap.of("message","修改成功"));
} }
@ApiOperation(value = "查询所有聚合模型") @ApiOperation(value = "查询所有聚合模型")
@GetMapping @GetMapping
public ResponseEntity<List<TableInfoEx>> findAll(){ public ResponseEntity findAll() {
List<TableInfoEx> tableInfos = tableInfoExService.findAll(); List<TableInfoEx> tableInfoExes = tableInfoExService.findAll();
return ResponseEntity.ok(tableInfos); return ResponseEntity.ok(ImmutableMap.of("data",tableInfoExes));
}
@ApiOperation(value = "根据process查询")
@GetMapping("/processKey/{processKey}")
public ResponseEntity findByProcessKey(@PathVariable String processKey) {
List<TableInfoEx> tableInfoExes = tableInfoExService.findByProcessKey(processKey);
return ResponseEntity.ok(ImmutableMap.of("data",tableInfoExes));
}
@ApiOperation(value = "根据process查询 以Json形式返回")
@GetMapping("/processKey/json/{processKey}")
public ResponseEntity findByProcessKeyInMap(@PathVariable String processKey) {
List<Map<String, Map<String, Object>>> tableInfoExes = tableInfoExService.findByProcessKeyInMap(processKey);
return ResponseEntity.ok(ImmutableMap.of("data",tableInfoExes));
} }
} }
...@@ -51,4 +51,5 @@ public class TableInfoEx { ...@@ -51,4 +51,5 @@ public class TableInfoEx {
@ApiModelProperty(value = "绑定信息", position = 5) @ApiModelProperty(value = "绑定信息", position = 5)
@Transient @Transient
private List<Bind> binds; private List<Bind> binds;
} }
...@@ -13,4 +13,6 @@ public interface TableInfoExRepository extends JpaRepository<TableInfoEx, Intege ...@@ -13,4 +13,6 @@ public interface TableInfoExRepository extends JpaRepository<TableInfoEx, Intege
List<TableInfoEx> findByName(String name); List<TableInfoEx> findByName(String name);
List<TableInfoEx> findByProcessKey(String processKey);
} }
...@@ -10,6 +10,8 @@ public interface TableInfoRepository extends JpaRepository<TableInfo, Integer> { ...@@ -10,6 +10,8 @@ public interface TableInfoRepository extends JpaRepository<TableInfo, Integer> {
Integer countByName(String name); Integer countByName(String name);
TableInfo findByNameAndVersion(String name, Integer version);
void deleteAllByName(String name); void deleteAllByName(String name);
void deleteAllByNameAndVersion(String name, Integer version); void deleteAllByNameAndVersion(String name, Integer version);
......
package com.tykj.workflowcore.model.service; package com.tykj.workflowcore.model.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import com.tykj.workflowcore.model.entity.Bind; import com.tykj.workflowcore.model.entity.Bind;
import com.tykj.workflowcore.model.entity.ColumnInfo;
import com.tykj.workflowcore.model.entity.TableInfo; import com.tykj.workflowcore.model.entity.TableInfo;
import com.tykj.workflowcore.model.entity.TableInfoEx; import com.tykj.workflowcore.model.entity.TableInfoEx;
import com.tykj.workflowcore.model.repository.BindRepository; import com.tykj.workflowcore.model.repository.BindRepository;
import com.tykj.workflowcore.model.repository.TableInfoExRepository; import com.tykj.workflowcore.model.repository.TableInfoExRepository;
import com.tykj.workflowcore.model.repository.TableInfoRepository; import com.tykj.workflowcore.model.repository.TableInfoRepository;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -24,6 +29,8 @@ public class TableInfoExService { ...@@ -24,6 +29,8 @@ public class TableInfoExService {
TableInfoRepository tableInfoRepository; TableInfoRepository tableInfoRepository;
@Autowired @Autowired
BindRepository bindRepository; BindRepository bindRepository;
@Autowired
TableInfoService tableInfoService;
public void save(TableInfoEx tableInfoEx) { public void save(TableInfoEx tableInfoEx) {
//数据检查 //数据检查
...@@ -76,6 +83,30 @@ public class TableInfoExService { ...@@ -76,6 +83,30 @@ public class TableInfoExService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public List<TableInfoEx> findByProcessKey(String processKey) {
return tableInfoExRepository.findByProcessKey(processKey).stream()
.map(this::getBinds)
.collect(Collectors.toList());
}
public List<Map<String, Map<String, Object>>> findByProcessKeyInMap(String processKey) {
return tableInfoExRepository.findByProcessKey(processKey).stream()
.map(TableInfoEx::getName)
.distinct()
.map(name -> ImmutableMap.of(name, findByNameInMap(name)))
.collect(Collectors.toList());
}
public String findByNameInJson(String name) {
Map<String, Object> result = findByNameInMap(name);
try {
return new ObjectMapper().writeValueAsString(result);
} catch (JsonProcessingException e) {
e.printStackTrace();
return "{}";
}
}
public void updateRelatedTableInfoEx(TableInfo tableInfo) { public void updateRelatedTableInfoEx(TableInfo tableInfo) {
List<String> names = bindRepository.findByName(tableInfo.getName()).stream() List<String> names = bindRepository.findByName(tableInfo.getName()).stream()
.map(Bind::getTableInfoExId) .map(Bind::getTableInfoExId)
...@@ -104,6 +135,19 @@ public class TableInfoExService { ...@@ -104,6 +135,19 @@ public class TableInfoExService {
//-----------------------------------------------------------------------------// //-----------------------------------------------------------------------------//
private Map<String, Object> findByNameInMap(String name) {
TableInfoEx tableInfoEx = tableInfoExRepository.findByName(name).stream()
.max(Comparator.comparingInt(TableInfoEx::getVersion))
.map(this::getBinds)
.orElseThrow(() -> new RuntimeException("查询数据失败"));
Map<String, Object> result = new HashMap<>();
for (Bind bind : tableInfoEx.getBinds()) {
Map<String, Object> map = bindToMap(bind);
result.put(bind.getName(), map);
}
return result;
}
private List<Bind> newBinds(List<Bind> binds, TableInfo tableInfo) { private List<Bind> newBinds(List<Bind> binds, TableInfo tableInfo) {
List<Bind> newBinds = new ArrayList<>(); List<Bind> newBinds = new ArrayList<>();
for (Bind bind : binds) { for (Bind bind : binds) {
...@@ -156,4 +200,23 @@ public class TableInfoExService { ...@@ -156,4 +200,23 @@ public class TableInfoExService {
return bind; return bind;
} }
private Map<String, Object> bindToMap(Bind bind) {
Map<String, Object> result = new HashMap<>();
TableInfo tableInfo = tableInfoService.findByNameAndVersion(bind.getName(), bind.getVersion());
if (nonNull(tableInfo)) {
List<ColumnInfo> columnInfos = tableInfo.getColumnInfos();
for (ColumnInfo columnInfo : columnInfos) {
result.put(columnInfo.getName(), Strings.EMPTY);
}
if (hasChildren(bind)) {
for (Bind child : bind.getChildren()) {
Map<String, Object> childMap = bindToMap(child);
result.put(child.getName(), childMap);
}
}
}
return result;
}
} }
...@@ -12,6 +12,7 @@ import java.util.Date; ...@@ -12,6 +12,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull; import static java.util.Objects.nonNull;
@SuppressWarnings("Duplicates") @SuppressWarnings("Duplicates")
...@@ -73,9 +74,12 @@ public class TableInfoService { ...@@ -73,9 +74,12 @@ public class TableInfoService {
tableInfoExService.updateRelatedTableInfoEx(tableInfo); tableInfoExService.updateRelatedTableInfoEx(tableInfo);
} }
public TableInfo findById(Integer id) { public TableInfo findByNameAndVersion(String name, Integer version) {
TableInfo tableInfo = tableInfoRepository.findById(id).orElseThrow(() -> new RuntimeException("该模型不存在")); TableInfo tableInfo = tableInfoRepository.findByNameAndVersion(name, version);
List<ColumnInfo> columnInfos = columnInfoRepository.findByTableInfoId(id); if (isNull(tableInfo)) {
throw new RuntimeException("该模型不存在");
}
List<ColumnInfo> columnInfos = columnInfoRepository.findByTableInfoId(tableInfo.getId());
tableInfo.setColumnInfos(columnInfos); tableInfo.setColumnInfos(columnInfos);
return tableInfo; return tableInfo;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论