#include "hx_custom.h"

int HX3_create_item_post(METHOD_message_t* msg , va_list va)
{
	
	tag_t current_group_mem_tag =NULLTAG,current_user_tag =NULLTAG;
	char          userid[SA_user_size_c + 1] = "\0";
	ITKCALL(SA_ask_current_groupmember(&current_group_mem_tag));	
	ITKCALL(SA_ask_groupmember_user(current_group_mem_tag,&current_user_tag));
	ITKCALL(SA_ask_user_identifier(current_user_tag,userid));
	char file_name[SS_MAXPATHLEN]	 ="\0";
	ITKCALL(SA_ask_user_pfile(userid,file_name));
	printf("user_pfile = %s \n",file_name);
	//RevisionAnchor

    fprintf(stdout,"get into post method ====================== \n");
    int ifail = ITK_ok ;
    char  new_item_rev_name[ITEM_type_size_c+1] = "";
	char errorStr[10240] = "\0";
	string error_string;
    //	logical istrue = FALSE;
    const char* item_id = va_arg(va,const char*); 
    const char* item_name = va_arg(va,const char*);
    const char* item_type = va_arg(va,const char*);
    const char* rev_id = va_arg(va,const char*);
    tag_t* item_tag = va_arg(va,tag_t*);
   // tag_t* rev_tag = va_arg(va,tag_t*);

	char * cd9_codeDesc =NULL;
   

	AOM_ask_value_string(*item_tag,"cd9_codeDesc",&cd9_codeDesc);

	printf("\ncd9 code => %s\n",cd9_codeDesc);
	if(cd9_codeDesc !=NULL){
		MEM_free(cd9_codeDesc);
		cd9_codeDesc =NULL;
	}

	
    if(*item_tag != NULLTAG && strcmp(item_type,"HX3_XXM")==0){
		int count = 0 ,entry_count = 0,status = 0,num_found=0;
		char ** values_list = NULL ;//** values = NULL, ** entries = NULL;

		tag_t query_tag = NULLTAG ,*results = NULL;
		
		//构建器
		ITKCALL(QRY_find("KHDH-TO-XM",&query_tag));
		if(query_tag==NULLTAG)
		{
			printf("没找到 [%s]查询构建器！\n","KHDH-TO-XM" );
			return 0;
		}
		printf("找到 [%s]查询构建器！\n","KHDH-TO-XM" );
		
		ITKCALL(AOM_ask_value_strings(*item_tag,"hx3_khdh",&count,&values_list));
		//char other_entrys[1][64] = {"客户代号"};//hx3_khdh 客户代号
		//char other_values[1][64] = {""};
		

		for(int i = 0 ;i < count;i++){
			char *other_values[1] ;
			char *other_entrys[1] ;
			other_values[0]= (char*)calloc(48,sizeof(char));
			other_entrys[0] = (char*)calloc(48,sizeof(char));
			tc_strcpy(other_entrys[0],"客户代号");
			tc_strcpy(other_values[0],values_list[i]);
			printf("执行查询[%s][%s]\n",other_entrys[0],other_values[0]);
			ITKCALL(status = QRY_execute(query_tag,1,other_entrys,other_values,&num_found,&results));
			printf("执行查询结果[%d]\n",status);
			free(other_values[0]);
			free(other_entrys[0]);
			//printf("11111111111111\n");
			if(status !=ITK_ok){
				char * message =NULL;
				EMH_ask_error_text(status, &message);
				printf("查询异常 : \"%d\",\"%s\"\n",status,message);
				MEM_free(message);
				message =NULL;
				return 0;
			}
			
			for(int j =0;j < num_found;j++){
				//记录错误信息
				char item_id1[ITEM_id_size_c + 1] = "\0";
				ITEM_ask_id(results[j],item_id1);
				if(strcmp(item_id,item_id1)!=0){
					ifail = ITEM_unable_to_create;
					//char msg[214] = "\0";
					char * object_string =NULL;
					AOM_ask_value_string(results[j],"object_string",&object_string);

					error_string.append("项目代号[").append(values_list[i]).append("]").append("已经存在于项目[").append(object_string).append("]客户代号中\n");

					if(object_string!=NULL){
						MEM_free(object_string);
						object_string =NULL;
					}
				}
			
			}
			if(results!=NULL){
				MEM_free(results);
				results =NULL;
			}

		}

		//printf("222222222222\n");

		//释放属性
		
		if(values_list!=NULL){
			for(int i = 0 ;i < count;i++){
				if(values_list[i]!=NULL){
					MEM_free(values_list[i]);
					values_list[i] = NULL;
				}
			}
			MEM_free(values_list);
			values_list =NULL;	
		}
    }
	// printf("333333333\n");
	//
	if(ITEM_unable_to_create == ifail){
		//	添加错误信息
		EMH_store_error_s1(EMH_severity_user_error,ERROR_QRY_NOT_FOUND,error_string.c_str());
		error_string.clear();
	}
    	
    
    return ifail;
}

