#define _CRT_SECURE_NO_WARNINGS
#include "epm_handler_common.h"

void getItemJson(int index, tag_t topLine, tag_t BomLine, bool isStart, map<string, string> typePropertyType, char parameters[100000]);
void getBomLineProperty(tag_t topLine, tag_t BomLine, map<string, string> typePropertyType, char* bomBaseNum, char* sortString, char parameters[100000]);

bool isSendBomStart = true;

int RB_SendErpBom(EPM_action_message_t msg)
{
	printf("=========================BOM下发到ERP Start===================\n");
	//POM_AM__set_application_bypass(true);
	int ifail = ITK_ok;
	int  attachments_num = 0;
	tag_t  rootTask = NULLTAG, * attachments = NULLTAG;
	//获取任务对象
	EPM_ask_root_task(msg.task, &rootTask);
	//获取任务目标对象
	EPM_ask_attachments(rootTask, EPM_target_attachment, &attachments_num, &attachments);

	//获取参数
	char* argflag = NULL, * argvalue = NULL, * arg = NULL;
	char messageUser[1024] = "", messageResult[1024] = "";
	int arg_cnt = TC_number_of_arguments(msg.arguments);
	printf("参数个数为：%d\n", arg_cnt);
	if (arg_cnt > 0)
	{
		for (int i = 0; i < arg_cnt; i++)
		{
			//获取下一个参数（从0开始）
			arg = TC_next_argument(msg.arguments);
			//获取参数的名称和值
			ifail = ITK_ask_argument_named_value((const char*)arg, &argflag, &argvalue);
			if (stricmp(argflag, "ownerId") == 0)
			{
				if (argvalue != NULL)
				{
					strcpy(messageUser, argvalue);
				}
			}
			else if (stricmp(argflag, "messageResult") == 0)
			{
				if (argvalue != NULL)
				{
					strcpy(messageResult, argvalue);
				}
			}
		}
	}

	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("RB_BOMSendErpProperty", &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 errorMessage[100000] = "";//写入到文件的值
	for (int i = 0; i < attachments_num; i++)
	{
		char* itemType = NULL;
		AOM_ask_value_string(attachments[i], "object_type", &itemType);

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

		//过滤掉非版本的对象
		if (strcmp(itemType, "RB3_ZCRevision") != 0)
		{
			DOFREE(itemType);
			continue;
		}


		isSendBomStart = true;

		char parameters[100000] = "";//写入到文件的值
		strcat(parameters, "getBomPropertys}}");
		strcat(parameters, "[");

		/*if ((strstr(itemType, "ZCRevision") == NULL) || (strstr(itemType, "Master") != NULL)
			|| (strstr(itemType, "master") != NULL) || (strstr(itemType, "BOM") != NULL) || (strstr(itemType, "bom") != NULL) || (strstr(itemType, "Bom") != NULL))
		{
			DOFREE(itemType);
			continue;
		}*/

		//获取所有包含替代项目组的BOM行
		vector<tag_t> bomLines;
		//获取子项
		tag_t top_line = NULLTAG, window = NULLTAG;
		BOM_create_window(&window);
		//设置顶层BOM
		BOM_set_window_top_line(window, NULLTAG, attachments[i], NULLTAG, &top_line);
		//获取单个的json字符串
		if (isSendBomStart)
		{
			getItemJson(-1, top_line, NULLTAG, isSendBomStart, typePropertyType, parameters);
			//isStart = false;
		}
		else
		{
			getItemJson(-1, top_line, NULLTAG, isSendBomStart, typePropertyType, parameters);
		}


		DOFREE(itemType);

		strcat(parameters, "]");
		//获取当前时间
		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, "RB_SendErp.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;
			strcat(errorMessage, strResult.c_str());
			if (strcmp(messageResult, "1") == 0)
			{
				ifail = 1;
			}
		}
	}

	messageUserValues.clear();
	vector<char*>().swap(messageUserValues);
	MEM_free(attachments);
	tc_root_file = NULL;
	pref_vals = NULL;
	if (ifail == 1)
	{
		EMH_store_error_s1(EMH_severity_user_error, EMH_USER_error_base, errorMessage);
	}
	printf("=========================BOM下发到ERP End===================\n");
	return ifail;
}

void getItemJson(int index, tag_t topLine, tag_t BomLine, bool isStart, map<string, string> typePropertyType, char parameters[100000])
{
	//获取版本产线
	int factoryNum = 0;
	char** factoryValues = NULL;
	char* localization_status;
	logical master;
	tag_t revisions = NULLTAG;

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

	char* itemType = NULL;
	AOM_ask_value_string(revisions, "object_type", &itemType);


	string propertyNames = typePropertyType[itemType];

	if (propertyNames.c_str() != NULL)
	{
		//获取工厂
		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);
			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);

					if (strcmp(values[1], "FACTORY") == 0)
					{
						//printf("values[0]:%s\n", values[0]);
						//TCGetPropertyValue(attachments[i], "Revision", values[0], &factoryValues);
						AOM_UIF_ask_localized_value_strings(revisions, values[0], "zh_CN", &factoryNum, &factoryValues, &localization_status, &master);
						//AOM_ask_value_strings(revisions, values[0], &factoryNum, &factoryValues);
					}
				}
			}
		}
		else
		{
			//按照-进行拆分。拆分条件
			int valueCount = 0;
			char** valueChar = new char* [64];
			//分割字符串
			split(name, "=", valueChar, &valueCount);
			if (strcmp(valueChar[1], "FACTORY") == 0)
			{
				//printf("valueChar[0]:%s\n", valueChar[0]);
				AOM_UIF_ask_localized_value_strings(revisions, valueChar[0], "zh_CN", &factoryNum, &factoryValues, &localization_status, &master);
				//AOM_UIF_ask_values(revisions, valueChar[0], &factoryNum, &factoryValues);
			}
		}
	}
	//获取当前时间
	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);


	printf("factoryNum:%d\n", factoryNum);
	if (factoryNum > 0)
	{
		for (int j = 0; j < factoryNum; j++)
		{
			if (factoryValues[j] == NULL || strcmp(factoryValues[j], "") == 0)
			{
				continue;
			}
			printf("factoryValues[j]:%s\n", factoryValues[j]);
			getBomLineProperty(topLine, BomLine, typePropertyType, factoryValues[j], date, parameters);
		}
	}
}

void getBomLineProperty(tag_t topLine, tag_t BomLine, map<string, string> typePropertyType, char* bomBaseNum, char* date, char parameters[100000])
{
	//char parameters[100000] = "";//写入到文件的值
	//bool isStart = true;
	int  count = 0;
	tag_t* children_line = NULLTAG;

	BOM_line_ask_all_child_lines(topLine, &count, &children_line);

	printf("count:%d\n", count);
	for (int i = 0; i < count; i++)
	{
		//AOM_ask_value_string(children_line[i], "fnd0bl_line_object_type", &itemType);


		char* itemType = NULL;
		AOM_ask_value_string(children_line[i], "bl_item_object_type", &itemType);

		char* puid = NULL;
		//获取PUID
		ITK__convert_tag_to_uid(children_line[i], &puid);
		string revisionType = itemType;
		string typeRev = revisionType + "Revision";
		printf("object_type%s\n", typeRev.c_str());
		//过滤掉非版本的对象
		string propertyNames = typePropertyType[typeRev];
		//printf("propertyNames%s\n", propertyNames.c_str());
		if (!propertyNames.empty() && propertyNames.length() > 0)
		{
			printf("propertyNames%s\n", propertyNames.c_str());
			if (isSendBomStart)
			{
				strcat(parameters, "{");
				isSendBomStart = false;
			}
			else
			{
				strcat(parameters, ",{");
			}

			const char* constName = propertyNames.c_str();
			char* name = new char[2048];//足够长
			strcpy(name, constName);

			if (strstr(name, ",") != NULL)
			{
				//按照,进行拆分。拆分条件
				printf("按照,进行拆分。拆分条件\n");
				int valueCount = 0;
				char** valueChar = new char* [64];
				//分割字符串
				split(name, ",", valueChar, &valueCount);
				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] == NULL ? "" : values[1]);
						strcat(parameters, "\"");
						strcat(parameters, ":");

						char* item_rev_value = NULL;
						//printf("values[0]%s\n", values[0]);
						TCGetPropertyValue(children_line[i], "BOMLine", values[0], &item_rev_value);
						//printf("item_rev_value%s\n", item_rev_value);
						if (strcmp(values[1], "INPUTTIME") == 0)
						{
							item_rev_value = date;
						}
						if (strcmp(values[1], "PARENTID") == 0)
						{
							TCGetPropertyValue(topLine, "BOMLine", "rev.item_id", &item_rev_value);
						}
						if (strcmp(values[1], "FACTORY") == 0)
						{
							item_rev_value = bomBaseNum;
						}

						if (strcmp(item_rev_value, "/") == 0)
						{
							item_rev_value = "";
						}
						strcat(parameters, "\"");
						strcat(parameters, item_rev_value == NULL ? "" : item_rev_value);
						strcat(parameters, "\"");
						if (k < valueCount - 1)
						{
							strcat(parameters, ",");
						}
						//printf("字符串%s\n", parameters);

						DOFREE(item_rev_value);
					}
				}
			}
			else
			{
				//按照-进行拆分。拆分条件
				printf("按照-进行拆分。拆分条件\n");
				int valueCount = 0;
				char** valueChar = new char* [64];
				//分割字符串
				split(name, "=", valueChar, &valueCount);

				strcat(parameters, "\"");
				strcat(parameters, valueChar[1] == NULL ? "" : valueChar[1]);
				strcat(parameters, "\"");
				strcat(parameters, ":");

				char* item_rev_value = NULL;
				TCGetPropertyValue(children_line[i], "BOMLine", valueChar[0], &item_rev_value);
				if (strcmp(valueChar[1], "INPUTTIME") == 0)
				{
					item_rev_value = date;
				}
				if (strcmp(valueChar[1], "PARENTID") == 0)
				{
					TCGetPropertyValue(topLine, "BOMLine", "rev.item_id", &item_rev_value);
				}
				if (strcmp(valueChar[1], "FACTORY") == 0)
				{
					item_rev_value = bomBaseNum;
				}

				if (strcmp(item_rev_value, "/") == 0)
				{
					item_rev_value = "";
				}
				strcat(parameters, "\"");
				strcat(parameters, item_rev_value == NULL ? "" : item_rev_value);
				strcat(parameters, "\"");

				//printf("字符串%s\n", parameters);

				DOFREE(item_rev_value);
			}
			strcat(parameters, "}");

			DOFREE(constName);
		}


		DOFREE(replaceProject);
		DOFREE(itemType);
		DOFREE(puid);

		printf("parameters:%s\n", parameters);
		getBomLineProperty(children_line[i], BomLine, typePropertyType, bomBaseNum, date, parameters);
	}

	DOFREE(children_line);
}


