首页 > 代码库 > 类和方法上加事务

类和方法上加事务

package com.yundaex.wms.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Component
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class })
public class TestAop {
    
    
    @Autowired
    private JdbcTemplate jdbcTemplate;

  
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public void test() {
        String sql = " select count(1) from riv_inbound_notice_h where inh_owner_no = ‘425-1‘ ";
        System.out.println(+jdbcTemplate.queryForObject(sql, Integer.class));
    }
    
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class })
    public void addData(IWMSC_Order_inboundData  param){
        IWMSC_Order_in_headerData header = param.getHeader();
        List<IWMSC_Order_in_itemData> items = param.getItems();
        if (header==null||!CommonMethodHelper.isCollectionValid(items)) {
            YDAssert.isErrData("入库通知单单头或明细为空");
        }
        
        WMSC_busi_inboundPO inh = new WMSC_busi_inboundPO();
        List<WMSC_busi_inbound_planPO> inls = new ArrayList<WMSC_busi_inbound_planPO>();
        List<WMSC_stock_matPO> stock_matPOs = new ArrayList<WMSC_stock_matPO>();
        // 业务单流水号
        String doc_id = SerialNumberUtil.getWholeSerialNumber(WMSCConstant.C_ORDER_IN);
        Timestamp d = new Timestamp(System.currentTimeMillis()); 
        
        
        getInboundPO(doc_id,d,header,inh);
        getPlanPOs(doc_id,d,header,items,inls,stock_matPOs);
        
        //保存数据
        save(inh,inls,stock_matPOs);
        
    }
}
 

 

类和方法上加事务