#pragma warning (disable: 4996) 
#pragma warning (disable: 4819) 
#include <cstdio>
#include <io.h>
#include <epm/epm.h>
#include <ict/ict_userservice.h>
#include <tccore/item.h>
#include <ae/ae.h>
#include <tc/folder.h>
#include <tccore/aom.h>
#include <sa/sa.h>
#include <tccore/aom_prop.h>
#include <tccore/workspaceobject.h>
#include <tccore//grm.h>
#include <tccore/grmtype.h>
#include <bom/bom.h>
#include <me/me.h>
#include <me/meline.h>
#include <fclasses/tc_date.h>
#include <ics/ics.h>
#include <ics/ics2.h>
#include "tc_util.h"
#include "tc_log.h"
#include <vector>
#include <epm/signoff.h>
#include <iostream>
#include "string_utils.h"
#include "tinyxml.h"
#include "ado.h"
#include <stdio.h>
#include <time.h>
using namespace std;
#define GUID_LEN 64

struct CHILD
{
	tag_t line;
	tag_t rev;
	tag_t item;
	string clone_id;
};
extern "C" int POM_AM__set_application_bypass(logical bypass);

string getGuid() {
	char buffer[GUID_LEN] = { 0 };
	GUID guid;
	if (CoCreateGuid(&guid))
	{
		return "ERROR";
	}
	_snprintf(buffer, sizeof(buffer), "%08X-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1],
		guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
	return buffer;
}

// 存在问题，工序明显表的主键未取到，孙子节点获取到的是子节点的对象需要处理

string readBOPXML(map<string, map<vector<string>, vector<string>>>& xmlMap, string xmlPath) {
	time_t currentTime;
	struct tm* timeInfo;
	char timeString[80];
	// 获取当前时间
	time(&currentTime);
	// 将时间转换为本地时间
	timeInfo = localtime(&currentTime);
	TiXmlDocument* pDoc = new TiXmlDocument();
	pDoc->LoadFile(xmlPath.c_str());
	//pDoc->Print();
	//char labelName[50]="";
	//获取根节点
	TiXmlElement* pRoot = pDoc->RootElement();
	string rootName = pRoot->Value();
	TiXmlElement* itemElement = pRoot->FirstChildElement("BOMCONTENTS");//
	string t_Item_info = rootName;//
	string itemLable = itemElement->Value();//中间表表名
											//循环遍历根节点下的兄弟节点
	char type[50] = "";
	char sessionId[50] = "";
	char transNowTime[50] = "";
	char transStatus[50] = "";
	char itemId[50] = "";
	char itemRev[50] = "";
	char itemName[50] = "";
	char itemRelease[50] = "";
	map<vector<string>, vector<string>> propertyMap;//字段名集合，值的集合
	vector<string> nameVec;
	vector<string> valueVec;
	TiXmlElement* pChild = itemElement->FirstChildElement();
	const char* attribute_value = NULL;
	if (pChild != NULL) {
		string childLabnelName = pChild->Value();
		attribute_value = pChild->Attribute("val");
		if (attribute_value == NULL) {
			strcpy(sessionId, " ");
		}
		else {
			strcpy(sessionId, attribute_value);
		}
		string tempValue = sessionId;
		nameVec.push_back(childLabnelName);
		valueVec.push_back(tempValue);
	}
	pChild = pChild->NextSiblingElement();
	while (true) {
		if (pChild != NULL) {
			string childLabnelName = pChild->Value();
			attribute_value = pChild->Attribute("val");
			if (attribute_value == NULL) {
				strcpy(sessionId, " ");
			}
			else {
				strcpy(sessionId, attribute_value);
			}
			string tempValue = sessionId;
			//propertyMap[childLabnelName]=tempValue;
			if (strcmp("TRANSNO", childLabnelName.c_str()) == 0) {
				//转换时间, 将时间按照指定格式转换为字符串
				strftime(timeString, sizeof(timeString), sessionId, timeInfo);
				// 打印转换后的时间字符串
				tempValue = timeString;
			}
			else if (strcmp("SONPZLIST", childLabnelName.c_str()) == 0) {
			}
			else if (strcmp("SUNPZLIST", childLabnelName.c_str()) == 0) {
			}
			if (strcmp("SONPZLIST", childLabnelName.c_str()) != 0 && strcmp("SUNPZLIST", childLabnelName.c_str()) != 0) {
				nameVec.push_back(childLabnelName);;
				valueVec.push_back(tempValue);
			}
			pChild = pChild->NextSiblingElement();
			if (pChild == NULL) {
				break;
			}
		}
	}
	propertyMap[nameVec] = valueVec;
	xmlMap["父"] = propertyMap;
	pChild = itemElement->FirstChildElement("SONPZLIST");
	vector<string> childNameVec;
	vector<string> childValueVec;
	map<vector<string>, vector<string>> childPropertyMap;//字段名集合，值的集合
	TiXmlElement* sonChild = pChild;
	TiXmlElement* cChild = sonChild->FirstChildElement();
	if (cChild != NULL) {
		string LabnelName = cChild->Value();
		attribute_value = cChild->Attribute("val");
		strcpy(sessionId, attribute_value);  // 将 str 复制给 copy
		string tempValue = sessionId;
		childNameVec.push_back(LabnelName);
		childValueVec.push_back(tempValue);
	}
	cChild = cChild->NextSiblingElement();
	while (true) {
		if (cChild != NULL) {
			string LabnelName = cChild->Value();
			attribute_value = cChild->Attribute("val");
			if (attribute_value == NULL) {
				strcpy(sessionId, " ");  // 将 str 复制给 copy
			}
			else {
				strcpy(sessionId, attribute_value);  // 将 str 复制给 copy
			}
			string tempValue = sessionId;
			childNameVec.push_back(LabnelName);
			childValueVec.push_back(tempValue);
		}
		cChild = cChild->NextSiblingElement();
		if (cChild == NULL) {
			break;
		}
	}
	childPropertyMap[childNameVec] = childValueVec;
	xmlMap["子"] = childPropertyMap;
	pChild = itemElement->FirstChildElement("SUNPZLIST");
	if (pChild != NULL) {
		vector<string> childLevel2NameVec;
		vector<string> childLevel2ValueVec;
		map<vector<string>, vector<string>> childLevel2PropertyMap;//字段名集合，值的集合
		TiXmlElement* sunChild = pChild;
		TiXmlElement* sChild = sunChild->FirstChildElement();
		if (sChild != NULL) {
			string LabnelName = sChild->Value();
			attribute_value = sChild->Attribute("val");
			strcpy(sessionId, attribute_value);  // 将 str 复制给 copy
			string tempValue = sessionId;
			childLevel2NameVec.push_back(LabnelName);
			childLevel2ValueVec.push_back(tempValue);
		}
		sChild = sChild->NextSiblingElement();
		while (true) {
			if (sChild != NULL) {
				string LabnelName = sChild->Value();
				attribute_value = sChild->Attribute("val");
				if (attribute_value == NULL) {
					strcpy(sessionId, " ");  // 将 str 复制给 copy
				}
				else {
					strcpy(sessionId, attribute_value);  // 将 str 复制给 copy
				}
				string tempValue = sessionId;
				childLevel2NameVec.push_back(LabnelName);
				childLevel2ValueVec.push_back(tempValue);
			}
			sChild = sChild->NextSiblingElement();
			if (sChild == NULL) {
				break;
			}
		}
		childLevel2PropertyMap[childLevel2NameVec] = childLevel2ValueVec;
		xmlMap["孙"] = childLevel2PropertyMap;
	}
	delete pDoc;//应该是必要的
	return t_Item_info;
}

string loadXml(string xmlUid, map<string, map<vector<string>, vector<string>>>& xmlMap) {
	tag_t bomInfoXml = NULL;
	ITK__convert_uid_to_tag(xmlUid.c_str(), &bomInfoXml);
	//获取文件
	char* temp_dir = getenv("temp");//获得缓存路径
	char output_file_xml_temp[SS_MAXPATHLEN] = "";
	strcpy(output_file_xml_temp, temp_dir);
	strcat(output_file_xml_temp, "\\");
	strcat(output_file_xml_temp, xmlUid.c_str());
	strcat(output_file_xml_temp, ".xml");
	if (access(output_file_xml_temp, 0) == 0) {//存在
		if (remove(output_file_xml_temp) == 0) {
			cout << "exist" << output_file_xml_temp << "delete" << endl;
		}
	}
	POM_AM__set_application_bypass(true);
	ITKCALL(AE_export_named_ref(bomInfoXml, "XMLRendering", output_file_xml_temp));
	POM_AM__set_application_bypass(false);
	string path = output_file_xml_temp;
	string tableName = readBOPXML(xmlMap, path);
	return tableName;
}

void loadBom(tag_t top_bom_line_tag, map<string, CHILD>& child_level1, map<string, vector<string>>& level1_level2, map<string, CHILD>& child_level2, map<string, vector<CHILD>> &gx_gb_bom, map<string, vector<CHILD>>& gx_gb_zy) {
	int child_count = 0; 
	tag_t* child_tags = NULLTAG;
	//ITKCALL(BOM_line_ask_child_lines(top_bom_line_tag, &child_count, &child_tags));
	//ITKCALL(ME_line_ask_child_lines(top_bom_line_tag, &child_count, &child_tags));
	ITKCALL(AOM_ask_value_tags(top_bom_line_tag, "Mfg0sub_elements", &child_count, &child_tags));
	// 遍历工艺下工序层级
	WriteLog("工序个数为：%d\n", child_count);
	for (int x = 0; x < child_count; x++)
	{
		char* gx_clone_id = NULL;
		CHILD child;
		tag_t	gx_rev = NULLTAG,
				gx_item = NULLTAG,
				* gx_child_tags = NULLTAG,
				gxgb = NULLTAG,
				* child_gbs = NULLTAG;
		int gx_child_count = 0,
			gb_child_count = 0;
		vector<string> child_vec;
		vector<CHILD> gb_vec;

		ITKCALL(AOM_ask_value_tag(child_tags[x], "bl_line_object", &gx_rev));
		ITKCALL(AOM_ask_value_string(child_tags[x], "bl_clone_stable_occurrence_id", &gx_clone_id));
		ITEM_ask_item_of_rev(gx_rev, &gx_item);
		string gx_key = string(gx_clone_id);
		child.item = gx_item;
		child.line = child_tags[x];
		child.rev = gx_rev;
		child.clone_id = gx_key;
		child_level1[gx_key] = child;
		// 遍历工工序下的工艺资源及文件
		ITKCALL(BOM_line_ask_child_lines(child_tags[x], &gx_child_count, &gx_child_tags));
		WriteLog("工序下级个数为：%d\n", gx_child_count);
		//ITKCALL(AOM_ask_value_tags(child_tags[x], "Mfg0sub_elements", &gx_child_count, &gx_child_tags));
		for (int y = 0; y < gx_child_count; y++)
		{
			char* zy_clone_id = NULL;
			CHILD gxChild;
			tag_t	zy_rev = NULLTAG,
					zy_Item = NULLTAG;
			ITKCALL(AOM_ask_value_tag(gx_child_tags[y], "bl_line_object", &zy_rev));
			ITKCALL(AOM_ask_value_string(gx_child_tags[y], "bl_clone_stable_occurrence_id", &zy_clone_id));
			string zy_key = string(zy_clone_id);
			ITEM_ask_item_of_rev(zy_rev, &zy_Item);
			gxChild.item = zy_Item;
			gxChild.line = gx_child_tags[y];
			gxChild.rev = zy_rev;
			gxChild.clone_id = zy_key;
			child_level2[zy_key] = gxChild;
			child_vec.push_back(zy_key);
			DOFREE(zy_clone_id);
		}
		level1_level2[gx_key] = child_vec;
		// 遍历工工序下的工步
		ITKCALL(AOM_ask_value_tag(child_tags[x], "bl_me_activity_lines", &gxgb));
		ITKCALL(AOM_ask_value_tags(gxgb, "me_cl_child_lines", &gb_child_count, &child_gbs));
		WriteLog("工步下级数量：%d\n", gb_child_count);
		if (gb_child_count > 0) {
			for (int z = 0; z < gb_child_count; z++) {
				char* puid = NULL;
				CHILD gbChild;
				tag_t	gb = NULLTAG,
						* gb_zys = NULLTAG;
				int tool_cnt = 0;
				vector<CHILD> gbzy_vec;
				ITKCALL(AOM_ask_value_tag(child_gbs[z], "al_object", &gb));
				ITK__convert_tag_to_uid(gb, &puid);
				string key = string(gx_clone_id) + string(puid);
				ITKCALL(AOM_ask_value_tags(child_gbs[z], "al_activity_tool_bl_list", &tool_cnt, &gb_zys));
				if (tool_cnt > 0) {
					for (int a = 0; a < tool_cnt; a++) {
						CHILD gbzyChild;
						tag_t	gbzy_rev = NULLTAG,
								gbzy_Item = NULLTAG;
						ITKCALL(AOM_ask_value_tag(gb_zys[a], "bl_line_object", &gbzy_rev));
						ITEM_ask_item_of_rev(gbzy_rev, &gbzy_Item);
						gbzyChild.rev = gbzy_rev;
						gbzyChild.item = gbzy_Item;
						gbzyChild.line = gb_zys[a];
						gbzy_vec.push_back(gbzyChild);
					}
				}
				gbChild.item = gb;
				gbChild.line = child_gbs[z];
				gb_vec.push_back(gbChild);
				gx_gb_zy[key] = gbzy_vec;
				DOFREE(puid);
				DOFREE(gb_zys);
			}
		}
		gx_gb_bom[gx_clone_id] = gb_vec;
		DOFREE(child_gbs);
		DOFREE(gx_clone_id);
		DOFREE(gx_child_tags);
	}
	DOFREE(child_tags);
}

// 工艺路线工序明细表
void insertGyGxBom(string xmlUid, bool &showError, ado ado0, tag_t gy_line, tag_t gy_item, tag_t gy_rev, map<string, CHILD> child_level1, map<string, string> &gx_cloneid_key) {
	WriteLog("记录工艺路线工序明细表数据库\n");
	int ifail = 0;
	char* type = NULL;
	//
	string sqlStr = "insert into ";
	string updateStr = "update ";
	string selectStr = "select * from  ";
	string selectAfterUpdateStr = "select * from  ";
	string updateWhere = "";
	// 加载工艺路线工序明显表数据
	// 解析xml文件
	// 创建一个XML结构并载入文件内容
	map<string, map<vector<string>, vector<string>>> xmlMap;//物料类型，<字段名，属性取值>
	string tableName = loadXml(xmlUid, xmlMap);

	map<vector<string>, vector<string>> parentPropertyMap = xmlMap["父"];//父级
	vector<string> parentNameVec;
	vector<string> parentValueVec;
	map<vector<string>, vector<string>>::iterator rev_it2;
	for (rev_it2 = parentPropertyMap.begin(); rev_it2 != parentPropertyMap.end(); rev_it2++) {
		parentNameVec = rev_it2->first;
		parentValueVec = rev_it2->second;
	}
	map<vector<string>, vector<string>> childPropertyMap = xmlMap["子"];//子级
	vector<string> childNameVec;
	vector<string> childValueVec;
	map<vector<string>, vector<string>>::iterator rev_it;
	for (rev_it = childPropertyMap.begin(); rev_it != childPropertyMap.end(); rev_it++) {
		childNameVec = rev_it->first;
		childValueVec = rev_it->second;
	}
	vector<string> updateVec;
	vector<string> selectVec;
	vector<string> insertVec;
	vector<string> selectAfterUpdateVec;
	vector<string> insertClonIdVec;


	sqlStr = sqlStr.append(tableName).append("(");
	selectStr = selectStr.append(tableName).append(" ");
	selectAfterUpdateStr = selectAfterUpdateStr.append(tableName).append(" ");
	string valueStr = " VALUES (";


	//获取父属性
	string parentColumnStr = "insert into ";
	parentColumnStr = parentColumnStr.append(tableName).append(" (");
	string parentValueStr = " values(";
	for (int j = 0; j < parentNameVec.size(); j++)
	{
		string columnName = parentNameVec[j];
		parentColumnStr = parentColumnStr.append(columnName);
		if (j < parentNameVec.size() - 1) {
			parentColumnStr = parentColumnStr.append(",");
		}
		string propertyName = parentValueVec[j];
		string tempValue = " ";
		string updateValue = "";
		if (strcmp(columnName.c_str(), "SESSIONID") == 0) {
			tempValue = propertyName;//固定值
		}
		else if (strcmp(columnName.c_str(), "TRANSNO") == 0) {
			tempValue = propertyName;//已处理
			if (updateWhere.length() == 0) {
				updateWhere = updateWhere.append(" where ");
				updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and ");
				selectStr = selectStr.append(" where ");
				selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(" where ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
			}
			else {
				updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and ");
				selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
			}
		}
		else if (strcmp(columnName.c_str(), "TRANSSTATUS") == 0) {
			//首次传递空值

			updateValue = propertyName;
			updateStr = updateStr.append(tableName).append(" set ").append(columnName).append("='").append(updateValue).append("'  ");
			selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(updateValue).append("' and ");
		}
		else if (strcmp(columnName.c_str(), "PPUID") == 0) {
			char* puid = NULL;
			ITK__convert_tag_to_uid(gy_rev, &puid);
			tempValue = puid;
			//selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
			if (updateWhere.length() == 0) {
				updateWhere = updateWhere.append(" where ");
				updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and ");
				selectStr = selectStr.append(" where ");
				selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(" where ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
			}
			else {
				updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and ");
				selectStr = selectStr.append(columnName).append("='").append(puid).append("' and ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(puid).append("' and ");
			}
			DOFREE(puid);
		}
		else {
			vector<string> propertyVec;
			Split(propertyName, ".", propertyVec);
			if (propertyVec.size() == 2) {
				string propertyPosition = propertyVec[0];
				tag_t propertyTag = NULL;
				if (strcmp("item", propertyPosition.c_str()) == 0) {
					propertyTag = gy_item;
				}
				else if (strcmp("rev", propertyPosition.c_str()) == 0) {
					propertyTag = gy_rev;
				}
				else if (strcmp("bomline", propertyPosition.c_str()) == 0) {
					propertyTag = gy_line;
				}
				string propertyName = propertyVec[1];
				char* propertyValue = NULL;
				if (strcmp("puid", propertyName.c_str()) == 0) {
					ITK__convert_tag_to_uid(propertyTag, &propertyValue);
				}
				else {
					ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue));
				}
				EMH_clear_errors();
				if (ifail == 0) {
					tempValue = propertyValue;
				}
				else {
					showError = true;
					WriteLog("属性异常：%s\n", propertyName.c_str());
					tempValue = " ";
				}
				DOFREE(propertyValue);
			}
		}
		parentValueStr = parentValueStr.append("'").append(tempValue).append("'");
		if (j < parentNameVec.size() - 1) {
			parentValueStr = parentValueStr.append(",");
		}
	}

	map<string, CHILD>::iterator child_it;
	for (child_it = child_level1.begin(); child_it != child_level1.end(); child_it++) {
		bool isContinue = false;
		string childColumnStr = "";
		string childSelectStr = "";
		string childUpdateSelectStr = "";
		string childUpdateWhere = "";
		string childValueStr = "";
		tag_t line = child_it->second.line;
		tag_t item = child_it->second.item;
		tag_t rev = child_it->second.rev;
		string clone_id = child_it->second.clone_id;
		string primay_key = "";
		ITKCALL(ifail = AOM_ask_value_string(rev, "object_type", &type));
		for (int j = 0; j < childNameVec.size(); j++)
		{
			string columnName = childNameVec[j];
			string propertyName = childValueVec[j];
			string tempValue = " ";
			
			if (strcmp(columnName.c_str(), "_FILTERTYPE") == 0) {
				if (strcmp(propertyName.c_str(), "ALL") == 0) {
					continue;
				}
				else {
					vector<string>typeVec;
					Split(propertyName, ";", typeVec);
					if (hasElement(typeVec, type) == 0) {
						continue;
					}
					else {
						isContinue = true;
						break;
					}
				}
			}
			else if (strcmp(columnName.c_str(), "CPUID") == 0) {
				char* puid = NULL;
				ITK__convert_tag_to_uid(rev, &puid);
				tempValue = puid;
				DOFREE(puid);
				childSelectStr = childSelectStr.append(columnName).append("='").append(tempValue).append("'  ");
				childUpdateSelectStr = childUpdateSelectStr.append(columnName).append("='").append(tempValue).append("'  ");
				childUpdateWhere = childUpdateWhere.append(columnName).append("='").append(tempValue).append("'");
			}
			else {
				vector<string> propertyVec;
				Split(propertyName, ".", propertyVec);
				if (propertyVec.size() == 2) {
					string propertyPosition = propertyVec[0];
					tag_t propertyTag = NULL;
					if (strcmp("item", propertyPosition.c_str()) == 0) {
						propertyTag = item;
					}
					else if (strcmp("rev", propertyPosition.c_str()) == 0) {
						propertyTag = rev;
					}
					else if (strcmp("bomline", propertyPosition.c_str()) == 0) {
						propertyTag = line;
					}
					string propertyName = propertyVec[1];
					char* propertyValue = NULL;
					if (strcmp("puid", propertyName.c_str()) == 0) {
						ITK__convert_tag_to_uid(propertyTag, &propertyValue);
					}
					else {
						ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue));
					}
					EMH_clear_errors();
					if (ifail == 0) {
						tempValue = propertyValue;
					}
					else {
						showError = true;
						WriteLog("属性异常：%s\n", propertyName.c_str());
						tempValue = " ";
					}
					DOFREE(propertyValue);
				}
				else if (strcmp("key", propertyName.c_str()) == 0) {
					primay_key = getGuid();
					tempValue = primay_key;
				}
				else {
					tempValue = " ";
				}
			}
			childColumnStr = childColumnStr.append(columnName);
			if (j < childNameVec.size() - 1) {
				childColumnStr = childColumnStr.append(",");
			}
			childValueStr = childValueStr.append("'").append(tempValue);
			if (j < childNameVec.size() - 1) {
				childValueStr = childValueStr.append("',");
			}
			else {
				childValueStr = childValueStr.append("'");
			}
		}
		if (isContinue) {
			continue;
		}
		string insertSql = "";
		string selectSql = "";
		string updateSelectSql = "";
		string updateSql = "";
		if (childColumnStr.size() > 0) {
			insertSql = insertSql.append(parentColumnStr).append(",").append(childColumnStr).append(")").append(parentValueStr).append(",").append(childValueStr).append(")");
		}
		else {
			insertSql = insertSql.append(parentColumnStr).append(")").append(parentValueStr).append(")");
		}
		selectSql = selectSql.append(selectStr).append(childSelectStr);
		updateSelectSql = updateSelectSql.append(selectAfterUpdateStr).append(childUpdateSelectStr);
		updateSql = updateSql.append(updateStr).append(updateWhere).append(childUpdateWhere);
		//updateStr = updateStr.append(updateWhere);

		insertSql = Utf8ToGbk(insertSql.c_str());
		updateSql = Utf8ToGbk(updateSql.c_str());
		selectSql = Utf8ToGbk(selectSql.c_str());
		updateSelectSql = Utf8ToGbk(updateSelectSql.c_str());
		WriteLog("工序明细插入语句：%s\n", insertSql.c_str());
		WriteLog("工序明细更新语句：%s\n", updateSql.c_str());
		WriteLog("工序明细查询语句：%s\n", selectSql.c_str());
		WriteLog("工序明细更新后查询语句：%s\n", updateSelectSql.c_str());
		insertVec.push_back(insertSql);
		updateVec.push_back(updateSql);
		selectVec.push_back(selectSql);
		selectAfterUpdateVec.push_back(updateSelectSql);
		insertClonIdVec.push_back(clone_id);
		char sendChar[400] = "";
		strcpy(sendChar, insertSql.c_str());
		char sendChar2[400] = "";
		strcpy(sendChar2, selectSql.c_str());
		int result = ado0.ado_QuerySQLNoInputParam(sendChar2);
		bool resultSql = ado0.executeInsert(sendChar2, sendChar, result);
		gx_cloneid_key[clone_id] = primay_key;
		//if (!resultSql) {
		//	WriteLog("数据库语句插入失败\n");
		//}
	}
	DOFREE(type);
	//WriteLog("开始更新数据库\n");
	//更新数据库
	//for (int i = 0; i < updateVec.size(); i++) {
	//	int outputColumn = 0, outputValueCount = 0;
	//	char*** outputValue = NULL;
	//	//string updateSql = updateVec[i];
	//	//string selectSql = selectVec[i];
	//	//string insertSql = insertVec[i];
	//	string selectUpdate = selectAfterUpdateVec[i];
	//	string clone_id = insertClonIdVec[i];
	//	char sendChar[400] = "";
	//	char sendChar2[400] = "";
	//	char sendChar3[400] = "";
	//	//strcpy(sendChar, updateSql.c_str());
	//	//strcpy(sendChar2, selectSql.c_str());
	//	strcpy(sendChar3, selectUpdate.c_str());
	//	int result = 0;
	//	//int result = ado0.ado_QuerySQLNoInputParam(sendChar2);
	//	//if (result == 0) {
	//	//	showError = true;
	//	//	WriteLog("工序明细插入失败：%s\n", insertSql.c_str());
	//	//}
	//	//else {
	//		//bool resultSql = ado0.execute2(sendChar2, sendChar, result);
	//		WriteLog("查询数据内容：%s\n", sendChar3);
	//		result = ado0.ado_QuerySQLNoInputParam2(sendChar3, &outputColumn, &outputValueCount, &outputValue);
	//		WriteLog("查询数据结果：%d\n", result);
	//		if (result == 0) {
	//			showError = true;
	//			//WriteLog("工序明细更新失败：%s\n", updateSql.c_str());
	//		}
	//		else{
	//			if (outputValueCount > 0) {
	//				WriteLog("设值gx_cloneid_key1\n");
	//				gx_cloneid_key[clone_id] = string(outputValue[0][0]);
	//				WriteLog("设值gx_cloneid_key2\n");
	//			}
	//		}
	//	//}
	//}
}

// 工序工步关系表
void insertGxGb(string xmlUid, bool& showError, ado ado0, map<string, CHILD> child_level1, map<string, string> gx_cloneid_key, map<string, vector<CHILD>> gx_gbs_bom, map<string, string>& gx_gb_key) {
	WriteLog("记录工序工步关系表数据库\n");
	int ifail = 0;
	char* gx_type = NULL;
	vector<string> updateVec;
	vector<string> selectVec;
	vector<string> insertVec;
	vector<string> selectAfterUpdateVec;
	vector<string> insertPuidVec;
	// 解析xml文件
	// 创建一个XML结构并载入文件内容
	map<string, map<vector<string>, vector<string>>> xmlMap;//物料类型，<字段名，属性取值>
	string tableName = loadXml(xmlUid, xmlMap);

	map<vector<string>, vector<string>> parentPropertyMap = xmlMap["父"];//父级
	vector<string> parentNameVec;
	vector<string> parentValueVec;
	map<vector<string>, vector<string>>::iterator rev_it2;
	for (rev_it2 = parentPropertyMap.begin(); rev_it2 != parentPropertyMap.end(); rev_it2++) {
		parentNameVec = rev_it2->first;
		parentValueVec = rev_it2->second;
	}
	map<vector<string>, vector<string>> childPropertyMap = xmlMap["子"];//子级
	vector<string> childNameVec;
	vector<string> childValueVec;
	map<vector<string>, vector<string>>::iterator rev_it;
	for (rev_it = childPropertyMap.begin(); rev_it != childPropertyMap.end(); rev_it++) {
		childNameVec = rev_it->first;
		childValueVec = rev_it->second;
	}

	map<string, CHILD>::iterator child_it;
	for (child_it = child_level1.begin(); child_it != child_level1.end(); child_it++) {
		bool isGxContinue = false;
		char* type = NULL;
		string sqlStr = "insert into ";
		string updateStr = "update ";
		string selectStr = "select * from  ";
		string selectAfterUpdateStr = "select * from  ";
		string updateWhere = "";
		string gx_clone_id = child_it->first;
		tag_t gx_line = child_it->second.line;
		tag_t gx_item = child_it->second.item;
		tag_t gx_rev = child_it->second.rev;
		vector<CHILD> gbs = gx_gbs_bom[gx_clone_id];
		ITKCALL(ifail = AOM_ask_value_string(gx_rev, "object_type", &gx_type));

		sqlStr = sqlStr.append(tableName).append("(");
		selectStr = selectStr.append(tableName).append(" ");
		selectAfterUpdateStr = selectAfterUpdateStr.append(tableName).append(" ");
		string valueStr = " VALUES (";

		//获取父属性
		string parentColumnStr = "insert into ";
		parentColumnStr = parentColumnStr.append(tableName).append(" (");
		string parentValueStr = " values(";
		for (int j = 0; j < parentNameVec.size(); j++)
		{
			string columnName = parentNameVec[j];
			parentColumnStr = parentColumnStr.append(columnName);
			if (j < parentNameVec.size() - 1) {
				parentColumnStr = parentColumnStr.append(",");
			}
			string propertyName = parentValueVec[j];
			string tempValue = " ";
			string updateValue = "";
			if (strcmp(columnName.c_str(), "_FILTERTYPE") == 0) {
				if (strcmp(propertyName.c_str(), "ALL") == 0) {
					continue;
				}
				else {
					vector<string>typeVec;
					Split(propertyName, ";", typeVec);
					if (hasElement(typeVec, gx_type) == 0) {
						continue;
					}
					else {
						isGxContinue = true;
						break;
					}
				}
			} 
			else if (strcmp(columnName.c_str(), "SESSIONID") == 0) {
				tempValue = propertyName;//固定值
			}
			else if (strcmp(columnName.c_str(), "PROCESS_DETAILS_ID") == 0) {
				tempValue = gx_cloneid_key[gx_clone_id];// 工序明细表ID（外键）
			}
			else if (strcmp(columnName.c_str(), "TRANSNO") == 0) {
				tempValue = propertyName;//已处理
				if (updateWhere.length() == 0) {
					updateWhere = updateWhere.append(" where ");
					updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and ");
					selectStr = selectStr.append(" where ");
					selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
					selectAfterUpdateStr = selectAfterUpdateStr.append(" where ");
					selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
				}
				else {
					updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and ");
					selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
					selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
				}
			}
			else if (strcmp(columnName.c_str(), "TRANSSTATUS") == 0) {
				//首次传递空值
				updateValue = propertyName;
				updateStr = updateStr.append(tableName).append(" set ").append(columnName).append("='").append(updateValue).append("'  ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(updateValue).append("' and ");
			}
			else if (strcmp(columnName.c_str(), "PPUID") == 0) {
				char* puid = NULL;
				ITK__convert_tag_to_uid(gx_rev, &puid);
				tempValue = puid;
				//selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
				if (updateWhere.length() == 0) {
					updateWhere = updateWhere.append(" where ");
					updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and ");
					selectStr = selectStr.append(" where ");
					selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
					selectAfterUpdateStr = selectAfterUpdateStr.append(" where ");
					selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
				}
				else {
					updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and ");
					selectStr = selectStr.append(columnName).append("='").append(puid).append("' and ");
					selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(puid).append("' and ");
				}
				DOFREE(puid);
			}
			else {
				vector<string> propertyVec;
				Split(propertyName, ".", propertyVec);
				if (propertyVec.size() == 2) {
					string propertyPosition = propertyVec[0];
					tag_t propertyTag = NULL;
					if (strcmp("item", propertyPosition.c_str()) == 0) {
						propertyTag = gx_item;
					}
					else if (strcmp("rev", propertyPosition.c_str()) == 0) {
						propertyTag = gx_rev;
					}
					else if (strcmp("bomline", propertyPosition.c_str()) == 0) {
						propertyTag = gx_line;
					}
					string propertyName = propertyVec[1];
					char* propertyValue = NULL;
					if (strcmp("puid", propertyName.c_str()) == 0) {
						ITK__convert_tag_to_uid(propertyTag, &propertyValue);
					}
					else {
						ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue));
					}
					EMH_clear_errors();
					if (ifail == 0) {
						tempValue = propertyValue;
					}
					else {
						showError = true;
						WriteLog("属性异常：%s\n", propertyName.c_str());
						tempValue = " ";
					}
					DOFREE(propertyValue);
				}
			}
			parentValueStr = parentValueStr.append("'").append(tempValue).append("'");
			if (j < parentNameVec.size() - 1) {
				parentValueStr = parentValueStr.append(",");
			}
		}
		if (isGxContinue) {
			continue;
		}

		int gb_count = gbs.size();
		if (gb_count > 0) {
			for (int x = 0; x < gb_count; x++) {
				bool isContinue = false;
				tag_t gb_line = gbs[x].line;
				tag_t gb_item = gbs[x].item;
				string childColumnStr = "";
				string childSelectStr = "";
				string childUpdateSelectStr = "";
				string childUpdateWhere = "";
				string childValueStr = "";
				string gb_puid = "";;
				string primay_key = "";
				ITKCALL(ifail = AOM_ask_value_string(gb_item, "object_type", &type));
				for (int j = 0; j < childNameVec.size(); j++)
				{
					string columnName = childNameVec[j];
					string propertyName = childValueVec[j];
					string tempValue = " ";
					if (strcmp(columnName.c_str(), "_FILTERTYPE") == 0) {
						if (strcmp(propertyName.c_str(), "ALL") == 0) {
							continue;
						}
						else {
							vector<string>typeVec;
							Split(propertyName, ";", typeVec);
							if (hasElement(typeVec, type) == 0) {
								continue;
							}
							else {
								isContinue = true;
								break;
							}
						}
					}
					else if (strcmp(columnName.c_str(), "CPUID") == 0) {
						char* puid = NULL;
						ITK__convert_tag_to_uid(gb_item, &puid);
						tempValue = puid;
						gb_puid = string(puid);

						childSelectStr = childSelectStr.append(columnName).append("='").append(tempValue).append("'  ");
						childUpdateSelectStr = childUpdateSelectStr.append(columnName).append("='").append(tempValue).append("'  ");
						childUpdateWhere = childUpdateWhere.append(columnName).append("='").append(tempValue).append("'");
						DOFREE(puid);
					}
					else {
						vector<string> propertyVec;
						Split(propertyName, ".", propertyVec);
						if (propertyVec.size() == 2) {
							string propertyPosition = propertyVec[0];
							tag_t propertyTag = NULL;
							if (strcmp("item", propertyPosition.c_str()) == 0) {
								propertyTag = gb_item;
							}
							else if (strcmp("bomline", propertyPosition.c_str()) == 0) {
								propertyTag = gb_line;
							}
							string propertyName = propertyVec[1];
							char* propertyValue = NULL;
							if (strcmp("puid", propertyName.c_str()) == 0) {
								ITK__convert_tag_to_uid(propertyTag, &propertyValue);
							}
							else {
								ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue));
							}
							EMH_clear_errors();
							if (ifail == 0) {
								tempValue = propertyValue;
							}
							else {
								showError = true;
								WriteLog("属性异常：%s\n", propertyName.c_str());
								tempValue = " ";
							}
							DOFREE(propertyValue);
						}
						else if (strcmp("key", propertyName.c_str()) == 0) {
							primay_key = getGuid();
							tempValue = primay_key;
						}
						else {
							tempValue = " ";
						}
					}
					childColumnStr = childColumnStr.append(columnName);
					if (j < childNameVec.size() - 1) {
						childColumnStr = childColumnStr.append(",");
					}
					childValueStr = childValueStr.append("'").append(tempValue);
					if (j < childNameVec.size() - 1) {
						childValueStr = childValueStr.append("',");
					}
					else {
						childValueStr = childValueStr.append("'");
					}
				}
				if (isContinue) {
					continue;
				}
				string insertSql = "";
				string selectSql = "";
				string updateSelectSql = "";
				string updateSql = "";
				if (childColumnStr.size() > 0) {
					insertSql = insertSql.append(parentColumnStr).append(",").append(childColumnStr).append(")").append(parentValueStr).append(",").append(childValueStr).append(")");
				}
				else {
					insertSql = insertSql.append(parentColumnStr).append(")").append(parentValueStr).append(")");
				}
				selectSql = selectSql.append(selectStr).append(childSelectStr);
				updateSelectSql = updateSelectSql.append(selectAfterUpdateStr).append(childUpdateSelectStr);
				updateSql = updateSql.append(updateStr).append(updateWhere).append(childUpdateWhere);
				//updateStr = updateStr.append(updateWhere);

				insertSql = Utf8ToGbk(insertSql.c_str());
				updateSql = Utf8ToGbk(updateSql.c_str());
				selectSql = Utf8ToGbk(selectSql.c_str());
				updateSelectSql = Utf8ToGbk(updateSelectSql.c_str());
				WriteLog("工步插入语句：%s\n", insertSql.c_str());
				WriteLog("工步更新语句：%s\n", updateSql.c_str());
				WriteLog("工步查询语句：%s\n", selectSql.c_str());
				WriteLog("工步更新后查询语句：%s\n", updateSelectSql.c_str());
				insertVec.push_back(insertSql);
				updateVec.push_back(updateSql);
				selectVec.push_back(selectSql);
				selectAfterUpdateVec.push_back(updateSelectSql);
				insertPuidVec.push_back(gx_clone_id + gb_puid);
				char sendChar[400] = "";
				strcpy(sendChar, insertSql.c_str());
				char sendChar2[400] = "";
				strcpy(sendChar2, selectSql.c_str());
				int result = ado0.ado_QuerySQLNoInputParam(sendChar2);
				bool resultSql = ado0.executeInsert(sendChar2, sendChar, result);
				string key = gx_clone_id + gb_puid;
				gx_gb_key[key] = primay_key;
				//if (!resultSql) {
				//	WriteLog("数据库语句插入失败\n");
				//}
			}
		}
		DOFREE(type);	
	}
	DOFREE(gx_type);
	//更新数据库
	//for (int i = 0; i < updateVec.size(); i++) {
	//	int outputColumn = 0, outputValueCount = 0;
	//	char*** outputValue = NULL;
	//	string updateSql = updateVec[i];
	//	string selectSql = selectVec[i];
	//	string insertSql = insertVec[i];
	//	string selectUpdate = selectAfterUpdateVec[i];
	//	string key = insertPuidVec[i];
	//	char sendChar[400] = "";
	//	char sendChar2[400] = "";
	//	char sendChar3[400] = "";
	//	strcpy(sendChar, updateSql.c_str());
	//	strcpy(sendChar2, selectSql.c_str());
	//	strcpy(sendChar3, selectUpdate.c_str());
	//	int result = ado0.ado_QuerySQLNoInputParam(sendChar2);
	//	if (result == 0) {
	//		showError = true;
	//		WriteLog("工步插入失败：%s\n", insertSql.c_str());
	//	}
	//	else {
	//		//bool resultSql = ado0.execute2(sendChar2, sendChar, result);
	//		result = ado0.ado_QuerySQLNoInputParam2(sendChar3, &outputColumn, &outputValueCount, &outputValue);
	//		if (result == 0) {
	//			showError = true;
	//			WriteLog("工步更新失败：%s\n", updateSql.c_str());
	//		}
	//		else {
	//			if (outputValueCount > 0) {
	//				gx_gb_key[key] = string(outputValue[0][0]);
	//			}
	//		}
	//	}
	//}
}

