TableGroupServiceImpl.java 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package org.dbsyncer.biz.impl;
  2. import org.dbsyncer.biz.TableGroupService;
  3. import org.dbsyncer.common.util.JsonUtil;
  4. import org.dbsyncer.connector.config.Field;
  5. import org.dbsyncer.connector.config.MetaInfo;
  6. import org.dbsyncer.connector.config.Table;
  7. import org.dbsyncer.manager.Manager;
  8. import org.dbsyncer.parser.model.FieldMapping;
  9. import org.dbsyncer.parser.model.Mapping;
  10. import org.dbsyncer.parser.model.TableGroup;
  11. import org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.util.Assert;
  16. import java.util.Arrays;
  17. import java.util.List;
  18. import java.util.Map;
  19. /**
  20. * @author AE86
  21. * @version 1.0.0
  22. * @date 2019/11/27 23:14
  23. */
  24. @Service
  25. public class TableGroupServiceImpl implements TableGroupService {
  26. private final Logger logger = LoggerFactory.getLogger(getClass());
  27. @Autowired
  28. private Manager manager;
  29. @Override
  30. public String add(Map<String, String> params) {
  31. String mappingId = params.get("mappingId");
  32. String sourceTable = params.get("sourceTable");
  33. String targetTable = params.get("targetTable");
  34. Assert.hasText(mappingId, "tableGroup mappingId is empty.");
  35. Assert.hasText(sourceTable, "tableGroup sourceTable is empty.");
  36. Assert.hasText(targetTable, "tableGroup targetTable is empty.");
  37. Mapping mapping = manager.getMapping(mappingId);
  38. Assert.notNull(mapping, "mapping can not be null.");
  39. TableGroup tableGroup = new TableGroup();
  40. tableGroup.setMappingId(mappingId);
  41. // 获取表字段
  42. tableGroup.setSourceTable(getTable(mapping.getSourceConnectorId(), sourceTable));
  43. tableGroup.setTargetTable(getTable(mapping.getTargetConnectorId(), targetTable));
  44. String json = JsonUtil.objToJson(tableGroup);
  45. return manager.addTableGroup(json);
  46. }
  47. @Override
  48. public String edit(Map<String, String> params) {
  49. return manager.editTableGroup(null);
  50. }
  51. @Override
  52. public boolean remove(String id) {
  53. manager.removeTableGroup(id);
  54. return true;
  55. }
  56. @Override
  57. public TableGroup getTableGroup(String id) {
  58. TableGroup tableGroup = manager.getTableGroup(id);
  59. Assert.notNull(tableGroup, "TableGroup can not be null");
  60. // TODO 模拟数据
  61. FieldMapping m = new FieldMapping();
  62. m.setSource(new Field("ID1", "VARCHAR", 12));
  63. m.setTarget(new Field("ID2", "VARCHAR", 12));
  64. tableGroup.setFieldMapping(Arrays.asList(m));
  65. return tableGroup;
  66. }
  67. @Override
  68. public List<TableGroup> getTableGroupAll(String mappingId) {
  69. return manager.getTableGroupAll(mappingId);
  70. }
  71. private Table getTable(String connectorId, String tableName) {
  72. MetaInfo metaInfo = manager.getMetaInfo(connectorId, tableName);
  73. Assert.notNull(metaInfo, "metaInfo can not be null.");
  74. return new Table().setName(tableName).setColumn(metaInfo.getColumn());
  75. }
  76. }