Commit e0f65606 by zhangkb

添加指标保存时保存指标关系和根据指标id查找关系接口

parent deb27883
package com.keymobile.indicators.api.hytobacco;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.keymobile.indicators.service.hytobacco.IndicatorsRelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(tags={"指标关系接口"})
@RestController
@RequestMapping(value = "/indRel")
public class IndicatorsRelCtrl {
@Autowired
private IndicatorsRelService indRelService;
@ApiOperation(value = "根据指标id获取指标关系,type:0 基础指标 1考核指标", notes = "根据指标id获取指标关系,type:0 基础指标 1考核指标")
@PostMapping(value = "/getRelByIndId")
public Map<String,Object> getRelByIndId(@RequestParam String indId,@RequestParam String type,
@RequestParam String incluSelf){
return indRelService.getRelByIndId(indId, type, incluSelf);
}
}
......@@ -18,6 +18,8 @@ public class BaseIndDefService {
private BaseIndDefMapper baseIndDefMapper;
@Autowired
private BaseIndDefVersionService baseIndDefVersionService;
@Autowired
private IndicatorsRelService indRelService;
public String saveOrUpdate(BaseIndDef baseIndDef,Integer catalogId,
String catalogIdPath,String user,String isUpdate)
......@@ -58,6 +60,8 @@ public class BaseIndDefService {
return "base ind is not exist,update ind fail";
}
}
//保存或修改指标关系
indRelService.saveOrUpdate(baseIndDef.getIndId(), "0");
return "success;indId:"+baseIndDef.getIndId();
}
......
......@@ -35,6 +35,8 @@ public class DriveIndDefService {
private ShortboardDriveIndRelMapper shortboardDriveIndRelMapper;
@Autowired
private ShortboardRuleMapper shortboardRuleMapper;
@Autowired
private IndicatorsRelService indRelService;
public String saveOrUpdate(DriveIndDef driveIndDef,Integer catalogId,String catalogIdPath,
String user,String isUpdate,String shortboardIds)throws Exception{
......@@ -94,6 +96,8 @@ public class DriveIndDefService {
}
}
}
//保存或修改指标关系
indRelService.saveOrUpdate(driveIndDef.getIndId(), "1");
return "success;driveIndId:"+driveIndDef.getIndId();
}
......
package com.keymobile.indicators.service.hytobacco;
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;
......@@ -31,6 +33,93 @@ public class IndicatorsRelService {
@Autowired
private IndicatorsRelMapper indicatorsRelMapper;
//incluSelf:表示是否包含自己 0:否 1:是
//type:0 基础指标 1:考核指标
public Map<String,Object> getRelByIndId(String indId,String type,String incluSelf){
Map<String,Object> resultMap = new HashMap<>();
//先从库里找,找不到再分析公式然后保存进库里
List<IndicatorsRel> indRels = indicatorsRelMapper.findByIndId(indId);
if(indRels.isEmpty()) {
resultMap = this.getRelFromFormula(indId, type, incluSelf);
}else {
String formula = null;
String formulaDesc = null;
List<String> resultIndIdList = new ArrayList<>();
//根据类型查找指标
if("0".equals(type)) {//基础指标
BaseIndDef baseIndDef = baseIndDefMapper.selectByPrimaryKey(indId);
if(baseIndDef!=null) {
formula = baseIndDef.getIndFormat();
formulaDesc = baseIndDef.getIndFormatDesc();
}
}else {//考核指标
DriveIndDef driveIndDef = driveIndDefMapper.selectByPrimaryKey(indId);
if(driveIndDef!=null) {
formula = driveIndDef.getIndFormat();
formulaDesc = driveIndDef.getIndFormatDesc();
}
}
resultMap.put("formula", formula);
resultMap.put("formulaDesc", formulaDesc);
for(IndicatorsRel indRel : indRels) {
resultIndIdList.add(indRel.getRelIndId());
}
if("1".equals(incluSelf)) {
resultIndIdList.add(indId);
}
resultMap.put("indIdList",resultIndIdList);
}
return resultMap;
}
public Map<String,Object> getRelFromFormula(String indId,String type,String incluSelf){
String formula = null;
String formulaDesc = null;
List<String> resultIndIdList = new ArrayList<>();
Map<String,Object> resultMap = new HashMap<>();
resultMap.put("indIdList",new ArrayList<>());
resultMap.put("formula", formula);
resultMap.put("formulaDesc", formulaDesc);
//根据类型查找指标
if("0".equals(type)) {//基础指标
BaseIndDef baseIndDef = baseIndDefMapper.selectByPrimaryKey(indId);
if(baseIndDef!=null) {
formula = baseIndDef.getIndFormat();
formulaDesc = baseIndDef.getIndFormatDesc();
}
}else {//考核指标
DriveIndDef driveIndDef = driveIndDefMapper.selectByPrimaryKey(indId);
if(driveIndDef!=null) {
formula = driveIndDef.getIndFormat();
formulaDesc = driveIndDef.getIndFormatDesc();
}
}
//解析公式关系
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);
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;
}
//type:0 基础指标 1:考核指标
public void saveOrUpdate(String indId,String type) {
String formula = null;
......
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