#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>
#include <stdlib.h>
#include <tccore/aom.h>
#include <tc/emh.h>
#include <ict/ict_userservice.h>
#include <tc/tc.h>
#include <tccore/tctype.h>
#include <sa/tcfile.h>
#include <ss/ss_errors.h>
#include <ics/ics.h>
#include <ics/ics2.h>


int jk_test_ask_icoAttribute(EPM_action_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;

	string errorMessage="";
	//获取当前触发的任务
	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);//对象类型
		logical    isClassified ;
		ITKCALL(ICS_is_wsobject_classified(attachments[i],&isClassified));//判断是否已经分类
		if(isClassified)
		{
			tag_t classObj,attribute_tag;
			ICS_ask_classification_object(attachments[i],&classObj);
			tag_t ics_tag;
			char * class_id = NULL;
			int  	theAttributeCount;
			ICS_view_attribute_descriptor_p_t  attributes;
			ICS_view_descriptor_p_t   theViewDescriptor =NULL;
			ITKCALL( ICS_ico_ask_class_tag(classObj,&ics_tag));
			ITKCALL(ICS_ico_ask_class(classObj,&class_id));
			
			ITKCALL(ICS_view_describe(class_id,"","",FALSE,&theViewDescriptor));
			theAttributeCount = theViewDescriptor->attributeCount;
			attributes = theViewDescriptor->attributes;
			for(int i = 0; i < theAttributeCount;i++){
				//WriteLog("ICO attr id = %d \n",attributes[i].id);
				//WriteLog("ICO attr name = %s \n",attributes[i].name);
				//WriteLog("ICO attr format = %d \n",attributes[i].format);
				string attr_name;
				cout<<"id--------------"<<attributes[i].id<<endl;
				cout<<"format----------------"<<attributes[i].format<<endl;
				cout<<"name-------------------"<<attributes[i].name<<endl;
				if(strcmp(attributes[i].name,"适用产品识别号")==0)
				{
					ITKCALL(ifail=ICS_ask_attribute(ics_tag,"适用产品识别号",&attribute_tag));
					char *classValue=NULL;
					if(ifail==0)
					{
						cout<<"有适用产品识别号------------------>"<<endl;
						ICS_ask_attribute_value(classObj,"适用产品识别号",&classValue);
						cout<<"适用产品识别号为------------------>"<<classValue<<endl;
					}
					if(classValue=NULL)
					{
						MEM_free(classValue);
						classValue=NULL;
					}
				}

			}
			if(class_id=NULL)
			{
				MEM_free(class_id);
				class_id=NULL;
			}
		}


		/*int          theAttributeCount;
		int*          theAttributeValCounts;
		char***       theAttributeValues ; 
		int*          theAttributeIds;
		ICS_ico_ask_all_attributes(classObj,&theAttributeCount,&theAttributeIds,&theAttributeValCounts,&theAttributeValues);*/




		/*ITKCALL(ifail=ICS_ask_attribute(classObj,"产品识别号",&attribute_tag));
		char *classValue=NULL;
		if(ifail==0)
		{
		cout<<"有产品识别号------------------>"<<endl;
		ICS_ask_attribute_value(classObj,"产品识别号",&classValue);
		cout<<"产品识别号为------------------>"<<classValue<<endl;
		}
		if(classValue=NULL)
		{
		MEM_free(classValue);
		classValue=NULL;
		}*/

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

}