map<string, int> getClassAttrMap(map<string, map<string, int>> classMap, char* classId) {
	map<string, int> attrMap;
	//分类属性名称对应id map存储
	if (classMap.find(classId) == classMap.end()) {
		int count = 0;
		int* ids;
		int* arraySize;
		int* formats;
		int* options;
		char** names;
		char** shortNames;
		char** annotations;
		char** unit;
		char** minValues;
		char** maxValues;
		char** defaultValues;
		char** descriptions;
		ITKCALL(ICS_class_describe_attributes(classId, &count, &ids, &names, &shortNames, &annotations, &arraySize,
			&formats, &unit, &minValues, &maxValues, &defaultValues, &descriptions, &options));
		for (int i = 0; i < count; i++)
		{
			attrMap.insert(pair<string, int>(names[i], ids[i]));
		}
		classMap.insert(pair<string, map<string, int>>(classId, attrMap));
		if (ids != NULL) {
			DOFREE(ids);
		}
		if (arraySize != NULL) {
			DOFREE(arraySize);
		}
		if (formats != NULL) {
			DOFREE(formats);
		}
		if (options != NULL) {
			DOFREE(options);
		}
		if (names != NULL) {
			DOFREE(names);
		}
		if (shortNames != NULL) {
			DOFREE(shortNames);
		}
		if (annotations != NULL) {
			DOFREE(annotations);
		}
		if (unit != NULL) {
			DOFREE(unit);
		}
		if (minValues != NULL) {
			DOFREE(minValues);
		}
		if (maxValues != NULL) {
			DOFREE(maxValues);
		}
		if (defaultValues != NULL) {
			DOFREE(defaultValues);
		}
		if (descriptions != NULL) {
			DOFREE(descriptions);
		}
	}
	else {
		attrMap = classMap[classId];
	}
	return attrMap;
}

void getItemClass(int status, char* itemType, tag_t ico_tag, tag_t zi_rev, map<string, int> attrMap, char* classId, char** classCode) {
	printf("-----------------getItemClass------------------------\n");
	if (status)
	{
		printf("提示:中间数据表访问失败\n");
	}
	else {
		char* field1 = NULL;
		char* field2 = NULL;
		int outputColumn = 0, outputValueCount = 0;
		char*** outputValue = NULL;
		//物料分类特殊处理,通过数据库表匹配
		char sql[1024] = "\0";
		if (strcmp("RB3_LBJRevision", itemType) == 0 || strcmp("RB3_GNZCRevision", itemType) == 0 || strcmp("RB3_GNLBJRevision", itemType) == 0 || strcmp("RB3_GYZYRevision", itemType) == 0) {
			if (strcmp("RB3_LBJRevision", itemType) == 0 && ico_tag != NULLTAG)
			{
				ITKCALL(AOM_UIF_ask_value(zi_rev, "object_name", &field1));
				char* value = NULL;
				ICS_ask_attribute_value(ico_tag, "类别", &value);
				if (value != NULL) {
					int id = attrMap["类别"];
					getClassValue(value, id, &field2);
					DOFREE(value);
				}
			}
			else if (strcmp("RB3_GNZCRevision", itemType) == 0 && ico_tag != NULLTAG)
			{
				char* value = NULL;
				ICS_ask_attribute_value(ico_tag, "产品类别", &value);
				if (value != NULL) {
					int id = attrMap["产品类别"];
					getClassValue(value, id, &field1);
					DOFREE(value);
				}
				ITKCALL(AOM_UIF_ask_value(zi_rev, "object_name", &field2));
			}
			else if (strcmp("RB3_GNLBJRevision", itemType) == 0 && ico_tag != NULLTAG)
			{
				ITKCALL(AOM_UIF_ask_value(zi_rev, "object_name", &field1));
				char* value = NULL;
				ICS_ask_attribute_value(ico_tag, "产品类别", &value);
				if (value != NULL) {
					int id = attrMap["产品类别"];
					getClassValue(value, id, &field2);
					DOFREE(value);
				}
			}
			else if (strcmp("RB3_GYZYRevision", itemType) == 0 && ico_tag != NULLTAG)
			{
				char* new_classId = NULL;
				if (startsWith(classId, '1', '2') || startsWith(classId, '1', '7'))
				{
					new_classId = getFirstStr(classId, 2);
				}
				else
				{
					new_classId = getFirstStr(classId, 4);
				}
				tag_t classTag = NULLTAG;
				char* id = NULL;
				if (new_classId != NULL) {
					ITKCALL(ICS_find_class(new_classId, &classTag));
					if (classTag != NULLTAG)
					{
						ITKCALL(ICS_ask_id_name(classTag, &id, &field1));
					}
				}
				if (id != NULL) {
					DOFREE(id);
				}
				if (classTag != NULL) {
					DOFREE(classTag);
				}
				if (new_classId != NULL) {
					DOFREE(new_classId);
				}
			}
			if (field1 != NULL) {
				if (field1 != NULL && field2 != NULL) {
					sprintf(sql, "select PCLASSCODE,PCLASSNAME,NEW_COLUMN,PUNIT from PLM_ERP_CLASS_TABLE where PFIELD01= '%s' and PFIELD02= '%s'", field1, field2);
				}
				else {
					sprintf(sql, "select PCLASSCODE,PCLASSNAME,NEW_COLUMN,PUNIT from PLM_ERP_CLASS_TABLE where PFIELD01= '%s'", field1);
				}
			}
		}
		else {
			if (strcmp("RB3_ZCRevision", itemType) == 0)
			{
				ITKCALL(AOM_UIF_ask_value(zi_rev, "rb3_zclx", &field1));
			}
			else if (strcmp("RB3_BZJRevision", itemType) == 0 || strcmp("RB3_BZJBJRevision", itemType) == 0
				|| strcmp("RB3_YZRevision", itemType) == 0 || strcmp("RB3_GQRevision", itemType) == 0
				|| strcmp("RB3_GQBJRevision", itemType) == 0 || strcmp("RB3_GZRevision", itemType) == 0
				|| strcmp("RB3_GZBJRevision", itemType) == 0)
			{
				ITKCALL(AOM_UIF_ask_value(zi_rev, "object_name", &field1));
				printf("提示:field1T==%s\n", field1);
			}
			else if (strcmp("RB3_YCLRevision", itemType) == 0 || strcmp("RB3_SLRevision", itemType) == 0
				|| strcmp("RB3_XJRevision", itemType) == 0 || strcmp("RB3_WJTLRevision", itemType) == 0)
			{
				ITKCALL(AOM_UIF_ask_value(zi_rev, "rb3_bjlx", &field1));
			}
			else if (strcmp("RB3_XZCPRevision", itemType) == 0)
			{
				ITKCALL(AOM_UIF_ask_value(zi_rev, "rb3_cplx2", &field1));
			}
			else if (strcmp("RB3_XZLBJRevision", itemType) == 0 && ico_tag != NULLTAG)
			{
				char* value = NULL;
				ICS_ask_attribute_value(ico_tag, "零件类别", &value);
				if (value != NULL) {
					int id = attrMap["零件类别"];
					getClassValue(value, id, &field1);
					DOFREE(value);
				}
			}
			if (field1 != NULL) {
				sprintf(sql, "select PCLASSCODE,PCLASSNAME,NEW_COLUMN,PUNIT from PLM_ERP_CLASS_TABLE where PFIELD01= '%s'", field1);
			}
		}
		if (strcmp("", sql) != 0) {
			printf("提示:sqlT==%s\n", sql);
			if (QuerySQLNoInputParam(sql, &outputColumn, &outputValueCount, &outputValue) == -1 || outputValueCount == 0)
			{
				//printf("提示:物料分类查询 失败, %s \n", sql);
				char sql2[128] = "\0";
				sprintf(sql2, "select PCLASSCODE,PCLASSNAME from PLM_ERP_CLASS_TABLE where PFIELD01= '%s'", field1);
				printf("提示:sql2T==%s\n", sql2);
				if (QuerySQLNoInputParam(sql2, &outputColumn, &outputValueCount, &outputValue) == -1)
				{
					printf("提示:物料分类查询 失败, %s \n", sql2);
				}
			}
			printf("outputValueCount=%d\n", outputValueCount);
			printf("outputColumn=%d\n", outputColumn);
			//free(sql);
			if (outputValueCount > 0) {
				*classCode = outputValue[0][0];
				printf("物料分类====%s\n", *classCode);
			}
		}
		if (outputValue != NULL) {
			DOFREE(outputValue);
		}
		if (field1 != NULL) {
			DOFREE(field1);
		}
		if (field2 != NULL) {
			DOFREE(field2);
		}
	}

}

void getBomLinePropertyNew(tag_t topLine, char** c_sql_values, vector<string>* parameters_vec, map<string, map<string, int>> classMap, map<string, vector<string>> factoryMap, map<string, string> unitMap)
{
	printf("开始获取子件信息\n");
	tag_t fu_rev = NULLTAG;
	AOM_ask_value_tag(topLine, "bl_line_object", &fu_rev);

	tag_t* children_line = NULLTAG;
	int  count = 0;

	BOM_line_ask_all_child_lines(topLine, &count, &children_line);
	if (count > 0) {
		int status = ConnServer(c_sql_values[1], c_sql_values[2], c_sql_values[0]);
		char* fu_item_id = NULL;
		char* fu_smzqzt = NULL;
		char* fu_item_revision_id = NULL;
		char* fu_object_name = NULL;
		char* fu_object_type = NULL;
		char* fu_cph = NULL;
		char** fu_scgc = NULL;
		int factoryCount = 0;
		ITKCALL(AOM_UIF_ask_value(fu_rev, "item_id", &fu_item_id));
		ITKCALL(AOM_UIF_ask_value(fu_rev, "rb3_smzqzt", &fu_smzqzt));
		ITKCALL(AOM_UIF_ask_value(fu_rev, "item_revision_id", &fu_item_revision_id));
		ITKCALL(AOM_UIF_ask_value(fu_rev, "object_name", &fu_object_name));
		ITKCALL(AOM_UIF_ask_value(fu_rev, "rb3_cph", &fu_cph));
		char* itemType = NULL;
		AOM_ask_value_string(fu_rev, "object_type", &itemType);
		if (strcmp("RB3_XZCPRevision", itemType) == 0 || strcmp("RB3_XZLBJRevision", itemType) == 0) {
			ITKCALL(AOM_UIF_ask_values(fu_rev, "rb3_xzscgc", &factoryCount, &fu_scgc));
		}
		else if (strcmp("RB3_GNZCRevision", itemType) == 0 || strcmp("RB3_GNLBJRevision", itemType) == 0
			|| strcmp("RB3_GYZYRevision", itemType) == 0 || strcmp("RB3_BZJRevision", itemType) == 0) {
			ITKCALL(AOM_UIF_ask_values(fu_rev, "rb3_scgc", &factoryCount, &fu_scgc));
		}
		else if (strcmp("RB3_YCLRevision", itemType) == 0) {
			ITKCALL(AOM_UIF_ask_values(fu_rev, "rb3_sygc1", &factoryCount, &fu_scgc));
		}
		else {
			ITKCALL(AOM_UIF_ask_values(fu_rev, "rb3_scgc1", &factoryCount, &fu_scgc));
		}
		ITKCALL(AOM_ask_value_string(fu_rev, "object_type", &fu_object_type));

		char facttoryNameStr[4000] = "\0";
		char factoryCodeStr[2000] = "\0";
		char organizeNameStr[5000] = "\0";
		char organizeCodeStr[3000] = "\0";
		//这里写服务名,不能用实例名(名称相同除外)
		if (status)
		{
			printf("提示:中间数据表访问失败\n");
		}
		else {
			//工厂组织编码特殊处理,通过数据库表匹配

			for (int i = 0; i < factoryCount; i++)
			{
				if (factoryMap.find(fu_scgc[i]) == factoryMap.end()) {
					char* factoryCode = NULL;
					char* factoryName = NULL;
					int factoryColumn = 0, factoryValueCount = 0;
					char*** factoryValue = NULL;
					char factorySql[128] = "\0";
					sprintf(factorySql, "select PFACTORYCODE,PFACTORYNAME from PLM_ERP_FACTORY_TABLE where PFACTORY= '%s'", fu_scgc[i]);
					printf("提示:factorySql==%s\n", factorySql);
					if (QuerySQLNoInputParam(factorySql, &factoryColumn, &factoryValueCount, &factoryValue) == -1)
					{
						printf("提示:组织编码查询 失败, %s \n", factorySql);
					}
					//printf("factoryValueCount=%d\n", factoryValueCount);
					//printf("factoryColumn=%d\n", factoryColumn);
					if (factoryValueCount > 0) {
						factoryCode = factoryValue[0][0];
						factoryName = factoryValue[0][1];
						vector<string> factoryVec;
						factoryVec.push_back(factoryCode);
						factoryVec.push_back(factoryName);
						factoryMap[fu_scgc[i]] = factoryVec;
						//printf("组织编码====%s\n", factoryCode);
						//printf("组织名称====%s\n", factoryName);
						if (strcmp(facttoryNameStr, "") != 0) {
							strcat(facttoryNameStr, ",");
							strcat(factoryCodeStr, ",");
						}
						if (factoryName != NULL) {
							strcat(facttoryNameStr, factoryName);
						}
						if (factoryCode != NULL) {
							strcat(factoryCodeStr, factoryCode);
						}

					}
					if (factoryValue != NULL) {
						DOFREE(factoryValue);
					}
					if (factoryCode != NULL) {
						DOFREE(factoryCode);
					}
					if (factoryName != NULL) {
						DOFREE(factoryName);
					}
				}
				else {
					vector<string> factoryVec = factoryMap[fu_scgc[i]];
					if (strcmp(facttoryNameStr, "") != 0) {
						strcat(facttoryNameStr, ",");
						strcat(factoryCodeStr, ",");
					}
					strcat(factoryCodeStr, factoryVec[0].c_str());
					strcat(facttoryNameStr, factoryVec[1].c_str());

				}

			}
			char* fu_class_code = NULL;
			tag_t fu_ico_tag = NULLTAG;
			char* fu_class_id = NULL;
			map<string, int> fuAttrMap;
			ICS_ask_classification_object(fu_rev, &fu_ico_tag);
			if (fu_ico_tag != NULLTAG) {
				ICS_ico_ask_class(fu_ico_tag, &fu_class_id);
				printf(">> fu_class_id: %s\n", fu_class_id);
				fuAttrMap = getClassAttrMap(classMap, fu_class_id);
			}
			getItemClass(status, fu_object_type, fu_ico_tag, fu_rev, fuAttrMap, fu_class_id, &fu_class_code);
			//处理组织工厂逻辑
			char* organizeCode = NULL;
			char* organizeName = NULL;
			char* organizeFactory = NULL;
			char factorySql2[128] = "\0";
			int organizeColumn = 0, organizeValueCount = 0;
			char*** organizeValue = NULL;
			printf("fu_object_type: %s\n", fu_object_type);
			printf("fu_class_code: %s\n", fu_class_code);
			printf("fu_item_id: %s\n", fu_item_id);
			if (strcmp("RB3_LBJRevision", fu_object_type) == 0) {
				sprintf(factorySql2, "select PFACTORY,PFACTORYCODE,PFACTORYNAME from PLM_FACTORY_ORGANIZE_TABLE where CLASSCODE= '%s'", fu_class_code);
				printf("提示:factorySql2==%s\n", factorySql2);
				if (QuerySQLNoInputParam(factorySql2, &organizeColumn, &organizeValueCount, &organizeValue) == -1)
				{
					printf("提示:组织编码查询 失败, %s \n", factorySql2);
				}
				//printf("factoryValueCount=%d\n", organizeValueCount);
				//printf("factoryColumn=%d\n", organizeColumn);
				if (organizeValueCount > 0) {
					organizeFactory = organizeValue[0][0];
					organizeCode = organizeValue[0][1];
					organizeName = organizeValue[0][2];
					printf("组织工厂====%s\n", organizeFactory);
					printf("组织名称2====%s\n", organizeName);
					printf("组织编码2====%s\n", organizeCode);
				}
				else {
					strcpy(organizeNameStr, facttoryNameStr);
					strcpy(organizeCodeStr, factoryCodeStr);

				}
				if (organizeFactory != NULL && strcmp("", organizeFactory) != 0 && strcmp("NULL", organizeFactory) != 0) {
					strcpy(organizeNameStr, facttoryNameStr);
					strcpy(organizeCodeStr, factoryCodeStr);
				}
				if (organizeName != NULL && strcmp("NULL", organizeName) != 0 && strcmp("", organizeName) != 0) {
					if (strcmp(organizeNameStr, "") != 0) {
						strcat(organizeNameStr, ",");
					}
					strcat(organizeNameStr, organizeName);
				}
				if (organizeCode != NULL && strcmp("NULL", organizeCode) != 0 && strcmp("", organizeCode) != 0) {
					if (strcmp(organizeCodeStr, "") != 0) {
						strcat(organizeCodeStr, ",");
					}
					strcat(organizeCodeStr, organizeCode);
				}
			}
			else if (strcmp("RB3_XZCPRevision", fu_object_type) == 0) {
				char* field1 = NULL;
				int outputColumn = 0, outputValueCount = 0;
				char*** outputValue = NULL;
				//物料分类特殊处理,通过数据库表匹配
				char sql[1024] = "\0";
				ITKCALL(AOM_UIF_ask_value(fu_rev, "rb3_cplx2", &field1));
				if (field1 != NULL) {
					sprintf(sql, "select PCLASSCODE from PLM_ERP_CLASS_TABLE where PFIELD01= '%s'", field1);
				}
				if (QuerySQLNoInputParam(sql, &outputColumn, &outputValueCount, &outputValue) == -1 || outputValueCount == 0)
				{
					printf("提示:父级物料分类查询 失败, %s \n", sql);
					strcpy(organizeNameStr, facttoryNameStr);
					strcpy(organizeCodeStr, factoryCodeStr);
				}
				else {
					//printf("outputValueCount=%d\n", outputValueCount);
					//printf("outputColumn=%d\n", outputColumn);
					//free(sql);
					char* fuClassCode = NULL;
					if (outputValueCount > 0) {
						fuClassCode = outputValue[0][0];
						//printf("父级物料分类====%s\n", fuClassCode);
					}
					if (strcmp("IN07", fuClassCode) == 0) {
						sprintf(factorySql2, "select PFACTORYCODE,PFACTORYNAME from PLM_FACTORY_ORGANIZE_TABLE where PTYPE= 'RB3_GNZCRevision' and PFIELD01= '滚动体类'");
						printf("提示:factorySql2==%s\n", factorySql2);
						if (QuerySQLNoInputParam(factorySql2, &organizeColumn, &organizeValueCount, &organizeValue) == -1)
						{
							printf("提示:组织编码查询 失败, %s \n", factoryCodeStr);
						}
						//printf("factoryValueCount=%d\n", organizeValueCount);
						//printf("factoryColumn=%d\n", organizeColumn);
						if (organizeValueCount > 0) {
							organizeCode = organizeValue[0][0];
							organizeName = organizeValue[0][1];
							printf("组织名称2====%s\n", organizeName);
							printf("组织编码2====%s\n", organizeCode);
						}
						else {
							strcpy(organizeNameStr, facttoryNameStr);
							strcpy(organizeCodeStr, factoryCodeStr);

						}
						if (organizeName != NULL && strcmp("NULL", organizeName) != 0) {
							strcpy(organizeNameStr, organizeName);
						}
						if (organizeCode != NULL && strcmp("NULL", organizeCode) != 0) {
							strcpy(organizeCodeStr, organizeCode);
						}
					}
					else {
						strcpy(organizeNameStr, facttoryNameStr);
						strcpy(organizeCodeStr, factoryCodeStr);
					}
					if (fuClassCode != NULL) {
						DOFREE(fuClassCode);
					}
				}
				if (field1 != NULL) {
					DOFREE(field1);
				}
				if (outputValue != NULL) {
					DOFREE(outputValue);
				}
			}
			else if (strcmp("RB3_BZJRevision", fu_object_type) == 0) {
				char* field1 = NULL;
				int outputColumn = 0, outputValueCount = 0;
				char*** outputValue = NULL;
				//物料分类特殊处理,通过数据库表匹配
				char sql[1024] = "\0";
				ITKCALL(AOM_UIF_ask_value(fu_rev, "object_name", &field1));
				if (field1 != NULL) {
					sprintf(sql, "select PCLASSCODE from PLM_ERP_CLASS_TABLE where PFIELD01= '%s'", field1);
				}
				if (QuerySQLNoInputParam(sql, &outputColumn, &outputValueCount, &outputValue) == -1 || outputValueCount == 0)
				{
					printf("提示:父级物料分类查询 失败, %s \n", sql);
					strcpy(organizeNameStr, facttoryNameStr);
					strcpy(organizeCodeStr, factoryCodeStr);
				}
				else {
					//printf("outputValueCount=%d\n", outputValueCount);
					//printf("outputColumn=%d\n", outputColumn);
					//free(sql);
					char* fuClassCode = NULL;
					if (outputValueCount > 0) {
						fuClassCode = outputValue[0][0];
						//printf("父级物料分类====%s\n", fuClassCode);
					}
					if (strcmp("IN07", fuClassCode) == 0) {
						sprintf(factorySql2, "select PFACTORY,PFACTORYCODE,PFACTORYNAME from PLM_FACTORY_ORGANIZE_TABLE where CLASSCODE= '%s'", fuClassCode);
						printf("提示:factorySql2==%s\n", factorySql2);
						if (QuerySQLNoInputParam(factorySql2, &organizeColumn, &organizeValueCount, &organizeValue) == -1)
						{
							printf("提示:组织编码查询 失败, %s \n", factoryCodeStr);
						}
						//printf("factoryValueCount=%d\n", organizeValueCount);
						//printf("factoryColumn=%d\n", organizeColumn);
						if (organizeValueCount > 0) {
							organizeFactory = organizeValue[0][0];
							organizeCode = organizeValue[0][1];
							organizeName = organizeValue[0][2];
							printf("组织工厂====%s\n", organizeFactory);
							printf("组织名称2====%s\n", organizeName);
							printf("组织编码2====%s\n", organizeCode);
						}
						else {
							strcpy(organizeNameStr, facttoryNameStr);
							strcpy(organizeCodeStr, factoryCodeStr);

						}
						if (organizeFactory != NULL && strcmp("", organizeFactory) != 0 && strcmp("NULL", organizeFactory) != 0) {
							strcpy(organizeNameStr, facttoryNameStr);
							strcpy(organizeCodeStr, factoryCodeStr);
						}
						if (organizeName != NULL && strcmp("NULL", organizeName) != 0 && strcmp("", organizeName) != 0) {
							if (strcmp(organizeNameStr, "") != 0) {
								strcat(organizeNameStr, ",");
							}
							strcat(organizeNameStr, organizeName);
						}
						if (organizeCode != NULL && strcmp("NULL", organizeCode) != 0 && strcmp("", organizeCode) != 0) {
							if (strcmp(organizeCodeStr, "") != 0) {
								strcat(organizeCodeStr, ",");
							}
							strcat(organizeCodeStr, organizeCode);
						}
					}
					else {
						strcpy(organizeNameStr, facttoryNameStr);
						strcpy(organizeCodeStr, factoryCodeStr);
					}
					if (fuClassCode != NULL) {
						DOFREE(fuClassCode);
					}
				}
				if (field1 != NULL) {
					DOFREE(field1);
				}
				if (outputValue != NULL) {
					DOFREE(outputValue);
				}
			}
			else {
				strcpy(organizeNameStr, facttoryNameStr);
				strcpy(organizeCodeStr, factoryCodeStr);

			}
			//if (strcmp("RB3_ZCRevision", fu_object_type) == 0) {	
			//	if (strstr(fu_object_name, "轴承") == NULL) {
			//		sprintf(factorySql2, "select PFACTORY,PFACTORYCODE,PFACTORYNAME from PLM_FACTORY_ORGANIZE_TABLE where PFIELD01= '%s'", fu_object_name);
			//		printf("提示:factorySql2==%s\n", factorySql2);
			//		if (QuerySQLNoInputParam(factorySql2, &organizeColumn, &organizeValueCount, &organizeValue) == -1)
			//		{
			//			printf("提示:组织编码查询 失败, %s \n", factorySql2);
			//		}
			//		printf("factoryValueCount=%d\n", organizeValueCount);
			//		printf("factoryColumn=%d\n", organizeColumn);
			//		organizeFactory = organizeValue[0][0];
			//		organizeCode = organizeValue[0][1];
			//		organizeName = organizeValue[0][2];
			//		printf("组织工厂====%s\n", organizeFactory);
			//		printf("组织名称2====%s\n", organizeName);
			//		printf("组织编码2====%s\n", organizeCode);
			//		if (strcmp("", organizeFactory) != 0 && organizeFactory != NULL && strcmp("NULL", organizeFactory) != 0) {
			//			strcpy(organizeNameStr, facttoryNameStr);
			//			strcpy(organizeCodeStr, factoryCodeStr);
			//		}
			//		if (organizeName != NULL && strcmp("NULL", organizeName) != 0) {
			//			if (strcmp(organizeNameStr, "") != 0) {
			//				strcat(organizeNameStr, ",");
			//			}
			//			strcat(organizeNameStr, organizeName);
			//		}
			//		if (organizeCode != NULL && strcmp("NULL", organizeCode) != 0) {
			//			if (strcmp(organizeCodeStr, "") != 0) {
			//				strcat(organizeCodeStr, ",");
			//			}
			//			strcat(organizeCodeStr, organizeCode);
			//		}
			//	}
			//	else {
			//		strcpy(organizeNameStr, facttoryNameStr);
			//		strcpy(organizeCodeStr, factoryCodeStr);

			//	}
			//}
			//else if (strcmp("RB3_XZCPRevision", fu_object_type) == 0) {
			//	char* field1 = NULL;
			//	int outputColumn = 0, outputValueCount = 0;
			//	char*** outputValue = NULL;
			//	//物料分类特殊处理,通过数据库表匹配
			//	char sql[1024] = "\0";
			//	ITKCALL(AOM_UIF_ask_value(fu_rev, "rb3_cplx2", &field1));
			//	if (field1 != NULL) {
			//		sprintf(sql, "select PCLASSCODE from PLM_ERP_CLASS_TABLE where PFIELD01= '%s'", field1);
			//	}
			//	if (QuerySQLNoInputParam(sql, &outputColumn, &outputValueCount, &outputValue) == -1 || outputValueCount == 0)
			//	{
			//		printf("提示:父级物料分类查询 失败, %s \n", sql);
			//	}
			//	else {
			//		printf("outputValueCount=%d\n", outputValueCount);
			//		printf("outputColumn=%d\n", outputColumn);
			//		//free(sql);
			//		char* fuClassCode = NULL;
			//		if (outputValueCount > 0) {
			//			fuClassCode = outputValue[0][0];
			//			printf("父级物料分类====%s\n", fuClassCode);
			//		}
			//		if (strcmp("IN07", fuClassCode) == 0) {
			//			sprintf(factorySql2, "select PFACTORYCODE,PFACTORYNAME from PLM_FACTORY_ORGANIZE_TABLE where PTYPE= 'RB3_GNZCRevision' and PFIELD01= '滚动体类'");
			//		}
			//		else {
			//			sprintf(factorySql2, "select PFACTORYCODE,PFACTORYNAME from PLM_FACTORY_ORGANIZE_TABLE where PTYPE= 'RB3_GNZCRevision' and PFIELD01= '除滚动体外产品'");
			//		}
			//		printf("提示:factorySql2==%s\n", factorySql2);
			//		if (QuerySQLNoInputParam(factorySql2, &organizeColumn, &organizeValueCount, &organizeValue) == -1)
			//		{
			//			printf("提示:组织编码查询 失败, %s \n", factoryCodeStr);
			//		}
			//		printf("factoryValueCount=%d\n", organizeValueCount);
			//		printf("factoryColumn=%d\n", organizeColumn);
			//		organizeCode = organizeValue[0][0];
			//		organizeName = organizeValue[0][1];
			//		printf("组织名称2====%s\n", organizeName);
			//		printf("组织编码2====%s\n", organizeCode);
			//		if (organizeName != NULL && strcmp("NULL", organizeName) != 0) {
			//			strcpy(organizeNameStr, organizeName);
			//		}
			//		if (organizeCode != NULL && strcmp("NULL", organizeCode) != 0) {
			//			strcpy(organizeCodeStr, organizeCode);
			//		}
			//		if (fuClassCode != NULL) {
			//			DOFREE(fuClassCode);
			//		}
			//	}
			//	if (field1 != NULL) {
			//		DOFREE(field1);
			//	}
			//	if (outputValue != NULL) {
			//		DOFREE(outputValue);
			//	}
			//}
			//else if (strcmp("RB3_GNZCRevision", fu_object_type) == 0) {
			//	sprintf(factorySql2, "select PFACTORYCODE,PFACTORYNAME from PLM_FACTORY_ORGANIZE_TABLE where PTYPE= 'RB3_GNZCRevision'");
			//	printf("提示:factorySql2==%s\n", factorySql2);

			//	if (QuerySQLNoInputParam(factorySql2, &organizeColumn, &organizeValueCount, &organizeValue) == -1)
			//	{
			//		printf("提示:组织编码查询 失败, %s \n", factoryCodeStr);
			//	}
			//	printf("factoryValueCount=%d\n", organizeValueCount);
			//	printf("factoryColumn=%d\n", organizeColumn);
			//	organizeCode = organizeValue[0][0];
			//	organizeName = organizeValue[0][1];
			//	printf("组织名称2====%s\n", organizeName);
			//	printf("组织编码2====%s\n", organizeCode);
			//	if (organizeName != NULL && strcmp("NULL", organizeName) != 0) {
			//		strcpy(organizeNameStr, organizeName);
			//	}
			//	if (organizeCode != NULL && strcmp("NULL", organizeCode) != 0) {
			//		strcpy(organizeCodeStr, organizeCode);
			//	}
			//}
			//else {
			//	strcpy(organizeNameStr, facttoryNameStr);
			//	strcpy(organizeCodeStr, factoryCodeStr);

			//}
			if (organizeCode != NULL) {
				DOFREE(organizeCode);
			}
			if (organizeName != NULL) {
				DOFREE(organizeName);
			}
			if (organizeFactory != NULL) {
				DOFREE(organizeFactory);
			}
			if (organizeValue != NULL) {
				DOFREE(organizeValue);
			}
			if (fu_class_code != NULL) {
				DOFREE(fu_class_code);
			}
			if (fu_class_id != NULL) {
				DOFREE(fu_class_id);
			}
		}
		printf("count:%d\n", count);
		// 初始化变量和预估最大长度
		size_t buffer_size = 200000; // 初始大小，可根据实际情况调整
		char* parameters = static_cast<char*>(malloc(buffer_size));

		parameters[0] = '\0'; // 确保字符串以空字符开始
		strcat(parameters, "{");

		//AOM_ask_value_string(children_line[i], "fnd0bl_line_object_type", &itemType);
		strcat(parameters, "\"parentPartCode\":\"");
		strcat(parameters, fu_item_id == NULL ? "" : fu_item_id);
		strcat(parameters, "\",");
		strcat(parameters, "\"lifeCycleStages\":\"");
		strcat(parameters, fu_smzqzt == NULL ? "" : fu_smzqzt);
		strcat(parameters, "\",");
		strcat(parameters, "\"version\":\"");
		strcat(parameters, fu_item_revision_id == NULL ? "" : fu_item_revision_id);
		strcat(parameters, "\",");
		strcat(parameters, "\"componentType\":\"");
		strcat(parameters, fu_object_name == NULL ? "" : fu_object_name);
		strcat(parameters, "\",");
		strcat(parameters, "\"bomProductNumber1\":\"");
		strcat(parameters, fu_cph == NULL ? "" : fu_cph);
		strcat(parameters, "\",");
		strcat(parameters, "\"usingOrgName\":\"");
		strcat(parameters, organizeNameStr == NULL ? "" : organizeNameStr);
		strcat(parameters, "\",");
		strcat(parameters, "\"usingOrgCode\":\"");
		strcat(parameters, organizeCodeStr == NULL ? "" : organizeCodeStr);
		strcat(parameters, "\",");
		strcat(parameters, "\"bomDetail\":[");
		for (int i = 0; i < count; i++)
		{
			tag_t zi_rev = NULLTAG;
			AOM_ask_value_tag(children_line[i], "bl_line_object", &zi_rev);
			tag_t ico_tag = NULLTAG;
			char* classId = NULL;
			map<string, int> attrMap;
			ICS_ask_classification_object(zi_rev, &ico_tag);
			if (ico_tag != NULLTAG) {
				ICS_ico_ask_class(ico_tag, &classId);
				printf(">> classId: %s\n", classId);
				attrMap = getClassAttrMap(classMap, classId);
			}
			char* itemType = NULL;
			AOM_ask_value_string(zi_rev, "object_type", &itemType);
			printf("object_type: %s\n", itemType);
			char* zi_item_id = NULL;
			char* zi_smzqzt = NULL;
			char* zi_item_revision_id = NULL;
			char* zi_object_name = NULL;
			char* zi_cph = NULL;
			ITKCALL(AOM_UIF_ask_value(zi_rev, "item_id", &zi_item_id));
			ITKCALL(AOM_UIF_ask_value(zi_rev, "rb3_smzqzt", &zi_smzqzt));
			ITKCALL(AOM_UIF_ask_value(zi_rev, "item_revision_id", &zi_item_revision_id));
			ITKCALL(AOM_UIF_ask_value(zi_rev, "object_name", &zi_object_name));
			ITKCALL(AOM_UIF_ask_value(zi_rev, "rb3_cph", &zi_cph));
			char* zi_uom = NULL;
			char* zi_quantity = NULL;
			ITKCALL(AOM_UIF_ask_value(children_line[i], "bl_uom", &zi_uom));
			ITKCALL(AOM_UIF_ask_value(children_line[i], "bl_quantity", &zi_quantity));
			strcat(parameters, "{");
			strcat(parameters, "\"componentCode\":\"");
			strcat(parameters, zi_item_id == NULL ? "" : zi_item_id);
			strcat(parameters, "\",");
			strcat(parameters, "\"theLifecycle\":\"");
			strcat(parameters, zi_smzqzt == NULL ? "" : zi_smzqzt);
			strcat(parameters, "\",");
			strcat(parameters, "\"bomObjectVersion\":\"");
			strcat(parameters, zi_item_revision_id == NULL ? "" : zi_item_revision_id);
			strcat(parameters, "\",");
			strcat(parameters, "\"bomObjectType\":\"");
			strcat(parameters, zi_object_name == NULL ? "" : zi_object_name);
			strcat(parameters, "\",");
			strcat(parameters, "\"bomProductNumber\":\"");
			strcat(parameters, zi_cph == NULL ? "" : zi_cph);
			strcat(parameters, "\",");
			strcat(parameters, "\"bomQuantity\":");
			strcat(parameters, zi_quantity == NULL ? "" : zi_quantity);
			strcat(parameters, ",");
			char* classCode = NULL;
			getItemClass(status, itemType, ico_tag, zi_rev, attrMap, classId, &classCode);

			//处理子件单位转换逻辑			
			if (strstr(zi_uom, "比例系数") != NULL) {
				strcat(parameters, "\"parentItemBase\":1,");
			}
			else {
				printf("zi_uom111 = %s \n", zi_uom);
				printf("classCode111 = %s \n", classCode);
				if (classCode != NULL) {
					if (strcmp("IN07", classCode) == 0 && strstr("L(粒)", zi_uom) != NULL)
					{
						zi_uom = "WL(万粒)";
						strcat(parameters, "\"parentItemBase\":10000,");
					}
					else if ((strcmp("IN01", classCode) == 0 || strcmp("IN56", classCode) == 0 || strcmp("IN59", classCode) == 0) && strstr("GM(克)", zi_uom) != NULL)
					{
						zi_uom = "T(吨)";
						strcat(parameters, "\"parentItemBase\":1000000,");
					}
					else if (strcmp("IN12", classCode) == 0 && strstr("GM(克)", zi_uom) != NULL)
					{
						zi_uom = "KG(千克)";
						strcat(parameters, "\"parentItemBase\":1000,");
					}
					else {
						strcat(parameters, "\"parentItemBase\":1,");
					}
				}
				else {
					strcat(parameters, "\"parentItemBase\":1,");
				}
			}
			strcat(parameters, "\"bomUnit\":\"");
			if (unitMap.find(zi_uom) != unitMap.end()) {
				strcat(parameters, unitMap[zi_uom].c_str());
			}
			else {
				strcat(parameters, zi_uom);
			}
			strcat(parameters, "\"");
			strcat(parameters, "}");
			//printf("parameters%d:%s\n", i,parameters);
			if (i < count - 1) {
				strcat(parameters, ",");
			}
			if (zi_item_id != NULL)
			{
				DOFREE(fu_item_id);
			}
			if (zi_smzqzt != NULL)
			{
				DOFREE(fu_smzqzt);
			}
			if (zi_item_revision_id != NULL)
			{
				DOFREE(fu_item_revision_id);
			}
			if (zi_object_name != NULL)
			{
				DOFREE(fu_object_name);
			}
			if (zi_cph != NULL)
			{
				DOFREE(fu_cph);
			}
			if (zi_uom != NULL)
			{
				DOFREE(zi_uom);
			}
			if (zi_quantity != NULL)
			{
				DOFREE(zi_quantity);
			}
			if (classCode != NULL)
			{
				DOFREE(classCode);
			}
			if (itemType != NULL) {
				DOFREE(itemType);
			}
		}
		if (fu_item_id != NULL)
		{
			DOFREE(fu_item_id);
		}
		if (fu_smzqzt != NULL)
		{
			DOFREE(fu_smzqzt);
		}
		if (fu_item_revision_id != NULL)
		{
			DOFREE(fu_item_revision_id);
		}
		if (fu_object_name != NULL)
		{
			DOFREE(fu_object_name);
		}
		if (fu_cph != NULL)
		{
			DOFREE(fu_cph);
		}
		if (fu_scgc != NULL)
		{
			DOFREE(fu_scgc);
		}
		if (fu_object_type != NULL)
		{
			DOFREE(fu_object_type);
		}
		DisConnServer();
		strcat(parameters, "]}");
		parameters_vec->push_back(parameters);
	}
	for (int i = 0; i < count; i++)
	{
		int child_count = 0;
		tag_t* zi_children_line = NULLTAG;
		BOM_line_ask_all_child_lines(children_line[i], &child_count, &zi_children_line);
		if (child_count > 0) {
			getBomLinePropertyNew(children_line[i], c_sql_values, parameters_vec, classMap, factoryMap, unitMap);
		}
	}
	if (children_line != NULL)
	{
		DOFREE(children_line);
	}

}

int RB_SendErpBom_New(EPM_action_message_t msg)
{
	printf("=========================BOM下发到ERP Start===================\n");
	//POM_AM__set_application_bypass(true);
	int ifail = ITK_ok;
	int  attachments_num = 0;
	tag_t  rootTask = NULLTAG, * attachments = NULLTAG;
	//获取任务对象
	EPM_ask_root_task(msg.task, &rootTask);
	//获取任务目标对象
	EPM_ask_attachments(rootTask, EPM_target_attachment, &attachments_num, &attachments);

	int c_sql_value_count = 0;
	char** c_sql_values;
	ITKCALL(PREF_ask_char_values("RB3_SQL_Connect2", &c_sql_value_count, &c_sql_values));
	if (c_sql_value_count != 3)
	{
		printf("首选项 RB3_SQL_Connect2 配置错误 数量%d  ", c_sql_value_count);
		return 1;
	}
	int unit_pref_cnt = 0;
	char** unit_pref_vals = NULL;
	//获取首选项的值
	PREF_ask_char_values("RB_SEND_UNIT_MATCHING", &unit_pref_cnt, &unit_pref_vals);
	map<string, string> unitMap;
	for (int i = 0; i < unit_pref_cnt; i++)
	{
		if (strstr(unit_pref_vals[i], "=") != NULL)
		{
			//按照-进行拆分。拆分条件
			int valueCount = 0;
			char** valueChar = new char* [64];
			//分割字符串
			split(unit_pref_vals[i], "=", valueChar, &valueCount);
			unitMap[valueChar[0]] = valueChar[1];
			DOFREE(valueChar);
		}
	}
	char* tc_root_file = getenv("tc_root");		//C:\Siemens\Teamcenter11

	char errorMessage[100000] = "";//写入到文件的值
	for (int i = 0; i < attachments_num; i++)
	{
		char* itemType = NULL;
		AOM_ask_value_string(attachments[i], "object_type", &itemType);

		printf("itemType：%s\n", itemType);

		//过滤掉非版本的对象
		if (strcmp(itemType, "RB3_ZCRevision") == 0 || strcmp(itemType, "RB3_GNZCRevision") == 0 || strcmp(itemType, "RB3_XZCPRevision") == 0)
		{
			//获取子项
			tag_t top_line = NULLTAG, window = NULLTAG;
			BOM_create_window(&window);
			//设置顶层BOM
			BOM_set_window_top_line(window, NULLTAG, attachments[i], NULLTAG, &top_line);
			//获取单个的json字符串
			vector<string> parameters_vec;
			map<string, map<string, int>> classMap;
			map<string, vector<string>> factoryMap;
			printf("=========================遍历获取子件信息===================\n");
			getBomLinePropertyNew(top_line, c_sql_values, &parameters_vec, classMap, factoryMap, unitMap)

				DOFREE(itemType);
			char parameters[100000] = "";//写入到文件的值
			strcat(parameters, "{\"data\":[");
			for (int i = 0; i < parameters_vec.size(); i++)
			{
				strcat(parameters, parameters_vec[i].c_str());
				if (i < parameters_vec.size() - 1) {
					strcat(parameters, ",");
				}
			}
			strcat(parameters, "],\"control\":{\"keydata\":null,\"ifid\": null,\"ifno\":\"JDE_MDM_BOM_01\",\"suser\": null,\"sysid\": null}}");
			//获取当前时间
			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");
			printf("data_file: %s\n", data_file);
			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, "RB_SendErp_New.jar");
			strcat(cmd, "\" ");
			//传参
			//cout << data_file << endl;
			strcat(cmd, data_file);
			//用来传递本流程的流程名称(@分割)
			strcat(cmd, "@BOM");
			//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);
				cout << strResult << endl;
				if (strstr(strResult.c_str(), "\"code\":200") == NULL)
				{
					printf("下发成功\n");
					strcat(errorMessage, strResult.c_str());

				}
			}
			DOFREE(itemType);
		}
	}

	MEM_free(attachments);
	MEM_free(c_sql_values);
	if (ifail == 1)
	{
		EMH_store_error_s1(EMH_severity_user_error, EMH_USER_error_base, errorMessage);
	}
	printf("=========================BOM下发到ERP End===================\n");
	return ifail;
}

