提交 a4344e8d 编写于 作者: xuhui961310148's avatar xuhui961310148

add:支持删除cql数据库构建结果

上级 dfb9fab1
......@@ -419,4 +419,49 @@ public class ExecResultRepository {
return insertStatement2;
}
/**
* 根据指标标识,业务数据主键,删除cql结果数据
* @param ruleids
* @param keyvaluefield
* @return
*/
public void deleteData(List<String> ruleids, String keyvaluefield){
final ResultSet result = session.execute(select().all().from(TABLE2).where(in("ruleid",ruleids)).and(eq("keyvaluefield",keyvaluefield)));
List<ExecResult2> list = mapper2.map(result).all();
if (list.size() > 0){
doDelete(list);
}
}
/**
* 删除数据
* @param list
*/
private void doDelete(List<ExecResult2> list){
for(ExecResult2 execResult2 : list) {
ExecResult execResult = new ExecResult();
execResult.setRuleid(execResult2.getRuleid());
execResult.setRetvalue(1);
execResult.setDimfield(execResult2.getDimfield());
execResult.setTimefield(execResult2.getTimefield());
execResult.setDomainsfield(execResult2.getDomainsfield());
execResult.setKeyvaluefield(execResult2.getKeyvaluefield());
try{
mapper.delete(execResult);
}catch(Exception ex){}
try{
mapper2.delete(execResult2);
}catch(Exception ex){}
}
}
/**
* 根据指标标识,删除结果数据
* @param ruleids
* @return
*/
public void deleteData(List<String> ruleids){
session.execute(delete().all().from(TABLE).where(in("ruleid",ruleids)).and(eq("retvalue",1)));
}
}
package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.analysis.domain.DAMetric;
import cn.ibizlab.core.analysis.domain.DAReport;
import cn.ibizlab.core.analysis.service.impl.DAReportServiceImpl;
import cn.ibizlab.core.extensions.cql.ExecResult;
import cn.ibizlab.core.extensions.cql.ExecResultRepository;
import cn.ibizlab.core.extensions.domain.FetchMetricDatasParam;
import cn.ibizlab.core.extensions.service.DACoreService;
import cn.ibizlab.core.extensions.service.DAMetricExService;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.DataObject;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
......@@ -34,6 +42,16 @@ public class DACoreResource {
@Autowired
private DAReportServiceImpl daReportService;
@Autowired
@Lazy
private ExecResultRepository execResultRepository;
@Autowired
@Lazy
private DAMetricExService daMetricExService;
// 删除cql结果批次大小
@Value("${ibiz.execresult.deletesize: 20}")
private int deletesize;
/**
* 通过指标获取相应的规则结果数据
* @param param
......@@ -159,4 +177,89 @@ public class DACoreResource {
this.fetchReportDatas(param);
return resultMap;
}
/**
* 删除cql库中结果数据
* @param param
* @return
*/
@PostMapping(value="/dst/analyse/reportdata/deleteexecresult")
public ResponseEntity<JSONObject> deleteRuleResultData(@RequestBody JSONObject param){
long t1 = DataObject.getNow().getTime();
JSONObject jsonObject = new JSONObject();
try{
String type = param.getString("type");
if (StringUtils.isEmpty(type)){
jsonObject.put("success",false);
jsonObject.put("message","未指定清除类型!");
return ResponseEntity.ok().body(jsonObject);
}
JSONArray list = param.getJSONArray("list");
if ("datakey".equalsIgnoreCase(type)){
JSONArray buildArray = param.getJSONArray("build");
if (StringUtils.isEmpty(list) || list.size() == 0 || StringUtils.isEmpty(buildArray) || buildArray.size() == 0){
jsonObject.put("success",false);
jsonObject.put("message","业务数据主键集合或者构建主键集合为空!");
return ResponseEntity.ok().body(jsonObject);
}
// 获取所有构建分析数据对应的指标标识
List<String> ruleids = new ArrayList<>();
for (int i = 0; i < buildArray.size(); i++) {
List<DAMetric> daMetricList = daMetricExService.list(Wrappers.<DAMetric>lambdaQuery().eq(DAMetric::getBuildId, buildArray.getString(i)));
for (DAMetric daMetric : daMetricList) {
ruleids.add(daMetric.getMetricId());
}
}
if (ruleids.size() == 0){
jsonObject.put("success",false);
jsonObject.put("message","未获取到指定构建对应的指标标识!");
return ResponseEntity.ok().body(jsonObject);
}
List<String> tempList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
for (String rule : ruleids) {
tempList.add(rule);
if (tempList.size() >= deletesize){
long start = DataObject.getNow().getTime();
execResultRepository.deleteData(tempList, list.getString(i));
log.info("根据指标标识:" + tempList + ",业务数据主键:" + list.getString(i) + ",删除cql结果,耗时:" + (DataObject.getNow().getTime()-start) + "毫秒");
tempList.clear();
}
}
if (tempList.size() > 0){
long start = DataObject.getNow().getTime();
execResultRepository.deleteData(tempList, list.getString(i));
log.info("根据指标标识:" + tempList + ",业务数据主键:" + list.getString(i) + ",删除cql结果,耗时:" + (DataObject.getNow().getTime()-start) + "毫秒");
tempList.clear();
}
}
jsonObject.put("success",true);
jsonObject.put("message","清除结果数据完成!");
}else if ("rule".equalsIgnoreCase(type)){
if (StringUtils.isEmpty(list) || list.size() == 0){
jsonObject.put("success",false);
jsonObject.put("message","指标标识集合为空!");
return ResponseEntity.ok().body(jsonObject);
}
List<String> tempList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
tempList.add(list.getString(i));
}
long start = DataObject.getNow().getTime();
execResultRepository.deleteData(tempList);
log.info("根据指标标识:" + list + ",删除cql结果成功,耗时:" + (DataObject.getNow().getTime()-start) + "毫秒");
jsonObject.put("success",true);
jsonObject.put("message","清除结果数据完成!");
}
}catch (Exception e){
e.printStackTrace();
jsonObject.put("success",false);
jsonObject.put("message","清除结果数据失败!原因:" + e.getMessage());
}
String cost = (DataObject.getNow().getTime() - t1) + "毫秒";
jsonObject.put("cost", cost);
log.info("删除cql结果数据执行完成,耗时:" + cost);
return ResponseEntity.ok().body(jsonObject);
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册