// 工艺路线-工序属性表
void insertGyGxProp(string xmlUid, bool& showError, ado ado0, tag_t gy_line, tag_t gy_item, tag_t gy_rev, map<string, CHILD> child_level1, map<string, string> gx_cloneid_key) {
	WriteLog("记录工艺路线-工序属性表数据库\n");
	int ifail = 0;
	char* type = NULL;
	//
	string sqlStr = "insert into ";
	string updateStr = "update ";
	string selectStr = "select * from  ";
	string selectAfterUpdateStr = "select * from  ";
	string updateWhere = "";
	// 加载工艺路线工序明显表数据
	// 解析xml文件
	// 创建一个XML结构并载入文件内容
	map<string, map<vector<string>, vector<string>>> xmlMap;//物料类型，<字段名，属性取值>
	string tableName = loadXml(xmlUid, xmlMap);

	map<vector<string>, vector<string>> parentPropertyMap = xmlMap["父"];//父级
	vector<string> parentNameVec;
	vector<string> parentValueVec;
	map<vector<string>, vector<string>>::iterator rev_it2;
	for (rev_it2 = parentPropertyMap.begin(); rev_it2 != parentPropertyMap.end(); rev_it2++) {
		parentNameVec = rev_it2->first;
		parentValueVec = rev_it2->second;
	}
	map<vector<string>, vector<string>> childPropertyMap = xmlMap["子"];//子级
	vector<string> childNameVec;
	vector<string> childValueVec;
	map<vector<string>, vector<string>>::iterator rev_it;
	for (rev_it = childPropertyMap.begin(); rev_it != childPropertyMap.end(); rev_it++) {
		childNameVec = rev_it->first;
		childValueVec = rev_it->second;
	}
	vector<string> updateVec;
	vector<string> selectVec;
	vector<string> insertVec;
	vector<string> selectAfterUpdateVec;

	sqlStr = sqlStr.append(tableName).append("(");
	selectStr = selectStr.append(tableName).append(" ");
	selectAfterUpdateStr = selectAfterUpdateStr.append(tableName).append(" ");
	string valueStr = " VALUES (";

	//获取父属性
	string parentColumnStr = "insert into ";
	parentColumnStr = parentColumnStr.append(tableName).append(" (");
	string parentValueStr = " values(";
	for (int j = 0; j < parentNameVec.size(); j++)
	{
		string columnName = parentNameVec[j];
		parentColumnStr = parentColumnStr.append(columnName);
		if (j < parentNameVec.size() - 1) {
			parentColumnStr = parentColumnStr.append(",");
		}
		string propertyName = parentValueVec[j];
		string tempValue = " ";
		string updateValue = "";
		if (strcmp(columnName.c_str(), "SESSIONID") == 0) {
			tempValue = propertyName;//固定值
		}
		else if (strcmp(columnName.c_str(), "TRANSNO") == 0) {
			tempValue = propertyName;//已处理
			if (updateWhere.length() == 0) {
				updateWhere = updateWhere.append(" where ");
				updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and ");
				selectStr = selectStr.append(" where ");
				selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(" where ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
			}
			else {
				updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and ");
				selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
			}
		}
		else if (strcmp(columnName.c_str(), "TRANSSTATUS") == 0) {
			//首次传递空值

			updateValue = propertyName;
			updateStr = updateStr.append(tableName).append(" set ").append(columnName).append("='").append(updateValue).append("'  ");
			selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(updateValue).append("' and ");
		}
		else if (strcmp(columnName.c_str(), "PPUID") == 0) {
			char* puid = NULL;
			ITK__convert_tag_to_uid(gy_rev, &puid);
			tempValue = puid;
			//selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
			if (updateWhere.length() == 0) {
				updateWhere = updateWhere.append(" where ");
				updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and ");
				selectStr = selectStr.append(" where ");
				selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(" where ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
			}
			else {
				updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and ");
				selectStr = selectStr.append(columnName).append("='").append(puid).append("' and ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(puid).append("' and ");
			}
			DOFREE(puid);
		}
		else {
			vector<string> propertyVec;
			Split(propertyName, ".", propertyVec);
			if (propertyVec.size() == 2) {
				string propertyPosition = propertyVec[0];
				tag_t propertyTag = NULL;
				if (strcmp("item", propertyPosition.c_str()) == 0) {
					propertyTag = gy_item;
				}
				else if (strcmp("rev", propertyPosition.c_str()) == 0) {
					propertyTag = gy_rev;
				}
				else if (strcmp("bomline", propertyPosition.c_str()) == 0) {
					propertyTag = gy_line;
				}
				string propertyName = propertyVec[1];
				char* propertyValue = NULL;
				if (strcmp("puid", propertyName.c_str()) == 0) {
					ITK__convert_tag_to_uid(propertyTag, &propertyValue);
				}
				else {
					ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue));
				}
				EMH_clear_errors();
				if (ifail == 0) {
					tempValue = propertyValue;
				}
				else {
					showError = true;
					WriteLog("属性异常：%s\n", propertyName.c_str());
					tempValue = " ";
				}
				DOFREE(propertyValue);
			}
		}
		parentValueStr = parentValueStr.append("'").append(tempValue).append("'");
		if (j < parentNameVec.size() - 1) {
			parentValueStr = parentValueStr.append(",");
		}
	}

	map<string, CHILD>::iterator child_it;
	for (child_it = child_level1.begin(); child_it != child_level1.end(); child_it++) {
		bool isContinue = false;
		string childColumnStr = "";
		string childSelectStr = "";
		string childUpdateSelectStr = "";
		string childUpdateWhere = "";
		string childValueStr = "";
		tag_t line = child_it->second.line;
		tag_t item = child_it->second.item;
		tag_t rev = child_it->second.rev;
		string clone_id = child_it->second.clone_id;
		ITKCALL(ifail = AOM_ask_value_string(rev, "object_type", &type));
		for (int j = 0; j < childNameVec.size(); j++)
		{
			string columnName = childNameVec[j];
			string propertyName = childValueVec[j];
			string tempValue = " ";
			if (strcmp(columnName.c_str(), "_FILTERTYPE") == 0) {
				if (strcmp(propertyName.c_str(), "ALL") == 0) {
					continue;
				}
				else {
					vector<string>typeVec;
					Split(propertyName, ";", typeVec);
					if (hasElement(typeVec, type) == 0) {
						continue;
					} 
					else {
						isContinue = true;
						break;
					}
				}
			} else if (strcmp(columnName.c_str(), "CPUID") == 0) {
				char* puid = NULL;
				ITK__convert_tag_to_uid(rev, &puid);
				tempValue = puid;

				childSelectStr = childSelectStr.append(columnName).append("='").append(tempValue).append("'  ");
				childUpdateSelectStr = childUpdateSelectStr.append(columnName).append("='").append(tempValue).append("'  ");
				childUpdateWhere = childUpdateWhere.append(columnName).append("='").append(tempValue).append("'");
				DOFREE(puid);
			}
			else if (strcmp(columnName.c_str(), "PRD_ID") == 0) {
				// 取明显表中的主键
				WriteLog("属clone_id：%s\n", clone_id.c_str());
				tempValue = gx_cloneid_key[clone_id];
				WriteLog("明显表中的主键：%s\n", tempValue.c_str());
			}
			else {
				vector<string> propertyVec;
				Split(propertyName, ".", propertyVec);
				if (propertyVec.size() == 2) {
					string propertyPosition = propertyVec[0];
					tag_t propertyTag = NULL;
					if (strcmp("item", propertyPosition.c_str()) == 0) {
						propertyTag = item;
					}
					else if (strcmp("rev", propertyPosition.c_str()) == 0) {
						propertyTag = rev;
					}
					else if (strcmp("bomline", propertyPosition.c_str()) == 0) {
						propertyTag = line;
					}
					string propertyName = propertyVec[1];
					char* propertyValue = NULL;
					if (strcmp("puid", propertyName.c_str()) == 0) {
						ITK__convert_tag_to_uid(propertyTag, &propertyValue);
					}
					else {
						ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue));
					}
					EMH_clear_errors();
					if (ifail == 0) {
						tempValue = propertyValue;
					}
					else {
						showError = true;
						WriteLog("属性异常：%s\n", propertyName.c_str());
						tempValue = " ";
					}
					DOFREE(propertyValue);
				}
				else if (strcmp("key", propertyName.c_str()) == 0){
					tempValue = getGuid();
				}
				else {
					tempValue = " ";
				}
			}
			childColumnStr = childColumnStr.append(columnName);
			if (j < childNameVec.size() - 1) {
				childColumnStr = childColumnStr.append(",");
			}
			childValueStr = childValueStr.append("'").append(tempValue);
			if (j < childNameVec.size() - 1) {
				childValueStr = childValueStr.append("',");
			}
			else {
				childValueStr = childValueStr.append("'");
			}
		}
		if (isContinue) {
			continue;
		}
		string insertSql = "";
		string selectSql = "";
		string updateSelectSql = "";
		string updateSql = "";
		if (childColumnStr.size() > 0) {
			insertSql = insertSql.append(parentColumnStr).append(",").append(childColumnStr).append(")").append(parentValueStr).append(",").append(childValueStr).append(")");
		}
		else {
			insertSql = insertSql.append(parentColumnStr).append(")").append(parentValueStr).append(")");
		}
		selectSql = selectSql.append(selectStr).append(childSelectStr);
		updateSelectSql = updateSelectSql.append(selectAfterUpdateStr).append(childUpdateSelectStr);
		updateSql = updateSql.append(updateStr).append(updateWhere).append(childUpdateWhere);
		//updateStr = updateStr.append(updateWhere);

		insertSql = Utf8ToGbk(insertSql.c_str());
		updateSql = Utf8ToGbk(updateSql.c_str());
		selectSql = Utf8ToGbk(selectSql.c_str());
		updateSelectSql = Utf8ToGbk(updateSelectSql.c_str());
		WriteLog("工序属性插入语句：%s\n", insertSql.c_str());
		WriteLog("工序属性更新语句：%s\n", updateSql.c_str());
		WriteLog("工序属性查询语句：%s\n", selectSql.c_str());
		WriteLog("工序属性更新后查询语句：%s\n", updateSelectSql.c_str());
		insertVec.push_back(insertSql);
		updateVec.push_back(updateSql);
		selectVec.push_back(selectSql);
		selectAfterUpdateVec.push_back(updateSelectSql);
		char sendChar[400] = "";
		strcpy(sendChar, insertSql.c_str());
		char sendChar2[400] = "";
		strcpy(sendChar2, selectSql.c_str());
		int result = ado0.ado_QuerySQLNoInputParam(sendChar2);
		bool resultSql = ado0.executeInsert(sendChar2, sendChar, result);
	}
	DOFREE(type);

	//更新数据库
	/*for (int i = 0; i < updateVec.size(); i++) {
		string updateSql = updateVec[i];
		string selectSql = selectVec[i];
		string insertSql = insertVec[i];
		string selectUpdate = selectAfterUpdateVec[i];
		char sendChar[200] = "";
		char sendChar2[200] = "";
		char sendChar3[200] = "";
		strcpy(sendChar, updateSql.c_str());
		strcpy(sendChar2, selectSql.c_str());
		strcpy(sendChar3, selectUpdate.c_str());
		int result = ado0.ado_QuerySQLNoInputParam(sendChar2);
		if (result == 0) {
			showError = true;
			WriteLog("工序属性插入失败：%s\n", insertSql.c_str());
		}
		else {
			bool resultSql = ado0.execute2(sendChar2, sendChar, result);
			result = ado0.ado_QuerySQLNoInputParam(sendChar3);
			if (result == 0) {
				showError = true;
				WriteLog("工序属性更新失败：%s\n", updateSql.c_str());
			}
		}
	}*/
}

// 工序工艺文件
void insertGyGxGywj(string xmlUid, bool& showError, ado ado0, tag_t gy_line, tag_t gy_item, tag_t gy_rev, map<string, CHILD> child_level1, map<string, vector<string>> level1_level2, map<string, CHILD> child_level2) {
	WriteLog("记录工序工艺文件数据库\n");
	int ifail = 0;
	char* type = NULL;
	//
	string sqlStr = "insert into ";
	string updateStr = "update ";
	string selectStr = "select * from  ";
	string selectAfterUpdateStr = "select * from  ";
	string updateWhere = "";
	// 解析xml文件
	// 创建一个XML结构并载入文件内容
	map<string, map<vector<string>, vector<string>>> xmlMap;//物料类型，<字段名，属性取值>
	string tableName = loadXml(xmlUid, xmlMap);

	map<vector<string>, vector<string>> parentPropertyMap = xmlMap["父"];//父级
	vector<string> parentNameVec;
	vector<string> parentValueVec;
	map<vector<string>, vector<string>>::iterator rev_it2;
	for (rev_it2 = parentPropertyMap.begin(); rev_it2 != parentPropertyMap.end(); rev_it2++) {
		parentNameVec = rev_it2->first;
		parentValueVec = rev_it2->second;
	}
	map<vector<string>, vector<string>> childPropertyMap = xmlMap["子"];//子级
	vector<string> childNameVec;
	vector<string> childValueVec;
	map<vector<string>, vector<string>>::iterator rev_it;
	for (rev_it = childPropertyMap.begin(); rev_it != childPropertyMap.end(); rev_it++) {
		childNameVec = rev_it->first;
		childValueVec = rev_it->second;
	}
	map<vector<string>, vector<string>> childLevel2PropertyMap = xmlMap["孙"];//子级的子级
	vector<string> childLevel2NameVec;
	vector<string> childLevel2ValueVec;
	map<vector<string>, vector<string>>::iterator rev_it_level2;
	for (rev_it_level2 = childLevel2PropertyMap.begin(); rev_it_level2 != childLevel2PropertyMap.end(); rev_it_level2++) {
		childLevel2NameVec = rev_it_level2->first;
		childLevel2ValueVec = rev_it_level2->second;
	}
	vector<string> updateVec;
	vector<string> selectVec;
	vector<string> insertVec;
	vector<string> selectAfterUpdateVec;

	sqlStr = sqlStr.append(tableName).append("(");
	selectStr = selectStr.append(tableName).append(" ");
	selectAfterUpdateStr = selectAfterUpdateStr.append(tableName).append(" ");
	string valueStr = " VALUES (";

	//获取父属性
	string parentColumnStr = "insert into ";
	parentColumnStr = parentColumnStr.append(tableName).append(" (");
	string parentValueStr = " values(";
	for (int j = 0; j < parentNameVec.size(); j++)
	{
		string columnName = parentNameVec[j];
		parentColumnStr = parentColumnStr.append(columnName);
		if (j < parentNameVec.size() - 1) {
			parentColumnStr = parentColumnStr.append(",");
		}
		string propertyName = parentValueVec[j];
		string tempValue = " ";
		string updateValue = "";
		if (strcmp(columnName.c_str(), "SESSIONID") == 0) {
			tempValue = propertyName;//固定值
		}
		else if (strcmp(columnName.c_str(), "TRANSNO") == 0) {
			tempValue = propertyName;//已处理
			if (updateWhere.length() == 0) {
				updateWhere = updateWhere.append(" where ");
				updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and ");
				selectStr = selectStr.append(" where ");
				selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(" where ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
			}
			else {
				updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and ");
				selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
			}
		}
		else if (strcmp(columnName.c_str(), "TRANSSTATUS") == 0) {
			//首次传递空值

			updateValue = propertyName;
			updateStr = updateStr.append(tableName).append(" set ").append(columnName).append("='").append(updateValue).append("'  ");
			selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(updateValue).append("' and ");
		}
		else if (strcmp(columnName.c_str(), "PPUID") == 0) {
			char* puid = NULL;
			ITK__convert_tag_to_uid(gy_rev, &puid);
			tempValue = puid;
			//selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
			if (updateWhere.length() == 0) {
				updateWhere = updateWhere.append(" where ");
				updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and ");
				selectStr = selectStr.append(" where ");
				selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(" where ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
			}
			else {
				updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and ");
				selectStr = selectStr.append(columnName).append("='").append(puid).append("' and ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(puid).append("' and ");
			}
			DOFREE(puid);
		}
		else {
			vector<string> propertyVec;
			Split(propertyName, ".", propertyVec);
			if (propertyVec.size() == 2) {
				string propertyPosition = propertyVec[0];
				tag_t propertyTag = NULL;
				if (strcmp("item", propertyPosition.c_str()) == 0) {
					propertyTag = gy_item;
				}
				else if (strcmp("rev", propertyPosition.c_str()) == 0) {
					propertyTag = gy_rev;
				}
				else if (strcmp("bomline", propertyPosition.c_str()) == 0) {
					propertyTag = gy_line;
				}
				string propertyName = propertyVec[1];
				char* propertyValue = NULL;
				if (strcmp("puid", propertyName.c_str()) == 0) {
					ITK__convert_tag_to_uid(propertyTag, &propertyValue);
				}
				else {
					ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue));
				}
				EMH_clear_errors();
				if (ifail == 0) {
					tempValue = propertyValue;
				}
				else {
					showError = true;
					WriteLog("属性异常：%s\n", propertyName.c_str());
					tempValue = " ";
				}
				DOFREE(propertyValue);
			}
		}
		parentValueStr = parentValueStr.append("'").append(tempValue).append("'");
		if (j < parentNameVec.size() - 1) {
			parentValueStr = parentValueStr.append(",");
		}
	}

	// 获取子对象的属性
	map<string, CHILD>::iterator child_it;
	for (child_it = child_level1.begin(); child_it != child_level1.end(); child_it++) {
		bool isContinue = false;
		string childColumnStr = "";
		string childSelectStr = "";
		string childUpdateSelectStr = "";
		string childUpdateWhere = "";
		string childValueStr = "";
		tag_t line = child_it->second.line;
		tag_t item = child_it->second.item;
		tag_t rev = child_it->second.rev;
		string clone_id = child_it->second.clone_id;
		vector<string> level2_vec = level1_level2[clone_id];
		int level2_cnt = level2_vec.size();
		ITKCALL(ifail = AOM_ask_value_string(rev, "object_type", &type));
		for (int j = 0; j < childNameVec.size(); j++)
		{
			string columnName = childNameVec[j];
			string propertyName = childValueVec[j];
			string tempValue = " ";
			if (strcmp(columnName.c_str(), "_FILTERTYPE") == 0) {
				if (strcmp(propertyName.c_str(), "ALL") == 0) {
					continue;
				}
				else {
					vector<string>typeVec;
					Split(propertyName, ";", typeVec);
					if (hasElement(typeVec, type) == 0) {
						continue;
					}
					else {
						isContinue = true;
						break;
					}
				}
			}
			else if (strcmp(columnName.c_str(), "CPUID") == 0) {
				char* puid = NULL;
				ITK__convert_tag_to_uid(rev, &puid);
				tempValue = puid;

				childSelectStr = childSelectStr.append(columnName).append("='").append(tempValue).append("' and ");
				childUpdateSelectStr = childUpdateSelectStr.append(columnName).append("='").append(tempValue).append("' and ");
				childUpdateWhere = childUpdateWhere.append(columnName).append("='").append(tempValue).append("' and ");
				DOFREE(puid);
			}
			else {
				vector<string> propertyVec;
				Split(propertyName, ".", propertyVec);
				if (propertyVec.size() == 2) {
					string propertyPosition = propertyVec[0];
					tag_t propertyTag = NULL;
					if (strcmp("item", propertyPosition.c_str()) == 0) {
						propertyTag = item;
					}
					else if (strcmp("rev", propertyPosition.c_str()) == 0) {
						propertyTag = rev;
					}
					else if (strcmp("bomline", propertyPosition.c_str()) == 0) {
						propertyTag = line;
					}
					string propertyName = propertyVec[1];
					char* propertyValue = NULL;
					if (strcmp("puid", propertyName.c_str()) == 0) {
						ITK__convert_tag_to_uid(propertyTag, &propertyValue);
					}
					else {
						ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue));
					}
					EMH_clear_errors();
					if (ifail == 0) {
						tempValue = propertyValue;
					}
					else {
						showError = true;
						WriteLog("属性异常：%s\n", propertyName.c_str());
						tempValue = " ";
					}
					DOFREE(propertyValue);
				}
				else {
					tempValue = " ";
				}
			}
			childColumnStr = childColumnStr.append(columnName);
			if (j < childNameVec.size() - 1) {
				childColumnStr = childColumnStr.append(",");
			}
			childValueStr = childValueStr.append("'").append(tempValue);
			if (j < childNameVec.size() - 1) {
				childValueStr = childValueStr.append("',");
			}
			else {
				childValueStr = childValueStr.append("'");
			}
		}
		if (isContinue) {
			continue;
		}
		if (level2_cnt > 0) {
			char* zy_type = NULL;
			for (int k = 0; k < level2_cnt; k++) {
				bool isZyContinue = false;
				CHILD level2_child = child_level2[level2_vec[k]];
				string childLevel2ColumnStr = "";
				string childLevel2SelectStr = "";
				string childLevel2UpdateSelectStr = "";
				string childLevel2UpdateWhere = "";
				string childLevel2ValueStr = "";
				tag_t zy_line = level2_child.line;
				tag_t zy_item = level2_child.item;
				tag_t zy_rev = level2_child.rev;
				string zy_clone_id = level2_child.clone_id;
				ITKCALL(ifail = AOM_ask_value_string(zy_rev, "object_type", &zy_type));
				for (int z = 0; z < childLevel2NameVec.size(); z++)
				{
					string columnName = childLevel2NameVec[z];
					string propertyName = childLevel2ValueVec[z];
					string tempValue = " ";
					if (strcmp(columnName.c_str(), "_FILTERTYPE") == 0) {
						if (strcmp(propertyName.c_str(), "ALL") == 0) {
							continue;
						}
						else {
							vector<string>typeVec;
							Split(propertyName, ";", typeVec);
							if (hasElement(typeVec, zy_type) == 0) {
								continue;
							}
							else {
								isZyContinue = true;
								break;
							}
						}
					}
					else if (strcmp(columnName.c_str(), "SPUID") == 0) {
						char* spuid = NULL;
						ITK__convert_tag_to_uid(zy_rev, &spuid);
						tempValue = spuid;

						childLevel2SelectStr = childLevel2SelectStr.append(columnName).append("='").append(tempValue).append("'  ");
						childLevel2UpdateSelectStr = childLevel2UpdateSelectStr.append(columnName).append("='").append(tempValue).append("'  ");
						childLevel2UpdateWhere = childLevel2UpdateWhere.append(columnName).append("='").append(tempValue).append("'");
						DOFREE(spuid);
					}
					else {
						vector<string> propertyVec;
						Split(propertyName, ".", propertyVec);
						if (propertyVec.size() == 2) {
							string propertyPosition = propertyVec[0];
							tag_t propertyTag = NULL;
							if (strcmp("item", propertyPosition.c_str()) == 0) {
								propertyTag = zy_item;
							}
							else if (strcmp("rev", propertyPosition.c_str()) == 0) {
								propertyTag = zy_rev;
							}
							else if (strcmp("bomline", propertyPosition.c_str()) == 0) {
								propertyTag = zy_line;
							}
							string propertyName = propertyVec[1];
							char* propertyValue = NULL;
							if (strcmp("puid", propertyName.c_str()) == 0) {
								ITK__convert_tag_to_uid(propertyTag, &propertyValue);
							}
							else {
								ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue));
							}
							EMH_clear_errors();
							if (ifail == 0) {
								tempValue = propertyValue;
							}
							else {
								showError = true;
								WriteLog("属性异常：%s\n", propertyName.c_str());
								tempValue = " ";
							}
							DOFREE(propertyValue);
						}
						else {
							tempValue = " ";
						}
					}
					childLevel2ColumnStr = childLevel2ColumnStr.append(columnName);
					if (z < childLevel2NameVec.size() - 1) {
						childLevel2ColumnStr = childLevel2ColumnStr.append(",");
					}
					childLevel2ValueStr = childLevel2ValueStr.append("'").append(tempValue);
					if (z < childLevel2NameVec.size() - 1) {
						childLevel2ValueStr = childLevel2ValueStr.append("',");
					}
					else {
						childLevel2ValueStr = childLevel2ValueStr.append("'");
					}
				}
				if (isZyContinue) {
					continue;
				}

				string insertSql = "";
				string selectSql = "";
				string updateSelectSql = "";
				string updateSql = "";

				if (parentColumnStr.size() > 0 && childColumnStr.size() > 0 && childLevel2ColumnStr.size() > 0) {
					insertSql = insertSql.append(parentColumnStr).append(",").append(childColumnStr).append(",").append(childLevel2ColumnStr).append(")").append(parentValueStr).append(",").append(childValueStr).append(",").append(childLevel2ValueStr).append(")");
				}
				selectSql = selectSql.append(selectStr).append(childSelectStr).append(childLevel2SelectStr);
				updateSelectSql = updateSelectSql.append(selectAfterUpdateStr).append(childUpdateSelectStr).append(childLevel2UpdateSelectStr);
				updateSql = updateSql.append(updateStr).append(updateWhere).append(childUpdateWhere).append(childLevel2UpdateWhere);
				//updateStr = updateStr.append(updateWhere);

				insertSql = Utf8ToGbk(insertSql.c_str());
				updateSql = Utf8ToGbk(updateSql.c_str());
				selectSql = Utf8ToGbk(selectSql.c_str());
				updateSelectSql = Utf8ToGbk(updateSelectSql.c_str());
				WriteLog("工艺文件插入语句：%s\n", insertSql.c_str());
				WriteLog("工艺文件更新语句：%s\n", updateSql.c_str());
				WriteLog("工艺文件查询语句：%s\n", selectSql.c_str());
				WriteLog("工艺文件更新后查询语句：%s\n", updateSelectSql.c_str());
				insertVec.push_back(insertSql);
				updateVec.push_back(updateSql);
				selectVec.push_back(selectSql);
				selectAfterUpdateVec.push_back(updateSelectSql);
				char sendChar[400] = "";
				strcpy(sendChar, insertSql.c_str());
				char sendChar2[400] = "";
				strcpy(sendChar2, selectSql.c_str());
				int result = ado0.ado_QuerySQLNoInputParam(sendChar2);
				bool resultSql = ado0.executeInsert(sendChar2, sendChar, result);
			}
			DOFREE(zy_type);
		}
	}
	DOFREE(type);

	//更新数据库
	/*for (int i = 0; i < updateVec.size(); i++) {
		string updateSql = updateVec[i];
		string selectSql = selectVec[i];
		string insertSql = insertVec[i];
		string selectUpdate = selectAfterUpdateVec[i];
		char sendChar[400] = "";
		char sendChar2[400] = "";
		char sendChar3[400] = "";
		strcpy(sendChar, updateSql.c_str());
		strcpy(sendChar2, selectSql.c_str());
		strcpy(sendChar3, selectUpdate.c_str());
		int result = ado0.ado_QuerySQLNoInputParam(sendChar2);
		if (result == 0) {
			showError = true;
			WriteLog("工艺文件插入失败：%s\n", insertSql.c_str());
		}
		else {
			bool resultSql = ado0.execute2(sendChar2, sendChar, result);
			result = ado0.ado_QuerySQLNoInputParam(sendChar3);
			if (result == 0) {
				showError = true;
				WriteLog("工艺文件更新失败：%s\n", updateSql.c_str());
			}
		}
	}*/
}