void getGYLXBomLinePropertyNew(tag_t topLine, char** c_sql_values, vector<string>* parameters_vec, map<string, string> unitMap, map<string, map<string, int>> classMap, map<string, string> workCenterMap)
{

	map<string, vector<tag_t>> ziVecMap;
	tag_t* children_line = NULLTAG;
	int  count = 0;
	map<string, vector<string>> factoryMap;
	ITKCALL(BOM_line_ask_all_child_lines(topLine, &count, &children_line));
	if (count > 0) {
		int status = ConnServer(c_sql_values[1], c_sql_values[2], c_sql_values[0]);
		//获取工艺路线关联的制造目标对象
		tag_t fu_rev = NULLTAG;
		ITKCALL(AOM_ask_value_tag(topLine, "bl_line_object", &fu_rev));
		tag_t* wl_items = NULLTAG;
		int wl_count = 0;
		ITKCALL(AOM_ask_value_tags(fu_rev, "IMAN_METarget", &wl_count, &wl_items));
		char* fu_item_id = NULL;
		ITKCALL(AOM_UIF_ask_value(fu_rev, "item_id", &fu_item_id));
		int valueCount = 0;
		char** valueChar = new char* [64];
		if (strstr(fu_item_id, "_") != NULL) {
			//按照-进行拆分。拆分条件

			//分割字符串
			split(fu_item_id, "_", valueChar, &valueCount);
		}
		char* describe1 = NULL;//rb3_ms
		char* partNumber = NULL;//rb3_jh
		char* productId = NULL;//rb3_cph
		char* assemblyType = NULL;//rb3_zclx
		char* lifecycleState = NULL;//rb3_smzqzt
		char* item_type = NULL;
		if (wl_count > 0) {
			tag_t wl_item = wl_items[0];
			ITKCALL(AOM_ask_value_string(wl_item, "object_type", &item_type));
			printf("item_type = %s \n", item_type);
			if (strcmp("RB3_ZCRevision", item_type) == 0) {
				ITKCALL(AOM_UIF_ask_value(wl_item, "rb3_ms", &describe1));
				ITKCALL(AOM_UIF_ask_value(wl_item, "rb3_cph", &productId));
				ITKCALL(AOM_UIF_ask_value(wl_item, "rb3_zclx", &assemblyType));
				ITKCALL(AOM_UIF_ask_value(wl_item, "rb3_smzqzt", &lifecycleState));
			}
			else if (strcmp("RB3_LBJRevision", item_type) == 0) {
				ITKCALL(AOM_UIF_ask_value(wl_item, "rb3_jh", &partNumber));

			}
		}
		printf("count:%d\n", count);
		for (int i = 0; i < count; i++)
		{
			char* wlbm = NULL;//bl_MEOPRevision_rb3_wlbm materialCode 物料编码
			char* jgbz = NULL;//bl_MEOPRevision_rb3_jgbz processingSteps 加工步骤
			ITKCALL(AOM_UIF_ask_value(children_line[i], "bl_MEOPRevision_rb3_wlbm", &wlbm));
			ITKCALL(AOM_UIF_ask_value(children_line[i], "bl_MEOPRevision_rb3_jgbz", &jgbz));
			if (wlbm == NULL || strcmp("", wlbm) == 0 || jgbz == NULL || strcmp("", jgbz) == 0) {
				if (wlbm != NULL) {
					DOFREE(wlbm);
				}
				if (jgbz != NULL) {
					DOFREE(jgbz);
				}
				continue;
			}
			char* jgbz_rel = NULL;
			ITKCALL(AOM_ask_value_string(children_line[i], "bl_MEOPRevision_rb3_jgbz", &jgbz_rel));
			char processRouteCode[64] = "\0";
			char processRouteName[64] = "\0";
			strcpy(processRouteCode, wlbm);
			strcat(processRouteCode, jgbz_rel);
			strcpy(processRouteName, wlbm);
			strcat(processRouteName, jgbz);

			if (ziVecMap.find(processRouteCode) == ziVecMap.end()) {
				vector<tag_t> ziVec;
				ziVec.push_back(children_line[i]);
				ziVecMap.insert(std::make_pair(processRouteCode, ziVec));
			}
			else {

				vector<tag_t> ziVec = ziVecMap[processRouteCode];
				//printf("parameters_map存值 \n");
				ziVec.push_back(children_line[i]);
				// 删除元素
				ziVecMap.erase(processRouteCode);
				ziVecMap.insert(std::make_pair(processRouteCode, ziVec));
			}
		}
		for (std::map<string, vector<tag_t>>::iterator it = ziVecMap.begin(); it != ziVecMap.end(); ++it)
		{
			string key = it->first;
			vector<tag_t> ziVec = it->second;
			char fu_params[10000] = "\0";
			for (int i = 0; i < ziVec.size(); i++)
			{
				tag_t zi_tag = ziVec[i];
				char* wlbm = NULL;//bl_MEOPRevision_rb3_wlbm materialCode 物料编码
				ITKCALL(AOM_UIF_ask_value(zi_tag, "bl_MEOPRevision_rb3_wlbm", &wlbm));
				char* jgbz = NULL;//bl_MEOPRevision_rb3_jgbz processingSteps 加工步骤
				char* jgbz_rel = NULL;
				ITKCALL(AOM_UIF_ask_value(zi_tag, "bl_MEOPRevision_rb3_jgbz", &jgbz));
				ITKCALL(AOM_ask_value_string(zi_tag, "bl_MEOPRevision_rb3_jgbz", &jgbz_rel));
				char* sfww = NULL;//bl_MEOPRevision_rb3_sfww whetherOutsource 是否委外
				ITKCALL(AOM_UIF_ask_value(zi_tag, "bl_MEOPRevision_rb3_sfww", &sfww));
				char* sfbg = NULL;//bl_MEOPRevision_rb3_sfbg whetherReportWork 是否报工
				ITKCALL(AOM_UIF_ask_value(zi_tag, "bl_MEOPRevision_rb3_sfbg", &sfbg));
				char* bzgs1 = NULL;//bl_MEOPRevision_rb3_bzgs1 standardWorkingHours 标准工时
				ITKCALL(AOM_UIF_ask_value(zi_tag, "bl_MEOPRevision_rb3_bzgs1", &bzgs1));
				char bzgs_str[64] = "\0";
				if (bzgs1 != NULL && strcmp(bzgs1, "") != 0 && strcmp(bzgs1, " ") != 0) {
					double bzgs_d = std::stod(bzgs1);
					//ITKCALL(AOM_ask_value_double(zi_tag, "bl_MEOPRevision_rb3_bzgs1", &bzgs1));
					bzgs_d = round(bzgs_d * 100) / 100;

					//long lValue = static_cast<long>(bzgs_d); // 转换为long
					if (bzgs_d > 0) {
						sprintf(bzgs_str, "%.2f", bzgs_d);
					}
					else {
						sprintf(bzgs_str, "%0.2f", bzgs_d);
					}
					printf("bzgs_str: %s\n", bzgs_str);
				}
				char* bzgsdw = NULL;//bl_MEOPRevision_rb3_bzgsdw standardWorkingHoursUnit 标准工时单位
				ITKCALL(AOM_UIF_ask_value(zi_tag, "bl_MEOPRevision_rb3_bzgsdw", &bzgsdw));
				char* sfjy = NULL;//bl_MEOPRevision_rb3_sfjy whetherVerify 是否检验
				ITKCALL(AOM_UIF_ask_value(zi_tag, "bl_MEOPRevision_rb3_sfjy", &sfjy));
				char* gzzx = NULL;//bl_MEOPRevision_rb3_gzzx workCenter 工作中心
				ITKCALL(AOM_UIF_ask_value(zi_tag, "bl_MEOPRevision_rb3_gzzx", &gzzx));
				char* sepuence_no = NULL;//bl_sepuence_no findNumber 查找编号
				ITKCALL(AOM_UIF_ask_value(zi_tag, "bl_sequence_no", &sepuence_no));
				char* quantity = NULL;//bl_quantity quantity 数量
				ITKCALL(AOM_UIF_ask_value(zi_tag, "bl_quantity", &quantity));
				char* uom = NULL;//bl_uom unitMeasurement 度量单位
				ITKCALL(AOM_UIF_ask_value(zi_tag, "bl_uom", &uom));


				int factoryCount = 0;
				char* scgc = NULL;//bl_MEOPRevision_rb3_scgc unitMeasurement 度量单位
				ITKCALL(AOM_UIF_ask_value(zi_tag, "bl_MEOPRevision_rb3_scgc", &scgc));
				if (strstr(scgc, ",") != NULL) {
					removeChar(scgc, ',');
				}
				char* gxh = NULL;//RB3_GXH processNumber 标准工序号
				ITKCALL(AOM_UIF_ask_value(zi_tag, "RB3_GXH", &gxh));
				//printf("jgbz = %s\n", jgbz);
				//printf("jgbz_rel = %s\n", jgbz_rel);
				//printf("sfww = %s\n", sfww);
				//printf("sfbg = %s\n", sfbg);
				//printf("bzgs1 = %s\n", bzgs1);
				//printf("bzgsdw = %s\n", bzgsdw);
				//printf("sfjy = %s\n", sfjy);
				//printf("gzzx = %s\n", gzzx);
				//printf("sepuence_no = %s\n", sepuence_no);
				//printf("quantity = %s\n", quantity);
				//printf("uom = %s\n", uom);
				//printf("scgc = %s\n", scgc);
				//printf("gxh = %s\n", gxh);
				char* newStr = NULL;
				if (strcmp("", scgc) != 0) {
					newStr = removeSpaces(scgc);
				}
				printf("newStr = %s\n", newStr);
				tag_t zi_rev = NULLTAG;
				ITKCALL(AOM_ask_value_tag(zi_tag, "bl_line_object", &zi_rev));
				char* item_id = NULL;//item_id componentId 工序ID
				ITKCALL(AOM_UIF_ask_value(zi_rev, "item_id", &item_id));
				char* object_name = NULL;//object_name componentName 工序名称
				ITKCALL(AOM_UIF_ask_value(zi_rev, "object_name", &object_name));
				//分类属性名称对应id map存储
				tag_t ico_tag = NULLTAG;
				char* cplb_disValue = NULL;
				char* classId = NULL;
				map<string, int> attrMap;
				ICS_ask_classification_object(zi_rev, &ico_tag);
				if (ico_tag != NULLTAG) {
					if (classMap.find(classId) == classMap.end()) {
						int count = 0;
						int* ids;
						int* arraySize;
						int* formats;
						int* options;
						char** names;
						char** shortNames;
						char** annotations;
						char** unit;
						char** minValues;
						char** maxValues;
						char** defaultValues;
						char** descriptions;
						ITKCALL(ICS_class_describe_attributes(classId, &count, &ids, &names, &shortNames, &annotations, &arraySize,
							&formats, &unit, &minValues, &maxValues, &defaultValues, &descriptions, &options));
						for (int i = 0; i < count; i++)
						{
							attrMap.insert(pair<string, int>(names[i], ids[i]));
						}
						classMap.insert(pair<string, map<string, int>>(classId, attrMap));
						if (ids != NULL) {
							DOFREE(ids);
						}
						if (arraySize != NULL) {
							DOFREE(arraySize);
						}
						if (formats != NULL) {
							DOFREE(formats);
						}
						if (options != NULL) {
							DOFREE(options);
						}
						if (names != NULL) {
							DOFREE(names);
						}
						if (shortNames != NULL) {
							DOFREE(shortNames);
						}
						if (annotations != NULL) {
							DOFREE(annotations);
						}
						if (unit != NULL) {
							DOFREE(unit);
						}
						if (minValues != NULL) {
							DOFREE(minValues);
						}
						if (maxValues != NULL) {
							DOFREE(maxValues);
						}
						if (defaultValues != NULL) {
							DOFREE(defaultValues);
						}
						if (descriptions != NULL) {
							DOFREE(descriptions);
						}
					}
					else {
						attrMap = classMap[classId];
					}

					if (attrMap.find("产品类别") != attrMap.end())
					{
						char* cplb = NULL;
						ICS_ask_attribute_value(ico_tag, "产品类别", &cplb);
						if (cplb != NULL) {
							int id = attrMap["产品类别"];
							getClassValue(cplb, id, &cplb_disValue);
							DOFREE(cplb);
						}
					}
				}
				char* rev_id = NULL;//object_name version 版本
				ITKCALL(AOM_UIF_ask_value(zi_rev, "item_revision_id", &rev_id));

				char processRouteCode[64] = "\0";
				char processRouteName[64] = "\0";
				strcpy(processRouteCode, wlbm);
				strcat(processRouteCode, jgbz_rel);
				strcpy(processRouteName, wlbm);
				strcat(processRouteName, jgbz);
				//printf("processRouteCode =%s\n", processRouteCode);
				//printf("processRouteName =%s\n", processRouteName);
				char* factoryCode = NULL;
				char* factoryName = NULL;
				string factoryCodeStr = "";
				string facttoryNameStr = "";
				if (newStr != NULL) {
					if (factoryMap.find(newStr) != factoryMap.end()) {
						vector<string> factoryVec = factoryMap[newStr];
						factoryCodeStr = factoryVec[0];
						facttoryNameStr = factoryVec[1];
					}
					else {
						if (status)
						{
							printf("提示:中间数据表访问失败\n");
						}
						else {
							//工厂组织编码特殊处理,通过数据库表匹配

							int factoryColumn = 0, factoryValueCount = 0;
							char*** factoryValue = NULL;
							char factorySql[128] = "\0";
							sprintf(factorySql, "select PFACTORYCODE,PFACTORYNAME from PLM_ERP_FACTORY_TABLE where PFACTORY= '%s'", newStr);
							printf("提示:factorySql==%s\n", factorySql);
							if (QuerySQLNoInputParam(factorySql, &factoryColumn, &factoryValueCount, &factoryValue) == -1)
							{
								printf("提示:组织编码查询 失败, %s \n", factorySql);
							}
							printf("factoryValueCount=%d\n", factoryValueCount);
							printf("factoryColumn=%d\n", factoryColumn);
							if (factoryValueCount > 0) {
								factoryCode = factoryValue[0][0];
								factoryName = factoryValue[0][1];
								vector<string> factoryVec;
								factoryVec.push_back(factoryCode);
								factoryVec.push_back(factoryName);
								factoryMap[newStr] = factoryVec;
								printf("组织编码====%s\n", factoryCode);
								printf("组织名称====%s\n", factoryName);
							}
							if (factoryValue != NULL) {
								DOFREE(factoryValue);
							}

						}
					}
				}
				if (strcmp("", fu_params) == 0) {
					strcat(fu_params, "{\"processRouteCode\":\"");
					strcat(fu_params, processRouteCode);
					strcat(fu_params, "\",");
					strcat(fu_params, "\"processRouteName\":\"");
					strcat(fu_params, processRouteName);
					strcat(fu_params, "\",");
					strcat(fu_params, "\"productionFactoryCode\":\"");
					if (factoryCode != NULL) {
						strcat(fu_params, factoryCode);
					}
					else {
						strcat(fu_params, factoryCodeStr.c_str());
					}
					strcat(fu_params, "\",");
					strcat(fu_params, "\"processingSteps\":\"");
					strcat(fu_params, jgbz);
					strcat(fu_params, "\",");
					strcat(fu_params, "\"productionFactoryName\":\"");
					if (factoryName != NULL) {
						strcat(fu_params, factoryName);
					}
					else {
						strcat(fu_params, facttoryNameStr.c_str());
					}
					strcat(fu_params, "\",");
					strcat(fu_params, "\"materialCode\":\"");
					strcat(fu_params, wlbm);
					strcat(fu_params, "\",");
					strcat(fu_params, "\"version\":\"");
					if (valueCount > 0) {
						strcat(fu_params, valueChar[1]);
						strcat(fu_params, rev_id);
					}
					else {
						strcat(fu_params, rev_id);
					}
					strcat(fu_params, "\",");
					strcat(fu_params, "\"standardWorkingHoursUnit\":\"");
					strcat(fu_params, bzgsdw);
					strcat(fu_params, "\",");
					strcat(fu_params, "\"processDetailed\":\ [");
				}
				strcat(fu_params, "{");
				strcat(fu_params, "\"componentId\":\"");
				strcat(fu_params, item_id);
				strcat(fu_params, "\",");
				strcat(fu_params, "\"describe1\":\"");
				if (describe1 != NULL) {
					strcat(fu_params, describe1);
				}
				strcat(fu_params, "\",");
				strcat(fu_params, "\"processNumber\":\"");
				strcat(fu_params, gxh);
				strcat(fu_params, "\",");
				strcat(fu_params, "\"findNumber\":\"");
				strcat(fu_params, sepuence_no);
				strcat(fu_params, "\",");
				strcat(fu_params, "\"componentName\":\"");
				//if (cplb_disValue != NULL) {
				//	strcat(fu_params, cplb_disValue);
				//	strcat(fu_params, "-");
				//}
				strcat(fu_params, object_name);
				strcat(fu_params, "\",");
				strcat(fu_params, "\"whetherOutsource\":\"");
				strcat(fu_params, sfww);
				strcat(fu_params, "\",");
				strcat(fu_params, "\"whetherReportWork\":\"");
				strcat(fu_params, sfbg);
				strcat(fu_params, "\",");
				strcat(fu_params, "\"standardWorkingHours\":\"");
				strcat(fu_params, bzgs_str);
				strcat(fu_params, "\",");
				strcat(fu_params, "\"whetherVerify\":\"");
				strcat(fu_params, sfjy);
				strcat(fu_params, "\",");
				strcat(fu_params, "\"workCenter\":\"");
				if (workCenterMap.find(gzzx) != workCenterMap.end()) {
					strcat(fu_params, workCenterMap[gzzx].c_str());
				}
				else {
					strcat(fu_params, gzzx);
				}
				strcat(fu_params, "\",");
				strcat(fu_params, "\"unitMeasurement\":\"");
				if (unitMap.find(uom) != unitMap.end()) {
					strcat(fu_params, unitMap[uom].c_str());
				}
				else {
					strcat(fu_params, uom);
				}
				strcat(fu_params, "\",");
				strcat(fu_params, "\"quantity\":\"");
				strcat(fu_params, quantity);
				strcat(fu_params, "\",");
				strcat(fu_params, "\"partNumber\":\"");
				if (partNumber != NULL) {
					strcat(fu_params, partNumber);
				}
				strcat(fu_params, "\",");
				strcat(fu_params, "\"productId\":\"");
				if (productId != NULL) {
					strcat(fu_params, productId);
				}
				strcat(fu_params, "\",");
				strcat(fu_params, "\"assemblyType\":\"");
				if (assemblyType != NULL) {
					strcat(fu_params, assemblyType);
				}
				strcat(fu_params, "\",");
				strcat(fu_params, "\"lifecycleState\":\"");
				if (lifecycleState != NULL) {
					strcat(fu_params, lifecycleState);
				}
				strcat(fu_params, "\"}");
				if (i < ziVec.size() - 1) {
					strcat(fu_params, ",");
				}
				if (factoryCode != NULL) {
					DOFREE(factoryCode);
				}
				if (factoryName != NULL) {
					DOFREE(factoryName);
				}
				if (zi_tag != NULL) {
					DOFREE(zi_tag);
				}
				if (zi_rev != NULL) {
					DOFREE(zi_rev);
				}
				if (scgc != NULL) {
					DOFREE(scgc);
				}
				if (gxh != NULL) {
					DOFREE(gxh);
				}
				if (object_name != NULL) {
					DOFREE(object_name);
				}
				if (rev_id != NULL) {
					DOFREE(rev_id);
				}
				if (jgbz != NULL) {
					DOFREE(jgbz);
				}
				if (jgbz_rel != NULL) {
					DOFREE(jgbz_rel);
				}
				if (sfww != NULL) {
					DOFREE(sfww);
				}
				if (sfbg != NULL) {
					DOFREE(sfbg);
				}
				if (bzgs1 != NULL) {
					DOFREE(bzgs1);
				}
				if (bzgsdw != NULL) {
					DOFREE(bzgsdw);
				}
				if (sfjy != NULL) {
					DOFREE(sfjy);
				}
				if (gzzx != NULL) {
					DOFREE(gzzx);
				}
				if (sepuence_no != NULL) {
					DOFREE(sepuence_no);
				}
				if (quantity != NULL) {
					DOFREE(quantity);
				}
				if (uom != NULL) {
					DOFREE(uom);
				}
				if (classId != NULL) {
					DOFREE(classId);
				}
				if (cplb_disValue != NULL) {
					DOFREE(cplb_disValue);
				}
			}
			strcat(fu_params, "]}");
			parameters_vec->push_back(fu_params);

		}
		if (fu_item_id != NULL)
		{
			DOFREE(fu_item_id);
		}
		if (describe1 != NULL) {
			DOFREE(describe1);
		}
		if (partNumber != NULL) {
			DOFREE(partNumber);
		}
		if (productId != NULL) {
			DOFREE(productId);
		}
		if (assemblyType != NULL) {
			DOFREE(assemblyType);
		}
		if (lifecycleState != NULL) {
			DOFREE(lifecycleState);
		}
		DisConnServer();
	}
	if (children_line != NULL)
	{
		DOFREE(children_line);
	}
	factoryMap.clear();

}