int HX3_post_prop_set_MJ( METHOD_message_t *msg, va_list args )
{
	int ifail = ITK_ok ,
		count = 0,
		form_count = 0;
	tag_t prop_tag =NULLTAG,
		obj_tag=NULLTAG,
		form_tag=NULLTAG, 
		* values_tags =NULL,
		* form_tags =NULL;
	//获取属性对象
	prop_tag = va_arg( args, tag_t ); 
	//获取个数
	count =  va_arg( args, int ); 
	//获取值
	values_tags = va_arg( args, tag_t* ); 

	printf("set prop \n");
	vector<string> vec;
	if(prop_tag!=NULLTAG ){
		//char * name =NULL;
		//获取属性对象
		PROP_ask_owning_object(prop_tag,&obj_tag);
		//获取版本表单
		AOM_ask_value_tags(obj_tag,"IMAN_master_form_rev",&form_count,&form_tags);



		if(form_count > 0){
			//清空属性
			for(int i = 0 ;i < 8;i++){
					char mj_propName[16] = "\0";
					char  mj_propValue[12] = "\0";
					//mj_propValue=(char*)malloc(256*sizeof(char));
					sprintf(mj_propName,"hx3_mjt%d",(i+1));

					ITKCALL(AOM_lock(form_tags[0]));
					ITKCALL(AOM_set_value_string(form_tags[0],mj_propName,mj_propValue));
					ITKCALL(AOM_save(form_tags[0]));

					//free(mj_propValue);
					//mj_propValue =NULL;
			
			}



			char ** value_list =NULL;
			if(count > 0){
				//开辟空间
				value_list=(char**)malloc(count*sizeof(char*));
				for(int i=0;i<count;i++) {
					char * object_string =NULL;
					value_list[i]=(char*)malloc(256*sizeof(char));

					ITKCALL(AOM_ask_value_string(values_tags[i],"object_string",&object_string));
					strcpy(value_list[i],object_string);

					char mj_propName[16] = "\0";
					sprintf(mj_propName,"hx3_mjt%d",(i+1));

					ITKCALL(AOM_lock(form_tags[0]));
					ITKCALL(AOM_set_value_string(form_tags[0],mj_propName,object_string));
					ITKCALL(AOM_save(form_tags[0]));


					if(object_string!=NULL){
						MEM_free(object_string);
						object_string =NULL;
					}
				}
			}
			//设置属性
			ITKCALL(AOM_lock(form_tags[0]));
			ITKCALL(AOM_set_value_strings(form_tags[0],"hx3_mjt",count,value_list));
			ITKCALL(AOM_save(form_tags[0]));
			AOM_unlock(form_tags[0]);
			//请缓存
			if(value_list!=NULL){
				for(int i=0;i<count;i++){
					free(value_list[i]);
					value_list[i] =NULL;
				}
				free(value_list);
				value_list =NULL;
			}

		}
		if(form_tags!=NULL){
			MEM_free(form_tags);
			form_tags =NULL;
		}
		//ITKCALL(AOM_ask_value_string(obj_tag,"object_string",&name));
	}

	return  ifail;
}


int Test_set_string( METHOD_message_t *msg, va_list args )
{

	tag_t prop_tag  = va_arg( args, tag_t ); 
	char * prop_value = va_arg( args, char* ); 

	printf("\nMY_CD9 CODE = >%s \n",prop_value);


	return  0 ;
}


