package com.connor.dfl.plm.dfl020; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; //import org.jacorb.idl.runtime.int_token; import com.connor.dfl.plm.util.AutoSign; import com.teamcenter.rac.aif.AbstractAIFApplication; import com.teamcenter.rac.aif.AbstractAIFOperation; import com.teamcenter.rac.aif.AbstractAIFUIApplication; import com.teamcenter.rac.aif.kernel.AIFComponentContext; import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; import com.teamcenter.rac.kernel.TCClassificationService; import com.teamcenter.rac.kernel.TCComponent; import com.teamcenter.rac.kernel.TCComponentBOMLine; import com.teamcenter.rac.kernel.TCComponentBOMWindow; import com.teamcenter.rac.kernel.TCComponentBOMWindowType; import com.teamcenter.rac.kernel.TCComponentGroup; import com.teamcenter.rac.kernel.TCComponentICO; import com.teamcenter.rac.kernel.TCComponentItem; import com.teamcenter.rac.kernel.TCComponentItemRevision; import com.teamcenter.rac.kernel.TCComponentListOfValues; import com.teamcenter.rac.kernel.TCComponentProject; import com.teamcenter.rac.kernel.TCComponentTask; import com.teamcenter.rac.kernel.TCException; import com.teamcenter.rac.kernel.TCProperty; import com.teamcenter.rac.kernel.TCSession; import com.teamcenter.rac.kernel.TCTypeService; import com.teamcenter.rac.kernel.ics.ICSAdminClass; import com.teamcenter.rac.kernel.ics.ICSAdminClassAttribute; import com.teamcenter.rac.kernel.ics.ICSProperty; import com.teamcenter.rac.util.MessageBox; import com.teamcenter.schemas.core._2012_09.projectlevelsecurity.ProjectTeamsResponse; import com.teamcenter.soaictstubs.stringSeq_tHolder; import oracle.sql.BLOB; public class Dfl020Operation extends AbstractAIFOperation{ private AbstractAIFApplication app; private TCSession session; private List attrList; private String url ; private String user; private String password ; private Connection conn = null;// private PreparedStatement pre = null;// private ResultSet result = null;// private String outPutInfo= ""; private String tops; private String ns ; //private String weiyi_id; String accountSet; private String zhangtao; private AutoSign as = null; private List list = new ArrayList(); String zong; private boolean isEquipment = false; String z_peizhi = ""; String outString = ""; private String txt_pinhao; public Dfl020Operation(AbstractAIFApplication app, TCSession session ,String accountSet,String zhangtao) { this.app = app; this.session = session; this.accountSet = accountSet; this.as=new AutoSign(); this.zhangtao = zhangtao; } public Dfl020Operation(AbstractAIFApplication app, TCSession session) { this.app = app; this.session = session; this.as=new AutoSign(); String[] stringArrays = session.getPreferenceService().getStringValues("DFL_zhangtao"); String[] BOMZT = session.getPreferenceService().getStringValues("DFL_ERPBom_zhangtao"); if (BOMZT == null || BOMZT.length <= 0 ) { MessageBox.post("首选项DFL_ERPBom_zhangtao未配置,请联系管理员!!", "错误", MessageBox.ERROR); return; } Map account_set = new HashMap(); if (stringArrays == null || stringArrays.length <= 0 ) { MessageBox.post("首选项DFL_zhangtao未配置,请联系管理员!!", "错误", MessageBox.ERROR); return; }else { for(int i = 0 ;i=2) { for (int i = 0; i < BOMZT.length; i++) { System.out.println("BOMZT[i]====="+BOMZT[i]); if(BOMZT[i].contains("=")) { String[] zts = BOMZT[i].split("="); System.out.println("names[names.length-2]====="+names[names.length-2]); if(names[names.length-2].equals(zts[0])) { this.zhangtao = zts[1]; this.accountSet = account_set.get(zhangtao); break; } } } } } } catch (TCException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void executeOperation(){ new Runnable() { public void run() { sendBOMTOERP(); } }.run(); } public void sendBOMTOERP() { InterfaceAIFComponent[] comp = app.getTargetComponents(); String uid =""; String[] stringArray = ((TCSession) app.getSession()).getPreferenceService().getStringValues("DFL2_SQL_Connect"); url = "jdbc:oracle:thin:@//"+stringArray[0];// user = stringArray[1];// password = stringArray[2];// conn = null;// pre = null;// result = null;// TCComponentItemRevision rev = null; try { if(comp[0] instanceof TCComponentItemRevision || comp[0] instanceof TCComponentBOMLine ) { if(comp[0] instanceof TCComponentItemRevision ) { rev = (TCComponentItemRevision) comp[0]; String rve_id = rev.getStringProperty("current_revision_id"); System.out.println("11.17rve_id======"+rve_id); } if(comp[0] instanceof TCComponentBOMLine ) { TCComponentBOMLine get_bom_line = (TCComponentBOMLine) comp[0]; rev = get_bom_line.getItemRevision(); } TCProperty tcProperty1 = rev.getTCProperty("release_status_list"); TCComponent[] targets1 = tcProperty1.getReferenceValueArray(); String item_type = rev.getType(); if("T2_EquipmentRevision".equals(item_type)) { isEquipment = true; } //限制没有发布状态的设备虚拟件版本发起bom传递erp命令 if("T2_VirtualRevision".equals(item_type) || "T2_EquipmentRevision".equals(item_type)) { if(targets1 == null || targets1.length <= 0) { MessageBox.post("您选中的版本对象没有发布状态","提示",MessageBox.INFORMATION); return; } } //限制外购件版本发起bom传递erp命令 if("T2_OutBuyPartRevision".equals(item_type)) { MessageBox.post("您选中的版本对象是外购件版本,不能进行bom传递erp","提示",MessageBox.INFORMATION); return; } //限制外协件版本发起bom传递erp命令 if ("T2_outsourceRevision".equals(item_type)) { MessageBox.post("您选中的版本对象是外协件版本,不能进行bom传递erp","提示",MessageBox.INFORMATION); return; } //限制系统方案版本发起bom传递erp命令 if ("T2_SystemSchemeRevision".equals(item_type)) { MessageBox.post("您选中的版本对象是系统方案版本,不能进行bom传递erp","提示",MessageBox.INFORMATION); return; } //TCProperty tcProperty = rev.getTCProperty("fnd0MyWorkflowTasks"); TCProperty tcProperty = rev.getTCProperty("fnd0MyWorkflowTasks"); TCComponent[] targets = tcProperty.getReferenceValueArray(); // if(targets != null && targets.length>0) { // MessageBox.post("您选中的版本对象没有在流程中","提示",MessageBox.INFORMATION); // return; // for(int i = 0;i 0) { createXMLFile(line,zhangtao); }else { MessageBox.post("不允许单个物料进行BOM传递ERP","提示",MessageBox.INFORMATION); return; } view.close(); if(!("".equals(uid))&& !(" ".equals(uid))) { as.AutoSignServer(uid,session); } MessageBox.post("BOM数据存储成功,准备传递ERP!!!", "提示", MessageBox.WARNING); } catch (Exception e) { // TODO Auto-generated catch block MessageBox.post("BOM数据存储失败,请检查后重新传递!!!", "提示", MessageBox.WARNING); e.printStackTrace(); } } //生产xml文件 protected void createXMLFile(TCComponentBOMLine line ,String zhangtao) throws TCException, IOException { String weiyi_id = ""; // List list = new ArrayList(); try { getBOMValue(line,list,1); if(list.size() <=0) { MessageBox.post("BOM 传递失败,请检查BOM行是否正确!!!", "提示", MessageBox.INFORMATION); return; } } catch (Exception e) { // TODO: handle exception MessageBox.post("BOM 传递失败,请检查BOM行是否正确!!!!" ,"提示",MessageBox.INFORMATION); e.printStackTrace(); return; } //获取父 属性 String userName = session.getUser().getUserName(); List toFus = new ArrayList(); for(int f_index = 0;f_index< list.size();f_index++) { String fuUID = list.get(f_index).getItem_uid(); if(!toFus.contains(fuUID)) { toFus.add(fuUID); }else { continue; } StringBuilder sb2 = new StringBuilder(); StringBuilder uidSB = new StringBuilder(); Date date = new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); String plmls = df.format(date); String s1 =""; String s3 = ""; String s4 = ""; String s5 = ""; String s6 = ""; sb2.append(s1); sb2.append(s3); sb2.append(s4); sb2.append(s5); sb2.append(s6); uidSB.append(list.get(f_index).getItem_uid()); if(f_index< list.size()-1) { uidSB.append(";"); } // int iii = f_index+1; // System.out.println("==== 第"+ iii+"个配置"); System.out.println("******品号"+list.get(f_index).getPinhao()+"*****"); String peizhi1 =""; // String peizhi1 =""; //String peizhi2 = "第"+iii +"个配置 "; String peizhi3 = ""; sb2.append(peizhi1); sb2.append(peizhi3); sb2.append(peizhi4); //z_peizhi+=peizhi; List l = (List) list.get(f_index).getList(); for(int z = 0 ;z")) { beizhu = beizhu.replace(">", ">"); } if(beizhu.contains("\"")) { beizhu = beizhu.replace("\"", """); } } String xh = ""; String yj = ""; String sxrq = ""; String yl = ""; String zybh = ""; String xjwz = ""; String bz = ""; String plmkey =""; sb2.append(xh);//序号 sb2.append(yj);//id sb2.append(sxrq);//生效日期 sb2.append(yl);// sb2.append(zybh);//作业编号 sb2.append(xjwz);// sb2.append(bz); sb2.append(plmkey); } sb2.append(""); String bottomS =""; sb2.append(bottomS); outPutInfo = sb2.toString(); System.out.println("================"+outPutInfo); String fileName ="BOM-"+ list.get(f_index).getPinhao()+"-"+plmls; String tempPath = System.getProperty("java.io.tmpdir"); String uid_fileName ="BOM-UID-"+list.get(f_index).getPinhao()+"-"+ plmls; System.out.println("10.20temp路径======="+tempPath); //String path = "D:\\SENDTOERPLOG\\" + fileName + ".txt"; String path = tempPath + fileName + ".txt"; String path1 = tempPath + uid_fileName + ".txt"; File file = new File(path); File file1 = new File(path1); if (!file.exists()) { //file.getParentFile().mkdirs(); file.createNewFile(); } if (!file1.exists()) { //file.getParentFile().mkdirs(); file1.createNewFile(); } try { FileOutputStream fos = new FileOutputStream(file); fos.write(outPutInfo.getBytes()); fos.flush(); fos.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } // // InputStream in = new FileInputStream("c:/fugang.jpg"); // // byte[] fileContent = new byte[in.available()]; // // in.read(fileContent); // // in.close(); // // //将txt文件 保存到数据库 weiyi_id = getId(); System.out.println("=======================唯一识别码" +weiyi_id); //if(f_index > 0 && f_index%60 == 0) { String uidString = uidSB.toString(); try { FileOutputStream fos2 = new FileOutputStream(file1); fos2.write(uidString.getBytes()); fos2.flush(); fos2.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } as.insertNewTxtFile(path,fileName, weiyi_id,session.getUser().getUid() , url, user, password,"CreatePLMBOMDataRequest",list.get(f_index).getPinhao(),zhangtao,session.getUser().getUserId(),path1,uid_fileName,session); } } private void getBOMValue(TCComponentBOMLine line, List list,int pQty) { FatherBomLineBean fatherBean = new FatherBomLineBean(); try { TCComponentItemRevision rev = line.getItemRevision(); AIFComponentContext[] childrens = line.getChildren(); if (childrens.length > 0) { rev.getStringProperty("t2_ERPBomStatus"); } else { return; } List z_list = new ArrayList(); String fuID = rev.getStringProperty("item_id"); String idlast =fuID.substring(fuID.length()-2, fuID.length()); if(idlast.endsWith("-Y")) { fuID = fuID.substring(0,fuID.length()-2); } // fuID = fuID.replace("-Y", ""); String fuType = rev.getStringProperty("object_type"); if ("T2_outsourceRevision".equals(fuType)) { String revId = rev.getStringProperty("item_revision_id"); //fuID = fuID + revId; } fatherBean.setPinhao(fuID); fatherBean.setItem_uid(rev.getUid()); int childLineNum = 0; boolean ispack = false; for (int i = 0; i < childrens.length; i++) { InterfaceAIFComponent childComp = childrens[i].getComponent(); if ((childComp instanceof TCComponentBOMLine)) { TCComponentBOMLine childLine = (TCComponentBOMLine)childComp; String occType = childLine.getStringProperty("TCAI_OCC_TYPE"); String num = childLine.getStringProperty( "T2_ActualConsumption");//实际用量 if(num==null||"".equals(num.trim())) { num = childLine.getStringProperty( "T2_DesignQuantity");//设计用量 if(num==null||"".equals(num.trim())) { num = childLine.getStringProperty( "bl_quantity");//用量 if(num==null||"".equals(num.trim())) { num = "1"; } } } System.out.println("num=============="+num); //如果是数量为“已打包的注释”则解包 if(childLine.isPacked() || "已打包的注释".equals(num) || "已打包的注释".equals(occType)) { childLine.unpack(); ispack = true; childLine.refresh(); } } } if (ispack) { line.refresh(); } childrens = line.getChildren(); List idList = new ArrayList(); for (int i = 0; i < childrens.length; i++) { InterfaceAIFComponent childComp = childrens[i].getComponent(); if ((childComp instanceof TCComponentBOMLine)) { TCComponentBOMLine childLine = (TCComponentBOMLine)childComp; String occType = childLine.getStringProperty("TCAI_OCC_TYPE"); if (!"Reference".equals(occType)) { getChildValue(childLine, z_list, childLineNum,idList,pQty); childLineNum++; } } } fatherBean.setList(z_list); list.add(fatherBean); for (int i = 0; i < childrens.length; i++) { TCComponentBOMLine z_line = (TCComponentBOMLine)childrens[i].getComponent(); TCComponentItem item = z_line.getItem(); // String idString = item.getStringProperty("item_id"); // System.out.println("11.17id======"+idString); System.out.println("11.17z_line======="+z_line); System.out.println("11.17list======="+list); String type = item.getType(); System.out.println("type=============" + type); if (!("T2_OutBuyPart".equals(type)) && !("T2_outsource".equals(type))) { String occType = z_line.getStringProperty("TCAI_OCC_TYPE"); if (!"Reference".equals(occType)) { AIFComponentContext[] childrenAifs = z_line.getChildren(); if (childrenAifs.length > 0) { String childType = z_line.getItemRevision().getType(); if(childType.equals("T2_VirtualRevision") && isEquipment) { TCProperty tcProperty1 = z_line.getItemRevision().getTCProperty("release_status_list"); TCComponent[] targets1 = tcProperty1.getReferenceValueArray(); if(targets1==null || targets1.length<=0) { continue; } } String num = z_line.getStringProperty( "T2_ActualConsumption");//实际用量 if(num==null||"".equals(num.trim())) { num = z_line.getStringProperty( "T2_DesignQuantity");//设计用量 if(num==null||"".equals(num.trim())) { num = z_line.getStringProperty( "bl_quantity");//用量 if(num==null||"".equals(num.trim())) { num = "1"; } } } // z_line.getStringProperty("bl_") getBOMValue(z_line, list,Integer.valueOf(num)*pQty); } } } } } catch (TCException e) { e.printStackTrace(); } } private String toString(int num1) { // TODO Auto-generated method stub return null; } public void getChildValue(TCComponentBOMLine childLine, List z_list,int childLineNum,List idList,int pQty) { try { String occType = childLine.getStringProperty("TCAI_OCC_TYPE"); if("Reference".equals(occType)) { return; } String childID = childLine.getItem().getStringProperty("item_id"); String childtypeString = childLine.getItem().getStringProperty("object_type"); String childRevstring = childLine.getItemRevision().getStringProperty("item_revision_id"); if("T2_outsource".equals(childtypeString)) { StringBuilder sb = new StringBuilder(childID); //2022/8/23 取消拼接版本 //sb.append(childRevstring); childID = sb.toString(); } System.out.println("childID2============"+childID); String Quantity = childLine.getStringProperty( "T2_ActualConsumption");//实际用量 if(Quantity==null||"".equals(Quantity.trim())) { Quantity = childLine.getStringProperty( "T2_DesignQuantity");//设计用量 if(Quantity==null||"".equals(Quantity.trim())) { Quantity = childLine.getStringProperty( "bl_quantity");//用量 if(Quantity==null||"".equals(Quantity.trim())) { Quantity =1+"";//默认为1 } } } // int num = Integer.valueOf(Quantity)*pQty; // Quantity = String.valueOf(num); System.out.println("Quantity=============="+Quantity); if(idList.contains(childID)) { int index = idList.indexOf(childID); ChirldBomBean child = z_list.get(index); String yl = child.getYonglian(); double d1 = Double.parseDouble(yl); double d2 = 0; if(Quantity != null && !("".equals(Quantity.trim()))) { try { d2 = Double.parseDouble(Quantity); } catch (Exception e) { // TODO: handle exception d2 = 1; } }else { d2 = 1; } double d3 = d1 + d2; System.out.println("d3=============="+d3); child.setYonglian(d3+""); return; }else { idList.add(childID); } ChirldBomBean childBean = new ChirldBomBean(); //获取系统当前日期 SimpleDateFormat sdf =new SimpleDateFormat("YYYYMMdd"); String daatatext = sdf.format(new Date()); int j = 0; childBean.setNumber(childLineNum+1);//序号 childBean.setYonglian(Quantity); String childRev = childLine.getItemRevision().getStringProperty("item_revision_id"); String childType = childLine.getItem().getStringProperty("object_type"); // childID = childID.replace("-Y", ""); String idlast =childID.substring(childID.length()-2, childID.length()); System.out.println("id的后两位:"+idlast); // if(idlast.contains("-Y")) { // return; // } if(childID.endsWith("-Y")) { childID = childID.replace("-Y", ""); } System.out.println("childID============"+childID); System.out.println("childRev============"+childRev); System.out.println("childType============"+childType); // if("T2_outsource".equals(childType)) { // StringBuilder sb = new StringBuilder(childID); // sb.append(childRev); // childID = sb.toString(); // } childBean.setPinhao(childID);//元件。也就是品号 //将获取到的date类型转换为String类型 java.text.SimpleDateFormat formatter = new SimpleDateFormat( "yyyy/MM/dd"); Date released_time = childLine.getItemRevision().getDateProperty("last_mod_date"); String date = formatter.format(released_time);//获取创建时间 childBean.setDate(date);//生效日期 //外购 外协 要判断是否发布 childBean.setWork_id(childLine.getStringProperty("T2_JobNumber"));//作业编号 childBean.setBeizhu(childLine.getStringProperty("T2_remark"));//备注 childBean.setChajian_id(childLine.getStringProperty("T2_weihao"));//插件位置 // T2_DesignQuantity 设计用量 // T2_JobNumber 作业编号 // T2_remark 备注 // T2_weihao 位号 childBean.setPlmkey(childID+"-"+childLine.getItemRevision().getStringProperty("item_revision_id") );//PLMkey z_list.add(childBean); } catch (Exception e) { // TODO: handle exception } } public static String getId(){ String id=UUID.randomUUID().toString();//生成的id942cd30b-16c8-449e-8dc5-028f38495bb5中间含有横杠,用来生成数据库的主键id是很实用的。 id=id.replace("-", "");//替换掉中间的那个斜杠 return id; } }