提交 592eac2e 编写于 作者: hebao@lab.ibiz5.com's avatar hebao@lab.ibiz5.com

cql数据支持删除无效result数据

上级 9616956e
......@@ -36,6 +36,9 @@ public class ExecResultRepository {
@Value("${ibiz.filterResultsData:false}")
private boolean filterResultsData;
@Value("${ibiz.deleteInvalidResultData:false}")
private boolean deleteInvalidResultData;
public ExecResultRepository(MappingManager mappingManager) {
createTable(mappingManager.getSession());
......@@ -110,22 +113,26 @@ public class ExecResultRepository {
this.saveResultsMQMsg2(resultsMQMsg);
return;
}
final ResultSet result = session.execute(select().all().from(TABLE2).where(in("ruleid",resultsMQMsg.getRules())).and(eq("keyvaluefield",resultsMQMsg.getKeyValueField())));
List<ExecResult2> list = mapper2.map(result).all();
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){}
if(deleteInvalidResultData) {
final ResultSet result = session.execute(select().all().from(TABLE2).where(in("ruleid", resultsMQMsg.getRules())).and(eq("keyvaluefield", resultsMQMsg.getKeyValueField())));
List<ExecResult2> list = mapper2.map(result).all();
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) {
}
}
}
List<ExecResult> results = resultsMQMsg.getDatas();
if(results != null && results.size() > 0){
......@@ -138,47 +145,49 @@ public class ExecResultRepository {
public void saveResultsMQMsg2(ResultsMQMsg resultsMQMsg){
log.info("--saveResultsMQMsg2--");
try {
final ResultSet result = session.execute(select().all().from(TABLE2).where(in("ruleid", resultsMQMsg.getRules())).and(eq("keyvaluefield", resultsMQMsg.getKeyValueField())));
List<ExecResult2> list = mapper2.map(result).all();
List<ExecResult> results = resultsMQMsg.getDatas();
//过滤需要删除的对象
if (results != null && results.size() > 0) {
for (ExecResult result1 : results) {
for (ExecResult2 result2 : list) {
if (result2.getRuleid().equals(result1.getRuleid()) && result2.getDimfield().equals(result1.getDimfield())
&& result2.getDomainsfield().equals(result1.getDomainsfield()) && result2.getKeyvaluefield().equals(result1.getKeyvaluefield())
&& result2.getTimefield().equals(result1.getTimefield())) {
list.remove(result2);
break;
if(deleteInvalidResultData) {
final ResultSet result = session.execute(select().all().from(TABLE2).where(in("ruleid", resultsMQMsg.getRules())).and(eq("keyvaluefield", resultsMQMsg.getKeyValueField())));
List<ExecResult2> list = mapper2.map(result).all();
//过滤需要删除的对象
if (results != null && results.size() > 0) {
for (ExecResult result1 : results) {
for (ExecResult2 result2 : list) {
if (result2.getRuleid().equals(result1.getRuleid()) && result2.getDimfield().equals(result1.getDimfield())
&& result2.getDomainsfield().equals(result1.getDomainsfield()) && result2.getKeyvaluefield().equals(result1.getKeyvaluefield())
&& result2.getTimefield().equals(result1.getTimefield())) {
list.remove(result2);
break;
}
}
}
}
}
//删除数据
PreparedStatement ps = this.getDeleteStatement();
PreparedStatement ps2 = this.getDeleteStatement2();
BatchStatement deleteBatch = new BatchStatement();
deleteBatch.setConsistencyLevel(ConsistencyLevel.ANY);// 设置一致性
BatchStatement deleteBatch2 = new BatchStatement();
deleteBatch2.setConsistencyLevel(ConsistencyLevel.ANY);// 设置一致性
for (ExecResult2 result2 : list) {
BoundStatement bs = ps.bind(result2.getRuleid(), 1, result2.getDimfield(), result2.getTimefield(), result2.getDomainsfield(), result2.getKeyvaluefield());
BoundStatement bs2 = ps2.bind(result2.getRuleid(), result2.getKeyvaluefield(), result2.getDimfield(), result2.getDomainsfield(), result2.getTimefield());
deleteBatch.add(bs);
deleteBatch2.add(bs2);
if ( deleteBatch.size() > batchSize) {
//删除数据
PreparedStatement ps = this.getDeleteStatement();
PreparedStatement ps2 = this.getDeleteStatement2();
BatchStatement deleteBatch = new BatchStatement();
deleteBatch.setConsistencyLevel(ConsistencyLevel.ANY);// 设置一致性
BatchStatement deleteBatch2 = new BatchStatement();
deleteBatch2.setConsistencyLevel(ConsistencyLevel.ANY);// 设置一致性
for (ExecResult2 result2 : list) {
BoundStatement bs = ps.bind(result2.getRuleid(), 1, result2.getDimfield(), result2.getTimefield(), result2.getDomainsfield(), result2.getKeyvaluefield());
BoundStatement bs2 = ps2.bind(result2.getRuleid(), result2.getKeyvaluefield(), result2.getDimfield(), result2.getDomainsfield(), result2.getTimefield());
deleteBatch.add(bs);
deleteBatch2.add(bs2);
if (deleteBatch.size() > batchSize) {
session.execute(deleteBatch);
deleteBatch.clear();
session.execute(deleteBatch2);
deleteBatch2.clear();
}
}
if (deleteBatch.size() > 0) {
session.execute(deleteBatch);
deleteBatch.clear();
session.execute(deleteBatch2);
deleteBatch2.clear();
}
}
if (deleteBatch.size() > 0) {
session.execute(deleteBatch);
deleteBatch.clear();
session.execute(deleteBatch2);
deleteBatch2.clear();
}
//保存数据
for (ExecResult execResult : results) {
save(execResult);
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册