在NC开发中,经常需要通过IN语句查询数据,但是NC系统对IN子句的候选项有限制,最大只能1000个,所以考虑采用分段的方式来处理,以下是java的处理逻辑:
int loop = results.length/1000+1;
int rem = results.length%1000;
int n=0;
int count =0;
Map<String,RepDataQueryResultVO> map = new HashMap<String,RepDataQueryResultVO>();
for(int t1=0;t1<loop;t1++){
StringBuilder sb = new StringBuilder();
sb.append("select alone_id,uploadflag,uploadtime,uploadperson from IUFO_SF_RESULT where alone_id in ('");
if(loop>1&&t1<loop-1)
count = 1000;
else if(loop==1||t1==loop-1)
count = rem;
for(int t2=0;t2<count;t2++){
String alone_id = results[n].getAlone_id();
map.put(alone_id, results[n++]);
sb.append(alone_id).append("','");
}
sb.delete(sb.length()-2, sb.length()).append(")");
List<Object[]> data = helper.getRows(sb.toString());
for(Object[] objs : data){
String alone_id = (String) objs[0];
UFBoolean uploadflag = new UFBoolean((String)objs[1]);
UFDateTime uploadtime = new UFDateTime((String)objs[2]);
String uploadperson = (String) objs[3];
RepDataQueryResultVO vo = map.get(alone_id);
vo.setUploadflag(uploadflag);
vo.setUploadtime(uploadtime);
vo.setUploadperson(uploadperson);
}
}