|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
package com.connor.chint.yunpi.command;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.BufferedWriter;
|
|
|
|
|
import java.io.FileWriter;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
@ -57,6 +59,8 @@ import com.teamcenter.rac.kernel.TCComponentBOMLine;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponentBOMWindowType;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponentDataset;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponentDatasetType;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponentFolder;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponentGroup;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponentICO;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponentItem;
|
|
|
|
@ -87,7 +91,7 @@ public class ZxjcController {
|
|
|
|
|
public List<ZxjcBean> partList = new ArrayList<>();
|
|
|
|
|
public ZxjcFram dialog;
|
|
|
|
|
private SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
private StringBuffer logStr = new StringBuffer();
|
|
|
|
|
public ZxjcController(ZxjcFram sapzyDialog, AbstractAIFApplication app) {
|
|
|
|
|
this.app = app;
|
|
|
|
|
this.session = (TCSession) app.getSession();
|
|
|
|
@ -102,6 +106,7 @@ public class ZxjcController {
|
|
|
|
|
project = (TCComponent) target;
|
|
|
|
|
|
|
|
|
|
zt2_ProjectNo = project.getProperty("zt2_ProjectNo");
|
|
|
|
|
|
|
|
|
|
wbs = project.getProperty("zt2_WBSNo");
|
|
|
|
|
System.out.println("检查对象:" + target);
|
|
|
|
|
List<TCComponentItemRevision> partRevList = KUtil.getCCPFromProject(project);
|
|
|
|
@ -159,6 +164,7 @@ public class ZxjcController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
|
|
|
|
|
private boolean isSucc = false;
|
|
|
|
|
|
|
|
|
|
public static String getXML() {
|
|
|
|
|
String soapXML = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:chintelectric.com:xi:plm\">\r\n"
|
|
|
|
@ -216,6 +222,8 @@ public class ZxjcController {
|
|
|
|
|
String cpxhValue = "";
|
|
|
|
|
String project_object_name = project.getStringProperty("object_name");
|
|
|
|
|
String project_zt2_ProjectNo = project.getStringProperty("zt2_ProjectNo");
|
|
|
|
|
String zt2_ProjectCode = project.getStringProperty("zt2_ProjectCode");
|
|
|
|
|
logStr.append("项目号==="+project_zt2_ProjectNo+"\n");
|
|
|
|
|
String project_zt2_WBSNo = project.getStringProperty("zt2_WBSNo");
|
|
|
|
|
// 获取项目所有者的工厂
|
|
|
|
|
// TCComponentGroup group = (TCComponentGroup) project.getRelatedComponent("owning_group");
|
|
|
|
@ -1172,48 +1180,109 @@ public class ZxjcController {
|
|
|
|
|
String strUrl = url[0];
|
|
|
|
|
String resultStr = sendRequest(strUrl, top);
|
|
|
|
|
System.out.println("resultStr=======" + resultStr);
|
|
|
|
|
if(resultStr.equals("请求成功")) {
|
|
|
|
|
isSucc = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//飞书通知
|
|
|
|
|
String userName = session.getUserName();
|
|
|
|
|
String userId = session.getUser().getUserId();
|
|
|
|
|
JSONObject msgJson = new JSONObject();
|
|
|
|
|
msgJson.put("mobiles", new String[] {});
|
|
|
|
|
userId+="@chint.com";
|
|
|
|
|
msgJson.put("emails", new String[] {userId});
|
|
|
|
|
msgJson.put("sms", false);
|
|
|
|
|
msgJson.put(
|
|
|
|
|
"content",
|
|
|
|
|
userName+"提交的"+project_zt2_ProjectNo+"项目的拆卸一览表信息已成功推送至装箱系统,请登陆装箱系统查阅。");
|
|
|
|
|
// String result = okHttpCli.doPostJson(finalUrl, msgJson.toJSONString());
|
|
|
|
|
|
|
|
|
|
URL fsurl = new URL("http://10.128.10.170/api/feishu/Message/sendMessages");
|
|
|
|
|
HttpURLConnection connection = (HttpURLConnection) fsurl.openConnection();
|
|
|
|
|
connection.setRequestMethod("POST");
|
|
|
|
|
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
|
|
|
|
connection.setRequestProperty("Accept", "application/json");
|
|
|
|
|
connection.setDoOutput(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OutputStream outputStream = connection.getOutputStream();
|
|
|
|
|
outputStream.write(msgJson.toString().getBytes("UTF-8"));
|
|
|
|
|
outputStream.flush();
|
|
|
|
|
|
|
|
|
|
int responseCode = connection.getResponseCode();
|
|
|
|
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
throw new RuntimeException("飞书发送失败 : " + responseCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("msgJson.toString() ==>"+msgJson.toString());
|
|
|
|
|
//飞书通知
|
|
|
|
|
String userName = session.getUserName();
|
|
|
|
|
String userId = session.getUser().getUserId();
|
|
|
|
|
JSONObject msgJson = new JSONObject();
|
|
|
|
|
msgJson.put("mobiles", new String[] {});
|
|
|
|
|
userId+="@chint.com";
|
|
|
|
|
msgJson.put("emails", new String[] {userId});
|
|
|
|
|
msgJson.put("sms", false);
|
|
|
|
|
msgJson.put(
|
|
|
|
|
"content",
|
|
|
|
|
userName+"提交的"+project_zt2_ProjectNo+"项目的拆卸一览表信息已成功推送至装箱系统,请登陆装箱系统查阅。");
|
|
|
|
|
// String result = okHttpCli.doPostJson(finalUrl, msgJson.toJSONString());
|
|
|
|
|
|
|
|
|
|
URL fsurl = new URL("http://10.128.10.170/api/feishu/Message/sendMessages");
|
|
|
|
|
HttpURLConnection connection = (HttpURLConnection) fsurl.openConnection();
|
|
|
|
|
connection.setRequestMethod("POST");
|
|
|
|
|
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
|
|
|
|
connection.setRequestProperty("Accept", "application/json");
|
|
|
|
|
connection.setDoOutput(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OutputStream outputStream = connection.getOutputStream();
|
|
|
|
|
outputStream.write(msgJson.toString().getBytes("UTF-8"));
|
|
|
|
|
outputStream.flush();
|
|
|
|
|
|
|
|
|
|
int responseCode = connection.getResponseCode();
|
|
|
|
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
|
|
|
System.out.println("飞书发送成功");
|
|
|
|
|
} else {
|
|
|
|
|
throw new RuntimeException("飞书发送失败 : " + responseCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logStr.append("飞书通知返回值Json==="+msgJson.toString()+"\n");
|
|
|
|
|
System.out.println("msgJson.toString() ==>"+msgJson.toString());
|
|
|
|
|
|
|
|
|
|
//日志放到项目对像下的“项目监控”文件夹下。
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
|
|
|
|
|
String timeStr = sdf.format(new Date());
|
|
|
|
|
String fileName = "";
|
|
|
|
|
if(isSucc) {
|
|
|
|
|
fileName = "装箱集成日志-"+zt2_ProjectCode+"-"+userName+"-"+timeStr+"-成功";
|
|
|
|
|
}else {
|
|
|
|
|
fileName = "装箱集成日志-"+zt2_ProjectCode+"-"+userName+"-"+timeStr+"-失败";
|
|
|
|
|
}
|
|
|
|
|
String filePath = System.getenv("TEMP") + "\\"+fileName+".txt";
|
|
|
|
|
|
|
|
|
|
//把日志写到文件中
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 使用FileWriter打开一个写文件流,true表示追加模式,文件存在则在文件末尾追加内容
|
|
|
|
|
BufferedWriter writer = new BufferedWriter(new FileWriter(filePath, true));
|
|
|
|
|
|
|
|
|
|
// 将日志信息写入文件
|
|
|
|
|
writer.write(logStr.toString());
|
|
|
|
|
|
|
|
|
|
// 刷新缓冲区,确保数据立即写入文件
|
|
|
|
|
writer.flush();
|
|
|
|
|
|
|
|
|
|
// 关闭写入流
|
|
|
|
|
writer.close();
|
|
|
|
|
|
|
|
|
|
System.out.println("日志记录成功!");
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
System.err.println("写入日志时发生错误:" + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取文件夹
|
|
|
|
|
TCComponentFolder projectMonitorFolder = getXMJKFolderFromProject(project);
|
|
|
|
|
//创建数据集放到文件夹下
|
|
|
|
|
if(projectMonitorFolder != null) {
|
|
|
|
|
savaLogAtClient(projectMonitorFolder,filePath,fileName, session);
|
|
|
|
|
System.out.println("日志存放成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 获得项目监控文件夹 */
|
|
|
|
|
public static TCComponentFolder getXMJKFolderFromProject(TCComponent targetComp) throws TCException {
|
|
|
|
|
TCComponent[] refs = targetComp.getRelatedComponents("IMAN_reference");
|
|
|
|
|
int len = refs == null ? 0 : refs.length;
|
|
|
|
|
TCComponentFolder projMontor = null;
|
|
|
|
|
System.out.println("查找项目监控文件夹:" + targetComp);
|
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
|
String cName = refs[i].getProperty("object_name");
|
|
|
|
|
System.out.println(">> 找到子对象:" + cName);
|
|
|
|
|
if ((refs[i] instanceof TCComponentFolder) && "项目监控".contains(cName)) {
|
|
|
|
|
projMontor = (TCComponentFolder) refs[i];
|
|
|
|
|
return projMontor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String sendRequest(String apiUrl, JSONObject jsonToSend) throws Exception {
|
|
|
|
|
URL url = new URL(apiUrl);
|
|
|
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
|
@ -1223,6 +1292,7 @@ public class ZxjcController {
|
|
|
|
|
connection.setDoOutput(true);
|
|
|
|
|
|
|
|
|
|
OutputStream outputStream = connection.getOutputStream();
|
|
|
|
|
logStr.append("发送的Json==="+jsonToSend.toString()+"\n");
|
|
|
|
|
outputStream.write(jsonToSend.toString().getBytes("UTF-8"));
|
|
|
|
|
outputStream.flush();
|
|
|
|
|
|
|
|
|
@ -1238,7 +1308,7 @@ public class ZxjcController {
|
|
|
|
|
}
|
|
|
|
|
JSONObject resultJson = JSON.parseObject(response.toString());
|
|
|
|
|
String msg = (String) resultJson.get("msg");
|
|
|
|
|
|
|
|
|
|
logStr.append("返回的Json==="+resultJson.toString()+"\n");
|
|
|
|
|
// 将响应内容解析为JSON对象
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
@ -1270,6 +1340,23 @@ public class ZxjcController {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//上传日志到指定文件夹下
|
|
|
|
|
public static void savaLogAtClient(TCComponent projectMonitorFolder, String mergeTxtPath,String title, TCSession session)
|
|
|
|
|
throws TCException {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
TCComponentDatasetType tccomponentDatasetType = (TCComponentDatasetType) session.getTypeComponent("Dataset");
|
|
|
|
|
TCComponentDataset tccomponentDataset = tccomponentDatasetType
|
|
|
|
|
.create(title, "", "Text");
|
|
|
|
|
tccomponentDataset.lock();
|
|
|
|
|
tccomponentDataset.setFiles(new String[] { mergeTxtPath }, new String[] { "Text" });
|
|
|
|
|
tccomponentDataset.save();
|
|
|
|
|
tccomponentDataset.unlock();
|
|
|
|
|
projectMonitorFolder.add("contents", tccomponentDataset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static TCComponentBOMLine getBOMLine(TCSession session, TCComponentItemRevision revision) {
|
|
|
|
|
TCComponentBOMLine bomLine = null;
|
|
|
|
|
try {
|
|
|
|
|