#define _CRT_SECURE_NO_WARNINGS
#include "epm_handler_common.h"

bool FindScheduleNode(TiXmlElement *pRoot, char * nodeName, int &index, TiXmlElement **&pNode);
bool isScheduleOK(tag_t item, char * where);
bool whereIsScheduleOK(tag_t item, char * where);

int ML_SetScheduleTaskProperty(EPM_action_message_t msg) {
	printf("=========================设置时间表属性 Start===================\n");
	auto startTime = std::chrono::high_resolution_clock::now();
	int ifail = ITK_ok;
	int  attachments_num = 0;
	tag_t  rootTask = NULLTAG, *attachments = NULLTAG;
	//获取任务对象
	EPM_ask_root_task(msg.task, &rootTask);
	//获取时间表任务
	AOM_ask_value_tags(rootTask, "fnd0RootScheduleTask", &attachments_num, &attachments);
	if (attachments_num <= 0)
	{
		EPM_ask_attachments(rootTask, EPM_target_attachment, &attachments_num, &attachments);
	}
	//获取任务目标对象
	//EPM_ask_attachments(rootTask, EPM_target_attachment, &attachments_num, &attachments);
	//int sub_task_count = 0;
	//tag_t * sub_tasks = NULLTAG;
	//得到根流程下的所有的一级节点
	//EPM_ask_sub_tasks(rootTask, &sub_task_count, &sub_tasks);

	try
	{
		//获取参数
		char *argflag = NULL, *argvalue = NULL, *arg = NULL;

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

		vector<char *> AOMPropertyValues;

		if (strstr(AOMProperty, ",") != NULL)
		{
			int vectorValueCount = 0;
			char ** vectorValueChar = new char *[64];
			split(AOMProperty, ",", vectorValueChar, &vectorValueCount);
			for (int i = 0; i < vectorValueCount; i++)
			{
				AOMPropertyValues.push_back(vectorValueChar[i]);
			}
		}
		else
		{
			AOMPropertyValues.push_back(AOMProperty);
		}

		tag_t dataSet = NULLTAG;
		//根据Uid获取数据集
		ITK__convert_uid_to_tag(fileUid, &dataSet);
		AE_reference_type_t ae_ref;
		tag_t ref_obj = NULLTAG;
		AE_ask_dataset_named_ref2(dataSet, "XMLRendering", &ae_ref, &ref_obj);

		char out_path[SS_MAXPATHLEN] = "";
		strcpy(out_path, getenv("temp"));
		strcat(out_path, "\\");
		strcat(out_path, "设置时间表任务属性.xml");

		IMF_export_file(ref_obj, out_path);

		char * processName = NULL;
		EPM_ask_name2(rootTask, &processName);
		cout << "流程名称" << processName << endl;

		TiXmlDocument* m_pDocument = new TiXmlDocument();
		if (!m_pDocument->LoadFile(out_path))
		{
			cout << "无法加载xml文件！" << endl;
		}
		//删除文件
		remove(out_path);
		if (NULL == m_pDocument)
		{
			printf("未找到文件===================\n");
		}
		printf("找到文件===================\n");
		TiXmlElement *pRoot = m_pDocument->RootElement();
		if (NULL == pRoot)
		{
			printf("未找到根节点===================\n");
		}
		printf("找到根节点===================\n");

		for (int ii = 0; ii < attachments_num; ii++)
		{
			char *itemType = NULL;

			AOM_ask_value_string(attachments[ii], "object_type", &itemType);
			printf("type_class : %s \r\n", itemType);

			if (strcmp(itemType, objectType) != 0)
			{
				continue;
			}

			int pTypeNodeCount = 0;
			TiXmlElement ** pTypeNode = (TiXmlElement **)MEM_alloc(1024 * sizeof(TiXmlElement *));

			FindScheduleNode(pRoot, itemType, pTypeNodeCount, pTypeNode);
			for (int jj = 0; jj < pTypeNodeCount; jj++)
			{
				int pNodeCount = 0;
				TiXmlElement ** pNode = (TiXmlElement **)MEM_alloc(1024 * sizeof(TiXmlElement *));

				FindScheduleNode(pTypeNode[jj], processName, pNodeCount, pNode);

				//for (int i = 0; i < sub_task_count; i++)
				//{
				char * cur_task_name = NULL;
				//获取节点名称
				EPM_ask_name2(msg.task, &cur_task_name);
				cout << "流程节点名称" << cur_task_name << endl;

				for (int j = 0; j < pNodeCount; j++)
				{
					//获取流程节点
					int pChildProcessNodeCount = 0;
					TiXmlElement ** pChildProcessNode = (TiXmlElement **)MEM_alloc(1024 * sizeof(TiXmlElement *));
					FindScheduleNode(pNode[j], cur_task_name, pChildProcessNodeCount, pChildProcessNode);

					for (int k = 0; k < pChildProcessNodeCount; k++)
					{
						TiXmlElement *pChild = pChildProcessNode[k];
						//int i = 0;
						for (pChild = pChild->FirstChildElement(); pChild != NULL; pChild = pChild->NextSiblingElement())
						{
							//TiXmlElement *p = pChild;
							//判断是否满足条件
							TiXmlAttribute *pAttr = NULL;
							char * referenced = NULL;
							char * where = NULL;
							for (pAttr = pChild->FirstAttribute(); pAttr != NULL; pAttr = pAttr->Next())
							{
								string propertyName = pAttr->Name();
								string propertyValue = pAttr->Value();

								cout << "属性名称" << propertyName << endl;
								cout << "属性值" << U2G(propertyValue.c_str()) << endl;
								if (strcmp(propertyName.c_str(), "referenced") == 0)
								{
									referenced = U2G(propertyValue.c_str());
								}
								else if (strcmp(propertyName.c_str(), "where") == 0)
								{
									where = U2G(propertyValue.c_str());
								}
							}
							tag_t item = attachments[ii];
							char * propertyValue = NULL;
							if (referenced != NULL && strcmp(referenced, "") != 0)
							{
								//获取关系属性的值
								AOM_ask_value_tag(item, referenced, &item);
							}
							//判断是否满足条件
							if (isScheduleOK(item, where))
							{
								//获取下挂的用户
								TiXmlElement *pUserChild = pChild;
								//int i = 0;
								for (pUserChild = pUserChild->FirstChildElement(); pUserChild != NULL; pUserChild = pUserChild->NextSiblingElement())
								{
									TiXmlAttribute *pUserAttr = NULL;
									char * referenced = "";
									char * referenced2 = "";
									char * name = "";
									char * value = "";
									for (pUserAttr = pUserChild->FirstAttribute(); pUserAttr != NULL; pUserAttr = pUserAttr->Next())
									{
										string propertyName = pUserAttr->Name();
										string propertyValue = pUserAttr->Value();

										cout << "属性名称" << propertyName << endl;
										cout << "属性值" << U2G(propertyValue.c_str()) << endl;
										if (strcmp(propertyName.c_str(), "referenced") == 0)
										{
											referenced = strdup(propertyValue.c_str());
										}
										else if (strcmp(propertyName.c_str(), "referenced2") == 0)
										{
											referenced2 = strdup(propertyValue.c_str());
										}
										else if (strcmp(propertyName.c_str(), "propertyName") == 0)
										{
											name = strdup(propertyValue.c_str());
										}
										else if (strcmp(propertyName.c_str(), "propertyValue") == 0)
										{
											value = U2G(propertyValue.c_str());
										}
									}
									tag_t userItem = attachments[ii];
									vector<tag_t> userVector;
									if (strcmp(name, "") != 0)
									{
										//判断是否需要通过关系查找
										if (strcmp(referenced, "") != 0)
										{
											//获取关系属性的值
											AOM_ask_value_tag(item, referenced, &userItem);
										}
										if (strcmp(referenced2, "") != 0)
										{
											//获取关系属性的值
											AOM_ask_value_tag(userItem, referenced2, &userItem);
										}
									}
									//判断是否包含.号
									if (strstr(name, ".") != NULL)
									{
										char *scheduleType = NULL;

										AOM_ask_value_string(userItem, "object_type", &scheduleType);

										//根据等号拆分条件和值
										int itemPropertyCount = 0;
										char ** itemPropertyChar = new char *[64];
										//分割字符串
										split(name, ".", itemPropertyChar, &itemPropertyCount);

										char * itemAddress = itemPropertyChar[0];
										//判断传进来的是版本还是对象
										if (strstr(scheduleType, "ScheduleTask") != NULL)
										{
											tag_t scheduleTag = NULLTAG;
											AOM_ask_value_tag(userItem, "schedule_tag", &scheduleTag);
											//传进来的是版本
											if (strcmp(itemAddress, "schedule") == 0)
											{
												userItem = scheduleTag;
											}
											else if (strcmp(itemAddress, "project") == 0)
											{
												int projectNum = 0;
												tag_t * projectTags = NULLTAG;
												AOM_ask_value_tags(scheduleTag, "project_list", &projectNum, &projectTags);
												if (projectNum == 0)
												{
													printf("未找到项目,继续...");
												}
												else
												{
													userItem = projectTags[0];
												}
												DOFREE(projectTags);
											}
										}

										//判断拆分出的数量是否大于2
										if (itemPropertyCount > 2)
										{
											//遍历查找关系对象
											for (int i = 1; i < itemPropertyCount - 1; i++)
											{
												//如果包含whereReferenced
												if (strstr(itemPropertyChar[i], "-") != NULL && strstr(itemPropertyChar[i], "whereReferenced") != NULL)
												{
													//根据等号拆分条件和值
													int referencedCount = 0;
													char ** referencedChar = new char *[64];
													//分割字符串
													split(itemPropertyChar[i], "-", referencedChar, &referencedCount);
													if (strcmp(referencedChar[0], "whereReferenced") == 0)
													{
														int n_references = 0;
														int *levels = 0;
														tag_t * references_tag = NULLTAG;
														char ** relation_type_name = NULL;

														//通过引用关系查找到文件夹
														WSOM_where_referenced(userItem, 1, &n_references, &levels, &references_tag, &relation_type_name);
														for (int j = 0; j < n_references; j++)
														{
															char *objectType = NULL;

															AOM_ask_value_string(references_tag[j], "object_type", &objectType);
															if ((strcmp(objectType, referencedChar[1]) != 0))
															{
																DOFREE(objectType);
																continue;
															}
															DOFREE(objectType);
															userItem = references_tag[j];
															break;
														}
														DOFREE(references_tag);
													}
												}
												else
												{
													AOM_ask_value_tag(userItem, itemPropertyChar[i], &userItem);
												}
											}
											//获取对象类型
											char *userItemType = NULL;

											AOM_ask_value_string(userItem, "object_type", &userItemType);

											//POM_AM__set_application_bypass(true);

											if (strcmp(userItemType, "Schedule") == 0)
											{
												if (strcmp(itemPropertyChar[itemPropertyCount - 1], "fnd0status") == 0)
												{
													//设置时间表任务状态
													SCHMGT_set_schedule_status(userItem, value);
												}
												else if (count(AOMPropertyValues, itemPropertyChar[itemPropertyCount - 1]))
												{
													AOM_lock(userItem);
													AOM_set_value_string(userItem, itemPropertyChar[itemPropertyCount - 1], value);
													AOM_save(userItem);
													AOM_unlock(userItem);
													AOM_refresh(userItem, FALSE);
												}
												else
												{
													ObjectUpdateContainer_t objCnt;
													objCnt.object = userItem;
													objCnt.updatesSize = 1;
													objCnt.updates[0].attrName = itemPropertyChar[itemPropertyCount - 1];
													objCnt.updates[0].attrValue = value;
													objCnt.updates[0].attrType = 7;

													//AOM_refresh(userItem, TRUE);
													int numUpdatedTasks = 0;
													tag_t *updatedTasks = NULL;
													//printf("设置属性%s：%s\r\n", itemPropertyChar[itemPropertyCount - 1], value);
													//RES_checkout2(userItem, "Test ITK function SCHMGT_update_tasks_non_interactive", NULL, NULL, RES_EXCLUSIVE_RESERVE);
													SCHMGT_update_schedule_non_interactive(objCnt, &numUpdatedTasks, &updatedTasks);
													//printf("设置属性完成%s：%s\r\n", itemPropertyChar[itemPropertyCount - 1], value);
													//AOM_save(userItem);
													//RES_checkin(userItem);
													//AOM_refresh(userItem, TRUE);
												}
											}
											else if (strcmp(userItemType, "ScheduleTask") == 0)
											{

												if (count(AOMPropertyValues, itemPropertyChar[itemPropertyCount - 1]))
												{
													AOM_lock(userItem);
													AOM_set_value_string(userItem, itemPropertyChar[itemPropertyCount - 1], value);
													AOM_save(userItem);
													AOM_unlock(userItem);
													AOM_refresh(userItem, FALSE);
												}
												else
												{
													//通过时间表任务获取时间表
													tag_t userSchedule = NULL;
													AOM_ask_value_tag(userItem, "schedule_tag", &userSchedule);
													ObjectUpdateContainer_t * objCnts = (ObjectUpdateContainer_t*)MEM_alloc(1 * sizeof(ObjectUpdateContainer_t));
													ObjectUpdateContainer_t objCnt;
													objCnt.object = userItem;
													objCnt.updatesSize = 1;
													objCnt.updates[0].attrName = itemPropertyChar[itemPropertyCount - 1];
													objCnt.updates[0].attrValue = value;
													objCnt.updates[0].attrType = 7;
													objCnts[0] = objCnt;
													//AOM_refresh(userItem, TRUE);
													int numUpdatedTasks = 0;
													tag_t *updatedTasks = NULL;
													//RES_checkout2(userItem, "Test ITK function SCHMGT_update_tasks_non_interactive", NULL, NULL, RES_EXCLUSIVE_RESERVE);
													SCHMGT_update_tasks_non_interactive(userSchedule, 1, objCnts, &numUpdatedTasks, &updatedTasks);
													//AOM_save(userItem);
													//RES_checkin(userItem);
													//AOM_refresh(userItem, TRUE);
												}
											}
											else
											{
												AOM_lock(userItem);
												AOM_set_value_string(userItem, itemPropertyChar[itemPropertyCount - 1], value);
												AOM_save(userItem);
												AOM_unlock(userItem);
												AOM_refresh(userItem, FALSE);
											}

											//POM_AM__set_application_bypass(false);
										}
										else if (itemPropertyCount == 2)
										{
											//设置属性值
											cout << "属性" << itemPropertyChar[itemPropertyCount - 1] << "值:" << value << endl;

											//获取对象类型
											char *userItemType = NULL;

											AOM_ask_value_string(userItem, "object_type", &userItemType);

											//POM_AM__set_application_bypass(true);

											if (strstr(userItemType, "Schedule") != NULL)
											{
												if (strcmp(itemPropertyChar[itemPropertyCount - 1], "fnd0status") == 0)
												{
													//设置时间表任务状态
													SCHMGT_set_schedule_status(userItem, value);
												}
												else if (count(AOMPropertyValues, itemPropertyChar[itemPropertyCount - 1]))
												{
													AOM_lock(userItem);
													AOM_set_value_string(userItem, itemPropertyChar[itemPropertyCount - 1], value);
													AOM_save(userItem);
													AOM_unlock(userItem);
													AOM_refresh(userItem, FALSE);
												}
												else
												{
													ObjectUpdateContainer_t objCnt;
													objCnt.object = userItem;
													objCnt.updatesSize = 1;
													objCnt.updates[0].attrType = 7;
													objCnt.updates[0].attrName = itemPropertyChar[itemPropertyCount - 1];
													objCnt.updates[0].attrValue = value;

													int numUpdatedTasks = 0;
													tag_t *updatedTasks = NULL;
													//签出
													//RES_checkout2(userItem, "Test ITK function SCHMGT_update_tasks_non_interactive", NULL, NULL, RES_EXCLUSIVE_RESERVE);
													//printf("设置属性%s：%s\r\n", itemPropertyChar[itemPropertyCount - 1], value);
													SCHMGT_update_schedule_non_interactive(objCnt, &numUpdatedTasks, &updatedTasks);
													//printf("设置属性完成%s：%s\r\n", itemPropertyChar[itemPropertyCount - 1], value);
													//AOM_save(userItem);
													//AOM_unlock(userItem);
													//AOM_refresh(userItem, FALSE);

													//签入
													//RES_checkin(userItem);
													//AOM_refresh(userItem, TRUE);
												}
											}
											else if (strcmp(userItemType, "ScheduleTask") == 0)
											{
												if (count(AOMPropertyValues, itemPropertyChar[itemPropertyCount - 1]))
												{
													AOM_lock(userItem);
													AOM_set_value_string(userItem, itemPropertyChar[itemPropertyCount - 1], value);
													AOM_save(userItem);
													AOM_unlock(userItem);
													AOM_refresh(userItem, FALSE);
												}
												else
												{
													//通过时间表任务获取时间表
													tag_t userSchedule = NULL;
													AOM_ask_value_tag(userItem, "schedule_tag", &userSchedule);
													ObjectUpdateContainer_t * objCnts = (ObjectUpdateContainer_t*)MEM_alloc(1 * sizeof(ObjectUpdateContainer_t));
													ObjectUpdateContainer_t objCnt;
													objCnt.object = userItem;
													objCnt.updatesSize = 1;
													objCnt.updates[0].attrName = itemPropertyChar[itemPropertyCount - 1];
													objCnt.updates[0].attrValue = value;
													objCnt.updates[0].attrType = 7;
													objCnts[0] = objCnt;
													//AOM_lock(userItem);
													//AOM_refresh(userItem, TRUE);
													int numUpdatedTasks = 0;
													tag_t *updatedTasks = NULL;
													//签出
													//RES_checkout2(userItem, "Test ITK function SCHMGT_update_tasks_non_interactive", NULL, NULL, RES_EXCLUSIVE_RESERVE);
													SCHMGT_update_tasks_non_interactive(userSchedule, 1, objCnts, &numUpdatedTasks, &updatedTasks);
													//AOM_save(userItem);
													//AOM_unlock(userItem);
													//AOM_refresh(userItem, FALSE);
													//签入
													//RES_checkin(userItem);
													//AOM_refresh(userItem, TRUE);
												}
											}
											else
											{
												AOM_lock(userItem);
												AOM_set_value_string(userItem, itemPropertyChar[itemPropertyCount - 1], value);
												AOM_save(userItem);
												AOM_unlock(userItem);
												AOM_refresh(userItem, FALSE);
											}

											//POM_AM__set_application_bypass(false);
										}

										delete[]itemPropertyChar;
										itemPropertyChar = NULL;
										DOFREE(scheduleType);
										DOFREE(itemAddress);
									}
									DOFREE(itemWhere);
									DOFREE(referenced);
									DOFREE(referenced2);
									DOFREE(name);
									DOFREE(value);
								}

								pUserChild = NULL;
							}

							pAttr = NULL;
							DOFREE(referenced);
							DOFREE(where);
							DOFREE(propertyValue);
						}

						pChild = NULL;
					}

					pChildProcessNode = NULL;
				}


				DOFREE(cur_task_name);
				//}

				pNode = NULL;
			}

			pTypeNode = NULL;
			DOFREE(itemType);
		}
		DOFREE(processName);
		m_pDocument = NULL;
		pRoot = NULL;
	}
	catch (exception exception) {
		printf("exception%s\r\n", exception.what());
	}
	DOFREE(attachments);
	//DOFREE(sub_tasks);
	DOFREE(argflag);
	DOFREE(argvalue);
	DOFREE(arg);

	auto stopTime = std::chrono::high_resolution_clock::now();
	auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stopTime - startTime);
	//std::cout << "ML_SetScheduleTaskProperty用时:" << duration.count() / 1000 << std::endl;
	string usetime = "ML_SetScheduleTaskProperty用时:";
	usetime.append(std::to_string(duration.count() / 1000));
	WriteLog(true, usetime.c_str());
	printf("=========================设置时间表属性 End===================\n");
	return 0;
}

