|
@@ -1,11 +1,16 @@
|
|
|
package com.citygis.web.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.lang.Snowflake;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.citygis.common.annotation.DataSource;
|
|
|
import com.citygis.common.core.domain.AjaxResult;
|
|
|
+import com.citygis.common.enums.DataSourceType;
|
|
|
+import com.citygis.framework.datasource.DynamicDataSourceContextHolder;
|
|
|
import com.citygis.web.domain.*;
|
|
|
import com.citygis.web.mapper.TabDatasourceMsgMapper;
|
|
|
import com.citygis.web.service.*;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -39,132 +44,265 @@ public class TabDatasourceMsgServiceImpl extends ServiceImpl<TabDatasourceMsgMap
|
|
|
@Resource
|
|
|
ITabUrlService tabUrlService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ ITabSystemMsgService tabSystemMsgService;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public AjaxResult insertDataSun(DataSun dataSun) {
|
|
|
+ Snowflake snowflake = IdUtil.getSnowflake(1, 1);
|
|
|
|
|
|
- List<TabEtl> etl = dataSun.getEtl();
|
|
|
- if (etl != null) {
|
|
|
- etl.forEach(tabEtl -> {
|
|
|
- tabEtl.setAccessFeedbackId(dataSun.getAccessFeedbackId());
|
|
|
- tabEtlService.save(tabEtl);
|
|
|
- });
|
|
|
- }
|
|
|
+
|
|
|
+ saveAndCreateTabSystemMsg(dataSun.getEtl(), "ETL", dataSun.getAccessFeedbackId(), snowflake);
|
|
|
+ saveAndCreateTabSystemMsg(dataSun.getKafka(), "KAFKA", dataSun.getAccessFeedbackId(), snowflake);
|
|
|
+ saveAndCreateTabSystemMsg(dataSun.getKb(), "KB", dataSun.getAccessFeedbackId(), snowflake);
|
|
|
+ saveAndCreateTabSystemMsg(dataSun.getSftp(), "SFTP", dataSun.getAccessFeedbackId(), snowflake);
|
|
|
+ saveAndCreateTabSystemMsg(dataSun.getUrl(), "URL", dataSun.getAccessFeedbackId(), snowflake);
|
|
|
|
|
|
- List<TabKafka> kafka = dataSun.getKafka();
|
|
|
- if (kafka != null) {
|
|
|
- kafka.forEach(tabKafka -> {
|
|
|
- tabKafka.setAccessFeedbackId(dataSun.getAccessFeedbackId());
|
|
|
- tabKafkaService.save(tabKafka);
|
|
|
- });
|
|
|
- }
|
|
|
+ return AjaxResult.success("添加成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private <T> void saveAndCreateTabSystemMsg(List<T> dataList, String accessManner, Long accessFeedbackId, Snowflake snowflake) {
|
|
|
+ if (dataList != null) {
|
|
|
+ dataList.forEach(data -> {
|
|
|
+
|
|
|
+ setAccessFeedbackId(data, accessFeedbackId);
|
|
|
+
|
|
|
+
|
|
|
+ if (data instanceof TabEtl) {
|
|
|
+ ((TabEtl) data).setId(snowflake.nextId());
|
|
|
+ tabEtlService.save((TabEtl) data);
|
|
|
+ } else if (data instanceof TabKafka) {
|
|
|
+ ((TabKafka) data).setId(snowflake.nextId());
|
|
|
+ tabKafkaService.save((TabKafka) data);
|
|
|
+ } else if (data instanceof TabKb) {
|
|
|
+ ((TabKb) data).setId(snowflake.nextId());
|
|
|
+ tabKbService.save((TabKb) data);
|
|
|
+ } else if (data instanceof TabSftp) {
|
|
|
+ ((TabSftp) data).setId(snowflake.nextId());
|
|
|
+ tabSftpService.save((TabSftp) data);
|
|
|
+ } else if (data instanceof TabUrl) {
|
|
|
+ ((TabUrl) data).setId(snowflake.nextId());
|
|
|
+ tabUrlService.save((TabUrl) data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- List<TabKb> kb = dataSun.getKb();
|
|
|
- if (kb != null) {
|
|
|
- kb.forEach(tabKb -> {
|
|
|
- tabKb.setAccessFeedbackId(dataSun.getAccessFeedbackId());
|
|
|
- tabKbService.save(tabKb);
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
- List<TabSftp> sftp = dataSun.getSftp();
|
|
|
- if (sftp != null) {
|
|
|
- sftp.forEach(tabSftp -> {
|
|
|
- tabSftp.setAccessFeedbackId(dataSun.getAccessFeedbackId());
|
|
|
- tabSftpService.save(tabSftp);
|
|
|
});
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- List<TabUrl> url = dataSun.getUrl();
|
|
|
- if (url != null) {
|
|
|
- url.forEach(tabUrl -> {
|
|
|
- tabUrl.setAccessFeedbackId(dataSun.getAccessFeedbackId());
|
|
|
- tabUrlService.save(tabUrl);
|
|
|
- });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @DataSource(DataSourceType.SLAVE)
|
|
|
+ private <T> void createTabSystemMsg(T data, String accessManner, Snowflake snowflake) {
|
|
|
+ TabSystemMsg tsm = new TabSystemMsg();
|
|
|
+ tsm.setId((int) snowflake.nextId());
|
|
|
+
|
|
|
+ if (data instanceof TabEtl) {
|
|
|
+ tsm.setTableEnglishName(((TabEtl) data).getTableEnglishName());
|
|
|
+ tsm.setTableName(((TabEtl) data).getTableName());
|
|
|
+ tsm.setSystemName(((TabEtl) data).getScenario());
|
|
|
+ tsm.setDataEssentialId(((TabEtl) data).getId());
|
|
|
+ } else if (data instanceof TabKafka) {
|
|
|
+ tsm.setTableEnglishName(((TabKafka) data).getTopicEnglishName());
|
|
|
+ tsm.setTableName(((TabKafka) data).getTopicName());
|
|
|
+ tsm.setSystemName(((TabKafka) data).getScenario());
|
|
|
+ tsm.setDataEssentialId(((TabKafka) data).getId());
|
|
|
+ } else if (data instanceof TabKb) {
|
|
|
+ tsm.setTableEnglishName(((TabKb) data).getTableEnglishName());
|
|
|
+ tsm.setTableName(((TabKb) data).getTableName());
|
|
|
+ tsm.setSystemName(((TabKb) data).getScenario());
|
|
|
+ tsm.setDataEssentialId(((TabKb) data).getId());
|
|
|
+ } else if (data instanceof TabSftp) {
|
|
|
+ tsm.setTableEnglishName(((TabSftp) data).getFileEnglishName());
|
|
|
+ tsm.setTableName(((TabSftp) data).getFileName());
|
|
|
+ tsm.setSystemName(((TabSftp) data).getScenario());
|
|
|
+ tsm.setDataEssentialId(((TabSftp) data).getId());
|
|
|
+ } else if (data instanceof TabUrl) {
|
|
|
+ tsm.setTableEnglishName(((TabUrl) data).getOfferUrl());
|
|
|
+ tsm.setTableName(((TabUrl) data).getUrlDetail());
|
|
|
+ tsm.setSystemName(((TabUrl) data).getScenario());
|
|
|
+ tsm.setDataEssentialId(((TabUrl) data).getId());
|
|
|
}
|
|
|
|
|
|
- return AjaxResult.success("添加成功");
|
|
|
+ tsm.setAccessManner(accessManner);
|
|
|
+ DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE.name());
|
|
|
+ boolean b = tabSystemMsgService.save(tsm);
|
|
|
+ DynamicDataSourceContextHolder.clearDataSourceType();;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public AjaxResult updateDataSun(DataSun dataSun) {
|
|
|
- List<TabEtl> etl = dataSun.getEtl();
|
|
|
- if (etl != null) {
|
|
|
- etl.forEach(tabEtl -> {
|
|
|
- tabEtl.setAccessFeedbackId(dataSun.getAccessFeedbackId());
|
|
|
- tabEtlService.saveOrUpdate(tabEtl);
|
|
|
- });
|
|
|
- }
|
|
|
+ updateTabSystemMsg(dataSun.getEtl(), "ETL", dataSun.getAccessFeedbackId());
|
|
|
+ updateTabSystemMsg(dataSun.getKafka(), "KAFKA", dataSun.getAccessFeedbackId());
|
|
|
+ updateTabSystemMsg(dataSun.getKb(), "KB", dataSun.getAccessFeedbackId());
|
|
|
+ updateTabSystemMsg(dataSun.getSftp(), "SFTP", dataSun.getAccessFeedbackId());
|
|
|
+ updateTabSystemMsg(dataSun.getUrl(), "URL", dataSun.getAccessFeedbackId());
|
|
|
|
|
|
- List<TabKafka> kafka = dataSun.getKafka();
|
|
|
- if (kafka != null) {
|
|
|
- kafka.forEach(tabKafka -> {
|
|
|
- tabKafka.setAccessFeedbackId(dataSun.getAccessFeedbackId());
|
|
|
- tabKafkaService.saveOrUpdate(tabKafka);
|
|
|
- });
|
|
|
- }
|
|
|
+ return AjaxResult.success("修改成功");
|
|
|
+ }
|
|
|
|
|
|
- List<TabKb> kb = dataSun.getKb();
|
|
|
- if (kb != null) {
|
|
|
- kb.forEach(tabKb -> {
|
|
|
- tabKb.setAccessFeedbackId(dataSun.getAccessFeedbackId());
|
|
|
- tabKbService.saveOrUpdate(tabKb);
|
|
|
+ private <T> void updateTabSystemMsg(List<T> dataList, String accessManner, Long accessFeedbackId) {
|
|
|
+ if (dataList != null) {
|
|
|
+ dataList.forEach(data -> {
|
|
|
+
|
|
|
+ setAccessFeedbackId(data, accessFeedbackId);
|
|
|
+
|
|
|
+
|
|
|
+ if (data instanceof TabEtl) {
|
|
|
+ tabEtlService.saveOrUpdate((TabEtl) data);
|
|
|
+ } else if (data instanceof TabKafka) {
|
|
|
+ tabKafkaService.saveOrUpdate((TabKafka) data);
|
|
|
+ } else if (data instanceof TabKb) {
|
|
|
+ tabKbService.saveOrUpdate((TabKb) data);
|
|
|
+ } else if (data instanceof TabSftp) {
|
|
|
+ tabSftpService.saveOrUpdate((TabSftp) data);
|
|
|
+ } else if (data instanceof TabUrl) {
|
|
|
+ tabUrlService.saveOrUpdate((TabUrl) data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
});
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- List<TabSftp> sftp = dataSun.getSftp();
|
|
|
- if (sftp != null) {
|
|
|
- sftp.forEach(tabSftp -> {
|
|
|
- tabSftp.setAccessFeedbackId(dataSun.getAccessFeedbackId());
|
|
|
- tabSftpService.saveOrUpdate(tabSftp);
|
|
|
- });
|
|
|
+ private <T> void setAccessFeedbackId(T data, Long accessFeedbackId) {
|
|
|
+ if (data instanceof TabEtl) {
|
|
|
+ ((TabEtl) data).setAccessFeedbackId(accessFeedbackId);
|
|
|
+ } else if (data instanceof TabKafka) {
|
|
|
+ ((TabKafka) data).setAccessFeedbackId(accessFeedbackId);
|
|
|
+ } else if (data instanceof TabKb) {
|
|
|
+ ((TabKb) data).setAccessFeedbackId(accessFeedbackId);
|
|
|
+ } else if (data instanceof TabSftp) {
|
|
|
+ ((TabSftp) data).setAccessFeedbackId(accessFeedbackId);
|
|
|
+ } else if (data instanceof TabUrl) {
|
|
|
+ ((TabUrl) data).setAccessFeedbackId(accessFeedbackId);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- List<TabUrl> url = dataSun.getUrl();
|
|
|
- if (url != null) {
|
|
|
- url.forEach(tabUrl -> {
|
|
|
- tabUrl.setAccessFeedbackId(dataSun.getAccessFeedbackId());
|
|
|
- tabUrlService.saveOrUpdate(tabUrl);
|
|
|
- });
|
|
|
+ private <T> TabSystemMsg createTabSystemMsg(T data, String accessManner) {
|
|
|
+ TabSystemMsg tsm = new TabSystemMsg();
|
|
|
+
|
|
|
+ if (data instanceof TabEtl) {
|
|
|
+ tsm.setTableEnglishName(((TabEtl) data).getTableEnglishName());
|
|
|
+ tsm.setTableName(((TabEtl) data).getTableName());
|
|
|
+ tsm.setSystemName(((TabEtl) data).getScenario());
|
|
|
+ } else if (data instanceof TabKafka) {
|
|
|
+ tsm.setTableEnglishName(((TabKafka) data).getTopicEnglishName());
|
|
|
+ tsm.setTableName(((TabKafka) data).getTopicName());
|
|
|
+ tsm.setSystemName(((TabKafka) data).getScenario());
|
|
|
+ } else if (data instanceof TabKb) {
|
|
|
+ tsm.setTableEnglishName(((TabKb) data).getTableEnglishName());
|
|
|
+ tsm.setTableName(((TabKb) data).getTableName());
|
|
|
+ tsm.setSystemName(((TabKb) data).getScenario());
|
|
|
+ } else if (data instanceof TabSftp) {
|
|
|
+ tsm.setTableEnglishName(((TabSftp) data).getFileEnglishName());
|
|
|
+ tsm.setTableName(((TabSftp) data).getFileName());
|
|
|
+ tsm.setSystemName(((TabSftp) data).getScenario());
|
|
|
+ } else if (data instanceof TabUrl) {
|
|
|
+ tsm.setTableEnglishName(((TabUrl) data).getOfferUrl());
|
|
|
+ tsm.setTableName(((TabUrl) data).getUrlDetail());
|
|
|
+ tsm.setSystemName(((TabUrl) data).getScenario());
|
|
|
}
|
|
|
|
|
|
- return AjaxResult.success("修改成功");
|
|
|
-
|
|
|
+ tsm.setAccessManner(accessManner);
|
|
|
+ return tsm;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public AjaxResult deleteDataSun(Long id) {
|
|
|
- TabEtl tabEtl = new TabEtl();
|
|
|
- tabEtl.setAccessFeedbackId(id);
|
|
|
- tabEtl.setIsDel(1);
|
|
|
- tabEtlService.updateById(tabEtl);
|
|
|
-
|
|
|
- TabKafka tabKafka = new TabKafka();
|
|
|
- tabKafka.setAccessFeedbackId(id);
|
|
|
- tabKafka.setIsDel(1);
|
|
|
- tabKafkaService.updateById(tabKafka);
|
|
|
-
|
|
|
- TabKb tabKb = new TabKb();
|
|
|
- tabKb.setAccessFeedbackId(id);
|
|
|
- tabKb.setIsDel(1);
|
|
|
- tabKbService.updateById(tabKb);
|
|
|
-
|
|
|
- TabSftp tabSftp = new TabSftp();
|
|
|
- tabSftp.setAccessFeedbackId(id);
|
|
|
- tabSftp.setIsDel(1);
|
|
|
- tabSftpService.updateById(tabSftp);
|
|
|
-
|
|
|
- TabUrl tabUrl = new TabUrl();
|
|
|
- tabUrl.setAccessFeedbackId(id);
|
|
|
- tabUrl.setIsDel(1);
|
|
|
- tabUrlService.updateById(tabUrl);
|
|
|
+
|
|
|
+ updateTabEntityStatus(TabEtl.class, id);
|
|
|
+
|
|
|
+
|
|
|
+ updateTabEntityStatus(TabKafka.class, id);
|
|
|
+
|
|
|
+
|
|
|
+ updateTabEntityStatus(TabKb.class, id);
|
|
|
+
|
|
|
+
|
|
|
+ updateTabEntityStatus(TabSftp.class, id);
|
|
|
+
|
|
|
+
|
|
|
+ updateTabEntityStatus(TabUrl.class, id);
|
|
|
|
|
|
return AjaxResult.success("删除成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private <T> void updateTabEntityStatus(Class<T> entityClass, Long id) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ T entity = entityClass.getDeclaredConstructor().newInstance();
|
|
|
+ entityClass.getMethod("setAccessFeedbackId", Long.class).invoke(entity, id);
|
|
|
+ entityClass.getMethod("setIsDel", Integer.class).invoke(entity, 1);
|
|
|
+ Object service = getServiceByEntityClass(entityClass);
|
|
|
+ service.getClass().getMethod("updateById", entityClass).invoke(service, entity);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ private Object getServiceByEntityClass(Class<?> entityClass) {
|
|
|
+ if (entityClass.equals(TabEtl.class)) {
|
|
|
+ return tabEtlService;
|
|
|
+ } else if (entityClass.equals(TabKafka.class)) {
|
|
|
+ return tabKafkaService;
|
|
|
+ } else if (entityClass.equals(TabKb.class)) {
|
|
|
+ return tabKbService;
|
|
|
+ } else if (entityClass.equals(TabSftp.class)) {
|
|
|
+ return tabSftpService;
|
|
|
+ } else if (entityClass.equals(TabUrl.class)) {
|
|
|
+ return tabUrlService;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public AjaxResult getDataSun(Long id) {
|
|
|
LambdaQueryWrapper<TabEtl> ql = new LambdaQueryWrapper<>();
|
|
@@ -198,5 +336,4 @@ public class TabDatasourceMsgServiceImpl extends ServiceImpl<TabDatasourceMsgMap
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|