IBATIS 저장 프로세스 쓰기

24158 단어 ibatis
코드!!!!
/**
     *         ,      
     * @param customerOrderInputDTO
     * @return
     * @throws BizServiceException
     */
    public CustomerOrderInputRspDTO orderInput(CustomerOrderInputDTO customerOrderInputDTO) throws BizServiceException{
        CustomerOrderInputRspDTO customerOrderInputRspDTO = new CustomerOrderInputRspDTO();
        Map map = new HashMap();
        setParameterMapInput(map,customerOrderInputDTO);	
        Integer orderType = customerOrderInputDTO.getCustomerOrderDTO().getOrderType();
        if(orderType==null){
        	throw new BizServiceException("orderType is null");
        }
        Long startTime = System.currentTimeMillis();
        /**
         *        
         	BO       :
			productDTOs
			productDTO:cardLayouts/packages(  packageFee)/replaceFee/validityPeriod
			custContractDTO:annualFee/deliveryFee/cardFee
			customerDTO:invoiceAddressList/invoiceCompanyList/deliveryPointList/deliveryPoint.recipientList/name/id
			deliveryRecipientDTOs
			orderDate/sales	
			cardValidityPeriod
			        currDate/sales
			        ->    ,            ,          
			    :    、        、        
         */
        if(orderType.equals(1)){
        	customerOrderDAO.queryForObject("RLOrderInput",map);
        }
        /**
    	 *         
    	 * BO       :
    		productDTOs
    		productDTO.accTypes/cardValidityPeriod
    		custAcctypeContractDTO.serviceFee
    		customerDTO:invoiceAddressList/invoiceCompanyList/name/id
    		orderDate/sales
    	  	        currDate/sales
    	  	           ->    ,            ,          
    		    :    、        、        、    
    	 */
        if(orderType.equals(2)){
        	customerOrderDAO.queryForObject("CROrderInput",map);
        }
        /**
    	 *              ,      
    	 * BO      :
    		productDTOs
    		productDTO:accTypes/cardLayouts/prodFaceValues
    		cardValidityPeriod
    		orderDate
    		    ->    ,      
    		    :        、         
    	 */
        if(orderType.equals(3)){
        	customerOrderDAO.queryForObject("GSTOrderInput",map);
        }
        /**
    	 *              ,      
    	 * BO      :
    		productDTOs
    		productDTO.accTypes
    		custContractDTO:deliveryFee
    		customerDTO:invoiceAddressList/invoiceCompanyList/deliveryPointList/deliveryPoint.recipientList/name/id
    		orderDate/sales
    	   	        currDate/sales
    	   	        ->    ,            ,          
    		    :    、        、        
    	 */
        if(orderType.equals(4)){
        	customerOrderDAO.queryForObject("GSLOrderInput",map);
        }
        
     	System.out.println("================= cost time  "+(System.currentTimeMillis() - startTime)+"/1000  seconds");
     	parseParameterMapResult(map, customerOrderInputRspDTO,customerOrderInputDTO);
    	return customerOrderInputRspDTO;
    }