int LP_set_prop( METHOD_message_t *msg, va_list args )
{
	printf("-----------------------------------------\n");
	printf("----------属性判断开始-------------------\n");
	printf("-----------------------------------------\n");
	int ifail = ITK_ok ;
	
	//获取属性对象
	tag_t prop_tag = va_arg( args, tag_t );
	
	//获取值
	char * values = va_arg( args, char* );

	char propContents[1024] = "\0";
	if(prop_tag!=NULLTAG ){
		char * propname = NULL;
		char propOptionName[128] = "\0";
		strcpy(propContents,"\0");
		int isContents = 0;
		//获取属性
		PROP_ask_name(prop_tag,&propname);
		sprintf(propOptionName,"LP_%s_Option",propname);
		printf("首选项名称[%s]\n",propOptionName);
		vector<string> pref_vec;
		getPrefStrings(propOptionName,TC_preference_site, pref_vec);
		strcat(propContents,"属性值:");
		strcat(propContents,values);
		strcat(propContents,",不包含在下列值中:\n");
		for(int i = 0 ;i <pref_vec.size();i++ ){
			if(strcmp(pref_vec[i].c_str(),values)==0)
			{
				isContents = 1;
			}
			strcat(propContents,pref_vec[i].c_str());
			strcat(propContents,"\n");
		}
		
		if(isContents){
			ifail = ITK_ok;
		}else{
			ifail = PROP_unable_to_set_cp_value;

		}

		if(propname!=NULL){
			MEM_free(propname);
			propname =NULL;
		}

	}
	if(ifail != ITK_ok){
		EMH_store_error_s1(EMH_severity_user_error,ifail,propContents);
	}
	printf("-----------------------------------------\n");
	printf("----------------属性判断结束-------------\n");
	printf("-----------------------------------------\n");

	return  ifail;
}

int HX3_post_prop_set_JJ( METHOD_message_t *msg, va_list args )
{
	int ifail = ITK_ok ,
		count = 0,
		form_count = 0;
	tag_t prop_tag =NULLTAG,
		obj_tag=NULLTAG,
		form_tag=NULLTAG, 
		* values_tags =NULL,
		* form_tags =NULL;
	//获取属性对象
	prop_tag = va_arg( args, tag_t ); 
	//获取个数
	count =  va_arg( args, int ); 
	//获取值
	values_tags = va_arg( args, tag_t* ); 

	printf("set prop \n");
	vector<string> vec;
	if(prop_tag!=NULLTAG ){
		//char * name =NULL;
		//获取属性对象
		PROP_ask_owning_object(prop_tag,&obj_tag);
		//获取版本表单
		AOM_ask_value_tags(obj_tag,"IMAN_master_form_rev",&form_count,&form_tags);
		if(form_count > 0){

			//清空属性
			for(int i = 0 ;i < 12;i++){
					char mj_propName[16] = "\0";
					char  mj_propValue[12] = "\0";
					//mj_propValue=(char*)malloc(256*sizeof(char));
					//strcpy(mj_propValue,"");
					sprintf(mj_propName,"hx3_jjt%d",(i+1));

					ITKCALL(AOM_lock(form_tags[0]));
					ITKCALL(AOM_set_value_string(form_tags[0],mj_propName,mj_propValue));
					ITKCALL(AOM_save(form_tags[0]));

					//free(mj_propValue);
					//mj_propValue =NULL;
			
			}

			char ** value_list =NULL;
			if(count > 0){
				//开辟空间
				value_list=(char**)malloc(count*sizeof(char*));
				for(int i=0;i<count;i++) {
					char * object_string =NULL;
					value_list[i]=(char*)malloc(256*sizeof(char));

					ITKCALL(AOM_ask_value_string(values_tags[i],"object_string",&object_string));
					strcpy(value_list[i],object_string);


					char mj_propName[16] = "\0";
					sprintf(mj_propName,"hx3_jjt%d",(i+1));

					ITKCALL(AOM_lock(form_tags[0]));
					ITKCALL(AOM_set_value_string(form_tags[0],mj_propName,object_string));
					ITKCALL(AOM_save(form_tags[0]));

					if(object_string!=NULL){
						MEM_free(object_string);
						object_string =NULL;
					}
				}
			}
			//设置属性
			ITKCALL(AOM_lock(form_tags[0]));
			ITKCALL(AOM_set_value_strings(form_tags[0],"hx3_jjt",count,value_list));
			ITKCALL(AOM_save(form_tags[0]));
			AOM_unlock(form_tags[0]);
			//请缓存
			if(value_list!=NULL){
				for(int i=0;i<count;i++){
					free(value_list[i]);
					value_list[i] =NULL;
				}
				free(value_list);
				value_list =NULL;
			}

		}
		if(form_tags!=NULL){
			MEM_free(form_tags);
			form_tags =NULL;
		}
		//ITKCALL(AOM_ask_value_string(obj_tag,"object_string",&name));
		
	
	}

	return  ifail;
}


