MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » ,spring3 注解事务 回滚失败

,spring3 注解事务 回滚失败(2)

www.MyException.Cn  网友分享于:2013-02-21  浏览:470次

上面是我的spring配置文件
Java code

@Transactional(propagation=Propagation.REQUIRED)
    public boolean saveDoodToStorage(GoodsArrivalForm form, Pager pager, Model model)
            {
//        DefaultTransactionDefinition def = new DefaultTransactionDefinition(); 
//        TransactionStatus status = transactionManager.getTransaction(def); 

        /**
         * 
         *这块为零星入库,需要跟原有的系统的采购入库集成,下面分为几步
         * 
         *StorageListService 先创建入库单
         * 
         *然后是入库单细目 StorageListDetailService
         * 
         *接着是库存成本,就是记录库存中的每个商品的数量,价钱 GoodsCostService
         * 
         *然后创建商品细目,记录一些入库单号,出库单号之类的 GoodsDetailService
         * 
         *以上全部成功后,修改商品购买记录
         * 
         */
        boolean succ = false;
//        try {
            int goodsno = 0;
            // 入库的商品数量
            if(ObjectUtil.isNotEmpty(form.getGoodsno())){
                goodsno=form.getGoodsno();
            }else{
                if (ObjectUtil.isNotEmpty(form.getCode())) {
                    if (CollectionsUtil.notEmpty(form.getCode())) {
                        goodsno = form.getCode().length;
                    }

                }
            }
            
            
            if(goodsno<=0){
                return false;
            }
            
            
            GoodsRecord gr = null;// 商品购买记录
            if (ObjectUtil.isNotEmpty(form.getGrid())) {
                gr = grservice.find(form.getGrid());
            }
            if (ObjectUtil.isEmpty(gr)) {
                return false;
            }

            Storage storage = null;
            if (ObjectUtil.isNotEmpty(form.getStoid())) {
                storage = stoservice.find(form.getStoid());
            }
            if (ObjectUtil.isEmpty(storage)) {
                return false;
            }

            StorageList storageList = new StorageList();
            Date createDate = new Date();

            storageList.setCode(codeService.createNewCode(CODE));
            storageList.setCreateDate(createDate);
            storageList.setCreateUser(form.getUser().getChinaname());
            storageList.setAuditStatus(1);// 零星入库为已审核状态
            storageList.setAboutTicket(form.getGrid() == null ? "" : form
                    .getGrid().toString());// 相关单据号,这块为商品购买记录id
            storageList.setAboutTicketType(5);// 5为零星入库

            succ = slservice.saveOrUpdate(storageList);
            if (succ == false) {
                return false;
            }
//            throw new RuntimeException("aaaaaaa");
            List<StorageList> stolist = slservice.findByItem(storageList);

            if (ObjectUtil.isNotEmpty(stolist)) {
                if (stolist.size() > 0) {
                    StorageList newsto = stolist.get(0);

                    /**
                     * 如果报销单保存成功,接下来为保存报销单细目
                     */
                    StorageListDetail stoderail = new StorageListDetail();
                    stoderail.setStorageList(newsto);
                    stoderail.setGoods(gr.getGoodsId());
                    stoderail.setGoodsNo(Float.valueOf(goodsno));
                    stoderail.setCost(gr.getPrice());
                    stoderail.setCreateDate(createDate);
                    stoderail.setStorageCode(storage.getCode());
                    stoderail.setGoodsUnitId(1);
                    succ = sldeservice.saveOrUpdate(stoderail);

                    if (succ == false) {
                        return false;
                    }

                    /**
                     * 下面为保存具体的每个商品的入库条码信息 也就是商品细目
                     */

                    for (int i = 0; i < goodsno; i++) {

                        GoodsDetail gd = new GoodsDetail();
                        gd.setCode("100010");
                        gd.setGoodsId(gr.getGoodsId().getId());
                        if(gr.getGoodsId().isEqualcode()==true){
                            gd.setGoodsCode(form.getCode()[0]);
                        }else{
                            gd.setGoodsCode(form.getCode()[i]);
                        }
                        
                        
                        gd.setStorage(storage);
                        gd.setEnterDate(createDate);
                        gd.setStatus(1);// 因为是零星入库,直接就是在库状态,跳过审核
                        gd.setStorageInCode(newsto.getCode());

                        succ = gdservice.saveOrUpdate(gd);
                        if (succ == false) {
                            return false;
                        }
                    }

                    /**
                     *接下来为保存库存成本
                     * 
                     *这块有待商榷,是否需要下次入库的时候,是修改原来的数据,还是新添加数据
                     */
                    GoodsCost goodscost = new GoodsCost();
                    goodscost.setGoods(gr.getGoodsId());
                    goodscost.setStorage(storage);
                    goodscost.setStockNo(gr.getNum().floatValue());// 采购数量
                    goodscost.setStorageNo(Float.valueOf(goodsno));// 库存数量
                    goodscost.setNo(Float.valueOf(goodsno));
                    goodscost.setTotalMoney(gr.getPrice() * goodsno);
                    succ = goodscostservice.saveOrUpdate(goodscost);
                    if (succ == false) {
                        return false;
                    }

                    /**
                     * 需要保存的数据全部成功后,修改商品购买记录的入库信息
                     */

                    Integer goodsnum = gr.getNum();
                    Integer no = goodsno + gr.getInstoreNum();// 已入库数量加上这次入库的数量

                    if (no < goodsnum) {
                        /**
                         * 如果已入库数量加上这次入库的数量,小于总体的采购数量 则状态为部分入库
                         */
                        gr.setInstoreStatus(2);

                    } else {

                        gr.setInstoreStatus(3);
                    }
                    gr.setInstoreNum(no);

                    succ = grservice.saveOrUpdate(gr);
                    if (succ == false) {
                        return false;
                    }
                }

            }

             
            throw new RuntimeException("aaaaaaa");
//        } catch (Exception e) {
//            // TODO: handle exception
//            throw e;
//        }

        // return succ;
    }

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有