|
|
package com.connor.bhdz.pdm.partToCapp;
|
|
|
|
|
|
import java.awt.Frame;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import com.connor.bhdz.pdm.assets.Constants;
|
|
|
import com.connor.bhdz.pdm.drawingToCapp.ConnOra;
|
|
|
import com.connor.bhdz.pdm.drawingToCapp.ProgressBarThread;
|
|
|
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
|
|
import com.teamcenter.rac.aif.common.actions.AbstractAIFAction;
|
|
|
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
|
|
|
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
|
|
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.TCComponentForm;
|
|
|
import com.teamcenter.rac.kernel.TCComponentItem;
|
|
|
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
|
|
import com.teamcenter.rac.kernel.TCComponentUser;
|
|
|
import com.teamcenter.rac.kernel.TCException;
|
|
|
import com.teamcenter.rac.kernel.TCSession;
|
|
|
import com.teamcenter.rac.util.MessageBox;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpException;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
|
public class SendPartToCappAction extends AbstractAIFAction {
|
|
|
private AbstractAIFApplication application;
|
|
|
private TCSession session;
|
|
|
|
|
|
protected SendPartToCappAction(AbstractAIFApplication application, Frame frame, String param) {
|
|
|
super(application, frame, param);
|
|
|
this.application = application;
|
|
|
this.session = (TCSession) application.getSession();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* »ñÈ¡µ±Ç°Ê±¼ä£¬¸ñʽΪ"yyyy-MM-dd HH-mm-ss"
|
|
|
* @return String
|
|
|
*/
|
|
|
private String getCurrentTime() {
|
|
|
System.out.println("getCurrentTime·½·¨¿ªÊ¼Ö´ÐÐ");
|
|
|
// »ñÈ¡µ±Ç°Ê±¼ä
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
|
// ¶¨Òå×Ô¶¨ÒåÈÕÆÚʱ¼ä¸ñʽ
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss");
|
|
|
|
|
|
// ¸ñʽ»¯µ±Ç°Ê±¼ä
|
|
|
String formattedDate = now.format(formatter);
|
|
|
|
|
|
return formattedDate;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* ±éÀúBOMÐУ¬×éÖ¯BOMÊôÐÔ´æ´¢µ½Êý¾Ý¿âBOM ±íÖÐ
|
|
|
* @param bomLine ¸¸ÏîbomÐÐ
|
|
|
* @throws TCException
|
|
|
* @throws SQLException
|
|
|
*/
|
|
|
// private void throwBom(TCComponentBOMLine bomLine) throws TCException, SQLException {
|
|
|
// // TODO Auto-generated method stub
|
|
|
// //»ñÈ¡¸¸ÏîBOMÐÅÏ¢
|
|
|
// TCComponentItem item = bomLine.getItem();
|
|
|
// TCComponentItemRevision itemRevision = bomLine.getItemRevision();
|
|
|
// String parent = item.getProperty("item_id");//¸¸ÏîÎïÁÏͼºÅ
|
|
|
// String parentversion = itemRevision.getProperty("item_revision_id");//¸¸ÏîÎïÁϰ汾
|
|
|
// String parentname = item.getProperty("object_name");//¸¸ÏîÎïÁÏÃû³Æ
|
|
|
//
|
|
|
// //±éÀú×ÓÏîBOM£¬»ñÈ¡×ÓÏîÐÅÏ¢²¢±£´æ
|
|
|
// if (bomLine.hasChildren()) {
|
|
|
// AIFComponentContext[] childrens = bomLine.getChildren();
|
|
|
// for (AIFComponentContext children : childrens) {
|
|
|
// TCComponentBOMLine bomLineChild = (TCComponentBOMLine) children.getComponent();
|
|
|
// TCComponentItem childItem = bomLineChild.getItem();
|
|
|
// TCComponentItemRevision childItemRevision = bomLineChild.getItemRevision();
|
|
|
// //±£´æ×ÓÏîµÄÎïÁÏÐÅÏ¢µ½Êý¾Ý¿â±íÖÐ
|
|
|
//// savePart(childItemRevision);
|
|
|
// //×éÖ¯×ÓÏîÊôÐÔÐÅÏ¢£¬²¢ºÍ¸¸ÏîÐÅÏ¢Ò»Æð±£´æÎªÒ»ÌõÊý¾Ý
|
|
|
// String sub = childItem.getProperty("item_id");//×ÓÏîÎïÁϱàÂë
|
|
|
// String subversion = childItemRevision.getProperty("item_revision_id");//×ÓÏî°æ±¾ºÅ
|
|
|
// String subname = childItem.getProperty("object_name");//×ÓÏîÃû³Æ
|
|
|
// bomLineChild.lock();
|
|
|
// String lineno = bomLineChild.getProperty("bl_sequence_no");//×ÓÏîÐкÅ
|
|
|
// String quantity = bomLineChild.getProperty("bl_quantity");//×ÓÏîÊýÁ¿
|
|
|
// bomLineChild.unlock();
|
|
|
// String user = session.getUser().getUserName();//Ï·¢ÈËÔ±
|
|
|
// //TODO ¸ù¾Ý¸¸×ÓÏî°æ±¾ºÍÎïÁÏIDÈ·¶¨Î¨Ò»ÐÔ£¬²éѯÊÇ·ñÒѾ´æÔÚ¸ÃÌõBOMÊý¾Ý£¨ÈôÒÑ´æÔÚÔòÖ»±£´æ¡±¸üÐÂʱ¼ä¡±Îªµ±Ç°Ê±¼ä£»Èô²»´æÔÚÔò±£´æ¡°Ï·¢Ê±¼ä¡±ºÍ¡°¸üÐÂʱ¼ä¡±Îªµ±Ç°Ê±¼ä£©
|
|
|
// if (true/*²»´æÔÚ*/) {
|
|
|
// String issuedtime = getCurrentTime();
|
|
|
// String updatetime = getCurrentTime();
|
|
|
// //TODO ²åÈëÊý¾Ýµ½BOMÊý¾Ý¿â±íÖÐ
|
|
|
//
|
|
|
// }else {
|
|
|
// String updatetime = getCurrentTime();
|
|
|
// //TODO ¸üÐÂÊý¾Ýµ½BOMÊý¾Ý¿â±íÖÐ
|
|
|
//
|
|
|
// }
|
|
|
// throwBom(bomLineChild);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
public static boolean isReleased(TCComponent comp) throws Exception {
|
|
|
TCComponent[] status = comp.getReferenceListProperty("release_status_list");
|
|
|
if (status == null || status.length == 0) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
public static TCComponentItemRevision getLastReleaseRevison(TCComponentItem targetComp) throws Exception {
|
|
|
System.out.println("Get Last Released Revision: " + targetComp);
|
|
|
if (targetComp == null) {
|
|
|
return null;
|
|
|
}
|
|
|
List<TCComponentItemRevision> releaseRevisionList = new ArrayList<>();
|
|
|
TCComponent[] comps = targetComp.getReferenceListProperty("revision_list");
|
|
|
System.out.println(">> Revisions: " + Arrays.toString(comps));
|
|
|
for (TCComponent comp : comps) {
|
|
|
if (isReleased(comp)) {
|
|
|
releaseRevisionList.add((TCComponentItemRevision) comp);
|
|
|
}
|
|
|
}
|
|
|
System.out.println(">> Released Revisions: " + releaseRevisionList);
|
|
|
return releaseRevisionList.size() == 0 ? null : releaseRevisionList.get(releaseRevisionList.size() - 1);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public void run() {
|
|
|
ProgressBarThread thread = new ProgressBarThread("Ï·¢ÖÐ", "Ï·¢ÖÐ...");
|
|
|
thread.start();
|
|
|
|
|
|
InterfaceAIFComponent[] components = application.getTargetComponents();
|
|
|
try {
|
|
|
for (InterfaceAIFComponent selectComponent : components) {
|
|
|
String itemID = "";//Áã×é¼þID
|
|
|
String revID = "";//°æ±¾
|
|
|
String sql = "";
|
|
|
String toTaskRevId = "";//msg
|
|
|
if (selectComponent instanceof TCComponentItem) {
|
|
|
//Èç¹ûÑ¡ÖжÔÏóÊÇÎïÁ϶ÔÏóH8_wuliao
|
|
|
TCComponentItem item = (TCComponentItem) selectComponent;
|
|
|
//»ñÈ¡×îÐÂÒÑ·¢²¼°æ±¾¶ÔÏó-latestReleasedRev
|
|
|
TCComponentItemRevision latestItemRevision = getLastReleaseRevison(item);
|
|
|
if (latestItemRevision == null) {
|
|
|
System.out.println("µ±Ç°Ñ¡ÖжÔÏó²»´æÔÚÒÑ·¢²¼°æ±¾£¡ÎÞ·¨Ï·¢¡¤¡¤¡¤");
|
|
|
MessageBox.post("µ±Ç°Ñ¡ÖжÔÏó²»´æÔÚÒÑ·¢²¼°æ±¾£¡ÎÞ·¨Ï·¢¡¤¡¤¡¤","Ìáʾ",MessageBox.INFORMATION);
|
|
|
thread.setBool(true);
|
|
|
return;
|
|
|
}
|
|
|
revID = latestItemRevision.getProperty("item_revision_id");//CÓïÑÔÖе÷Óòéѯ¹¹½¨Æ÷£º¸ù¾Ý£¿£¿»ñÈ¡¾ßÌå°æ±¾
|
|
|
itemID = latestItemRevision.getProperty("item_id");
|
|
|
toTaskRevId = itemID + "-" + revID;
|
|
|
|
|
|
}else if (selectComponent instanceof TCComponentItemRevision) {
|
|
|
//TODO Èç¹ûÑ¡ÖжÔÏóÊÇÎïÁϰ汾¶ÔÏóH8_PartRevision
|
|
|
System.out.println("µ±Ç°Ñ¡ÖжÔÏóÊÇ H8_drawingRevision");
|
|
|
TCComponentItemRevision revision = (TCComponentItemRevision)selectComponent;
|
|
|
String releaseDate = revision.getProperty("date_released");
|
|
|
System.out.println("===>»ñÈ¡µ½µ±Ç°°æ±¾¶ÔÏóµÄ·¢²¼×´Ì¬£º"+releaseDate);
|
|
|
if (releaseDate == null) {
|
|
|
System.out.println("µ±Ç°°æ±¾Î´·¢²¼");
|
|
|
MessageBox.post("µ±Ç°°æ±¾Î´·¢²¼£¡ÎÞ·¨Ï·¢¡¤¡¤¡¤","Ìáʾ",MessageBox.INFORMATION);
|
|
|
thread.setBool(true);
|
|
|
return;
|
|
|
}
|
|
|
revID = revision.getProperty("item_revision_id");
|
|
|
itemID = revision.getProperty("item_id");
|
|
|
toTaskRevId = itemID + "-" + revID;
|
|
|
|
|
|
}else {
|
|
|
MessageBox.post("erro select!","tip",MessageBox.INFORMATION);
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
//×éÖ¯³ýmsgÍâµÄTask±íÊý¾Ý
|
|
|
String tasksource = "ÊÖ¶¯Ï·¢";
|
|
|
String userName = session.getUser().getUserName();
|
|
|
String userId = session.getUser().getUserId();
|
|
|
String status = "δ¿ªÊ¼";
|
|
|
String starttime = getCurrentTime();
|
|
|
//ÅжÏtask±íÖÐÊÇ·ñÒѾ´æÔÚÏàͬÊý¾Ý
|
|
|
|
|
|
Map<String, Object> paramMap = new HashMap<String, Object>();
|
|
|
//Æ¥ÅäspringbootÖеIJéѯ·½·¨
|
|
|
paramMap.put("MSG", toTaskRevId);
|
|
|
Integer result = sendRequest("getByMSG",paramMap);
|
|
|
if (result > 0) {//´æÔÚÖØ¸´Êý¾Ý£¬¸üÐÂ
|
|
|
System.out.println("TASK±í´æÔÚÖØ¸´Êý¾Ý£¬¸üС¤¡¤¡¤");
|
|
|
Map<String, Object> paramMapU = new HashMap<String, Object>();
|
|
|
paramMapU.put("TASKSOURCE",tasksource);
|
|
|
paramMapU.put("USERNAME",userName);
|
|
|
paramMapU.put("USERID",userId);
|
|
|
paramMapU.put("STATUS",status);
|
|
|
paramMapU.put("STARTTIME",starttime);
|
|
|
paramMapU.put("MSG",toTaskRevId);
|
|
|
Integer resultU = sendRequest("updateTask",paramMapU);
|
|
|
if (resultU == -1){
|
|
|
System.out.println("Ïòspringboot·¢ËÍÇëÇóʧ°Ü£¡updateTask");
|
|
|
}
|
|
|
}else {//²»´æÔÚÖØ¸´Êý¾Ý£¬²åÈë
|
|
|
System.out.println("TASK±í²»´æÔÚÖØ¸´Êý¾Ý£¬²åÈ롤¡¤¡¤");
|
|
|
Map<String, Object> paramMapI = new HashMap<String, Object>();
|
|
|
paramMapI.put("TASKSOURCE",tasksource);
|
|
|
paramMapI.put("USERNAME",userName);
|
|
|
paramMapI.put("USERID",userId);
|
|
|
paramMapI.put("STATUS",status);
|
|
|
paramMapI.put("MSG",toTaskRevId);
|
|
|
paramMapI.put("STARTTIME",starttime);
|
|
|
Integer resultI = sendRequest("insertTask",paramMapI);
|
|
|
if (resultI == -1){
|
|
|
System.out.println("Ïòspringboot·¢ËÍÇëÇóʧ°Ü£¡insertTask");
|
|
|
}
|
|
|
System.out.println("1");
|
|
|
}
|
|
|
System.out.println("2");
|
|
|
}
|
|
|
System.out.println("deal end!");
|
|
|
} catch (Exception e) {
|
|
|
// TODO: handle exception
|
|
|
System.out.println("===>Ï·¢Ê§°Ü");
|
|
|
MessageBox.post("Ï·¢Ê§°Ü","Ìáʾ",MessageBox.INFORMATION);
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
MessageBox.post("Ï·¢³É¹¦","Ìáʾ",MessageBox.INFORMATION);
|
|
|
|
|
|
thread.setBool(true);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* ÏòÒì²½·þÎñ·¢ËÍÇëÇó
|
|
|
* @return ·µ»Ø-1 ±íʾʧ°Ü
|
|
|
*/
|
|
|
private Integer sendRequest(String way,Map<String, Object> param){
|
|
|
System.out.println("¿ªÊ¼µ÷Ó÷½·¨£ºÏòSpringBoot³ÌÐò·¢ËÍÇëÇ󡤡¤¡¤");
|
|
|
Integer resultInteger = 0;
|
|
|
String urlString = "http://"+Constants.SPRING_ADDRESS+"/part/"+way;
|
|
|
try {//²âÊÔ»úip£º192.168.3.125
|
|
|
String url = StrUtil.format(urlString);//springboot·þÎñËùÔÚ·þÎñÆ÷µÄipµØÖ·
|
|
|
System.out.println(urlString);
|
|
|
// ·¢ËÍPOSTÇëÇó
|
|
|
HttpResponse response = HttpRequest.post(url)
|
|
|
.header("Content-Type", "application/json") // ÉèÖÃÄÚÈÝÀàÐÍΪJSON
|
|
|
.body(JSONUtil.toJsonStr(param)) // ÉèÖÃÇëÇóÌåΪJSON×Ö·û´®
|
|
|
.timeout(20*1000) // ÉèÖó¬Ê±Ê±¼ä
|
|
|
.execute();
|
|
|
System.out.println("µ÷ÓÃSpringBootÖ´ÐÐÊý¾Ý¿â²Ù×÷ºóµÄ½á¹ûΪ£º"+response.body()+"\n ÇëÇóЯ´øÐÅϢΪ£º"+param.toString());
|
|
|
resultInteger = Integer.parseInt(response.body());
|
|
|
int statusCode = response.getStatus();
|
|
|
if (statusCode < 200 && statusCode > 300) {
|
|
|
System.out.println("ÏìÓ¦Òì³£: »ñÈ¡ÐÅϢΪ¿Õ!");
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
} catch (HttpException e) {
|
|
|
// ¼ì²éÊÇ·ñÊdz¬Ê±Òì³£
|
|
|
if (e.getMessage().contains("Read timed out") || e.getMessage().contains("Connect timed out")) {
|
|
|
System.out.println("ÇëÇó³¬Ê±: " + e.getMessage());
|
|
|
return -2; // ʹÓò»Í¬µÄ·µ»ØÖµ±êʶ³¬Ê±Çé¿ö
|
|
|
} else {
|
|
|
// ÆäËûÀàÐ͵ÄHttpException
|
|
|
System.out.println("ÇëÇó¹ý³ÌÖз¢ÉúHttpException: " + e.getMessage());
|
|
|
return -1;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
// ²¶»ñÆäËûËùÓÐÒì³£
|
|
|
System.out.println("ÇëÇó¹ý³ÌÖз¢ÉúÒì³£: " + e.getMessage());
|
|
|
e.printStackTrace(); // ´òÓ¡¶ÑÕ»¸ú×ÙÐÅÏ¢ÒÔ±ãµ÷ÊÔ
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
return resultInteger;
|
|
|
}
|
|
|
|
|
|
}
|