Commit e609702d by zhangkb

指标关系接口优化

parent e0f65606
...@@ -18,6 +18,7 @@ public class IndicatorsRel { ...@@ -18,6 +18,7 @@ public class IndicatorsRel {
private Integer id; private Integer id;
private String indId; private String indId;
private String relIndId; private String relIndId;
private String indType;//类型 0:基础指标 1:考核指标
private String indFormat;//指标公式 private String indFormat;//指标公式
private String indFormatDesc;//指标公式描述 private String indFormatDesc;//指标公式描述
} }
...@@ -35,6 +35,7 @@ public class IndicatorsRelService { ...@@ -35,6 +35,7 @@ public class IndicatorsRelService {
//incluSelf:表示是否包含自己 0:否 1:是 //incluSelf:表示是否包含自己 0:否 1:是
//type:0 基础指标 1:考核指标 //type:0 基础指标 1:考核指标
@SuppressWarnings("unchecked")
public Map<String,Object> getRelByIndId(String indId,String type,String incluSelf){ public Map<String,Object> getRelByIndId(String indId,String type,String incluSelf){
Map<String,Object> resultMap = new HashMap<>(); Map<String,Object> resultMap = new HashMap<>();
//先从库里找,找不到再分析公式然后保存进库里 //先从库里找,找不到再分析公式然后保存进库里
...@@ -59,19 +60,45 @@ public class IndicatorsRelService { ...@@ -59,19 +60,45 @@ public class IndicatorsRelService {
formulaDesc = driveIndDef.getIndFormatDesc(); formulaDesc = driveIndDef.getIndFormatDesc();
} }
} }
resultMap.put("formula", formula);
resultMap.put("formulaDesc", formulaDesc);
for(IndicatorsRel indRel : indRels) { for(IndicatorsRel indRel : indRels) {
resultIndIdList.add(indRel.getRelIndId()); resultIndIdList.add(indRel.getRelIndId());
} }
//循环找出基础指标包含的指标
Map<String,Object> resultBaseRelMap = this.getBaseIndRel(resultIndIdList, formula);
resultIndIdList.addAll((List<String>)resultBaseRelMap.get("resultIndIdList"));
if(resultBaseRelMap.get("formula")!=null &&
!"".equals(resultBaseRelMap.get("formula"))) {
formula = resultBaseRelMap.get("formula").toString();
}
if("1".equals(incluSelf)) { if("1".equals(incluSelf)) {
resultIndIdList.add(indId); resultIndIdList.add(indId);
} }
resultMap.put("ind_type", type);
resultMap.put("formula", formula);
resultMap.put("formulaDesc", formulaDesc);
resultMap.put("indIdList",resultIndIdList); resultMap.put("indIdList",resultIndIdList);
} }
return resultMap; return resultMap;
} }
@SuppressWarnings("unchecked")
public Map<String,Object> getBaseIndRel(List<String> resultIndIdList,String formula){
Map<String,Object> result = new HashMap<>();
List<String> resultRelIndList = new ArrayList<>();
for(String indId : resultIndIdList) {
Map<String,Object> relIndIdMap = this.getRelFromFormula(indId, "0", "0");
if(relIndIdMap.get("formula")!=null && !"".equals(relIndIdMap.get("formula"))) {
String relIndFormula = relIndIdMap.get("formula").toString();
List<String> relIndList = (List<String>)relIndIdMap.get("indIdList");
resultRelIndList.addAll(relIndList);
formula = formula.replace("["+indId+"]", "("+relIndFormula+")");
}
}
result.put("resultIndIdList", resultRelIndList);
result.put("formula", formula);
return result;
}
public Map<String,Object> getRelFromFormula(String indId,String type,String incluSelf){ public Map<String,Object> getRelFromFormula(String indId,String type,String incluSelf){
String formula = null; String formula = null;
String formulaDesc = null; String formulaDesc = null;
...@@ -80,6 +107,8 @@ public class IndicatorsRelService { ...@@ -80,6 +107,8 @@ public class IndicatorsRelService {
resultMap.put("indIdList",new ArrayList<>()); resultMap.put("indIdList",new ArrayList<>());
resultMap.put("formula", formula); resultMap.put("formula", formula);
resultMap.put("formulaDesc", formulaDesc); resultMap.put("formulaDesc", formulaDesc);
//判断该指标有没有保存了关联指标
List<IndicatorsRel> indRels = indicatorsRelMapper.findByIndId(indId);
//根据类型查找指标 //根据类型查找指标
if("0".equals(type)) {//基础指标 if("0".equals(type)) {//基础指标
BaseIndDef baseIndDef = baseIndDefMapper.selectByPrimaryKey(indId); BaseIndDef baseIndDef = baseIndDefMapper.selectByPrimaryKey(indId);
...@@ -94,29 +123,39 @@ public class IndicatorsRelService { ...@@ -94,29 +123,39 @@ public class IndicatorsRelService {
formulaDesc = driveIndDef.getIndFormatDesc(); formulaDesc = driveIndDef.getIndFormatDesc();
} }
} }
//解析公式关系 if(!indRels.isEmpty()) {
if(StringUtils.isNotBlank(formula)) { for(IndicatorsRel rel : indRels) {
List<String> indIdList = new ArrayList<>(); resultIndIdList.add(rel.getRelIndId());
Matcher m = P.matcher(formula);
while(m.find()){
indIdList.add(m.group().substring(1, m.group().length()-1));
}
for(String relIndId : indIdList) {
IndicatorsRel indRel = new IndicatorsRel();
indRel.setIndId(indId);
indRel.setRelIndId(relIndId);
indRel.setIndFormat(formula);
indRel.setIndFormatDesc(formulaDesc);
indicatorsRelMapper.insert(indRel);
resultIndIdList.add(relIndId);
} }
if("1".equals(incluSelf)) { if("1".equals(incluSelf)) {
resultIndIdList.add(indId); resultIndIdList.add(indId);
} }
resultMap.put("indIdList",resultIndIdList); }else {
resultMap.put("formula", formula); //解析公式关系
resultMap.put("formulaDesc", formulaDesc); if(StringUtils.isNotBlank(formula)) {
List<String> indIdList = new ArrayList<>();
Matcher m = P.matcher(formula);
while(m.find()){
indIdList.add(m.group().substring(1, m.group().length()-1));
}
for(String relIndId : indIdList) {
IndicatorsRel indRel = new IndicatorsRel();
indRel.setIndId(indId);
indRel.setRelIndId(relIndId);
indRel.setIndFormat(formula);
indRel.setIndFormatDesc(formulaDesc);
indRel.setIndType(type);
indicatorsRelMapper.insert(indRel);
resultIndIdList.add(relIndId);
}
if("1".equals(incluSelf)) {
resultIndIdList.add(indId);
}
}
} }
resultMap.put("indIdList",resultIndIdList);
resultMap.put("formula", formula);
resultMap.put("formulaDesc", formulaDesc);
return resultMap; return resultMap;
} }
...@@ -157,6 +196,7 @@ public class IndicatorsRelService { ...@@ -157,6 +196,7 @@ public class IndicatorsRelService {
indRel.setRelIndId(relIndId); indRel.setRelIndId(relIndId);
indRel.setIndFormat(formula); indRel.setIndFormat(formula);
indRel.setIndFormatDesc(formulaDesc); indRel.setIndFormatDesc(formulaDesc);
indRel.setIndType(type);
indicatorsRelMapper.insert(indRel); indicatorsRelMapper.insert(indRel);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment