#define _CRT_SECURE_NO_WARNINGS
#include "epm_handler_common.h"

void getTCMUserMesSopJson(int index, tag_t topLine, tag_t BomLine, map<string, string> typePropertyType, char parameters[100000]);
void getTCMUserMesSopProperty(tag_t topLine, tag_t BomLine, char * prodOrderNo, char * ERPCode, map<string, string> typePropertyType, char parameters[100000]);

bool isUserMesSopStart = true;

void getTCMUserMesItemSopProperty(tag_t item, map<string, string> typePropertyType, char parameters[100000])
{
	char *itemType = NULL;
	AOM_ask_value_string(item, "object_type", &itemType);

	printf("itemType%s Start===================\n", itemType);

	//过滤掉非版本的对象
	if ((strstr(itemType, "Revision") == NULL) || (strstr(itemType, "Master") != NULL)
		|| (strstr(itemType, "master") != NULL) || (strstr(itemType, "BOM") != NULL) || (strstr(itemType, "bom") != NULL) || (strstr(itemType, "Bom") != NULL))
	{
		DOFREE(itemType);
		return;
	}
	//获取子项
	tag_t top_line = NULLTAG, window = NULLTAG;
	BOM_create_window(&window);
	//设置顶层BOM
	BOM_set_window_top_line(window, NULLTAG, item, NULLTAG, &top_line);
	//获取单个的json字符串
	if (isUserMesSopStart)
	{
		getTCMUserMesSopJson(-1, top_line, NULLTAG, typePropertyType, parameters);
		isUserMesSopStart = false;
	}
	else
	{
		getTCMUserMesSopJson(-1, top_line, NULLTAG, typePropertyType, parameters);
	}

	BOM_close_window(window);
	MEM_free(itemType);
}

int ML_TCMUserSendMesSop(void * returnValue)
{
	printf("=========================TCM USER SOP下发到MES 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<char *> 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<string, string> 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<char*, char*>(valueChar[0], valueChar[1]));
		}
	}

	char *tc_root_file = getenv("tc_root");		//C:\Siemens\Teamcenter11
	char parameters[100000] = "";//写入到文件的值
	strcat(parameters, "getTCMMesSopPropertys}}");
	strcat(parameters, messageUser);
	strcat(parameters, "}}");
	/*strcat(parameters, "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\">");
	strcat(parameters, "<soapenv:Header/>");
	strcat(parameters, "<soapenv:Body>");
	strcat(parameters, "<tem:PostSOPInformationData>");
	strcat(parameters, "<tem:dataList>");*/
	strcat(parameters, "[");


	getTCMUserMesItemSopProperty(item, typePropertyType, parameters);

	strcat(parameters, "]");
	/*strcat(parameters, "</tem:dataList>");
	strcat(parameters, "</tem:PostSOPInformationData>");
	strcat(parameters, "</soapenv:Body>");
	strcat(parameters, "</soapenv:Envelope>");*/

	isUserMesSopStart = true;
	//获取当前时间
	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 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(attachments[i], "ml8_BOMFirstTime", dateNow);
			}
			else
			{
			AOM_set_value_string(attachments[i], "ml8_BOMNewTime", dateNow);
			}*/
			AOM_save(item);
			AOM_unlock(item);
			AOM_refresh(item, false);
			DOFREE(sendTime);
		}
		DOFREE(itemType);
		POM_AM__set_application_bypass(FALSE);
	}
	messageUserValues.clear();
	vector<char *>().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 BOM下发到SAP End===================\n");
	return ifail;
}

