package com.connor.erp.searchImpResult;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Test {

	public static void main(String[] args) {
		String output = "{\"checkResult\":[{\"item\":\"012759\",\"uom\":\"件\",\"existInNHL\":true,\"existInNSC\":false,\"existInNBJ\":false,\"existInNSJ\":true,\"uomExist\":true,\"canImport\":false}],\"canAllImport\":false}";
		if(output!=null&&output.length()>=14&&output.substring(0,14).equals("{\"checkResult\"")) {
			   JSONObject json = JSONObject.fromObject(output);
			   JSONArray jsonArray = json.getJSONArray("checkResult");
			   System.out.println("jsonarray==="+jsonArray);
			   StringBuffer sb = new StringBuffer();
			   for(int i =0;i<jsonArray.size();i++) {
				  JSONObject fromObject = JSONObject.fromObject(jsonArray.get(i));
				  System.out.println("fromObject==="+fromObject);
				  String itemID = fromObject.getString("item");
				  String uom = fromObject.getString("uom");
				  boolean existNiNHL = fromObject.getBoolean("existInNHL");
				  boolean existNiNSC = fromObject.getBoolean("existInNSC");
				  boolean existNiNBJ = fromObject.getBoolean("existInNBJ");
				  boolean existNiNSJ = fromObject.getBoolean("existInNSJ");
				  boolean uomExist = fromObject.getBoolean("uomExist");
				  boolean canImport = fromObject.getBoolean("canImport");
				  if(canImport) continue;
				  else {
					if(existNiNHL)sb.append(itemID+"在主组织中已存在;");
					if(existNiNSC)sb.append(itemID+"在生产组织中已存在;");
					if(existNiNBJ)sb.append(itemID+"在备件组织中已存在;");
					if(existNiNSJ)sb.append(itemID+"在非生产组织中已存在;");
					if(!uomExist)sb.append(itemID+"的单位["+uom+"]不存在;");
				  }
			   }
			   output = sb.toString();
			   System.out.println("output==="+output);
		}
	}
}
