package com.connor.jingdiao.handlers;

import java.util.HashMap;
import java.util.Optional;

public class Test {
	
	public static void main(String[] args) {
		HashMap<String[], String> opm = new HashMap<>();
//		for (int i = 0; i < options.length; i++) {
		String optionString = "rev.j6_drawingtype=零件@rev.j6_processtype=外购件@@#rev.j6_productseries+rev.j6_topicno";
		String[] sss = optionString.split("@@");
		opm.put(sss[0].split("@"), sss[1]);
		
		boolean present = Optional.ofNullable("ss").isPresent();
		System.out.println("::"+present);
		
		OPM: for (String[] ss : opm.keySet()) {
			boolean check = false;
			for (int j = 0; j < ss.length; j++) {
				String[] s2 = ss[j].split("=");
				String[] ss2 = s2[1].split(";");
				boolean c = true;
				for(String s : ss2) {
					System.out.println("::"+s+"=="+"<<"+s2[0]);
//					if(s.equals(impTable.getValueAt(i, map.get(s2[0])))){
//						c = false;
//						break;
//					}
				}
				System.out.println(c);
				if(c)
					check = true;
			}
			System.out.println("check:"+check);
//			if(check)
//				continue;
//			norule = false;
			StringBuilder id = new StringBuilder("");
			String rul = opm.get(ss);
			String[] rule = rul.split("\\+");
			for(String s : rule) {
				if(s.startsWith(".")) {
					id.append(s);
				}else if(s.startsWith("LSH")) {
					String lsh = "%" + String.format("%02d", Integer.parseInt(s.substring(3))) + "d";
					id.append(String.format(lsh, 2));
//					List<HashMap<String, Object>> results = SqlUtil.getDBInfo(conn, "select SERIALNUMBER from JD_CODE_RULE where CODEKEY='"+id+"'");
//					if (results.size() == 0) {
//						SqlUtil.update("insert into JD_CODE_RULE values('" +id+ "',1)");
//						id.append(String.format(lsh, 1));
//					} else {
//						int no = (Integer) results.get(0).get("SERIALNUMBER") + 1;
//						SqlUtil.update("update JD_CODE_RULE set SERIALNUMBER=" + no + " where CODEKEY='" +id+ "'");
//						id.append(String.format(lsh, no));
//					}
				}else if(s.startsWith("#rev.")) {
					System.out.println("s.substring(5)==>"+s.substring(5));
//					String value = rev.getStringProperty(s.substring(5));
//					if(value.isEmpty()) {
//						msg.append(rev).append(" 的部分图号相关属性为空，请检查\n");
//						break OPM;
//					}
					id.append("revVal");
				}
//				else if(map.containsKey(s)) {
//					String value = impTable.getValueAt(i, map.get(s)).toString();
//					if(value.isEmpty()) {
//						msg.append(rev).append(" 的部分图号相关属性为空，请检查\n");
//						break OPM;
//					}
//					id.append(value);
//				}
				else if(s.contains(".")) {//.startsWith("J6_ASSOCIATED_REL.j6_drawingno")
					String[] sp = s.split("\\.");
					System.out.println("sp[0]"+sp[0]+"sp[1]"+sp[1]);
//					id.append(s);
				}else {
					id.append(s);
				}
			}
			if(!rul.contains("LSH")) {
				System.out.println("sql==>"+"select SERIALNUMBER from JD_CODE_RULE where CODEKEY='"+id+"'");
//				List<HashMap<String, Object>> results = SqlUtil.getDBInfo(conn, "select SERIALNUMBER from JD_CODE_RULE where CODEKEY='"+id+"'");
//				if (results.size() == 0) {
//					
//					SqlUtil.update("insert into JD_CODE_RULE values('" +id+ "',0)");
//				}else {
//					msg.append(rev).append(" 的物料编码 ").append(id).append(" 已存在，请检查相关属性值\n");
//					break;
//				}
			}
			String dno = id.toString();
			System.out.println("dno==>"+dno);
			break;
		}
		
//		}
	}

}