int RB_Send_MDM_GYLX_New(EPM_action_message_t msg)
{
	printf("=========================工艺路线下发到mdm Start===================\n");
	//POM_AM__set_application_bypass(true);
	int ifail = ITK_ok;
	int  attachments_num = 0;
	tag_t  rootTask = NULLTAG, * attachments = NULLTAG;
	//获取任务对象
	EPM_ask_root_task(msg.task, &rootTask);
	//获取任务目标对象
	EPM_ask_attachments(rootTask, EPM_target_attachment, &attachments_num, &attachments);

	int c_sql_value_count = 0;
	char** c_sql_values;
	ITKCALL(PREF_ask_char_values("RB3_SQL_Connect2", &c_sql_value_count, &c_sql_values));
	if (c_sql_value_count != 3)
	{
		printf("首选项 RB3_SQL_Connect2 配置错误 数量%d  ", c_sql_value_count);
		return 1;
	}
	int unit_pref_cnt = 0;
	char** unit_pref_vals = NULL;
	//获取首选项的值
	PREF_ask_char_values("RB_SEND_UNIT_MATCHING", &unit_pref_cnt, &unit_pref_vals);
	map<string, string> unitMap;
	for (int i = 0; i < unit_pref_cnt; i++)
	{
		if (strstr(unit_pref_vals[i], "=") != NULL)
		{
			//按照-进行拆分。拆分条件
			int valueCount = 0;
			char** valueChar = new char* [64];
			//分割字符串
			split(unit_pref_vals[i], "=", valueChar, &valueCount);
			unitMap[valueChar[0]] = valueChar[1];
			DOFREE(valueChar);
		}
	}
	int workCenter_pref_cnt = 0;
	char** workCenter_pref_vals = NULL;
	//获取首选项的值
	PREF_ask_char_values("RB3_GYLX_workCenter", &workCenter_pref_cnt, &workCenter_pref_vals);
	map<string, string> workCenterMap;
	for (int i = 0; i < workCenter_pref_cnt; i++)
	{
		if (strstr(workCenter_pref_vals[i], "=") != NULL)
		{
			//按照-进行拆分。拆分条件
			int valueCount = 0;
			char** valueChar = new char* [64];
			//分割字符串
			split(workCenter_pref_vals[i], "=", valueChar, &valueCount);
			workCenterMap[valueChar[0]] = valueChar[1];
			DOFREE(valueChar);
		}
	}
	map<string, map<string, int>> classMap;
	char* tc_root_file = getenv("tc_root");		//C:\Siemens\Teamcenter11

	for (int i = 0; i < attachments_num; i++)
	{
		char* itemType = NULL;
		AOM_ask_value_string(attachments[i], "object_type", &itemType);

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

		//过滤掉非版本的对象
		if (strcmp(itemType, "MEProcessRevision") != 0)
		{
			DOFREE(itemType);
			continue;
		}

		//获取子项
		tag_t top_line = NULLTAG, window = NULLTAG;
		BOM_create_window(&window);
		//设置顶层BOM
		BOM_set_window_top_line(window, NULLTAG, attachments[i], NULLTAG, &top_line);
		//获取单个的json字符串
		vector<string> parameters_vec;
		getGYLXBomLinePropertyNew(top_line, c_sql_values, &parameters_vec, unitMap, classMap, workCenterMap);


		char parameters[100000] = "";//写入到文件的值
		strcat(parameters, "{\"data\":[");
		for (int i = 0; i < parameters_vec.size(); i++)
		{
			strcat(parameters, parameters_vec[i].c_str());
			if (i < parameters_vec.size() - 1) {
				strcat(parameters, ",");
			}
		}
		strcat(parameters, "],\"control\":{\"keydata\":null,\"ifid\": null,\"ifno\":\"TC_to_MDM_GYLX\",\"suser\": null,\"sysid\": null}}");
		//获取当前时间
		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");
		printf("data_file: %s\n", data_file);
		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, "RB_SendErp_New.jar");
		strcat(cmd, "\" ");
		//传参
		//cout << data_file << endl;
		strcat(cmd, data_file);
		//用来传递本流程的流程名称(@分割)
		strcat(cmd, "@GYLX");
		//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);

		unsigned int iSize = strResult.size();
		if (iSize > 0 && strResult[iSize - 1] == '\n' && strlen(parameters) > 0)
		{
			strResult = strResult.substr(0, iSize - 1);
			cout << strResult << endl;
			if (strstr(strResult.c_str(), "\"code\":200") == NULL)
			{
				printf("下发成功\n");

			}
		}
		MEM_free(itemType);
	}
	MEM_free(attachments);
	MEM_free(c_sql_values);
	printf("=========================工艺路线下发到mdm End===================\n");
	return ifail;
}