• 采购订单写入sap失败后,抛出自定义异常,回滚数据库


    @Transactional(rollbackFor = Exception.class)
    	@Override
    	public Map<String,Object> getOderInfo(String processInstanceId) {
    		Map<String,Object> map=new HashMap<String,Object>();
    		SapOrderAll sapOrderAll=new SapOrderAll();
    		SapProcessPurchaseOrder sapProcessPurchaseOrder=purchaseOrderMapper.getOderInfo(processInstanceId);
    		sapOrderAll.setMaster(sapProcessPurchaseOrder);
    		sapOrderAll.setCompany(sapProcessPurchaseOrder.getCompany());
    		System.out.println("processInstanceId======"+processInstanceId+"---------sapProcessPurchaseOrder========="+sapProcessPurchaseOrder);
    		if(null!=sapProcessPurchaseOrder){
    			String orderNumber=sapProcessPurchaseOrder.getOrderNumber();
    			//获取采购订单明细
    			List<SapProcessPurchaseOrderDetail>list=purchaseOrderDetailMapper.getSapOrderDetail(orderNumber);
    			sapOrderAll.setSlave(list);
    		}
    		//先修改采购申请单数据
    		if(null!=sapOrderAll && null!=sapOrderAll.getSlave()){
    			List<PurchaseRequestLine> purchaseRequestList=new ArrayList<PurchaseRequestLine>();
    			List<SapProcessPurchaseOrderDetail>listRequest= sapOrderAll.getSlave();
    			System.out.println("采购订单信息反馈给采购申请单listRequest================="+listRequest);
    			if(null!=listRequest && listRequest.size()>0){
    				for (SapProcessPurchaseOrderDetail OrderDetail :listRequest){
    					PurchaseRequestLine purchaseRequestLine=new PurchaseRequestLine();
    					//将数据封装成 采购申请单需要的类型
    					purchaseRequestLine.setId(OrderDetail.getRequestId());
    					purchaseRequestLine.setQuantity(new BigDecimal(OrderDetail.getQuantity()));
    					log.info("采购订单信息反馈给采购申请单purchaseRequestLine================="+purchaseRequestLine);
    					//将数据放入list中
    					purchaseRequestList.add(purchaseRequestLine);
    				}
    			}
    			//插入sapc成功后信息返回给 采购申请单
    			log.info("插入sapc成功后信息返回给purchaseRequestList================="+purchaseRequestList);
    			boolean msg=purchaseRequestLineService.updateQuantity(purchaseRequestList);
    			log.info("插入sapc成功后信息返回给 采购申请单msg========="+msg);
    			//判断反馈给采购申请单是否成功
    			if(!msg){
    				throw new RuntimeException("修改采购申请单失败");
    			}
    			//数据进入sap
    			if(msg){
    				String json=new JSONObject().toJSONString(sapOrderAll);
    				log.info("json================"+json);
    				String url = SapConstant.PURCHASEORDER_CREATE;
    				String itemStr = HttpUtil.doJsonPost(url,json, SapUtil.getReadToken());
    				log.info("itemStr====================="+itemStr);
    				map.put("itemStr",itemStr);//将sap返回信息放入map中
    				//字符串转json
    				SapReturnResult sapReturnResult = JSONObject.parseObject(itemStr,SapReturnResult.class);
    				log.info("map=================="+itemStr);
    				//map.get("data")中有值说明 插入sap成功
    				if(sapReturnResult.isSuccess()){
    					updateResult(true,sapOrderAll.getMaster().getOrderNumber(),"写入sap成功,修改采购订单数量成功",sapReturnResult.getData());
    				}else {
    					throw new RuntimeException("插入sap失败");
    				}
    			}
    		}else{
    			map.put("msg",false);
    			map.put("data","查询要写入sap的数据为空");
    			map.put("itemStr","");
    			return map;
    		}
    		map.put("msg",true);
    		map.put("data","写入sap成功");
    		map.put("itemStr","");
    		return map;
    	}
    
    /**
    	 * 根据执行结果判断插入采购订单是否成功
    	 */
    	public void updateResult(boolean mags,String orderNumber,String hint,String sapData){
    		log.info("根据执行结果判断插入采购订单是否成功mags====="+mags+"-----orderNumber========="+orderNumber+"--hint====="+hint);
    		//调用接口修改才有订单的状态值
    		if(mags){
    			//返回结果为true
    			purchaseOrderMapper.updateOderInfo("true"+hint,orderNumber,sapData);
    		}else {
    			//返回结果为false
    			purchaseOrderMapper.updateOderInfo("false"+hint,orderNumber,sapData);
    		}
    	}
    

      

  • 相关阅读:
    MySQL 第四天
    MySQL 第三天
    MySQL第二天
    MySQL第一天
    Day27-28 基础加强
    Day24-26 项目练习(图书商城)
    Day23 ajax
    Day22 文件上传下载和javaMail
    Day21 过滤器(Filter)
    小轮播图
  • 原文地址:https://www.cnblogs.com/xianz666/p/13744801.html
Copyright © 2020-2023  润新知