#pragma warning (disable: 4996) 
#pragma warning (disable: 4819) 
#pragma warning (disable: 4995) 

#include <tc/tc.h>
#include "epm_handler_common.h"

#include <ict/ict_userservice.h>
#include <tccore/custom.h>
#include <epm/epm_toolkit_tc_utils.h>
#include <tccore/aom.h>
#include <tccore/aom_prop.h>
#include <tccore/item.h>
#include <bom/bom.h>
#include "ps/ps.h";
#include "ps/vrule.h"
#include "sstream"
#include <tccore/grm.h>
#include "epm/epm.h"
#include "sa/sa.h"
#include "libxl.h"
#include <map>
#include "epm/signoff.h"
#include <ctime>
#include <vector>
#include <locale>
#include <codecvt>
#include "ae/dataset.h"
#include <iostream>
typedef struct{
	string ITEM_ID;//id号
}PROPERTY_STRUCT;
int WX_Check_Property(EPM_rule_message_t msg)
{
	EPM_decision_t decision = EPM_go;
	int ifail = ITK_ok, arg_cnt = 0, i = 0, att_cnt = 0;
	tag_t task_tag = NULLTAG, rootTask_tag = NULLTAG, *attachments = NULL;
	char * object_TYPE_1 = NULL;
	char * object_string = NULL;
	string value_type = "";
	string value_property="";
	TC_argument_t *args;//设置参数
	args = msg.arguments->arguments;//->取指针型结构体的成员符。获取流程中设置的参数
	for (auto i = 0; i<msg.arguments->number_of_arguments; i++)
	{
		string val(args[i].val_union.str_value);
		int index = val.find('=');//找到=所在的位置
		string val_t = val.substr(0, index);//返回val从位置0开始长度为index的字符串
		string args = "-object_type";
		string args2 = "-property_name";
		if (args.compare(val_t) == 0)
		{
			value_type = val.substr(index + 1);//返回=以后的字符串，
			cout<<"对象类型---------"<<value_type.c_str()<<endl;
		}
		if (args2.compare(val_t) == 0)
		{
			value_property= val.substr(index + 1);
			cout<<"属性名称---------"<<value_property.c_str()<<endl;
		}

	}
	vector<PROPERTY_STRUCT>	item_vec;
	//获取当前触发的任务
	task_tag = msg.task;
	//获取根流程节点
	ifail = EPM_ask_root_task(task_tag, &rootTask_tag);
	//获取目标引用对象
	ifail = EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments);
	//循环目标对象
	for (i = 0; i < att_cnt; i++) {
	

		ifail = AOM_ask_value_string(attachments[i], "object_type", &object_TYPE_1);//对象类型
		cout << object_TYPE_1;
		cout << endl;
		if(strcmp(value_type.c_str(),object_TYPE_1)==0)
		{
		ifail = AOM_ask_value_string(attachments[i], value_property.c_str(), &object_string);//属性名称
			if(std::strlen(object_string)==0)
			{
				PROPERTY_STRUCT elements ;
				decision=EPM_nogo;
				ifail = AOM_ask_value_string(attachments[i], "object_string", &object_TYPE_1);//对象类型
				elements.ITEM_ID.assign(object_TYPE_1);
				item_vec.push_back(elements);
				
			}
		}
		
	}
	if (attachments != NULL)
	{
		MEM_free(attachments);
		attachments = NULL;
	}
	if (object_TYPE_1 != NULL)
	{
		MEM_free(object_TYPE_1);
		object_TYPE_1 = NULL;
	}
	if (object_string != NULL)
	{
		MEM_free(object_string);
		object_string = NULL;
	}
	
	if(decision==EPM_nogo)
	{
		string name="以下对象的\""+value_property+"\"属性没有填写:\n";
	for (int i=0;i<item_vec.size();i++)
	{
		name=name+item_vec[i].ITEM_ID+"\n";
	}
	EMH_store_error_s1(EMH_severity_warning, EMH_AE_error_base, name.c_str());
		
	}
	return decision;
}