int  HX3_regist_runtime_prop(METHOD_message_t* msg, va_list args){
	printf("========================================================\n");
	printf("进入Runtime属性\n");
	printf("========================================================\n");
    double value=0.00;
    int ifail	= ITK_ok;

	tag_t prop_tag = NULL_TAG;
	char ** string_value = NULL;
	//获取属性对象
	prop_tag = va_arg(args,tag_t );
	//获取属性值
    string_value=va_arg(args, char**);

	return ifail;
}


void getAllBomline(tag_t line_tag,vector<tag_t> & line_vec){
	int count  = 0 , ifail =ITK_ok;
	tag_t *lineS = NULL,rev_tag =NULL_TAG;
	ITKCALL(ifail = AOM_ask_value_tag(line_tag,"bl_line_object",&rev_tag));
	line_vec.push_back(rev_tag);
	ITKCALL(ifail = BOM_line_ask_all_child_lines(line_tag,&count,&lineS));
	//遍历所有的子
	for(int i = 0 ;i < count;i++){
		getAllBomline(lineS[i],line_vec);
	}
	//资源释放
	if(lineS!=NULL){
		MEM_free(lineS);
		lineS =NULL;
	}
}

/****************************************
*
*	获取不同的BOM顶层匹配关系
*
*****************************************/
void getBomClassInfo(vector<CLASS_DEFINE_STRUCT> & class_define_vec){
	vector<string> pref_vec;
	getPrefStrings("HXsortmapping",TC_preference_site, pref_vec);
	for(int i = 0;i < pref_vec.size();i++){
		vector<string> vec_1 ;
		Split(pref_vec[i],"/",vec_1);
		if(vec_1.size() != 2){
			continue;
		}
		vector<string> vec_2;
		Split(vec_1[0],"&",vec_2);
		if(vec_2.size() != 3){
			continue;
		}
		CLASS_DEFINE_STRUCT class_struct;
		class_struct.id.assign(vec_2[0]);
		class_struct.class_dis_name.assign(vec_2[1]);
		class_struct.class_rel_name.assign(vec_2[2]);

		vector<string> vec_3;
		Split(vec_1[1],"|",vec_3);
		for(int j = 0 ;j < vec_3.size();j++){
			vector<string> vec_4;
			Split(vec_3[j],":",vec_4);
			if(vec_4.size()!=4){
				continue;
			}
			//TODO
			ATTR_NODE attr_node;
			attr_node.p_attr_id.assign(vec_4[0]);
			attr_node.c_class_name.assign(vec_4[1]);
			attr_node.c_class_id.assign(vec_4[2]);
			attr_node.c_attr_id.assign(vec_4[3]);
			//
			class_struct.attr_node_vec.push_back(attr_node);
		}
		class_define_vec.push_back(class_struct);
	}
}
/***************************************
*
*  获取分类id和分类名称的匹配关系
*
*****************************************/
void getNameIDMapping(map<string,string> & name_id_mapping){
	vector<string> pref_vec;
	getPrefStrings("HXpartname_IDmapping",TC_preference_site, pref_vec);
	for(int i = 0;i < pref_vec.size();i++){
		vector<string> name_id;
		Split(pref_vec[i],":",name_id);
		if(name_id.size()==2){
			name_id_mapping.insert(pair<string,string>(name_id[0],name_id[1]));
		}
	}
}

