Commit c2952291 authored by shyWang's avatar shyWang

PDM前端改造

PBOM签审PBOM数据同步
parent 4c888858
......@@ -24,6 +24,8 @@ import java.util.Map;
public class SearchOperatorEnumUtil {
public static final String DEX_URL = "http://162.14.109.151:9002/";
public static final String DX_VIEWID = "dxViewId";
public static final String DX_ID = "id";
......
package com.yonde.common;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Map;
/**
* https请求工具类
*
* @author seer
* @date 2018/3/6 9:12
*/
public class HttpsUtils {
/*
* https请求是在http请求的基础上加上一个ssl层
*/
public static String doPost(String requestUrl, String bodyStr, Map<String, String> header, String charset, String contentType) throws Exception {
System.out.printf("--- https post 请求地址:%s 内容:%s", requestUrl, bodyStr);
charset = null == charset ? "utf-8" : charset;
// 创建SSLContext
SSLContext sslContext = SSLContext.getInstance("SSL");
TrustManager[] trustManagers = {new X509TrustManager() {
/*
* 实例化一个信任连接管理器
* 空实现是所有的连接都能访问
*/
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}};
// 初始化
sslContext.init(null, trustManagers, new SecureRandom());
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
URL url = new URL(requestUrl);
HttpURLConnection httpsURLConnection = (HttpURLConnection) url.openConnection();
//HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
//httpsURLConnection.setSSLSocketFactory(sslSocketFactory);
// 以下参照http请求
httpsURLConnection.setDoOutput(true);
httpsURLConnection.setDoInput(true);
httpsURLConnection.setUseCaches(false);
httpsURLConnection.setRequestMethod("POST");
httpsURLConnection.setRequestProperty("Accept-Charset", charset);
httpsURLConnection.setRequestProperty("Dex-Auth-Type", "Ukey");
httpsURLConnection.setRequestProperty("Dex-Ukey-Token", "EGodShy5fsbE5NM9YGh2O+wjA/oilVAYt0qmGCvwPDg/q6vfnUK4kn4MDkjX2urCoO0hDgbudWIoW4AIH+beiQ==");
if (null != bodyStr) {
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(bodyStr.length()));
}
if (contentType == null) {
httpsURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
} else {
httpsURLConnection.setRequestProperty("Content-Type", contentType);
}
if (!header.isEmpty()) {
for (Map.Entry<String, String> entry : header.entrySet()) {
httpsURLConnection.setRequestProperty(entry.getKey(), entry.getValue());
}
}
httpsURLConnection.connect();
// 读写内容
OutputStream outputStream = null;
InputStream inputStream = null;
InputStreamReader streamReader = null;
BufferedReader bufferedReader = null;
StringBuffer stringBuffer;
try {
if (null != bodyStr) {
outputStream = httpsURLConnection.getOutputStream();
outputStream.write(bodyStr.getBytes(charset));
outputStream.close();
}
if (httpsURLConnection.getResponseCode() >= 300) {
throw new Exception("https post failed, response code " + httpsURLConnection.getResponseCode());
}
inputStream = httpsURLConnection.getInputStream();
streamReader = new InputStreamReader(inputStream, charset);
bufferedReader = new BufferedReader(streamReader);
stringBuffer = new StringBuffer();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line);
}
} catch (Exception e) {
throw e;
} finally {
if (outputStream != null) {
outputStream.close();
}
if (inputStream != null) {
inputStream.close();
}
if (streamReader != null) {
streamReader.close();
}
if (bufferedReader != null) {
bufferedReader.close();
}
}
System.out.printf("--- https post 返回内容:%s", stringBuffer.toString());
return stringBuffer.toString();
}
public static void main(String[] args) {
String url = args[0];
String content = args[1];
try {
HttpsUtils.doPost(url, content, null, null, null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.yonde.wfc.util;
import com.alibaba.fastjson.JSON;
import com.yonde.basedata.search.SearchOperatorEnumUtil;
import com.yonde.common.DxPartUtil;
import com.yonde.common.HttpsUtils;
import com.yonde.common.ObjectsUtil;
import com.yonde.common.PartUtil;
import com.yonde.part.bean.PdmPartBean;
import wt.fc.Persistable;
import wt.fc.QueryResult;
import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.part.WTPart;
import wt.part.WTPartHelper;
import wt.part.WTPartMaster;
import wt.part.WTPartUsageLink;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class WorkflowUtils implements RemoteAccess {
/**
* 同步pdm数据
*
* @return
*/
public static void synPlanningPart(Persistable pbo) throws Exception {
if (!RemoteMethodServer.ServerFlag) {
RemoteMethodServer.getDefault().invoke("synPlanningPart", WorkflowUtils.class.getName(), null,
new Class[] { Persistable.class },
new Object[] { pbo });
return;
}
//获取同步数据
List<PdmPartBean> pdmPartBeanList = new ArrayList<PdmPartBean>();
if (pbo instanceof WTPart) {
WTPart wtPart = (WTPart) pbo;
PdmPartBean pdmPartBean = new PdmPartBean(wtPart);
pdmPartBeanList.add(pdmPartBean);
cyclicBuildPartBean(wtPart, pdmPartBeanList);
}
String pdmPartBeanStr = JSON.toJSONString(pdmPartBeanList);
//调用同步接口
HttpsUtils.doPost(SearchOperatorEnumUtil.DEX_URL + "DxPartSync/syncPart",pdmPartBeanStr,new HashMap<String, String>(),null, "application/json");
}
public static void cyclicBuildPartBean(WTPart wtPart, List<PdmPartBean> beanList) throws Exception {
QueryResult partMasters = WTPartHelper.service.getUsesWTPartMasters(wtPart);
while (partMasters.hasMoreElements()) {
WTPartUsageLink link = (WTPartUsageLink) partMasters.nextElement();
PdmPartBean pdmPartBean = new PdmPartBean(link);
beanList.add(pdmPartBean);
WTPartMaster uses = (WTPartMaster) link.getUses();
WTPart child = PartUtil.getLatestPartByNoViewWithState(uses.getNumber(), pdmPartBean.getViewType(), null, false);
if (ObjectsUtil.nonNull(child)) {
cyclicBuildPartBean(child, beanList);
}
}
}
public static void main(String[] args) {
RemoteMethodServer.getDefault().setUserName(args[0]);
RemoteMethodServer.getDefault().setPassword(args[1]);
try {
String result = testApi(args[2]);
System.out.println("callBack2>>>>>>>>>body=" + result);
} catch (Exception e) {
e.printStackTrace();
}
}
public static String testApi(String id) throws Exception {
if (!RemoteMethodServer.ServerFlag) {
return (String) RemoteMethodServer.getDefault().invoke("testApi", WorkflowUtils.class.getName(), null,
new Class[] { String.class },
new Object[] { id });
}
String result = "";
WTPart partById = DxPartUtil.getPartById(Long.valueOf(id));
synPlanningPart(partById);
result = "成功!";
return result;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment