指标库:衍生指标创建页面,输出查询
This commit is contained in:
parent
2aee4515b6
commit
bbcab977bd
@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 目标管控-指标
|
||||
@ -150,4 +151,11 @@ public class TargetController {
|
||||
String result = targetService.getListResult(params);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "衍生输出查询")
|
||||
@PostMapping("/getExpandResult")
|
||||
public R<List<Map<String, Object>>> getExpandResult(@RequestBody JSONObject params) {
|
||||
List<Map<String, Object>> result = targetService.getExpandResult(params);
|
||||
return R.ok(result);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import iet.ustb.sf.domain.Target;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hyy
|
||||
@ -40,4 +41,6 @@ public interface TargetService extends IService<Target> {
|
||||
JSONObject getTogethDetail(JSONObject params);
|
||||
|
||||
String getListResult(JSONObject params);
|
||||
|
||||
List<Map<String, Object>> getExpandResult(JSONObject params);
|
||||
}
|
||||
|
@ -652,6 +652,56 @@ public class TargetServiceImpl extends ServiceImpl<TargetMapper, Target>
|
||||
return String.valueOf(mbgkTargetData.getVal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getExpandResult(JSONObject params) {
|
||||
String id = params.getString("id");
|
||||
CheckUtils.checkEmpty(id, "指标ID");
|
||||
TargetOption expandOption = params.getObject("option", TargetOption.class);
|
||||
CheckUtils.checkSingleOption(expandOption);
|
||||
|
||||
List<Target> childTargetList = targetMapper.selectList(new QueryWrapper<Target>().eq("parent", id));
|
||||
if (!childTargetList.isEmpty()) {
|
||||
List<String> ids = childTargetList.stream().map(Target::getId).collect(Collectors.toList());
|
||||
QueryWrapper<TargetOption> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("column_name", expandOption.getColumnName());
|
||||
queryWrapper.in("target_id", ids);
|
||||
List<TargetOption> optionList = targetOptionMapper.selectList(queryWrapper);
|
||||
ThrowUtils.throwIf(!optionList.isEmpty(), ErrorCode.OPERATION_ERROR, "衍生条件已经在指标中了!");
|
||||
}
|
||||
|
||||
Target target = targetMapper.selectById(id);
|
||||
String[] strArr = utilService.getCurrentCycleDataByCycle(new Date(), target.getCycle());
|
||||
return SqlRunner.db().selectList(getExpandResultSql(
|
||||
target.getResultSql(), expandOption),
|
||||
strArr[3],
|
||||
strArr[4]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接衍生指标结果SQL
|
||||
*
|
||||
* @param sql 父指标结果SQL
|
||||
* @param expandOption 衍生字段
|
||||
* @return SQL结果
|
||||
*/
|
||||
private String getExpandResultSql(String sql, TargetOption expandOption) {
|
||||
sql = sql.substring(0, 7) + expandOption.getColumnName() + ", "
|
||||
+ sql.substring(7, sql.indexOf("FROM") - 7)
|
||||
+ sql.substring(sql.indexOf("CAST") + 5, sql.indexOf(" AS "))
|
||||
+ sql.substring(sql.indexOf("FROM") - 1);
|
||||
if (sql.contains("GROUP BY")) {
|
||||
sql = sql.substring(0, sql.indexOf("GROUP BY"))
|
||||
+ " AND " + getWhereSql(Collections.singletonList(expandOption))
|
||||
+ " " + sql.substring(sql.indexOf("GROUP BY"))
|
||||
+ "," + expandOption.getColumnName();
|
||||
} else {
|
||||
sql += " AND " + getWhereSql(Collections.singletonList(expandOption))
|
||||
+ " GROUP BY " + expandOption.getColumnName();
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指标变更后,修改对应的监控数据
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user