#define _CRT_SECURE_NO_WARNINGS
#include "epm_handler_common.h"

#include <thread>
string& replace_all_distinct(string& str, const string& old_value, const string& new_value)
{
	for (string::size_type pos(0); pos != string::npos; pos += new_value.length()) {
		if ((pos = str.find(old_value, pos)) != string::npos)
			str.replace(pos, old_value.length(), new_value);
		else break;
	}
	return str;
}
void getTCMSrmItemJson(int index, tag_t topLine, tag_t BomLine, bool isStart, map<string, string> typePropertyType, char parameters[100000]);
void getTCMSrmBomLineProperty(tag_t topLine, tag_t BomLine, map<string, string> typePropertyType, char * bomBaseNum, char * sortString, bool isBomStart, char parameters[100000]);

int ML_TCMSendSrmBom(EPM_action_message_t msg)
{
	printf("=========================BOM下发到SRM 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);
	bool isMessage = false;
	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);
				}
			}
			else if (stricmp(argflag, "isMessage") == 0)
			{
				printf("有配置参数，发送弹窗");
				isMessage = true;
			}
		}
	}

	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_BOMSendSrmProperty", &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]));
		}
	}

	bool isStart = true;
	char *tc_root_file = getenv("tc_root");		//C:\Siemens\Teamcenter11
	char *temp_dir = getenv("TEMP");		//临时文件夹
	char* parameters = new char[100000000];
	//char parameters[100000] = "";//写入到文件的值
	strcat(parameters, "getTCMSrmBomPropertys}}");
	strcat(parameters, messageUser);
	strcat(parameters, "}}");
	strcat(parameters, "[");
	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, "BOMView Revision") == 0|| strstr(itemType, "Revision") == NULL) {
			continue;
		}
		//过滤掉非版本的对象
		//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))
		//{
			//判断ml8_AddTrade为否ml8_ProcessingMode为外协外购并且包含子件则不传递
			//char * addTrade = NULL, * processingMode = NULL;
			//AOM_ask_value_string(attachments[i], "ml8_AddTrade", &addTrade);
			//AOM_ask_value_string(attachments[i], "ml8_ProcessingMode", &processingMode);
			//int childNum = 0;
			//tag_t * childItem = NULLTAG;
			////获取子件
			//AOM_ask_value_tags(attachments[i], "ps_children", &childNum, &childItem);
			//if (strcmp(addTrade, "否") == 0 && strcmp(processingMode, "外协外购") == 0 && childNum > 0)
			//{
			//	MEM_free(addTrade);
			//	MEM_free(processingMode);
			//	MEM_free(childItem);
			//	continue;
			//}
			//判断是否发布
			int releaseCount = 0;
			tag_t * releaseTag = NULL;
			//判断子件是否发布
			AOM_ask_value_tags(attachments[i], "release_status_list", &releaseCount, &releaseTag);

			printf("发布状态%d===================\n", releaseCount);
			if (releaseCount <= 0)
			{
				MEM_free(releaseTag);
				MEM_free(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 (isStart)
			{
				getTCMSrmItemJson(-1, top_line, NULLTAG, isStart, typePropertyType, parameters);
				isStart = false;
			}
			else
			{
				getTCMSrmItemJson(-1, top_line, NULLTAG, isStart, typePropertyType, parameters);
			}

			BOM_close_window(window);

			/*MEM_free(addTrade);
			MEM_free(processingMode);
			MEM_free(childItem);*/
		//}
			//MEM_free(releaseTag);
		MEM_free(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, temp_dir);
	//strcat(data_file, "\\");
	strcat(data_file, "ML_TCMSendSrmBom");
	strcat(data_file, date);
	strcat(data_file, ".txt");

	ofstream file;
	file.open(data_file);
	file << parameters << endl; // 使用与cout同样的方式进行写入
	file.close();

	//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);



	//等待4秒钟
	std::this_thread::sleep_for(std::chrono::seconds(6));//1秒
				
	//把数据用写入文件
	char dataResult_file[SS_MAXPATHLEN] = "";
	strcat(dataResult_file, temp_dir);
	//strcat(dataResult_file, "\\");
	strcat(dataResult_file, "ML_TCMSendSrmBom");
	strcat(dataResult_file, newGUID());
	strcat(dataResult_file, ".txt");

	ofstream fileResult;
	fileResult.open(dataResult_file);
	fileResult << parameters << endl; // 使用与cout同样的方式进行写入
	fileResult.close();

	//cmd指令
	char cmdResult[512] = "";
	strcpy(cmdResult, "java -jar \"");
	//strcat(cmd, jar_file);
	strcat(cmdResult, tc_root_file);
	strcat(cmdResult, "\\portal\\plugins\\");
	strcat(cmdResult, "ML_SendBOMResult.jar");
	strcat(cmdResult, "\" ");
	//传参
	cout << dataResult_file << endl;
	strcat(cmdResult, dataResult_file);
	//用来传递本流程的流程名称(@分割)
	//strcat(cmd,"@");
	//strcat(cmd,handler_name);
	printf("路径:\n%s\n", cmdResult);
	char bufResult[8000] = { 0 };
	FILE *pfResult = NULL;
	if ((pfResult = _popen(cmdResult, "r")) == NULL) {
		printf("接口返回:\n%s", "1");
	}

	string strResult;
	while (fgets(bufResult, sizeof bufResult, pfResult)) {
		strResult += bufResult;
	}
	_pclose(pfResult);

	//char  messageValue[1024] = "";
	//调用jar包获取传递状态
	cout << strResult << endl;
	unsigned int iSize = strResult.size();
	printf("size=%d\n", iSize);
	if (iSize > 0 && strlen(parameters) > 0)
	{
		strResult = strResult.substr(0, iSize - 1);
		printf("下发失败\n");
		cout << strResult << endl;

		
		if (isMessage)

		{
			printf("配置参数弹窗报错");
			ifail = 1;
			EMH_store_error_s1(EMH_severity_user_error, EMH_USER_error_base, strResult.c_str());
		}
		

		strResult = replace_all_distinct(strResult,"\n","\\n");
		//发送消息到企业微信
		for (auto messageUserValue : messageUserValues) {
			itemSendToWeixin_srm(messageUserValue, rootTask, strResult);
		}
		//strcat(messageValue, strResult.c_str());
	}



	messageUserValues.clear();
	vector<char *>().swap(messageUserValues);
	MEM_free(attachments);
	//tc_root_file = NULL;
	//pref_vals = NULL;
	//if (iSize > 0)
	//{
	//	ifail == 1;
	//	EMH_store_error_s1(EMH_severity_user_error, EMH_USER_error_base, strResult.c_str());
	//}
	if (!isMessage)
	{
		printf("没有配置参数不弹窗报错");
		ifail = ITK_ok;
	}
	printf("ifail=%d\n", ifail);
	printf("=========================BOM下发到SRM End===================\n");
	return ifail;
}

void getTCMSrmItemJson(int index, tag_t topLine, tag_t BomLine, bool isStart, map<string, string> typePropertyType, char parameters[100000])
{
	bool isBomStart = true;
	char *itemType = NULL;
	AOM_ask_value_string(topLine, "fnd0bl_line_object_type", &itemType);
	string propertyNames = typePropertyType[itemType];
	if (propertyNames.c_str() != NULL)
	{
		if (isBomStart)
		{
			strcat(parameters, "{");
			isBomStart = false;
		}
		else
		{
			strcat(parameters, ",{");
		}


		strcat(parameters, "\"tcmUid\":");
		strcat(parameters, "\"");
		strcat(parameters, newGUID());
		strcat(parameters, "\"");
		strcat(parameters, ",");


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

		if (strstr(name, ",") != NULL)
		{
			//按照,进行拆分。拆分条件
			int valueCount = 0;
			char ** valueChar = new char *[64];
			//分割字符串
			split(name, ",", valueChar, &valueCount);
			for (int k = 0; k < valueCount; k++)
			{
				if (strstr(valueChar[k], "=") != NULL)
				{
					//按照-进行拆分。拆分条件
					int valueNum = 0;
					char ** values = new char *[64];
					//分割字符串
					split(valueChar[k], "=", values, &valueNum);

					strcat(parameters, "\"");
					strcat(parameters, values[1]);
					strcat(parameters, "\"");
					strcat(parameters, ":");

					char * item_rev_value = NULL;
					TCGetPropertyValue(topLine, "BOMLine", values[0], &item_rev_value);
					if (strcmp(values[1], "itemno") == 0)
					{
						//需要*10后，格式化为4位长度后进行传递
						int number = std::atoi(item_rev_value);
						stringToLenth(number * 10, 4, &item_rev_value);
					}
					//if (strcmp(valueChar[0], "parentCode") == 0)
					//{
					//	item_rev_value = "";
					//}
					if (strstr(item_rev_value, "\"") != NULL)
					{
						string resultString = replace_all_distinct(item_rev_value, "\"", "&\"");

						char resultChar[256] = "";

						strcpy(resultChar, resultString.c_str());

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

						item_rev_value = resultChar;

					}
					if (strcmp(item_rev_value, "每个") == 0 || strcmp(item_rev_value, "Much") == 0)
					{
						item_rev_value = "EA";
					}
					else if (strcmp(item_rev_value, "升") == 0)
					{
						item_rev_value = "L";
					}
					else if (strcmp(item_rev_value, "台") == 0)
					{
						item_rev_value = "TAI";
					}
					else if (strcmp(item_rev_value, "bot") == 0 || strcmp(item_rev_value, "瓶") == 0)
					{
						item_rev_value = "BOT";
					}
					else if (strcmp(item_rev_value, "g") == 0 || strcmp(item_rev_value, "克") == 0)
					{
						item_rev_value = "G";
					}
					else if (strcmp(item_rev_value, "kg") == 0 || strcmp(item_rev_value, "公斤") == 0)
					{
						item_rev_value = "KG";
					}
					else if (strcmp(item_rev_value, "m") == 0 || strcmp(item_rev_value, "米") == 0)
					{
						item_rev_value = "M";
					}
					else if (strcmp(item_rev_value, "m2") == 0 || strcmp(item_rev_value, "平方米") == 0)
					{
						item_rev_value = "M2";
					}
					else if (strcmp(item_rev_value, "m3") == 0 || strcmp(item_rev_value, "立方米") == 0)
					{
						item_rev_value = "M3";
					}
					else if (strcmp(item_rev_value, "mm2") == 0 || strcmp(item_rev_value, "平方毫米") == 0)
					{
						item_rev_value = "MM2";
					}
					else if (strcmp(item_rev_value, "tao") == 0 || strcmp(item_rev_value, "套") == 0)
					{
						item_rev_value = "TAO";
					}
					strcat(parameters, "\"");
					strcat(parameters, item_rev_value);
					strcat(parameters, "\"");
					if (k < valueCount - 1)
					{
						strcat(parameters, ",");
					}
					//printf(parameters);

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

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

			char * item_rev_value = NULL;
			TCGetPropertyValue(topLine, "BOMLine", valueChar[0], &item_rev_value);

			if (strcmp(valueChar[1], "itemno") == 0)
			{
				//需要*10后，格式化为4位长度后进行传递
				int number = std::atoi(item_rev_value);
				stringToLenth(number * 10, 4, &item_rev_value);
			}
			//if (strcmp(valueChar[0], "parentCode") == 0)
			//{
			//	item_rev_value = "";
			//}
			if (strstr(item_rev_value, "\"") != NULL)
			{
				string resultString = replace_all_distinct(item_rev_value, "\"", "&\"");

				char resultChar[256] = "";

				strcpy(resultChar, resultString.c_str());

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

				item_rev_value = resultChar;

			}
			if (strcmp(item_rev_value, "每个") == 0 || strcmp(item_rev_value, "Much") == 0)
			{
				item_rev_value = "EA";
			}
			else if (strcmp(item_rev_value, "升") == 0)
			{
				item_rev_value = "L";
			}
			else if (strcmp(item_rev_value, "台") == 0)
			{
				item_rev_value = "TAI";
			}
			else if (strcmp(item_rev_value, "bot") == 0 || strcmp(item_rev_value, "瓶") == 0)
			{
				item_rev_value = "BOT";
			}
			else if (strcmp(item_rev_value, "g") == 0 || strcmp(item_rev_value, "克") == 0)
			{
				item_rev_value = "G";
			}
			else if (strcmp(item_rev_value, "kg") == 0 || strcmp(item_rev_value, "公斤") == 0)
			{
				item_rev_value = "KG";
			}
			else if (strcmp(item_rev_value, "m") == 0 || strcmp(item_rev_value, "米") == 0)
			{
				item_rev_value = "M";
			}
			else if (strcmp(item_rev_value, "m2") == 0 || strcmp(item_rev_value, "平方米") == 0)
			{
				item_rev_value = "M2";
			}
			else if (strcmp(item_rev_value, "m3") == 0 || strcmp(item_rev_value, "立方米") == 0)
			{
				item_rev_value = "M3";
			}
			else if (strcmp(item_rev_value, "mm2") == 0 || strcmp(item_rev_value, "平方毫米") == 0)
			{
				item_rev_value = "MM2";
			}
			else if (strcmp(item_rev_value, "tao") == 0 || strcmp(item_rev_value, "套") == 0)
			{
				item_rev_value = "TAO";
			}
			strcat(parameters, "\"");
			strcat(parameters, item_rev_value);
			strcat(parameters, "\"");

			//printf(parameters);

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

		DOFREE(constName);
	}
	getTCMSrmBomLineProperty(topLine, BomLine, typePropertyType, "", "", isBomStart, parameters);
	DOFREE(itemType);
}

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

	BOM_line_ask_all_child_lines(topLine, &count, &children_line);

	for (int i = 0; i < count; i++)
	{
		char *itemType = NULL;
		AOM_ask_value_string(children_line[i], "fnd0bl_line_object_type", &itemType);
		char * puid = NULL;
		//获取PUID
		ITK__convert_tag_to_uid(children_line[i], &puid);
		//过滤掉非版本的对象
		string propertyNames = typePropertyType[itemType];
		if (propertyNames.c_str() != NULL)
		{
			if (isBomStart)
			{
				strcat(parameters, "{");
				isBomStart = false;
			}
			else
			{
				strcat(parameters, ",{");
			}

			
			strcat(parameters, "\"tcmUid\":");
			strcat(parameters, "\"");
			strcat(parameters, newGUID());
			strcat(parameters, "\"");
			strcat(parameters, ",");


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

			if (strstr(name, ",") != NULL)
			{
				//按照,进行拆分。拆分条件
				int valueCount = 0;
				char ** valueChar = new char *[64];
				//分割字符串
				split(name, ",", valueChar, &valueCount);
				for (int k = 0; k < valueCount; k++)
				{
					if (strstr(valueChar[k], "=") != NULL)
					{
						//按照-进行拆分。拆分条件
						int valueNum = 0;
						char ** values = new char *[64];
						//分割字符串
						split(valueChar[k], "=", values, &valueNum);

						strcat(parameters, "\"");
						strcat(parameters, values[1]);
						strcat(parameters, "\"");
						strcat(parameters, ":");

						char * item_rev_value = NULL;
						TCGetPropertyValue(children_line[i], "BOMLine", values[0], &item_rev_value);
						if (strcmp(values[1], "parentCode") == 0)
						{
							//需要*10后，格式化为4位长度后进行传递
							AOM_ask_value_string(topLine, "bl_item_item_id", &item_rev_value);
						}

						if (strstr(item_rev_value, "\"") != NULL)
						{
							string resultString = replace_all_distinct(item_rev_value, "\"", "&\"");

							char resultChar[256] = "";

							strcpy(resultChar, resultString.c_str());

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

							item_rev_value = resultChar;

						}
						if (strcmp(item_rev_value, "每个") == 0 || strcmp(item_rev_value, "Much") == 0)
						{
							item_rev_value = "EA";
						}
						else if (strcmp(item_rev_value, "升") == 0)
						{
							item_rev_value = "L";
						}
						else if (strcmp(item_rev_value, "台") == 0)
						{
							item_rev_value = "TAI";
						}
						else if (strcmp(item_rev_value, "bot") == 0 || strcmp(item_rev_value, "瓶") == 0)
						{
							item_rev_value = "BOT";
						}
						else if (strcmp(item_rev_value, "g") == 0 || strcmp(item_rev_value, "克") == 0)
						{
							item_rev_value = "G";
						}
						else if (strcmp(item_rev_value, "kg") == 0 || strcmp(item_rev_value, "公斤") == 0)
						{
							item_rev_value = "KG";
						}
						else if (strcmp(item_rev_value, "m") == 0 || strcmp(item_rev_value, "米") == 0)
						{
							item_rev_value = "M";
						}
						else if (strcmp(item_rev_value, "m2") == 0 || strcmp(item_rev_value, "平方米") == 0)
						{
							item_rev_value = "M2";
						}
						else if (strcmp(item_rev_value, "m3") == 0 || strcmp(item_rev_value, "立方米") == 0)
						{
							item_rev_value = "M3";
						}
						else if (strcmp(item_rev_value, "mm2") == 0 || strcmp(item_rev_value, "平方毫米") == 0)
						{
							item_rev_value = "MM2";
						}
						else if (strcmp(item_rev_value, "tao") == 0 || strcmp(item_rev_value, "套") == 0)
						{
							item_rev_value = "TAO";
						}
						strcat(parameters, "\"");
						strcat(parameters, item_rev_value);
						strcat(parameters, "\"");
						if (k < valueCount - 1)
						{
							strcat(parameters, ",");
						}
						//printf(parameters);

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

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

				char * item_rev_value = NULL;
				TCGetPropertyValue(children_line[i], "BOMLine", valueChar[0], &item_rev_value);


				if (strcmp(valueChar[0], "parentCode") == 0)
				{
					AOM_ask_value_string(topLine, "bl_item_item_id", &item_rev_value);
				}

				if (strstr(item_rev_value, "\"") != NULL)
				{
					string resultString = replace_all_distinct(item_rev_value, "\"", "&\"");

					char resultChar[256] = "";

					strcpy(resultChar, resultString.c_str());

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

					item_rev_value = resultChar;

				}
				if (strcmp(item_rev_value, "每个") == 0 || strcmp(item_rev_value, "Much") == 0)
				{
					item_rev_value = "EA";
				}
				else if (strcmp(item_rev_value, "升") == 0)
				{
					item_rev_value = "L";
				}
				else if (strcmp(item_rev_value, "台") == 0)
				{
					item_rev_value = "TAI";
				}
				else if (strcmp(item_rev_value, "bot") == 0 || strcmp(item_rev_value, "瓶") == 0)
				{
					item_rev_value = "BOT";
				}
				else if (strcmp(item_rev_value, "g") == 0 || strcmp(item_rev_value, "克") == 0)
				{
					item_rev_value = "G";
				}
				else if (strcmp(item_rev_value, "kg") == 0 || strcmp(item_rev_value, "公斤") == 0)
				{
					item_rev_value = "KG";
				}
				else if (strcmp(item_rev_value, "m") == 0 || strcmp(item_rev_value, "米") == 0)
				{
					item_rev_value = "M";
				}
				else if (strcmp(item_rev_value, "m2") == 0 || strcmp(item_rev_value, "平方米") == 0)
				{
					item_rev_value = "M2";
				}
				else if (strcmp(item_rev_value, "m3") == 0 || strcmp(item_rev_value, "立方米") == 0)
				{
					item_rev_value = "M3";
				}
				else if (strcmp(item_rev_value, "mm2") == 0 || strcmp(item_rev_value, "平方毫米") == 0)
				{
					item_rev_value = "MM2";
				}
				else if (strcmp(item_rev_value, "tao") == 0 || strcmp(item_rev_value, "套") == 0)
				{
					item_rev_value = "TAO";
				}
				strcat(parameters, "\"");
				strcat(parameters, item_rev_value);
				strcat(parameters, "\"");

				//printf(parameters);

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

			DOFREE(constName);
		}


		DOFREE(itemType);
		DOFREE(puid);
	}

	DOFREE(children_line);
}