|
@ -4,14 +4,23 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.yihu.ehr.elasticsearch.ElasticSearchPool;
|
|
|
import com.yihu.ehr.elasticsearch.ElasticSearchUtil;
|
|
|
import com.yihu.ehr.util.datetime.DateUtil;
|
|
|
import com.yihu.quota.etl.formula.DictFunc;
|
|
|
import com.yihu.quota.etl.formula.DivisionFunc;
|
|
|
import com.yihu.quota.util.ElasticSearchHandler;
|
|
|
import com.yihu.quota.vo.CubeMappingModel;
|
|
|
import com.yihu.quota.vo.CubeMemberMappingModel;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.NumberFormat;
|
|
|
import java.text.ParseException;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@ -30,8 +39,6 @@ public class ElasticSearchDataProcessService {
|
|
|
@Autowired
|
|
|
private CubeMappingService cubeMappingService;
|
|
|
@Autowired
|
|
|
private CubeService cubeService;
|
|
|
@Autowired
|
|
|
private CubeMemberMappingService cubeMemberMappingService;
|
|
|
@Autowired
|
|
|
private ElasticSearchPool elasticSearchPool;
|
|
@ -74,7 +81,6 @@ public class ElasticSearchDataProcessService {
|
|
|
//通过表找到 对应的数据集 保存的索引和type
|
|
|
//TODO 可以维护到数据字典 - 保存到redis 减少去数据库里面查询
|
|
|
|
|
|
|
|
|
String rowKey = dataMap.get("rowKey").toString();
|
|
|
String action = dataMap.get("action").toString();
|
|
|
dataMap.remove("table");
|
|
@ -82,10 +88,93 @@ public class ElasticSearchDataProcessService {
|
|
|
dataMap.remove("action");
|
|
|
try {
|
|
|
if(action.contains(action_put)){
|
|
|
//保存数据
|
|
|
//TODO 子属性数据 更新 ,需要将库中数据查询出来,然后合并在保存到库中
|
|
|
//TODO 扩展的属性值 更新 如 字典 子成员 更加数据类型转换
|
|
|
String keyValue = "";
|
|
|
for(String key : dataMap.keySet()){
|
|
|
if(dataMap.get(key)!= null){
|
|
|
keyValue = dataMap.get(key).toString();
|
|
|
}
|
|
|
|
|
|
//根据列名 查找出 对应的维度code及是否要数据字典,是否通过算法扩展出来
|
|
|
// 是否是子集模式中
|
|
|
List<CubeMappingModel> cubeMappingModels = cubeMappingService.findCubeMappingModelsByFieldCode(table, key);
|
|
|
if(cubeMappingModels != null && cubeMappingModels.size() > 0){
|
|
|
for(CubeMappingModel cubeMappingModel :cubeMappingModels){
|
|
|
String cloumnCode = cubeMappingModel.getDimensionCode();
|
|
|
//字典扩展
|
|
|
if(StringUtils.isNotEmpty(cubeMappingModel.getDict())){
|
|
|
DictFunc dictFunc = new DictFunc();
|
|
|
String param[] = {cubeMappingModel.getDict(),cloumnCode};
|
|
|
String value = dictFunc.execute(param);
|
|
|
String dictCode = cloumnCode + ".Code";
|
|
|
String dictName = cloumnCode + ".Name";
|
|
|
source.put(dictCode,key);
|
|
|
source.put(dictName,value);
|
|
|
}else if(StringUtils.isNotEmpty(cubeMappingModel.getAlgorithm())){
|
|
|
//具体维度 对应具体算法
|
|
|
}else {
|
|
|
if(StringUtils.isNotEmpty(cubeMappingModel.getDataType())){
|
|
|
String dataType = cubeMappingModel.getDataType();
|
|
|
Object value = dataConver(dataType,keyValue);
|
|
|
source.put(cloumnCode,value);
|
|
|
}else{
|
|
|
source.put(cloumnCode,dataMap.get(key));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
List<CubeMemberMappingModel> cubeMemberMappingModels = cubeMemberMappingService.findCubeMemberMappingModels(table,key);
|
|
|
if(cubeMemberMappingModels != null && cubeMemberMappingModels.size() > 0){
|
|
|
for(CubeMemberMappingModel cubeMemberMappingModel :cubeMemberMappingModels){
|
|
|
String cloumnCode = cubeMemberMappingModel.getDimensionCode();
|
|
|
String parentCode = cubeMemberMappingModel.getParentCode();
|
|
|
if(cubeMemberMappingModel.getChildSaveType() != null){
|
|
|
int childSaveType = cubeMemberMappingModel.getChildSaveType();
|
|
|
if(childSaveType == 1 ){//对象方式
|
|
|
|
|
|
}
|
|
|
if(childSaveType == 2 ){//nested 方式
|
|
|
//查出历史数据 然后组合保存
|
|
|
}
|
|
|
}else {
|
|
|
|
|
|
}
|
|
|
//字典扩展
|
|
|
if(StringUtils.isNotEmpty(cubeMemberMappingModel.getDict())){
|
|
|
DictFunc dictFunc = new DictFunc();
|
|
|
String param[] = {cubeMemberMappingModel.getDict(),cloumnCode};
|
|
|
String value = dictFunc.execute(param);
|
|
|
String dictCode = cloumnCode + ".Code";
|
|
|
String dictName = cloumnCode + ".Name";
|
|
|
source.put(dictCode,key);
|
|
|
source.put(dictName,value);
|
|
|
}else if(StringUtils.isNotEmpty(cubeMemberMappingModel.getAlgorithm())){
|
|
|
if(cubeMemberMappingModel.getAlgorithm().equals("DivisionFunc") && StringUtils.isNotEmpty(cubeMemberMappingModel.getParm())){
|
|
|
if(cubeMemberMappingModel.getParm().equals(key)){
|
|
|
DivisionFunc divisionFunc = new DivisionFunc();
|
|
|
String townParam[] = {dataMap.get(key).toString(),"1"};
|
|
|
String townVal = divisionFunc.execute(townParam);
|
|
|
String cityParam[] = {dataMap.get(key).toString(),"2"};
|
|
|
String cityVal = divisionFunc.execute(cityParam);
|
|
|
String provinceParam[] = {dataMap.get(key).toString(),"3"};
|
|
|
String provinceVal = divisionFunc.execute(provinceParam);
|
|
|
source.put("",townVal);
|
|
|
source.put("",cityVal);
|
|
|
source.put("",provinceVal);
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
|
if(StringUtils.isNotEmpty(cubeMemberMappingModel.getDataType())){
|
|
|
String dataType = cubeMemberMappingModel.getDataType();
|
|
|
Object value = dataConver(dataType,keyValue);
|
|
|
source.put(cloumnCode,value);
|
|
|
}else{
|
|
|
source.put(cloumnCode,dataMap.get(key));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
elasticSearchUtil.index(index, type, dataMap);
|
|
|
}else if (action.contains(action_del)){
|
|
|
for(String key : dataMap.keySet()){
|
|
@ -101,6 +190,9 @@ public class ElasticSearchDataProcessService {
|
|
|
logger.debug("elasticSearch 执行失败");
|
|
|
e.printStackTrace();
|
|
|
e.getMessage();
|
|
|
} catch (Exception e) {
|
|
|
logger.debug("数据解析异常");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
@ -119,4 +211,31 @@ public class ElasticSearchDataProcessService {
|
|
|
return source;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 数据类型转换
|
|
|
* @param dataType
|
|
|
* @param keyValue
|
|
|
*/
|
|
|
public Object dataConver(String dataType,String keyValue){
|
|
|
NumberFormat nf = NumberFormat.getInstance();
|
|
|
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;
|
|
|
}
|
|
|
return value;
|
|
|
}
|
|
|
|
|
|
}
|