void getTCMUserMesSopJson(int index, tag_t topLine, tag_t BomLine, map<string, string> typePropertyType, char parameters[100000])
{
	//获取订单BOM属性
	char * prodOrderNo = NULL;//生产订单号
	char * ERPCode = NULL;//ERP班组编码

	tag_t revisions = NULLTAG;

	AOM_ask_value_tag(topLine, "bl_line_object", &revisions);


	//获取版本下的订单BOM IMAN_METarget
	int tagCount = 0;
	tag_t * tags = NULL;
	AOM_ask_value_tags(revisions, "IMAN_METarget", &tagCount, &tags);

	if (tagCount > 0)
	{
		AOM_ask_value_string(tags[0], "ml8_ProdOrderNo", &prodOrderNo);
		char* ceshiname;
		AOM_ask_value_string(tags[0], "object_string", &ceshiname);
		printf("名称：%s", ceshiname);
		printf("生产订单号：%s",prodOrderNo);
		AOM_ask_value_string(tags[0], "ml8_ERPCode", &ERPCode);



		if (strlen(prodOrderNo) == 7)
		{

			char orderNo[12] = "";
			strcat(orderNo, "00000");
			strcat(orderNo, prodOrderNo);
			strcpy(prodOrderNo, orderNo);
		}
		else if (strlen(prodOrderNo) == 10)
		{

			char orderNo[14] = ""; // 分配足够的空间来存储连接后的字符串
			strcpy(orderNo, "00");
			strcat(orderNo, prodOrderNo);
			strcpy(prodOrderNo, orderNo);
		}

		//获取订单工艺SOP文件
		tag_t relation_tag = NULLTAG;
		//获取关系
		GRM_find_relation_type("IMAN_specification", &relation_tag);
		if (relation_tag != NULLTAG) {
			int rfCount = 0;
			tag_t * rfTags = NULLTAG;
			GRM_list_secondary_objects_only(revisions, relation_tag, &rfCount, &rfTags);
			for (int j = 0; j < rfCount; j++)
			{
				char *dsType = NULL;
				tag_t dataset = rfTags[j];
				//获取类型
				AOM_ask_value_string(dataset, "object_type", &dsType);
				if (strcmp(dsType, "pdf") == 0 || strcmp(dsType, "pdf") == 0)
				{
					char * ext = ".pdf";
					/*if (strcmp(dsType, "MSExcelX") == 0)
					{
						ext = "xlsx";
					}
					else
					{
						ext = "xls";
					}*/

					//下载数据集
					tag_t spec_dataset_rev = NULLTAG,
						ref_object = NULLTAG;

					AE_reference_type_t reference_type;
					AE_ask_dataset_latest_rev(dataset, &spec_dataset_rev);

					char ref_name[WSO_name_size_c + 1] = "pdf";
					AE_ask_dataset_named_ref2(spec_dataset_rev, ref_name, &reference_type, &ref_object);
					if (reference_type == AE_PART_OF)
					{
						char * pathname = NULL;
						IMF_ask_file_pathname2(ref_object, SS_WNT_MACHINE, &pathname);
						char * origin_file_name = NULL;
						IMF_ask_original_file_name2(ref_object, &origin_file_name);
						char new_ds_name[WSO_name_size_c + 1] = "";
						char *new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0);
						char *temp_dir = getenv("temp");
						char temp_file[SS_MAXPATHLEN] = "";
						strcpy(temp_file, temp_dir);
						strcat(temp_file, "\\");
						strcat(temp_file, new_file_name);

						IMF_export_file(ref_object, temp_file);

						//上传到FTP
						const char * sapFilePath = inputFileToFtp(temp_file);
						if (sapFilePath != NULL)
						{
							//拼接json字符串
							if (isUserMesSopStart)
							{
								strcat(parameters, "{");
								isUserMesSopStart = FALSE;
							}
							else
							{
								strcat(parameters, ",{");
							}

							strcat(parameters, "\"");
							strcat(parameters, "LineCode");
							strcat(parameters, "\"");
							strcat(parameters, ":");
							strcat(parameters, "\"");
							strcat(parameters, ERPCode);
							strcat(parameters, "\",");
							strcat(parameters, "\"");
							strcat(parameters, "PrdOrderCode");
							strcat(parameters, "\"");
							strcat(parameters, ":");
							strcat(parameters, "\"");
							strcat(parameters, prodOrderNo);
							strcat(parameters, "\",");
							strcat(parameters, "\"");
							strcat(parameters, "StationCode");
							strcat(parameters, "\"");
							strcat(parameters, ":");
							strcat(parameters, "\"");
							strcat(parameters, "");
							strcat(parameters, "\",");
							strcat(parameters, "\"");
							strcat(parameters, "StationName");
							strcat(parameters, "\"");
							strcat(parameters, ":");
							strcat(parameters, "\"");
							strcat(parameters, "");
							strcat(parameters, "\",");
							strcat(parameters, "\"");
							strcat(parameters, "SOPUrl");
							strcat(parameters, "\"");
							strcat(parameters, ":");
							strcat(parameters, "\"");
							strcat(parameters, sapFilePath);
							strcat(parameters, "\"");

							strcat(parameters, "}");
						}

						DOFREE(pathname);
						DOFREE(origin_file_name);
					}
					DOFREE(ext);
				}
				DOFREE(dsType);
			}
			DOFREE(rfTags);
		}


		getTCMUserMesSopProperty(topLine, BomLine, prodOrderNo, ERPCode, typePropertyType, parameters);
	}
	DOFREE(tags);
	DOFREE(prodOrderNo);
	DOFREE(ERPCode);
}

