|
|
|
@ -0,0 +1,221 @@
|
|
|
|
|
package com.connor.plm.process;
|
|
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import javax.swing.JOptionPane;
|
|
|
|
|
|
|
|
|
|
import com.connor.chint.sap2.util.MyProgressBarCompent;
|
|
|
|
|
import com.connor.chint.sap2.util.SAPMessageUtilFram;
|
|
|
|
|
import com.connor.chint.sap2.util.SAPUtil;
|
|
|
|
|
import com.connor.chint.sap2.util.SqlUtil;
|
|
|
|
|
import com.connor.chint.yunpi.KCommand;
|
|
|
|
|
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
|
|
|
|
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
|
|
|
|
|
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
|
|
|
|
import com.teamcenter.rac.aifrcp.AIFUtility;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponent;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponentBOMLine;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponentItem;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCPreferenceService;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCSession;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCUserService;
|
|
|
|
|
import com.teamcenter.rac.util.MessageBox;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能描述: 功能叠加-工艺路线指派功能+自动投料功能
|
|
|
|
|
* 创建日期:2024-04-18
|
|
|
|
|
* @author 李冬阳
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
|
public class AssProcessAutoFeedingCommand extends KCommand {
|
|
|
|
|
|
|
|
|
|
public AssProcessAutoFeedingCommand(AbstractAIFApplication app, String commandId, String actionInfo) {
|
|
|
|
|
super(app, commandId, actionInfo);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
InterfaceAIFComponent targetComponent = app.getTargetComponent();
|
|
|
|
|
TCSession session = (TCSession)app.getSession();
|
|
|
|
|
String groupID = SAPUtil.getGroupID(session);
|
|
|
|
|
if(!groupID.equals("M060")) {
|
|
|
|
|
MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("info1"), "", MessageBox.ERROR);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
TCComponentItemRevision rev;
|
|
|
|
|
if(targetComponent instanceof TCComponentBOMLine) {
|
|
|
|
|
rev = ((TCComponentBOMLine)targetComponent).getItemRevision();
|
|
|
|
|
}else if(targetComponent instanceof TCComponentItemRevision) {
|
|
|
|
|
rev = (TCComponentItemRevision) targetComponent;
|
|
|
|
|
}else {
|
|
|
|
|
MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("info2"), "", MessageBox.ERROR);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(!rev.getType().equals("Part Revision")) {
|
|
|
|
|
MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("info3"), "", MessageBox.ERROR);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
new Thread() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
MyProgressBarCompent comp = null;
|
|
|
|
|
try {
|
|
|
|
|
// TCComponentItemRevision pRevision = getPRevision(rev);
|
|
|
|
|
TCComponentItemRevision topZzItem = getTopZzItem(rev);
|
|
|
|
|
String name = rev.getProperty("object_name");
|
|
|
|
|
String property = topZzItem.getProperty("zt2_ifpbom");
|
|
|
|
|
if(!property.equals("P") && topZzItem.getStringProperty("object_desc").contains("1ZDB300000P")) {
|
|
|
|
|
MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("info3"), "", MessageBox.ERROR);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
boolean isback = false;
|
|
|
|
|
TCPreferenceService service = session.getPreferenceService();
|
|
|
|
|
String[] rules = service.getStringValues("CHINT_PROCESS_RULE");
|
|
|
|
|
for(String rule : rules) {
|
|
|
|
|
String[] split = rule.split(":");
|
|
|
|
|
if(!split[0].equals(groupID))
|
|
|
|
|
continue;
|
|
|
|
|
String[] backs = split[1].split(";");
|
|
|
|
|
for(String back : backs) {
|
|
|
|
|
System.out.println(name + "==" + back + ">>" + name.contains(back));
|
|
|
|
|
if(name.contains(back)) {
|
|
|
|
|
isback = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(isback)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
TCComponentItemRevision desginRev = (TCComponentItemRevision) topZzItem.getRelatedComponent("TC_Is_Represented_By");
|
|
|
|
|
System.out.println("topZzItem==" + topZzItem.toString() + ">>" + isback);
|
|
|
|
|
if(isback) {
|
|
|
|
|
AIFComponentContext[] folders = topZzItem.getItem()
|
|
|
|
|
.whereReferencedByTypeRelation(new String[] { "ZT2_ProjectFolder" }, null);//new String[] { "contents" }
|
|
|
|
|
if(folders.length == 0) {
|
|
|
|
|
MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("info4"), "INFO", MessageBox.WARNING);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
AIFComponentContext[] ccps = folders[0].getComponent().getChildren();
|
|
|
|
|
System.out.println(folders[0].getComponent() + "==>" + ccps.length);
|
|
|
|
|
for(AIFComponentContext aifcc : ccps) {
|
|
|
|
|
TCComponentItem item = (TCComponentItem) aifcc.getComponent();
|
|
|
|
|
desginRev = (TCComponentItemRevision) item.getLatestItemRevision().getRelatedComponent("TC_Is_Represented_By");
|
|
|
|
|
System.out.println(item + "==>" + desginRev);
|
|
|
|
|
if(desginRev != null)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(desginRev == null) {
|
|
|
|
|
MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("info5"), "INFO", MessageBox.WARNING);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Map<String, String> classificationAttributes = desginRev.getItem().getClassificationAttributes();
|
|
|
|
|
System.out.println(classificationAttributes.toString());
|
|
|
|
|
|
|
|
|
|
for(String key : classificationAttributes.keySet()) {
|
|
|
|
|
if(key.equals(PlmLocale.getString("cpxh"))) {
|
|
|
|
|
String cphx = classificationAttributes.get(key);
|
|
|
|
|
String sql = "SELECT \"ProductZu\" FROM \"CHINT_WORKHOUR_WhProductXH\" where \"ProductXH\" = '"+cphx+"'";
|
|
|
|
|
String[] prefs = service.getStringValues("database_tc");
|
|
|
|
|
SqlUtil.getTCDataConnection(prefs);
|
|
|
|
|
ResultSet read2 = SqlUtil.read(sql);
|
|
|
|
|
if(!read2.next()) {
|
|
|
|
|
String searchSql = "SELECT distinct \"ProductZu\" FROM \"CHINT_WORKHOUR_WhProductXH\" where \"COMPANYCODE\" = 'M060'";
|
|
|
|
|
ResultSet read = SqlUtil.read(searchSql);
|
|
|
|
|
List<String> productZuList = new ArrayList<String>();
|
|
|
|
|
while(read.next()){
|
|
|
|
|
productZuList.add(read.getString(1));
|
|
|
|
|
}
|
|
|
|
|
System.out.println(productZuList.toString());
|
|
|
|
|
String[] array = productZuList.toArray(new String[] {});
|
|
|
|
|
Object showInputDialog = JOptionPane.showInputDialog(null, PlmLocale.getString("info6"), "INFO",
|
|
|
|
|
JOptionPane.QUESTION_MESSAGE, null, array,array[0]);
|
|
|
|
|
if(showInputDialog == null) {
|
|
|
|
|
return;
|
|
|
|
|
}else {
|
|
|
|
|
System.out.println("showInputDialog:" + showInputDialog.toString());
|
|
|
|
|
String insertSql = "INSERT INTO \"CHINT_WORKHOUR_WhProductXH\" "
|
|
|
|
|
+ "(\"ProductXH\",\"ProductZu\",\"COMPANYCODE\") "
|
|
|
|
|
+ "VALUES (?,?,?)";
|
|
|
|
|
SqlUtil.write(insertSql, new Object[] { cphx, showInputDialog.toString(), "M060" });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comp = new MyProgressBarCompent("", PlmLocale.getString("info7"));
|
|
|
|
|
TCUserService userService = (TCUserService) session.getUserService();
|
|
|
|
|
Object call = userService.call("CloneTempProcess", new Object[] { rev.getUid() });
|
|
|
|
|
String assignResult = call.toString();
|
|
|
|
|
System.out.println(assignResult);
|
|
|
|
|
if(!assignResult.equals("succ")) {
|
|
|
|
|
comp.setVisible(false);
|
|
|
|
|
new SAPMessageUtilFram("", PlmLocale.getString("info8") + assignResult);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comp.setShowLabel(PlmLocale.getString("info9"));
|
|
|
|
|
call = userService.call("AutoFeeding", new Object[] { rev.getUid() });
|
|
|
|
|
comp.setVisible(false);
|
|
|
|
|
String feedResult = call.toString();
|
|
|
|
|
System.out.println(feedResult);
|
|
|
|
|
|
|
|
|
|
boolean succ = true;
|
|
|
|
|
if(!feedResult.equals("succ")) {
|
|
|
|
|
new SAPMessageUtilFram("", PlmLocale.getString("info10") + feedResult);
|
|
|
|
|
}else if(succ) {
|
|
|
|
|
MessageBox.post(PlmLocale.getString("info11"), "INFO", MessageBox.INFORMATION);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e1) {
|
|
|
|
|
e1.printStackTrace();
|
|
|
|
|
MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("err") + e1.toString(), "", MessageBox.ERROR);
|
|
|
|
|
}finally {
|
|
|
|
|
SqlUtil.freeAll();
|
|
|
|
|
if(comp != null) {
|
|
|
|
|
comp.dispose();//.setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}.start();
|
|
|
|
|
}catch(Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
MessageBox.post(AIFUtility.getActiveDesktop(), PlmLocale.getString("err") + e.toString(), "", MessageBox.ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 获取总装(BOM顶层)
|
|
|
|
|
* @param rev 目标对象
|
|
|
|
|
* @return BOM顶层版本
|
|
|
|
|
*/
|
|
|
|
|
private TCComponentItemRevision getTopZzItem(TCComponentItemRevision rev) throws Exception {
|
|
|
|
|
TCComponent[] whereUsed = rev.whereUsed((short)0);
|
|
|
|
|
if(whereUsed.length==0) {
|
|
|
|
|
return rev;
|
|
|
|
|
}else {
|
|
|
|
|
List<TCComponentItemRevision> revPs = new ArrayList<TCComponentItemRevision>();
|
|
|
|
|
for(int i = 0; i < whereUsed.length; i++) {
|
|
|
|
|
TCComponentItemRevision revP = (TCComponentItemRevision)whereUsed[i];
|
|
|
|
|
if(revP.getType().contains("Part")) {
|
|
|
|
|
revPs.add(revP);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for(TCComponentItemRevision revP : revPs) {
|
|
|
|
|
if(revPs.size()>1) {
|
|
|
|
|
// TCComponentItemRevision revP = (TCComponentItemRevision)whereUsed[i];
|
|
|
|
|
String property = revP.getProperty("zt2_ifpbom");
|
|
|
|
|
if(property == null || !property.equals("P")) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
TCComponentItemRevision item = getTopZzItem(revP);
|
|
|
|
|
if(item != null) {
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|