|
|
@ -2,12 +2,14 @@ package com.gaotao.modules.base.service.Impl; |
|
|
|
|
|
|
|
|
import com.gaotao.modules.base.service.BaseService; |
|
|
import com.gaotao.modules.base.service.BaseService; |
|
|
import com.gaotao.modules.base.service.DataSourceService; |
|
|
import com.gaotao.modules.base.service.DataSourceService; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.jdbc.core.JdbcTemplate; |
|
|
import org.springframework.jdbc.core.JdbcTemplate; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Service |
|
|
@Service |
|
|
public class DataSourceServiceImpl implements DataSourceService { |
|
|
public class DataSourceServiceImpl implements DataSourceService { |
|
|
|
|
|
|
|
|
@ -20,10 +22,49 @@ public class DataSourceServiceImpl implements DataSourceService { |
|
|
public List<Map<String, Object>> getViewFieldsByLabelType(String labelType, String site) { |
|
|
public List<Map<String, Object>> getViewFieldsByLabelType(String labelType, String site) { |
|
|
List<Map<String, Object>> fields = new ArrayList<>(); |
|
|
List<Map<String, Object>> fields = new ArrayList<>(); |
|
|
try { |
|
|
try { |
|
|
// 根据标签类型获取对应的视图名称 |
|
|
|
|
|
String viewName = getViewNameByLabelType(labelType); |
|
|
|
|
|
if (viewName != null) { |
|
|
|
|
|
// 查询视图的字段信息 |
|
|
|
|
|
|
|
|
// 根据标签类型获取对应的视图信息 |
|
|
|
|
|
Map<String, String> viewInfo = getViewInfoByLabelType(labelType); |
|
|
|
|
|
String mainViewName = viewInfo.get("viewSql"); |
|
|
|
|
|
String ifsViewName = viewInfo.get("ifsViewSql"); |
|
|
|
|
|
|
|
|
|
|
|
// 查询主视图的字段信息 |
|
|
|
|
|
if (mainViewName != null && !mainViewName.trim().isEmpty()) { |
|
|
|
|
|
List<Map<String, Object>> mainViewFields = getViewFields(mainViewName, "主视图"); |
|
|
|
|
|
fields.addAll(mainViewFields); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 查询IFS视图的字段信息,自动添加_ifs后缀 |
|
|
|
|
|
if (ifsViewName != null && !ifsViewName.trim().isEmpty()) { |
|
|
|
|
|
List<Map<String, Object>> ifsViewFields = getViewFields(ifsViewName, "IFS视图"); |
|
|
|
|
|
// 给所有IFS视图字段添加_ifs后缀 |
|
|
|
|
|
for (Map<String, Object> field : ifsViewFields) { |
|
|
|
|
|
String originalFieldName = field.get("fieldName").toString(); |
|
|
|
|
|
field.put("fieldName", originalFieldName + "_ifs"); |
|
|
|
|
|
} |
|
|
|
|
|
fields.addAll(ifsViewFields); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果两个视图都没有找到,使用模拟数据 |
|
|
|
|
|
if (fields.isEmpty()) { |
|
|
|
|
|
fields = getCCLLabel(labelType, site); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 获取已保存的字段描述 |
|
|
|
|
|
loadFieldDescriptions(labelType, site, fields); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("获取视图字段失败: labelType={}, error={}", labelType, e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
return fields; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取指定视图的字段信息 |
|
|
|
|
|
*/ |
|
|
|
|
|
private List<Map<String, Object>> getViewFields(String viewName, String viewSource) { |
|
|
|
|
|
List<Map<String, Object>> fields = new ArrayList<>(); |
|
|
|
|
|
try { |
|
|
String sql = "SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE " + |
|
|
String sql = "SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE " + |
|
|
"FROM INFORMATION_SCHEMA.COLUMNS " + |
|
|
"FROM INFORMATION_SCHEMA.COLUMNS " + |
|
|
"WHERE TABLE_NAME = ? " + |
|
|
"WHERE TABLE_NAME = ? " + |
|
|
@ -37,16 +78,11 @@ public class DataSourceServiceImpl implements DataSourceService { |
|
|
field.put("fieldType", column.get("DATA_TYPE")); |
|
|
field.put("fieldType", column.get("DATA_TYPE")); |
|
|
field.put("isRequired", "NO".equals(column.get("IS_NULLABLE"))); |
|
|
field.put("isRequired", "NO".equals(column.get("IS_NULLABLE"))); |
|
|
field.put("fieldDescription", ""); // 初始为空,后续可以从配置表获取 |
|
|
field.put("fieldDescription", ""); // 初始为空,后续可以从配置表获取 |
|
|
|
|
|
field.put("viewSource", viewSource); // 标识字段来源 |
|
|
fields.add(field); |
|
|
fields.add(field); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
|
|
|
// 如果没有找到对应的视图,使用模拟数据 |
|
|
|
|
|
fields = getCCLLabel(labelType, site); |
|
|
|
|
|
} |
|
|
|
|
|
// 获取已保存的字段描述 |
|
|
|
|
|
loadFieldDescriptions(labelType, site, fields); |
|
|
|
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
|
|
|
|
log.error("获取视图字段失败: viewName={}, viewSource={}, error={}", viewName, viewSource, e.getMessage()); |
|
|
} |
|
|
} |
|
|
return fields; |
|
|
return fields; |
|
|
} |
|
|
} |
|
|
@ -99,9 +135,27 @@ public class DataSourceServiceImpl implements DataSourceService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private String getViewNameByLabelType(String labelType) { |
|
|
|
|
|
List<java.util.Map<String, Object>> viewMapping = baseService.getLabelTypeList(null,labelType); |
|
|
|
|
|
return viewMapping.isEmpty()?null:(viewMapping.getFirst().get("viewSql")!=null?viewMapping.getFirst().get("viewSql").toString():null); |
|
|
|
|
|
|
|
|
private Map<String, String> getViewInfoByLabelType(String labelType) { |
|
|
|
|
|
Map<String, String> viewInfo = new HashMap<>(); |
|
|
|
|
|
List<java.util.Map<String, Object>> viewMapping = baseService.getLabelTypeList(null, labelType); |
|
|
|
|
|
|
|
|
|
|
|
if (!viewMapping.isEmpty()) { |
|
|
|
|
|
java.util.Map<String, Object> mapping = viewMapping.getFirst(); |
|
|
|
|
|
|
|
|
|
|
|
// 获取主视图SQL |
|
|
|
|
|
Object viewSql = mapping.get("viewSql"); |
|
|
|
|
|
if (viewSql != null) { |
|
|
|
|
|
viewInfo.put("viewSql", viewSql.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 获取IFS视图SQL |
|
|
|
|
|
Object ifsViewSql = mapping.get("ifsViewSql"); |
|
|
|
|
|
if (ifsViewSql != null) { |
|
|
|
|
|
viewInfo.put("ifsViewSql", ifsViewSql.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return viewInfo; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void loadFieldDescriptions(String labelType, String site, List<Map<String, Object>> fields) { |
|
|
private void loadFieldDescriptions(String labelType, String site, List<Map<String, Object>> fields) { |
|
|
|