总业务方法(saveOrderUtil),直接被controller调用,saveOrderUtil在调用第一个业务(interceptororder)对订单状态进行修改,在第二个业务方法中(orerpoint)中写了一个错误的sql(select from orders where)异常后没有回滚
- Java code
@Override @Transactional(rollbackFor=Exception.class,propagation=Propagation.REQUIRED) public void saveOrderUtil(Orders orders, Member member,boolean ismembermoney, double membermoney,boolean type) throws Exception { if(IConstants.IsNotEmpty(orders) && IConstants.IsNotEmpty(member)){ //拦截订单 interceptorOrder(orders, member); //送积分 orderPoint(orders.getOrders_code(),member); //送优惠券 orderEtick(String.valueOf(orders.getOrders_ticketid()), member); if(ismembermoney){ //余额支付 memberBuy(member, membermoney); } if(type){ //非货到付款修改订单状支付态为已付款 dao.updateBySql("update orders set orders_statustype=1 where orders_code='"+orders.getOrders_code()+"'"); } //订单解锁 dao.updateBySql("update orders set lock_status=0 where orders_code='"+orders.getOrders_code()+"'"); } }/* (non-Javadoc) * @see com.cfuture.ysj.web.service.ICommonService#orderPoint(java.lang.String, com.cfuture.ysj.web.vo.users.Member) */ @Override @Transactional(rollbackFor=Exception.class,propagation=Propagation.REQUIRED) public void orderPoint(String orders_code, Member member) throws Exception { ArrayList<String> kunCunSqls = new ArrayList<String>(); //是否购物送积分 int point=orderService.getpointratiopoint(member); if(point>0){ //订单信息 Orders orders=dao.queryBySql(Orders.class,"select from orders where orders_code='"+orders_code+"'",null); point+=orders.getOrders_point(); if(orders.getOrders_point()>0){ //修改用户积分 dao.updateBySql("update member set member_consumepoint="+point+" where member_id="+member.getMember_id()+""); String res=WebServicesCall.initServices("addpoint",new Object[]{"ecmemberid","point","note"},new Object[]{member.getMember_id(),point,"订单商品积分"}); if(null==res||(null!=res&&"-1".equals(res.split(IConstants.REMOTE_SPLIT)[0]))){ throw new Exception("订单积分异常"); } // 记录积分流水 saveMemberLevelGride(member,res.split(IConstants.REMOTE_SPLIT)[1],point,IConstants.sdf.format(new Date()),"购物积分"); } } //修改商品程控信息 kunCunSqls.add("update merchandiseprog set createordercount=createordercount+1 where merchandise_code in (select ordermerchandise_merchandisecode from ordermerchandise where orders_code='"+orders_code+"')"); //修改库存 List<OrderMerchandise> orderMerchandises=dao.queryListByCond(OrderMerchandise.class,"select * from ordermerchandise where orders_code='"+orders_code+"'"); for (OrderMerchandise om : orderMerchandises) { kunCunSqls.add("update storestock set stock=stock-"+om.getOrdermerchandise_count()+" where dcNo='"+om.getMer_store()+"' and concat(mer_code,'_',mer_spec1,'_',mer_spec2)='"+om.getOrdermerchandise_sku()+"'"); } dao.patchUpdateOrDelete(kunCunSqls.toArray(new String[]{})); }@Override @Transactional(rollbackFor=Exception.class,propagation=Propagation.REQUIRED) public void orderEtick(String etick_id, Member member) throws Exception { //是否开启购物送券 GlobalProperty gvo=dao.queryBySql(GlobalProperty.class,"select * from globalproperty where property_id=13",null); if(gvo!=null&&"1".equals(gvo.getProperty_value())){ String time=CommonUtils.formatDate(new Date(),2); // 查询一张券 Eticket evo=dao.queryByCond(Eticket.class,null,null, "eticket_gettype=2 and eticket_status1=2 and eticket_status2=1 and eticket_faileddate > '" +time+"'"," order by eticket_id LIMIT 0,1"); if(evo!=null){ evo.setEticket_status1(Short.valueOf("3")); dao.updateById(evo,"eticket_id"); TicketUse tvo=new TicketUse(); tvo.setTicketuse_happentime(time); tvo.setTicketuse_memberid(member.getMember_id()); tvo.setTicketuse_ticketid(evo.getEticketpatch_code()); tvo.setTicketuse_ticketcode(evo.getEticket_code()); tvo.setTicketuse_happentype(Short.valueOf("1")); tvo.setTicketuse_membername(member.getMember_email()); tvo.setTicketuse_tickettype(evo.getEticket_gettype()); tvo.setTicketuse_mz(evo.getEticket_mz()); tvo.setTicketuse_moneycond(evo.getEticket_moneycond()); tvo.setTicketuse_ticketovertime(evo.getEticket_faileddate()); tvo.setTicketuse_ticketstatus2(evo.getEticket_status2()); dao.insertSingle(tvo); } } }/* (non-Javadoc) * @see com.cfuture.ysj.web.service.ICommonService#interceptorOrder(com.cfuture.ysj.web.vo.payment.Orders) */ @Override @Transactional(rollbackFor=Exception.class,propagation=Propagation.REQUIRED) public void interceptorOrder(Orders orders,Member member) throws Exception { //查询所有已开启订单拦截条件 List<GlobalProperty> list=findProperty("property_group=11 and property_value=1"); Map<String,GlobalProperty> map=new HashMap<String, GlobalProperty>(); for (GlobalProperty p : list) { map.put(p.getProperty_key(),p); } if(IConstants.IsNotEmpty(orders) && map.size()>0 && IConstants.IsNotEmpty(member)){ //订单收货人信息 OrderReceive orderReceive=dao.queryBySql(OrderReceive.class,"select * from orderreceive where orders_code='"+orders.getOrders_code()+"'", null); //订单支付方式 OrderPayInfo orderPayInfo=dao.queryBySql(OrderPayInfo.class,"select * from orderpayinfo where orderpayinfo_payid=4",null); if(IConstants.IsNotEmpty(orderReceive) ){ String mark=""; if(!checkIp(member.getMember_lastloginip(),orderReceive.getOrderreceive_provincename().concat(orderReceive.getOrderreceive_cityname())) && map.get(IConstants.MEMBER_ADDRESS)!=null){ mark+="登陆IP地址和配送IP地址不在一个区域"; } if(member.getMember_isorders()==0 && map.get("MEMBER_FIRSTBUY")!=null){ mark+=" 第一次购物"; } if(orderPayInfo!=null && map.get("CASHONDELIVERY")!=null){ mark+=" 货到付款订单"; } if(orders.getOrders_deliverycost().doubleValue()>0 && map.get("POSTAGE")!=null){ mark+=" 订单配送地在邮费付费区域1开启0关闭"; } String updatesql="update orders set intercept_status=1,orders_operamemo='"+mark+"' where orders_code='"+orders.getOrders_code()+"'"; //登陆IP与配送IP是否一至 if(!checkIp(member.getMember_lastloginip(),orderReceive.getOrderreceive_provincename().concat(orderReceive.getOrderreceive_cityname())) && map.get(IConstants.MEMBER_ADDRESS)!=null){ dao.updateBySql(updatesql); //是否第一次购物 }else if(member.getMember_isorders()==0 && map.get("MEMBER_FIRSTBUY")!=null){ dao.updateBySql(updatesql); //订单是否为货到付款 }else if(orderPayInfo!=null && map.get("CASHONDELIVERY")!=null){ dao.updateBySql(updatesql); //是否有运费 }else if(orders.getOrders_deliverycost().doubleValue()>0 && map.get("POSTAGE")!=null){ dao.updateBySql(updatesql); }else { //修改订单状态为已审核 已付款 dao.updateBySql("update orders set orders_status=3 where orders_code='"+orders.getOrders_code()+"'"); //同步订单 int call=(Integer)dao.callProcessStore("{call proc_orders(?,?)}",new Object[]{orders.getOrders_code()}); if(call==1){ // 调用订单状态同步 dao.callProcessStore("{call proc_order_status_write(?,?)}",new Object[]{orders.getOrders_code()}); } } } }else{ dao.updateBySql("update orders set intercept_status=1 where orders_code='"+orders.getOrders_code()+"'"); }/* (non-Javadoc) * @see com.cfuture.ysj.web.service.ICommonService#memberBuy(com.cfuture.ysj.web.vo.users.Member, double) */ @Override @Transactional(rollbackFor=Exception.class,propagation=Propagation.REQUIRED) public void memberBuy(Member member, double membermoney) throws Exception { String res=WebServicesCall.initServices("addvalue",new Object[]{"ecmemberid","value","note"},new Object[]{member.getMember_id(),-membermoney,"积点支付订单"}); if(null==res||"".equals(res)||(null!=res&&"-1".equals(res.split(IConstants.REMOTE_SPLIT)[0]))){ throw new Exception("余额支付异常"); } saveChargeDetail(member,String.valueOf(membermoney),String.valueOf(member.getMember_balance()),IConstants.sdf.format(new Date())); }以下是我写的测试方法,可以正常回滚/* (non-Javadoc) * @see com.cfuture.ysj.web.businesscard.services.IBusinesscardServices#trans1() */ @Override @Transactional(rollbackFor=Exception.class,propagation=Propagation.REQUIRED) public void trans1() throws Exception { dao.updateBySql("update orders set orders_status=20 where orers_code='1207922871200042'"); } /* (non-Javadoc) * @see com.cfuture.ysj.web.businesscard.services.IBusinesscardServices#trans2() */ @Override @Transactional(rollbackFor=Exception.class,propagation=Propagation.REQUIRED) public void trans2() { dao.query("select from member"); } /* (non-Javadoc) * @see com.cfuture.ysj.web.businesscard.services.IBusinesscardServices#transmain() */ @Override @Transactional(rollbackFor=Exception.class,propagation=Propagation.REQUIRED) public void transmain() throws Exception { trans1(); trans2(); }