/*    */ package com.connor.erp.BomImport;
/*    */ 
/*    */ import com.connor.erp.toolkit.AimType;
/*    */ import com.connor.erp.toolkit.FileType;
/*    */ import com.connor.erp.toolkit.UtilApi;
/*    */ import java.io.FileNotFoundException;
/*    */ import java.io.FileOutputStream;
/*    */ import java.io.PrintWriter;
/*    */ import java.util.Iterator;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import javax.xml.parsers.DocumentBuilder;
/*    */ import javax.xml.parsers.DocumentBuilderFactory;
/*    */ import javax.xml.parsers.ParserConfigurationException;
/*    */ import javax.xml.transform.Transformer;
/*    */ import javax.xml.transform.TransformerException;
/*    */ import javax.xml.transform.TransformerFactory;
/*    */ import javax.xml.transform.dom.DOMSource;
/*    */ import javax.xml.transform.stream.StreamResult;
/*    */ import org.w3c.dom.Document;
/*    */ import org.w3c.dom.Element;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class ValidateBomXMLWriter
/*    */ {
/*    */   public static void createXML(String user_id, String file, FileType fileType, AimType aimType, Map<String, Map<String, List<String>>> map) throws ParserConfigurationException, FileNotFoundException, TransformerException {
/* 39 */     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
/* 40 */     DocumentBuilder db = dbf.newDocumentBuilder();
/* 41 */     Document doc = db.newDocument();
/*    */     
/* 43 */     Element root = doc.createElement("ERPFramework");
/* 44 */     root.setAttribute("userId", user_id);
/* 45 */     root.setAttribute("time", UtilApi.getCurrentTime());
/* 46 */     root.setAttribute("actionType", "validate");
/* 47 */     root.setAttribute("fileType", fileType.toString());
/* 48 */     root.setAttribute("aimType", aimType.toString());
/* 49 */     root.setAttribute("compareType", "details");
/* 50 */     doc.appendChild(root);
/*    */     
/* 52 */     Iterator<String> iterator = map.keySet().iterator();
/* 53 */     while (iterator.hasNext()) {
/* 54 */       String item_number = iterator.next();
/* 55 */       Element BomInfo = doc.createElement("BomInfo");
/*    */       
/* 57 */       Element assembly_item_number = doc.createElement("assembly_item_number");
/*    */       
/* 59 */       assembly_item_number.setTextContent(item_number);
/* 60 */       Element component_item_number = doc.createElement("component_item_number");
/*    */       
/* 62 */       Map<String, List<String>> item_name_map = map.get(item_number);
/*    */       
/* 64 */       List<String> namelist = item_name_map.get("item_name");
/*    */       
/* 66 */       List<String> numlist = item_name_map.get("operation_seq_num");
/* 67 */       int listSize = namelist.size();
/* 68 */       for (int i = 0; i < listSize; i++) {
/* 69 */         Element item = doc.createElement("item");
/* 70 */         Element item_name = doc.createElement("item_name");
/* 71 */         Element operation_seq_num = doc.createElement("operation_seq_num");
/* 72 */         item_name.setTextContent(namelist.get(i));
/* 73 */         operation_seq_num.setTextContent(numlist.get(i));
/* 74 */         item.appendChild(item_name);
/* 75 */         item.appendChild(operation_seq_num);
/* 76 */         component_item_number.appendChild(item);
/*    */       } 
/*    */       
/* 79 */       BomInfo.appendChild(assembly_item_number);
/* 80 */       BomInfo.appendChild(component_item_number);
/*    */       
/* 82 */       root.appendChild(BomInfo);
/*    */     } 
/*    */     
/* 85 */     TransformerFactory tf = TransformerFactory.newInstance();
/* 86 */     Transformer transformer = tf.newTransformer();
/* 87 */     DOMSource source = new DOMSource(doc);
/* 88 */     transformer.setOutputProperty("encoding", "GB2312");
/* 89 */     transformer.setOutputProperty("indent", "yes");
/* 90 */     PrintWriter pw = new PrintWriter(new FileOutputStream(file));
/* 91 */     StreamResult result = new StreamResult(pw);
/* 92 */     transformer.transform(source, result);
/* 93 */     pw.close();
/*    */   }
/*    */ }


/* Location:              C:\Users\cyh\Documents\WeChat Files\wxid_ztg4pdvd5bjn12\FileStorage\File\2022-03\com.origin.erpintegration_1.0.0.jar!\com\origin\erp\BomImport\ValidateBomXMLWriter.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.1.3
 */