void getTCMUserMesSopProperty(tag_t topLine, tag_t BomLine, char * prodOrderNo, char * ERPCode, map<string, string> typePropertyType, char parameters[100000])
{
	//通过根据订单工艺获取产线工艺
	int  count;
	tag_t *children_line = NULLTAG;

	BOM_line_ask_all_child_lines(topLine, &count, &children_line);

	printf("产线工艺数量%d Start===================\n", count);
	for (int i = 0; i < count; i++)
	{
		//获取班组工艺
		int  classProcessCount = 0;
		tag_t* classProcess_Bomline = NULLTAG;

		BOM_line_ask_all_child_lines(children_line[i], &classProcessCount, &classProcess_Bomline);
		printf("班组工艺数量%d Start===================\n", classProcessCount);
		for (int kk = 0; kk < classProcessCount; kk++)
		{
			//获取工位工艺信息
			int  procLineCount;
			tag_t* procLine_Bomline = NULLTAG;

			BOM_line_ask_all_child_lines(classProcess_Bomline[kk], &procLineCount, &procLine_Bomline);
			printf("工位工艺数量%d Start===================\n", procLineCount);
			for (int k = 0; k < procLineCount; k++)
			{
				//获取工位工艺下的工步信息
				int  stepCount;
				tag_t* step_Bomline = NULLTAG;

				BOM_line_ask_all_child_lines(procLine_Bomline[k], &stepCount, &step_Bomline);
				printf("工步数量%d Start===================\n", stepCount);
				//先遍历获取工位编号和名称
				char* itemId = NULL;
				char* objectName = NULL;
				for (int j = 0; j < stepCount; j++)
				{
					char* itemType = NULL;
					AOM_ask_value_string(step_Bomline[j], "fnd0bl_line_object_type", &itemType);
					if (strcmp(itemType, "ML8_StationRevision") == 0)
					{
						AOM_ask_value_string(step_Bomline[j], "bl_item_item_id", &itemId);
						AOM_ask_value_string(step_Bomline[j], "bl_item_object_name", &objectName);
						DOFREE(itemType);
						break;
					}
					DOFREE(itemType);
				}
				printf("工位编号%s Start===================\n", itemId);
				printf("工位名称%s Start===================\n", objectName);

				//获取SOP文件
				tag_t stationRevisions = NULLTAG;
				AOM_ask_value_tag(procLine_Bomline[k], "bl_line_object", &stationRevisions);

				//获取工位SOP文件
				tag_t relation_tag = NULLTAG;
				//获取关系
				GRM_find_relation_type("IMAN_specification", &relation_tag);
				if (relation_tag != NULLTAG) {
					int rfCount = 0;
					tag_t* rfTags = NULLTAG;
					GRM_list_secondary_objects_only(stationRevisions, relation_tag, &rfCount, &rfTags);
					printf("数据集数量%d Start===================\n", rfCount);
					for (int j = 0; j < rfCount; j++)
					{
						char* dsType = NULL;
						tag_t dataset = rfTags[j];
						//获取类型
						AOM_ask_value_string(dataset, "object_type", &dsType);
						printf("数据集类型%s Start===================\n", dsType);
						if (strcmp(dsType, "PDF") == 0 || strcmp(dsType, "PDF") == 0)
						{
							char* ext = "pdf";
							/*if (strcmp(dsType, "MSExcelX") == 0)
							{
								ext = "xlsx";
							}
							else
							{
								ext = "xls";
							}*/

							//下载数据集
							tag_t spec_dataset_rev = NULLTAG,
								ref_object = NULLTAG;

							AE_reference_type_t reference_type;
							AE_ask_dataset_latest_rev(dataset, &spec_dataset_rev);

							char ref_name[WSO_name_size_c + 1] = "PDF_Reference";
							AE_ask_dataset_named_ref2(spec_dataset_rev, ref_name, &reference_type, &ref_object);
							if (reference_type == AE_PART_OF)
							{
								char* pathname = NULL;
								IMF_ask_file_pathname2(ref_object, SS_WNT_MACHINE, &pathname);
								char* origin_file_name = NULL;
								IMF_ask_original_file_name2(ref_object, &origin_file_name);
								char new_ds_name[WSO_name_size_c + 1] = "";
								char* new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0);
								char* temp_dir = getenv("temp");
								char temp_file[SS_MAXPATHLEN] = "";
								strcpy(temp_file, temp_dir);
								strcat(temp_file, "\\");
								strcat(temp_file, new_file_name);



								if (strstr(temp_file, "\\") != NULL)
								{
									string resultString = replace_all_distinct(temp_file, "\\", "/");

									//char resultChar[SS_MAXPATHLEN] = "";

									strcpy(temp_file, resultString.c_str());

									*(temp_file + strlen(resultString.c_str())) = '\0';

									//temp_file = resultChar;

								}

								printf("下载到：%s Start===================\n", temp_file);
								IMF_export_file(ref_object, temp_file);

								//上传到FTP
								char* sapFilePath = inputFileToFtp(temp_file);
								if (sapFilePath != NULL && strcmp(sapFilePath, "") != 0)
								{
									//拼接json字符串
									if (isUserMesSopStart)
									{
										strcat(parameters, "{");
										isUserMesSopStart = FALSE;
									}
									else
									{
										strcat(parameters, ",{");
									}
									printf("拼接json2:orderNo=%s\n", prodOrderNo);
									strcat(parameters, "\"");
									strcat(parameters, "LineCode");
									strcat(parameters, "\"");
									strcat(parameters, ":");
									strcat(parameters, "\"");
									strcat(parameters, ERPCode);
									strcat(parameters, "\",");
									strcat(parameters, "\"");
									strcat(parameters, "PrdOrderCode");
									strcat(parameters, "\"");
									strcat(parameters, ":");
									strcat(parameters, "\"");
									strcat(parameters, prodOrderNo);
									strcat(parameters, "\",");
									strcat(parameters, "\"");
									strcat(parameters, "StationCode");
									strcat(parameters, "\"");
									strcat(parameters, ":");
									strcat(parameters, "\"");
									strcat(parameters, itemId);
									strcat(parameters, "\",");
									strcat(parameters, "\"");
									strcat(parameters, "StationName");
									strcat(parameters, "\"");
									strcat(parameters, ":");
									strcat(parameters, "\"");
									strcat(parameters, objectName);
									strcat(parameters, "\",");
									strcat(parameters, "\"");
									strcat(parameters, "SOPUrl");
									strcat(parameters, "\"");
									strcat(parameters, ":");
									strcat(parameters, "\"");
									strcat(parameters, sapFilePath);
									strcat(parameters, "\"");

									strcat(parameters, "}");
									printf("拼接json2:parameters=%s\n", parameters);
								}

								DOFREE(pathname);
								DOFREE(origin_file_name);
							}
							DOFREE(ext);
						}
						DOFREE(dsType);
					}
					DOFREE(rfTags);
				}
				DOFREE(step_Bomline);
				DOFREE(objectName);
				DOFREE(itemId);

			}
			//传递3DPDF关系
			for (int k = 0; k < procLineCount; k++)
			{
				//获取工位工艺下的工步信息
				int  stepCount;
				tag_t* step_Bomline = NULLTAG;

				BOM_line_ask_all_child_lines(procLine_Bomline[k], &stepCount, &step_Bomline);
				printf("工步数量%d Start===================\n", stepCount);
				//先遍历获取工位编号和名称
				char* itemId = NULL;
				char* objectName = NULL;
				for (int j = 0; j < stepCount; j++)
				{
					char* itemType = NULL;
					AOM_ask_value_string(step_Bomline[j], "fnd0bl_line_object_type", &itemType);

					//BOM_line_ask_item
					if (strcmp(itemType, "ML8_StationRevision") == 0)
					{
						AOM_ask_value_string(step_Bomline[j], "bl_item_item_id", &itemId);
						AOM_ask_value_string(step_Bomline[j], "bl_rev_object_name", &objectName);
						DOFREE(itemType);
						break;
					}
					DOFREE(itemType);
				}
				printf("工位编号%s Start===================\n", itemId);
				printf("工位名称%s Start===================\n", objectName);

				//获取SOP文件
				tag_t stationRevisions = NULLTAG;
				AOM_ask_value_tag(procLine_Bomline[k], "bl_line_object", &stationRevisions);
				//获取工位SOP文件
				tag_t relation_tag2 = NULLTAG;
				//获取关系
				GRM_find_relation_type("ML8_3Dpdf", &relation_tag2);
				char* itemType = NULL, * value = NULL;
				AOM_ask_value_string(stationRevisions, "object_type", &itemType);
				AOM_ask_value_string(stationRevisions, "object_string", &value);
				printf("object:%s	itemType:%s\n", value, itemType);
				if (strcmp(itemType, "ML8_ProcStatnRevision") == 0 && relation_tag2 != NULLTAG) {
					int rfCount = 0;
					tag_t* rfTags = NULLTAG;
					GRM_list_secondary_objects_only(stationRevisions, relation_tag2, &rfCount, &rfTags);
					printf("ML8_3Dpdf数据集数量%d Start===================\n", rfCount);
					for (int j = 0; j < rfCount; j++)
					{
						char* dsType = NULL;
						tag_t dataset = rfTags[j];
						//获取类型
						AOM_ask_value_string(dataset, "object_type", &dsType);
						printf("数据集类型%s Start===================\n", dsType);
						if (strcmp(dsType, "pdf") == 0 || strcmp(dsType, "PDF") == 0)
						{
							char* ext = "pdf";
							/*if (strcmp(dsType, "MSExcelX") == 0)
							{
							ext = "xlsx";
							}
							else
							{
							ext = "xls";
							}*/

							//下载数据集
							tag_t spec_dataset_rev = NULLTAG,
								ref_object = NULLTAG;

							AE_reference_type_t reference_type;
							AE_ask_dataset_latest_rev(dataset, &spec_dataset_rev);

							char ref_name[WSO_name_size_c + 1] = "PDF_Reference";
							AE_ask_dataset_named_ref2(spec_dataset_rev, ref_name, &reference_type, &ref_object);
							if (reference_type == AE_PART_OF)
							{
								char* pathname = NULL;
								IMF_ask_file_pathname2(ref_object, SS_WNT_MACHINE, &pathname);
								char* origin_file_name = NULL;
								IMF_ask_original_file_name2(ref_object, &origin_file_name);
								char new_ds_name[WSO_name_size_c + 1] = "";
								char* new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0);
								char* temp_dir = getenv("temp");
								char temp_file[SS_MAXPATHLEN] = "";
								strcpy(temp_file, temp_dir);
								strcat(temp_file, "\\");
								strcat(temp_file, new_file_name);



								if (strstr(temp_file, "\\") != NULL)
								{
									string resultString = replace_all_distinct(temp_file, "\\", "/");

									//char resultChar[SS_MAXPATHLEN] = "";

									strcpy(temp_file, resultString.c_str());

									*(temp_file + strlen(resultString.c_str())) = '\0';

									//temp_file = resultChar;

								}

								printf("下载到：%s Start===================\n", temp_file);
								IMF_export_file(ref_object, temp_file);

								//上传到FTP
								char* sapFilePath = inputFileToFtp(temp_file);
								if (sapFilePath != NULL && strcmp(sapFilePath, "") != 0)
								{
									//拼接json字符串
									if (isUserMesSopStart)
									{
										strcat(parameters, "{");
										isUserMesSopStart = FALSE;
									}
									else
									{
										strcat(parameters, ",{");
									}
									printf("拼接json2:orderNo=%s\n", prodOrderNo);
									strcat(parameters, "\"");
									strcat(parameters, "LineCode");
									strcat(parameters, "\"");
									strcat(parameters, ":");
									strcat(parameters, "\"");
									strcat(parameters, ERPCode);
									strcat(parameters, "\",");
									strcat(parameters, "\"");
									strcat(parameters, "PrdOrderCode");
									strcat(parameters, "\"");
									strcat(parameters, ":");
									strcat(parameters, "\"");
									strcat(parameters, prodOrderNo);
									strcat(parameters, "\",");
									strcat(parameters, "\"");
									strcat(parameters, "StationCode");
									strcat(parameters, "\"");
									strcat(parameters, ":");
									strcat(parameters, "\"");
									strcat(parameters, itemId);
									strcat(parameters, "\",");
									strcat(parameters, "\"");
									strcat(parameters, "StationName");
									strcat(parameters, "\"");
									strcat(parameters, ":");
									strcat(parameters, "\"");
									strcat(parameters, objectName);
									strcat(parameters, "\",");
									strcat(parameters, "\"");
									strcat(parameters, "SOPUrl");
									strcat(parameters, "\"");
									strcat(parameters, ":");
									strcat(parameters, "\"");
									strcat(parameters, sapFilePath);
									strcat(parameters, "\"");

									strcat(parameters, "}");
									printf("拼接json2:parameters=%s\n", parameters);
								}

								DOFREE(pathname);
								DOFREE(origin_file_name);
							}
							DOFREE(ext);
						}
						DOFREE(dsType);
					}
					DOFREE(rfTags);
				}

				DOFREE(step_Bomline);
				DOFREE(objectName);
				DOFREE(itemId);

			}
		}
	

		DOFREE(procLine_Bomline);
	}

	DOFREE(children_line);
}