/**
     *     ,        ,     parameterMap
     * @param map
     * @param customerOrderInputDTO
     * @throws BizServiceException
     */
    private void setParameterMapInput(Map map,CustomerOrderInputDTO customerOrderInputDTO) throws BizServiceException{
    	CustomerOrderDTO customerOrderDTO = customerOrderInputDTO.getCustomerOrderDTO();
    	Long productId = customerOrderDTO.getProductId();
        Short acctypeId = customerOrderDTO.getAccTypeId();
        Long customerId = customerOrderDTO.getCustomerId();
        Integer orderType = customerOrderDTO.getOrderType();
        Long orderId = customerOrderDTO.getOrderId();
        productId = (productId==null)?-1l:productId;
        customerId = (customerId==null)?-1l:customerId;
        acctypeId = (acctypeId==null)?(short)-1:acctypeId;
        orderId = (orderId==null)?-1l:orderId;
    	map.put("i_issuerId", customerOrderInputDTO.getDefaultIssuerId());
     	map.put("i_issuerGroupId", customerOrderInputDTO.getDefaultIssuerGroupId());
     	map.put("i_orderType", orderType);
     	map.put("i_customerId",customerId);
     	map.put("i_productId", productId);
     	map.put("i_accTypeId", acctypeId);
     	map.put("i_orderId", orderId);
    }
    /**
     *     ,        ,       , MAP  DTO
     * @param map
     * @param customerOrderInputRspDTO
     * @throws BizServiceException
     */
    @SuppressWarnings("unchecked")
	private void parseParameterMapResult(Map map,CustomerOrderInputRspDTO customerOrderInputRspDTO,CustomerOrderInputDTO customerOrderInputDTO) throws BizServiceException{
		try{
			CustomerDTO customerDTO = new CustomerDTO();
			customerDTO.setCustomerId(customerOrderInputDTO.getCustomerOrderDTO().getCustomerId());
			//        
			List users = (List) map.get("o_sales");
			List saleUserList = new ArrayList();
			if(users!=null){
				for (User user : users) {
					UserDTO dto = new UserDTO();
					ReflectionUtil.copyProperties(user, dto);
					saleUserList.add(dto);
				}
			}
			//      
			List currDates = (List) map.get("o_orderDate");
			Date currDate = null;
			if(currDates!=null&&currDates.size()>0&&currDates.get(0).get("currDate")!=null){
				currDate = new SimpleDateFormat("yyyyMMdd").parse(currDates.get(0).get("currDate").toString());
			}
			//      
			List products = (List) map.get("o_products");
			//    
			List products2 = (List) map.get("o_product");
			ProductDTO productDTO = new ProductDTO();
			if(products2!=null&&products2.size()>0){
				productDTO = products2.get(0);
			}
			//        ,          
			List deliveryPointDTOs = (List) map.get("o_deliveryPointList");
			if(deliveryPointDTOs!=null&&deliveryPointDTOs.size()>0){
				for(DeliveryPointDTO deliveryPointDTO:deliveryPointDTOs){
					String str = deliveryPointDTO.getRecipientsStr();//   "..id,name;.."
					if(str==null){
						break;
					}
					List deliveryRecipientDTOs = new ArrayList();
					for(String s:str.split(";")){
						if(s==null){
							break;
						}
						DeliveryRecipientDTO deliveryRecipientDTO = new DeliveryRecipientDTO();
						deliveryRecipientDTO.setRecipientId(Long.parseLong(s.split(",")[0]));
						deliveryRecipientDTO.setRecipient(s.split(",")[1]);
						deliveryRecipientDTOs.add(deliveryRecipientDTO);
					}
					deliveryPointDTO.setRecipientList(deliveryRecipientDTOs);
				}
			}
			customerDTO.setDeliveryPointList(deliveryPointDTOs);
			//                   
			List deliveryRecipientDTOs = new ArrayList();
			if(deliveryPointDTOs!=null&&deliveryPointDTOs.size()>0){
				DeliveryPointDTO deliveryPointDTO = deliveryPointDTOs.get(0);
				if(deliveryPointDTO!=null){
					deliveryRecipientDTOs = deliveryPointDTO.getRecipientList();
				}
			}
			//        
			List invoiceAddressDTOs = (List) map.get("o_invoiceAddressList");
			customerDTO.setInvoiceAddressList(invoiceAddressDTOs);
			//        
			List invoiceCompanyDTOs = (List) map.get("o_invoiceCompanyList");
			customerDTO.setInvoiceCompanyList(invoiceCompanyDTOs);
			//         
			List accTypeDTOs = (List) map.get("o_accTypes");
			productDTO.setAccTypes(accTypeDTOs);
			//         
			List packageDTOs = (List) map.get("o_packages");
			productDTO.setPackages(packageDTOs);
			//      ,       
			List contractDTOs = (List) map.get("o_custContracts");
            CustContractDTO contractDTO = new CustContractDTO();
            if(contractDTOs!=null&&contractDTOs.size()>0){
            	contractDTO = contractDTOs.get(0);
            }
			//         
			List cardLayoutDTOs = (List) map.get("o_cardLayouts");
			productDTO.setCardLayouts(cardLayoutDTOs);
			//         
			List prodFaceValueDTOs = (List) map.get("o_prodFaceValues");
			productDTO.setProdFaceValues(prodFaceValueDTOs);
			//      
			String customerName = (String)map.get("o_customerName");
			customerDTO.setCustomerName(customerName);
			//     (    )
			BigDecimal serviceFee = (BigDecimal) map.get("o_serviceFee");
			CustAcctypeContractDTO custAcctypeContractDTO = new CustAcctypeContractDTO();
			if(serviceFee!=null){
				custAcctypeContractDTO.setServiceFee(serviceFee);
			}
			
			CustomerOrderDTO customerOrderDTO = customerOrderInputDTO.getCustomerOrderDTO();
			if(map.get("o_customerOrder")!=null&&((List)map.get("o_customerOrder")).size()>0){
				ReflectionUtil.copyProperties((CustomerOrder)((List)map.get("o_customerOrder")).get(0), customerOrderDTO);
				customerOrderDTO.setCustomerName(customerName);
				if(map.get("o_productName")!=null){
					customerOrderDTO.setProductName(map.get("o_productName").toString());
				}
				if(map.get("o_issuerName")!=null){
					customerOrderDTO.setIssuerName(map.get("o_issuerName").toString());
				}
			}else{
				customerOrderDTO.setOrderDate(currDate);
				customerOrderDTO.setCustomerId(customerDTO.getCustomerId());
				customerOrderDTO.setCustomerName(customerName);
				customerOrderDTO.setProductId(productDTO.getProductId());
				Date cardValidityPeriod = null;
				if(productDTO.getValidityePeriod()!=null){
					cardValidityPeriod = DateUtil.countCardValidate(new Date(), productDTO.getValidityePeriod());
				}
	            customerOrderDTO.setCardValidityPeriod(cardValidityPeriod);
	            customerOrderDTO.setAccTypeId(custAcctypeContractDTO.getAccTypeId());
	            if(deliveryRecipientDTOs!=null&&deliveryRecipientDTOs.size()>0){
	            	customerOrderDTO.setOrderContact(deliveryRecipientDTOs.get(0).getRecipientId());
	            }
			}
			customerOrderInputRspDTO.setSaleUserList(saleUserList);
			customerOrderInputRspDTO.setCustomerOrderDTO(customerOrderDTO);
			customerOrderInputRspDTO.setCustContractDTO(contractDTO);
			customerOrderInputRspDTO.setProductDTO(productDTO);
			customerOrderInputRspDTO.setProductDTOs(products);
			customerOrderInputRspDTO.setCustomerDTO(customerDTO);
			customerOrderInputRspDTO.setDeliveryRecipientDTOs(deliveryRecipientDTOs);
			customerOrderInputRspDTO.setCustAcctypeContractDTO(custAcctypeContractDTO);
		}catch(Exception e){
			e.printStackTrace();
			throw new BizServiceException("    ");
		}
    }