// 工艺资源
void insertGyGxGyzy(string xmlUid, bool& showError, ado ado0, tag_t gy_line, tag_t gy_item, tag_t gy_rev, map<string, CHILD> child_level1, map<string, vector<string>> level1_level2, map<string, CHILD> child_level2) {
	WriteLog("记录工艺资源数据库\n");
	int ifail = 0;
	char* type = NULL;
	//
	string sqlStr = "insert into ";
	string updateStr = "update ";
	string selectStr = "select * from  ";
	string selectAfterUpdateStr = "select * from  ";
	string updateWhere = "";
	// 解析xml文件
	// 创建一个XML结构并载入文件内容
	map<string, map<vector<string>, vector<string>>> xmlMap;//物料类型，<字段名，属性取值>
	string tableName = loadXml(xmlUid, xmlMap);

	map<vector<string>, vector<string>> parentPropertyMap = xmlMap["父"];//父级
	vector<string> parentNameVec;
	vector<string> parentValueVec;
	map<vector<string>, vector<string>>::iterator rev_it2;
	for (rev_it2 = parentPropertyMap.begin(); rev_it2 != parentPropertyMap.end(); rev_it2++) {
		parentNameVec = rev_it2->first;
		parentValueVec = rev_it2->second;
	}
	map<vector<string>, vector<string>> childPropertyMap = xmlMap["子"];//子级
	vector<string> childNameVec;
	vector<string> childValueVec;
	map<vector<string>, vector<string>>::iterator rev_it;
	for (rev_it = childPropertyMap.begin(); rev_it != childPropertyMap.end(); rev_it++) {
		childNameVec = rev_it->first;
		childValueVec = rev_it->second;
	}
	map<vector<string>, vector<string>> childLevel2PropertyMap = xmlMap["孙"];//子级的子级
	vector<string> childLevel2NameVec;
	vector<string> childLevel2ValueVec;
	map<vector<string>, vector<string>>::iterator rev_it_level2;
	for (rev_it_level2 = childLevel2PropertyMap.begin(); rev_it_level2 != childLevel2PropertyMap.end(); rev_it_level2++) {
		childLevel2NameVec = rev_it_level2->first;
		childLevel2ValueVec = rev_it_level2->second;
	}
	vector<string> updateVec;
	vector<string> selectVec;
	vector<string> insertVec;
	vector<string> selectAfterUpdateVec;

	sqlStr = sqlStr.append(tableName).append("(");
	selectStr = selectStr.append(tableName).append(" ");
	selectAfterUpdateStr = selectAfterUpdateStr.append(tableName).append(" ");
	string valueStr = " VALUES (";

	//获取父属性
	string parentColumnStr = "insert into ";
	parentColumnStr = parentColumnStr.append(tableName).append(" (");
	string parentValueStr = " values(";
	for (int j = 0; j < parentNameVec.size(); j++)
	{
		string columnName = parentNameVec[j];
		parentColumnStr = parentColumnStr.append(columnName);
		if (j < parentNameVec.size() - 1) {
			parentColumnStr = parentColumnStr.append(",");
		}
		string propertyName = parentValueVec[j];
		string tempValue = " ";
		string updateValue = "";
		if (strcmp(columnName.c_str(), "SESSIONID") == 0) {
			tempValue = propertyName;//固定值
		}
		else if (strcmp(columnName.c_str(), "TRANSNO") == 0) {
			tempValue = propertyName;//已处理
			if (updateWhere.length() == 0) {
				updateWhere = updateWhere.append(" where ");
				updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and ");
				selectStr = selectStr.append(" where ");
				selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(" where ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
			}
			else {
				updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and ");
				selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
			}
		}
		else if (strcmp(columnName.c_str(), "TRANSSTATUS") == 0) {
			//首次传递空值

			updateValue = propertyName;
			updateStr = updateStr.append(tableName).append(" set ").append(columnName).append("='").append(updateValue).append("'  ");
			selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(updateValue).append("' and ");
		}
		else if (strcmp(columnName.c_str(), "PPUID") == 0) {
			char* puid = NULL;
			ITK__convert_tag_to_uid(gy_rev, &puid);
			tempValue = puid;
			//selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
			if (updateWhere.length() == 0) {
				updateWhere = updateWhere.append(" where ");
				updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and ");
				selectStr = selectStr.append(" where ");
				selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(" where ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
			}
			else {
				updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and ");
				selectStr = selectStr.append(columnName).append("='").append(puid).append("' and ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(puid).append("' and ");
			}
			DOFREE(puid);
		}
		else {
			vector<string> propertyVec;
			Split(propertyName, ".", propertyVec);
			if (propertyVec.size() == 2) {
				string propertyPosition = propertyVec[0];
				tag_t propertyTag = NULL;
				if (strcmp("item", propertyPosition.c_str()) == 0) {
					propertyTag = gy_item;
				}
				else if (strcmp("rev", propertyPosition.c_str()) == 0) {
					propertyTag = gy_rev;
				}
				else if (strcmp("bomline", propertyPosition.c_str()) == 0) {
					propertyTag = gy_line;
				}
				string propertyName = propertyVec[1];
				char* propertyValue = NULL;
				if (strcmp("puid", propertyName.c_str()) == 0) {
					ITK__convert_tag_to_uid(propertyTag, &propertyValue);
				}
				else {
					ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue));
				}
				EMH_clear_errors();
				if (ifail == 0) {
					tempValue = propertyValue;
				}
				else {
					showError = true;
					WriteLog("属性异常：%s\n", propertyName.c_str());
					tempValue = " ";
				}
				DOFREE(propertyValue);
			}
		}
		parentValueStr = parentValueStr.append("'").append(tempValue).append("'");
		if (j < parentNameVec.size() - 1) {
			parentValueStr = parentValueStr.append(",");
		}
	}

	// 获取子对象的属性
	map<string, CHILD>::iterator child_it;
	for (child_it = child_level1.begin(); child_it != child_level1.end(); child_it++) {
		bool isContinue = false;
		string childColumnStr = "";
		string childSelectStr = "";
		string childUpdateSelectStr = "";
		string childUpdateWhere = "";
		string childValueStr = "";
		tag_t line = child_it->second.line;
		tag_t item = child_it->second.item;
		tag_t rev = child_it->second.rev;
		string clone_id = child_it->second.clone_id;
		vector<string> level2_vec = level1_level2[clone_id];
		int level2_cnt = level2_vec.size();
		ITKCALL(ifail = AOM_ask_value_string(rev, "object_type", &type));
		for (int j = 0; j < childNameVec.size(); j++)
		{
			string columnName = childNameVec[j];
			string propertyName = childValueVec[j];
			string tempValue = " ";
			if (strcmp(columnName.c_str(), "_FILTERTYPE") == 0) {
				if (strcmp(propertyName.c_str(), "ALL") == 0) {
					continue;
				}
				else {
					vector<string>typeVec;
					Split(propertyName, ";", typeVec);
					if (hasElement(typeVec, type) == 0) {
						continue;
					}
					else {
						isContinue = true;
						break;
					}
				}
			}
			else if (strcmp(columnName.c_str(), "CPUID") == 0) {
				char* puid = NULL;
				ITK__convert_tag_to_uid(rev, &puid);
				tempValue = puid;

				childSelectStr = childSelectStr.append(columnName).append("='").append(tempValue).append("' and ");
				childUpdateSelectStr = childUpdateSelectStr.append(columnName).append("='").append(tempValue).append("' and ");
				childUpdateWhere = childUpdateWhere.append(columnName).append("='").append(tempValue).append("' and ");
				DOFREE(puid);
			}
			else {
				vector<string> propertyVec;
				Split(propertyName, ".", propertyVec);
				if (propertyVec.size() == 2) {
					string propertyPosition = propertyVec[0];
					tag_t propertyTag = NULL;
					if (strcmp("item", propertyPosition.c_str()) == 0) {
						propertyTag = item;
					}
					else if (strcmp("rev", propertyPosition.c_str()) == 0) {
						propertyTag = rev;
					}
					else if (strcmp("bomline", propertyPosition.c_str()) == 0) {
						propertyTag = line;
					}
					string propertyName = propertyVec[1];
					char* propertyValue = NULL;
					if (strcmp("puid", propertyName.c_str()) == 0) {
						ITK__convert_tag_to_uid(propertyTag, &propertyValue);
					}
					else {
						ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue));
					}
					EMH_clear_errors();
					if (ifail == 0) {
						tempValue = propertyValue;
					}
					else {
						showError = true;
						WriteLog("属性异常：%s\n", propertyName.c_str());
						tempValue = " ";
					}
					DOFREE(propertyValue);
				}
				else {
					tempValue = " ";
				}
			}
			childColumnStr = childColumnStr.append(columnName);
			if (j < childNameVec.size() - 1) {
				childColumnStr = childColumnStr.append(",");
			}
			childValueStr = childValueStr.append("'").append(tempValue);
			if (j < childNameVec.size() - 1) {
				childValueStr = childValueStr.append("',");
			}
			else {
				childValueStr = childValueStr.append("'");
			}
		}
		if (isContinue) {
			continue;
		}
		if (level2_cnt > 0) {
			char* zy_type = NULL;
			for (int k = 0; k < level2_cnt; k++) {
				bool isZyContinue = false;
				CHILD level2_child = child_level2[level2_vec[k]];
				string childLevel2ColumnStr = "";
				string childLevel2SelectStr = "";
				string childLevel2UpdateSelectStr = "";
				string childLevel2UpdateWhere = "";
				string childLevel2ValueStr = "";
				tag_t zy_line = level2_child.line;
				tag_t zy_item = level2_child.item;
				tag_t zy_rev = level2_child.rev;
				string zy_clone_id = level2_child.clone_id;
				ITKCALL(ifail = AOM_ask_value_string(zy_rev, "object_type", &zy_type));
				for (int z = 0; z < childLevel2NameVec.size(); z++)
				{
					string columnName = childLevel2NameVec[z];
					string propertyName = childLevel2ValueVec[z];
					string tempValue = " ";
					if (strcmp(columnName.c_str(), "_FILTERTYPE") == 0) {
						if (strcmp(propertyName.c_str(), "ALL") == 0) {
							continue;
						}
						else {
							vector<string>typeVec;
							Split(propertyName, ";", typeVec);
							if (hasElement(typeVec, zy_type) == 0) {
								continue;
							}
							else {
								isZyContinue = true;
								break;
							}
						}
					}
					else if (strcmp(columnName.c_str(), "SPUID") == 0) {
						char* spuid = NULL;
						ITK__convert_tag_to_uid(rev, &spuid);
						tempValue = spuid;

						childLevel2SelectStr = childLevel2SelectStr.append(columnName).append("='").append(tempValue).append("'  ");
						childLevel2UpdateSelectStr = childLevel2UpdateSelectStr.append(columnName).append("='").append(tempValue).append("'  ");
						childLevel2UpdateWhere = childLevel2UpdateWhere.append(columnName).append("='").append(tempValue).append("'");
						DOFREE(spuid);
					}
					else {
						vector<string> propertyVec;
						Split(propertyName, ".", propertyVec);
						if (propertyVec.size() == 2) {
							string propertyPosition = propertyVec[0];
							tag_t propertyTag = NULL;
							if (strcmp("item", propertyPosition.c_str()) == 0) {
								propertyTag = zy_item;
							}
							else if (strcmp("rev", propertyPosition.c_str()) == 0) {
								propertyTag = zy_rev;
							}
							else if (strcmp("bomline", propertyPosition.c_str()) == 0) {
								propertyTag = zy_line;
							}
							string propertyName = propertyVec[1];
							char* propertyValue = NULL;
							if (strcmp("puid", propertyName.c_str()) == 0) {
								ITK__convert_tag_to_uid(propertyTag, &propertyValue);
							}
							else {
								ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue));
							}
							EMH_clear_errors();
							if (ifail == 0) {
								tempValue = propertyValue;
							}
							else {
								showError = true;
								WriteLog("属性异常：%s\n", propertyName.c_str());
								tempValue = " ";
							}
							DOFREE(propertyValue);
						}
						else {
							tempValue = " ";
						}
					}
					childLevel2ColumnStr = childLevel2ColumnStr.append(columnName);
					if (z < childLevel2NameVec.size() - 1) {
						childLevel2ColumnStr = childLevel2ColumnStr.append(",");
					}
					childLevel2ValueStr = childLevel2ValueStr.append("'").append(tempValue);
					if (z < childLevel2NameVec.size() - 1) {
						childLevel2ValueStr = childLevel2ValueStr.append("',");
					}
					else {
						childLevel2ValueStr = childLevel2ValueStr.append("'");
					}
				}
				if (isZyContinue) {
					continue;
				}

				string insertSql = "";
				string selectSql = "";
				string updateSelectSql = "";
				string updateSql = "";

				if (parentColumnStr.size() > 0 && childColumnStr.size() > 0 && childLevel2ColumnStr.size() > 0) {
					insertSql = insertSql.append(parentColumnStr).append(",").append(childColumnStr).append(",").append(childLevel2ColumnStr).append(")").append(parentValueStr).append(",").append(childValueStr).append(",").append(childLevel2ValueStr).append(")");
				}
				selectSql = selectSql.append(selectStr).append(childSelectStr).append(childLevel2SelectStr);
				updateSelectSql = updateSelectSql.append(selectAfterUpdateStr).append(childUpdateSelectStr).append(childLevel2UpdateSelectStr);
				updateSql = updateSql.append(updateStr).append(updateWhere).append(childUpdateWhere).append(childLevel2UpdateWhere);
				//updateStr = updateStr.append(updateWhere);

				insertSql = Utf8ToGbk(insertSql.c_str());
				updateSql = Utf8ToGbk(updateSql.c_str());
				selectSql = Utf8ToGbk(selectSql.c_str());
				updateSelectSql = Utf8ToGbk(updateSelectSql.c_str());
				WriteLog("插入语句：%s\n", insertSql.c_str());
				WriteLog("更新语句：%s\n", updateSql.c_str());
				WriteLog("查询语句：%s\n", selectSql.c_str());
				WriteLog("更新后查询语句：%s\n", updateSelectSql.c_str());
				insertVec.push_back(insertSql);
				updateVec.push_back(updateSql);
				selectVec.push_back(selectSql);
				selectAfterUpdateVec.push_back(updateSelectSql);
				char sendChar[400] = "";
				strcpy(sendChar, insertSql.c_str());
				char sendChar2[400] = "";
				strcpy(sendChar2, selectSql.c_str());
				int result = ado0.ado_QuerySQLNoInputParam(sendChar2);
				bool resultSql = ado0.executeInsert(sendChar2, sendChar, result);
			}
			DOFREE(zy_type);
		}
	}
	DOFREE(type);

	//更新数据库
	/*for (int i = 0; i < updateVec.size(); i++) {
		string updateSql = updateVec[i];
		string selectSql = selectVec[i];
		string insertSql = insertVec[i];
		string selectUpdate = selectAfterUpdateVec[i];
		char sendChar[400] = "";
		char sendChar2[400] = "";
		char sendChar3[400] = "";
		strcpy(sendChar, updateSql.c_str());
		strcpy(sendChar2, selectSql.c_str());
		strcpy(sendChar3, selectUpdate.c_str());
		int result = ado0.ado_QuerySQLNoInputParam(sendChar2);
		if (result == 0) {
			showError = true;
			WriteLog("插入失败：%s\n", insertSql.c_str());
		}
		else {
			bool resultSql = ado0.execute2(sendChar2, sendChar, result);
			result = ado0.ado_QuerySQLNoInputParam(sendChar3);
			if (result == 0) {
				showError = true;
				WriteLog("更新失败：%s\n", updateSql.c_str());
			}
		}
	}*/
}

