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.

194 lines
5.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include"kutil.h"
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include "libxl.h"
#include <io.h>
#include <direct.h>
#include <cfm/cfm.h>
#include <wchar.h>
#include <locale>
#include <codecvt>
#include <chrono>
#include <Windows.h>
#include <thread>
#include <regex>
#include <res\reservation.h>
#include "libxl.h"
#include <map>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <filesystem>
#include <sys/stat.h>
#include <iostream>
using namespace libxl;
using namespace std::chrono_literals;
using namespace std;
#define debug true
#define ITK_err 919012
int LD_GYLXFrozen(EPM_action_message_t msg) {
printf("《《《《《《《《《《《《《《《《《《《开始执行LD_GYLXFrozen处理程序》》》》》》》》》》》》》》》》");
tag_t rootTask_tag = NULLTAG;
tag_t task = NULLTAG;
char* arg = NULL, * argflag = NULL, * argvalue = NULL;
int arg_cnt = TC_number_of_arguments(msg.arguments);
//流程参数
char* ZBS = NULL;
char* type = NULL;
//目标对象参数
int doc_num = 0;
tag_t* doc_tags = NULLTAG;
task = msg.task;
ITKCALL(EPM_ask_root_task(task, &rootTask_tag));
if (arg_cnt > 0)
{
for (int i = 0; i < arg_cnt; i++)
{
arg = TC_next_argument(msg.arguments);
ITKCALL(ITK_ask_argument_named_value((const char*)arg, &argflag, &argvalue));
if (strcmp(argflag, "ZBS") == 0) {
if (argvalue != NULL)
{
printf("获取的值%s:\n", argvalue);
ZBS = argvalue;
}
}
if (strcmp(argflag, "type") == 0) {
if (argvalue != NULL)
{
printf("获取的值%s:\n", argvalue);
type = argvalue;
}
}
}
//获取流程目标对象版本
ITKCALL(EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &doc_num, &doc_tags));
auto file = std::make_unique<std::ofstream>("D:\\TCTOSAP\\jsonStr.txt");
//std::ofstream file("D:\\MESTOTC\\example.txt", std::ios_base::trunc); // 打开文件,并清空内容
file->is_open();
for (int i = 0; i < doc_num;i++) {
string jsonStr = "";
string douhao = ",";
string ate = "@";
string fenhao = ";";
char* mbtype;
ITKCALL(AOM_ask_value_string(doc_tags[i], "object_type", &mbtype));
printf("类型为%s\n",mbtype);
if (strstr(type,mbtype)!= nullptr) {
printf("匹配到了类型\n");
char* id;
ITKCALL(AOM_ask_value_string(doc_tags[i], "item_id", &id));
jsonStr = jsonStr + ZBS + douhao + id + douhao + mbtype + douhao;
printf("JSONStr = %s\n",jsonStr.c_str());
printf("开始获取表格属性\n");
printf("获取关系\n");
//关系参数
int gx_num = 0;
tag_t* gx_tags = NULLTAG;
ITKCALL(AOM_ask_value_tags(doc_tags[i], "LD6_GYLXCompanyFormRelation", &gx_num,&gx_tags));
printf("获取表单\n");
for (int j = 0; j < gx_num;j++) {
char* gxtype;
ITKCALL(AOM_ask_value_string(gx_tags[j], "object_type", &gxtype));
printf("类型为%s\n", gxtype);
if (strcmp(gxtype,"LD6_GYLXCompanyForm") == 0) {
printf("匹配到了表单\n");
printf("获取表格属性\n");
//遍历表格
int num;//表格行数
tag_t* rows = NULL;//表格对象
ITKCALL(AOM_ask_table_rows(gx_tags[j], "ld6_GYLXCompanyTable", &num, &rows));
printf("获取表格\n");
for (int a = 0; a < num; a++) {
char* WERKS, * MATNR, * PLNNR, * PLNAL;
ITKCALL(AOM_ask_value_string(rows[a], "ld6_company", &WERKS));
ITKCALL(AOM_ask_value_string(rows[a], "ld6_partid", &MATNR));
ITKCALL(AOM_ask_value_string(rows[a], "ld6_groupNum", &PLNNR));
ITKCALL(AOM_ask_value_string(rows[a], "ld6_groupCounter", &PLNAL));
if (a == num-1) {
jsonStr = jsonStr + WERKS + ate + MATNR + ate + PLNNR + ate + PLNAL;
}
else {
jsonStr = jsonStr + WERKS + ate + MATNR + ate + PLNNR + ate + PLNAL + fenhao;
}
}
printf("jsonStr = %s\n", jsonStr.c_str());
//将数据写入文件
*file << jsonStr.c_str() << std::endl;
//退出当前循环
break;
}
}
}
}
//执行jar包给SAP发送请求
//获取当前流程uid
char* flowId;
ITK__convert_tag_to_uid(rootTask_tag, &flowId);
//调用cmd执行jar包将数据传递到MES和SAP中
char cmd[8192] = "";
strcpy(cmd, "java -jar D:\\Siemens\\Teamcenter13\\bin\\sapjco3.jar");
strcat(cmd, " ");
strcat(cmd, "SendSAP");
strcat(cmd, " ");
strcat(cmd, flowId);
system(cmd);
//读取本地的result文件SAP
string fileid = flowId;
string SAPfile = "D:\\TCTOSAP\\" + fileid + "result.txt";
std::ifstream file1(SAPfile);
if (!file1.is_open()) {
std::cerr << "Failed to open file!" << std::endl;
char* error = "服务未响应";
EMH_store_error_s2(EMH_severity_error, ITK_err, "提示", error);
return 1;
}
else {
std::stringstream buffer1;
buffer1 << file1.rdbuf();
std::string resultStr = buffer1.str();
printf("返回的值%s:\n", resultStr.c_str());
if (strcmp(resultStr.c_str(), "成功") == 0) {
for (int i = 0; i < doc_num; i++) {
char* mbtype;
ITKCALL(AOM_ask_value_string(doc_tags[i], "object_type", &mbtype));
if (strcmp(mbtype, argflag) == 0) {
//修改属性值
AOM_lock(doc_tags[i]);
ITKCALL(AOM_set_value_string(doc_tags[i], "ld6_gylxiffrozentosap", "成功"));
AOM_save(doc_tags[i]);
AOM_unlock(doc_tags[i]);
AOM_refresh(doc_tags[i], true);
}
}
return 0;
}
else {
for (int i = 0; i < doc_num; i++) {
char* mbtype;
ITKCALL(AOM_ask_value_string(doc_tags[i], "object_type", &mbtype));
if (strcmp(mbtype, argflag) == 0) {
//修改属性值
AOM_lock(doc_tags[i]);
ITKCALL(AOM_set_value_string(doc_tags[i], "ld6_gylxiffrozentosap", "失败"));
AOM_save(doc_tags[i]);
AOM_unlock(doc_tags[i]);
AOM_refresh(doc_tags[i], true);
}
}
EMH_store_error_s2(EMH_severity_error, ITK_err, "提示", resultStr.c_str());
return 1;
}
}
return 1;
}
}