You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.0 KiB
107 lines
3.0 KiB
package com.connor.rb.plm.rb027;
|
|
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
import org.apache.http.client.methods.HttpGet;
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
import org.apache.http.impl.client.HttpClients;
|
|
import org.apache.http.util.EntityUtils;
|
|
|
|
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
|
import com.teamcenter.rac.aif.AbstractAIFCommand;
|
|
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
|
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
|
import com.teamcenter.rac.kernel.TCSession;
|
|
import com.teamcenter.rac.util.MessageBox;
|
|
|
|
import net.sf.json.JSONArray;
|
|
import net.sf.json.JSONObject;
|
|
|
|
|
|
public class GetNumberCommand extends AbstractAIFCommand {
|
|
private AbstractAIFApplication app;
|
|
private TCSession session;
|
|
|
|
|
|
public GetNumberCommand(AbstractAIFApplication app, TCSession session) {
|
|
// TODO Auto-generated constructor stub
|
|
this.app = app;
|
|
this.session = session;
|
|
}
|
|
|
|
@Override
|
|
public void executeModal() throws Exception {
|
|
// TODO Auto-generated method stub
|
|
//获取选中对象
|
|
InterfaceAIFComponent comp = app.getTargetComponent();
|
|
|
|
if(!(comp instanceof TCComponentItemRevision))
|
|
{
|
|
MessageBox.post("请选中版本对象!", "错误", MessageBox.ERROR);
|
|
return;
|
|
}
|
|
|
|
TCComponentItemRevision itemRevision = (TCComponentItemRevision) comp;
|
|
String result = sendPost("http://10.20.7.27:9889/jde/getNumber");
|
|
System.out.println(result);
|
|
//获取返回结果
|
|
JSONObject resultJson = JSONObject.fromObject(result);
|
|
|
|
|
|
JSONArray jsonArray = resultJson.getJSONArray("data");
|
|
for (int i=0; i < jsonArray.size(); i++) {
|
|
|
|
//获取autoNextNumber
|
|
String autoNextNumber = "";
|
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
Iterator iter = jsonObject.entrySet().iterator();
|
|
while (iter.hasNext()) {
|
|
Map.Entry entry = (Map.Entry) iter.next();
|
|
System.out.println(entry.getKey().toString());
|
|
switch (entry.getKey().toString()) {
|
|
case "autoNextNumber":
|
|
System.out.println(entry.getValue().toString());
|
|
autoNextNumber = entry.getValue().toString();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
itemRevision.setStringProperty("rb3_spm", autoNextNumber);
|
|
itemRevision.refresh();
|
|
MessageBox.post("获取商品码成功!", "成功", MessageBox.INFORMATION);
|
|
return;
|
|
}
|
|
super.executeModal();
|
|
}
|
|
public static String sendPost(String url) {
|
|
String response = null;
|
|
|
|
try {
|
|
CloseableHttpClient httpclient = null;
|
|
CloseableHttpResponse httpresponse = null;
|
|
try {
|
|
httpclient = HttpClients.createDefault();
|
|
HttpGet httpGet = new HttpGet(url);
|
|
httpresponse = httpclient.execute(httpGet);
|
|
response = EntityUtils.toString(httpresponse.getEntity());
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
} finally {
|
|
if (httpclient != null) {
|
|
httpclient.close();
|
|
}
|
|
if (httpresponse != null) {
|
|
httpresponse.close();
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return response;
|
|
}
|
|
|
|
}
|