本文主要是介绍保存校验,根据表体String和UFDouble的两个字段,判断哪些记录重复,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
方法一 :保存校验,根据业务类型和税率判断哪些记录重复(不推荐)
import org.apache.commons.collections.CollectionUtils;private void ywlxAndSlCheck(List<JsdtbBVO> bvolist) throws BusinessException {bvolist = translateBodyVO(bvolist);JsdtbBVO[] bvos = bvolist.toArray(new JsdtbBVO[0]);if(bvos != null && bvos.length > 0){Map<String, List<UFDouble>> map = new HashMap<String, List<UFDouble>>();//往map中存值,往list中存值for(int i = 0; i < bvos.length; i++){String ywlx = NullValueUtils.getNullStringValue(bvos[i].getYwlx());UFDouble taxrate = NullValueUtils.getNullUFdoubleValue((bvos[i].getTaxrate()));if(map.containsKey(ywlx)){List<UFDouble> list = map.get(ywlx);list.add(taxrate);map.put(ywlx, list);}else{List<UFDouble> list = new ArrayList<>();list.add(taxrate);map.put(ywlx, list);}}StringBuilder sb = new StringBuilder();for(String ywlx : map.keySet()){if(map.containsKey(ywlx)){List<UFDouble> list = map.get(ywlx);//list去重Set<UFDouble> set = new HashSet<>(list);//获取重复元素集合Collection<UFDouble> rs = CollectionUtils.disjunction(list, set);//newList为重复元素集合List<UFDouble> newList = new ArrayList<>(rs); if(newList!=null && newList.size()>0){sb.append("业务类型为:");sb.append(ywlx);sb.append(",税率为:");for (UFDouble str : newList) {sb.append(str).append(",");}sb.delete(sb.length() - 1, sb.length());sb.append(";");}}}if(sb!=null&&sb.length()>0){throw new BusinessException(sb+ "表体重复,请检查!");}}}private List<JsdtbBVO> translateBodyVO(List<JsdtbBVO> bvolist) {SuperVOUtil.execFormulaWithVOs((SuperVO[]) bvolist.toArray(new JsdtbBVO[0]),new String[] {//业务类型"ywlx->getcolvalue2(bd_defdoc,name,pk_defdoclist,getcolvalue(bd_defdoclist,pk_defdoclist,code,\"ZK_0001\"),pk_defdoc,ywlx)"});return bvolist;}
方法二 :保存校验,根据业务类型和税率判断哪些记录重复(推荐)
//表体业务类型+税率不重复private void ywlxAndSlCheck(List<JsdtbBVO> bvolist) throws BusinessException {bvolist = translateBodyVO(bvolist);JsdtbBVO[] bvos = bvolist.toArray(new JsdtbBVO[0]);if(bvos != null && bvos.length > 0){List<String> ywlxList = new ArrayList<String>();List<UFDouble> taxrateList = new ArrayList<UFDouble>();StringBuilder sb = new StringBuilder();//往map中存值,往list中存值for(int i = 0; i < bvos.length; i++){String ywlx = NullValueUtils.getNullStringValue(bvos[i].getYwlx());UFDouble taxrate = NullValueUtils.getNullUFdoubleValue((bvos[i].getTaxrate()));String rowno = NullValueUtils.getNullStringValue(bvos[i].getRowno().substring(0, bvos[i].getRowno().length()-1));String classify = NullValueUtils.getNullStringValue(bvos[i].getClassify());if(ywlxList.contains(ywlx) && taxrateList.contains(taxrate)){sb.append("行号为:").append(rowno);sb.append(",业务类型为:").append(ywlx);sb.append(",分类为:").append(classify);sb.append(",税率为:").append(taxrate);sb.append(";");}ywlxList.add(ywlx);taxrateList.add(taxrate);}if(sb != null && sb.length() > 0){throw new BusinessException(sb+ "表体重复,请检查!");}}}private List<JsdtbBVO> translateBodyVO(List<JsdtbBVO> bvolist) {SuperVOUtil.execFormulaWithVOs((SuperVO[]) bvolist.toArray(new JsdtbBVO[0]),new String[] {//业务类型"ywlx->getcolvalue2(bd_defdoc,name,pk_defdoclist,getcolvalue(bd_defdoclist,pk_defdoclist,code,\"ZK_0001\"),pk_defdoc,ywlx)"});return bvolist;}
方法三 :保存校验,根据业务类型和税率判断哪些记录重复(极力推荐)
//表体业务类型+税率不重复private void ywlxAndSlCheck(List<JsdtbBVO> bvolist) throws BusinessException {bvolist = translateBodyVO(bvolist);JsdtbBVO[] bvos = bvolist.toArray(new JsdtbBVO[0]);if(bvos != null && bvos.length > 0){Map<String, Map<String,List<String>> >map = new HashMap<String, Map<String,List<String>>>();for(int i = 0; i < bvos.length; i++){if(bvos[i].getYwlx() != null && !bvos[i].getYwlx().equals("")&&bvos[i].getTaxrate() != null){String rowno = NullValueUtils.getNullStringValue(i+1);String ywlx = NullValueUtils.getNullStringValue(bvos[i].getYwlx());String classify = NullValueUtils.getNullStringValue(bvos[i].getClassify());UFDouble taxrate = NullValueUtils.getNullUFdoubleValue(bvos[i].getTaxrate()).setScale(2, UFDouble.ROUND_HALF_UP);if(map.containsKey(ywlx+"@"+taxrate)){Map<String, List<String>> classifymap = map.get(ywlx+"@"+taxrate);List<String> list = classifymap.get(classify);list.add(rowno);classifymap.put(classify, list);map.put(ywlx+"@"+taxrate, classifymap);}else{Map<String, List<String>> classifymap = new HashMap<String,List<String>>();List<String> list = new ArrayList<>();list.add(rowno);classifymap.put(classify, list);map.put(ywlx+"@"+taxrate, classifymap);}}}StringBuilder sb = new StringBuilder();for (String ywlxTaxrate : map.keySet()) {Map<String, List<String>> classifymap = map.get(ywlxTaxrate);for(String classify : classifymap.keySet()){List<String> list = classifymap.get(classify);if(list != null && list.size() > 1){Collections.sort(list);//对list进行升序排序for (String str : list) {sb.append("第").append(str).append("行").append("和");}sb.delete(sb.length() - 1, sb.length());sb.append("的分类:").append(classify);int index = ywlxTaxrate.indexOf("@");sb.append(",业务类型:").append(ywlxTaxrate.substring(0,index));sb.append(",税率:").append(ywlxTaxrate.substring(index+1,ywlxTaxrate.length()));sb.append("重复;");}}}if(sb != null && sb.length() > 0){sb.delete(sb.length() - 3, sb.length());throw new BusinessException(sb+"重复,不允许保存,请检查!");}}}private List<JsdtbBVO> translateBodyVO(List<JsdtbBVO> bvolist) {SuperVOUtil.execFormulaWithVOs((SuperVO[]) bvolist.toArray(new JsdtbBVO[0]),new String[] {//业务类型"ywlx->getcolvalue2(bd_defdoc,name,pk_defdoclist,getcolvalue(bd_defdoclist,pk_defdoclist,code,\"ZK_0001\"),pk_defdoc,ywlx)"});return bvolist;}
这篇关于保存校验,根据表体String和UFDouble的两个字段,判断哪些记录重复的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!