int  HX3_bom_save(METHOD_message_t* msg, va_list args){
	printf("\n========================================================\n");
	printf("进入保存后操作\n");
	printf("========================================================\n");
    double value=0.00;
    int ifail	= ITK_ok;
	tag_t window_tag = NULL_TAG,top_line =NULL_TAG,top_rev_tag =NULL_TAG, top_classificationObject = NULL_TAG,top_class_tag=NULL_TAG;
	char * top_rev_item_id =NULL ,* top_class_id = NULL,* top_class_name = NULL;
	int classNameCount = 0;
	vector<tag_t> child_rev_vec ;
	vector<CLASS_DEFINE_STRUCT> class_define_vec;
	map<string,string> name_id_mapping;
	//获取首选项，并解析首选项
	getBomClassInfo(class_define_vec);
	getNameIDMapping(name_id_mapping);

	//获取保存的bomwindow
	window_tag = va_arg(args,tag_t );
	if(window_tag ==NULL_TAG)
	{
		return ITK_ok;
	}
	ITKCALL(ifail = BOM_ask_window_top_line(window_tag,&top_line));
	if(top_line == NULL_TAG)
	{
		return ITK_ok;
	}
	ITKCALL(ifail = AOM_ask_value_tag(top_line,"bl_line_object",&top_rev_tag));
	if(top_rev_tag == NULL_TAG)
	{
		return ITK_ok;
	}
	if(!(checkIsTypeOrSubtype(top_rev_tag,"HX3_ZPTRevision") || checkIsTypeOrSubtype(top_rev_tag,"HX3_LJTRevision")))
	{
		printf("类型不匹配 ：HX3_ZPTRevision ，HX3_LJTRevision\n ");
		return ITK_ok;
	}
	
	//获取ITEM_ID判断是否是以“FD、FC”开头
	char id_temp[8] = "\0";
	ITKCALL(ifail = AOM_ask_value_string(top_rev_tag,"item_id",&top_rev_item_id));
	if(top_rev_item_id!=NULL)
	{
		sprintf(id_temp,"%c%c",top_rev_item_id[0],top_rev_item_id[1]);
		if(!(strcmp(id_temp,"FD")==0 || strcmp(id_temp,"FC")==0))
		{
			printf("ID 不匹配 ：FD ，FC \n ");
			MEM_free(top_rev_item_id);
			top_rev_item_id =NULL;
			return ITK_ok;
		}
		MEM_free(top_rev_item_id);
		top_rev_item_id =NULL;
	}
	//获取顶层 REVISION 对应的分类
	ICS_ask_classification_object(top_rev_tag,&top_classificationObject);
	if(top_classificationObject == NULL_TAG)
	{
		printf("顶层对象没有发送到分类\n");
		return  0;
	}
	
	ICS_ask_class_of_classification_obj(top_classificationObject,&top_class_tag);
	ICS_ask_id_name(top_class_tag,&top_class_id,&top_class_name);

	printf("BOM TOP LINE CLASS ID = %s | NAME = %s \n",top_class_id,top_class_name);
	//获取所有的子对应的版本
	getAllBomline(top_line,child_rev_vec);

	//获取分类的名称
	
	for(int j = 0 ;j < class_define_vec.size();j++)
	{
		if(!(strcmp(id_temp,class_define_vec[j].id.c_str())==0 
			&& strcmp(class_define_vec[j].class_dis_name.c_str(),top_class_name)==0
			&& strcmp(class_define_vec[j].class_rel_name.c_str(),top_class_id)==0))
		{
			continue;
		}
		vector<ATTR_NODE> attr_node_vec = class_define_vec[j].attr_node_vec;
		//获取遍历版本的分类
		for(int w = 1;w < child_rev_vec.size();w++)
		{
			//
			int child_rev_class_names_count = 0,child_attr_count = 0;
			char * child_rev_class_name =NULL,*child_rev_class_id =NULL,**child_attr_names =NULL,**child_attr_values =NULL;
			tag_t child_classfication_tag = NULL_TAG, child_class_tag = NULL_TAG,*child_attr_list = NULL;
			//获取子的分类的信息
			ICS_ask_classification_object(child_rev_vec[w],&child_classfication_tag);
			if(child_classfication_tag == NULL_TAG)
			{
				continue;
			}
			ICS_ask_class_of_classification_obj(child_classfication_tag,&child_class_tag);
			ICS_ask_id_name(child_class_tag,&child_rev_class_id,&child_rev_class_name);
			//ICS_ask_attributes(child_class_tag,&child_attr_count,&child_attr_list);
			ICS_ask_attributes_of_classification_obj(child_classfication_tag,&child_attr_count,&child_attr_names,&child_attr_values);
			//对配置循环
			for(int w_1 = 0;w_1 < attr_node_vec.size();w_1++)
			{
				if(!(strcmp(attr_node_vec[w_1].c_class_id.c_str(),child_rev_class_id)==0 
					&&strcmp(attr_node_vec[w_1].c_class_name.c_str(),child_rev_class_name)==0 ))
				{
					continue;
				}
				for(int w_2 = 0 ;w_2 < child_attr_count;w_2++){
					printf("attr[%d] name = %s | value =%s \n",w_2,child_attr_names[w_2],child_attr_values[w_2]);
					
				}

			}
			if(child_attr_names !=NULL)
			{
				for(int i = 0;i < child_attr_count;i++){
					MEM_free(child_attr_names[i]);
					child_attr_names[i] =NULL;
				}
				MEM_free(child_attr_names);
				child_attr_names =NULL;
			}

			if(child_attr_values !=NULL)
			{
				for(int i = 0;i < child_attr_count;i++){
					MEM_free(child_attr_values[i]);
					child_attr_values[i] =NULL;
				}
				MEM_free(child_attr_values);
				child_attr_values =NULL;
			}

			if(child_attr_list == NULL)
			{
				MEM_free(child_attr_list);
				child_attr_list =NULL;
			}
			if(child_rev_class_id!=NULL)
			{
				MEM_free(child_rev_class_id);
				child_rev_class_id =NULL;
			}
			if(child_rev_class_name!=NULL)
			{
				MEM_free(child_rev_class_name);
				child_rev_class_name =NULL;
			}
		}
	}
	
	//释放资源
	FREE_ALL:
	if(top_class_id!=NULL){
		MEM_free(top_class_id);
		top_class_id =NULL;
	}
	if(top_class_name!=NULL){
		MEM_free(top_class_name);
		top_class_name =NULL;
	}

	printf("========================================================\n");
	printf("结束保存后操作\n");
	printf("========================================================\n");

	return 0;
}


