public R startProcess(@RequestBody ShouldCredentialPayable bean) { System.out.println("应付贷项参数bean========="+bean); //开启审批流程之前先验证库存 boolean judge=false; if(null!=bean.getCredentialPayableDetail() && bean.getCredentialPayableDetail().size()>0){ List<SapVerifyInventory> sapList=new ArrayList<SapVerifyInventory>(); //对明细根据来源编号进行分组 Map<Long,List<ShouldCredentialPayableDetail>>map=grouping(bean.getCredentialPayableDetail()); //如果map不为空 if(!map.isEmpty()){ //获取map所有key 和value Iterator it = map.entrySet().iterator(); while(it.hasNext()){ Map.Entry entry =(Map.Entry )it.next(); Long key=(Long)entry.getKey(); System.out.println("key=============="+key); //获取key值 List<ShouldCredentialPayableDetail>listValue=(List)entry.getValue(); System.out.println("list=============="+listValue); //根据company,baseID查询库存 String company=bean.getCompany(); Long baseID=key; String url= MessageFormat.format(SapConstant.PURCHASECREDIT_DETAIL_STOCK+"?Company={0}&BaseID={1}",company,baseID); //System.out.println("url========================"+url); String result=HttpUtil.doGet(url,SapUtil.getReadToken()); SapReturnResult sapReturnResult=JSONObject.parseObject(result, SapReturnResult.class); System.out.println("sapReturnResult================="+sapReturnResult); String datas=sapReturnResult.getData(); System.out.println("datas================="+datas); //将data数据转换成 SapVerifyInventory List<SapVerifyInventory> list2=JSONObject.parseArray(datas,SapVerifyInventory.class); //比较提交的库存和sap现有的库存 if(null!=list2 && list2.size()>0 && null!=listValue && listValue.size()>0){ for(SapVerifyInventory sapVerifyInventory :list2){ for (ShouldCredentialPayableDetail shouldCredentialPayableDetail : listValue){ //当来源编号相同,仓库相同,物料编号相同时 比较库存 if(sapVerifyInventory.getItemCode().equals(shouldCredentialPayableDetail.getItemCode()) && sapVerifyInventory.getBaseEntry().longValue()==shouldCredentialPayableDetail.getSourceCode().longValue() && sapVerifyInventory.getWhsCode().equals(shouldCredentialPayableDetail.getWhsCode())){ System.out.println("开始判断》》》》》》》》》》》》》》》》》》》》》》》》》》》2222222222"); System.out.println(sapVerifyInventory.getItemCode().equals(shouldCredentialPayableDetail.getItemCode()) && sapVerifyInventory.getBaseEntry()==shouldCredentialPayableDetail.getSourceCode() && sapVerifyInventory.getWhsCode().equals(shouldCredentialPayableDetail.getWhsCode())); //Double 值比较大小 BigDecimal outValue = new BigDecimal(sapVerifyInventory.getQuantity()); BigDecimal inValue = new BigDecimal(shouldCredentialPayableDetail.getQuantity()); System.out.println("outValue======"+outValue+"---inValue====="+inValue+"---(outValue.compareTo(inValue)===="+outValue.compareTo(inValue)); //如果库存小于 提交的数量 if(outValue.compareTo(inValue)<0){ System.out.println("库存小于提交的数量>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); sapList.add(sapVerifyInventory); judge=true; } } } } } } } //数量和库存不一致 if(judge){ return R.data(sapList); } } return R.data("在测试"); //return R.status(shouldCredentialPayableService.startProcess(bean)); } //根据来源编号对明细进行分组 public Map<Long,List<ShouldCredentialPayableDetail>> grouping(List<ShouldCredentialPayableDetail> list){ Map<Long,List<ShouldCredentialPayableDetail>> map=new HashMap<Long,List<ShouldCredentialPayableDetail>>(); if(null!=list && list.size()>0){ for (ShouldCredentialPayableDetail shouldCredentialPayableDetail : list){ Long key=shouldCredentialPayableDetail.getSourceCode(); if(map.containsKey(key)){ map.get(key).add(shouldCredentialPayableDetail); }else{ //map中不存在以此id作为的key,新建key用来存放数据 List<ShouldCredentialPayableDetail> credentialPayableList=new ArrayList<ShouldCredentialPayableDetail>(); credentialPayableList.add(shouldCredentialPayableDetail); map.put(key,credentialPayableList); } } } return map; }