|
|
#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>
|
|
|
#include <random>
|
|
|
#include <windows.h>
|
|
|
#include <objbase.h>
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
using namespace libxl;
|
|
|
using namespace std::chrono_literals;
|
|
|
using namespace std;
|
|
|
|
|
|
#define debug true
|
|
|
#define ITK_err 919012
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个函数来写入数据
|
|
|
void writeDataToFile(const std::string& fileName, const std::string& data) {
|
|
|
// 创建一个输出文件流对象
|
|
|
std::ofstream outputFile(fileName);
|
|
|
|
|
|
// 检查文件是否成功打开
|
|
|
if (outputFile.is_open()) {
|
|
|
// 写入数据
|
|
|
outputFile << data;
|
|
|
|
|
|
// 关闭文件
|
|
|
outputFile.close();
|
|
|
std::cout << "Data written to file successfully." << std::endl;
|
|
|
}
|
|
|
else {
|
|
|
std::cerr << "Unable to open file for writing: " << fileName << std::endl;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 生成UUID
|
|
|
char* generateRandomEightDigitNumberAsCharArray() {
|
|
|
GUID guid;
|
|
|
if (S_OK == CoCreateGuid(&guid)) {
|
|
|
// 动态分配足够的内存来存储GUID字符串(包括'\0')
|
|
|
char* guidStr = new char[37];
|
|
|
|
|
|
sprintf(guidStr, "%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX",
|
|
|
guid.Data1, guid.Data2, guid.Data3,
|
|
|
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
|
|
|
guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
|
|
|
|
|
|
std::cout << "Generated GUID: " << guidStr << std::endl;
|
|
|
|
|
|
// 返回指向新创建字符串的指针
|
|
|
return guidStr;
|
|
|
}
|
|
|
else {
|
|
|
std::cerr << "Failed to create a GUID." << std::endl;
|
|
|
return nullptr; // 出错时返回nullptr
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LD_SendECRECN_ToSAPMES(EPM_action_message_t msg) {
|
|
|
printf("《《《《《《《《《《《《《《《《《《《开始执行LD_SendECRECN_ToSAPMES处理程序》》》》》》》》》》》》》》》》");
|
|
|
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* type = NULL;
|
|
|
char* relation = NULL;
|
|
|
char* secondarytype = NULL;
|
|
|
//目标对象参数
|
|
|
int doc_num = 0;
|
|
|
tag_t* doc_tags = NULLTAG;
|
|
|
//错误信息参数
|
|
|
string erro2 = "";
|
|
|
string erro = "";
|
|
|
//发送信息参数
|
|
|
int send1 = 0;
|
|
|
int send2 = 0;
|
|
|
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, "primarytype") == 0) {
|
|
|
if (argvalue != NULL)
|
|
|
{
|
|
|
printf("获取的值%s:\n", argvalue);
|
|
|
type = argvalue;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
if (strcmp(argflag, "relation") == 0) {
|
|
|
if (argvalue != NULL)
|
|
|
{
|
|
|
printf("获取的值%s:\n", argvalue);
|
|
|
relation = argvalue;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
if (strcmp(argflag, "secondarytype") == 0) {
|
|
|
if (argvalue != NULL)
|
|
|
{
|
|
|
printf("获取的值%s:\n", argvalue);
|
|
|
secondarytype = argvalue;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (strcmp(type, "") == 0 || strcmp(relation, "") == 0 || strcmp(secondarytype, "") == 0) {
|
|
|
//返回信息报错提示
|
|
|
char* error = "请检查流程参数是否有为空或未定义的情况";
|
|
|
EMH_store_error_s2(EMH_severity_error, ITK_err, "提示", error);
|
|
|
return 1;
|
|
|
}
|
|
|
//获取MES的传递地址
|
|
|
char* url;
|
|
|
PREF_ask_char_value("LD_PLM2MES_ECRECN_Config", 0, &url);
|
|
|
//获取文件传输地址
|
|
|
char* sendfilepath, *fileURL;
|
|
|
|
|
|
PREF_ask_char_value("LD_SendECRECN_FileURL", 0, &sendfilepath);
|
|
|
PREF_ask_char_value("LD_SendECRECN_FileURL", 1, &fileURL);
|
|
|
//获取流程目标对象版本
|
|
|
ITKCALL(EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &doc_num, &doc_tags));
|
|
|
char* flowId = "";
|
|
|
//获取当前时间
|
|
|
time_t nowtime;
|
|
|
time(&nowtime); //获取1970年1月1日0点0分0秒到现在经过的秒数
|
|
|
tm p;
|
|
|
localtime_s(&p, &nowtime); //将秒数转换为本地时间,年从1900算起,需要+1900,月为0-11,所以要+1
|
|
|
char buffer[80];
|
|
|
//sprintf_s(buffer, "%04d%d%02d%02d%02d%02d", 1900 + p.tm_year, p.tm_mon + 1, p.tm_mday, p.tm_hour, p.tm_min, p.tm_sec);
|
|
|
sprintf_s(buffer, "%04d-%02d-%02d %02d:%02d:%2d", 1900 + p.tm_year, p.tm_mon + 1, p.tm_mday, p.tm_hour, p.tm_min,p.tm_sec);
|
|
|
printf("获取的时间:%s\n", buffer);
|
|
|
if (doc_num>0) {
|
|
|
//开始循环获取对象传递
|
|
|
std::stringstream jsonStr;
|
|
|
jsonStr << "[";
|
|
|
for (int i = 0; i < doc_num;i++) {
|
|
|
char* objtype = NULL;
|
|
|
printf("获取类型\n");
|
|
|
ITKCALL(AOM_ask_value_string(doc_tags[i], "object_type", &objtype));
|
|
|
printf("比较%s和%s是否相同\n",type, objtype);
|
|
|
if (strcmp(type, objtype) == 0) {
|
|
|
printf("获取到了匹配的类型");
|
|
|
//判断-primarytype参数中值的对象类型,检查版本上的ld6_ifeffectProds属性值是否包含“无影响”,如包含,则跳过此数据传递
|
|
|
char* isbaohan;
|
|
|
ITKCALL(AOM_ask_value_string(doc_tags[i], "item_id", &flowId));
|
|
|
ITKCALL(AOM_ask_value_string(doc_tags[i], "ld6_ifeffectProd", &isbaohan));
|
|
|
if (strstr(isbaohan,"无影响")!=NULL) {
|
|
|
printf("当前匹配类型包含无影响,跳过该对象");
|
|
|
continue;
|
|
|
}
|
|
|
//获取指定关系下的对象
|
|
|
int das_num = 0;
|
|
|
tag_t* das_tags;
|
|
|
ITKCALL(AOM_ask_value_tags(doc_tags[i], relation, &das_num, &das_tags));
|
|
|
|
|
|
if (das_num>0) {
|
|
|
//获取类型匹配次对象类型
|
|
|
char* cdxtype = NULL;
|
|
|
for (int j = 0; j < das_num;j++) {
|
|
|
//开始拼接字符串组成json数据
|
|
|
char* MATNR = "", * ZVERSION = "", * ECNDOCU = "", * ECNSTATE = "", * ECRDOCU = "", * ECRSTATE = "", * ZSFYXSC = "", * ZDATE = "", * URLADD = " ";
|
|
|
ITKCALL(AOM_ask_value_string(das_tags[j], "object_type", &cdxtype));
|
|
|
if (strstr(secondarytype, cdxtype) != NULL) {
|
|
|
//获取MATNR物料号
|
|
|
printf("获取MATNR物料号\n");
|
|
|
ITKCALL(AOM_ask_value_string(das_tags[j], "item_id", &MATNR));
|
|
|
printf("获取ZVERSION零件版本\n");
|
|
|
ITKCALL(AOM_ask_value_string(das_tags[j], "ld6_clientPartRev", &ZVERSION));
|
|
|
//获取ECNDOCU单号
|
|
|
/*
|
|
|
* LD6_ECRRevision时,获取流程目标中类型是LD6_ECRRevision的item_id属性
|
|
|
* LD6_ECNRevision时,获取流程目标中类型是LD6_ECNRevision的item_id属性
|
|
|
*/
|
|
|
if (strcmp(type, "LD6_CNRevision") == 0) {
|
|
|
ITKCALL(AOM_ask_value_string(doc_tags[i], "item_id", &ECNDOCU));
|
|
|
date_t time1;
|
|
|
ITKCALL(AOM_ask_value_date(doc_tags[i], "date_released", &time1));
|
|
|
if (time1.year == 0) {
|
|
|
//日期为空
|
|
|
ECNSTATE = "未关闭";
|
|
|
}
|
|
|
else {
|
|
|
//日期不为空
|
|
|
ECNSTATE = "已关闭";
|
|
|
}
|
|
|
int gx = 0;
|
|
|
tag_t* gxtag;
|
|
|
ITKCALL(AOM_ask_value_tags(doc_tags[i], "CMImplements", &gx, &gxtag));
|
|
|
if (gx > 0)
|
|
|
{
|
|
|
for (int b = 0; b < gx; b++) {
|
|
|
char* ty;
|
|
|
ITKCALL(AOM_ask_value_string(gxtag[b], "object_type", &ty));
|
|
|
if (strcmp("LD6_CRRevision", ty) == 0) {
|
|
|
ITKCALL(AOM_ask_value_string(gxtag[b], "item_id", &ECRDOCU));
|
|
|
date_t time;
|
|
|
ITKCALL(AOM_ask_value_date(gxtag[b], "date_released", &time));
|
|
|
if (time.year == 0) {
|
|
|
//日期为空
|
|
|
ECRSTATE = "未关闭";
|
|
|
}
|
|
|
else {
|
|
|
//日期不为空
|
|
|
ECRSTATE = "已关闭";
|
|
|
}
|
|
|
}
|
|
|
//获取ZSFYXSC
|
|
|
ITKCALL(AOM_ask_value_string(doc_tags[i], "ld6_ifeffectProd", &ZSFYXSC));
|
|
|
//获取时间ZDATE
|
|
|
ZDATE = buffer;
|
|
|
//获取URLADD 将规范关系(IMAN_specification)的数据集传递到ftp中,传递URL地址
|
|
|
int gfnum = 0;
|
|
|
tag_t* gftag = NULL;
|
|
|
printf("开始获取规范关系文件\n");
|
|
|
ITKCALL(AOM_ask_value_tags(doc_tags[i], "IMAN_specification", &gfnum, &gftag));
|
|
|
//获取数据集的引用对象
|
|
|
string files = "";
|
|
|
|
|
|
for (int a = 0; a < gfnum; a++) {
|
|
|
printf("获取到了规范关系文件,开始遍历\n");
|
|
|
char* fileName = NULL;
|
|
|
ITKCALL(AOM_ask_value_string(gftag[a], "object_name", &fileName));
|
|
|
time_t nowtime;
|
|
|
time(&nowtime); //获取1970年1月1日0点0分0秒到现在经过的秒数
|
|
|
tm p;
|
|
|
localtime_s(&p, &nowtime); //将秒数转换为本地时间,年从1900算起,需要+1900,月为0-11,所以要+1
|
|
|
char fileDate[128] = "";
|
|
|
char getbuffer[80];
|
|
|
sprintf_s(getbuffer, "%04d%d%02d%02d%02d%02d", 1900 + p.tm_year, p.tm_mon + 1, p.tm_mday, p.tm_hour, p.tm_min, p.tm_sec);
|
|
|
//sprintf_s(getbuffer, "%04d年%d月%02d日 %02d:%02d", 1900 + p.tm_year, p.tm_mon + 1, p.tm_mday, p.tm_hour, p.tm_min);
|
|
|
printf("获取的时间:%s\n", getbuffer);
|
|
|
char sendname[SS_MAXPATHLEN] = "";
|
|
|
strcat(sendname, getbuffer);
|
|
|
strcat(sendname, "-");
|
|
|
char* random = generateRandomEightDigitNumberAsCharArray();
|
|
|
strcat(sendname, random);
|
|
|
strcat(sendname, "-");
|
|
|
strcat(sendname, fileName);
|
|
|
printf("合并后的字符串: % s\n", sendname);
|
|
|
printf("开始复制文件到file空间\n");
|
|
|
|
|
|
tag_t ref_object = NULLTAG;
|
|
|
printf("1");
|
|
|
AE_reference_type_t reference_type;
|
|
|
printf("2");
|
|
|
char ref_name[WSO_name_size_c + 1] = "excel";
|
|
|
ITKCALL(AE_ask_dataset_named_ref2(gftag[a], ref_name, &reference_type, &ref_object));
|
|
|
printf("3");
|
|
|
if (reference_type == AE_PART_OF)
|
|
|
{
|
|
|
printf("7");
|
|
|
char temp_file[SS_MAXPATHLEN] = "";
|
|
|
strcpy(temp_file, sendfilepath);
|
|
|
strcat(temp_file, "\\");
|
|
|
strcat(temp_file, sendname);
|
|
|
printf("temp_file%s", temp_file);
|
|
|
ITKCALL(IMF_export_file(ref_object, temp_file));
|
|
|
}
|
|
|
char temp_fileurl[SS_MAXPATHLEN] = "";
|
|
|
strcpy(temp_fileurl, fileURL);
|
|
|
strcat(temp_fileurl, sendname);
|
|
|
files = files + temp_fileurl + ",";
|
|
|
|
|
|
}
|
|
|
if (!files.empty()) {
|
|
|
files = files.substr(0, files.length() - 1);
|
|
|
}
|
|
|
URLADD = const_cast<char*>(files.c_str());
|
|
|
//开始拼接字符串MATNR,ZVERSION,ECNDOCU,ECNSTATE,ECRDOCU,ECRSTATE,ZSFYXSC,DATE,URLADD;
|
|
|
jsonStr << "{";
|
|
|
jsonStr << "\"matnr\":\"" << MATNR << "\",";
|
|
|
jsonStr << "\"zversion\":\"" << ZVERSION << "\",";
|
|
|
jsonStr << "\"ecndocu\":\"" << ECNDOCU << "\",";
|
|
|
jsonStr << "\"ecnstate\":\"" << ECNSTATE << "\",";
|
|
|
jsonStr << "\"ecrdocu\":\"" << ECRDOCU << "\",";
|
|
|
jsonStr << "\"ecrstate\":\"" << ECRSTATE << "\",";
|
|
|
jsonStr << "\"zsfyxsc\":\"" << ZSFYXSC << "\",";
|
|
|
jsonStr << "\"zdate\":\"" << ZDATE << "\",";
|
|
|
jsonStr << "\"urladd\":\"" << URLADD << "\"},";
|
|
|
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//获取ZSFYXSC
|
|
|
ITKCALL(AOM_ask_value_string(doc_tags[i], "ld6_ifeffectProd", &ZSFYXSC));
|
|
|
//获取时间ZDATE
|
|
|
ZDATE = buffer;
|
|
|
//获取URLADD 将规范关系(IMAN_specification)的数据集传递到ftp中,传递URL地址
|
|
|
int gfnum = 0;
|
|
|
tag_t* gftag = NULL;
|
|
|
printf("开始获取规范关系文件\n");
|
|
|
ITKCALL(AOM_ask_value_tags(doc_tags[i], "IMAN_specification", &gfnum, &gftag));
|
|
|
//获取数据集的引用对象
|
|
|
string files = "";
|
|
|
|
|
|
for (int a = 0; a < gfnum; a++) {
|
|
|
printf("获取到了规范关系文件,开始遍历\n");
|
|
|
char* fileName = NULL;
|
|
|
ITKCALL(AOM_ask_value_string(gftag[a], "object_name", &fileName));
|
|
|
time_t nowtime;
|
|
|
time(&nowtime); //获取1970年1月1日0点0分0秒到现在经过的秒数
|
|
|
tm p;
|
|
|
localtime_s(&p, &nowtime); //将秒数转换为本地时间,年从1900算起,需要+1900,月为0-11,所以要+1
|
|
|
char fileDate[128] = "";
|
|
|
char getbuffer[80];
|
|
|
sprintf_s(getbuffer, "%04d%d%02d%02d%02d%02d", 1900 + p.tm_year, p.tm_mon + 1, p.tm_mday, p.tm_hour, p.tm_min, p.tm_sec);
|
|
|
//sprintf_s(getbuffer, "%04d年%d月%02d日 %02d:%02d", 1900 + p.tm_year, p.tm_mon + 1, p.tm_mday, p.tm_hour, p.tm_min);
|
|
|
printf("获取的时间:%s\n", getbuffer);
|
|
|
char sendname[SS_MAXPATHLEN] = "";
|
|
|
strcat(sendname, getbuffer);
|
|
|
strcat(sendname, "-");
|
|
|
char* random = generateRandomEightDigitNumberAsCharArray();
|
|
|
strcat(sendname, random);
|
|
|
strcat(sendname, "-");
|
|
|
strcat(sendname, fileName);
|
|
|
printf("合并后的字符串: % s\n", sendname);
|
|
|
printf("开始复制文件到file空间\n");
|
|
|
|
|
|
tag_t ref_object = NULLTAG;
|
|
|
printf("1");
|
|
|
AE_reference_type_t reference_type;
|
|
|
printf("2");
|
|
|
char ref_name[WSO_name_size_c + 1] = "excel";
|
|
|
ITKCALL(AE_ask_dataset_named_ref2(gftag[a], ref_name, &reference_type, &ref_object));
|
|
|
printf("3");
|
|
|
if (reference_type == AE_PART_OF)
|
|
|
{
|
|
|
printf("7");
|
|
|
char temp_file[SS_MAXPATHLEN] = "";
|
|
|
strcpy(temp_file, sendfilepath);
|
|
|
strcat(temp_file, "\\");
|
|
|
strcat(temp_file, sendname);
|
|
|
printf("temp_file%s", temp_file);
|
|
|
ITKCALL(IMF_export_file(ref_object, temp_file));
|
|
|
}
|
|
|
char temp_fileurl[SS_MAXPATHLEN] = "";
|
|
|
strcpy(temp_fileurl, fileURL);
|
|
|
strcat(temp_fileurl, sendname);
|
|
|
files = files + temp_fileurl + ",";
|
|
|
|
|
|
}
|
|
|
if (!files.empty()) {
|
|
|
files = files.substr(0, files.length() - 1);
|
|
|
}
|
|
|
URLADD = const_cast<char*>(files.c_str());
|
|
|
//开始拼接字符串MATNR,ZVERSION,ECNDOCU,ECNSTATE,ECRDOCU,ECRSTATE,ZSFYXSC,DATE,URLADD;
|
|
|
jsonStr << "{";
|
|
|
jsonStr << "\"matnr\":\"" << MATNR << "\",";
|
|
|
jsonStr << "\"zversion\":\"" << ZVERSION << "\",";
|
|
|
jsonStr << "\"ecndocu\":\"" << ECNDOCU << "\",";
|
|
|
jsonStr << "\"ecnstate\":\"" << ECNSTATE << "\",";
|
|
|
jsonStr << "\"ecrdocu\":\"" << ECRDOCU << "\",";
|
|
|
jsonStr << "\"ecrstate\":\"" << ECRSTATE << "\",";
|
|
|
jsonStr << "\"zsfyxsc\":\"" << ZSFYXSC << "\",";
|
|
|
jsonStr << "\"zdate\":\"" << ZDATE << "\",";
|
|
|
jsonStr << "\"urladd\":\"" << URLADD << "\"},";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else if (strcmp(type, "LD6_CRRevision") == 0) {
|
|
|
int gx = 0;
|
|
|
tag_t *gxtag;
|
|
|
ITKCALL(AOM_ask_value_tags(doc_tags[i], "CMImplementedBy", &gx, &gxtag));
|
|
|
ITKCALL(AOM_ask_value_string(doc_tags[i], "item_id", &ECRDOCU));
|
|
|
date_t time1;
|
|
|
ITKCALL(AOM_ask_value_date(doc_tags[i], "date_released", &time1));
|
|
|
if (time1.year == 0) {
|
|
|
//日期为空
|
|
|
ECRSTATE = "未关闭";
|
|
|
}
|
|
|
else {
|
|
|
//日期不为空
|
|
|
ECRSTATE = "已关闭";
|
|
|
}
|
|
|
for (int b = 0; b < gx;b++) {
|
|
|
char* ty;
|
|
|
ITKCALL(AOM_ask_value_string(gxtag[b], "object_type", &ty));
|
|
|
if (strcmp("LD6_CNRevision",ty) == 0) {
|
|
|
ITKCALL(AOM_ask_value_string(gxtag[b], "item_id", &ECNDOCU));
|
|
|
date_t time;
|
|
|
ITKCALL(AOM_ask_value_date(gxtag[b], "date_released", &time));
|
|
|
if (time.year == 0) {
|
|
|
//日期为空
|
|
|
ECNSTATE = "未关闭";
|
|
|
}
|
|
|
else {
|
|
|
//日期不为空
|
|
|
ECNSTATE = "已关闭";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//获取ZSFYXSC
|
|
|
ITKCALL(AOM_ask_value_string(doc_tags[i], "ld6_ifeffectProd", &ZSFYXSC));
|
|
|
//获取时间ZDATE
|
|
|
ZDATE = buffer;
|
|
|
//获取URLADD 将规范关系(IMAN_specification)的数据集传递到ftp中,传递URL地址
|
|
|
int gfnum = 0;
|
|
|
tag_t* gftag = NULL;
|
|
|
printf("开始获取规范关系文件\n");
|
|
|
ITKCALL(AOM_ask_value_tags(doc_tags[i], "IMAN_specification", &gfnum, &gftag));
|
|
|
//获取数据集的引用对象
|
|
|
string files = "";
|
|
|
for (int a = 0; a < gfnum; a++) {
|
|
|
printf("获取到了规范关系文件,开始遍历\n");
|
|
|
char* fileName = NULL;
|
|
|
ITKCALL(AOM_ask_value_string(gftag[a], "object_name", &fileName));
|
|
|
time_t nowtime;
|
|
|
time(&nowtime); //获取1970年1月1日0点0分0秒到现在经过的秒数
|
|
|
tm p;
|
|
|
localtime_s(&p, &nowtime); //将秒数转换为本地时间,年从1900算起,需要+1900,月为0-11,所以要+1
|
|
|
char fileDate[128] = "";
|
|
|
char getbuffer[80];
|
|
|
sprintf_s(getbuffer, "%04d%d%02d%02d%02d%02d", 1900 + p.tm_year, p.tm_mon + 1, p.tm_mday, p.tm_hour, p.tm_min, p.tm_sec);
|
|
|
//sprintf_s(getbuffer, "%04d年%d月%02d日 %02d:%02d", 1900 + p.tm_year, p.tm_mon + 1, p.tm_mday, p.tm_hour, p.tm_min);
|
|
|
printf("获取的时间:%s\n", getbuffer);
|
|
|
char sendname[SS_MAXPATHLEN] = "";
|
|
|
strcat(sendname, getbuffer);
|
|
|
strcat(sendname, "-");
|
|
|
char* random = generateRandomEightDigitNumberAsCharArray();
|
|
|
strcat(sendname, random);
|
|
|
strcat(sendname, "-");
|
|
|
strcat(sendname, fileName);
|
|
|
printf("合并后的字符串: % s\n", sendname);
|
|
|
printf("开始复制文件到file空间\n");
|
|
|
|
|
|
tag_t ref_object = NULLTAG;
|
|
|
printf("1");
|
|
|
AE_reference_type_t reference_type;
|
|
|
printf("2");
|
|
|
char ref_name[WSO_name_size_c + 1] = "excel";
|
|
|
ITKCALL(AE_ask_dataset_named_ref2(gftag[a], ref_name, &reference_type, &ref_object));
|
|
|
printf("3");
|
|
|
if (reference_type == AE_PART_OF)
|
|
|
{
|
|
|
printf("7");
|
|
|
char temp_file[SS_MAXPATHLEN] = "";
|
|
|
strcpy(temp_file, sendfilepath);
|
|
|
strcat(temp_file, "\\");
|
|
|
strcat(temp_file, sendname);
|
|
|
printf("temp_file%s", temp_file);
|
|
|
ITKCALL(IMF_export_file(ref_object, temp_file));
|
|
|
}
|
|
|
char temp_fileurl[SS_MAXPATHLEN] = "";
|
|
|
strcpy(temp_fileurl, fileURL);
|
|
|
strcat(temp_fileurl, sendname);
|
|
|
files = files + temp_fileurl + ",";
|
|
|
|
|
|
}
|
|
|
if (!files.empty()) {
|
|
|
files = files.substr(0, files.length() - 1);
|
|
|
}
|
|
|
URLADD = const_cast<char*>(files.c_str());
|
|
|
//开始拼接字符串MATNR,ZVERSION,ECNDOCU,ECNSTATE,ECRDOCU,ECRSTATE,ZSFYXSC,DATE,URLADD;
|
|
|
jsonStr << "{";
|
|
|
jsonStr << "\"matnr\":\"" << MATNR << "\",";
|
|
|
jsonStr << "\"zversion\":\"" << ZVERSION << "\",";
|
|
|
jsonStr << "\"ecndocu\":\"" << ECNDOCU << "\",";
|
|
|
jsonStr << "\"ecnstate\":\"" << ECNSTATE << "\",";
|
|
|
jsonStr << "\"ecrdocu\":\"" << ECRDOCU << "\",";
|
|
|
jsonStr << "\"ecrstate\":\"" << ECRSTATE << "\",";
|
|
|
jsonStr << "\"zsfyxsc\":\"" << ZSFYXSC << "\",";
|
|
|
jsonStr << "\"zdate\":\"" << ZDATE << "\",";
|
|
|
jsonStr << "\"urladd\":\"" << URLADD << "\"},";
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else {
|
|
|
/*
|
|
|
* 如-primarytype参数为LD6_CNRevision,且LD6_CNRevision下-relation参数指定的关系下数据为空,
|
|
|
则获取LD6_CNRevision下CMImplements关系下的LD6_CRRevision下-relation参数指定的关系下
|
|
|
-secondarytype参数指定的类型
|
|
|
*/
|
|
|
if (strcmp(type,"LD6_CNRevision") == 0) {
|
|
|
int das_num2 = 0;
|
|
|
tag_t* das_tags2;
|
|
|
ITKCALL(AOM_ask_value_tags(doc_tags[i], "CMImplements", &das_num2, &das_tags2));
|
|
|
if (das_num2 > 0) {
|
|
|
//获取类型匹配次对象类型
|
|
|
char* cdxtype = NULL;
|
|
|
for (int j = 0; j < das_num2; j++) {
|
|
|
//开始拼接字符串组成json数据
|
|
|
char* MATNR = "", * ZVERSION = "", * ECNDOCU = "", * ECNSTATE = "", * ECRDOCU = "", * ECRSTATE = "", * ZSFYXSC = "", * ZDATE = "", * URLADD = " ";
|
|
|
ITKCALL(AOM_ask_value_string(das_tags2[j], "object_type", &cdxtype));
|
|
|
if (strstr(secondarytype, cdxtype) != NULL) {
|
|
|
//获取MATNR物料号
|
|
|
printf("获取MATNR物料号\n");
|
|
|
ITKCALL(AOM_ask_value_string(das_tags2[j], "item_id", &MATNR));
|
|
|
printf("获取ZVERSION零件版本\n");
|
|
|
ITKCALL(AOM_ask_value_string(das_tags2[j], "ld6_clientPartRev", &ZVERSION));
|
|
|
//获取ECNDOCU单号
|
|
|
/*
|
|
|
* LD6_ECRRevision时,获取流程目标中类型是LD6_ECRRevision的item_id属性
|
|
|
* LD6_ECNRevision时,获取流程目标中类型是LD6_ECNRevision的item_id属性
|
|
|
*/
|
|
|
if (strcmp(type, "LD6_CNRevision") == 0) {
|
|
|
ITKCALL(AOM_ask_value_string(doc_tags[i], "item_id", &ECNDOCU));
|
|
|
date_t time;
|
|
|
ITKCALL(AOM_ask_value_date(doc_tags[i], "date_released", &time));
|
|
|
if (time.year == 0) {
|
|
|
//日期为空
|
|
|
ECNSTATE = "未关闭";
|
|
|
}
|
|
|
else {
|
|
|
//日期不为空
|
|
|
ECNSTATE = "已关闭";
|
|
|
}
|
|
|
}
|
|
|
else if (strcmp(type, "LD6_CRRevision") == 0) {
|
|
|
ITKCALL(AOM_ask_value_string(doc_tags[i], "item_id", &ECRDOCU));
|
|
|
date_t time;
|
|
|
ITKCALL(AOM_ask_value_date(doc_tags[i], "date_released", &time));
|
|
|
if (time.year == 0) {
|
|
|
//日期为空
|
|
|
ECRSTATE = "未关闭";
|
|
|
}
|
|
|
else {
|
|
|
//日期不为空
|
|
|
ECRSTATE = "已关闭";
|
|
|
}
|
|
|
}
|
|
|
//获取ZSFYXSC
|
|
|
ITKCALL(AOM_ask_value_string(doc_tags[i], "ld6_ifeffectProd", &ZSFYXSC));
|
|
|
//获取时间ZDATE
|
|
|
ZDATE = buffer;
|
|
|
//获取URLADD 将规范关系(IMAN_specification)的数据集传递到ftp中,传递URL地址
|
|
|
int gfnum = 0;
|
|
|
tag_t* gftag;
|
|
|
ITKCALL(AOM_ask_value_tags(doc_tags[i], "IMAN_specification", &gfnum, &gftag));
|
|
|
//获取数据集的引用对象
|
|
|
string files = "";
|
|
|
for (int a = 0; a < gfnum; a++) {
|
|
|
char* fileName = NULL;
|
|
|
ITKCALL(AOM_ask_value_string(gftag[a], "object_name", &fileName));
|
|
|
time_t nowtime;
|
|
|
time(&nowtime); //获取1970年1月1日0点0分0秒到现在经过的秒数
|
|
|
tm p;
|
|
|
localtime_s(&p, &nowtime); //将秒数转换为本地时间,年从1900算起,需要+1900,月为0-11,所以要+1
|
|
|
char fileDate[128] = "";
|
|
|
char getbuffer[80];
|
|
|
sprintf_s(getbuffer, "%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);
|
|
|
printf("获取的时间:%s\n", getbuffer);
|
|
|
char sendname[SS_MAXPATHLEN] = "";
|
|
|
strcat(sendname, getbuffer);
|
|
|
strcat(sendname, "-");
|
|
|
char* random = generateRandomEightDigitNumberAsCharArray();
|
|
|
strcat(sendname, random);
|
|
|
strcat(sendname, "-");
|
|
|
strcat(sendname, fileName);
|
|
|
printf("合并后的字符串: % s\n", sendname);
|
|
|
printf("开始复制文件到file空间\n");
|
|
|
tag_t ref_object = NULLTAG;
|
|
|
printf("1");
|
|
|
AE_reference_type_t reference_type;
|
|
|
printf("2");
|
|
|
char ref_name[WSO_name_size_c + 1] = "excel";
|
|
|
ITKCALL(AE_ask_dataset_named_ref2(gftag[a], ref_name, &reference_type, &ref_object));
|
|
|
printf("3");
|
|
|
if (reference_type == AE_PART_OF)
|
|
|
{
|
|
|
printf("7");
|
|
|
char temp_file[SS_MAXPATHLEN] = "";
|
|
|
strcpy(temp_file, sendfilepath);
|
|
|
strcat(temp_file, "\\");
|
|
|
strcat(temp_file, sendname);
|
|
|
printf("temp_file%s", temp_file);
|
|
|
ITKCALL(IMF_export_file(ref_object, temp_file));
|
|
|
}
|
|
|
char temp_fileurl[SS_MAXPATHLEN] = "";
|
|
|
strcpy(temp_fileurl, fileURL);
|
|
|
strcat(temp_fileurl, sendname);
|
|
|
files = files + temp_fileurl + ",";
|
|
|
|
|
|
}
|
|
|
if (!files.empty()) {
|
|
|
files = files.substr(0, files.length() - 1);
|
|
|
}
|
|
|
URLADD = const_cast<char*>(files.c_str());
|
|
|
//开始拼接字符串MATNR,ZVERSION,ECNDOCU,ECNSTATE,ECRDOCU,ECRSTATE,ZSFYXSC,DATE,URLADD;
|
|
|
jsonStr << "{";
|
|
|
jsonStr << "\"matnr\":\"" << MATNR << "\",";
|
|
|
jsonStr << "\"zversion\":\"" << ZVERSION << "\",";
|
|
|
jsonStr << "\"ecndocu\":\"" << ECNDOCU << "\",";
|
|
|
jsonStr << "\"ecnstate\":\"" << ECNSTATE << "\",";
|
|
|
jsonStr << "\"ecrdocu\":\"" << ECRDOCU << "\",";
|
|
|
jsonStr << "\"ecrstate\":\"" << ECRSTATE << "\",";
|
|
|
jsonStr << "\"zsfyxsc\":\"" << ZSFYXSC << "\",";
|
|
|
jsonStr << "\"zdate\":\"" << ZDATE << "\",";
|
|
|
jsonStr << "\"urladd\":\"" << URLADD << "\"},";
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
char* MATNR = "", * ZVERSION = "", * ECNDOCU = "", * ECNSTATE = "", * ECRDOCU = "", * ECRSTATE = "", * ZSFYXSC = "", * ZDATE = "", * URLADD = " ";
|
|
|
//获取MATNR物料号
|
|
|
printf("获取MATNR物料号\n");
|
|
|
MATNR = " ";
|
|
|
printf("获取ZVERSION零件版本\n");
|
|
|
ZVERSION = " ";
|
|
|
//获取ECNDOCU单号
|
|
|
/*
|
|
|
* LD6_ECRRevision时,获取流程目标中类型是LD6_ECRRevision的item_id属性
|
|
|
* LD6_ECNRevision时,获取流程目标中类型是LD6_ECNRevision的item_id属性
|
|
|
*/
|
|
|
if (strcmp(type, "LD6_CNRevision") == 0) {
|
|
|
ITKCALL(AOM_ask_value_string(doc_tags[i], "item_id", &ECNDOCU));
|
|
|
date_t time;
|
|
|
ITKCALL(AOM_ask_value_date(doc_tags[i], "date_released", &time));
|
|
|
if (time.year == 0) {
|
|
|
//日期为空
|
|
|
ECNSTATE = "未关闭";
|
|
|
}
|
|
|
else {
|
|
|
//日期不为空
|
|
|
ECNSTATE = "已关闭";
|
|
|
}
|
|
|
}
|
|
|
else if (strcmp(type, "LD6_CRRevision") == 0) {
|
|
|
ITKCALL(AOM_ask_value_string(doc_tags[i], "item_id", &ECRDOCU));
|
|
|
date_t time;
|
|
|
ITKCALL(AOM_ask_value_date(doc_tags[i], "date_released", &time));
|
|
|
if (time.year == 0) {
|
|
|
//日期为空
|
|
|
ECRSTATE = "未关闭";
|
|
|
}
|
|
|
else {
|
|
|
//日期不为空
|
|
|
ECRSTATE = "已关闭";
|
|
|
}
|
|
|
}
|
|
|
//获取ZSFYXSC
|
|
|
ITKCALL(AOM_ask_value_string(doc_tags[i], "ld6_ifeffectProd", &ZSFYXSC));
|
|
|
//获取时间ZDATE
|
|
|
ZDATE = buffer;
|
|
|
//获取URLADD 将规范关系(IMAN_specification)的数据集传递到ftp中,传递URL地址
|
|
|
int gfnum = 0;
|
|
|
tag_t* gftag;
|
|
|
ITKCALL(AOM_ask_value_tags(doc_tags[i], "IMAN_specification", &gfnum, &gftag));
|
|
|
//获取数据集的引用对象
|
|
|
string files = "";
|
|
|
if (gfnum>0)
|
|
|
{
|
|
|
for (int a = 0; a < gfnum; a++) {
|
|
|
char* fileName = NULL;
|
|
|
ITKCALL(AOM_ask_value_string(gftag[a], "object_name", &fileName));
|
|
|
time_t nowtime;
|
|
|
time(&nowtime); //获取1970年1月1日0点0分0秒到现在经过的秒数
|
|
|
tm p;
|
|
|
localtime_s(&p, &nowtime); //将秒数转换为本地时间,年从1900算起,需要+1900,月为0-11,所以要+1
|
|
|
char fileDate[128] = "";
|
|
|
char getbuffer[80];
|
|
|
sprintf_s(getbuffer, "%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);
|
|
|
printf("获取的时间:%s\n", getbuffer);
|
|
|
char sendname[SS_MAXPATHLEN] = "";
|
|
|
strcat(sendname, getbuffer);
|
|
|
strcat(sendname, "-");
|
|
|
char* random = generateRandomEightDigitNumberAsCharArray();
|
|
|
strcat(sendname, random);
|
|
|
strcat(sendname, "-");
|
|
|
strcat(sendname, fileName);
|
|
|
printf("合并后的字符串: % s\n", sendname);
|
|
|
printf("开始复制文件到file空间\n");
|
|
|
tag_t ref_object = NULLTAG;
|
|
|
printf("1");
|
|
|
AE_reference_type_t reference_type;
|
|
|
printf("2");
|
|
|
char ref_name[WSO_name_size_c + 1] = "excel";
|
|
|
ITKCALL(AE_ask_dataset_named_ref2(gftag[a], ref_name, &reference_type, &ref_object));
|
|
|
printf("3");
|
|
|
if (reference_type == AE_PART_OF)
|
|
|
{
|
|
|
printf("7");
|
|
|
char temp_file[SS_MAXPATHLEN] = "";
|
|
|
strcpy(temp_file, sendfilepath);
|
|
|
strcat(temp_file, "\\");
|
|
|
strcat(temp_file, sendname);
|
|
|
printf("temp_file%s", temp_file);
|
|
|
ITKCALL(IMF_export_file(ref_object, temp_file));
|
|
|
}
|
|
|
char temp_fileurl[SS_MAXPATHLEN] = "";
|
|
|
strcpy(temp_fileurl, fileURL);
|
|
|
strcat(temp_fileurl, sendname);
|
|
|
files = files + temp_fileurl + ",";
|
|
|
|
|
|
}
|
|
|
}
|
|
|
if (!files.empty()) {
|
|
|
files = files.substr(0, files.length() - 1);
|
|
|
}
|
|
|
URLADD = const_cast<char*>(files.c_str());
|
|
|
//开始拼接字符串MATNR,ZVERSION,ECNDOCU,ECNSTATE,ECRDOCU,ECRSTATE,ZSFYXSC,DATE,URLADD;
|
|
|
jsonStr << "{";
|
|
|
jsonStr << "\"matnr\":\"" << MATNR << "\",";
|
|
|
jsonStr << "\"zversion\":\"" << ZVERSION << "\",";
|
|
|
jsonStr << "\"ecndocu\":\"" << ECNDOCU << "\",";
|
|
|
jsonStr << "\"ecnstate\":\"" << ECNSTATE << "\",";
|
|
|
jsonStr << "\"ecrdocu\":\"" << ECRDOCU << "\",";
|
|
|
jsonStr << "\"ecrstate\":\"" << ECRSTATE << "\",";
|
|
|
jsonStr << "\"zsfyxsc\":\"" << ZSFYXSC << "\",";
|
|
|
jsonStr << "\"zdate\":\"" << ZDATE << "\",";
|
|
|
jsonStr << "\"urladd\":\"" << URLADD << "\"},";
|
|
|
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//删除最后一位逗号
|
|
|
// 获取当前的字符串内容
|
|
|
std::string str = jsonStr.str();
|
|
|
|
|
|
// 检查并移除结尾的逗号(如果存在)
|
|
|
if (!str.empty() && str.back() == ',') {
|
|
|
str.pop_back();
|
|
|
}
|
|
|
|
|
|
// 在字符串末尾添加一个中括号
|
|
|
str += "]";
|
|
|
|
|
|
printf("获取的值数组:%s\n", str.c_str());
|
|
|
|
|
|
if (strcmp(str.c_str(),"[]") == 0) {
|
|
|
//没有获取到数据 跳过检查
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
char* taguid;
|
|
|
ITK__convert_tag_to_uid(rootTask_tag, &taguid);
|
|
|
string taguidstring = taguid;
|
|
|
string inputFile = "D:\\TCTOMAS\\" + taguidstring + "input.txt";
|
|
|
|
|
|
//将值数组写入本地
|
|
|
writeDataToFile(inputFile, str.c_str());
|
|
|
|
|
|
|
|
|
//调用cmd执行jar包,将数据传递到MES和SAP中
|
|
|
char cmd[4196] = "";
|
|
|
strcpy(cmd, "java -jar D:\\Siemens\\Teamcenter13\\bin\\sapjco3.jar");
|
|
|
printf("\n1%s\n", cmd);
|
|
|
strcat(cmd, " ");
|
|
|
printf("\n2%s\n", cmd);
|
|
|
strcat(cmd, url);
|
|
|
printf("\n3%s\n", cmd);
|
|
|
strcat(cmd, " ");
|
|
|
printf("\n4%s\n", cmd);
|
|
|
strcat(cmd, taguid);
|
|
|
printf("\n5%s\n", cmd);
|
|
|
strcat(cmd, " ");
|
|
|
printf("\n6%s\n", cmd);
|
|
|
strcat(cmd, "ECNECR");
|
|
|
printf("\n7%s\n", cmd);
|
|
|
strcat(cmd, " ");
|
|
|
printf("\n8%s\n", cmd);
|
|
|
strcat(cmd, flowId);
|
|
|
printf("\n9%s\n", cmd);
|
|
|
system(cmd);
|
|
|
|
|
|
//读取本地文件获取执行结果
|
|
|
//读取本地的result文件(SAP)
|
|
|
string fileid = flowId;
|
|
|
string MESfile = "D:\\TCTOMAS\\" + fileid + "result.txt";
|
|
|
std::ifstream file(MESfile);
|
|
|
if (!file.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 << file.rdbuf();
|
|
|
std::string resultStr = buffer1.str();
|
|
|
printf("返回的值%s:\n", resultStr.c_str());
|
|
|
if (strcmp(resultStr.c_str(), "SAP:成功,MES:成功") == 0) {
|
|
|
return 0;
|
|
|
}
|
|
|
else {
|
|
|
EMH_store_error_s2(EMH_severity_error, ITK_err, "提示", resultStr.c_str());
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
//返回信息报错提示
|
|
|
char* error = "流程目标下没有对象";
|
|
|
EMH_store_error_s2(EMH_severity_error, ITK_err, "提示", error);
|
|
|
return 1;
|
|
|
}
|
|
|
} |