Commit a66fa4e1 by zhangkb

考核指标公式脑图分析接口上传

parent 7bcd537d
......@@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.keymobile.indicators.model.entity.IndAcsScoreInfo;
import com.keymobile.indicators.model.entity.IndRelTree;
import com.keymobile.indicators.service.cmbkpi.IndAcsScoreInfoService;
import com.keymobile.indicators.utils.DateUtils;
......@@ -66,4 +67,11 @@ public class IndAcsScoreInfoCtrl {
@RequestParam(required=false) String type) throws Exception{
return indAscScoreService.getIndByKeywordAndType(keyword, type);
}
@ApiOperation(value = "分析考核指标公式脑图",notes = "分析考核指标公式脑图")
@PostMapping(value = "/analysisIndTree")
public IndRelTree analysisIndTree(@RequestParam String orgId,
@RequestParam String indId,@RequestParam String indAttrId) throws Exception{
return indAscScoreService.analysisIndTree(orgId, indId, indAttrId);
}
}
package com.keymobile.indicators.model.entity;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
@Data
public class IndRelTree {
private Double weight;
private String indId;
private String indName;
private String indAttrId;
private String type;
private List<IndRelTree> children = new ArrayList<>();
}
......@@ -12,9 +12,11 @@ import org.springframework.stereotype.Service;
import com.keymobile.indicators.model.entity.IndAcsDef;
import com.keymobile.indicators.model.entity.IndAcsScoreInfo;
import com.keymobile.indicators.model.entity.IndAnaDef;
import com.keymobile.indicators.model.entity.IndRelTree;
import com.keymobile.indicators.model.mapper.IndAcsDefMapper;
import com.keymobile.indicators.model.mapper.IndAcsScoreInfoMapper;
import com.keymobile.indicators.model.mapper.IndAnaDefMapper;
import com.keymobile.indicators.utils.FormulaUtils;
@Service
public class IndAcsScoreInfoService {
......@@ -122,4 +124,61 @@ public class IndAcsScoreInfoService {
}
return resultList;
}
public Map<String,String> getIndicatorByInId(String indId){
Map<String,String> result = new HashMap<>();
IndAcsDef indAscDef = new IndAcsDef();
indAscDef.setIndId(indId);
IndAnaDef indAnaDef = new IndAnaDef();
indAnaDef.setIndId(indId);
IndAcsDef ascDef = indAcsDefMapper.selectOne(indAscDef);
if(ascDef!=null) {
result.put("indId", ascDef.getIndId());
result.put("indName", ascDef.getIndName());
result.put("type", "1");
}else {
IndAnaDef anaDef = indAnaDefMapper.selectOne(indAnaDef);
if(anaDef!=null) {
result.put("indId", anaDef.getIndId());
result.put("indName", anaDef.getIndName());
result.put("type", "0");
}
}
return result;
}
public IndRelTree analysisIndTree(String orgId,String indId,String indAttrId) throws Exception{
IndRelTree indRelTree = new IndRelTree();
//获取指标信息
Map<String,String> indInfo = this.getIndicatorByInId(indId);
if(indInfo.isEmpty()) {
indRelTree.setIndId(indId+" has been deleted");
indRelTree.setIndName(indId+" 被删除");
indRelTree.setType(indInfo.get("unknown"));
}else {
indRelTree.setIndId(indInfo.get("indId"));
indRelTree.setIndName(indInfo.get("indName"));
indRelTree.setType(indInfo.get("type"));
}
indRelTree.setChildren(new ArrayList<IndRelTree>());
//根据机构id,指标id和指标类型获取考核指标
IndAcsScoreInfo indAcsScoreInfo = this.selectOneByOrgIdAndIndidAndIndtype(orgId,
indId, indAttrId);
if(indAcsScoreInfo!=null) {
indRelTree.setIndAttrId(indAcsScoreInfo.getIndexAttrId());
indRelTree.setWeight(indAcsScoreInfo.getWeight());
//分析公式
String formula = indAcsScoreInfo.getScoreFormula();
if(StringUtils.isNotBlank(formula)) {
List<Map<String,String>> formulaInfo = FormulaUtils.analysisFormula(formula);
for(Map<String,String> map : formulaInfo) {
indRelTree.getChildren().add(analysisIndTree(orgId,
map.get("indId"),map.get("indAttrId")));
}
}
}
return indRelTree;
}
}
package com.keymobile.indicators.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class FormulaUtils {
public static List<Map<String,String>> analysisFormula(String formula){
List<Map<String,String>> result = new ArrayList<>();
Pattern p = Pattern.compile("(\\[[^\\]]*\\])");
Matcher m = p.matcher(formula);
while(m.find()){
Map<String,String> map = new HashMap<>();
String expression = m.group().substring(1, m.group().length()-1);
String[] params = expression.split(":");
map.put("indId", params[0]);
map.put("indAttrId", params[1]);
map.put("dateRef", params[2]);
result.add(map);
}
return result;
}
}
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