|
@ -12,6 +12,7 @@ import com.yihu.quota.model.source.DataSourcesTableField;
|
|
|
import com.yihu.quota.service.source.DataSourcesTableFieldService;
|
|
|
import com.yihu.quota.vo.CubeMappingModel;
|
|
|
import com.yihu.quota.vo.CubeMemberMappingModel;
|
|
|
import com.yihu.quota.vo.DataSourcesTableModel;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@ -32,6 +33,7 @@ public class ElasticSearchDataProcessService {
|
|
|
private static String dataSource_mysql = "mysql";
|
|
|
private static String action_del = "DeleteFamily";//删除整行
|
|
|
private static String action_put = "Put"; //添加和修改单个字段值
|
|
|
private static String action_delAll = "delAll";
|
|
|
|
|
|
private static String dataSource_k = "dataSource";
|
|
|
private static String database_k = "database";
|
|
@ -40,7 +42,6 @@ public class ElasticSearchDataProcessService {
|
|
|
private static String rowKey_k = "rowkey";
|
|
|
private static String profileId_k = "profile_id";
|
|
|
private static String action_k = "action";
|
|
|
private static String action_delAll = "delAll";
|
|
|
|
|
|
@Autowired
|
|
|
private JdbcBasicService jdbcBasicService;
|
|
@ -67,9 +68,9 @@ public class ElasticSearchDataProcessService {
|
|
|
String dataSource = dataMap.get(dataSource_k).toString();
|
|
|
dataMap.remove(dataSource_k);
|
|
|
if(dataSource.toLowerCase().equals(dataSource_hbase)){
|
|
|
dataProcess(dataMap);
|
|
|
dataProcess(dataMap);
|
|
|
}else if(dataSource.toLowerCase().equals(dataSource_mysql)){
|
|
|
dataProcess(dataMap);
|
|
|
dataProcess(dataMap);
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@ -84,7 +85,6 @@ public class ElasticSearchDataProcessService {
|
|
|
* 如果是 删除 子表中的一行数据,es 这边就无法确定删除哪个数据
|
|
|
*/
|
|
|
public void dataProcess(Map<String, Object> dataMap) throws Exception{
|
|
|
Map<String, Object> source = new HashMap<>();
|
|
|
String table = "";
|
|
|
String rowKey = "";
|
|
|
String profileId = "";
|
|
@ -98,8 +98,6 @@ public class ElasticSearchDataProcessService {
|
|
|
}
|
|
|
if(dataMap.containsKey(rowKey_k)){
|
|
|
rowKey = dataMap.get(rowKey_k).toString();
|
|
|
source.put(id_k,rowKey);
|
|
|
source.put(rowKey_k,rowKey);
|
|
|
}
|
|
|
if(dataMap.containsKey(profileId_k)){
|
|
|
profileId = dataMap.get(profileId_k).toString();
|
|
@ -111,20 +109,28 @@ public class ElasticSearchDataProcessService {
|
|
|
dataMap.remove(table_k);
|
|
|
dataMap.remove(rowKey_k);
|
|
|
dataMap.remove(action_k);
|
|
|
String baseCloumnValue = "";
|
|
|
String baseCloumnValue = null;
|
|
|
if(action.contains(action_put)){
|
|
|
for(String baseCloumnCode : dataMap.keySet()){
|
|
|
if(dataMap.get(baseCloumnCode)!= null){
|
|
|
baseCloumnValue = dataMap.get(baseCloumnCode).toString();
|
|
|
}else {
|
|
|
baseCloumnValue = null;
|
|
|
}
|
|
|
System.out.println("开始解析数据:" + baseCloumnCode + " ,值为 = " + baseCloumnValue);
|
|
|
List<CubeMappingModel> cubeMappingModels = cubeMappingService.findCubeMappingModelsByFieldCode(table, baseCloumnCode);
|
|
|
if(cubeMappingModels != null && cubeMappingModels.size() > 0){
|
|
|
for(CubeMappingModel cubeMappingModel :cubeMappingModels){
|
|
|
Map<String, Object> source = new HashMap<>();
|
|
|
source.put(id_k,rowKey);
|
|
|
source.put(rowKey_k,rowKey);
|
|
|
String index = cubeMappingModel.getIndexName();
|
|
|
String type = cubeMappingModel.getIndexType();
|
|
|
String cloumnCode = cubeMappingModel.getDimensionCode();
|
|
|
System.out.println("维度code = " + cloumnCode + ",维度类型:" + cubeMappingModel.getDataType());
|
|
|
//维度数据扩展保存
|
|
|
Map<String, Object> esDataMap = dimensionDataExtendToMap(cubeMappingModel,cloumnCode,baseCloumnValue);
|
|
|
Map<String, Object> esDataMap = new HashMap<>();
|
|
|
esDataMap = dimensionDataExtendToMap(cubeMappingModel,cloumnCode,baseCloumnValue);
|
|
|
source.putAll(esDataMap);
|
|
|
saveElasticSearchData(index, type,rowKey,source);
|
|
|
}
|
|
@ -142,46 +148,38 @@ public class ElasticSearchDataProcessService {
|
|
|
String subRowKey = rowKey;
|
|
|
if(action.contains(action_put)){
|
|
|
//维度成员数据扩展保存
|
|
|
Map<String, Object> source = new HashMap<>();
|
|
|
source = dimensionMemberDataExtendToMap(cubeMemberMappingModel,baseCloumnValue,subRowKey,profileId);
|
|
|
saveElasticSearchData(index, type,profileId,source);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//是否为关联字段 start
|
|
|
List<CubeMappingModel> relationMappingModels = cubeMappingService.findRelationMappingModelsByFieldCode(table, baseCloumnCode);
|
|
|
if(relationMappingModels != null && relationMappingModels.size() > 0) {
|
|
|
for (CubeMappingModel cubeMappingModel : relationMappingModels) {
|
|
|
DataSourcesTableField dataSourcesTableField = dataSourcesTableFieldService.findById(cubeMappingModel.getDataFieldId());
|
|
|
Object object = jdbcBasicService.getEntityByRelationId(database ,table, dataSourcesTableField.getFieldCode(), cubeMappingModel.getRelationFieldId());
|
|
|
String value = converMapObject(object);
|
|
|
String index = cubeMappingModel.getIndexName();
|
|
|
String type = cubeMappingModel.getIndexType();
|
|
|
String cloumnCode = cubeMappingModel.getDimensionCode();
|
|
|
//维度数据扩展保存
|
|
|
Map<String, Object> esDataMap = dimensionDataExtendToMap(cubeMappingModel,cloumnCode,value);
|
|
|
source.putAll(esDataMap);
|
|
|
saveElasticSearchData(index, type,rowKey,source);
|
|
|
}
|
|
|
}
|
|
|
// //主表字段关联出相关表数据 start
|
|
|
List<CubeMemberMappingModel> relationMemberMappingModels = cubeMemberMappingService.findRelationMemberMappingModels(table,baseCloumnCode);
|
|
|
if(relationMemberMappingModels != null && relationMemberMappingModels.size() > 0) {
|
|
|
profileId = rowKey;
|
|
|
for (CubeMemberMappingModel cubeMemberMappingModel : relationMemberMappingModels) {
|
|
|
//父级对象
|
|
|
if(cubeMemberMappingModel.getChildSaveType() == 1){
|
|
|
DataSourcesTableField dataSourcesTableField = dataSourcesTableFieldService.findById(cubeMemberMappingModel.getDataFieldId());
|
|
|
String value = jdbcBasicService.getEntityByRelationId(database ,table, dataSourcesTableField.getFieldCode(), cubeMemberMappingModel.getRelationFieldId());
|
|
|
String index = cubeMemberMappingModel.getIndexName();
|
|
|
String type = cubeMemberMappingModel.getIndexType();
|
|
|
String subRowKey = rowKey;
|
|
|
if(action.contains(action_put)){
|
|
|
//维度成员数据扩展保存
|
|
|
source = dimensionMemberDataExtendToMap(cubeMemberMappingModel,value,subRowKey,profileId);
|
|
|
saveElasticSearchData(index, type,profileId,source);
|
|
|
if(cubeMemberMappingModel.getChildSaveType() == 1 && cubeMemberMappingModel.getRelationSubFieldId() != null){
|
|
|
DataSourcesTableModel dataSourcesTableModel = dataSourcesTableFieldService.findDataSourcesTableModel(cubeMemberMappingModel.getDataFieldId());
|
|
|
DataSourcesTableModel subdataSourcesTableModel = dataSourcesTableFieldService.findDataSourcesTableModel(cubeMemberMappingModel.getRelationSubFieldId());
|
|
|
if(dataSourcesTableModel != null && subdataSourcesTableModel != null){
|
|
|
String value = jdbcBasicService.getEntityByRelationId(subdataSourcesTableModel.getDatabaseName() ,subdataSourcesTableModel.getTableCode(), dataSourcesTableModel.getFieldCode(),subdataSourcesTableModel.getFieldCode(),subdataSourcesTableModel.getFieldType(),baseCloumnValue);
|
|
|
if(StringUtils.isNotEmpty(value)){
|
|
|
String index = cubeMemberMappingModel.getIndexName();
|
|
|
String type = cubeMemberMappingModel.getIndexType();
|
|
|
if(action.contains(action_put)){
|
|
|
//维度成员数据扩展保存
|
|
|
Map<String, Object> source = new HashMap<>();
|
|
|
source = dimensionMemberDataExtendToMap(cubeMemberMappingModel,value,null,profileId);
|
|
|
saveElasticSearchData(index, type,profileId,source);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//是否为关联字段 end
|
|
|
//主表字段关联出相关表数据 end
|
|
|
}
|
|
|
}else if(action.contains(action_del)){
|
|
|
//一个表只能对应到一个 索引type
|
|
@ -191,7 +189,7 @@ public class ElasticSearchDataProcessService {
|
|
|
}else {
|
|
|
throw new Exception("视图,表不存在");
|
|
|
}
|
|
|
} else if (action.contains(action_delAll)) {
|
|
|
}else if (action.contains(action_delAll)) {
|
|
|
String cubeId = "";
|
|
|
if (dataMap.containsKey("cubeId")) {
|
|
|
cubeId = dataMap.remove("cubeId").toString();
|
|
@ -442,23 +440,37 @@ public class ElasticSearchDataProcessService {
|
|
|
* @param dataType
|
|
|
* @param keyValue
|
|
|
*/
|
|
|
public Object dataConver(String dataType,String keyValue){
|
|
|
NumberFormat nf = NumberFormat.getInstance();
|
|
|
public Object dataConver(String dataType,String keyValue) throws Exception{
|
|
|
Object value = null;
|
|
|
dataType = dataType.toLowerCase();
|
|
|
if(dataType.equals("string")){
|
|
|
value = keyValue;
|
|
|
}else if(dataType.equals("int")){
|
|
|
int intValue = Integer.valueOf(keyValue);
|
|
|
value = intValue;
|
|
|
}else if(dataType.equals("double")){
|
|
|
nf.setGroupingUsed(false);
|
|
|
nf.setMaximumFractionDigits(2);
|
|
|
double doubleValue = Double.valueOf(keyValue);
|
|
|
value = doubleValue;
|
|
|
}else if(dataType.equals("date")){
|
|
|
Date dateValue = DateUtil.formatCharDateYMDHMS(keyValue);
|
|
|
value = dateValue;
|
|
|
NumberFormat nf = NumberFormat.getInstance();
|
|
|
try {
|
|
|
if(StringUtils.isNotEmpty(keyValue)){
|
|
|
dataType = dataType.toLowerCase();
|
|
|
if(dataType.equals("string")){
|
|
|
value = keyValue;
|
|
|
}else if(dataType.equals("integer")){
|
|
|
int intValue = Integer.valueOf(keyValue);
|
|
|
value = intValue;
|
|
|
}else if(dataType.equals("double")){
|
|
|
nf.setGroupingUsed(false);
|
|
|
nf.setMaximumFractionDigits(2);
|
|
|
double doubleValue = Double.valueOf(keyValue);
|
|
|
value = doubleValue;
|
|
|
}else if(dataType.equals("date")){
|
|
|
String dateFormat = DateUtil.DEFAULT_DATE_YMD_FORMAT;
|
|
|
if(keyValue.length() > 10){
|
|
|
dateFormat = DateUtil.DEFAULT_YMDHMSDATE_FORMAT;;
|
|
|
}
|
|
|
Date dateValue = DateUtil.parseDate(keyValue, dateFormat);
|
|
|
Calendar ca = Calendar.getInstance();
|
|
|
ca.setTime(dateValue);
|
|
|
ca.add(Calendar.HOUR_OF_DAY, 8);
|
|
|
value = ca.getTime();
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
logger.debug("数据转换异常!");
|
|
|
}
|
|
|
return value;
|
|
|
}
|
|
@ -484,4 +496,5 @@ public class ElasticSearchDataProcessService {
|
|
|
}
|
|
|
return index;
|
|
|
}
|
|
|
|
|
|
}
|