IBATIS XML 파일


 
	
	
		
	
	
		
		
		
		
	
	
		
		
	
	
		
		
		
	
	
		
		
	
	
		
		
		
	
	
		
		
		
	
	
		
		
		
		
	
	
		
		
	
	
		
		
	
	
	
	
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	
	
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	
	
	
		{call RLOrderInput(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}
	
	
		{call CROrderInput(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}
	
	
		{call GSTOrderInput(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}
	
	
		{call GSLOrderInput(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}
	
	
	
		{call RLOrderEdit(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}
	
	
		{call CROrderEdit(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}
	
	
		{call GSTOrderEdit(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}
	
	
		{call GSLOrderEdit(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}
	


ORACLE 저장 프로세스
create or replace procedure RLOrderInput(
       o_products out sys_refcursor,
       o_product out sys_refcursor,
       o_accTypes out sys_refcursor,
       o_cardLayouts out sys_refcursor,
       o_packages out sys_refcursor,
       o_prodFaceValues out sys_refcursor,
       o_custContracts out sys_refcursor,
       o_invoiceAddressList out sys_refcursor,
       o_invoiceCompanyList out sys_refcursor,
       o_deliveryPointList out sys_refcursor,
       o_orderDate out sys_refcursor,
       o_sales out sys_refcursor,
       o_customerName out varchar,
       o_serviceFee out number,
       i_orderType in number,
       i_customerId in number,
       i_productId in number,
       i_accTypeId in number,
       i_issuerId in number,
       i_issuerGroupId in number) 
as 
       productId number;
begin
  productId := -1;
    --     :     sales/orderDate,                   ,         
    --    :    、        、        

      if i_customerId!=-1 then--             
        begin
          getprodsbycustidandptype(o_products,i_customerId,1,1);
          getinvoicebycustid(o_invoiceAddressList,o_invoiceCompanyList,i_customerId,1);
          getdeliverybycustid(o_deliveryPointList,i_customerId,1);
          select t.customer_name into o_customerName from tb_ent_customer t where t.customer_id=i_customerId;
          
        end;
      end if;
      if i_customerId=-1 then--        
        begin
          getprodsbycustidandptype(o_products,i_customerId,1,0);
          getinvoicebycustid(o_invoiceAddressList,o_invoiceCompanyList,i_customerId,0);
          getdeliverybycustid(o_deliveryPointList,i_customerId,0);
        end;
      end if;
     if i_customerId!=-1 and i_productId=-1 then--                  
        begin
          select t2.product_id into productId 
                from tb_ent_cust_contract t1,tb_ent_product t2 
                where t1.product_id=t2.product_id and t1.customer_id=i_customerId and t2.product_type=1  
                and t2.data_state=1 and t1.data_state=1 and t2.prod_stat=1
                and nvl(t1.start_date,sysdate)<=sysdate and nvl(t1.end_date,sysdate)>=sysdate AND ROWNUM=1;
                
          EXCEPTION WHEN NO_DATA_FOUND THEN 
            NULL;
        end;
      end if; 
      if i_productId!=-1 then--                 
        begin
          productId := i_productId;
        end;
      end if;
      if productId!=-1 then--              
        begin
          getprodfororderinput(o_product,productId,1);
          getcardlayoutsbyprodid(o_cardLayouts,productId,1);
          getpackagesbyprodid(o_packages,productId,1);
          getvalidcustcontract(o_custcontracts,i_customerId,productId,1);
        end;
      end if;
      if productId=-1 then--              
        begin
          getprodfororderinput(o_product,productId,0);
          getcardlayoutsbyprodid(o_cardLayouts,productId,0);
          getpackagesbyprodid(o_packages,productId,0);
          getvalidcustcontract(o_custcontracts,i_customerId,productId,0);
        end;
      end if;
      getcurrdateandsales(o_orderDate,o_sales,i_issuerId,i_issuerGroupId,1);
    getacctypesbyprodid(o_accTypes,productId,0);
    getprodfacevaluesbyprodid(o_prodFaceValues,productId,0);
 
end RLOrderInput;

그중에 다른 저장 프로세스가 호출되었다
---------------------------------------------------------
참고::::::::::::::::::::
IBATIS 버전 2.3.4
DTO마다 RESULTMAP을 하나씩 쓰는데 어쩔 수 없어요. 안 해도 돼요. 다른 좋은 방법이 없어요.
MYIBATIS 설정 XML 파일이 더 편할 것 같습니다. 여기는 이럴 수밖에 없습니다.
저장 과정 중 OUT 커서 CURSOR는 전부 OPEN이어야 한다. 그렇지 않으면 JAVA가'CURSOR IS CLOSED...'
저장 프로세스는 이해하기 어렵고 유지 보수가 번거롭다. 장점은 빠르다는 것이다. 여기서 DAO를 사용하면 데이터베이스에 78번 접근할 수 있기 때문에 저장 프로세스는 방문 횟수가 많은 경우에 적용된다.

좋은 웹페이지 즐겨찾기