int  HX3_mod_date(METHOD_message_t* msg, va_list args){
	printf("========================================================\n");
	printf("进入HX3_mod_date保存后操作\n");
	printf("========================================================\n");
    double value=0.00;
    int ifail	= ITK_ok;

	tag_t prop_tag = NULL_TAG;
	logical isNew = NULL;
	


	printf("========================================================\n");
	printf("结束HX3_mod_date保存后操作\n");
	printf("========================================================\n");

	return 0;
}




/************************************************
*
* 检查对象属性不能为空
*  -attachement = target 或者 reference   获取目标或者引用
*  -includeType = ItemRevision,HX3_WLRevision  引用目标下的对象
*  -relation = IMAN_master_form_rev,IMAN_specification 对象下的关系
*  -targetType = ItemRevisionMastreForm,Form   获取属性的对象的类型
*  -properties = hx3_gy,hx3_wl  需要获取的属性
*
*************************************************/
int HX3_check_prop_is_not_empty(EPM_rule_message_t msg)
{
	int ifail = ITK_ok,arg_cnt = 0,i = 0,att_cnt = 0;
	tag_t task_tag = NULLTAG ,rootTask_tag = NULLTAG, *attachments =NULL;
	char *arg = NULL,*argflag = NULL, *argvalue = NULL,type_class[WSO_object_type_size_c+1] ="\0";
	string attachement,includeType,relation,targetType,properties;
	vector<string> includeTypeVec,relationVec,targetTypeVec,propertiesVec;

	EPM_decision_t decision = EPM_go;
	task_tag = msg.task;
	if(task_tag == NULLTAG)
	{
		return EPM_nogo;
	}
	//获得参数
	arg_cnt = TC_number_of_arguments(msg.arguments);
	for (i=0;i<arg_cnt;i++)
	{
			arg = TC_next_argument(msg.arguments);
			ITKCALL(ifail = ITK_ask_argument_named_value((const char*)arg, &argflag, &argvalue));
			if (stricmp(argflag, "attachement") == 0)
			{
				if(argvalue != NULL)
				{
					attachement.assign(argvalue);
				}
			}
			else if(stricmp(argflag, "includeType") == 0)
			{
				if(argvalue != NULL)
				{
					includeType.assign(argvalue);
				}
			}
			else if(stricmp(argflag,"relation") == 0)
			{
				if( argvalue!= NULL)
				{
					relation.assign(argvalue);
				}
			}	
			else if(stricmp(argflag,"targetType") == 0)
			{
				if( argvalue!= NULL)
				{
					targetType.assign(argvalue);
				}
			}
			else if(stricmp(argflag,"properties") == 0)
			{
				if( argvalue!= NULL)
				{
					properties.assign(argvalue);
				}
			}
			//释放资源
			if(argflag != NULL){
				MEM_free(argflag);
				argflag = NULL;
			}
			if(argvalue != NULL){
				MEM_free(argvalue);
				argvalue = NULL;
			}
	}
	
	ITKCALL(ifail = EPM_ask_root_task(task_tag, &rootTask_tag));

	if(strcmp(attachement.c_str(),"target") == 0)
	{
		ITKCALL(ifail = EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments));
	}else if(strcmp(attachement.c_str(),"reference") == 0)
	{
		ITKCALL(ifail = EPM_ask_attachments(rootTask_tag, EPM_reference_attachment, &att_cnt, &attachments));
	}else{
		return EPM_nogo;
	}

	for( i = 0; i < att_cnt; i++ )
	{
		//获取对象的类型
		/**********************************************
		 *	对象类型：JK8DerPIdenNOAppForm
		 *	对象类型：JK8SpecPINOAppForm
		 *	对象类型：JK8NewPIdenNOAppForm
		 *	对象类型：JK8NPModINOAppForm
		 **********************************************/
		ITKCALL( WSOM_ask_object_type(attachments[i], type_class));
		printf("对象类型：%s \n",type_class);
		if(strcmp(type_class,"JK8DerPIdenNOAppForm") ==0 
			||strcmp(type_class,"JK8SpecPINOAppForm") ==0 
			||strcmp(type_class,"JK8NewPIdenNOAppForm") ==0 
			||strcmp(type_class,"JK8NPModINOAppForm") ==0 )
		{
		
		
		}


	}
	if(attachments!=NULL){
		MEM_free(attachments);
		attachments = NULL;
	}

	return decision;
}