// 工步资源 
void insertGbzy(string xmlUid, bool& showError, ado ado0, map<string, CHILD> child_level1, map<string, string> gx_gb_key, map<string, vector<CHILD>> gx_gbs_bom, map<string, vector<CHILD>> gx_gb_zy) {
	WriteLog("记录工步资源数据库\n");
	int ifail = 0;
	vector<string> updateVec;
	vector<string> selectVec;
	vector<string> insertVec;
	vector<string> selectAfterUpdateVec;
	// 解析xml文件
	// 创建一个XML结构并载入文件内容
	map<string, map<vector<string>, vector<string>>> xmlMap;//物料类型，<字段名，属性取值>
	string tableName = loadXml(xmlUid, xmlMap);

	map<vector<string>, vector<string>> parentPropertyMap = xmlMap["父"];//父级
	vector<string> parentNameVec;
	vector<string> parentValueVec;
	map<vector<string>, vector<string>>::iterator rev_it2;
	for (rev_it2 = parentPropertyMap.begin(); rev_it2 != parentPropertyMap.end(); rev_it2++) {
		parentNameVec = rev_it2->first;
		parentValueVec = rev_it2->second;
	}
	map<vector<string>, vector<string>> childPropertyMap = xmlMap["子"];//子级
	vector<string> childNameVec;
	vector<string> childValueVec;
	map<vector<string>, vector<string>>::iterator rev_it;
	for (rev_it = childPropertyMap.begin(); rev_it != childPropertyMap.end(); rev_it++) {
		childNameVec = rev_it->first;
		childValueVec = rev_it->second;
	}

	map<string, CHILD>::iterator child_it;
	for (child_it = child_level1.begin(); child_it != child_level1.end(); child_it++) {
		char* gb_type = NULL;
		string gx_clone_id = child_it->first;
		vector<CHILD> gbs = gx_gbs_bom[gx_clone_id];
		int gb_count = gbs.size();
		if (gb_count > 0) {
			for (int x = 0; x < gb_count; x++) {
				bool isGbContinue = false;
				tag_t gb_line = gbs[x].line;
				tag_t gb_item = gbs[x].item;

				char* zy_type = NULL;
				string sqlStr = "insert into ";
				string updateStr = "update ";
				string selectStr = "select * from  ";
				string selectAfterUpdateStr = "select * from  ";
				string updateWhere = "";
				string gb_puid = "";

				ITKCALL(ifail = AOM_ask_value_string(gb_item, "object_type", &gb_type));
				sqlStr = sqlStr.append(tableName).append("(");
				selectStr = selectStr.append(tableName).append(" ");
				selectAfterUpdateStr = selectAfterUpdateStr.append(tableName).append(" ");
				string valueStr = " VALUES (";

				//获取父属性
				string parentColumnStr = "insert into ";
				parentColumnStr = parentColumnStr.append(tableName).append(" (");
				string parentValueStr = " values(";
				for (int j = 0; j < parentNameVec.size(); j++)
				{
					string columnName = parentNameVec[j];
					parentColumnStr = parentColumnStr.append(columnName);
					if (j < parentNameVec.size() - 1) {
						parentColumnStr = parentColumnStr.append(",");
					}
					string propertyName = parentValueVec[j];
					string tempValue = " ";
					string updateValue = "";
					if (strcmp(columnName.c_str(), "_FILTERTYPE") == 0) {
						if (strcmp(propertyName.c_str(), "ALL") == 0) {
							continue;
						}
						else {
							vector<string>typeVec;
							Split(propertyName, ";", typeVec);
							if (hasElement(typeVec, gb_type) == 0) {
								continue;
							}
							else {
								isGbContinue = true;
								break;
							}
						}
					}
					else if (strcmp(columnName.c_str(), "SESSIONID") == 0) {
						tempValue = propertyName;//固定值
					}
					else if (strcmp(columnName.c_str(), "TRANSNO") == 0) {
						tempValue = propertyName;//已处理
						if (updateWhere.length() == 0) {
							updateWhere = updateWhere.append(" where ");
							updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and ");
							selectStr = selectStr.append(" where ");
							selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
							selectAfterUpdateStr = selectAfterUpdateStr.append(" where ");
							selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
						}
						else {
							updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and ");
							selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
							selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
						}
					}
					else if (strcmp(columnName.c_str(), "TRANSSTATUS") == 0) {
						//首次传递空值
						updateValue = propertyName;
						updateStr = updateStr.append(tableName).append(" set ").append(columnName).append("='").append(updateValue).append("'  ");
						selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(updateValue).append("' and ");
					}
					else if (strcmp(columnName.c_str(), "PPUID") == 0) {
						char* puid = NULL;
						ITK__convert_tag_to_uid(gb_item, &puid);
						gb_puid = string(puid);
						tempValue = puid;
						//selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
						if (updateWhere.length() == 0) {
							updateWhere = updateWhere.append(" where ");
							updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and ");
							selectStr = selectStr.append(" where ");
							selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and ");
							selectAfterUpdateStr = selectAfterUpdateStr.append(" where ");
							selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and ");
						}
						else {
							updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and ");
							selectStr = selectStr.append(columnName).append("='").append(puid).append("' and ");
							selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(puid).append("' and ");
						}
						DOFREE(puid);
					}
					else {
						vector<string> propertyVec;
						Split(propertyName, ".", propertyVec);
						if (propertyVec.size() == 2) {
							string propertyPosition = propertyVec[0];
							tag_t propertyTag = NULL;
							if (strcmp("item", propertyPosition.c_str()) == 0) {
								propertyTag = gb_item;
							}
							else if (strcmp("bomline", propertyPosition.c_str()) == 0) {
								propertyTag = gb_line;
							}
							string propertyName = propertyVec[1];
							char* propertyValue = NULL;
							if (strcmp("puid", propertyName.c_str()) == 0) {
								ITK__convert_tag_to_uid(propertyTag, &propertyValue);
							}
							else {
								ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue));
							}
							EMH_clear_errors();
							if (ifail == 0) {
								tempValue = propertyValue;
							}
							else {
								showError = true;
								WriteLog("属性异常：%s\n", propertyName.c_str());
								tempValue = " ";
							}
							DOFREE(propertyValue);
						}
					}
					parentValueStr = parentValueStr.append("'").append(tempValue).append("'");
					if (j < parentNameVec.size() - 1) {
						parentValueStr = parentValueStr.append(",");
					}
				}
				if (isGbContinue) {
					continue;
				}

				string key = gx_clone_id + gb_puid;
				string other_key = gx_gb_key[key];
				vector<CHILD> gbzys = gx_gb_zy[key];
				int gbzy_count = gbzys.size();
				if (gbzy_count > 0) {
					for (int y = 0; y < gbzy_count; y++) {
						bool isContinue = false;
						tag_t gbzy_rev = gbzys[y].rev;
						tag_t gbzy_item = gbzys[y].item;
						tag_t gbzy_line = gbzys[y].line;
						string childColumnStr = "";
						string childSelectStr = "";
						string childUpdateSelectStr = "";
						string childUpdateWhere = "";
						string childValueStr = "";

						ITKCALL(ifail = AOM_ask_value_string(gb_item, "object_type", &zy_type));
						for (int j = 0; j < childNameVec.size(); j++)
						{
							string columnName = childNameVec[j];
							string propertyName = childValueVec[j];
							string tempValue = " ";
							if (strcmp(columnName.c_str(), "_FILTERTYPE") == 0) {
								if (strcmp(propertyName.c_str(), "ALL") == 0) {
									continue;
								}
								else {
									vector<string>typeVec;
									Split(propertyName, ";", typeVec);
									if (hasElement(typeVec, zy_type) == 0) {
										continue;
									}
									else {
										isContinue = true;
										break;
									}
								}
							}
							else if (strcmp(columnName.c_str(), "CPUID") == 0) {
								char* puid = NULL;
								ITK__convert_tag_to_uid(gbzy_rev, &puid);
								tempValue = puid;

								childSelectStr = childSelectStr.append(columnName).append("='").append(tempValue).append("'  ");
								childUpdateSelectStr = childUpdateSelectStr.append(columnName).append("='").append(tempValue).append("'  ");
								childUpdateWhere = childUpdateWhere.append(columnName).append("='").append(tempValue).append("'");
								DOFREE(puid);
							}
							else if (strcmp(columnName.c_str(), "BP_BASIC_PROCESS_ID") == 0) {
								tempValue = other_key;
							}
							else {
								vector<string> propertyVec;
								Split(propertyName, ".", propertyVec);
								if (propertyVec.size() == 2) {
									string propertyPosition = propertyVec[0];
									tag_t propertyTag = NULL;
									if (strcmp("item", propertyPosition.c_str()) == 0) {
										propertyTag = gbzy_item;
									}
									else if (strcmp("rev", propertyPosition.c_str()) == 0) {
										propertyTag = gbzy_rev;
									}
									else if (strcmp("bomline", propertyPosition.c_str()) == 0) {
										propertyTag = gbzy_line;
									}
									string propertyName = propertyVec[1];
									char* propertyValue = NULL;
									if (strcmp("puid", propertyName.c_str()) == 0) {
										ITK__convert_tag_to_uid(propertyTag, &propertyValue);
									}
									else {
										ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue));
									}
									EMH_clear_errors();
									if (ifail == 0) {
										tempValue = propertyValue;
									}
									else {
										showError = true;
										WriteLog("属性异常：%s\n", propertyName.c_str());
										tempValue = " ";
									}
									DOFREE(propertyValue);
								}
								else {
									tempValue = " ";
								}
							}
							childColumnStr = childColumnStr.append(columnName);
							if (j < childNameVec.size() - 1) {
								childColumnStr = childColumnStr.append(",");
							}
							childValueStr = childValueStr.append("'").append(tempValue);
							if (j < childNameVec.size() - 1) {
								childValueStr = childValueStr.append("',");
							}
							else {
								childValueStr = childValueStr.append("'");
							}
						}
						if (isContinue) {
							continue;
						}
						string insertSql = "";
						string selectSql = "";
						string updateSelectSql = "";
						string updateSql = "";
						if (childColumnStr.size() > 0) {
							insertSql = insertSql.append(parentColumnStr).append(",").append(childColumnStr).append(")").append(parentValueStr).append(",").append(childValueStr).append(")");
						}
						else {
							insertSql = insertSql.append(parentColumnStr).append(")").append(parentValueStr).append(")");
						}
						selectSql = selectSql.append(selectStr).append(childSelectStr);
						updateSelectSql = updateSelectSql.append(selectAfterUpdateStr).append(childUpdateSelectStr);
						updateSql = updateSql.append(updateStr).append(updateWhere).append(childUpdateWhere);
						//updateStr = updateStr.append(updateWhere);

						insertSql = Utf8ToGbk(insertSql.c_str());
						updateSql = Utf8ToGbk(updateSql.c_str());
						selectSql = Utf8ToGbk(selectSql.c_str());
						updateSelectSql = Utf8ToGbk(updateSelectSql.c_str());
						WriteLog("工步资源插入语句：%s\n", insertSql.c_str());
						WriteLog("工步资源更新语句：%s\n", updateSql.c_str());
						WriteLog("工步资源查询语句：%s\n", selectSql.c_str());
						WriteLog("工步资源更新后查询语句：%s\n", updateSelectSql.c_str());
						insertVec.push_back(insertSql);
						updateVec.push_back(updateSql);
						selectVec.push_back(selectSql);
						selectAfterUpdateVec.push_back(updateSelectSql);
						char sendChar[400] = "";
						strcpy(sendChar, insertSql.c_str());
						char sendChar2[400] = "";
						strcpy(sendChar2, selectSql.c_str());
						int result = ado0.ado_QuerySQLNoInputParam(sendChar2);
						bool resultSql = ado0.executeInsert(sendChar2, sendChar, result);
					}
				}
				DOFREE(zy_type);
			}
		}
		DOFREE(gb_type);
	}
	//更新数据库
	/*for (int i = 0; i < updateVec.size(); i++) {
		string updateSql = updateVec[i];
		string selectSql = selectVec[i];
		string insertSql = insertVec[i];
		string selectUpdate = selectAfterUpdateVec[i];
		char sendChar[200] = "";
		char sendChar2[200] = "";
		char sendChar3[200] = "";
		strcpy(sendChar, updateSql.c_str());
		strcpy(sendChar2, selectSql.c_str());
		strcpy(sendChar3, selectUpdate.c_str());
		int result = ado0.ado_QuerySQLNoInputParam(sendChar2);
		if (result == 0) {
			showError = true;
			WriteLog("工步资源插入失败：%s\n", insertSql.c_str());
		}
		else {
			bool resultSql = ado0.execute2(sendChar2, sendChar, result);
			result = ado0.ado_QuerySQLNoInputParam(sendChar3);
			if (result == 0) {
				showError = true;
				WriteLog("工步资源更新失败：%s\n", updateSql.c_str());
			}
		}
	}*/
}

