 package com.connor.erp.ProcessImport;
 
 import com.connor.erp.ProcessImport.ProcessAddTransferToERP.RootCheckResult;
import com.connor.erp.ProcessImport.ProcessAddTransferToERP.RouteLineCheck;
import com.connor.erpintegration.entity.BOMLineEntity;
import com.connor.erpintegration.entity.BomCheckResult;
import com.connor.erpintegration.entity.RouteCheckResult;
import com.connor.erpintegration.entity.RouteLineEntity;
import com.teamcenter.rac.kernel.TCSession;

import net.sf.json.JSONObject;

import java.io.File;
 import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jdom.Attribute;
 import org.jdom.Document;
 import org.jdom.Element;
 import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
 
 public class ProcessImportReadXMLStr {
//   public static String xmlAddElements(File xmlFilePath, StringBuffer errorInfo) {
///*  41 */     SAXBuilder sb = new SAXBuilder();
///*  42 */     Element root = null;
//     try {
///*  45 */       Document doc = sb.build(xmlFilePath);
///*  47 */       root = doc.getRootElement();
///*  48 */       if (root.getAttribute("hasWrong").getValue().equals("false"))
///*  49 */         return "成功"; 
///*  51 */     } catch (JDOMException e) {
///*  52 */       e.printStackTrace();
///*  53 */     } catch (IOException e) {
///*  54 */       e.printStackTrace();
//     } 
///*  56 */     return loadAddElements(root.getChildren(), errorInfo);
//   }
   
   public static String xmlAddElements(TCSession session, File xmlFilePath) {
/*  60 */     StringBuffer errorInfo = new StringBuffer("");
/*  62 */     SAXBuilder sb = new SAXBuilder();
     try {
/*  65 */       Document doc = sb.build(xmlFilePath);
/*  67 */       Element root = doc.getRootElement();
///*  68 */       loadAddElements(root.getChildren(), errorInfo);
/*  69 */     } catch (JDOMException e) {
/*  70 */       e.printStackTrace();
/*  71 */     } catch (IOException e) {
/*  72 */       e.printStackTrace();
     } 
/*  74 */     return errorInfo.toString();
   }
   
//   public static String xmlChgElements(File xmlFilePath, List<String> listAll, List<String> listAllAssAndOper, List<String[]> listOld, List<String> listOldAssAndOper) {
///*  78 */     StringBuffer errorInfo = new StringBuffer("");
///*  81 */     SAXBuilder sb = new SAXBuilder();
//     try {
///*  84 */       Document doc = sb.build(xmlFilePath);
///*  86 */       Element root = doc.getRootElement();
///*  87 */       loadChgElements(root.getChildren(), errorInfo, listAll, listAllAssAndOper, listOld, listOldAssAndOper);
///*  88 */     } catch (JDOMException e) {
///*  89 */       e.printStackTrace();
///*  90 */     } catch (IOException e) {
///*  91 */       e.printStackTrace();
//     } 
///*  93 */     return errorInfo.toString();
//   }
   
   public static String xmlChgElements(TCSession session, File xmlFilePath) {
/*  97 */     StringBuffer errorInfo = new StringBuffer("");
/* 100 */     SAXBuilder sb = new SAXBuilder();
     try {
/* 103 */       Document doc = sb.build(xmlFilePath);
/* 105 */       Element root = doc.getRootElement();
///* 106 */       loadChgElements(root.getChildren(), errorInfo);
/* 107 */     } catch (JDOMException e) {
/* 108 */       e.printStackTrace();
/* 109 */     } catch (IOException e) {
/* 110 */       e.printStackTrace();
     } 
/* 112 */     return errorInfo.toString();
   }
   
   public static String loadAddElements(List list) {
/* 116 */     int listSize = list.size();
/* 117 */     if (listSize == 0)
/* 118 */       return ""; 
				StringBuffer errorInfo = new StringBuffer("");
/* 120 */     int routeExistNum = 0;
/* 121 */     for (int i = 0; i < listSize; i++) {
/* 122 */       RootCheckResult routeCheckResult =(RootCheckResult) list.get(i);
//List<RouteLineCheck> routeLine = routeCheckResult.getRouteLine();

//				Map<String, Class> classMap = new HashMap<String, Class>();
//				classMap.put("RouteLine", RouteLineCheck.class);
//				RootCheckResult r =(RootCheckResult)JSONObject.toBean(JSONObject.fromObject(routeCheckResult),RootCheckResult.class,classMap);
//				if(r.getCanRouteImport().equals("true"))return "成功";
///* 123 */       List<?> listRouteInfoChild = routeInfo_et.getChildren();
///* 124 */       int listRouteInfoChildSize = listRouteInfoChild.size();
/* 125 */       String item_number_et = "";
/* 126 */       List<RouteLineCheck> processes_et = routeCheckResult.getRouteLine();
System.out.println(routeCheckResult.getAssembly_item());
/* 131 */           item_number_et = routeCheckResult.getAssembly_item();
///* 132 */         } else if (etName.equals("processes")) {
/* 133 */           processes_et = routeCheckResult.getRouteLine();
//         } 
//       } 
/* 136 */       boolean isContinue = false;
/* 137 */       String item_number = "";
/* 138 */       if (item_number_et != null&&item_number_et.length()>0) {
/* 139 */         item_number = item_number_et;
///* 140 */         List<?> attrList = item_number_et.getAttributes();
///* 141 */         int attrNum = attrList.size();
/* 142 */         boolean isExist = false;
/* 143 */         boolean isRouteExist = false;
///* 144 */         for (int m = 0; m < attrNum; m++) {
///* 145 */           Attribute attr = item_number_et.getAttributes().get(m);
///* 146 */           String attr_name = attr.getName();
///* 147 */           String attr_value = attr.getValue();
					if(routeCheckResult.getAssembly_item_exist().equals("true"))
						isExist = true;
					if(routeCheckResult.getRoute_exist().equals("true")) {
						routeExistNum++;
						isRouteExist = true;
					}
/* 159 */         if (isExist) {
/* 160 */           if (isRouteExist) {
/* 161 */             errorInfo.append(String.valueOf(item_number) + "装配件的工艺路线已经存在<br>");
           } else {
/* 163 */             isContinue = true;
           } 
         } else {
/* 166 */           errorInfo.append(String.valueOf(item_number) + " 装配件不存在或已失效<br>");
         } 
       } 
/* 169 */       if (isContinue) {
/* 170 */         StringBuffer errorInfo2 = new StringBuffer(String.valueOf(item_number) + " 装配件已经存在,但");
///* 171 */         List<?> listProcessesChild = processes_et.getChildren();
///* 172 */         int listSize2 = listProcessesChild.size();
/* 173 */         for (int k = 0; k < processes_et.size(); k++) {
/* 174 */           RouteLineCheck process_et = processes_et.get(k);
					

///* 175 */           Element department_code_et = process_et.getChild("department_code");
///* 176 */           List<?> listDepartmentAttr = department_code_et.getAttributes();
///* 177 */           if (listDepartmentAttr != null && listDepartmentAttr.size() > 0) {
/* 178 */             String isExist_at = process_et.getDepartment_exist();
/* 179 */             if (isExist_at.equals("false"))
/* 180 */               errorInfo2.append(process_et.getDepartment_code()).append(","); 
//           } 
         } 
/* 184 */         if (!errorInfo2.toString().endsWith(",但")) {
/* 185 */           String errorInfoStr = errorInfo2.toString();
/* 186 */           errorInfo2 = errorInfo2.replace(errorInfoStr.length() - 1, errorInfoStr.length(), "");
/* 187 */           errorInfo2.append(" 部门不存在<br>");
/* 188 */           errorInfo.append(errorInfo2.toString());
         } 
       } 
     } 
System.out.println(listSize+"listSize"+routeExistNum);
/* 192 */     if (routeExistNum == listSize)
/* 193 */       return "所有的工艺路线都已经存在"; 
/* 195 */     return errorInfo.toString();
   }
   
   public static void loadChgElements(List<RouteCheckResult> list, StringBuffer errorInfo, List<String> listAll, List<String> listAllAssAndOper, List<String[]> listOld, List<String> listOldAssAndOper) {
/* 199 */     int listSize = list.size();
/* 200 */     if (listSize == 0)
				return; 
int routeExistNum = 0;
/* 203 */     for (int i = 0; i < listSize; i++) {
/* 204 */       RouteCheckResult routeInfo_et = (RouteCheckResult)list.get(i);
///* 205 */       List<?> listRouteInfoChild = routeInfo_et.getChildren();
///* 206 */       int listRouteInfoChildSize = listRouteInfoChild.size();
///* 207 */       Element item_number_et = null;
///* 208 */       Element processes_et = null;
///* 210 */       for (int j = 0; j < listRouteInfoChildSize; j++) {
///* 211 */         Element childEt = (Element)listRouteInfoChild.get(j);
///* 212 */         String etName = childEt.getName();
///* 213 */         if (etName.equals("assembly_item_number")) {
///* 214 */           item_number_et = childEt;
///* 215 */         } else if (etName.equals("processes")) {
///* 216 */           processes_et = childEt;
//         } 
//       } 
/* 219 */       boolean isContinue = false;
/* 220 */       String item_number = "";
/* 221 */       if (routeInfo_et != null) {
/* 225 */         boolean isExist = false;
/* 226 */         boolean isRouteExist = false;
				item_number=routeInfo_et.getAssembly_item();
/* 227 */         if(routeInfo_et.getAssembly_item_exist().equals("true"))
						isExist = true;
				if(routeInfo_et.getRoute_exist().equals("true")) {
						routeExistNum++;
						isRouteExist = true;
					}
/* 241 */         if (isExist) {
/* 242 */           if (isRouteExist) {
/* 243 */             isContinue = true;
           } else {
/* 245 */             errorInfo.append(String.valueOf(item_number) + " 装配件存在，但工艺路线不存在<br>");
           } 
         } else {
/* 248 */           errorInfo.append(String.valueOf(item_number) + " 装配件不存在或已失效<br>");
         } 
       } 
/* 251 */       if (isContinue) {
/* 252 */         StringBuffer errorInfo2 = (new StringBuffer(item_number)).append(" 装配件已经存在,但");
///* 253 */         List<?> processesChildList = processes_et.getChildren();
///* 254 */         int processesChildNum = processesChildList.size();
/* 255 */         int operationNum = 0;
				List<RouteLineEntity> routeLine = routeInfo_et.getRouteLine();
/* 256 */         for (int k = 0; k < routeLine.size(); k++) {
/* 257 */           StringBuffer allAssAndOperStr = new StringBuffer("");
/* 258 */           StringBuffer oldAssAndOperStr = new StringBuffer("");
/* 259 */           String[] oldStr = new String[6];
/* 260 */           String[] allStr = new String[6];
/* 261 */           allAssAndOperStr.append(item_number).append(",");
/* 262 */           oldAssAndOperStr.append(item_number).append(",");
/* 263 */           oldStr[0] = item_number;
/* 264 */           allStr[0] = item_number;
/* 265 */           RouteLineEntity process_et = (RouteLineEntity)routeLine.get(k);
///* 266 */           List<?> processChildList = process_et.getChildren();
///* 267 */           int processChildNum = processChildList.size();
/* 268 */           boolean isDepartmentExist = false;
/* 269 */           boolean isOperationExist = false;
/* 270 */           String departmentValue = "";
					
					String operation_seq_num = process_et.getOperation_seq_num();
					String seq_num_exist = process_et.getSeq_num_exist();
					if(seq_num_exist!=null && seq_num_exist.equals("true")) {
						isOperationExist = true;
						oldStr[1] = operation_seq_num;
						oldAssAndOperStr.append(operation_seq_num);
					}else if(seq_num_exist ==null || seq_num_exist.equals("")){
						isOperationExist = true;
						oldStr[1] = operation_seq_num;
						oldAssAndOperStr.append(operation_seq_num);
					}else {
						 oldStr[1] = "";
					}
					allStr[1] = operation_seq_num;
					allAssAndOperStr.append(operation_seq_num);
					String department_code_exist = process_et.getDepartment_code_exist();
					if(department_code_exist!=null && department_code_exist.equals("true")) {
						isDepartmentExist = true; 
					}else if (department_code_exist==null || department_code_exist.equals("")) {
						isDepartmentExist = true; 
					}else {
						departmentValue=process_et.getDepartment_code_erp();//20231018改动
					}
					String department_code = process_et.getDepartment_code_erp();//20231018改动
					 oldStr[3] = department_code;
					 allStr[3] = department_code;
					 String operation_description = process_et.getOperation_description();
					 oldStr[2] = operation_description;
					 allStr[2] = operation_description;
					 
					 String usage_rate_or_amount = process_et.getUsage_rate_or_amount();
					 oldStr[4] = usage_rate_or_amount;
					 allStr[4] = usage_rate_or_amount;
					 String usage_rate_or_amount_auxiliary = process_et.getUsage_rate_or_amount_auxiliary();
					 oldStr[5] = usage_rate_or_amount_auxiliary;
					 allStr[5] = usage_rate_or_amount_auxiliary;

///* 272 */             Element child_et = (Element)processChildList.get(n);
///* 273 */             String et_name = child_et.getName();
///* 274 */             String et_value = child_et.getValue();
///* 275 */             if (et_name.equals("operation_seq_num")) {
//	
//				} else if (et_name.equals("department_code_new")) {
///* 308 */             } else if (et_name.equals("department_code")) {
///* 309 */               oldStr[3] = et_value;
///* 310 */               allStr[3] = et_value;
///* 311 */             } else if (et_name.equals("operation_description")) {
///* 312 */               oldStr[2] = et_value;
///* 313 */               allStr[2] = et_value;
///* 314 */             } else if (et_name.equals("usage_rate_or_amount")) {
//						} else if (et_name.equals("usage_rate_or_amount_auxiliary")) {
///* 323 */               if (et_value.trim().equals("")) {
///* 324 */                 oldStr[5] = "0";
///* 325 */                 allStr[5] = "0";
//               } else {
///* 327 */                 oldStr[5] = et_value;
///* 328 */                 allStr[5] = et_value;
//               } 
//             } 
            
					 System.out.println("isDepartmentExist"+isDepartmentExist);
/* 332 */           if (!isDepartmentExist) {
/* 333 */             errorInfo2.append(departmentValue).append(",");
/* 335 */           } else if (isOperationExist) {
/* 336 */             operationNum++;
           } 
/* 339 */           listAllAssAndOper.add(allAssAndOperStr.toString());
/* 340 */           StringBuffer allStrBuf = new StringBuffer("");
/* 341 */           for (int m = 0; m < 6; m++) {
/* 342 */             if (m == 5) {
/* 343 */               allStrBuf.append(allStr[m]);
               break;
             } 
/* 346 */             allStrBuf.append(allStr[m]).append(",");
           } 
/* 348 */           listAll.add(allStrBuf.toString());
System.out.println(allStrBuf.toString());
System.out.println(oldStr[0]);
System.out.println(oldAssAndOperStr.toString());
/* 349 */           if (!oldStr[1].equals("")) {
/* 350 */             listOld.add(oldStr);
/* 351 */             listOldAssAndOper.add(oldAssAndOperStr.toString());
           } 
         } 
/* 354 */         if (!errorInfo2.toString().endsWith(",但")) {
/* 355 */           String errorInfoStr = errorInfo2.toString();
/* 356 */           errorInfo2 = errorInfo2.replace(errorInfoStr.length() - 1, errorInfoStr.length(), "");
/* 357 */           errorInfo2.append(" 部门不存在<br>");
/* 358 */           errorInfo.append(errorInfo2.toString());
/* 360 */         } else if (operationNum == 0) {
/* 361 */           errorInfo.append((new StringBuffer(String.valueOf(item_number) + " 装配件和部门已经存在,但工序号都不存在<br>")).toString());
         } 
       } 
     } 
   }
   
   public static String loadChgElements(List<RouteCheckResult> list) {
/* 370 */     int listSize = list.size();
/* 371 */     if (listSize == 0)
       			return ""; 
				StringBuffer errorInfo = new StringBuffer("");
/* 374 */     for (int i = 0; i < listSize; i++) {
/* 375 */       RouteCheckResult routeCheckResult = list.get(i);
				Map<String, Class> classMap = new HashMap<String, Class>();
				classMap.put("RouteLine", RouteLineEntity.class);
				RouteCheckResult r =(RouteCheckResult)JSONObject.toBean(JSONObject.fromObject(routeCheckResult),RouteCheckResult.class,classMap);
///* 376 */       List<?> listRouteInfoChild = routeInfo_et.getChildren();
///* 377 */       int listRouteInfoChildSize = listRouteInfoChild.size();
/* 378 */       String item_number_et = null;
/* 379 */       List<RouteLineEntity> processes_et = null;
///* 381 */       for (int j = 0; j < listRouteInfoChildSize; j++) {
///* 382 */         Element childEt = (Element)listRouteInfoChild.get(j);
///* 383 */         String etName = childEt.getName();
///* 384 */         if (etName.equals("assembly_item_number")) {
/* 385 */           item_number_et = r.getAssembly_item();
///* 386 */         } else if (etName.equals("processes")) {
/* 387 */           processes_et = r.getRouteLine();
//         } 
//       } 
/* 390 */       boolean isContinue = false;
/* 391 */       String item_number = "";
/* 392 */       if (item_number_et != null&&item_number_et.length()>0) {
/* 393 */         item_number = item_number_et;
///* 394 */         List<?> attrList = item_number_et.getAttributes();
///* 395 */         int attrNum = attrList.size();
/* 396 */         boolean isExist = false;
/* 397 */         boolean isRouteExist = false;
					if(r.getAssembly_item_exist().equals("true"))
						isExist = true;
					else if(r.getRoute_exist().equals("true")) {
						isRouteExist = true;
					}
///* 398 */         for (int m = 0; m < attrNum; m++) {
///* 399 */           Attribute attr = item_number_et.getAttributes().get(m);
/////* 400 */           String attr_name = attr.getName();
///* 401 */           String attr_value = attr.getValue();
///* 402 */           if (attr_name.equals("isExist")) {
///* 403 */             if (attr_value.equals("true"))
///* 404 */               isExist = true; 
///* 406 */           } else if (attr_name.equals("isROUTEExist") && 
///* 407 */             attr_value.equals("true")) {
///* 408 */             isRouteExist = true;
//           } 
//         } 
/* 412 */         if (isExist) {
/* 413 */           if (isRouteExist) {
/* 414 */             isContinue = true;
           } else {
/* 416 */             errorInfo.append(String.valueOf(item_number) + " 装配件存在，但工艺路线不存在<br>");
           } 
         } else {
/* 419 */           errorInfo.append(String.valueOf(item_number) + " 装配件不存在或已失效<br>");
         } 
       } 
/* 422 */       if (isContinue) {
/* 423 */         StringBuffer errorInfo2 = (new StringBuffer(item_number)).append(" 装配件已经存在,但");
///* 424 */         List<?> processesChildList = processes_et.getChildren();
///* 425 */         int processesChildNum = processesChildList.size();
/* 426 */         int operationNum = 0;
/* 427 */         for (int k = 0; k < processes_et.size(); k++) {
/* 428 */           RouteLineEntity process_et = processes_et.get(k);
///* 429 */           List<?> processChildList = process_et.getChildren();
///* 430 */           int processChildNum = processChildList.size();
/* 431 */           boolean isDepartmentExist = false;
/* 432 */           boolean isOperationExist = false;
/* 433 */           String departmentValue = process_et.getDepartment_code();
///* 434 */           for (int m = 0; m < processChildNum; m++) {
///* 435 */             Element child_et = (Element)processChildList.get(m);
///* 436 */             String et_name = child_et.getName();
///* 437 */             String et_value = child_et.getValue();
///* 438 */             if (et_name.equals("operation_seq_num")) {
///* 439 */               List<?> arrList = child_et.getAttributes();
///* 440 */               if (arrList != null && arrList.size() > 0) {
///* 441 */                 Attribute isExist_at = child_et.getAttributes().get(0);
///* 442 */                 if (isExist_at.getValue().equals("true"))
///* 443 */                   isOperationExist = true; 
//               } else {
						if("true".equals(process_et.getSeq_num_exist()))
/* 446 */                 isOperationExist = true;
//               } 
///* 448 */             } 
//else if (et_name.equals("department_code_new")) {
///* 449 */               if (!et_value.equals("")) {
///* 450 */                 departmentValue = et_value;
///* 451 */                 List<?> arrList = child_et.getAttributes();
///* 452 */                 if (arrList != null && arrList.size() > 0) {
///* 453 */                   Attribute isExist_at = child_et.getAttributes().get(0);
///* 454 */                   if (isExist_at.getValue().equals("true"))
///* 455 */                     isDepartmentExist = true; 
//                 } else {
///* 458 */                   isDepartmentExist = true;
//                 } 
//               } else {
						if("true".equals(process_et.getDepartment_code_exist()))
/* 461 */                 isDepartmentExist = true;
//               } 
//             } 
//           } 
/* 465 */           if (!isDepartmentExist) {
/* 466 */             errorInfo2.append(departmentValue).append(",");
/* 468 */           } else if (isOperationExist) {
/* 469 */             operationNum++;
           } 
         } 
/* 473 */         if (!errorInfo2.toString().endsWith(",但")) {
/* 474 */           String errorInfoStr = errorInfo2.toString();
/* 475 */           errorInfo2 = errorInfo2.replace(errorInfoStr.length() - 1, errorInfoStr.length(), "");
/* 476 */           errorInfo2.append(" 部门不存在<br>");
/* 477 */           errorInfo.append(errorInfo2.toString());
/* 479 */         } else if (operationNum == 0) {
/* 480 */           errorInfo.append((new StringBuffer(String.valueOf(item_number) + " 装配件和部门已经存在,但工序号都不存在<br>")).toString());
         } 
       } 
     } 
	return errorInfo.toString();
   }
 }