int HX3_check_prop_is_not_empty_2(EPM_rule_message_t msg)
{
	EPM_decision_t decision = EPM_go;
/*
	int ifail = ITK_ok, arg_cnt = 0, att_cnt = 0, i, j, k, m,p,q, pref_count = 0, bvr_cnt = 0, child_cnt = 0, 
		status_attr_id = 0, rev_attr_id = 0, form_count =0, value_count = 0,n_instances = 0,
		factory_count = 0, num = 0, bvr_count = 0;
	tag_t task_tag = NULLTAG, rootTask_tag = NULLTAG, type_tag = NULLTAG, rev_rule_tag = NULLTAG;
	tag_t *attachments = NULL, *bvrs = NULL, *child_lines = NULL, child_rev_tag = NULLTAG, item_tag = NULLTAG,
		rev_tag = NULLTAG, user = NULLTAG;
	char *arg = NULL, *flag = NULL, *value = NULL, **values = NULL, type_class[WSO_object_type_size_c+1], 
		item_id[ITEM_id_size_c+1], rev_id[ITEM_id_size_c+1], *argflag =NULL,*argvalue=NULL ,
		arg_rev_rule[128] = "",arg_status[128] = "",arg3value[128]="",arg_debug[10]="", userid[33]="";


	tag_t bomWindow = NULLTAG, bom_top_line = NULLTAG, bom_config_rule = NULLTAG;
	map<string,int> errMap;
	vector<string> status_vec;
	//map<string,string> zuhaoMap;
	EPM_decision_t decision = EPM_go;
	logical debug = true;
	ECHO("*************************************************************\n");
	ECHO("*                 HZ_Check_BOM_Condition is comming !            *\n");
	ECHO("*************************************************************\n");
	task_tag = msg.task;
	if(task_tag == NULLTAG)
	{
        ifail = ITK_ok;
		//goto end_handler;
		return EPM_nogo;
	}
	tag_t rootTask = NULLTAG;
	status_vec.clear();
	status_vec.push_back("working");
	status_vec.push_back("H9_M0");
	status_vec.push_back("H9_M1");
	status_vec.push_back("H9_M2");
	status_vec.push_back("H9_P");
	status_vec.push_back("H9_M3");
	status_vec.push_back("H9_B");
	status_vec.push_back("H9_D");
	status_vec.push_back("H9_Released");

	//获得参数
	arg_cnt = TC_number_of_arguments(msg.arguments);
	for (i=0;i<arg_cnt;i++)
	{
			arg = TC_next_argument(msg.arguments);
			ITKCALL(ifail = ITK_ask_argument_named_value((const char*)arg, &argflag, &argvalue));
			if (stricmp(argflag, "rev_rule") == 0)
			{
				if(argvalue != NULL)
				{
					strcpy(arg_rev_rule,argvalue);
				}
			}
			else if(stricmp(argflag, "status") == 0)
			{
				if(argvalue != NULL)
				{
					strcpy(arg_status,argvalue);
				}
			}
			else if(stricmp(argflag,"debug") == 0)
			{
				if( argvalue!= NULL)
				{
				strcpy(arg_debug,argvalue);
				if( strcmp( arg_debug, "true") == 0)
				{
					debug = true;
				}
				else
				{
					debug = false;
				
				}
				}
			}	
	}
	if( strlen(arg_status) <2 )
	{
		string key_id;
		key_id.assign("缺少status参数");
		errMap.insert(pair<string,int>(key_id,HANDLER_ARGUMENT_ERROR));
		return EPM_nogo;
	}
	
	ifail = CFM_find(arg_rev_rule, &rev_rule_tag );

	ITKCALL(ifail = EPM_ask_root_task(task_tag, &rootTask_tag));

	ITKCALL(AOM_ask_owner(rootTask_tag, &user));
	
	ITKCALL(SA_ask_user_identifier( user , userid));
	ITKCALL(ifail = EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments));
	if( debug )
	ECHO("DEBUG:   find %d target\n", att_cnt);	
	for( i = 0; i < att_cnt; i++ )
	{
		ITKCALL( WSOM_ask_object_type(attachments[i], type_class));
		if (((strstr(type_class,"Revision") != NULL) || (strstr(type_class,"revision") != NULL))
		&&(strstr(type_class,"Master") == NULL) &&(strstr(type_class,"master") == NULL)
		&& (strstr(type_class,"BOM") ==NULL) && (strstr(type_class,"bom") ==NULL) && (strstr(type_class,"Bom") == NULL))
		{
			rev_tag = attachments[i];
			ITKCALL(ITEM_ask_item_of_rev(rev_tag, &item_tag));
			ITKCALL(ITEM_ask_id(item_tag, item_id));
			tag_t	ebom_view = NULLTAG, ebom_bvr = NULLTAG, ebom_window = NULLTAG, ebom_line = NULLTAG,
				dbom_view = NULLTAG,dbom_bvr = NULLTAG;
			ifail = getBomView(rev_tag, BOM_VIEWTYPE, &ebom_view, &ebom_bvr, 1);	

			if( ebom_view != NULLTAG )
			{
				ITKCALL( BOM_create_window( &ebom_window ) );
				if( rev_rule_tag != NULLTAG)
					ITKCALL( BOM_set_window_config_rule(ebom_window, rev_rule_tag));
				ITKCALL( BOM_set_window_top_line_bvr( ebom_window, ebom_bvr, &ebom_line ) );
				CycleBOM(ebom_line,userid,arg_status,status_vec,errMap,debug);
				ITKCALL(BOM_close_window(ebom_window));
			}
		}
	
	}
	DOFREE(attachments);
	if( debug )
		ECHO("DEBUG:   errMap.size is %d\n", errMap.size());	
	if( errMap.size() > 0 )
		decision = EPM_nogo;
	else
		decision = EPM_go;
	map<string,int>::iterator err_it;
	for( err_it = errMap.begin(); err_it != errMap.end(); err_it++ )
	{
		ECHO("DEBUG:  err_it is %s\n", err_it->first.c_str());
		EMH_store_error_s1(EMH_severity_information,err_it->second, err_it->first.c_str());
	}
	errMap.clear();
	ECHO("\n************************************************************\n");
	ECHO("*					HZ_Check_BOM_Condition is end!					 *\n");
	ECHO("*************************************************************\n");
	*/
	return decision;
}