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

[数据模型]增加提供普通数据模型json示例的方法

上级 a39061a2
package com.tykj.workflowcore.model_layer.service.impl;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tykj.workflowcore.base.result.ApiException;
import com.tykj.workflowcore.model_layer.dao.AggregationDao;
import com.tykj.workflowcore.model_layer.dao.ColumnInfoDao;
import com.tykj.workflowcore.model_layer.dao.TableInfoDao;
import com.tykj.workflowcore.model_layer.dao.TableInfoExDao;
import com.tykj.workflowcore.model_layer.entity.Aggregation;
import com.tykj.workflowcore.model_layer.entity.ColumnInfo;
import com.tykj.workflowcore.model_layer.entity.TableInfo;
import com.tykj.workflowcore.model_layer.entity.TableInfoEx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -33,10 +32,36 @@ public class ModelHelper {
@Autowired
private AggregationDao aggregationDao;
public String getJsonExample(Integer tableInfoExId) {
TableInfoEx tableInfoEX = tableInfoExDao.findById(tableInfoExId)
.orElseThrow(() -> new RuntimeException(format("未找到该id的数据:%s", tableInfoExId)));
/**
* 获取指定数据模型的json格式数据示例
*
* @param tableInfoId 指定id
* @return json格式的数据示例
*/
public String getJsonExpample(Integer tableInfoId) {
Map<String, Object> result = new HashMap<>();
List<ColumnInfo> columnInfos = columnInfoDao.findAllByDbId(tableInfoId);
for (ColumnInfo columnInfo : columnInfos) {
result.put(columnInfo.getFieldName(), null);
}
try {
return new ObjectMapper().writeValueAsString(result);
} catch (JsonProcessingException e) {
e.printStackTrace();
throw new ApiException("json转换时出现异常");
}
}
/**
* 获取指定聚合对象模型的json格式数据示例
*
* @param tableInfoExId 指定id
* @return json格式的数据示例
*/
public String getExJsonExample(Integer tableInfoExId) {
Map<String, Object> result = new HashMap<>();
TableInfoEx tableInfoEX = tableInfoExDao.findById(tableInfoExId)
.orElseThrow(() -> new ApiException(format("未找到该id的数据:%s", tableInfoExId)));
List<ColumnInfo> columnInfos = columnInfoDao.findAllByDbId(tableInfoEX.getMainTableId());
for (ColumnInfo columnInfo : columnInfos) {
result.put(columnInfo.getFieldName(), null);
......@@ -63,13 +88,14 @@ public class ModelHelper {
result.put(subTableName, subResults);
break;
default:
throw new RuntimeException(format("未识别的聚合类型:%s", relationshipType));
throw new ApiException(format("未识别的聚合类型:%s", relationshipType));
}
}
try {
return new ObjectMapper().writeValueAsString(result);
} catch (JsonProcessingException e) {
return "";
e.printStackTrace();
throw new ApiException("json转换时出现异常");
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论