package cn.net.test;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import cn.net.cpzslibs.label.JinLabelUtil;
import cn.net.test.bean.BoxBean;
import cn.net.test.bean.LabelTestBean;

public class ACreateJinTestData {
	// INSERT INTO `tbl_index_17` (label_id, produce_index, YEAR) VALUES
	// ('415060600100700500', '301', '2017')
	//
	// INSERT INTO `tbl_pro_301_17` (label_id, cuanhuo_label_id,
	// package_label_id,tray_id,product_id)
	// VALUES('415060600100700500','28678500100077','286785104400','123455','100007');
	static int line_code = 23;
	static List<String> trays = new ArrayList<>();
	static List<BoxBean> boxs = new ArrayList<>();
//	static List<String> labels = new ArrayList<>();
//	static List<String> db18labels = new ArrayList<>();
//	static List<String> bottles = new ArrayList<>();
	static List<LabelTestBean> labels = new ArrayList<>();
	private static long orgin_label = 100000000000L;
	static Calendar c = Calendar.getInstance();
	// private static StringBuilder trayStr = new StringBuilder();
	private static String saveStr = "";
	private static String saveDBStr = "";
	public static void main(String[] args) {
		for (int i = 0; i < 10; i++) {
			// System.err.println(i + " " +
			// JinLabelUtil.getPalletCode(line_code));
			String tray_id = JinLabelUtil.getPalletCode(line_code);
			System.out.println("tray_id:" + tray_id);
			trays.add(tray_id);
//			trayStr = trayStr + "\"" + tray_id + "\"\n";
		}

		for (String t : trays) {
			for (int j = 0; j < 20; j++) {
				String box_id = JinLabelUtil.getBoxCode(line_code);
				// System.out.println("box_id:" + box_id);
				BoxBean b = new BoxBean();
				b.setTray_id(t);
				b.setBox_id(box_id);
				boxs.add(b);
				System.err.println(t + "  box:" + box_id);
			}
		}

		for (BoxBean b : boxs) {

			for (int k = 0; k < 6; k++) {
				orgin_label++;
				String label_id = JinLabelUtil.getJinLabelId(orgin_label);
				String bottle_id = JinLabelUtil.getBottleId(line_code);
				// System.out.println("label_id:" + label_id);
				// System.out.println("bottle_id:" + bottle_id);
				String label_18_id = JinLabelUtil.getDB18Label(label_id);
//				labels.add(label_id);
//				bottles.add(bottle_id);
//				db18labels.add(JinLabelUtil.getDB18Label(label_id));
				LabelTestBean lBean = new LabelTestBean();
				lBean.setTray_id(b.getTray_id());
				lBean.setBox_id(b.getBox_id());
				lBean.setLabel_id(label_id);
				lBean.setLabel_18_id(label_18_id);
				lBean.setBottle_id(bottle_id);
				labels.add(lBean);
//				System.out.println(b + "   " + label_id.length() + "  18位：" + JinLabelUtil.getDB18Label(label_id)
//						+ " label_id:" + label_id + "  bottle_id:" + bottle_id);
			}

		}

		saveFile();

	}

	private static void saveFile() {
		Date d = new Date();
//		DateFormat format = new SimpleDateFormat("yyyy-MM-dd HHmmss"); //
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		String s = format.format(d);
		System.err.println("s:" + s);

		FileOperation operation = new FileOperation();
//		String filePath = "D:\\echo\\JinTestData\\" + s + "\\trays.text";
		String destDirName = "D:\\echo\\JinTestData\\" + s;
		String filePath = destDirName + "\\multi.text";
		
		for (int i = 0; i < labels.size(); i++) {
			LabelTestBean b = labels.get(i);
			saveStr = saveStr +"（" + i + "）  托盘：" + b.getTray_id() +"  箱码：" + b.getBox_id() +" \n" 
			+"  盒码：" + b.getLabel_id() +"  瓶码：" + b.getBottle_id() +"  数据库盒码：" + b.getLabel_18_id() +"\n";
		}
		
		
		try { 
//			System.err.println(trays.size() + " trays:" + trays.toString());
//			System.out.println(" trayStr:" + trayStr.toString());
			operation.createDir(destDirName);
			operation.createFile(new File(filePath));
//			写入
			
			operation.contentToTxt(filePath, saveStr); 
			// List<String> l = operation.readTextFile(new File(filePath)); //

		} catch (Exception e) { // TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
