package cn.net.test.tools;

import java.util.ArrayList;
import java.util.List;

import cn.net.test.bean.DealerInvoiceFromOrderBeanT;
import cn.net.test.bean.InvoiceProductFromOrderBeanT;

public class DealerOrderInvoiceTools {
	/**
	 * 根据经销商出库单的详情数据，获取经销商数据
	 * @param invoiceStr
	 * @return
	 */
	public DealerInvoiceFromOrderBeanT parseDealerOrder(String invoiceStr){
		
		if(!invoiceStr.contains("||")) return null;
		DealerInvoiceFromOrderBeanT b = new DealerInvoiceFromOrderBeanT();
		String[] ds = invoiceStr.split("\\|\\|");
		if(ds.length >= 1) b.setDealer_id(ds[0]);
		if(ds.length >= 2) b.setOrder_id(ds[1]);
		if(ds.length >= 3) b.setDealer_name(ds[2]);
		if (ds.length >= 4) {
			String productListOrigin = ds[3].replaceAll("\\(", "").replaceAll("\\)", "");
			System.out.println("productListOrigin:" + productListOrigin);
			if (productListOrigin.contains("|") && productListOrigin.contains(",")) {
				List<InvoiceProductFromOrderBeanT> pBeans = new ArrayList<>();
				String[] pL = productListOrigin.split("\\|");
				for (int i = 0; i < pL.length; i++) {
					String [] pInfo = pL[i].split(",");
					InvoiceProductFromOrderBeanT pB = new InvoiceProductFromOrderBeanT();
					if(pInfo.length >= 1) pB.setProduct_nid(pInfo[0]);
					if(pInfo.length >= 2) pB.setOrderAmount(pInfo[1]);
					pBeans.add(pB);
				}
				b.setProducts(pBeans);
			}
			
		}

		
		
		return b;
	}
	
	/**
	 * 根据经销商出库单的详情数据，获取经销商数据
	 * @param invoiceStr
	 * @return
	 */
	public DealerInvoiceFromOrderBeanT parseDealerOrderAndProduct(String invoiceStr){
		
		if(!invoiceStr.contains("||")) return null;
		DealerInvoiceFromOrderBeanT b = new DealerInvoiceFromOrderBeanT();
		String[] ds = invoiceStr.split("\\|\\|");
		if(ds.length > 1) b.setDealer_id(ds[0]);
		if(ds.length > 2) b.setOrder_id(ds[1]);
		if(ds.length > 3) b.setDealer_name(ds[2]);
		if (ds.length > 4) {
			String productListOrigin = ds[3].replaceAll("\\(", "").replaceAll("\\)", "");
			if (productListOrigin.contains("|") && productListOrigin.contains(",")) {
				List<InvoiceProductFromOrderBeanT> pBeans = new ArrayList<>();
				String[] pL = productListOrigin.split("\\|");
				for (int i = 0; i < pL.length; i++) {
					String [] pInfo = pL[i].split(",");
					InvoiceProductFromOrderBeanT pB = new InvoiceProductFromOrderBeanT();
					if(pInfo.length > 1) pB.setProduct_nid(pInfo[0]);
					if(pInfo.length > 2) pB.setOrderAmount(pInfo[1]);
					pBeans.add(pB);
				}
				b.setProducts(pBeans);
			}
			
		}

		
		
		return b;
	}

}
