后台逻辑判断案例:选择列表是否是同一张卡

来源:互联网 发布:银河证券量化交易软件 编辑:程序博客网 时间:2024/06/05 05:16

条件:全部都不同 || 全部都相同(小组为单位)

1.new一个Set集合

HashSet set=new HashSet();

2.遍历集合,add到set中

for (int i = 0; i < list.size(); i++) {
 LmAcctChg lc=list.get(i);
         set.add(lc.getCustCardid());
    }

3.判断:set集合中数量!=1,表示集合中值至少有两个不一致;set集合中数量和list size不一致,表示list里面的卡号不相同

  if(set.size()!=1&&!(set.size()==list.size())){
context.put("flag", "failure");
context.put("lmSeq", "组内只要有任意成员用他人的银行卡还款");
throw new AsynException(errorMessage("failure","组内只要有任意成员用他人的银行卡还款,则该小组只能用一张卡!"));

   }

4.如果set.size()!=1,并且 客户id与选择的银行卡拥有者id不相等,就表示不符合条件

for (LmAcctChg lmAcctChg : list) {
      //如果新卡custid 为空,则取老卡custid
String ccid="".equals(lmAcctChg.getCardCustId())?lmAcctChg.getAcctCustId():lmAcctChg.getCardCustId();
if(!ccid.equals(lmAcctChg.getCustId())){
context.put("flag", "failure");
context.put("lmSeq", "银行卡选择错误");
//throw new Exception("组内只要有任意成员用他人的银行卡还款,则该小组只能用一张卡!");
throw new AsynException(errorMessage("failure","组内只要有任意成员用他人的银行卡还款,则该小组只能用一张卡!"));
    }
}