bool isScheduleOK(tag_t item, char * where)
{
	bool result = true;

	if (strstr(where, "AND") != NULL)
	{
		//按照AND进行拆分。拆分条件
		int valueCount = 0;
		char ** valueChar = new char *[64];
		//分割字符串
		split(where, "AND", valueChar, &valueCount);

		for (int i = 0; i < valueCount; i++)
		{
			cout << "拆分AND" << valueChar[i] << endl;

			//如果拆分出来包含OR的（列：(A OR B)）
			if (strstr(valueChar[i], "[") != NULL && strstr(valueChar[i], "]") != NULL && strstr(valueChar[i], "OR") != NULL)
			{
				removeChar(valueChar[i], '[');
				removeChar(valueChar[i], ']');
				removeChar(valueChar[i], ' ');

				//根据OR进行拆分
				int orValueCount = 0;
				char ** orValueChar = new char *[64];
				//分割字符串
				split(valueChar[i], "OR", orValueChar, &orValueCount);
				bool isOK = true;
				for (int j = 0; j < orValueCount; j++)
				{
					//判断是否满足条件
					if (!whereIsScheduleOK(item, orValueChar[j]))
					{
						isOK = false;
						break;
					}
				}

				delete[]orValueChar;
				orValueChar = NULL;

				if (!isOK)
				{
					result = false;
					break;
				}
			}
			//如果拆分出的AND包含括号的（列：(A AND B) 拆分后就是：(A ）
			else if (strstr(valueChar[i], "[") != NULL)
			{
				//去除左括号
				removeChar(valueChar[i], '[');
				removeChar(valueChar[i], ' ');
				//判断是否满足条件
				if (!whereIsScheduleOK(item, valueChar[i]))
				{
					result = false;
					break;
				}
			}
			//如果拆分出的AND包含括号的（列：(A AND B) 拆分后就是：B) ）
			else if (strstr(valueChar[i], "]") != NULL)
			{
				//去除右括号
				removeChar(valueChar[i], ']');
				removeChar(valueChar[i], ' ');
				//判断是否满足条件
				if (!whereIsScheduleOK(item, valueChar[i]))
				{
					result = false;
					break;
				}

			}
			//如果拆分出的AND包含OR但不包含括号的（列：A AND B OR C 拆分后就是：A、B OR C ）
			else if (strstr(valueChar[i], "OR") != NULL)
			{
				removeChar(valueChar[i], ' ');
				//根据OR进行拆分
				int orValueCount = 0;
				char ** orValueChar = new char *[64];
				//分割字符串
				split(valueChar[i], "OR", orValueChar, &orValueCount);

				bool isOk = true;

				for (int j = 1; j < orValueCount; j++)
				{
					if (!whereIsScheduleOK(item, orValueChar[j]))
					{
						isOk = false;
						break;
					}
				}

				delete[]orValueChar;
				orValueChar = NULL;

				if (!whereIsScheduleOK(item, orValueChar[0]) && !isOk)
				{
					isOk = false;
					break;
				}

			}
			else
			{
				removeChar(valueChar[i], ' ');
				//判断是否满足条件
				if (!whereIsScheduleOK(item, valueChar[i]))
				{
					result = false;
					break;
				}
			}
		}

		delete[]valueChar;
		valueChar = NULL;
	}
	else
	{
		removeChar(where, ' ');
		result = whereIsScheduleOK(item, where);
	}

	return result;
}