int JD_BOPInfoToMediDatabase(EPM_action_message_t msg) {
	bool showError = false;
	nowTime();
	time_t now;
	struct tm* p;
	//获取当前时间
	time(&now);
	//本地化时间，可以细分为年月日时分秒等
	p = localtime(&now);
	createDir();//创建日志目录
	char TC_LOG_FILE[128] = "";
	// 把日志名称赋予给某变量
	sprintf_s(TC_LOG_FILE, "%s\\tmplog\\JD_BOPInfoToMediDatabase_log_[%d-%d-%d-%d-%02d-%02d].txt", getenv("TEMP"), 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
	ECHO("创建日志文件[%s]\n", TC_LOG_FILE);
	CreateLogFile(TC_LOG_FILE);
	//流程节点相关
	tag_t root_task = NULLTAG, * sub_tasks = NULL, current_task = NULLTAG, type_tag = NULLTAG;
	int arg_cnt = 0, ifail = 0;
	char arg1value[1024] = "";//物料类型
	char* argflag = NULL, * argvalue = NULL, * arg = NULL;
	//得到触发此函数的节点
	current_task = msg.task;
	WriteLog("=========================================================\n");
	WriteLog("JD_BOPInfoToMediDatabase 开始执行\n");
	WriteLog("=========================================================\n");
	//获取handler的参数的个数
	arg_cnt = TC_number_of_arguments(msg.arguments);
	WriteLog("参数个数为：%d\n", arg_cnt);
	if (arg_cnt > 0)
	{
		for (int i = 0; i < arg_cnt; i++)
		{
			//获取下一个参数（从0开始）
			arg = TC_next_argument(msg.arguments);
			//获取参数的名称和值
			ITKCALL(ifail = ITK_ask_argument_named_value((const char*)arg, &argflag, &argvalue));
			if (stricmp(argflag, "PartItem") == 0)
			{
				if (argvalue != NULL)
				{
					strcpy(arg1value, argvalue);
				}
			}
		}
		MEM_free(argflag);
		MEM_free(argvalue);
	}
	//先获取首选项Jd_MES_Info_Connect，解析其中的用户名，密码，配置文件等信息
	vector<string>		pref_vec1;
	getPrefStrings1("Jd_MES_Info_Connect", TC_preference_site, pref_vec1);
	string ip = pref_vec1[0];
	string databaseName = pref_vec1[1];
	string user = pref_vec1[2];
	string password = pref_vec1[3];
	string xmlUid1 = pref_vec1[4];
	string xmlUid2 = pref_vec1[5];
	string xmlUid3 = pref_vec1[6];
	string xmlUid4 = pref_vec1[7];
	string xmlUid5 = pref_vec1[8];
	string xmlUid6 = pref_vec1[9];
	WriteLog("ip:%s\n", ip.c_str());
	WriteLog("databaseName:%s\n", databaseName.c_str());
	WriteLog("user:%s\n", user.c_str());
	WriteLog("password:%s\n", password.c_str());
	WriteLog("工艺路线工序明细表xmlUid:%s\n", xmlUid1.c_str());
	WriteLog("工序工步关系表xmlUid:%s\n", xmlUid2.c_str());
	WriteLog("工艺路线-工序属性表xmlUid:%s\n", xmlUid3.c_str());
	WriteLog("工序工艺文件xmlUid:%s\n", xmlUid4.c_str());
	WriteLog("工艺资源xmlUid:%s\n", xmlUid5.c_str());
	WriteLog("工步资源 xmlUid:%s\n", xmlUid6.c_str());
	ado ado0;
	char userName[100];
	strcpy(userName, user.c_str());
	char pwd[100];
	strcpy(pwd, password.c_str());
	string info = "Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=";
	info.append(databaseName).append(";Data Source=").append(ip);
	WriteLog("连接信息：%s\n", info.c_str());
	bool log = ado0.open(userName, pwd, info.c_str());
	//遍历map所有层级
	string revType = arg1value;
	vector<string> revTypeVec;
	Split(revType, ";", revTypeVec);
	int att_cnt = 0;
	tag_t* attachments = NULL;
	//获取根流程节点
	tag_t task_tag = msg.task;
	tag_t rootTask_tag = NULL;
	ifail = EPM_ask_root_task(task_tag, &rootTask_tag);
	//获取目标引用对象
	ifail = EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments);
	for (int i = 0; i < att_cnt; i++) {
		char* object_TYPE_1 = NULL;
		ifail = AOM_ask_value_string(attachments[i], "object_type", &object_TYPE_1);//对象类型
		WriteLog("当前类型对象为   %s\n", object_TYPE_1);
		string partType = object_TYPE_1;
		if (hasElement(revTypeVec, partType) == 0) {
			//包含类型,连接数据库
			if (log == false) {
				WriteLog("登录成功\n");
				tag_t partItem = NULL;
				ITEM_ask_item_of_rev(attachments[i], &partItem);
				char* itemType = NULL;
				AOM_ask_value_string(partItem, "object_type", &itemType);
				//TODO 获取BOM结构
				//获取版本下的bom视图
				int bom_num = 0;
				tag_t* bom_tags = NULLTAG;
				AOM_ask_value_tags(attachments[i], "structure_revisions", &bom_num, &bom_tags);
				if (bom_num > 0)
				{
					tag_t only_bom = bom_tags[0];
					tag_t bom_window_tag = NULLTAG, top_bom_line_tag = NULLTAG;
					map<string, string> gx_cloneid_key;
					map<string, string> gx_gb_key;
					map<string, CHILD> child_level1;
					map<string, vector<CHILD>> gx_gbs_bom;
					map<string, vector<string>> level1_level2;
					map<string, CHILD> child_level2;
					map<string, vector<CHILD>> gx_gb_zy;
					ITKCALL(ifail = ME_create_bop_window(&bom_window_tag));
					ITKCALL(ifail = BOM_set_window_top_line_bvr(bom_window_tag, only_bom, &top_bom_line_tag));
					/*ITKCALL(ifail = BOM_create_window(&bom_window_tag));
					ITKCALL(ifail = BOM_set_window_top_line_bvr(bom_window_tag, only_bom, &top_bom_line_tag));*/
					loadBom(top_bom_line_tag, child_level1, level1_level2, child_level2, gx_gbs_bom, gx_gb_zy);

					map<string, CHILD>::iterator it1;
					for (it1 = child_level1.begin(); it1 != child_level1.end(); it1++) {
						WriteLog("工序clone:%s\n", it1->first.c_str());
					}
					map<string, vector<CHILD>>::iterator it2;
					for (it2 = gx_gbs_bom.begin(); it2 != gx_gbs_bom.end(); it2++) {
						WriteLog("工序clone:%s,工部数量:%d\n", it2->first.c_str(), it2->second.size());
					}
					map<string, vector<string>>::iterator it3;
					for (it3 = level1_level2.begin(); it3 != level1_level2.end(); it3++) {
						int cnt = it3->second.size();
						for (int f = 0; f < cnt; f++) {
							WriteLog("工序clone:%s,工序下级clone:%s\n", it3->first.c_str(), it3->second[f].c_str());
						}
					}
					map<string, CHILD>::iterator it4;
					for (it4 = child_level2.begin(); it4 != child_level2.end(); it4++) {
						WriteLog("工序下级clone:%s\n", it4->first.c_str());
					}
					map<string, vector<CHILD>>::iterator it5;
					for (it5 = gx_gb_zy.begin(); it5 != gx_gb_zy.end(); it5++) {
						WriteLog("工序clone及工部uid:%s,工部资源数量:%d\n", it5->first.c_str(), it5->second.size());
					}

					insertGyGxBom(xmlUid1, showError, ado0, top_bom_line_tag, partItem, attachments[i], child_level1, gx_cloneid_key);

					map<string, string>::iterator it6;
					for (it6 = gx_cloneid_key.begin(); it6 != gx_cloneid_key.end(); it6++) {
						WriteLog("工序gx_cloneid_key,key:%s,val:%s\n", it6->first.c_str(), it6->second.c_str());
					}

					insertGxGb(xmlUid2, showError, ado0, child_level1, gx_cloneid_key, gx_gbs_bom, gx_gb_key);

					map<string, string>::iterator it7;
					for (it7 = gx_gb_key.begin(); it7 != gx_gb_key.end(); it7++) {
						WriteLog("工序gx_gb_key,key:%s,val:%s\n", it7->first.c_str(), it7->second.c_str());
					}
					insertGyGxProp(xmlUid3, showError, ado0, top_bom_line_tag, partItem, attachments[i], child_level1, gx_cloneid_key);
					insertGyGxGywj(xmlUid4, showError, ado0, top_bom_line_tag, partItem, attachments[i], child_level1, level1_level2, child_level2);
					insertGyGxGyzy(xmlUid5, showError, ado0, top_bom_line_tag, partItem, attachments[i], child_level1, level1_level2, child_level2);
					insertGbzy(xmlUid6, showError, ado0, child_level1, gx_gb_key, gx_gbs_bom, gx_gb_zy);
					ITKCALL(ifail = ME_close_bop_window(bom_window_tag));//有开必有关
					//ITKCALL(ifail = BOM_close_window(bom_window_tag));//有开必有关
				}
				DOFREE(bom_tags);
			}
			else {
				WriteLog("登录失败====\n");
			}
		}
		DOFREE(object_TYPE_1);
	}
	ado0.close();
	//EMH_clear_errors();
	DOFREE(attachments);
	//if (showError == true) {
	//	string logName = "数据异常，详见服务器日志：";
	//	logName = logName.append(TC_LOG_FILE);
	//	EMH_store_error_s1(EMH_severity_warning, EMH_AE_error_base, logName.c_str());
	//}
	WriteLog("=========================================================\n");
	WriteLog("JD_BOPInfoToMediDatabase 完成\n");
	WriteLog("=========================================================\n");
	return 0;
}  