/*     */ package com.connor.erp.BomImport;
/*     */ 
/*     */ import com.connor.erp.toolkit.ActionType;
/*     */ 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 TransferBomXMLWriter
/*     */ {
/*     */   public static void createXML(String user_id, String file, ActionType actionType, 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", actionType.toString());
/*  47 */     root.setAttribute("fileType", fileType.toString());
/*  48 */     root.setAttribute("aimType", aimType.toString());
/*  49 */     doc.appendChild(root);
/*     */     
/*  51 */     Iterator<String> iterator = map.keySet().iterator();
/*  52 */     while (iterator.hasNext()) {
/*  53 */       String item_number = iterator.next();
/*  54 */       Element BomInfo = doc.createElement("BomInfo");
/*  55 */       if (actionType.toString().equals(ActionType.transfer)) {
/*  56 */         Element organization_id = doc.createElement("organization_id");
/*  57 */         organization_id.setTextContent("2");
/*  58 */         BomInfo.appendChild(organization_id);
/*     */       } 
/*     */       
/*  61 */       Element assembly_item_number = doc.createElement("assembly_item_number");
/*  62 */       Element component_item_number = doc.createElement("component_item_number");
/*     */ 
/*     */       
/*  65 */       assembly_item_number.setTextContent(item_number);
/*     */       
/*  67 */       Map<String, List<String>> item_name_map = map.get(item_number);
/*  68 */       List<String> item_name_list = item_name_map.get("item_name");
/*  69 */       List<String> item_quantity_list = item_name_map.get("item_quantity");
/*  70 */       List<String> operation_seq_num_list = item_name_map.get("operation_seq_num");
/*     */       
/*  72 */       for (int i = 0; i < item_name_list.size(); i++) {
/*     */         
/*  74 */         Element item = doc.createElement("item");
/*  75 */         Element item_name = doc.createElement("item_name");
/*  76 */         Element item_quantity = doc.createElement("item_quantity");
/*  77 */         Element operation_seq_num = doc.createElement("operation_seq_num");
/*  78 */         item_name.setTextContent(item_name_list.get(i));
/*  79 */         item_quantity.setTextContent(item_quantity_list.get(i));
/*  80 */         operation_seq_num.setTextContent(operation_seq_num_list.get(i));
/*     */         
/*  82 */         item.appendChild(item_name);
/*  83 */         item.appendChild(item_quantity);
/*  84 */         item.appendChild(operation_seq_num);
/*  85 */         component_item_number.appendChild(item);
/*     */       } 
/*     */ 
/*     */       
/*  89 */       BomInfo.appendChild(assembly_item_number);
/*  90 */       BomInfo.appendChild(component_item_number);
/*     */       
/*  92 */       root.appendChild(BomInfo);
/*     */     } 
/*     */     
/*  95 */     TransformerFactory tf = TransformerFactory.newInstance();
/*  96 */     Transformer transformer = tf.newTransformer();
/*  97 */     DOMSource source = new DOMSource(doc);
/*  98 */     transformer.setOutputProperty("encoding", "GB2312");
/*  99 */     transformer.setOutputProperty("indent", "yes");
/* 100 */     PrintWriter pw = new PrintWriter(new FileOutputStream(file));
/* 101 */     StreamResult result = new StreamResult(pw);
/* 102 */     transformer.transform(source, result);
/* 103 */     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\TransferBomXMLWriter.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.1.3
 */