#define _CRT_SECURE_NO_WARNINGS #include "epm_handler_common.h" void getTCMUserBomLineReplaceItem(tag_t topLine, vector &bomLine); void getTCMUserItemJson(int index,tag_t topLine, tag_t BomLine, map typePropertyType, char parameters[100000]); void getTCMUserBomLineProperty(tag_t topLine, tag_t BomLine, map typePropertyType, char * bomBaseNum, char parameters[100000]); void getTCMUserBomLineChildProperty(tag_t topLine, map typePropertyType, char parameters[100000]); bool isUserBomStart = true; void getTCMUserItemBomProperty(tag_t item, map typePropertyType, char parameters[100000]) { char * lineCode = NULL;//产线代码,BOM版本为产线代号加1位流水 AOM_ask_value_string(item, "ml8_LineCode", &lineCode); if (lineCode == NULL || strcmp(lineCode, "") == 0) { MEM_free(lineCode); return; } char *itemType = NULL; AOM_ask_value_string(item, "object_type", &itemType); printf("itemType%s Start===================\n", itemType); //过滤掉非版本的对象 if ((strcmp(itemType, "ML8_RefrigeratorRevision") == 0) || (strcmp(itemType, "ML8_WashingRevision") == 0) || (strcmp(itemType, "ML8_ColdRevision") == 0) || (strcmp(itemType, "ML8_OthersRevision") == 0) || (strcmp(itemType, "ML8_PartRevision") == 0) || (strcmp(itemType, "ML8_RawMaterialRevision") == 0)) { //判断是否发布 int releaseCount = 0; tag_t * releaseTag = NULL_TAG; //判断子件是否发布 AOM_ask_value_tags(item, "release_status_list", &releaseCount, &releaseTag); printf("发布状态%d===================\n", releaseCount); if (releaseCount <= 0) { MEM_free(releaseTag); MEM_free(itemType); return; } //获取所有包含替代项目组的BOM行 vector bomLines; //获取子项 tag_t top_line = NULLTAG, window = NULLTAG; BOM_create_window(&window); //设置顶层BOM BOM_set_window_top_line(window, NULLTAG, item, NULLTAG, &top_line); getTCMUserBomLineReplaceItem(top_line, bomLines); if (bomLines.size() > 0) { for (int j = 0; j < bomLines.size(); j++) { tag_t bomLine = bomLines.at(j); //获取单个的json字符串 if (isUserBomStart) { getTCMUserItemJson(j + 1, top_line, bomLine, typePropertyType, parameters); isUserBomStart = false; } else { getTCMUserItemJson(j + 1, top_line, bomLine, typePropertyType, parameters); } } //获取子BOM的属性 //getTCMUserBomLineChildProperty(top_line, typePropertyType, parameters); } else { //获取单个的json字符串 if (isUserBomStart) { getTCMUserItemJson(-1, top_line, NULLTAG, typePropertyType, parameters); isUserBomStart = false; } else { getTCMUserItemJson(-1, top_line, NULLTAG, typePropertyType, parameters); } //获取子BOM的属性 //getTCMUserBomLineChildProperty(top_line, typePropertyType, parameters); } BOM_close_window(window); MEM_free(releaseTag); } MEM_free(lineCode); MEM_free(itemType); } int ML_TCMUserSendSapBom(void * returnValue) { printf("=========================TCM User BOM下发到SAP Start===================\n"); //POM_AM__set_application_bypass(true); int ifail = ITK_ok; tag_t item = NULLTAG; char * messageUser = NULL; USERARG_get_tag_argument(&item); USERARG_get_string_argument(&messageUser); vector messageUserValues; if (strstr(messageUser, ",") != NULL) { int vectorValueCount = 0; char ** vectorValueChar = new char *[64]; split(messageUser, ",", vectorValueChar, &vectorValueCount); for (int i = 0; i < vectorValueCount; i++) { messageUserValues.push_back(vectorValueChar[i]); } } else { messageUserValues.push_back(messageUser); } int pref_cnt = 0; char ** pref_vals = NULL; //获取首选项的值 PREF_ask_char_values("ML_TCMBOMSendSapProperty", &pref_cnt, &pref_vals); map typePropertyType; for (int j = 0; j < pref_cnt; j++) { if (strstr(pref_vals[j], "-") != NULL) { //按照-进行拆分。拆分条件 int valueCount = 0; char ** valueChar = new char *[64]; //分割字符串 split(pref_vals[j], "-", valueChar, &valueCount); typePropertyType[valueChar[0]] = valueChar[1];// .insert(std::pair(valueChar[0], valueChar[1])); } } //获取当前时间 time_t now = time(0); tm *p = localtime(&now); char date[128] = ""; sprintf_s(date, "%04d%02d%02d%02d%02d%02d", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec); char *tc_root_file = getenv("tc_root"); //C:\Siemens\Teamcenter11 char parameters[100000] = "";//写入到文件的值 strcat(parameters, "getTCMBomPropertys}}"); strcat(parameters, messageUser); strcat(parameters, "}}"); strcat(parameters, ""); getTCMUserItemBomProperty(item, typePropertyType, parameters); strcat(parameters, ""); isUserBomStart = true; //把数据用写入文件 char data_file[SS_MAXPATHLEN] = ""; strcat(data_file, tc_root_file); strcat(data_file, "\\"); strcat(data_file, date); strcat(data_file, ".txt"); ofstream file; file.open(data_file); file << parameters << endl; // 使用与cout同样的方式进行写入 file.close(); string strResult; //cmd指令 char cmd[256] = ""; strcpy(cmd, "java -jar \""); //strcat(cmd, jar_file); strcat(cmd, tc_root_file); strcat(cmd, "\\portal\\plugins\\"); strcat(cmd, "ML_SendSap.jar"); strcat(cmd, "\" "); //传参 cout << data_file << endl; strcat(cmd, data_file); //用来传递本流程的流程名称(@分割) //strcat(cmd,"@"); //strcat(cmd,handler_name); printf("路径:\n%s\n", cmd); char buf[8000] = { 0 }; FILE *pf = NULL; if ((pf = _popen(cmd, "r")) == NULL) { printf("接口返回:\n%s", "1"); } while (fgets(buf, sizeof buf, pf)) { strResult += buf; } _pclose(pf); cout << strResult << endl; unsigned int iSize = strResult.size(); if (iSize > 0 && strResult[iSize - 1] == '\n' && strlen(parameters) > 0) { strResult = strResult.substr(0, iSize - 1); printf("下发失败\n"); cout << strResult << endl; //发送消息到企业微信 for (auto messageUserValue : messageUserValues) { BOMSendToWeixin(messageUserValue, NULLTAG, strResult); } } else { POM_AM__set_application_bypass(TRUE); //获取首次发送时间 char *itemType = NULL; AOM_ask_value_string(item, "object_type", &itemType); //过滤掉非版本的对象 if ((strcmp(itemType, "ML8_RefrigeratorRevision") == 0) || (strcmp(itemType, "ML8_WashingRevision") == 0) || (strcmp(itemType, "ML8_ColdRevision") == 0) || (strcmp(itemType, "ML8_OthersRevision") == 0) || (strcmp(itemType, "ML8_PartRevision") == 0) || (strcmp(itemType, "ML8_RawMaterialRevision") == 0)) { //获取当前时间 time_t now = time(0); tm *p = localtime(&now); char dateNow[128] = ""; sprintf_s(dateNow, "%04d-%02d-%02d %02d:%02d:%02d", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec); AOM_lock(item); /*if (sendTime == NULL || strcmp(sendTime, "") == 0) { AOM_set_value_string(item, "ml8_BOMFirstTime", dateNow); } else { AOM_set_value_string(item, "ml8_BOMNewTime", dateNow); }*/ AOM_save(item); AOM_unlock(item); AOM_refresh(item, false); } DOFREE(itemType); POM_AM__set_application_bypass(FALSE); } messageUserValues.clear(); vector().swap(messageUserValues); tc_root_file = NULL; pref_vals = NULL; if (ifail == 1) { EMH_store_error_s1(EMH_severity_user_error, EMH_USER_error_base, strResult.c_str()); } printf("=========================TCM User BOM下发到SAP End===================\n"); return ifail; } void getTCMUserBomLineReplaceItem(tag_t topLine, vector &bomLine) { int count; tag_t *children_line; BOM_line_ask_all_child_lines(topLine, &count, &children_line); for (int i = 0; i < count; i++) { char * replaceProject = NULL; AOM_ask_value_string(children_line[i], "ML8_ProjectTeam", &replaceProject); printf("ML8_ProjectTeam%s===================\n", replaceProject); if (replaceProject != NULL && strcmp(replaceProject, "A0") == 0) { bomLine.push_back(children_line[i]); } DOFREE(replaceProject); } DOFREE(children_line); } void getTCMUserItemJson(int index,tag_t topLine, tag_t BomLine, map typePropertyType, char parameters[100000]) { /*if (isUserBomStart) { strcat(parameters, "{"); } else { strcat(parameters, ",{"); }*/ //获取属性 char * matnr = NULL;//物料编码 char * werks = NULL;//工厂 char * lineCode = NULL;//产线代码,BOM版本为产线代号加1位流水 char * bomusage = "1";//BOM用途 char * alternative = NULL;//BOM版本 char * validdate = "20200101";//有效期起 char * description = NULL;//可选BOM文本 char * basequan = "1000";//基本数量 tag_t revisions = NULLTAG; AOM_ask_value_tag(topLine, "bl_line_object", &revisions); char * puid = NULL; //获取PUID ITK__convert_tag_to_uid(revisions, &puid); AOM_ask_value_string(topLine, "bl_item_item_id", &matnr); if (strstr(matnr, "-") != NULL) { //按照,进行拆分。拆分条件 int matnrCount = 0; char ** matnrChar = new char *[64]; //分割字符串 split(matnr, "-", matnrChar, &matnrCount); matnr = matnrChar[0]; } AOM_ask_value_string(revisions, "ml8_Factory", &werks); AOM_ask_value_string(revisions, "ml8_LineCode", &lineCode); if (index > -1) { char itc[10]; _itoa(index, itc, 10); alternative = itc; } else { alternative = "1"; //AOM_ask_value_string(revisions, "ml8_SAPBOMRevision", &alternative); } AOM_ask_value_string(topLine, "bl_item_object_name", &description); AOM_ask_value_string(revisions, "ml8_BOMBasicQuantity", &basequan); //获取当前时间 time_t now = time(0); tm *p = localtime(&now); char date[128] = ""; sprintf_s(date, "%04d%02d%02d%02d%02d%02d", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, newGUID()); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, newGUID()); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, "JT0001"); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, "维护MOBM接口"); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, date); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, "TCM"); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, "SAP"); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, matnr); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, "
"); strcat(parameters, ""); strcat(parameters, matnr); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, werks); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, bomusage); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, lineCode); strcat(parameters, alternative); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, basequan); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, validdate); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, description); strcat(parameters, ""); strcat(parameters, ""); strcat(parameters, puid); strcat(parameters, ""); strcat(parameters, "
"); getTCMUserBomLineProperty(topLine, BomLine, typePropertyType, basequan, parameters); strcat(parameters, "
"); strcat(parameters, "
"); DOFREE(matnr); DOFREE(werks); DOFREE(bomusage); DOFREE(alternative); DOFREE(validdate); DOFREE(description); DOFREE(basequan); DOFREE(puid); } void getTCMUserBomLineChildProperty(tag_t topLine, map typePropertyType, char parameters[100000]) { int count; tag_t *children_line = NULLTAG; BOM_line_ask_all_child_lines(topLine, &count, &children_line); for (int i = 0; i < count; i++) { int childCount; tag_t *children_bomLine = NULLTAG; BOM_line_ask_all_child_lines(children_line[i], &childCount, &children_bomLine); if (childCount > 0) { tag_t revisions = NULLTAG; AOM_ask_value_tag(children_line[i], "bl_line_object", &revisions); getTCMUserItemBomProperty(revisions, typePropertyType, parameters); } DOFREE(children_bomLine); } DOFREE(children_line); } void getTCMUserBomLineProperty(tag_t topLine, tag_t BomLine, map typePropertyType, char * bomBaseNum, char parameters[100000]) { //char parameters[100000] = "";//写入到文件的值 bool isStart = true; int count; tag_t *children_line = NULLTAG; BOM_line_ask_all_child_lines(topLine, &count, &children_line); for (int i = 0; i < count; i++) { char * replaceProject = NULL; AOM_ask_value_string(children_line[i], "ML8_ProjectTeam", &replaceProject); if (replaceProject != NULL && strcmp(replaceProject, "A0") == 0 && BomLine != NULLTAG) { //判断是否等于传进来的BOM行 char * itemId = NULL; AOM_ask_value_string(children_line[i], "bl_item_item_id", &itemId); char * inputItemId = NULL; AOM_ask_value_string(BomLine, "bl_item_item_id", &inputItemId); if (strcmp(itemId, inputItemId) != 0) { continue; } } char *itemType = NULL; AOM_ask_value_string(children_line[i], "fnd0bl_line_object_type", &itemType); char * puid = NULL; //获取PUID ITK__convert_tag_to_uid(children_line[i], &puid); //过滤掉非版本的对象 string propertyNames = typePropertyType[itemType]; if (propertyNames.c_str() != NULL) { /*if (isStart) { strcat(parameters, "{"); isStart = false; } else { strcat(parameters, ",{"); }*/ const char * constName = propertyNames.c_str(); char* name = new char[2048];//足够长 strcpy(name, constName); if (strstr(name, ",") != NULL) { //按照,进行拆分。拆分条件 int valueCount = 0; char ** valueChar = new char *[64]; //分割字符串 split(name, ",", valueChar, &valueCount); strcat(parameters, ""); for (int k = 0; k < valueCount; k++) { if (strstr(valueChar[k], "=") != NULL) { //按照-进行拆分。拆分条件 int valueNum = 0; char ** values = new char *[64]; //分割字符串 split(valueChar[k], "=", values, &valueNum); strcat(parameters, "<"); strcat(parameters, values[1]); strcat(parameters, ">"); char * item_rev_value = NULL; TCGetPropertyValue(children_line[i], "BOMLine", values[0], &item_rev_value); if (strcmp(values[1], "POSNR") == 0) { char itc[10]; sprintf(itc, "%d", i); item_rev_value = itc; } strcat(parameters, item_rev_value); strcat(parameters, ""); DOFREE(item_rev_value); } } strcat(parameters, ""); } else { //按照-进行拆分。拆分条件 int valueCount = 0; char ** valueChar = new char *[64]; //分割字符串 split(name, "=", valueChar, &valueCount); strcat(parameters, ""); strcat(parameters, "<"); strcat(parameters, valueChar[1]); strcat(parameters, ">"); char * item_rev_value = NULL; TCGetPropertyValue(children_line[i], "BOMLine", valueChar[0], &item_rev_value); if (strcmp(valueChar[1], "POSNR") == 0) { char itc[10]; sprintf(itc, "%d", i); item_rev_value = itc; } strcat(parameters, item_rev_value); strcat(parameters, ""); strcat(parameters, ""); DOFREE(item_rev_value); } DOFREE(constName); } DOFREE(replaceProject); DOFREE(itemType); DOFREE(puid); } DOFREE(children_line); }