遍历的同时,修改,list,有三种方法:1、用迭代器,2、普通的for循环(能获取到索引index确定元素位置的for)倒序或者3、普通for循环正序遍历。
程序代码:
//一次发放操作,不能发券总量过大 <10万 ,优惠券投放张数限制优化,需计算投放人数×张数 不能大于10万 :这里限制一次投放任务task的发券投放量
int sendCouponEach = 0;
// for (TCloudcrmCouponTaskRelate relate : task.getCouponTaskRelates()) {
for (int index=0 ;index<task.getCouponTaskRelates().size(); index++) {
TCloudcrmCouponTaskRelate relate=task.getCouponTaskRelates().get(index);
sendCouponEach = relate.getCouponNum().intValue()*openIds.size();
if(sendCouponEach> PropertiesConstants.COUPON_TOTAL_NUM.intValue()){
// throw new FuiouException(RspmsgConst.FAILE_CODE, "一次发放操作,发券总量>10万,请核实!");
LogWriter.info("TimeAutoCouponService.timeAutoCoupon step-7--> merchantCode:"+mchntCd+",sendRuleId:"+sendRule.getSendRuleId()+",taskId:"+sendRule.getTaskId()+"relate:"+JSON.toJSONString(relate)+"一次发放操作,单券发券总量>10万,请核实!");
// continue;
task.getCouponTaskRelates().remove(relate);
// 删除某个元素后,因为删除元素后,后面的元素都往前移动了一位
index--;
}
}
Iterator<SmsTemplatePtwyReq> iterator = promotersInfos.iterator();
// 条件筛选 ,移除不可用
while (iterator.hasNext()) {
SmsTemplatePtwyReq info = iterator.next();
if(StringUtil.isEmpty(info.getPhone())){
iterator.remove();
continue;
}