//判断条件（例：item.owning_user.user_id=1111）是否满足
bool whereIsScheduleOK(tag_t item, char * where)
{
	bool result = false;
	if (strstr(where, "!=") != NULL)
	{
		//根据等号拆分条件和值
		int valueCount = 0;
		char ** valueChar = new char *[64];
		//分割字符串
		split(where, "!=", valueChar, &valueCount);

		char * itemWhere = valueChar[0];
		char * value = valueChar[1];
		//判断是否包含.号
		if (strstr(itemWhere, ".") != NULL)
		{
			char *itemType = NULL;

			AOM_ask_value_string(item, "object_type", &itemType);

			//根据等号拆分条件和值
			int itemPropertyCount = 0;
			char ** itemPropertyChar = new char *[64];
			//分割字符串
			split(itemWhere, ".", itemPropertyChar, &itemPropertyCount);

			char * itemAddress = itemPropertyChar[0];
			//判断传进来的是版本还是对象
			if (strstr(itemType, "ScheduleTask") != NULL)
			{
				tag_t scheduleTag = NULLTAG;
				AOM_ask_value_tag(item, "schedule_tag", &scheduleTag);
				//传进来的是版本
				if (strcmp(itemAddress, "schedule") == 0)
				{
					item = scheduleTag;
				}
				else if (strcmp(itemAddress, "project") == 0)
				{
					int projectNum = 0;
					tag_t * projectTags = NULLTAG;
					AOM_ask_value_tags(scheduleTag, "project_list", &projectNum, &projectTags);
					if (projectNum == 0)
					{
						printf("未找到项目,继续...");
					}
					else
					{
						item = projectTags[0];
					}
					DOFREE(projectTags);
				}
			}

			//判断拆分出的数量是否大于2
			if (itemPropertyCount > 2)
			{
				//遍历查找关系对象
				for (int i = 1; i < itemPropertyCount - 1; i++)
				{
					AOM_ask_value_tag(item, itemPropertyChar[i], &item);
				}
				//获取属性值
				char * getValue = NULL;
				AOM_ask_value_string(item, itemPropertyChar[itemPropertyCount - 1], &getValue);
				cout << "比较条件" << getValue << value << endl;
				if (strcmp("空", value) == 0)
				{
					if (getValue != NULL && strcmp("", getValue) != 0)
					{
						result = true;
					}
				}
				else
				{
					if (strcmp(getValue, value) != 0)
					{
						result = true;
					}
				}
				DOFREE(getValue);
			}
			else if (itemPropertyCount == 2)
			{
				//获取属性值
				char * getValue = NULL;
				AOM_ask_value_string(item, itemPropertyChar[itemPropertyCount - 1], &getValue);
				cout << "比较条件" << getValue << value << endl;

				if (strcmp("空", value) == 0)
				{
					if (getValue != NULL && strcmp("", getValue) != 0)
					{
						result = true;
					}
				}
				else
				{
					if (strcmp(getValue, value) != 0)
					{
						result = true;
					}
				}
				DOFREE(getValue);
			}

			delete[]itemPropertyChar;
			itemPropertyChar = NULL;
			DOFREE(itemType);
			DOFREE(itemAddress);

		}

		delete[]valueChar;
		valueChar = NULL;
		DOFREE(itemWhere);
		DOFREE(value);
	}
	else if (strstr(where, "=") != NULL)
	{
		//根据等号拆分条件和值
		int valueCount = 0;
		char ** valueChar = new char *[64];
		//分割字符串
		split(where, "=", valueChar, &valueCount);

		char * itemWhere = valueChar[0];
		char * value = valueChar[1];
		//判断是否包含.号
		if (strstr(itemWhere, ".") != NULL)
		{
			char *itemType = NULL;

			AOM_ask_value_string(item, "object_type", &itemType);

			//根据等号拆分条件和值
			int itemPropertyCount = 0;
			char ** itemPropertyChar = new char *[64];
			//分割字符串
			split(itemWhere, ".", itemPropertyChar, &itemPropertyCount);

			char * itemAddress = itemPropertyChar[0];
			//判断传进来的是版本还是对象
			if (strstr(itemType, "ScheduleTask") != NULL)
			{
				tag_t scheduleTag = NULLTAG;
				AOM_ask_value_tag(item, "schedule_tag", &scheduleTag);
				//传进来的是版本
				if (strcmp(itemAddress, "schedule") == 0)
				{
					item = scheduleTag;
				}
				else if (strcmp(itemAddress, "project") == 0)
				{
					int projectNum = 0;
					tag_t * projectTags = NULLTAG;
					AOM_ask_value_tags(scheduleTag, "project_list", &projectNum, &projectTags);
					if (projectNum == 0)
					{
						printf("未找到项目,继续...");
					}
					else
					{
						item = projectTags[0];
					}
					DOFREE(projectTags);
				}
			}

			//判断拆分出的数量是否大于2
			if (itemPropertyCount > 2)
			{
				//遍历查找关系对象
				for (int i = 1; i < itemPropertyCount - 1; i++)
				{
					AOM_ask_value_tag(item, itemPropertyChar[i], &item);
				}
				//获取属性值
				char * getValue = NULL;
				AOM_ask_value_string(item, itemPropertyChar[itemPropertyCount - 1], &getValue);
				cout << "比较条件" << getValue << value << endl;
				if (strcmp("空", value) == 0)
				{
					if (getValue == NULL || strcmp("", getValue) == 0)
					{
						result = true;
					}
				}
				else
				{
					if (strcmp(getValue, value) == 0)
					{
						result = true;
					}
				}
				DOFREE(getValue);
			}
			else if (itemPropertyCount == 2)
			{
				//获取属性值
				char * getValue = NULL;
				AOM_ask_value_string(item, itemPropertyChar[itemPropertyCount - 1], &getValue);
				cout << "比较条件" << getValue << value << endl;
				if (strcmp("空", value) == 0)
				{
					if (getValue == NULL || strcmp("", getValue) == 0)
					{
						result = true;
					}
				}
				else
				{
					if (strcmp(getValue, value) == 0)
					{
						result = true;
					}
				}
				DOFREE(getValue);
			}

			delete[]itemPropertyChar;
			itemPropertyChar = NULL;
			DOFREE(itemType);
			DOFREE(itemAddress);
		}

		delete[]valueChar;
		valueChar = NULL;
		DOFREE(itemWhere);
		DOFREE(value);
	}
	else if (strstr(where, "NOT IN") != NULL)
	{
		//根据等号拆分条件和值
		int valueCount = 0;
		char ** valueChar = new char *[64];
		//分割字符串
		split(where, "NOT IN", valueChar, &valueCount);

		char * itemWhere = valueChar[0];
		char * value = valueChar[1];
		vector<char *> vectorValues;

		if (strstr(value, ",") != NULL)
		{
			int vectorValueCount = 0;
			char ** vectorValueChar = new char *[64];
			split(where, ",", vectorValueChar, &vectorValueCount);
			for (int i = 0; i < vectorValueCount; i++)
			{
				vectorValues.push_back(vectorValueChar[i]);
			}
		}
		else
		{
			vectorValues.push_back(value);
		}
		//判断是否包含.号
		if (strstr(itemWhere, ".") != NULL)
		{
			char *itemType = NULL;

			AOM_ask_value_string(item, "object_type", &itemType);

			//根据等号拆分条件和值
			int itemPropertyCount = 0;
			char ** itemPropertyChar = new char *[64];
			//分割字符串
			split(itemWhere, ".", itemPropertyChar, &itemPropertyCount);

			char * itemAddress = itemPropertyChar[0];
			//判断传进来的是版本还是对象
			if (strstr(itemType, "ScheduleTask") != NULL)
			{
				tag_t scheduleTag = NULLTAG;
				AOM_ask_value_tag(item, "schedule_tag", &scheduleTag);
				//传进来的是版本
				if (strcmp(itemAddress, "schedule") == 0)
				{
					item = scheduleTag;
				}
				else if (strcmp(itemAddress, "project") == 0)
				{
					int projectNum = 0;
					tag_t * projectTags = NULLTAG;
					AOM_ask_value_tags(scheduleTag, "project_list", &projectNum, &projectTags);
					if (projectNum == 0)
					{
						printf("未找到项目,继续...");
					}
					else
					{
						item = projectTags[0];
					}
					DOFREE(projectTags);
				}
			}

			//判断拆分出的数量是否大于2
			if (itemPropertyCount > 2)
			{
				//遍历查找关系对象
				for (int i = 1; i < itemPropertyCount - 1; i++)
				{
					AOM_ask_value_tag(item, itemPropertyChar[i], &item);
				}
				//获取属性值
				char * getValue = NULL;
				AOM_ask_value_string(item, itemPropertyChar[itemPropertyCount - 1], &getValue);
				cout << "比较条件" << getValue << value << endl;
				if (!count(vectorValues, getValue))
				{
					result = true;
				}
				DOFREE(getValue);
			}
			else if (itemPropertyCount == 2)
			{
				//获取属性值
				char * getValue = NULL;
				AOM_ask_value_string(item, itemPropertyChar[itemPropertyCount - 1], &getValue);
				cout << "比较条件" << getValue << value << endl;
				if (!count(vectorValues, getValue))
				{
					result = true;
				}
				DOFREE(getValue);
			}

			delete[]itemPropertyChar;
			itemPropertyChar = NULL;
			DOFREE(itemType);
			DOFREE(itemAddress);
		}

		delete[]valueChar;
		valueChar = NULL;
		DOFREE(itemWhere);
		DOFREE(value);
	}
	else if (strstr(where, "IN") != NULL)
	{
		//根据等号拆分条件和值
		int valueCount = 0;
		char ** valueChar = new char *[64];
		//分割字符串
		split(where, "IN", valueChar, &valueCount);

		char * itemWhere = valueChar[0];
		char * value = valueChar[1];
		vector<char *> vectorValues;

		if (strstr(value, ",") != NULL)
		{
			int vectorValueCount = 0;
			char ** vectorValueChar = new char *[64];
			split(where, ",", vectorValueChar, &vectorValueCount);
			for (int i = 0; i < vectorValueCount; i++)
			{
				vectorValues.push_back(vectorValueChar[i]);
			}
		}
		else
		{
			vectorValues.push_back(value);
		}
		//判断是否包含.号
		if (strstr(itemWhere, ".") != NULL)
		{
			char *itemType = NULL;

			AOM_ask_value_string(item, "object_type", &itemType);

			//根据等号拆分条件和值
			int itemPropertyCount = 0;
			char ** itemPropertyChar = new char *[64];
			//分割字符串
			split(itemWhere, ".", itemPropertyChar, &itemPropertyCount);

			char * itemAddress = itemPropertyChar[0];
			//判断传进来的是版本还是对象
			if (strstr(itemType, "ScheduleTask") != NULL)
			{
				tag_t scheduleTag = NULLTAG;
				AOM_ask_value_tag(item, "schedule_tag", &scheduleTag);
				//传进来的是版本
				if (strcmp(itemAddress, "schedule") == 0)
				{
					item = scheduleTag;
				}
				else if (strcmp(itemAddress, "project") == 0)
				{
					int projectNum = 0;
					tag_t * projectTags = NULLTAG;
					AOM_ask_value_tags(scheduleTag, "project_list", &projectNum, &projectTags);
					if (projectNum == 0)
					{
						printf("未找到项目,继续...");
					}
					else
					{
						item = projectTags[0];
					}
					DOFREE(projectTags);
				}
			}

			//判断拆分出的数量是否大于2
			if (itemPropertyCount > 2)
			{
				//遍历查找关系对象
				for (int i = 1; i < itemPropertyCount - 1; i++)
				{
					AOM_ask_value_tag(item, itemPropertyChar[i], &item);
				}
				//获取属性值
				char * getValue = NULL;
				AOM_ask_value_string(item, itemPropertyChar[itemPropertyCount - 1], &getValue);
				cout << "比较条件" << getValue << value << endl;
				if (count(vectorValues, getValue))
				{
					result = true;
				}
				DOFREE(getValue);
			}
			else if (itemPropertyCount == 2)
			{
				//获取属性值
				char * getValue = NULL;
				AOM_ask_value_string(item, itemPropertyChar[itemPropertyCount - 1], &getValue);
				cout << "比较条件" << getValue << value << endl;
				if (count(vectorValues, getValue))
				{
					result = true;
				}
				DOFREE(getValue);
			}

			delete[]itemPropertyChar;
			itemPropertyChar = NULL;
			DOFREE(itemType);
			DOFREE(itemAddress);
		}

		delete[]valueChar;
		valueChar = NULL;
		DOFREE(itemWhere);
		DOFREE(value);
	}
	else if (strstr(where, "NOT LIKE") != NULL)
	{
		//根据等号拆分条件和值
		int valueCount = 0;
		char ** valueChar = new char *[64];
		//分割字符串
		split(where, "!=", valueChar, &valueCount);

		char * itemWhere = valueChar[0];
		char * value = valueChar[1];
		//判断是否包含.号
		if (strstr(itemWhere, ".") != NULL)
		{
			char *itemType = NULL;

			AOM_ask_value_string(item, "object_type", &itemType);

			//根据等号拆分条件和值
			int itemPropertyCount = 0;
			char ** itemPropertyChar = new char *[64];
			//分割字符串
			split(itemWhere, ".", itemPropertyChar, &itemPropertyCount);

			char * itemAddress = itemPropertyChar[0];
			//判断传进来的是版本还是对象
			if (strstr(itemType, "ScheduleTask") != NULL)
			{
				tag_t scheduleTag = NULLTAG;
				AOM_ask_value_tag(item, "schedule_tag", &scheduleTag);
				//传进来的是版本
				if (strcmp(itemAddress, "schedule") == 0)
				{
					item = scheduleTag;
				}
				else if (strcmp(itemAddress, "project") == 0)
				{
					int projectNum = 0;
					tag_t * projectTags = NULLTAG;
					AOM_ask_value_tags(scheduleTag, "project_list", &projectNum, &projectTags);
					if (projectNum == 0)
					{
						printf("未找到项目,继续...");
					}
					else
					{
						item = projectTags[0];
					}
					DOFREE(projectTags);
				}
			}

			//判断拆分出的数量是否大于2
			if (itemPropertyCount > 2)
			{
				//遍历查找关系对象
				for (int i = 1; i < itemPropertyCount - 1; i++)
				{
					AOM_ask_value_tag(item, itemPropertyChar[i], &item);
				}
				//获取属性值
				char * getValue = NULL;
				AOM_ask_value_string(item, itemPropertyChar[itemPropertyCount - 1], &getValue);
				cout << "比较条件" << getValue << value << endl;
				if (strstr(getValue, value) == NULL)
				{
					result = true;
				}
				DOFREE(getValue);
			}
			else if (itemPropertyCount == 2)
			{
				//获取属性值
				char * getValue = NULL;
				AOM_ask_value_string(item, itemPropertyChar[itemPropertyCount - 1], &getValue);
				cout << "比较条件" << getValue << value << endl;
				if (strstr(getValue, value) == NULL)
				{
					result = true;
				}
				DOFREE(getValue);
			}

			delete[]itemPropertyChar;
			itemPropertyChar = NULL;
			DOFREE(itemType);
			DOFREE(itemAddress);

		}

		delete[]valueChar;
		valueChar = NULL;
		DOFREE(itemWhere);
		DOFREE(value);
	}
	else if (strstr(where, "LIKE") != NULL)
	{
		//根据等号拆分条件和值
		int valueCount = 0;
		char ** valueChar = new char *[64];
		//分割字符串
		split(where, "LIKE", valueChar, &valueCount);

		char * itemWhere = valueChar[0];
		char * value = valueChar[1];
		//判断是否包含.号
		if (strstr(itemWhere, ".") != NULL)
		{
			char *itemType = NULL;

			AOM_ask_value_string(item, "object_type", &itemType);

			//根据等号拆分条件和值
			int itemPropertyCount = 0;
			char ** itemPropertyChar = new char *[64];
			//分割字符串
			split(itemWhere, ".", itemPropertyChar, &itemPropertyCount);

			char * itemAddress = itemPropertyChar[0];
			//判断传进来的是版本还是对象
			if (strstr(itemType, "ScheduleTask") != NULL)
			{
				tag_t scheduleTag = NULLTAG;
				AOM_ask_value_tag(item, "schedule_tag", &scheduleTag);
				//传进来的是版本
				if (strcmp(itemAddress, "schedule") == 0)
				{
					item = scheduleTag;
				}
				else if (strcmp(itemAddress, "project") == 0)
				{
					int projectNum = 0;
					tag_t * projectTags = NULLTAG;
					AOM_ask_value_tags(scheduleTag, "project_list", &projectNum, &projectTags);
					if (projectNum == 0)
					{
						printf("未找到项目,继续...");
					}
					else
					{
						item = projectTags[0];
					}
					DOFREE(projectTags);
				}
			}

			//判断拆分出的数量是否大于2
			if (itemPropertyCount > 2)
			{
				//遍历查找关系对象
				for (int i = 1; i < itemPropertyCount - 1; i++)
				{
					AOM_ask_value_tag(item, itemPropertyChar[i], &item);
				}
				//获取属性值
				char * getValue = NULL;
				AOM_ask_value_string(item, itemPropertyChar[itemPropertyCount - 1], &getValue);
				cout << "比较条件" << getValue << value << endl;
				if (strstr(getValue, value) != NULL)
				{
					result = true;
				}
				DOFREE(getValue);
			}
			else if (itemPropertyCount == 2)
			{
				//获取属性值
				char * getValue = NULL;
				AOM_ask_value_string(item, itemPropertyChar[itemPropertyCount - 1], &getValue);
				cout << "比较条件" << getValue << value << endl;
				if (strstr(getValue, value) != NULL)
				{
					result = true;
				}
				DOFREE(getValue);
			}

			delete[]itemPropertyChar;
			itemPropertyChar = NULL;
			DOFREE(itemType);
			DOFREE(itemAddress);
		}

		delete[]valueChar;
		valueChar = NULL;
		DOFREE(itemWhere);
		DOFREE(value);
	}

	return result;
}

//根据节点属性值，获取节点的集合
bool FindScheduleNode(TiXmlElement *pRoot, char * nodeName, int &index, TiXmlElement **&pNode)
{
	TiXmlElement *p = pRoot;
	//int i = 0;
	for (p = p->FirstChildElement(); p != NULL; p = p->NextSiblingElement())
	{
		TiXmlAttribute *pAttr = NULL;
		for (pAttr = p->FirstAttribute(); pAttr != NULL; pAttr = pAttr->Next())
		{
			char * value = NULL;
			value = U2G(pAttr->Value());

			cout << "xml节点名称" << value << endl;
			if (strcmp(value, nodeName) == 0)
			{
				pNode[index] = p;
				index++;
			}
		}
	}
	return false;
}