#ifndef _cplusplus
#ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE
#endif
#endif

#include"erp_send_item.h"

#ifdef WIN32
#pragma warning( push )
#pragma warning( disable: 4311 )
#pragma warning( disable: 4312 )
#endif

char control_plan_fields[29][45] = {
	"STAGE",//阶段 tm2_cpjd
	"KEY_PHONE",//主要联系人电话  tm2_zylxdh
	"cust_approval",//客户审批  tm2_gkpz
	"KEY_CONTACT",//主要联系人 tm2_zylxr
	"DATE_ORIG",//编制日期 //5 tm2_bzrq
	"DATE_REV",//修订日期  tm2_xdrq
	"PLAP_NO",//控制计划编号  tm2_kzjhbh
	"SOR",//SOR tm2_sor
	"CORE_TEAM",//核心小组  tm2_hxxz
	"Customer_engineering_approval",//顾客工程批准/日期 //10 tm2_gkgcpz
	"Part_Num_Latest_change",//零件号/最新更改程度  tm2_zxggcd
	"Supplier_Plant_Approval",//供方/工厂批准/日期 tm2_gfgcpz
	"Customer_quality_approval",//顾客质量批准/日期 tm2_gkzlpz
	"Customer_Part_Number",//客户图纸编号 tm2_khtzbh
	"Part_Name_Description",//零件名称/描述//15  tm2_ljmc
	"Supplier_Plant",//供方/工厂 tm2_gfgc
	"Supplier_Code",//供方代号 tm2_gfdh
	"Mode_year",//车型/年度 tm2_cxnd
	"Other_approval_1",//其他批准/日期// tm2_qtpzrq1
	"Other_approval_2",//其他批准/日期//20 tm2_qtpzrq2
	"KEY_CONNECT",//KEY键
	"CHANGE_LEV",//变更阶段 tm2_xgdj
	"STATUS",
	"ORIGINER",
	"ERROR_MSG",//25
	"COMMIT_TIME",
	"OPERATE_TIME",
	"BATCH_ID",
	"ORIGINER_SYS"//29
};
typedef struct{
	string STAGE;
	string KEY_PHONE;
	string cust_approval;
	string KEY_CONTACT;
	string DATE_ORIG;//5
	string DATE_REV;
	string PLAN_NO;
	string SOR;
	string CORE_TEAM;
	string Customer_engineering_approval;//10
	string Part_Num_Latest_change;
	string Supplier_Plant_Approval;
	string Customer_quality_approval;
	string Customer_Part_Number;
	string Part_Name_Description;//15
	string Supplier_Plant;
	string Supplier_Code;
	string Mode_year;
	string Other_approval_1;
	string Other_approval_2;//20
	string KEY_CONNECT;
	string CHANGE_LEV;//业务数据结束
	string STATUS;
	string ORIGINER;
	string ERROR_MSG;//25
	string COMMIT_TIME;
	string OPERATE_TIME;
	string BATCH_ID;
	string ORIGINER_SYS;//29
}CONTROL_PLAN_STRUCT;

char comtrol_plan_array_fields[20][45]={
	"Part_Process_Number",//tm2_ljgybh
	"Process_Name_Description",//tm2_gcmcms
	"Machine_Device",//tm2_jqsbgzjj
	"Characteristics_Bubbled",//tm2_qptbh
	"Characteristics_Size",//5//tm2_cc
	"Characteristics_No",//tm2_xh
	"Characteristics_Product",//tm2_cp
	"Characteristics_Process",//tm2_gc
	"Special_Char_Class",//tm2_tstxfl
	"Specification_Tolerance",//10//tm2_cpgcgggc
	"UP_SPEC",//tm2_spc
	"DOWN_SPEC",//tm2_xpc
	"Evaluation_Measurement",//tm2_pgclff
	"Sample_Size",//tm2_rl
	"Sample_Freq",//15//tm2_pl
	"Resp",//tm2_fzr
	"Control_Method",//tm2_kzff
	"Operation_criteria",//tm2_czgf
	"Reaction_Plan",//tm2_fyjh
	"KEY_CONNECT"//20
	
};

typedef struct{
	string Part_Process_Number;
	string Process_Name_Description;
	string Machine_Device;
	string Characteristics_Bubbled;
	string Characteristics_Size;//5
	string Characteristics_No;
	string Characteristics_Product;
	string Characteristics_Process;
	string Special_Char_Class;
	string Specification_Tolerance;//10
	string UP_SPEC;
	string DOWN_SPEC;
	string Evaluation_Measurement;
	string Sample_Size;
	string Sample_Freq;//15
	string Resp;
	string Control_Method;
	string Operation_criteria;
	string Reaction_Plan;
	string KEY_CONNECT;//20
}CONTROL_PLAN_ARRAY_STRUCT;

//-----------------------------------

char erp_part_fields[28][40]={
	"PART_NAMBER",
	"PART_NAME",
	"REVISION",
	"SPECIFICATION",
	"CUSTOMER_PART_NUMBER",//5
	"PART_MODEL",
	"STOCK_KEEPING_UNIT",
	"SHELF_LIFE",
	"SOURCE",
	"FORMULA_TYPE",//10
	"CLASSIFICATION",
	"SALE_CLASSIFICATION",
	"INDICATIVE_PRICE",
	"APPLICANT",
	"APPLICANT_DATE",//15
	"PART_TYPE",
	"VALID_DATE",
	"INVALID_DATE",
	"STATUS",
	"ORIGINER",//20
	//"ERROR_MSG",
	"COMMIT_TIME",
	//"OPERATE_TIME",
	"BATCH_ID",
	//"PUID",//25
	"ORIGINER_SYS",
	"POWDER_NO",
	"CUSTOMER_NAME",
	"WEIGHT",
	"BLENDING_WAY",
	"BASKET"
};
//--------------------------------
typedef struct{
	string PART_NAMBER;
	string PART_NAME;
	string REVISION;
	string SPECIFICATION;
	string CUSTOMER_PART_NUMBER;//5
	string PART_MODEL;
	string STOCK_KEEPING_UNIT;
	string SHELF_LIFE;
	string SOURCE;
	string FORMULA_TYPE;//10
	string CLASSIFICATION;
	string SALE_CLASSIFICATION;
	string INDICATIVE_PRICE;
	string APPLICANT;
	string APPLICANT_DATE;//15
	string PART_TYPE;
	string VALID_DATE;
	string INVALID_DATE;
	string STATUS;
	string ORIGINER;//20
	//string ERROR_MSG;
	string COMMIT_TIME;
	//string OPERATE_TIME;
	string BATCH_ID;
	//string PUID;//25
	string ORIGINER_SYS;
	string POWDER_NO;
	string CUSTOMER_NAME;
	string WEIGHT;
	string BLENDING_WAY;
	string BASKET;
}ERP_PART_STRUCT;
//------------------------------------
char erp_bom_fields[21][40]={
	"SEQ_NUMBER",
	"P_NUMBER",
	"P_REV",
	"PART_NUMBER",
	"PART_REV",//5
	"QUANTITY",
	"UNIT",
	"ACQUISITION",
	"REPLACE_TYPE",
	"VALID_DATE",//10
	"INVALID_DATE",
	"STATUS",
	"ORIGINER",
	"COMMIT_TIME",
	"BATCH_ID",//15
	"ORIGINER_SYS",
	"SCALE",
	"P_DEVIATION",
	"M_DEVIATION",
	"BASKET_BOMLINE",
	"BL_SQUENCE"
};
//---------------------------------
typedef struct{
	string SEQ_NUMBER;
	string P_NUMBER;
	string P_REV;
	string PART_NUMBER;
	string PART_REV;//5
	string QUANTITY;
	string UNIT;
	string ACQUISITION;
	string REPLACE_TYPE;
	string VALID_DATE;//10
	string INVALID_DATE;
	string STATUS;
	string ORIGINER;
	string COMMIT_TIME;
	string BATCH_ID;//15
	string ORIGINER_SYS;
	string SCALE;
	string P_DEVIATION;
	string M_DEVIATION;
	string BASKET_BOMLINE;
	string BL_SQUENCE;
}ERP_BOM_STRUCT;
//----------------------------------
char hl_part_fields[21][40]={
	"PART_NAMBER",
	"PART_NAME",
	"REVISION",
	"SPECIFICATION",
	//"CUSTOMER_PART_NUMBER",
	//"PART_MODEL",
	"STOCK_KEEPING_UNIT",//5
	"SHELF_LIFE",
	"SOURCE",
	"FORMULA_TYPE",
	"CLASSIFICATION",
	//"SALE_CLASSIFICATION",
	//"INDICATIVE_PRICE",
	"APPLICANT",//10
	"APPLICANT_DATE",
	"PART_TYPE",
	"VALID_DATE",
	"INVALID_DATE",
	"STATUS",//15
	"ORIGINER",
	//"ERROR_MSG",
	"COMMIT_TIME",
	//"OPERATE_TIME",
	"BATCH_ID",
	//"PUID",
	"ORIGINER_SYS",
	"BLENDING_WAY",
	"BASKET"

};
typedef struct{
	string PART_NAMBER;
	string PART_NAME;
	string REVISION;
	string SPECIFICATION;
	//string CUSTOMER_PART_NUMBER;
	//string PART_MODEL;
	string STOCK_KEEPING_UNIT;
	string SHELF_LIFE;
	string SOURCE;
	string FORMULA_TYPE;
	string CLASSIFICATION;
	//string SALE_CLASSIFICATION;
	//string INDICATIVE_PRICE;
	string APPLICANT;
	string APPLICANT_DATE;
	string PART_TYPE;
	string VALID_DATE;
	string INVALID_DATE;
	string STATUS;
	string ORIGINER;
	//string ERROR_MSG;
	string COMMIT_TIME;
	//string OPERATE_TIME;
	string BATCH_ID;
	//string PUID;
	string ORIGINER_SYS;
	string BLENDING_WAY;
	string BASKET;
}HL_PART_STRUCT;

char hl_bom_fields[22][40]={
	"SEQ_NUMBER",
	"P_NUMBER",
	"P_REV",
	"PART_NUMBER",
	"PART_REV",//5
	"QUANTITY",
	"UNIT",
	"ACQUISITION",
	"REPLACE_TYPE",
	"VALID_DATE",//10
	"INVALID_DATE",
	"STATUS",
	"ORIGINER",
	"COMMIT_TIME",
	"BATCH_ID",//15
	"ORIGINER_SYS",
	"WASTAGE",
	"SCALE",
	"P_DEVIATION",
	"M_DEVIATION",
	"BASKET_BOMLINE",
	"BL_SQUENCE"
};

typedef struct{
	string SEQ_NUMBER;
	string P_NUMBER;
	string P_REV;
	string PART_NUMBER;
	string PART_REV;//5
	string QUANTITY;
	string UNIT;
	string ACQUISITION;
	string REPLACE_TYPE;
	string VALID_DATE;//10
	string INVALID_DATE;
	string STATUS;
	string ORIGINER;
	string COMMIT_TIME;
	string BATCH_ID;//15
	string ORIGINER_SYS;
	string WASTAGE;
	string SCALE;
	string P_DEVIATION;
	string M_DEVIATION;
	string BASKET_BOMLINE;
	string BL_SQUENCE;
}HL_BOM_STRUCT;


//----------------------------------------------------------
char part_fields[18][40]={
"PART_NUMBER",
"PART_NAME",
"PART_REV",
"STATUS",
"BATCH_ID",//5
"COMMIT_TIME",
"ORIGINER",
"PART_SPEC",
"CLASS_CODE",
"SOURCE",//10
"PROJ_CODE",
"UNIT",
"RELEASED_STATUS",
"INVALID_DATE",
"CUSTOMER_PART_NUMBER",//15
"IS_STANDARD",
"CREATER",
"CREATE_DATE"
};

typedef struct{
string PART_NUMBER;
string PART_NAME;
string PART_REV;
string STATUS;
string BATCH_ID;//5
string COMMIT_TIME;
string ORIGINER;
string PART_SPEC;
string CLASS_CODE;
string SOURCE;//10
string PROJ_CODE;
string UNIT;
string RELEASED_STATUS;
string INVALID_DATE;
string CUSTOMER_PART_NUMBER;//15
string IS_STANDARD;
string CREATER;
string CREATE_DATE;
string SCALE;
string P_DEVIATION;
string M_DEVIATION;

}PART_STRUCT;

char bom_fields[17][40]={
"SEQ_NUMBER",
"P_NUMBER",
"RELEASED_DATE",
"PART_NUMBER",
"VALID_DATE",//5
"INVALID_DATE",
"QUANTITY",
"ASSEM_QUANTITY",
"OTHERS",
"ULLAGE",//10
"JOB_NUMBER",
"REPLACE_TYPE",
"BATCH_ID",
"ORIGINER",
"COMMIT_TIME",//15
"OPERATE_TIME",
"STATUS"
};

typedef struct{
string SEQ_NUMBER;
string P_NUMBER;
string RELEASED_DATE;
string PART_NUMBER;
string VALID_DATE;//5
string INVALID_DATE;
string QUANTITY;
string ASSEM_QUANTITY;
string OTHERS;
string ULLAGE;//10
string JOB_NUMBER;
string REPLACE_TYPE;
string BATCH_ID;
string ORIGINER;
string COMMIT_TIME;//15
string OPERATE_TIME;
string STATUS;

}BOM_STRUCT;


extern "C" int POM_AM__set_application_bypass(logical bypass);

/**
*获取分群码的匹配mapping
*/
void get_class_code_mapping(map<string,string> &pdm_wpm_attribute_map){
	vector<string> pref_vec;
	getPrefStrings("Cust_ERP_PLM_Class_Code_Mapping",TC_preference_site, pref_vec);
	for(int i = 0 ;i < pref_vec.size();i++){
		vector<string> values ;
		Split(pref_vec[i],"@",values);
		if(values.size() == 2){
			pdm_wpm_attribute_map.insert(pair<string,string>(values[0],values[1]));
			printf("CLASS_CODE PLM = %s , ERP = %s \n",values[0],values[1]);
		}
	}
}
/**
* 获取分群码
*/
void get_class_code(map<string,string> code_map  ,string &value){
	vector<int> vec;
	vec.push_back(7);
	vec.push_back(4);
	for(int i = 0;i < vec.size();i++)
	{
		string v_str = value.substr(0,vec[i]);
		map<string,string>::iterator node;
		node = code_map.find(v_str);
		if(node != code_map.end())
		{
			
			value = node->second;
			printf("\n====找到分群码%s\n",value.c_str());
			break;
		}
	}
}


/**
*拼接字符串
*
*/
void get_erp_name(tag_t value_tag, vector<string> prop_name,string &erp_name,tag_t item_tag){
	int ifail = ITK_ok;
	char * str_value = NULL;
	string erp_name_t;
	tag_t descript = NULLTAG;
	for(int i = 0 ;i < prop_name.size();i++){
		//ITKCALL(ifail = AOM_ask_descriptor(value_tag,prop_name[i].c_str(),descript));
		//PROPDESC_ask_display_values_from_LOV_attachments
		//PROPDESC_ask_lov
		//AOM_UIF_ask_value
		if(strcmp(prop_name[i].c_str(),"object_name")==0){
			ITKCALL(ifail = AOM_UIF_ask_value(item_tag,prop_name[i].c_str(),&str_value));
		}else{
			ITKCALL(ifail = AOM_UIF_ask_value(value_tag,prop_name[i].c_str(),&str_value));
		}
		if(str_value!=NULL){
			if(strcmp(str_value,"")!=0){
				erp_name_t.append("/").append(str_value);
			}
			MEM_free(str_value);
			str_value = NULL;
		}
	}
	if(erp_name_t.length() > 0 && erp_name_t.c_str()[0]=='/'){
		erp_name = erp_name_t.substr(1,(erp_name_t.length()-1));
	}
}


/**
*	获取对象的版本的属性
*
*/
int jf_erp_send_all_item(map<tag_t,string> rev_map,vector<ERP_PART_STRUCT> &part_vec,string batchid,char * nowtime){
	int ifail = ITK_ok;
	tag_t tag_value = NULLTAG,item = NULLTAG;
	date_t p;
	//	char *  value =NULL;
	char ** str_values = NULL ,*value = NULL;
	char  item_type[ITEM_type_size_c + 1] ="";
	char rev_id[ITEM_id_size_c+1]="";
	char item_id[ITEM_id_size_c+1]="",item_name[ITEM_id_size_c+1]="";

	map<tag_t,string>::iterator rev_it;
	for( rev_it = rev_map.begin(); rev_it != rev_map.end(); rev_it++ )
	{
		
		
		int formcount = 0;
		int rev_count = 0;
		tag_t * rev_tags = NULL;
		tag_t * formtags = NULL;
		ERP_PART_STRUCT one_elem;
		ITEM_ask_item_of_rev(rev_it->first, &item) ;
		ITEM_list_all_revs(item,&rev_count,&rev_tags);
		if(rev_count > 1){
			MEM_free(rev_tags);
			rev_tags = NULL;
			continue;
		}

		ITEM_ask_id(item, item_id);
		ITEM_ask_name(item, item_name);
		ITEM_ask_type(item,item_type);
		if((strcmp(item_type,"TM2_materials")==0||strcmp(item_type,"TM2_auxiliary")==0||strcmp(item_type,"TM2_powder")==0||strcmp(item_type,"TM2_rawpowder")==0)!=1){
			printf("[%s]不属于物料类型\n",item_type);
			continue;
		}else{
			//one_elem.PART_TYPE.assign(item_type);
			one_elem.PART_NAMBER.assign(item_id);
			one_elem.PART_NAME.assign(item_name);
			
		}
		if(strcmp(item_type,"TM2_materials")==0){
			one_elem.PART_TYPE.assign("成品");
		}else if(strcmp(item_type,"TM2_auxiliary")==0){
			one_elem.PART_TYPE.assign("配套产品");
		}else if(strcmp(item_type,"TM2_powder")==0){
			one_elem.PART_TYPE.assign("配方粉");
		}else {
			one_elem.PART_TYPE.assign("原材料粉");
		}

		ITEM_ask_rev_id(rev_it->first, rev_id);
		one_elem.REVISION.assign(rev_id);
		AOM_ask_value_tags(rev_it->first,"IMAN_master_form_rev",&formcount,&formtags);
		//对象获取单位属性
		ifail = ITEM_ask_unit_of_measure(item,&tag_value);
		if(ifail == ITK_ok&& tag_value!=NULLTAG){
			
			UOM_ask_symbol(tag_value,&value);
			if(value!=NULL){
				one_elem.STOCK_KEEPING_UNIT.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.STOCK_KEEPING_UNIT.assign("");
			}
		}else{
			one_elem.STOCK_KEEPING_UNIT.assign("");
		}
		
		
		ifail = SA_ask_current_groupmember(&tag_value);
		if(ifail == ITK_ok)
		{
			tag_t user_tag = NULLTAG;
			SA_ask_groupmember_user(tag_value,&user_tag);
			if(user_tag!=NULLTAG)
			{
				char user_id_temp[SA_user_size_c+1] ="";
				ifail = SA_ask_user_identifier(user_tag,user_id_temp);
				one_elem.ORIGINER.assign(user_id_temp);	
			}
		}
		//版本获取属性

		//版本表单获取属性
		if(formcount!=0){
			//-----------公用属性-------------------sqr sqsj
			
			tag_t user_tag = NULLTAG;
				AOM_ask_value_tag(formtags[0],"owning_user",&user_tag);//创建人
				if(user_tag !=NULLTAG){
					AOM_ask_value_string(user_tag,"user_name",&value);
				if(value!=NULL){
					one_elem.APPLICANT.assign(value);
					MEM_free(value);
					value = NULL;
				}else{
					one_elem.APPLICANT.assign("");
				}
				}

				ifail = AOM_ask_value_date(formtags[0],"creation_date",&p);//创建人创建时间
				if(ifail==ITK_ok&&p.year!=0){//CREATE_DATE
					char date_value_str[128] = "";
					if(p.year !=0){
						sprintf(date_value_str,"%04d-%02d-%02d %02d:%02d:%02d",p.year,p.month+1 ,p.day,p.hour,p.minute,p.second);
						one_elem.APPLICANT_DATE.assign(date_value_str);
					}
				}
			
			//------------------------------
			if(strcmp(item_type,"TM2_materials")==0||strcmp(item_type,"TM2_auxiliary")==0){
				AOM_ask_value_string(formtags[0],"tm2_ckjg",&value);//料品形态类型
				if(value!=NULL){
					one_elem.INDICATIVE_PRICE.assign(value);
					MEM_free(value);
					value = NULL;
				}else{
					one_elem.SPECIFICATION.assign("");
				}
				//get_erp_name(formtags[0],ycl_name_vec,erpname,item);

				AOM_ask_value_string(formtags[0],"tm2_khth",&value);//客户图号
				if(value!=NULL){
					one_elem.CUSTOMER_PART_NUMBER.assign(value);
					MEM_free(value);
					value = NULL;
				}else{
					one_elem.CUSTOMER_PART_NUMBER.assign("");
				}

				AOM_ask_value_string(formtags[0],"tm2_fh",&value);//粉号
				if(value!=NULL){
					one_elem.POWDER_NO.assign(value);
					MEM_free(value);
					value = NULL;
				}else{
					one_elem.CUSTOMER_PART_NUMBER.assign("");
				}
				AOM_ask_value_string(formtags[0],"tm2_khmc",&value);//粉号
				if(value!=NULL){
					one_elem.CUSTOMER_NAME.assign(value);
					MEM_free(value);
					value = NULL;
				}else{
					one_elem.CUSTOMER_PART_NUMBER.assign("");
				}
				AOM_ask_value_string(formtags[0],"tm2_zl",&value);//粉号
				if(value!=NULL){
					one_elem.WEIGHT.assign(value);
					MEM_free(value);
					value = NULL;
				}else{
					one_elem.CUSTOMER_PART_NUMBER.assign("");
				}

				AOM_ask_value_string(formtags[0],"tm2_cpxh",&value);//产品型号
				if(value!=NULL){
					one_elem.PART_MODEL.assign(value);
					MEM_free(value);
					value = NULL;
				}else{
					one_elem.PART_MODEL.assign("");
				}

				AOM_ask_value_string(formtags[0],"tm2_xsfl",&value);//销售分类
				if(value!=NULL){
					one_elem.SALE_CLASSIFICATION.assign(value);
					MEM_free(value);
					value = NULL;
				}else{
					one_elem.SALE_CLASSIFICATION.assign("");
				}
				
				
			}else{
				
				if(strcmp(item_type,"TM2_powder")==0){
				
					AOM_ask_value_string(formtags[0],"tm2_pflx",&value);//配方类型
					if(value!=NULL){
						one_elem.FORMULA_TYPE.assign(value);
						MEM_free(value);
						value = NULL;
					}else{
						one_elem.FORMULA_TYPE.assign("");
					}
				}
				if(strcmp(item_type,"TM2_rawpowder")==0){
					//BLENDING_WAY
					AOM_UIF_ask_value(formtags[0],"tm2_lt",&value);//料桶
					if(value!=NULL){
						one_elem.BASKET.assign(value);
						MEM_free(value);
						value = NULL;
					}else{
						one_elem.BASKET.assign("");
					}
					AOM_UIF_ask_value(formtags[0],"tm2_plfs",&value);//配料方式
					if(value!=NULL){
						one_elem.BLENDING_WAY.assign(value);
						MEM_free(value);
						value = NULL;
					}else{
						one_elem.BLENDING_WAY.assign("");
					}
					
					AOM_ask_value_string(formtags[0],"tm2_ylfl",&value);//配方类型
					if(value!=NULL){
						one_elem.CLASSIFICATION.assign(value);
						MEM_free(value);
						value = NULL;
					}else{
						one_elem.CLASSIFICATION.assign("");
					}

					AOM_ask_value_string(formtags[0],"tm2_gg",&value);//料品形态类型
					if(value!=NULL){
						one_elem.SPECIFICATION.assign(value);
						MEM_free(value);
						value = NULL;
					}else{
						one_elem.SPECIFICATION.assign("");
					}
				}
				ifail = AOM_ask_value_date(formtags[0],"tm2_effective_date",&p);
				if(ifail==ITK_ok && p.year!=0){//CREATE_DATE
					char date_value_str[128] = "";
					sprintf(date_value_str,"%04d-%02d-%02d %02d:%02d:%02d",p.year,p.month+1 ,p.day,p.hour,p.minute,p.second);
					one_elem.VALID_DATE.assign(date_value_str);
				}
				ifail = AOM_ask_value_date(formtags[0],"tm2_expiry_date",&p);
				if(ifail==ITK_ok && p.year!=0){//CREATE_DATE
					char date_value_str[128] = "";
					sprintf(date_value_str,"%04d-%02d-%02d %02d:%02d:%02d",p.year,p.month +1,p.day,p.hour,p.minute,p.second);
					one_elem.INVALID_DATE.assign(date_value_str);
				}
				AOM_ask_value_string(formtags[0],"tm2_bzq",&value);//保质期
				if(value!=NULL){
					one_elem.SHELF_LIFE.assign(value);
					MEM_free(value);
					value = NULL;
				}else{
					one_elem.SHELF_LIFE.assign("");
				}
				AOM_ask_value_string(formtags[0],"tm2_lpxtlx",&value);//料品形态类型
				if(value!=NULL){
					one_elem.SOURCE.assign(value);
					MEM_free(value);
					value = NULL;
				}else{
					one_elem.SOURCE.assign("");
				}

				
				
				
			}
			
		}
		
		one_elem.COMMIT_TIME.assign(nowtime);//COMMIT_TIME
		one_elem.ORIGINER_SYS.assign("PLM");//IS_STANDARD
		one_elem.BATCH_ID.assign(batchid);//BATCH_ID
		one_elem.STATUS.assign("0");//STATUS

		part_vec.push_back(one_elem);
		
		if(formtags!=NULL){
			MEM_free(formtags);
			formtags = NULL;
		}

	}
	printf("\n获取属性完毕\n");
}

/**
*	获取对象的版本的属性(混料)
*
*/
int jf_hl_send_all_item(map<tag_t,string> rev_map,vector<HL_PART_STRUCT> &part_vec,string batchid,char * nowtime){
	int ifail = ITK_ok;
	tag_t tag_value = NULLTAG,item = NULLTAG;
	date_t p;
	//	char *  value =NULL;
	char ** str_values = NULL ,*value = NULL;
	char  item_type[ITEM_type_size_c + 1] ="";
	char rev_id[ITEM_id_size_c+1]="";
	char item_id[ITEM_id_size_c+1]="",item_name[ITEM_id_size_c+1]="";
	map<tag_t,string>::iterator rev_it;
	for( rev_it = rev_map.begin(); rev_it != rev_map.end(); rev_it++ )
	{
		
		
		int formcount = 0;
		int rev_count = 0;
		tag_t * rev_tags = NULL;
		tag_t * formtags = NULL;
		HL_PART_STRUCT one_elem;
		ITKCALL( ITEM_ask_item_of_rev(rev_it->first, &item) );
		ITKCALL(ITEM_list_all_revs(item,&rev_count,&rev_tags));
		/*if(rev_count > 1){
			MEM_free(rev_tags);
			rev_tags = NULL;
			continue;
		}*/

		ITKCALL( ITEM_ask_id(item, item_id) );
		ITKCALL( ITEM_ask_name(item, item_name));
		ITKCALL(ITEM_ask_type(item,item_type));
		if((strcmp(item_type,"TM2_powder")==0||strcmp(item_type,"TM2_rawpowder")==0)!=1){
			printf("[%s]不属于物料类型\n",item_type);
			continue;
		}else{
			//one_elem.PART_TYPE.assign(item_type);
			one_elem.PART_NAMBER.assign(item_id);
			one_elem.PART_NAME.assign(item_name);
			
		}
		if(strcmp(item_type,"TM2_materials")==0){
			one_elem.PART_TYPE.assign("成品");
		}else if(strcmp(item_type,"TM2_auxiliary")==0){
			one_elem.PART_TYPE.assign("配套产品");
		}else if(strcmp(item_type,"TM2_powder")==0){
			one_elem.PART_TYPE.assign("配方粉");
		}else {
			one_elem.PART_TYPE.assign("原材料粉");
		}

		ITKCALL( ITEM_ask_rev_id(rev_it->first, rev_id));
		one_elem.REVISION.assign(rev_id);
		 AOM_ask_value_tags(rev_it->first,"IMAN_master_form_rev",&formcount,&formtags);
		//对象获取单位属性
		ITKCALL(ifail = ITEM_ask_unit_of_measure(item,&tag_value));
		if(ifail == ITK_ok&& tag_value!=NULLTAG){
			
			ITKCALL(UOM_ask_symbol(tag_value,&value));
			if(value!=NULL){
				one_elem.STOCK_KEEPING_UNIT.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.STOCK_KEEPING_UNIT.assign("");
			}
		}else{
			one_elem.STOCK_KEEPING_UNIT.assign("");
		}
		
		ITKCALL(ifail = SA_ask_current_groupmember(&tag_value));
		if(ifail == ITK_ok)
		{
			tag_t user_tag = NULLTAG;
			SA_ask_groupmember_user(tag_value,&user_tag);
			if(user_tag!=NULLTAG)
			{
				char user_id_temp[SA_user_size_c+1] ="";
				ITKCALL(ifail = SA_ask_user_identifier(user_tag,user_id_temp));
				one_elem.ORIGINER.assign(user_id_temp);	
			}
		}
	
		//版本获取属性

		//版本表单获取属性
		if(formcount!=0){
			
			tag_t user_tag = NULLTAG;
				AOM_ask_value_tag(formtags[0],"owning_user",&user_tag);//申请人
				if(user_tag !=NULLTAG){
					ITKCALL(AOM_ask_value_string(user_tag,"user_name",&value));
				if(value!=NULL){
					one_elem.APPLICANT.assign(value);
					MEM_free(value);
					value = NULL;
				}else{
					one_elem.APPLICANT.assign("");
				}
				}

				ifail = AOM_ask_value_date(formtags[0],"creation_date",&p);//创建人创建时间
				if(ifail==ITK_ok&&p.year!=0){//CREATE_DATE
					char date_value_str[128] = "";
					if(p.year !=0){
						sprintf(date_value_str,"%04d-%02d-%02d %02d:%02d:%02d",p.year,p.month+1 ,p.day,p.hour,p.minute,p.second);
						one_elem.APPLICANT_DATE.assign(date_value_str);
					}
				}
			
			//------------------------------
			if(strcmp(item_type,"TM2_materials")==0||strcmp(item_type,"TM2_auxiliary")==0){
				
				
			}else{
				
				if(strcmp(item_type,"TM2_powder")==0){
				
					AOM_ask_value_string(formtags[0],"tm2_pflx",&value);//配方类型
					if(value!=NULL){
						one_elem.FORMULA_TYPE.assign(value);
						MEM_free(value);
						value = NULL;
					}else{
						one_elem.FORMULA_TYPE.assign("");
					}
				}
				if(strcmp(item_type,"TM2_rawpowder")==0){
					AOM_UIF_ask_value(formtags[0],"tm2_lt",&value);//料桶
					if(value!=NULL){
						one_elem.BASKET.assign(value);
						MEM_free(value);
						value = NULL;
					}else{
						one_elem.BASKET.assign("");
					}

					AOM_UIF_ask_value(formtags[0],"tm2_plfs",&value);//配料方式
					if(value!=NULL){
						one_elem.BLENDING_WAY.assign(value);
						MEM_free(value);
						value = NULL;
					}else{
						one_elem.BLENDING_WAY.assign("");
					}
					
					AOM_ask_value_string(formtags[0],"tm2_ylfl",&value);//配方类型
					if(value!=NULL){
						one_elem.CLASSIFICATION.assign(value);
						MEM_free(value);
						value = NULL;
					}else{
						one_elem.CLASSIFICATION.assign("");
					}

					AOM_ask_value_string(formtags[0],"tm2_gg",&value);//料品形态类型
					if(value!=NULL){
						one_elem.SPECIFICATION.assign(value);
						MEM_free(value);
						value = NULL;
					}else{
						one_elem.SPECIFICATION.assign("");
					}
				}
				ifail = AOM_ask_value_date(formtags[0],"tm2_effective_date",&p);
				if(ifail==ITK_ok&&p.year!=0){//CREATE_DATE
					char date_value_str[128] = "";
					sprintf(date_value_str,"%04d-%02d-%02d %02d:%02d:%02d",p.year,p.month+1 ,p.day,p.hour,p.minute,p.second);
					one_elem.VALID_DATE.assign(date_value_str);
				}
				ifail = AOM_ask_value_date(formtags[0],"tm2_expiry_date",&p);
				if(ifail==ITK_ok&&p.year!=0){//CREATE_DATE
					char date_value_str[128] = "";
					sprintf(date_value_str,"%04d-%02d-%02d %02d:%02d:%02d",p.year,p.month +1,p.day,p.hour,p.minute,p.second);
					one_elem.INVALID_DATE.assign(date_value_str);
				}
				AOM_ask_value_string(formtags[0],"tm2_bzq",&value);//保质期
				if(value!=NULL){
					one_elem.SHELF_LIFE.assign(value);
					MEM_free(value);
					value = NULL;
				}else{
					one_elem.SHELF_LIFE.assign("");
				}
				AOM_ask_value_string(formtags[0],"tm2_lpxtlx",&value);//料品形态类型
				if(value!=NULL){
					one_elem.SOURCE.assign(value);
					MEM_free(value);
					value = NULL;
				}else{
					one_elem.SOURCE.assign("");
				}

				
				
				
			}
			
		}
		
		one_elem.COMMIT_TIME.assign(nowtime);//COMMIT_TIME
		one_elem.ORIGINER_SYS.assign("PLM");//IS_STANDARD
		one_elem.BATCH_ID.assign(batchid);//BATCH_ID
		one_elem.STATUS.assign("0");//STATUS

		part_vec.push_back(one_elem);
		
		if(formtags!=NULL){
			MEM_free(formtags);
			formtags = NULL;
		}
	}
}

/**
*	获取控制计划的信息
*/
int jf_control_send_all_item(map<tag_t,string> rev_map,vector<CONTROL_PLAN_STRUCT> & part_vec, vector<CONTROL_PLAN_ARRAY_STRUCT> &array_vec,string batchid,char * nowtime){
	int ifail = ITK_ok;
	tag_t tag_value = NULLTAG,item = NULLTAG;
	date_t p;
	//	char *  value =NULL;
	char ** str_values = NULL ,*value = NULL;
	char  item_type[ITEM_type_size_c + 1] ="";
	char rev_id[ITEM_id_size_c+1]="";
	char item_id[ITEM_id_size_c+1]="",item_name[ITEM_id_size_c+1]="";
	map<tag_t,string>::iterator rev_it;
	int i =0 , j = 0;
	for( rev_it = rev_map.begin(); rev_it != rev_map.end(); rev_it++ )
	{
		int formcount = 0;
		//int rev_count = 0;
		//tag_t * rev_tags = NULL;
		tag_t * formtags = NULL;
		CONTROL_PLAN_STRUCT one_elem;
	 ITEM_ask_item_of_rev(rev_it->first, &item);
		//ITKCALL(ITEM_list_all_revs(item,&rev_count,&rev_tags));
		

		 ITEM_ask_id(item, item_id);
		 ITEM_ask_name(item, item_name);
		ITEM_ask_type(item,item_type);
		if(strcmp(item_type,"TM2_SCKZJH")!=0){
			printf("[%s]不属于物料类型\n",item_type);
			continue;
		}
		
		//ITKCALL( ITEM_ask_rev_id(rev_it->first, rev_id));
		//one_elem.REVISION.assign(rev_id);
		AOM_ask_value_tags(rev_it->first,"IMAN_master_form_rev",&formcount,&formtags);
		
		ifail = SA_ask_current_groupmember(&tag_value);
		if(ifail == ITK_ok)
		{
			tag_t user_tag = NULLTAG;
			SA_ask_groupmember_user(tag_value,&user_tag);
			if(user_tag!=NULLTAG)
			{
				char user_id_temp[SA_user_size_c+1] ="";
				ifail = SA_ask_user_identifier(user_tag,user_id_temp);
				one_elem.ORIGINER.assign(user_id_temp);	
			}
		}

		int outputColumn = 0;
		int outputValueCount = 0;
		char *** outputValue;
		string batchid = "000";
		char keyConnectSQL[100] = "SELECT keyconnect_id_sequence.nextval FROM DUAL";
		if(QuerySQLNoInputParam(keyConnectSQL,&outputColumn,&outputValueCount,&outputValue) != -1)
		{
			WriteLog("DEBUG: 查询中间表失败\n");
		

			for (int i=0;i<outputValueCount;i++) //行数
			{	
				batchid.assign(outputValue[i][0]);
			}
			for (i=0;i<outputValueCount;i++)
			{
			
				for(j=0;j<outputColumn;j++)
					free(outputValue[i][j]);
				free(outputValue[i]);
			}	
			if(outputValue!=NULL)
				free(outputValue);
			outputValue=NULL;
		}

		one_elem.KEY_CONNECT.assign(batchid.c_str());

		//版本表单获取属性
		if(formcount!=0){
			

			AOM_ask_value_string(formtags[0],"tm2_cpjd",&value);
			if(value!=NULL){
				one_elem.STAGE.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.STAGE.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_zylxdh",&value);
			if(value!=NULL){
				one_elem.KEY_PHONE.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.KEY_PHONE.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_gkpz",&value);
			if(value!=NULL){
				one_elem.cust_approval.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.cust_approval.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_zylxr",&value);
			if(value!=NULL){
				one_elem.KEY_CONTACT.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.KEY_CONTACT.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_bzrq",&value);
			if(value!=NULL){
				one_elem.DATE_ORIG.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.DATE_ORIG.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_xdrq",&value);
			if(value!=NULL){
				one_elem.DATE_REV.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.DATE_REV.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_kzjhbh",&value);
			if(value!=NULL){
				one_elem.PLAN_NO.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.PLAN_NO.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_sor",&value);
			if(value!=NULL){
				one_elem.SOR.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.SOR.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_hxxz",&value);
			if(value!=NULL){
				one_elem.CORE_TEAM.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.CORE_TEAM.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_gkgcpz",&value);
			if(value!=NULL){
				one_elem.Customer_engineering_approval.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.Customer_engineering_approval.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_zxggcd",&value);
			if(value!=NULL){
				one_elem.Part_Num_Latest_change.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.Part_Num_Latest_change.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_gfgcpz",&value);
			if(value!=NULL){
				one_elem.Supplier_Plant_Approval.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.Supplier_Plant_Approval.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_gkzlpz",&value);
			if(value!=NULL){
				one_elem.Customer_quality_approval.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.Customer_quality_approval.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_khtzbh",&value);
			if(value!=NULL){
				one_elem.Customer_Part_Number.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.Customer_Part_Number.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_ljmc",&value);
			if(value!=NULL){
				one_elem.Part_Name_Description.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.Part_Name_Description.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_gfgc",&value);
			if(value!=NULL){
				one_elem.Supplier_Plant.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.Supplier_Plant.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_gfdh",&value);
			if(value!=NULL){
				one_elem.Supplier_Code.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.Supplier_Code.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_cxnd",&value);
			if(value!=NULL){
				one_elem.Mode_year.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.Mode_year.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_qtpzrq1",&value);
			if(value!=NULL){
				one_elem.Other_approval_1.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.Other_approval_1.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_qtpzrq2",&value);
			if(value!=NULL){
				one_elem.Other_approval_2.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.Other_approval_2.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_xgdj",&value);
			if(value!=NULL){
				one_elem.CHANGE_LEV.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.CHANGE_LEV.assign("");
			}
			AOM_ask_value_string(formtags[0],"tm2_qtpzrq1",&value);
			if(value!=NULL){
				one_elem.Other_approval_1.assign(value);
				MEM_free(value);
				value = NULL;
			}else{
				one_elem.Other_approval_1.assign("");
			}

			
		
			one_elem.COMMIT_TIME.assign(nowtime);//COMMIT_TIME
			one_elem.ORIGINER_SYS.assign("PLM");//IS_STANDARD
			one_elem.BATCH_ID.assign(batchid);//BATCH_ID
			one_elem.STATUS.assign("0");//STATUS

			part_vec.push_back(one_elem);


			//char ** value_vec = NULL;
			char ** value_vec_1 =NULL;
			int vec_conut = 0;
			int vec_couut_1 = 0;

			AOM_ask_value_strings(formtags[0],"tm2_ljgybh",&vec_couut_1,&value_vec_1);
			for(int w = 0 ;w < vec_couut_1;w++){
				CONTROL_PLAN_ARRAY_STRUCT arr_not;
				arr_not.Part_Process_Number.assign(value_vec_1[w]);
				arr_not.KEY_CONNECT.assign(batchid);
				array_vec.push_back(arr_not);
			}

			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_couut_1;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}

			AOM_ask_value_strings(formtags[0],"tm2_gcmcms",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].Process_Name_Description.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}
			AOM_ask_value_strings(formtags[0],"tm2_jqsbgzjj",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].Machine_Device.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}
			///---------------------
			AOM_ask_value_strings(formtags[0],"tm2_qptbh",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].Characteristics_Bubbled.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}


			AOM_ask_value_strings(formtags[0],"tm2_cc",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].Characteristics_Size.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}

			AOM_ask_value_strings(formtags[0],"tm2_xh",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].Characteristics_No.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}


			AOM_ask_value_strings(formtags[0],"tm2_cp",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].Characteristics_Product.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}


			AOM_ask_value_strings(formtags[0],"tm2_gc",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].Characteristics_Process.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}


			AOM_ask_value_strings(formtags[0],"tm2_tstxfl",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].Special_Char_Class.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}


			AOM_ask_value_strings(formtags[0],"tm2_cpgcgggc",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].Specification_Tolerance.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}


			AOM_ask_value_strings(formtags[0],"tm2_spc",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].UP_SPEC.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}


			AOM_ask_value_strings(formtags[0],"tm2_xpc",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].DOWN_SPEC.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}


			AOM_ask_value_strings(formtags[0],"tm2_pgclff",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].Evaluation_Measurement.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}


			AOM_ask_value_strings(formtags[0],"tm2_rl",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].Sample_Size.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}

			AOM_ask_value_strings(formtags[0],"tm2_pl",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].Sample_Freq.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}

			AOM_ask_value_strings(formtags[0],"tm2_fzr",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].Resp.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}

			AOM_ask_value_strings(formtags[0],"tm2_kzff",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].Control_Method.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}

			AOM_ask_value_strings(formtags[0],"tm2_czgf",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].Operation_criteria.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}

			AOM_ask_value_strings(formtags[0],"tm2_fyjh",&vec_conut,&value_vec_1);
			if(vec_conut == vec_couut_1){
				for(int w = 0 ;w < vec_couut_1;w++){
					array_vec[w].Reaction_Plan.assign(value_vec_1[w]);
				}
			}
			if(value_vec_1!=NULL){
				for(int t = 0 ; t < vec_conut;t++){
					if(value_vec_1[t]!=NULL){
						MEM_free(value_vec_1[t]);
						value_vec_1[t] =NULL;
					}
				}
				MEM_free(value_vec_1);
				value_vec_1 =NULL;
			}

			//part_map.insert(pair<CONTROL_PLAN_STRUCT,vector<CONTROL_PLAN_ARRAY_STRUCT>>(one_elem,cp_vec));
		
			if(formtags!=NULL){
				MEM_free(formtags);
				formtags = NULL;
			}
		}
	}
}


/**
*  遍历BOM结构(ERP)
*/
int jf_erp_bom_struct(tag_t bom_line ,map<tag_t,string> &rev_map,vector<ERP_BOM_STRUCT> &bom_vec,string batchid,char * nowtime ){
	int ifail = ITK_ok;
	char user_id_temp[SA_user_size_c+1] ="";
	tag_t tag_value;
	//获取当前登陆用户
	ITKCALL(ifail = SA_ask_current_groupmember(&tag_value));
	if(ifail == ITK_ok)
	{
		tag_t user_tag = NULLTAG;
		SA_ask_groupmember_user(tag_value,&user_tag);
		if(user_tag!=NULLTAG)
		{
			ITKCALL(ifail = SA_ask_user_identifier(user_tag,user_id_temp));
				//one_elem.ORIGINER.assign(user_id_temp);	
		}
	}
	//
	if(bom_line!=NULL){
		int child_count = 0;
		tag_t * child_tags = NULL;
		char * parent_item_id = NULL;
		char * parent_rev_id = NULL;
		//获取父的属性
		ITKCALL(ifail =  BOM_line_ask_all_child_lines(bom_line,&child_count,&child_tags));
		//获取父ID
		ITKCALL(ifail = AOM_ask_value_string(bom_line,"bl_item_item_id",&parent_item_id));
		ITKCALL(ifail = AOM_ask_value_string(bom_line,"bl_rev_item_revision_id",&parent_rev_id));
		//string parent_temp ;
		//parent_temp.assign(parent_item_id);
		//添加遍历逻辑
		for(int i = 0 ;i < child_count;i++){
			char * child_item_id = NULL;
			char * quantity = NULL;
			char * sequence_no =NULL;
			char * child_rev_id = NULL;
			char * value = NULL;
			char  item_type[ITEM_type_size_c + 1] ="";
			char * bili = NULL;
			char * spc = NULL;
			char * xpc = NULL;
			char * lt = NULL;
			tag_t item = NULLTAG;
			tag_t rev_tag = NULLTAG;
			ERP_BOM_STRUCT one_elem ;
			//获取子ID
			ifail = AOM_ask_value_string(child_tags[i],"bl_item_item_id",&child_item_id);
			ifail = AOM_ask_value_string(child_tags[i],"bl_rev_item_revision_id",&child_rev_id);
			ifail = AOM_ask_value_string(child_tags[i],"bl_quantity",&quantity);
			ifail = AOM_ask_value_string(child_tags[i],"TM2_bl",&bili);
			ifail = AOM_ask_value_string(child_tags[i],"TM2_spc",&spc);
			ifail = AOM_ask_value_string(child_tags[i],"TM2_xpc",&xpc);
			ifail = AOM_ask_value_string(child_tags[i],"tm2_lt_bomline",&lt);
			ifail = AOM_ask_value_string(child_tags[i],"bl_sequence_no",&sequence_no);
			ifail = AOM_ask_value_tag(child_tags[i],"bl_line_object",&rev_tag);
			ITKCALL(ifail = ITEM_ask_item_of_rev(rev_tag,&item));
			ITKCALL(ifail = ITEM_ask_type(item,item_type));

			ITKCALL(ifail = ITEM_ask_unit_of_measure(item,&tag_value));
			if(ifail == ITK_ok&& tag_value!=NULLTAG){
				ITKCALL(UOM_ask_symbol(tag_value,&value));
				if(value!=NULL){
					one_elem.UNIT.assign(value);
					MEM_free(value);
					value = NULL;
				}else{
					one_elem.UNIT.assign("");
				}
			}else{
				one_elem.UNIT.assign("");
			}
			if(strcmp(item_type,"TM2_powder") == 0 || strcmp(item_type,"TM2_rawpowder") == 0 ){
				int form_count = 0;
				tag_t * form_tags = NULL;
				ITKCALL(ifail = AOM_ask_value_tags(rev_tag,"IMAN_master_form_rev",&form_count,&form_tags));
				if(ifail == ITK_ok && form_count>0){
					date_t p ;
					ifail = AOM_ask_value_date(form_tags[0],"tm2_effective_date",&p);
					if(ifail==ITK_ok&&p.year!=0){//CREATE_DATE
						char date_value_str[128] = "";
						sprintf(date_value_str,"%04d-%02d-%02d %02d:%02d:%02d",p.year,p.month ,p.day,p.hour,p.minute,p.second);
						one_elem.VALID_DATE.assign(date_value_str);
					}
					ifail = AOM_ask_value_date(form_tags[0],"tm2_expiry_date",&p);
					if(ifail==ITK_ok&&p.year!=0){//CREATE_DATE
						char date_value_str[128] = "";
						sprintf(date_value_str,"%04d-%02d-%02d %02d:%02d:%02d",p.year,p.month ,p.day,p.hour,p.minute,p.second);
						one_elem.INVALID_DATE.assign(date_value_str);
					}
				}
				if(form_tags!=NULL){
					MEM_free(form_tags);
					form_tags = NULL;
				}
			}




			jf_erp_bom_struct(child_tags[i],rev_map,bom_vec,batchid,nowtime);
			
			one_elem.P_NUMBER.assign(parent_item_id);
			one_elem.PART_NUMBER.assign(child_item_id);
			one_elem.SEQ_NUMBER.assign(sequence_no);
			one_elem.QUANTITY.assign(quantity);
			one_elem.P_REV.assign(parent_rev_id);//5
			one_elem.PART_REV.assign(child_rev_id);
			one_elem.SCALE.assign(bili);
			one_elem.P_DEVIATION.assign(spc);
			one_elem.M_DEVIATION.assign(xpc);
			one_elem.BASKET_BOMLINE.assign(lt);
			
			char temp_i_str[10] = "";
			sprintf(temp_i_str,"%d",i+1);
			one_elem.BL_SQUENCE.assign(temp_i_str);
			one_elem.ACQUISITION.assign("");
			one_elem.REPLACE_TYPE.assign("");
			//one_elem.VALID_DATE.assign("");//10
			//one_elem.INVALID_DATE.assign("");

			one_elem.BATCH_ID.assign(batchid);
			one_elem.COMMIT_TIME.assign(nowtime);
			one_elem.ORIGINER.assign(user_id_temp);//15
			one_elem.STATUS.assign("0");
			one_elem.ORIGINER_SYS.assign("PLM");
			one_elem.ORIGINER.assign(user_id_temp);
			
			bom_vec.push_back(one_elem);
			rev_map.insert(pair<tag_t,string>(rev_tag,""));
			if(child_item_id !=NULL){
				MEM_free(child_item_id);
				child_item_id = NULL;
			}
			if(quantity !=NULL){
				MEM_free(quantity);
				quantity = NULL;
			}
			if(sequence_no !=NULL){
				MEM_free(sequence_no);
				sequence_no = NULL;
			}
			if(child_rev_id !=NULL){
				MEM_free(child_rev_id);
				child_rev_id = NULL;
			}
			if(bili !=NULL){
				MEM_free(bili);
				bili = NULL;
			}
			if(spc !=NULL){
				MEM_free(spc);
				spc = NULL;
			}
			if(xpc !=NULL){
				MEM_free(xpc);
				xpc = NULL;
			}
			if(lt !=NULL){
				MEM_free(lt);
				lt = NULL;
			}
		
		}
		if(child_tags!=NULL ){
			MEM_free(child_tags);
			child_tags = NULL;
		}
		if(parent_item_id!=NULL){
			MEM_free(parent_item_id);
			parent_item_id = NULL;
		}
		if(parent_rev_id !=NULL){
			MEM_free(parent_rev_id);
			parent_rev_id = NULL;
		}
		
		
	}
}

/**
*	获取BOM的结构信息(ERP)
*/
void jf_erp_bom_all_bom(map<tag_t,string> bom_map,map<tag_t,string> &rev_map,vector<ERP_BOM_STRUCT> &bom_vec,string batchid,char * nowtime){
	int ifail = ITK_ok;

	//遍历BOM结构
	map<tag_t,string>::iterator bom_it;
	for( bom_it = bom_map.begin(); bom_it != bom_map.end(); bom_it++ )
	{
		tag_t bom_window_tag = NULLTAG,top_bom_line_tag =NULLTAG,rev_tag = NULLTAG,item_tag =NULLTAG;
		ITKCALL(ifail = BOM_create_window(&bom_window_tag));
		ITKCALL(ifail = BOM_set_window_top_line_bvr(bom_window_tag,bom_it->first,&top_bom_line_tag));
		
		if(top_bom_line_tag != NULLTAG){
			ITKCALL(ifail = AOM_ask_value_tag(top_bom_line_tag,"bl_line_object",&rev_tag));
			if(rev_tag!=NULLTAG){
				ITKCALL(ifail = ITEM_ask_item_of_rev(rev_tag,&item_tag));
				if(item_tag!=NULLTAG){
					int rev_count = 0 ;
					tag_t * rev_all = NULL;
					ITKCALL(ifail = ITEM_list_all_revs(item_tag,&rev_count,&rev_all));
					if(rev_all!=NULL){
						if(rev_count>1){
							continue;
						}
						MEM_free(rev_all);
						rev_all = NULL;
					}
				}
			}else{
				continue;
			}
			//=================================================
			jf_erp_bom_struct(top_bom_line_tag,rev_map,bom_vec,batchid,nowtime);
		}

		ITKCALL(ifail = BOM_close_window(bom_window_tag));
	}
}


/**
*  遍历BOM结构(混料)
*/
int jf_hl_bom_struct(tag_t bom_line ,map<tag_t,string> &rev_map,vector<HL_BOM_STRUCT> &bom_vec,string batchid,char * nowtime ){
	int ifail = ITK_ok;
	char user_id_temp[SA_user_size_c+1] ="";
	tag_t tag_value;
	//获取当前登陆用户
	ITKCALL(ifail = SA_ask_current_groupmember(&tag_value));
	if(ifail == ITK_ok)
	{
		tag_t user_tag = NULLTAG;
		SA_ask_groupmember_user(tag_value,&user_tag);
		if(user_tag!=NULLTAG)
		{
			ITKCALL(ifail = SA_ask_user_identifier(user_tag,user_id_temp));
				//one_elem.ORIGINER.assign(user_id_temp);	
		}
	}
	//
	if(bom_line!=NULL){
		int child_count = 0;
		tag_t * child_tags = NULL;
		char * parent_item_id = NULL;
		char * parent_rev_id = NULL;
		//获取父的属性
		ITKCALL(ifail =  BOM_line_ask_all_child_lines(bom_line,&child_count,&child_tags));
		//获取父ID
		ITKCALL(ifail = AOM_ask_value_string(bom_line,"bl_item_item_id",&parent_item_id));
		ITKCALL(ifail = AOM_ask_value_string(bom_line,"bl_rev_item_revision_id",&parent_rev_id));
		//string parent_temp ;
		//parent_temp.assign(parent_item_id);
		//添加遍历逻辑
		for(int i = 0 ;i < child_count;i++){
			char * child_item_id = NULL;
			char * quantity = NULL;
			char * sequence_no =NULL;
			char * child_rev_id = NULL;
			char * value = NULL;
			char  item_type[ITEM_type_size_c + 1] ="";
			char * wastage = NULL;
			char * bili = NULL;
			char * spc = NULL;
			char * xpc = NULL;
			char * lt = NULL;
			tag_t item = NULLTAG;
			tag_t rev_tag = NULLTAG;
			HL_BOM_STRUCT one_elem ;
			//获取子ID
			ifail = AOM_ask_value_string(child_tags[i],"bl_item_item_id",&child_item_id);
			ifail = AOM_ask_value_string(child_tags[i],"bl_rev_item_revision_id",&child_rev_id);
			ifail = AOM_ask_value_string(child_tags[i],"bl_quantity",&quantity);
			ifail = AOM_ask_value_string(child_tags[i],"bl_sequence_no",&sequence_no);
			ifail = AOM_ask_value_tag(child_tags[i],"bl_line_object",&rev_tag);
			ifail = AOM_ask_value_string(child_tags[i],"TM2_sh",&wastage);
			ifail = AOM_ask_value_string(child_tags[i],"TM2_bl",&bili);
			ifail = AOM_ask_value_string(child_tags[i],"TM2_spc",&spc);
			ifail = AOM_ask_value_string(child_tags[i],"TM2_xpc",&xpc);
			ifail = AOM_ask_value_string(child_tags[i],"tm2_lt_bomline",&lt);

			ifail = ITEM_ask_item_of_rev(rev_tag,&item);
			ifail = ITEM_ask_type(item,item_type);

			ifail = ITEM_ask_unit_of_measure(item,&tag_value);
			if(ifail == ITK_ok&& tag_value!=NULLTAG){
				ITKCALL(UOM_ask_symbol(tag_value,&value));
				if(value!=NULL){
					one_elem.UNIT.assign(value);
					MEM_free(value);
					value = NULL;
				}else{
					one_elem.UNIT.assign("");
				}
			}else{
				one_elem.UNIT.assign("");
			}
			if(strcmp(item_type,"TM2_powder") == 0 || strcmp(item_type,"TM2_rawpowder") == 0 ){
				int form_count = 0;
				tag_t * form_tags = NULL;
				ITKCALL(ifail = AOM_ask_value_tags(rev_tag,"IMAN_master_form_rev",&form_count,&form_tags));
				if(ifail == ITK_ok && form_count>0){
					date_t p ;
					ITKCALL(ifail = AOM_ask_value_date(form_tags[0],"tm2_effective_date",&p));
					if(ifail==ITK_ok&&p.year!=0){//CREATE_DATE
						char date_value_str[128] = "";
						sprintf(date_value_str,"%04d-%02d-%02d %02d:%02d:%02d",p.year,p.month ,p.day,p.hour,p.minute,p.second);
						one_elem.VALID_DATE.assign(date_value_str);
					}
					ITKCALL(ifail = AOM_ask_value_date(form_tags[0],"tm2_expiry_date",&p));
					if(ifail==ITK_ok&&p.year!=0){//CREATE_DATE
						char date_value_str[128] = "";
						sprintf(date_value_str,"%04d-%02d-%02d %02d:%02d:%02d",p.year,p.month ,p.day,p.hour,p.minute,p.second);
						one_elem.INVALID_DATE.assign(date_value_str);
					}
				}
				if(form_tags!=NULL){
					MEM_free(form_tags);
					form_tags = NULL;
				}
			}




			jf_hl_bom_struct(child_tags[i],rev_map,bom_vec,batchid,nowtime);
			
			one_elem.P_NUMBER.assign(parent_item_id);
			one_elem.PART_NUMBER.assign(child_item_id);
			one_elem.SEQ_NUMBER.assign(sequence_no);
			one_elem.QUANTITY.assign(quantity);
			one_elem.P_REV.assign(parent_rev_id);//5
			one_elem.PART_REV.assign(child_rev_id);
			
			one_elem.ACQUISITION.assign("");
			one_elem.REPLACE_TYPE.assign("");
			//one_elem.VALID_DATE.assign("");//10
			//one_elem.INVALID_DATE.assign("");

			one_elem.BATCH_ID.assign(batchid);
			one_elem.COMMIT_TIME.assign(nowtime);
			one_elem.ORIGINER.assign(user_id_temp);//15
			one_elem.STATUS.assign("0");
			one_elem.ORIGINER_SYS.assign("PLM");
			one_elem.ORIGINER.assign(user_id_temp);
			one_elem.WASTAGE.assign(wastage);
			one_elem.BASKET_BOMLINE.assign(lt);

			char temp_i_str[10] = "";
			sprintf(temp_i_str,"%d",i+1);

			one_elem.BL_SQUENCE.assign(temp_i_str);
			one_elem.SCALE.assign(bili);
			one_elem.P_DEVIATION.assign(spc);
			one_elem.M_DEVIATION.assign(xpc);
			
			bom_vec.push_back(one_elem);
			rev_map.insert(pair<tag_t,string>(rev_tag,""));
			if(child_item_id !=NULL){
				MEM_free(child_item_id);
				child_item_id = NULL;
			}
			if(lt !=NULL){
				MEM_free(lt);
				lt = NULL;
			}
			if(quantity !=NULL){
				MEM_free(quantity);
				quantity = NULL;
			}
			if(sequence_no !=NULL){
				MEM_free(sequence_no);
				sequence_no = NULL;
			}
			if(child_rev_id !=NULL){
				MEM_free(child_rev_id);
				child_rev_id = NULL;
			}
			if(wastage!=NULL){
				MEM_free(wastage);
				wastage = NULL;
			}

			if(bili !=NULL)
		{
			MEM_free(bili);
			bili = NULL;
		}
		if(spc !=NULL)
		{
			MEM_free(spc);
			spc = NULL;
		
		}
		if(xpc !=NULL)
		{
			MEM_free(xpc);
			xpc = NULL;
		}
		}
		if(child_tags!=NULL ){
			MEM_free(child_tags);
			child_tags = NULL;
		}
		if(parent_item_id!=NULL){
			MEM_free(parent_item_id);
			parent_item_id = NULL;
		}
		if(parent_rev_id !=NULL){
			MEM_free(parent_rev_id);
			parent_rev_id = NULL;
		}
		
		
	}
}

/**
*	获取BOM的结构信息(混料)
*/
void jf_hl_bom_all_bom(map<tag_t,string> bom_map,map<tag_t,string> &rev_map,vector<HL_BOM_STRUCT> &bom_vec,string batchid,char * nowtime){
	int ifail = ITK_ok;

	//遍历BOM结构
	map<tag_t,string>::iterator bom_it;
	for( bom_it = bom_map.begin(); bom_it != bom_map.end(); bom_it++ )
	{
		tag_t bom_window_tag = NULLTAG,top_bom_line_tag =NULLTAG,rev_tag = NULLTAG,item_tag =NULLTAG;
		ITKCALL(ifail = BOM_create_window(&bom_window_tag));
		ITKCALL(ifail = BOM_set_window_top_line_bvr(bom_window_tag,bom_it->first,&top_bom_line_tag));
		
		if(top_bom_line_tag != NULLTAG){
			ITKCALL(ifail = AOM_ask_value_tag(top_bom_line_tag,"bl_line_object",&rev_tag));
			if(rev_tag!=NULLTAG){
				ITKCALL(ifail = ITEM_ask_item_of_rev(rev_tag,&item_tag));
				if(item_tag!=NULLTAG){
					//做类型判断

					int rev_count = 0 ;
					tag_t * rev_all = NULL;
					ITKCALL(ifail = ITEM_list_all_revs(item_tag,&rev_count,&rev_all));
					if(rev_all!=NULL){
						/*if(rev_count>1){
							continue;
						}*/
						MEM_free(rev_all);
						rev_all = NULL;
					}
				}
			}else{
				continue;
			}
			//=================================================
			jf_hl_bom_struct(top_bom_line_tag,rev_map,bom_vec,batchid,nowtime);
		}

		ITKCALL(ifail = BOM_close_window(bom_window_tag));
	}
}


/**
*	获取BOM结构的数据（ERP）
*
*/
int jf_erp_send_boms(EPM_action_message_t msg){
	int ifail = ITK_ok;
	ECHO("=========================================================\n");
	ECHO("向ERP传递BOM  执行开始\n");
	ECHO("=========================================================\n");

	int  rcode = 0, debug = 0;
	//参数相关
	char  *value = NULL;
	char *argflag =NULL,*argvalue=NULL ,*arg = NULL, *flag = NULL;
	BOOL bypass = FALSE;
	int arg_cnt = 0;
	//流程节点相关
	tag_t task_tag = NULLTAG, rootTask_tag = NULLTAG, type_tag = NULLTAG, rev_rule_tag = NULLTAG;
	int sub_task_count = 0;
	char root_task_name[128]="",task_name[128] = "";
	int att_cnt = 0;
	tag_t *attachments = NULL;
	char tgt_type[WSO_name_size_c+1]="",type_class[TCTYPE_class_name_size_c+1]="";
	////循环内部变量
	tag_t cur_task = NULLTAG;

	//循环变量
	int i=0, j=0, k=0, count = 0, n = 0;
	//节点信息变量
	//char sign_info[2048]="";
	//节点循环处理变量
	tag_t item = NULLTAG, itemrevision = NULLTAG,master_form_rel_type = NULLTAG,rev_master_tag = NULLTAG;
	char rev_id[ITEM_id_size_c+1]="";
	char item_id[ITEM_id_size_c+1]="",item_name[ITEM_id_size_c+1]="";
	int form_count = 0;
	tag_t *form_list = NULL,master_form = NULLTAG;

	//char				*qrySQL;
	vector<string>		pref_vec;
	

	map<tag_t,string>	rev_map;
	map<tag_t,string>   bom_map;
	vector<ERP_PART_STRUCT> part_vec;
	vector<ERP_BOM_STRUCT>	bom_vec;
	getPrefStrings(PREF_JF3_ERP_DB_Login_Info,TC_preference_site, pref_vec);
	//--------------------
	//vector<string>		erp_cp_name_vec;
	//vector<string>		erp_cp_gg_vec;
	//vector<string>		erp_bcp_name_vec;
	//vector<string>		erp_bcp_gg_vec;
	//vector<string>		erp_ycl_name_vec;
	
	//-------------------
	//getPrefStrings(CUST_CP_NAME_PROPS,TC_preference_site, erp_cp_name_vec);
	//getPrefStrings(CUST_CP_GG_PROPS,TC_preference_site, erp_cp_gg_vec);
	//getPrefStrings(CUST_BCP_NAME_PROPS,TC_preference_site, erp_bcp_name_vec);
	//getPrefStrings(CUST_BCP_GG_PROPS,TC_preference_site, erp_bcp_gg_vec);
	//getPrefStrings(CUST_YCL_NAME_PROPS,TC_preference_site, erp_ycl_name_vec);

	if( pref_vec.size() != 3)
	{
		if (debug)
		{
			ECHO("DEBUG:   首选项%s配置不正确\n",PREF_JF3_ERP_DB_Login_Info);
		}
		EMH_store_error_s1( EMH_severity_information, 
							ERROR_PREFERENCE_ERROR, 
							PREF_JF3_ERP_DB_Login_Info );
		ifail = ERROR_PREFERENCE_ERROR;
		return ifail;
	}
	if(ConnServer((char*)pref_vec[0].c_str(),(char*)pref_vec[1].c_str(),(char*)pref_vec[2].c_str()) == -1)
	{
		ECHO("提示:中间数据表访问失败\n");

		EMH_store_error_s1( EMH_severity_information, 
							ERROR_ERP_LOGIN_FAIL, 
							"中间数据表访问失败" );
		ifail = ERROR_ERP_LOGIN_FAIL;
		return ifail;
	}
	task_tag = msg.task;
	if(task_tag == NULLTAG)
	{
        ifail = ITK_ok;
		
		//goto end_handler;
		return ifail;
	}
	arg_cnt = TC_number_of_arguments(msg.arguments);
	if (debug)
		ECHO("\n arg_cnt=%d\n",arg_cnt);
	ITKCALL(ifail = EPM_setup_parser(task_tag));
	if (arg_cnt > 0)
	{
		for (i=0;i<arg_cnt;i++)
		{
			arg = TC_next_argument(msg.arguments);
			ITKCALL(ifail = ITK_ask_argument_named_value((const char*)arg, &flag, &value));
			ECHO("\n flag:%s",flag);
			if (tc_strcmp(flag, "debug") == 0)
			{
				if (tc_strcmp(value, "true") == 0)
					debug = 1;
				else if (tc_strcmp(value, "false") == 0)
					debug = 0;
			}
			MEM_free(flag);
			MEM_free(value);
		}
	}
	//======================================================
	//map<string,string> class_mapping;
	//get_class_code_mapping(class_mapping);
	

	//======================================================
	char updatesqlF[256] ="UPDATE ERP_PART_INFO_TABLE SET STATUS='%s',OPERATE_TIME=to_date('%s','yyyy-MM-dd HH24:mi:ss') WHERE PART_NAMBER='%s' AND REVISION ='%s' AND STATUS='%s'";
	
	char updatesqlBom[256] ="UPDATE ERP_BOM_INFO_TABLE SET STATUS='%s',OPERATE_TIME=to_date('%s','yyyy-MM-dd HH24:mi:ss') WHERE P_NUMBER='%s' AND STATUS='%s'";
	char updatesqlBom2[256] ="UPDATE ERP_BOM_INFO_TABLE SET STATUS='%s',OPERATE_TIME=to_date('%s','yyyy-MM-dd HH24:mi:ss') WHERE P_NUMBER='%s' AND STATUS='%s' AND PART_NUMBER='%s'";
	
	//===================获取批次======================
	char batchidqrySQL[100] = "SELECT batch_id_sequence.nextval FROM DUAL";
	int outputColumn = 0;
	int outputValueCount = 0;
	char *** outputValue;
	string batchid = "000";
	if(QuerySQLNoInputParam(batchidqrySQL,&outputColumn,&outputValueCount,&outputValue) != -1)
	{
		WriteLog("DEBUG: 查询中间表失败\n");
		//findError =TRUE;
		//return ifail;

		for (int i=0;i<outputValueCount;i++) //行数
		{	
			batchid.assign(outputValue[i][0]);
		}
		for (i=0;i<outputValueCount;i++)
		{
			
			for(j=0;j<outputColumn;j++)
				free(outputValue[i][j]);
			free(outputValue[i]);
		}	
		if(outputValue!=NULL)
			free(outputValue);
		outputValue=NULL;
	}


	//===============================================

	ECHO("\n 获得流程目标...");
	ITKCALL(ifail = EPM_ask_root_task(task_tag, &rootTask_tag));
	ITKCALL(ifail = EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments));
	for( i = 0; i < att_cnt; i++ )
	{
			ITKCALL(TCTYPE_ask_object_type(attachments[i], &type_tag));
			ITKCALL(ifail = TCTYPE_ask_class_name(type_tag, type_class));
			ECHO("type_class : %s\n",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_map.insert(pair<tag_t,string>(attachments[i],""));
			}

			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))){
					bom_map.insert(pair<tag_t,string>(attachments[i],""));
			
		}
	}




	
	//属性存储
	tag_t tag_value = NULLTAG;
	//	char *  value =NULL;
	char ** str_values = NULL;
	char  item_type[ITEM_type_size_c + 1] ="";
	date_t p;
	struct tm *pp;
	time_t now;
	time(&now);
	pp = localtime(&now);
	char nowtime[30] = "";
	sprintf(nowtime,"%04d-%02d-%02d %02d:%02d:%02d",1900+pp->tm_year,pp->tm_mon+1 ,pp->tm_mday,pp->tm_hour,pp->tm_min,pp->tm_sec);
	
	//--------------------------------传递BOM信息-------------------------------------------------
	jf_erp_bom_all_bom(bom_map,rev_map,bom_vec,batchid,nowtime);
	//--------------------------------传递BOM结束-------------------------------------------------

	//--------------------------------传递所有的item----------------------------------------------
	//获取物料属性
	jf_erp_send_all_item(rev_map,part_vec,batchid,nowtime);
	
	//拼接sql语句
	//qrySQL= (char *) calloc (1000,sizeof(char));
	char fields[4096]="", insert_values[4096]="";
	for( i = 0; i < 28; i++ )
	{
		strcat(fields, erp_part_fields[i]);
		if( i != 27 )
			strcat(fields,",");
	}
	//BOM
	char  qrySQLBom[6000] = "";
	//qrySQLBom= (char *) calloc (1000,sizeof(char));
	char fieldsBOM[4096]="", insert_valuesBOM[4096]="";
	for( i = 0; i < 21; i++ )
	{
		strcat(fieldsBOM, erp_bom_fields[i]);
		if( i != 20 )
			strcat(fieldsBOM,",");
	}
	/*
	"SEQ_NUMBER",
	"P_NUMBER",
	"P_REV",
	"PART_NUMBER",
	"PART_REV",//5
	"QUANTITY",
	"UNIT",
	"ACQUISITION",
	"REPLACE_TYPE",
	"VALID_DATE",//10
	"INVALID_DATE",
	"STATUS",
	"ORIGINER",
	"COMMIT_TIME",
	"BATCH_ID",//15
	"ORIGINER_SYS"
*/
	for(i = 0; i < bom_vec.size(); i++ ){

		char updateSQL[300] ="\0";
		sprintf(updateSQL,updatesqlBom,
			"4",
			nowtime,
			bom_vec[i].P_NUMBER,
			"0"
			);
		ECHO("\nupdateqrySQL: %s",updateSQL);
		ExecuteSQLNoInputParam(updateSQL);
		
		sprintf(updateSQL,updatesqlBom,
			"3",
			nowtime,
			bom_vec[i].P_NUMBER,
			"2"
			);
		ECHO("\nupdateqrySQL: %s",updateSQL);
		ExecuteSQLNoInputParam(updateSQL);

	}


	for(i = 0; i < bom_vec.size(); i++ ){
		strcpy(insert_valuesBOM,"'");
		strcat(insert_valuesBOM,bom_vec[i].SEQ_NUMBER.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].P_NUMBER.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].P_REV.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].PART_NUMBER.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].PART_REV.c_str());//5
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].QUANTITY.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].UNIT.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].ACQUISITION.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].REPLACE_TYPE.c_str());
		strcat(insert_valuesBOM,"',to_date('");
		strcat(insert_valuesBOM, bom_vec[i].VALID_DATE.c_str());//10
		strcat(insert_valuesBOM,"','yyyy-MM-dd HH24:mi:ss'),to_date('");
		strcat(insert_valuesBOM, bom_vec[i].INVALID_DATE.c_str());
		strcat(insert_valuesBOM,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_valuesBOM, bom_vec[i].STATUS.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].ORIGINER.c_str());
		strcat(insert_valuesBOM,"',to_date('");
		strcat(insert_valuesBOM, bom_vec[i].COMMIT_TIME.c_str());
		strcat(insert_valuesBOM,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_valuesBOM, bom_vec[i].BATCH_ID.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].ORIGINER_SYS.c_str());
		strcat(insert_valuesBOM,"','");
		//---------------------
		strcat(insert_valuesBOM, bom_vec[i].SCALE.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].P_DEVIATION.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].M_DEVIATION.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].BASKET_BOMLINE.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].BL_SQUENCE.c_str());
		strcat(insert_valuesBOM,"'");
		
		sprintf(qrySQLBom,"insert into %s (%s) values (%s)",
				"ERP_BOM_INFO_TABLE",
				fieldsBOM,
				insert_valuesBOM);
		ECHO("\n  11qrySQL: %s",qrySQLBom);

		char updateSQL[300] ="\0";
		sprintf(updateSQL,updatesqlBom2,
			"1",
			nowtime,
			bom_vec[i].P_NUMBER,
			"0",
			bom_vec[i].PART_NUMBER
			);
		ECHO("\nupdateqrySQL: %s",updateSQL);
		ExecuteSQLNoInputParam(updateSQL);
		
		
		if(ExecuteSQLNoInputParam(qrySQLBom)==-1)
		{
			ECHO("提示:插入BOM_TABLE表 失败, %s \n",qrySQLBom);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			goto end_handler;
		}else{
		ECHO("提示:插入BOM_TABLE表 成功, %s \n",qrySQLBom);
		
		}
	}
	//ECHO("提示:插入part_vec.size()表 成功, %d \n",part_vec.size());
	//rev_map
	//ECHO("提示:插入rev_map.size()表 成功, %d \n",rev_map.size());
	//执行插入


	for( i = 0; i < part_vec.size(); i++ )
	{
		strcpy(insert_values,"'");
		strcat(insert_values, part_vec[i].PART_NAMBER.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].PART_NAME.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].REVISION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SPECIFICATION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].CUSTOMER_PART_NUMBER.c_str());//5
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].PART_MODEL.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].STOCK_KEEPING_UNIT.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SHELF_LIFE.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SOURCE.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].FORMULA_TYPE.c_str());//10
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].CLASSIFICATION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SALE_CLASSIFICATION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].INDICATIVE_PRICE.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].APPLICANT.c_str());
		strcat(insert_values,"',to_date('");
		strcat(insert_values, part_vec[i].APPLICANT_DATE.c_str());//15
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_values, part_vec[i].PART_TYPE.c_str());
		strcat(insert_values,"',to_date('");
		strcat(insert_values, part_vec[i].VALID_DATE.c_str());
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),to_date('");
		strcat(insert_values, part_vec[i].INVALID_DATE.c_str());
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_values, part_vec[i].STATUS.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].ORIGINER.c_str());//20
		strcat(insert_values,"',to_date('");
		strcat(insert_values, part_vec[i].COMMIT_TIME.c_str());
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_values, part_vec[i].BATCH_ID.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].ORIGINER_SYS.c_str());
		strcat(insert_values,"','");
		//------------------
		strcat(insert_values, part_vec[i].POWDER_NO.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].CUSTOMER_NAME.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].WEIGHT.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].BLENDING_WAY.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].BASKET.c_str());
		strcat(insert_values,"'");
		char qrySQL[5000] = "\0";
		sprintf(qrySQL,"insert into %s (%s) values (%s)",
				"ERP_PART_INFO_TABLE",
				fields,
				insert_values);
		ECHO("\nqrySQL: %s",qrySQL);
		char updateSQL[300] ="\0";
		sprintf(updateSQL,updatesqlF,
			"4",
			nowtime,
			part_vec[i].PART_NAMBER,
			part_vec[i].REVISION,
			"0"
			);
		ExecuteSQLNoInputParam(updateSQL);
		
		sprintf(updateSQL,updatesqlF,
			"3",
			nowtime,
			part_vec[i].PART_NAMBER,
			part_vec[i].REVISION,
			"2"
			);
		ExecuteSQLNoInputParam(updateSQL);
		
		if(ExecuteSQLNoInputParam(qrySQL)==-1)
		{
			ECHO("提示:插入PART_INFO_TABLE表 失败, %s \n",qrySQL);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			goto end_handler;
		}

	}
	//--------------------------------------------------------------------------------------------
	ExecuteSQLNoInputParam("commit");
	//ifail= 0;
	DisConnServer();

	ECHO("=========================================================\n");
	ECHO("向ERP传递BOM 执行开始 执行结束\n");
	ECHO("=========================================================\n");
	end_handler:
	if (ifail != ITK_ok )
	{
		pref_vec.clear();
		//DOFREE(qrySQL);
		DisConnServer();
	}

	return ifail;
}

/**
*	获取BOM结构的数据(混料)
*
*/
int jf_hl_send_boms(EPM_action_message_t msg){
	int ifail = ITK_ok;
	ECHO("=========================================================\n");
	ECHO("向HL传递BOM 执行开始\n");
	ECHO("=========================================================\n");
	int  rcode = 0, debug = 0;
	//参数相关
	char  *value = NULL;
	char *argflag =NULL,*argvalue=NULL ,*arg = NULL, *flag = NULL;
	BOOL bypass = FALSE;
	int arg_cnt = 0;
	//流程节点相关
	tag_t task_tag = NULLTAG, rootTask_tag = NULLTAG, type_tag = NULLTAG, rev_rule_tag = NULLTAG;
	int sub_task_count = 0;
	char root_task_name[128]="",task_name[128] = "";
	int att_cnt = 0;
	tag_t *attachments = NULL;
	char tgt_type[WSO_name_size_c+1]="",type_class[TCTYPE_class_name_size_c+1]="";
	////循环内部变量
	tag_t cur_task = NULLTAG;

	//循环变量
	int i=0, j=0, k=0, count = 0, n = 0;
	//节点信息变量
	//char sign_info[2048]="";
	//节点循环处理变量
	tag_t item = NULLTAG, itemrevision = NULLTAG,master_form_rel_type = NULLTAG,rev_master_tag = NULLTAG;
	char rev_id[ITEM_id_size_c+1]="";
	char item_id[ITEM_id_size_c+1]="",item_name[ITEM_id_size_c+1]="";
	int form_count = 0;
	tag_t *form_list = NULL,master_form = NULLTAG;

	//char				*qrySQL;
	vector<string>		pref_vec;
	

	map<tag_t,string>	rev_map;
	map<tag_t,string>   bom_map;
	vector<HL_PART_STRUCT> part_vec;
	vector<HL_BOM_STRUCT>	bom_vec;
	getPrefStrings(PREF_JF3_ERP_DB_Login_Info,TC_preference_site, pref_vec);
	//--------------------
	//vector<string>		erp_cp_name_vec;
	//vector<string>		erp_cp_gg_vec;
	//vector<string>		erp_bcp_name_vec;
	//vector<string>		erp_bcp_gg_vec;
	//vector<string>		erp_ycl_name_vec;
	
	//-------------------
	//getPrefStrings(CUST_CP_NAME_PROPS,TC_preference_site, erp_cp_name_vec);
	//getPrefStrings(CUST_CP_GG_PROPS,TC_preference_site, erp_cp_gg_vec);
	//getPrefStrings(CUST_BCP_NAME_PROPS,TC_preference_site, erp_bcp_name_vec);
	//getPrefStrings(CUST_BCP_GG_PROPS,TC_preference_site, erp_bcp_gg_vec);
	//getPrefStrings(CUST_YCL_NAME_PROPS,TC_preference_site, erp_ycl_name_vec);

	if( pref_vec.size() != 3)
	{
		if (debug)
		{
			ECHO("DEBUG:   首选项%s配置不正确\n",PREF_JF3_ERP_DB_Login_Info);
		}
		EMH_store_error_s1( EMH_severity_information, 
							ERROR_PREFERENCE_ERROR, 
							PREF_JF3_ERP_DB_Login_Info );
		ifail = ERROR_PREFERENCE_ERROR;
		return ifail;
	}
	if(ConnServer((char*)pref_vec[0].c_str(),(char*)pref_vec[1].c_str(),(char*)pref_vec[2].c_str()) == -1)
	{
		ECHO("提示:中间数据表访问失败\n");

		EMH_store_error_s1( EMH_severity_information, 
							ERROR_ERP_LOGIN_FAIL, 
							"中间数据表访问失败" );
		ifail = ERROR_ERP_LOGIN_FAIL;
		return ifail;
	}
	task_tag = msg.task;
	if(task_tag == NULLTAG)
	{
        ifail = ITK_ok;
		
		//goto end_handler;
		return ifail;
	}
	arg_cnt = TC_number_of_arguments(msg.arguments);
	if (debug)
		ECHO("\n arg_cnt=%d\n",arg_cnt);
	ITKCALL(ifail = EPM_setup_parser(task_tag));
	if (arg_cnt > 0)
	{
		for (i=0;i<arg_cnt;i++)
		{
			arg = TC_next_argument(msg.arguments);
			ITKCALL(ifail = ITK_ask_argument_named_value((const char*)arg, &flag, &value));
			ECHO("\n flag:%s",flag);
			if (tc_strcmp(flag, "debug") == 0)
			{
				if (tc_strcmp(value, "true") == 0)
					debug = 1;
				else if (tc_strcmp(value, "false") == 0)
					debug = 0;
			}
			MEM_free(flag);
			MEM_free(value);
		}
	}
	//======================================================
	//map<string,string> class_mapping;
	//get_class_code_mapping(class_mapping);
	

	//======================================================
	//char updatesqlF[256] ="UPDATE HL_PART_INFO_TABLE SET STATUS='%s',OPERATE_TIME='%s' WHERE PART_NAMBER='%s' AND REVISION ='%s' AND STATUS='%s'";
	char updatesqlF[256] ="UPDATE HL_PART_INFO_TABLE SET STATUS='%s',OPERATE_TIME=to_date('%s','yyyy-MM-dd HH24:mi:ss') WHERE PART_NAMBER='%s' AND REVISION ='%s' AND STATUS='%s'";
	char updatesqlBom[256] ="UPDATE HL_BOM_INFO_TABLE SET STATUS='%s',OPERATE_TIME=to_date('%s','yyyy-MM-dd HH24:mi:ss') WHERE P_NUMBER='%s' AND STATUS='%s'";
	char updatesqlBom2[256] ="UPDATE HL_BOM_INFO_TABLE SET STATUS='%s',OPERATE_TIME=to_date('%s','yyyy-MM-dd HH24:mi:ss') WHERE P_NUMBER='%s' AND STATUS='%s' AND PART_NUMBER='%s'";
	
	//===================获取批次======================
	char batchidqrySQL[100] = "SELECT batch_id_sequence.nextval FROM DUAL";
	int outputColumn = 0;
	int outputValueCount = 0;
	char *** outputValue;
	string batchid = "000";
	if(QuerySQLNoInputParam(batchidqrySQL,&outputColumn,&outputValueCount,&outputValue) != -1)
	{
		WriteLog("DEBUG: 查询中间表失败\n");
		//findError =TRUE;
		//return ifail;

		for (int i=0;i<outputValueCount;i++) //行数
		{	
			batchid.assign(outputValue[i][0]);
		}
		for (i=0;i<outputValueCount;i++)
		{
			
			for(j=0;j<outputColumn;j++)
				free(outputValue[i][j]);
			free(outputValue[i]);
		}	
		if(outputValue!=NULL)
			free(outputValue);
		outputValue=NULL;
	}


	//===============================================

	ECHO("\n 获得流程目标...\n");
	ITKCALL(ifail = EPM_ask_root_task(task_tag, &rootTask_tag));
	ITKCALL(ifail = EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments));
	for( i = 0; i < att_cnt; i++ )
	{
			ITKCALL(TCTYPE_ask_object_type(attachments[i], &type_tag));
			ITKCALL(ifail = TCTYPE_ask_class_name(type_tag, type_class));
			ECHO("type_class : %s\n",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_map.insert(pair<tag_t,string>(attachments[i],""));
			}

			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)))
			{
					bom_map.insert(pair<tag_t,string>(attachments[i],""));
			}
		}
	//属性存储
	tag_t tag_value = NULLTAG;
	//	char *  value =NULL;
	char ** str_values = NULL;
	char  item_type[ITEM_type_size_c + 1] ="";
	date_t p;
	struct tm *pp;
	time_t now;
	time(&now);
	pp = localtime(&now);
	char nowtime[30] = "";
	sprintf(nowtime,"%04d-%02d-%02d %02d:%02d:%02d",1900+pp->tm_year,pp->tm_mon+1 ,pp->tm_mday,pp->tm_hour,pp->tm_min,pp->tm_sec);
	
	//--------------------------------传递BOM信息-------------------------------------------------
	jf_hl_bom_all_bom(bom_map,rev_map,bom_vec,batchid,nowtime);
	//--------------------------------传递BOM结束-------------------------------------------------

	//--------------------------------传递所有的item----------------------------------------------
	//获取物料属性
	jf_hl_send_all_item(rev_map,part_vec,batchid,nowtime);
	
	//拼接sql语句
	//qrySQL= (char *) calloc (1000,sizeof(char));
	char fields[4096]="", insert_values[4096]="";
	for( i = 0; i < 21; i++ )
	{
		strcat(fields, hl_part_fields[i]);
		if( i != 20 )
			strcat(fields,",");
	}
	//BOM
	char qrySQLBom[6000] = "";
	//qrySQLBom= (char *) calloc (1000,sizeof(char));
	char fieldsBOM[5000]="", insert_valuesBOM[5000]="";
	for( i = 0; i < 22; i++ )
	{
		strcat(fieldsBOM, hl_bom_fields[i]);
		if( i != 21 )
			strcat(fieldsBOM,",");
	}
	/*
	"SEQ_NUMBER",
	"P_NUMBER",
	"P_REV",
	"PART_NUMBER",
	"PART_REV",//5
	"QUANTITY",
	"UNIT",
	"ACQUISITION",
	"REPLACE_TYPE",
	"VALID_DATE",//10
	"INVALID_DATE",
	"STATUS",
	"ORIGINER",
	"COMMIT_TIME",
	"BATCH_ID",//15
	"ORIGINER_SYS"
*/
	for(i = 0; i < bom_vec.size(); i++ ){

		char updateSQL[300] ="\0";
		sprintf(updateSQL,updatesqlBom,
			"4",
			nowtime,
			bom_vec[i].P_NUMBER,
			"0"
			);
		ECHO("\nupdateqrySQL: %s",updateSQL);
		ExecuteSQLNoInputParam(updateSQL);
		
		sprintf(updateSQL,updatesqlBom,
			"3",
			nowtime,
			bom_vec[i].P_NUMBER,
			"2"
			);
		ECHO("\nupdateqrySQL: %s",updateSQL);
		ExecuteSQLNoInputParam(updateSQL);

	}
	printf("更新BOM完成\n");

	for(i = 0; i < bom_vec.size(); i++ ){
		strcpy(insert_valuesBOM,"'");
		strcat(insert_valuesBOM,bom_vec[i].SEQ_NUMBER.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].P_NUMBER.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].P_REV.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].PART_NUMBER.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].PART_REV.c_str());//5
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].QUANTITY.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].UNIT.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].ACQUISITION.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].REPLACE_TYPE.c_str());
		strcat(insert_valuesBOM,"',to_date('");
		strcat(insert_valuesBOM, bom_vec[i].VALID_DATE.c_str());//10
		strcat(insert_valuesBOM,"','yyyy-MM-dd HH24:mi:ss'),to_date('");
		strcat(insert_valuesBOM, bom_vec[i].INVALID_DATE.c_str());
		strcat(insert_valuesBOM,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_valuesBOM, bom_vec[i].STATUS.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].ORIGINER.c_str());
		strcat(insert_valuesBOM,"',to_date('");
		strcat(insert_valuesBOM, bom_vec[i].COMMIT_TIME.c_str());
		strcat(insert_valuesBOM,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_valuesBOM, bom_vec[i].BATCH_ID.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].ORIGINER_SYS.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].WASTAGE.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].SCALE.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].P_DEVIATION.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].M_DEVIATION.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].BASKET_BOMLINE.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].BL_SQUENCE.c_str());
		strcat(insert_valuesBOM,"'");

		sprintf(qrySQLBom,"insert into %s (%s) values (%s)",
				"HL_BOM_INFO_TABLE",
				fieldsBOM,
				insert_valuesBOM);
		ECHO("\n  11qrySQL: %s",qrySQLBom);

		char updateSQL[300] ="\0";
		sprintf(updateSQL,updatesqlBom2,
			"1",
			nowtime,
			bom_vec[i].P_NUMBER,
			"0",
			bom_vec[i].PART_NUMBER
			);
		ECHO("\nupdateqrySQL: %s",updateSQL);
		ExecuteSQLNoInputParam(updateSQL);
	
		if(ExecuteSQLNoInputParam(qrySQLBom)==-1)
		{
			ECHO("提示:插入BOM_TABLE表 失败, %s \n",qrySQLBom);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			goto end_handler;
		}else{
		ECHO("提示:插入BOM_TABLE表 成功, %s \n",qrySQLBom);
		
		}
	}
	//ECHO("提示:插入part_vec.size()表 成功, %d \n",part_vec.size());
	//rev_map
	//ECHO("提示:插入rev_map.size()表 成功, %d \n",rev_map.size());
	//执行插入


	

	for( i = 0; i < part_vec.size(); i++ )
	{
		strcpy(insert_values,"'");
		strcat(insert_values, part_vec[i].PART_NAMBER.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].PART_NAME.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].REVISION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SPECIFICATION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].STOCK_KEEPING_UNIT.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SHELF_LIFE.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SOURCE.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].FORMULA_TYPE.c_str());//10
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].CLASSIFICATION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].APPLICANT.c_str());
		strcat(insert_values,"',to_date('");
		strcat(insert_values, part_vec[i].APPLICANT_DATE.c_str());//15
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_values, part_vec[i].PART_TYPE.c_str());
		strcat(insert_values,"',to_date('");
		strcat(insert_values, part_vec[i].VALID_DATE.c_str());
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),to_date('");
		strcat(insert_values, part_vec[i].INVALID_DATE.c_str());
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_values, part_vec[i].STATUS.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].ORIGINER.c_str());//20
		strcat(insert_values,"',to_date('");
		strcat(insert_values, part_vec[i].COMMIT_TIME.c_str());
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_values, part_vec[i].BATCH_ID.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].ORIGINER_SYS.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].BLENDING_WAY.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].BASKET.c_str());
		strcat(insert_values,"'");
		char qrySQL[5000] = "\0";
		sprintf(qrySQL,"insert into %s (%s) values (%s)",
				"HL_PART_INFO_TABLE",
				fields,
				insert_values);
		ECHO("\nqrySQL: %s",qrySQL);
		char updateSQL[300] ="\0";
		sprintf(updateSQL,updatesqlF,
			"4",
			nowtime,
			part_vec[i].PART_NAMBER,
			part_vec[i].REVISION,
			"0"
			);
		ExecuteSQLNoInputParam(updateSQL);
		
		sprintf(updateSQL,updatesqlF,
			"3",
			nowtime,
			part_vec[i].PART_NAMBER,
			part_vec[i].REVISION,
			"2"
			);
		ExecuteSQLNoInputParam(updateSQL);
		
		if(ExecuteSQLNoInputParam(qrySQL)==-1)
		{
			ECHO("提示:插入PART_INFO_TABLE表 失败, %s \n",qrySQL);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			goto end_handler;
		}

	}
	//--------------------------------------------------------------------------------------------
	ExecuteSQLNoInputParam("commit");
	//ifail = 0;
	DisConnServer();

	ECHO("=========================================================\n");
	ECHO("向HL传递BOM 执行结束\n");
	ECHO("=========================================================\n");
	end_handler:
	if (ifail != ITK_ok )
	{
		pref_vec.clear();
		//DOFREE(qrySQL);
		DisConnServer();
	}
	return ifail;
}


/**
*	传递对象版本到ERP中间表(ERP)
*/
int jf_erp_send_items(EPM_action_message_t msg)
{
	ECHO("=========================================================\n");
	ECHO("向ERP传递物料 执行开始\n");
	ECHO("=========================================================\n");
	int ifail = ITK_ok, rcode = 0, debug = 0;
	//参数相关
	char  *value = NULL;
	char *argflag =NULL,*argvalue=NULL ,*arg = NULL, *flag = NULL;
	BOOL bypass = FALSE;
	int arg_cnt = 0;
	//流程节点相关
	tag_t task_tag = NULLTAG, rootTask_tag = NULLTAG, type_tag = NULLTAG, rev_rule_tag = NULLTAG;
	int sub_task_count = 0;
	char root_task_name[128]="",task_name[128] = "";
	int att_cnt = 0;
	tag_t *attachments = NULL;
	char tgt_type[WSO_name_size_c+1]="",type_class[TCTYPE_class_name_size_c+1]="";
	////循环内部变量
	tag_t cur_task = NULLTAG;

	//循环变量
	int i=0, j=0, k=0, count = 0, n = 0;
	//节点信息变量
	//char sign_info[2048]="";
	//节点循环处理变量
	tag_t item = NULLTAG, itemrevision = NULLTAG,master_form_rel_type = NULLTAG,rev_master_tag = NULLTAG;
	char rev_id[ITEM_id_size_c+1]="";
	char item_id[ITEM_id_size_c+1]="",item_name[ITEM_id_size_c+1]="";
	int form_count = 0;
	tag_t *form_list = NULL,master_form = NULLTAG;

	//
	vector<string>		pref_vec;
	map<tag_t,string>	rev_map;
	vector<ERP_PART_STRUCT> part_vec;
	
	getPrefStrings(PREF_JF3_ERP_DB_Login_Info,TC_preference_site, pref_vec);

	//vector<string>		cp_name_vec;
	//vector<string>		cp_gg_vec;
	//vector<string>		bcp_name_vec;
	//vector<string>		bcp_gg_vec;
	//vector<string>		ycl_name_vec;
	
	//-------------------
	//getPrefStrings(CUST_CP_NAME_PROPS,TC_preference_site, cp_name_vec);
	//getPrefStrings(CUST_CP_GG_PROPS,TC_preference_site, cp_gg_vec);
	//getPrefStrings(CUST_BCP_NAME_PROPS,TC_preference_site, bcp_name_vec);
	//getPrefStrings(CUST_BCP_GG_PROPS,TC_preference_site, bcp_gg_vec);
	//getPrefStrings(CUST_YCL_NAME_PROPS,TC_preference_site, ycl_name_vec);
	if( pref_vec.size() != 3)
	{
		if (debug)
		{
			ECHO("DEBUG:   首选项%s配置不正确\n",PREF_JF3_ERP_DB_Login_Info);
		}
		EMH_store_error_s1( EMH_severity_information, 
							ERROR_PREFERENCE_ERROR, 
							PREF_JF3_ERP_DB_Login_Info );
		ifail = ERROR_PREFERENCE_ERROR;
		return ifail;
	}
	if(ConnServer((char*)pref_vec[0].c_str(),(char*)pref_vec[1].c_str(),(char*)pref_vec[2].c_str()) == -1)
	{
		ECHO("提示:中间数据表访问失败\n");

		EMH_store_error_s1( EMH_severity_information, 
							ERROR_ERP_LOGIN_FAIL, 
							"中间数据表访问失败" );
		ifail = ERROR_ERP_LOGIN_FAIL;
		return ifail;
	}
	task_tag = msg.task;
	if(task_tag == NULLTAG)
	{
        ifail = ITK_ok;
		
		//goto end_handler;
		return ifail;
	}
	arg_cnt = TC_number_of_arguments(msg.arguments);
	if (debug)
		ECHO("\n arg_cnt=%d\n",arg_cnt);
	ITKCALL(ifail = EPM_setup_parser(task_tag));
	if (arg_cnt > 0)
	{
		for (i=0;i<arg_cnt;i++)
		{
			arg = TC_next_argument(msg.arguments);
			ITKCALL(ifail = ITK_ask_argument_named_value((const char*)arg, &flag, &value));
			ECHO("\n flag:%s",flag);
			if (tc_strcmp(flag, "debug") == 0)
			{
				if (tc_strcmp(value, "true") == 0)
					debug = 1;
				else if (tc_strcmp(value, "false") == 0)
					debug = 0;
			}
			MEM_free(flag);
			MEM_free(value);
		}
	}
	//======================================================
	//map<string,string> class_mapping;
	//get_class_code_mapping(class_mapping);
	

	//======================================================
	char updatesqlF[256] ="UPDATE ERP_PART_INFO_TABLE SET STATUS='%s',OPERATE_TIME=to_date('%s','yyyy-MM-dd HH24:mi:ss') WHERE PART_NAMBER='%s' AND REVISION ='%s' AND STATUS='%s'";
	//===================获取批次======================
	char batchidqrySQL[100] = "SELECT batch_id_sequence.nextval FROM DUAL";
	int outputColumn = 0;
	int outputValueCount = 0;
	char *** outputValue;
	string batchid = "000";
	if(QuerySQLNoInputParam(batchidqrySQL,&outputColumn,&outputValueCount,&outputValue) != -1)
	{
		printf("DEBUG: 查询中间表失败\n");
		//findError =TRUE;
		//return ifail;

		for (int i=0;i<outputValueCount;i++) //行数
		{	
			batchid.assign(outputValue[i][0]);
		}
		for (i=0;i<outputValueCount;i++)
		{
			
			for(j=0;j<outputColumn;j++)
				free(outputValue[i][j]);
			free(outputValue[i]);
		}	
		if(outputValue!=NULL)
			free(outputValue);
		outputValue=NULL;
	}


	//===============================================

	ECHO("\n 获得流程目标...");
	ITKCALL(ifail = EPM_ask_root_task(task_tag, &rootTask_tag));
	ITKCALL(ifail = EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments));
	for( i = 0; i < att_cnt; i++ )
	{
			ITKCALL(TCTYPE_ask_object_type(attachments[i], &type_tag));
			ITKCALL(ifail = TCTYPE_ask_class_name(type_tag, type_class));
			ECHO("type_class : %s",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_map.insert(pair<tag_t,string>(attachments[i],""));
			}
	}
	//属性存储
	tag_t tag_value = NULLTAG;
	//	char *  value =NULL;
	char ** str_values = NULL;
	char  item_type[ITEM_type_size_c + 1] ="";
	date_t p;
	struct tm *pp;
	time_t now;
	time(&now);
	pp = localtime(&now);
	char nowtime[30] = "";
	sprintf(nowtime,"%04d-%02d-%02d %02d:%02d:%02d",1900+pp->tm_year,pp->tm_mon+1 ,pp->tm_mday,pp->tm_hour,pp->tm_min,pp->tm_sec);
	//获取物料属性
	jf_erp_send_all_item(rev_map,part_vec,batchid,nowtime);
	//拼接sql语句
	//qrySQL= (char *) calloc (500,sizeof(char));
	char fields[5000]="", insert_values[5000]="";
	for( i = 0; i < 28; i++ )
	{
		strcat(fields, erp_part_fields[i]);
		if( i != 27 )
			strcat(fields,",");
	}
	//执行插入
	for( i = 0; i < part_vec.size(); i++ )
	{

		strcpy(insert_values,"'");
		strcat(insert_values, part_vec[i].PART_NAMBER.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].PART_NAME.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].REVISION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SPECIFICATION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].CUSTOMER_PART_NUMBER.c_str());//5
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].PART_MODEL.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].STOCK_KEEPING_UNIT.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SHELF_LIFE.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SOURCE.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].FORMULA_TYPE.c_str());//10
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].CLASSIFICATION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SALE_CLASSIFICATION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].INDICATIVE_PRICE.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].APPLICANT.c_str());
		strcat(insert_values,"',to_date('");
		strcat(insert_values, part_vec[i].APPLICANT_DATE.c_str());//15
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_values, part_vec[i].PART_TYPE.c_str());
		strcat(insert_values,"',to_date('");
		strcat(insert_values, part_vec[i].VALID_DATE.c_str());
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),to_date('");
		strcat(insert_values, part_vec[i].INVALID_DATE.c_str());
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_values, part_vec[i].STATUS.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].ORIGINER.c_str());//20
		strcat(insert_values,"',to_date('");
		strcat(insert_values, part_vec[i].COMMIT_TIME.c_str());
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_values, part_vec[i].BATCH_ID.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].ORIGINER_SYS.c_str());
		strcat(insert_values,"','");

		strcat(insert_values, part_vec[i].POWDER_NO.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].CUSTOMER_NAME.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].WEIGHT.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].BLENDING_WAY.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].BASKET.c_str());
		strcat(insert_values,"'");

		char qrySQL[5000] = "\0";
		sprintf(qrySQL,"insert into %s (%s) values (%s)",
				PART_INFO_TABLE,
				fields,
				insert_values);
		ECHO("\nqrySQL: %s",qrySQL);

		char updateSQL[300] ="\0";
		sprintf(updateSQL,updatesqlF,
			"4",
			nowtime,
			part_vec[i].PART_NAMBER,
			part_vec[i].REVISION,
			"0"
			);
		ExecuteSQLNoInputParam(updateSQL);
		
		sprintf(updateSQL,updatesqlF,
			"3",
			nowtime,
			part_vec[i].PART_NAMBER,
			part_vec[i].REVISION,
			"2"
			);
		ExecuteSQLNoInputParam(updateSQL);
		
		if(ExecuteSQLNoInputParam(qrySQL)==-1)
		{
			ECHO("提示:插入PART_INFO_TABLE表 失败, %s \n",qrySQL);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			goto end_handler;
		}
	}
	ExecuteSQLNoInputParam("commit");
	//ifail = 0;
	DisConnServer();
	ECHO("=========================================================\n");
	ECHO("向ERP传递物料 执行结束\n");
	ECHO("=========================================================\n");

end_handler:
	if (ifail != ITK_ok )
	{
		pref_vec.clear();
		DisConnServer();
	}

	return ifail;
}

/**
*	传递对象版本到混料中间表(混料)
*/
int jf_hl_send_items(EPM_action_message_t msg)
{
	ECHO("=========================================================\n");
	ECHO("向HL传递物料 执行开始\n");
	ECHO("=========================================================\n");
	int ifail = ITK_ok, rcode = 0, debug = 0;
	//参数相关
	char  *value = NULL;
	char *argflag =NULL,*argvalue=NULL ,*arg = NULL, *flag = NULL;
	BOOL bypass = FALSE;
	int arg_cnt = 0;
	//流程节点相关
	tag_t task_tag = NULLTAG, rootTask_tag = NULLTAG, type_tag = NULLTAG, rev_rule_tag = NULLTAG;
	int sub_task_count = 0;
	char root_task_name[128]="",task_name[128] = "";
	int att_cnt = 0;
	tag_t *attachments = NULL;
	char tgt_type[WSO_name_size_c+1]="",type_class[TCTYPE_class_name_size_c+1]="";
	////循环内部变量
	tag_t cur_task = NULLTAG;

	//循环变量
	int i=0, j=0, k=0, count = 0, n = 0;
	//节点信息变量
	//char sign_info[2048]="";
	//节点循环处理变量
	tag_t item = NULLTAG, itemrevision = NULLTAG,master_form_rel_type = NULLTAG,rev_master_tag = NULLTAG;
	char rev_id[ITEM_id_size_c+1]="";
	char item_id[ITEM_id_size_c+1]="",item_name[ITEM_id_size_c+1]="";
	int form_count = 0;
	tag_t *form_list = NULL,master_form = NULLTAG;

	//char				*qrySQL;
	vector<string>		pref_vec;
	map<tag_t,string>	rev_map;
	vector<HL_PART_STRUCT> part_vec;
	
	

	getPrefStrings(PREF_JF3_ERP_DB_Login_Info,TC_preference_site, pref_vec);


	//vector<string>		cp_name_vec;
	//vector<string>		cp_gg_vec;
	//vector<string>		bcp_name_vec;
	//vector<string>		bcp_gg_vec;
	//vector<string>		ycl_name_vec;
	
	//-------------------
	//getPrefStrings(CUST_CP_NAME_PROPS,TC_preference_site, cp_name_vec);
	//getPrefStrings(CUST_CP_GG_PROPS,TC_preference_site, cp_gg_vec);
	//getPrefStrings(CUST_BCP_NAME_PROPS,TC_preference_site, bcp_name_vec);
	//getPrefStrings(CUST_BCP_GG_PROPS,TC_preference_site, bcp_gg_vec);
	//getPrefStrings(CUST_YCL_NAME_PROPS,TC_preference_site, ycl_name_vec);
	if( pref_vec.size() != 3)
	{
		if (debug)
		{
			ECHO("DEBUG:   首选项%s配置不正确\n",PREF_JF3_ERP_DB_Login_Info);
		}
		EMH_store_error_s1( EMH_severity_information, 
							ERROR_PREFERENCE_ERROR, 
							PREF_JF3_ERP_DB_Login_Info );
		ifail = ERROR_PREFERENCE_ERROR;
		return ifail;
	}
	if(ConnServer((char*)pref_vec[0].c_str(),(char*)pref_vec[1].c_str(),(char*)pref_vec[2].c_str()) == -1)
	{
		ECHO("提示:中间数据表访问失败\n");

		EMH_store_error_s1( EMH_severity_information, 
							ERROR_ERP_LOGIN_FAIL, 
							"中间数据表访问失败" );
		ifail = ERROR_ERP_LOGIN_FAIL;
		return ifail;
	}
	task_tag = msg.task;
	if(task_tag == NULLTAG)
	{
        ifail = ITK_ok;
		//goto end_handler;
		return ifail;
	}
	arg_cnt = TC_number_of_arguments(msg.arguments);
	if (debug)
		ECHO("\n arg_cnt=%d\n",arg_cnt);
	ITKCALL(ifail = EPM_setup_parser(task_tag));
	if (arg_cnt > 0)
	{
		for (i=0;i<arg_cnt;i++)
		{
			arg = TC_next_argument(msg.arguments);
			ITKCALL(ifail = ITK_ask_argument_named_value((const char*)arg, &flag, &value));
			ECHO("\n flag:%s",flag);
			if (tc_strcmp(flag, "debug") == 0)
			{
				if (tc_strcmp(value, "true") == 0)
					debug = 1;
				else if (tc_strcmp(value, "false") == 0)
					debug = 0;
			}
			MEM_free(flag);
			MEM_free(value);
		}
	}
	//======================================================
	//map<string,string> class_mapping;
	//get_class_code_mapping(class_mapping);
	

	//======================================================
	char updatesqlF[256] ="UPDATE HL_PART_INFO_TABLE SET STATUS='%s',OPERATE_TIME=to_date('%s','yyyy-MM-dd HH24:mi:ss') WHERE PART_NAMBER='%s' AND REVISION ='%s' AND STATUS='%s'";
	//===================获取批次======================
	char batchidqrySQL[100] = "SELECT batch_id_sequence.nextval FROM DUAL";
	int outputColumn = 0;
	int outputValueCount = 0;
	char *** outputValue;
	string batchid = "000";
	if(QuerySQLNoInputParam(batchidqrySQL,&outputColumn,&outputValueCount,&outputValue) != -1)
	{
		WriteLog("DEBUG: 查询中间表失败\n");
		//findError =TRUE;
		//return ifail;

		for (int i=0;i<outputValueCount;i++) //行数
		{	
			batchid.assign(outputValue[i][0]);
		}
		for (i=0;i<outputValueCount;i++)
		{
			
			for(j=0;j<outputColumn;j++)
				free(outputValue[i][j]);
			free(outputValue[i]);
		}	
		if(outputValue!=NULL)
			free(outputValue);
		outputValue=NULL;
	}


	//===============================================

	ECHO("\n 获得流程目标...");
	ITKCALL(ifail = EPM_ask_root_task(task_tag, &rootTask_tag));
	ITKCALL(ifail = EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments));
	for( i = 0; i < att_cnt; i++ )
	{
			ITKCALL(TCTYPE_ask_object_type(attachments[i], &type_tag));
			ITKCALL(ifail = TCTYPE_ask_class_name(type_tag, type_class));
			ECHO("type_class : %s",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_map.insert(pair<tag_t,string>(attachments[i],""));
			}
	}
	//属性存储
	tag_t tag_value = NULLTAG;
	//	char *  value =NULL;
	char ** str_values = NULL;
	char  item_type[ITEM_type_size_c + 1] ="";
	date_t p;
	struct tm *pp;
	time_t now;
	time(&now);
	pp = localtime(&now);
	char nowtime[30] = "";
	sprintf(nowtime,"%04d-%02d-%02d %02d:%02d:%02d",1900+pp->tm_year,pp->tm_mon+1 ,pp->tm_mday,pp->tm_hour,pp->tm_min,pp->tm_sec);
	//获取物料属性
	jf_hl_send_all_item(rev_map,part_vec,batchid,nowtime);
	//拼接sql语句
	//qrySQL= (char *) calloc (500,sizeof(char));
	char fields[4096]="", insert_values[4096]="";
	for( i = 0; i < 21; i++ )
	{
		strcat(fields, hl_part_fields[i]);
		if( i != 20 )
			strcat(fields,",");
	}
	//执行插入
	for( i = 0; i < part_vec.size(); i++ )
	{

		/*
	"PART_NAMBER",
	"PART_NAME",
	"REVISION",
	"SPECIFICATION",
	"CUSTOMER_PART_NUMBER",//5
	"PART_MODEL",
	"STOCK_KEEPING_UNIT",
	"SHELF_LIFE",
	"SOURCE",
	"FORMULA_TYPE",//10
	"CLASSIFICATION",
	"SALE_CLASSIFICATION",
	"INDICATIVE_PRICE",
	"APPLICANT",
	"APPLICANT_DATE",//15
	"PART_TYPE",
	"VALID_DATE",
	"INVALID_DATE",
	"STATUS",
	"ORIGINER",//20
	"ERROR_MSG",
	"COMMIT_TIME",
	"OPERATE_TIME",
	"BATCH_ID",
	"PUID",//25
	"ORIGINER_SYS"
*/
		strcpy(insert_values,"'");
		strcat(insert_values, part_vec[i].PART_NAMBER.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].PART_NAME.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].REVISION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SPECIFICATION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].STOCK_KEEPING_UNIT.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SHELF_LIFE.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SOURCE.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].FORMULA_TYPE.c_str());//10
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].CLASSIFICATION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].APPLICANT.c_str());
		strcat(insert_values,"',to_date('");
		strcat(insert_values, part_vec[i].APPLICANT_DATE.c_str());//15
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_values, part_vec[i].PART_TYPE.c_str());
		strcat(insert_values,"',to_date('");
		strcat(insert_values, part_vec[i].VALID_DATE.c_str());
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),to_date('");
		strcat(insert_values, part_vec[i].INVALID_DATE.c_str());
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_values, part_vec[i].STATUS.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].ORIGINER.c_str());//20
		strcat(insert_values,"',to_date('");
		strcat(insert_values, part_vec[i].COMMIT_TIME.c_str());
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_values, part_vec[i].BATCH_ID.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].ORIGINER_SYS.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].BLENDING_WAY.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].BASKET.c_str());
		strcat(insert_values,"'");

		char qrySQL[5000] = "\0";
		sprintf(qrySQL,"insert into %s (%s) values (%s)",
				"HL_PART_INFO_TABLE",
				fields,
				insert_values);
		ECHO("\nqrySQL: %s",qrySQL);

		char updateSQL[300] ="\0";
		sprintf(updateSQL,updatesqlF,
			"4",
			nowtime,
			part_vec[i].PART_NAMBER,
			part_vec[i].REVISION,
			"0"
			);
		ExecuteSQLNoInputParam(updateSQL);
		
		sprintf(updateSQL,updatesqlF,
			"3",
			nowtime,
			part_vec[i].PART_NAMBER,
			part_vec[i].REVISION,
			"2"
			);
		ExecuteSQLNoInputParam(updateSQL);
		
		if(ExecuteSQLNoInputParam(qrySQL)==-1)
		{
			ECHO("提示:插入PART_INFO_TABLE表 失败, %s \n",qrySQL);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			goto end_handler;
		}
	}
	ExecuteSQLNoInputParam("commit");
	//ifail = ITK_ok;
	DisConnServer();
	ECHO("=========================================================\n");
	ECHO("向HL传递物料 执行结束\n");
	ECHO("=========================================================\n");

end_handler:
	if (ifail != ITK_ok )
	{
		pref_vec.clear();
		//DOFREE(qrySQL);
		DisConnServer();
	}

	return ifail;
}

/**
*	传递变更到ERP
*/
int jf_erp_ecn_send_msg(EPM_action_message_t msg){
	int ifail = ITK_ok;
	ECHO("=========================================================\n");
	ECHO("向ERP 传递 ECN  执行开始\n");
	ECHO("=========================================================\n");

	int  rcode = 0, debug = 0;
	//参数相关
	char  *value = NULL;
	char *argflag =NULL,*argvalue=NULL ,*arg = NULL, *flag = NULL;
	BOOL bypass = FALSE;
	int arg_cnt = 0;
	//流程节点相关
	tag_t task_tag = NULLTAG, rootTask_tag = NULLTAG, type_tag = NULLTAG, rev_rule_tag = NULLTAG;
	int sub_task_count = 0;
	char root_task_name[128]="",task_name[128] = "";
	int att_cnt = 0;
	tag_t *attachments = NULL;
	char tgt_type[WSO_name_size_c+1]="",type_class[TCTYPE_class_name_size_c+1]="";
	////循环内部变量
	tag_t cur_task = NULLTAG;

	//循环变量
	int i=0, j=0, k=0, count = 0, n = 0;
	//节点信息变量
	//char sign_info[2048]="";
	//节点循环处理变量
	tag_t item = NULLTAG, itemrevision = NULLTAG,master_form_rel_type = NULLTAG,rev_master_tag = NULLTAG;
	char rev_id[ITEM_id_size_c+1]="";
	char item_id[ITEM_id_size_c+1]="",item_name[ITEM_id_size_c+1]="";
	int form_count = 0;
	tag_t *form_list = NULL,master_form = NULLTAG;

	char				*qrySQL;
	vector<string>		pref_vec;
	

	map<tag_t,string>	rev_map;
	map<tag_t,string>   bom_map;
	vector<ERP_PART_STRUCT> part_vec;
	vector<ERP_BOM_STRUCT>	bom_vec;
	getPrefStrings(PREF_JF3_ERP_DB_Login_Info,TC_preference_site, pref_vec);
	//--------------------
	//vector<string>		erp_cp_name_vec;
	//vector<string>		erp_cp_gg_vec;
	//vector<string>		erp_bcp_name_vec;
	//vector<string>		erp_bcp_gg_vec;
	//vector<string>		erp_ycl_name_vec;
	
	//-------------------
	//getPrefStrings(CUST_CP_NAME_PROPS,TC_preference_site, erp_cp_name_vec);
	//getPrefStrings(CUST_CP_GG_PROPS,TC_preference_site, erp_cp_gg_vec);
	//getPrefStrings(CUST_BCP_NAME_PROPS,TC_preference_site, erp_bcp_name_vec);
	//getPrefStrings(CUST_BCP_GG_PROPS,TC_preference_site, erp_bcp_gg_vec);
	//getPrefStrings(CUST_YCL_NAME_PROPS,TC_preference_site, erp_ycl_name_vec);

	if( pref_vec.size() != 3)
	{
		if (debug)
		{
			ECHO("DEBUG:   首选项%s配置不正确\n",PREF_JF3_ERP_DB_Login_Info);
		}
		EMH_store_error_s1( EMH_severity_information, 
							ERROR_PREFERENCE_ERROR, 
							PREF_JF3_ERP_DB_Login_Info );
		ifail = ERROR_PREFERENCE_ERROR;
		return ifail;
	}
	if(ConnServer((char*)pref_vec[0].c_str(),(char*)pref_vec[1].c_str(),(char*)pref_vec[2].c_str()) == -1)
	{
		ECHO("提示:中间数据表访问失败\n");

		EMH_store_error_s1( EMH_severity_information, 
							ERROR_ERP_LOGIN_FAIL, 
							"中间数据表访问失败" );
		ifail = ERROR_ERP_LOGIN_FAIL;
		return ifail;
	}
	task_tag = msg.task;
	if(task_tag == NULLTAG)
	{
        ifail = ITK_ok;
		
		//goto end_handler;
		return ifail;
	}
	arg_cnt = TC_number_of_arguments(msg.arguments);
	if (debug)
		ECHO("\n arg_cnt=%d\n",arg_cnt);
	ITKCALL(ifail = EPM_setup_parser(task_tag));
	if (arg_cnt > 0)
	{
		for (i=0;i<arg_cnt;i++)
		{
			arg = TC_next_argument(msg.arguments);
			ITKCALL(ifail = ITK_ask_argument_named_value((const char*)arg, &flag, &value));
			ECHO("\n flag:%s",flag);
			if (tc_strcmp(flag, "debug") == 0)
			{
				if (tc_strcmp(value, "true") == 0)
					debug = 1;
				else if (tc_strcmp(value, "false") == 0)
					debug = 0;
			}
			MEM_free(flag);
			MEM_free(value);
		}
	}
	//======================================================
	map<string,string> class_mapping;
	get_class_code_mapping(class_mapping);
	

	//======================================================
	char updatesqlF[256] ="UPDATE ERP_PART_INFO_TABLE SET STATUS='%s',OPERATE_TIME='%s' WHERE PART_NAMBER='%s' AND REVISION ='%s' AND STATUS='%s'";
	
	char updatesqlBom[256] ="UPDATE ERP_BOM_TABLE SET STATUS='%s',OPERATE_TIME='%s' WHERE P_NUMBER='%s' AND STATUS='%s'";
	char updatesqlBom2[256] ="UPDATE ERP_BOM_TABLE SET STATUS='%s',OPERATE_TIME='%s' WHERE P_NUMBER='%s' AND STATUS='%s' AND PART_NUMBER='%s'";
	
	//===================获取批次======================
	char batchidqrySQL[100] = "SELECT batch_id_sequence.nextval FROM DUAL";
	int outputColumn = 0;
	int outputValueCount = 0;
	char *** outputValue;
	string batchid = "000";
	if(QuerySQLNoInputParam(batchidqrySQL,&outputColumn,&outputValueCount,&outputValue) != -1)
	{
		WriteLog("DEBUG: 查询中间表失败\n");
		//findError =TRUE;
		//return ifail;

		for (int i=0;i<outputValueCount;i++) //行数
		{	
			batchid.assign(outputValue[i][0]);
		}
		for (i=0;i<outputValueCount;i++)
		{
			
			for(j=0;j<outputColumn;j++)
				free(outputValue[i][j]);
			free(outputValue[i]);
		}	
		if(outputValue!=NULL)
			free(outputValue);
		outputValue=NULL;
	}


	//===============================================

	ECHO("\n 获得流程目标...");
	ITKCALL(ifail = EPM_ask_root_task(task_tag, &rootTask_tag));
	ITKCALL(ifail = EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments));
	for( i = 0; i < att_cnt; i++ )
	{
			ITKCALL(TCTYPE_ask_object_type(attachments[i], &type_tag));
			ITKCALL(ifail = TCTYPE_ask_class_name(type_tag, type_class));
			ECHO("type_class : %s\n",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_map.insert(pair<tag_t,string>(attachments[i],""));
			}

			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)))
			{
					bom_map.insert(pair<tag_t,string>(attachments[i],""));
			
			}
	}




	
	//属性存储
	tag_t tag_value = NULLTAG;
	//	char *  value =NULL;
	char ** str_values = NULL;
	char  item_type[ITEM_type_size_c + 1] ="";
	date_t p;
	struct tm *pp;
	time_t now;
	time(&now);
	pp = localtime(&now);
	char nowtime[30] = "";
	sprintf(nowtime,"%04d-%02d-%02d %02d:%02d:%02d",1900+pp->tm_year,pp->tm_mon+1 ,pp->tm_mday,pp->tm_hour,pp->tm_min,pp->tm_sec);
	
	//--------------------------------传递BOM信息-------------------------------------------------
	jf_erp_bom_all_bom(bom_map,rev_map,bom_vec,batchid,nowtime);
	//--------------------------------传递BOM结束-------------------------------------------------

	//--------------------------------传递所有的item----------------------------------------------
	//获取物料属性
	jf_erp_send_all_item(rev_map,part_vec,batchid,nowtime);
	
	//拼接sql语句
	qrySQL= (char *) calloc (1000,sizeof(char));
	char fields[4096]="", insert_values[4096]="";
	for( i = 0; i < 28; i++ )
	{
		strcat(fields, erp_part_fields[i]);
		if( i != 27 )
			strcat(fields,",");
	}
	//BOM
	char * qrySQLBom = NULL;
	qrySQLBom= (char *) calloc (1000,sizeof(char));
	char fieldsBOM[4096]="", insert_valuesBOM[4096]="";
	for( i = 0; i < 21; i++ )
	{
		strcat(fieldsBOM, erp_bom_fields[i]);
		if( i != 20 )
			strcat(fieldsBOM,",");
	}
	/*
	"SEQ_NUMBER",
	"P_NUMBER",
	"P_REV",
	"PART_NUMBER",
	"PART_REV",//5
	"QUANTITY",
	"UNIT",
	"ACQUISITION",
	"REPLACE_TYPE",
	"VALID_DATE",//10
	"INVALID_DATE",
	"STATUS",
	"ORIGINER",
	"COMMIT_TIME",
	"BATCH_ID",//15
	"ORIGINER_SYS"
*/
	for(i = 0; i < bom_vec.size(); i++ ){

		char updateSQL[300] ="\0";
		sprintf(updateSQL,updatesqlBom,
			"4",
			nowtime,
			bom_vec[i].P_NUMBER,
			"0"
			);
		ECHO("\nupdateqrySQL: %s",updateSQL);
		ExecuteSQLNoInputParam(updateSQL);
		
		sprintf(updateSQL,updatesqlBom,
			"3",
			nowtime,
			bom_vec[i].P_NUMBER,
			"2"
			);
		ECHO("\nupdateqrySQL: %s",updateSQL);
		ExecuteSQLNoInputParam(updateSQL);

	}


	for(i = 0; i < bom_vec.size(); i++ ){
		strcpy(insert_valuesBOM,"'");
		strcat(insert_valuesBOM,bom_vec[i].SEQ_NUMBER.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].P_NUMBER.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].P_REV.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].PART_NUMBER.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].PART_REV.c_str());//5
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].QUANTITY.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].UNIT.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].ACQUISITION.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].REPLACE_TYPE.c_str());
		strcat(insert_valuesBOM,"',to_date('");
		strcat(insert_valuesBOM, bom_vec[i].VALID_DATE.c_str());//10
		strcat(insert_valuesBOM,"','yyyy-MM-dd HH24:mi:ss'),to_date('");
		strcat(insert_valuesBOM, bom_vec[i].INVALID_DATE.c_str());
		strcat(insert_valuesBOM,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_valuesBOM, bom_vec[i].STATUS.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].ORIGINER.c_str());
		strcat(insert_valuesBOM,"',to_date('");
		strcat(insert_valuesBOM, bom_vec[i].COMMIT_TIME.c_str());
		strcat(insert_valuesBOM,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_valuesBOM, bom_vec[i].BATCH_ID.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].ORIGINER_SYS.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].BASKET_BOMLINE.c_str());
		strcat(insert_valuesBOM,"','");
		strcat(insert_valuesBOM, bom_vec[i].BL_SQUENCE.c_str());
		strcat(insert_valuesBOM,"'");
		
		sprintf(qrySQLBom,"insert into %s (%s) values (%s)",
				"ERP_BOM_INFO_TABLE",
				fieldsBOM,
				insert_valuesBOM);
		ECHO("\n  11qrySQL: %s",qrySQLBom);

		char updateSQL[300] ="\0";
		sprintf(updateSQL,updatesqlBom2,
			"1",
			nowtime,
			bom_vec[i].P_NUMBER,
			"0",
			bom_vec[i].PART_NUMBER
			);
		ECHO("\nupdateqrySQL: %s",updateSQL);
		ExecuteSQLNoInputParam(updateSQL);
		
		if(ExecuteSQLNoInputParam(qrySQLBom)==-1)
		{
			ECHO("提示:插入BOM_TABLE表 失败, %s \n",qrySQLBom);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			goto end_handler;
		}else{
		ECHO("提示:插入BOM_TABLE表 成功, %s \n",qrySQLBom);
		
		}
	}
	//ECHO("提示:插入part_vec.size()表 成功, %d \n",part_vec.size());
	//rev_map
	//ECHO("提示:插入rev_map.size()表 成功, %d \n",rev_map.size());
	//执行插入


	

	for( i = 0; i < part_vec.size(); i++ )
	{
		strcpy(insert_values,"'");
		strcat(insert_values, part_vec[i].PART_NAMBER.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].PART_NAME.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].REVISION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SPECIFICATION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].CUSTOMER_PART_NUMBER.c_str());//5
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].PART_MODEL.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].STOCK_KEEPING_UNIT.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SHELF_LIFE.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SOURCE.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].FORMULA_TYPE.c_str());//10
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].CLASSIFICATION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SALE_CLASSIFICATION.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].INDICATIVE_PRICE.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].APPLICANT.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].APPLICANT_DATE.c_str());//15
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].PART_TYPE.c_str());
		strcat(insert_values,"',to_date('");
		strcat(insert_values, part_vec[i].VALID_DATE.c_str());
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),to_date('");
		strcat(insert_values, part_vec[i].INVALID_DATE.c_str());
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_values, part_vec[i].STATUS.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].ORIGINER.c_str());//20
		strcat(insert_values,"',to_date('");
		strcat(insert_values, part_vec[i].COMMIT_TIME.c_str());
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_values, part_vec[i].BATCH_ID.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].ORIGINER_SYS.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].BLENDING_WAY.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].BASKET.c_str());
		strcat(insert_values,"'");
		
		sprintf(qrySQL,"insert into %s (%s) values (%s)",
				PART_INFO_TABLE,
				fields,
				insert_values);
		ECHO("\nqrySQL: %s",qrySQL);
		char updateSQL[300] ="\0";
		sprintf(updateSQL,updatesqlF,
			"4",
			nowtime,
			part_vec[i].PART_NAMBER,
			part_vec[i].REVISION,
			"0"
			);

		ExecuteSQLNoInputParam(updateSQL);
		
		sprintf(updateSQL,updatesqlF,
			"3",
			nowtime,
			part_vec[i].PART_NAMBER,
			part_vec[i].REVISION,
			"2"
			);
		ExecuteSQLNoInputParam(updateSQL);
		
		if(ExecuteSQLNoInputParam(qrySQL)==-1)
		{
			ECHO("提示:插入PART_INFO_TABLE表 失败, %s \n",qrySQL);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			goto end_handler;
		}

	}
	//--------------------------------------------------------------------------------------------
	ExecuteSQLNoInputParam("commit");
	ifail = 0;
	DisConnServer();

	ECHO("=========================================================\n");
	ECHO("向ERP传递 ECN 执行结束\n");
	ECHO("=========================================================\n");
	end_handler:
	if (ifail != ITK_ok )
	{
		pref_vec.clear();
		DOFREE(qrySQL);
		DisConnServer();
	}
	return ifail;
}



/**
*	传递对象版本到混料中间表(混料)
*/
int jf_control_plan_send(EPM_action_message_t msg){

	ECHO("=========================================================\n");
	ECHO("传递控制计划 执行开始\n");
	ECHO("=========================================================\n");
	int ifail = ITK_ok, rcode = 0, debug = 0;
	//参数相关
	char  *value = NULL;
	char *argflag =NULL,*argvalue=NULL ,*arg = NULL, *flag = NULL;
	BOOL bypass = FALSE;
	int arg_cnt = 0;
	//流程节点相关
	tag_t task_tag = NULLTAG, rootTask_tag = NULLTAG, type_tag = NULLTAG, rev_rule_tag = NULLTAG;
	int sub_task_count = 0;
	char root_task_name[128]="",task_name[128] = "";
	int att_cnt = 0;
	tag_t *attachments = NULL;
	char tgt_type[WSO_name_size_c+1]="",type_class[TCTYPE_class_name_size_c+1]="";
	////循环内部变量
	tag_t cur_task = NULLTAG;

	//循环变量
	int i=0, j=0, k=0, count = 0, n = 0;
	//节点信息变量
	//char sign_info[2048]="";
	//节点循环处理变量
	tag_t item = NULLTAG, itemrevision = NULLTAG,master_form_rel_type = NULLTAG,rev_master_tag = NULLTAG;
	char rev_id[ITEM_id_size_c+1]="";
	char item_id[ITEM_id_size_c+1]="",item_name[ITEM_id_size_c+1]="";
	int form_count = 0;
	tag_t *form_list = NULL,master_form = NULLTAG;

	//char				*qrySQL;
	vector<string>		pref_vec;
	map<tag_t,string>	rev_map;
	vector<CONTROL_PLAN_STRUCT> part_vec;
	vector<CONTROL_PLAN_ARRAY_STRUCT> array_vec;

	getPrefStrings(PREF_JF3_ERP_DB_Login_Info,TC_preference_site, pref_vec);

	if( pref_vec.size() != 3)
	{
		if (debug)
		{
			ECHO("DEBUG:   首选项%s配置不正确\n",PREF_JF3_ERP_DB_Login_Info);
		}
		EMH_store_error_s1( EMH_severity_information, 
							ERROR_PREFERENCE_ERROR, 
							PREF_JF3_ERP_DB_Login_Info );
		ifail = ERROR_PREFERENCE_ERROR;
		return ifail;
	}
	if(ConnServer((char*)pref_vec[0].c_str(),(char*)pref_vec[1].c_str(),(char*)pref_vec[2].c_str()) == -1)
	{
		ECHO("提示:中间数据表访问失败\n");

		EMH_store_error_s1( EMH_severity_information, 
							ERROR_ERP_LOGIN_FAIL, 
							"中间数据表访问失败" );
		ifail = ERROR_ERP_LOGIN_FAIL;
		return ifail;
	}
	task_tag = msg.task;
	if(task_tag == NULLTAG)
	{
        ifail = ITK_ok;
		
		//goto end_handler;
		return ifail;
	}
	arg_cnt = TC_number_of_arguments(msg.arguments);
	if (debug)
		ECHO("\n arg_cnt=%d\n",arg_cnt);
	ITKCALL(ifail = EPM_setup_parser(task_tag));
	if (arg_cnt > 0)
	{
		for (i=0;i<arg_cnt;i++)
		{
			arg = TC_next_argument(msg.arguments);
			ITKCALL(ifail = ITK_ask_argument_named_value((const char*)arg, &flag, &value));
			ECHO("\n flag:%s",flag);
			if (tc_strcmp(flag, "debug") == 0)
			{
				if (tc_strcmp(value, "true") == 0)
					debug = 1;
				else if (tc_strcmp(value, "false") == 0)
					debug = 0;
			}
			MEM_free(flag);
			MEM_free(value);
		}
	}
	

	//======================================================
	char updatesqlF[256] ="UPDATE CP_INFO_TABLE SET STATUS='%s',OPERATE_TIME=to_date('%s','yyyy-MM-dd HH24:mi:ss') WHERE  PLAP_NO='%s'  AND STATUS='%s'";
	//===================获取批次======================
	char keyConnectSQL[100] = "SELECT keyconnect_id_sequence.nextval FROM DUAL";
	char batchidqrySQL[100] = "SELECT batch_id_sequence.nextval FROM DUAL";
	int outputColumn = 0;
	int outputValueCount = 0;
	char *** outputValue;
	string batchid = "000";

	if(QuerySQLNoInputParam(batchidqrySQL,&outputColumn,&outputValueCount,&outputValue) != -1)
	{
		WriteLog("DEBUG: 查询中间表失败\n");
		//findError =TRUE;
		//return ifail;

		for (int i=0;i<outputValueCount;i++) //行数
		{	
			batchid.assign(outputValue[i][0]);
		}
		for (i=0;i<outputValueCount;i++)
		{
			
			for(j=0;j<outputColumn;j++)
				free(outputValue[i][j]);
			free(outputValue[i]);
		}	
		if(outputValue!=NULL)
			free(outputValue);
		outputValue=NULL;
	}


	//===============================================

	ECHO("\n 获得流程目标...");
	ITKCALL(ifail = EPM_ask_root_task(task_tag, &rootTask_tag));
	ITKCALL(ifail = EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments));
	for( i = 0; i < att_cnt; i++ )
	{
			ITKCALL(TCTYPE_ask_object_type(attachments[i], &type_tag));
			ITKCALL(ifail = TCTYPE_ask_class_name(type_tag, type_class));
			ECHO("type_class : %s",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))
			{
				if(strcmp(type_class,"TM2_SCKZJHRevision")==0){
					rev_map.insert(pair<tag_t,string>(attachments[i],""));
				}
			}
	}
	//属性存储
	tag_t tag_value = NULLTAG;
	//	char *  value =NULL;
	char ** str_values = NULL;
	char  item_type[ITEM_type_size_c + 1] ="";
	date_t p;
	struct tm *pp;
	time_t now;
	time(&now);
	pp = localtime(&now);
	char nowtime[30] = "";
	sprintf(nowtime,"%04d-%02d-%02d %02d:%02d:%02d",1900+pp->tm_year,pp->tm_mon+1 ,pp->tm_mday,pp->tm_hour,pp->tm_min,pp->tm_sec);
	//获取物料属性
	jf_control_send_all_item(rev_map,part_vec,array_vec,batchid,nowtime);
	//拼接sql语句
	//qrySQL= (char *) calloc (500,sizeof(char));
	char fields[4096]="", insert_values[4096]="";
	for( i = 0; i < 29; i++ )
	{
		strcat(fields, control_plan_fields[i]);
		if( i != 28 )
			strcat(fields,",");
	}
	//执行插入
	//map<CONTROL_PLAN_STRUCT,vector<CONTROL_PLAN_ARRAY_STRUCT>>::iterator itNote;
	for( i = 0;i< part_vec.size();i++ )
	{
		strcpy(insert_values,"'");
		strcat(insert_values, part_vec[i].STAGE.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].KEY_PHONE.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].cust_approval.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].KEY_CONTACT.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].DATE_ORIG.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].DATE_REV.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].PLAN_NO.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].SOR.c_str());//10
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].CORE_TEAM.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].Customer_engineering_approval.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].Part_Num_Latest_change.c_str());//15
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].Supplier_Plant_Approval.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].Customer_quality_approval.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].Customer_Part_Number.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].Part_Name_Description.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].Supplier_Plant.c_str());//20
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].Supplier_Code.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].Mode_year.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].Other_approval_1.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].Other_approval_2.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].KEY_CONNECT.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].CHANGE_LEV.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].STATUS.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].ORIGINER.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].ERROR_MSG.c_str());
		strcat(insert_values,"',to_date('");
		strcat(insert_values, part_vec[i].COMMIT_TIME.c_str());
		strcat(insert_values,"','yyyy-MM-dd HH24:mi:ss'),'");
		strcat(insert_values, part_vec[i].OPERATE_TIME.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].BATCH_ID.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, part_vec[i].ORIGINER_SYS.c_str());
		strcat(insert_values,"'");

		char qrySQL[5000] = "\0";
		sprintf(qrySQL,"insert into %s (%s) values (%s)",
				"CP_INFO_TABLE",
				fields,
				insert_values);
		ECHO("\nqrySQL: %s",qrySQL);

		char updateSQL[300] ="\0";
		sprintf(updateSQL,updatesqlF,
			"4",
			nowtime,
			part_vec[i].PLAN_NO.c_str(),
			
			"0"
			);
		ExecuteSQLNoInputParam(updateSQL);
		
		sprintf(updateSQL,updatesqlF,
			"3",
			nowtime,
			part_vec[i].PLAN_NO.c_str(),
			
			"2"
			);
		ExecuteSQLNoInputParam(updateSQL);
		
		if(ExecuteSQLNoInputParam(qrySQL)==-1)
		{
			ECHO("提示:插入CP_INFO_TABLE表 失败, %s \n",qrySQL);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			goto end_handler;
		}
	}

	strcpy(fields,"");
	for( i = 0; i < 20; i++ )
	{
		strcat(fields, comtrol_plan_array_fields[i]);
		if( i != 19 )
			strcat(fields,",");
	}

	for( i = 0;i< array_vec.size();i++ )
	{
		strcpy(insert_values,"'");
		strcat(insert_values, array_vec[i].Part_Process_Number.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].Process_Name_Description.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].Machine_Device.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].Characteristics_Bubbled.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].Characteristics_Size.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].Characteristics_No.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].Characteristics_Product.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].Characteristics_Process.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].Special_Char_Class.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].Specification_Tolerance.c_str());//10
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].UP_SPEC.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].DOWN_SPEC.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].Evaluation_Measurement.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].Sample_Size.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].Sample_Freq.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].Resp.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].Control_Method.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].Operation_criteria.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].Reaction_Plan.c_str());
		strcat(insert_values,"','");
		strcat(insert_values, array_vec[i].KEY_CONNECT.c_str());
		strcat(insert_values,"'");

		char qrySQL[5000] = "\0";
		sprintf(qrySQL,"insert into %s (%s) values (%s)",
				"CP_INFO_ARRAY_TABLE",
				fields,
				insert_values);
		ECHO("\nqrySQL: %s",qrySQL);

		
		
		if(ExecuteSQLNoInputParam(qrySQL)==-1)
		{
			ECHO("提示:插入CP_INFO_ARRAY_TABLE表 失败, %s \n",qrySQL);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			goto end_handler;
		}
	}

	ExecuteSQLNoInputParam("commit");
	//ifail = ITK_ok;
	DisConnServer();
	ECHO("=========================================================\n");
	ECHO("传递控制计划 执行结束\n");
	ECHO("=========================================================\n");

end_handler:
	if (ifail != ITK_ok )
	{
		pref_vec.clear();
		//DOFREE(qrySQL);
		DisConnServer();
	}

	return ifail;


	//return 0;
};

/**
*传入数据集，就下载数据集，调用JAVA程序插入图片
*
*/
int insert_pdf(tag_t dataset, char *ext)
{
	printf("insert_pdf \r\n");
	tag_t spec_dataset_rev = NULLTAG,
		ref_object = NULLTAG;
	AE_reference_type_t reference_type;
	ITKCALL(AE_ask_dataset_latest_rev(dataset, &spec_dataset_rev));
	char ref_name[WSO_name_size_c + 1] = "PDF_Reference";
	ITKCALL(AE_ask_dataset_named_ref(spec_dataset_rev, ref_name, &reference_type, &ref_object));
	if(reference_type == AE_PART_OF)
	{
		char pathname[SS_MAXPATHLEN] = "";
		ITKCALL(IMF_ask_file_pathname(ref_object, SS_WNT_MACHINE, pathname));
		char origin_file_name[IMF_filename_size_c + 1] = "";
		ITKCALL(IMF_ask_original_file_name(ref_object, origin_file_name));
		char new_ds_name[WSO_name_size_c + 1] = "";
		char *new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0);
		char *temp_dir = getenv("temp");
		temp_dir="E:\\TEMP";
		char * tc_root_dir = getenv("tc_root");
		char img_file[SS_MAXPATHLEN] = "";
		char temp_file[SS_MAXPATHLEN] = "";
		char temp_file2[SS_MAXPATHLEN] = "";
		char jar_file[SS_MAXPATHLEN] = "";
		//-----------------------------
		strcpy(temp_file, temp_dir);
		strcat(temp_file, "\\");
		strcat(temp_file, new_file_name);
		//--------------------------
		strcpy(temp_file2, temp_dir);
		strcat(temp_file2, "\\");
		strcat(temp_file2, new_file_name);
		strcat(temp_file2, ".pdf");
		//-----------------------------
		strcpy(img_file, tc_root_dir);
		strcat(img_file, "\\bin\\");
		strcat(img_file, "jfom_img.tif");
		//-----------------------------
		strcpy(jar_file, tc_root_dir);
		strcat(jar_file, "\\bin\\");
		strcat(jar_file, "insert_pdf.jar");

		ITKCALL(IMF_export_file(ref_object, temp_file));
		ITKCALL(IMF_export_file(ref_object, temp_file2));
		int   iCnt;
		char *user_lib_env,pTempStr[500];
		char local_path[MAX_PATH] = "";
		char cmd[256] = "";
		//strcpy( cmd, user_lib_env );
		strcpy( cmd, "java -jar \"" );
		strcat( cmd, jar_file ); 
		strcat( cmd, "\" \"" ); 
		strcat( cmd, temp_file2 ); 
		strcat( cmd, "\" \"" );
		strcat( cmd, temp_file ); 
		strcat( cmd, "\" \"" );
		strcat( cmd, img_file );
		strcat( cmd, "\"" );
		printf( "\n%s\n",cmd );
		system( cmd );

		//strcpy(user_lib_env, local_path);
		tag_t new_file_tag = NULLTAG;
		IMF_file_t file_descriptor;	
		ITKCALL(IMF_import_file(temp_file, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor));
		ITKCALL(IMF_set_original_file_name(new_file_tag, origin_file_name));
		ITKCALL(IMF_close_file(file_descriptor));
		ITKCALL(AOM_save(new_file_tag));
		ITKCALL(AOM_unlock(new_file_tag));
		ITKCALL(AOM_lock(spec_dataset_rev));
		ITKCALL(AE_remove_dataset_named_ref_by_tag(spec_dataset_rev, ref_name, ref_object));
		ITKCALL(AE_add_dataset_named_ref(spec_dataset_rev, ref_name, AE_PART_OF, new_file_tag));
		ITKCALL(AOM_save(spec_dataset_rev));
		ITKCALL(AOM_unlock(spec_dataset_rev));
		//free(new_file_name);
		//free(temp_dir);
	}

	return ITK_ok;
}


/**
*在PDF中插入图片handler
*
*/
int jf_insert_img_pdf(EPM_action_message_t msg)
{
	//变量定义
	POM_AM__set_application_bypass(true);
	int ifail = ITK_ok,att_cnt  = 0, i = 0;
	tag_t task_tag = NULLTAG,
		rootTask_tag = NULLTAG,
		*attachments = NULL,
		relation_type = NULLTAG,
		type_tag =NULLTAG;
	char tgt_type[WSO_name_size_c+1]="",
		type_class[TCTYPE_class_name_size_c+1]="",
		rev_type[ITEM_type_size_c+1]="";
	map<tag_t,string> rev_map;
	//获取流程
	task_tag = msg.task;
	//获取根流程
	ITKCALL(ifail = EPM_ask_root_task(task_tag, &rootTask_tag));
	//获取流程目标对象
	ITKCALL(ifail = EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments));
	for( i = 0; i < att_cnt; i++ )
	{
			ITKCALL(TCTYPE_ask_object_type(attachments[i], &type_tag));
			ITKCALL(ifail = TCTYPE_ask_class_name(type_tag, type_class));
			ECHO("type_class : %s \r\n",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_map.insert(pair<tag_t,string>(attachments[i],""));
			}
	}

	//
	ITKCALL(GRM_find_relation_type(IMAN_specification_rtype, &relation_type ));
	//ITKCALL(GRM_create_relation(pTags[i],new_dataset,relation_type,NULLTAG,&relation));

	//遍历版本对象
	map<tag_t,string>::iterator rev_it;
	for( rev_it = rev_map.begin(); rev_it != rev_map.end(); rev_it++ )
	{
		ITKCALL(ITEM_ask_rev_type(rev_it->first,rev_type));
		tag_t * second_tags = NULL;
		int second_tags_count = 0;
		//if(strcmp(rev_type,"JF3_CPRevision")==0){
		if(true){
			//添加数据集下载逻辑
			ITKCALL(GRM_list_secondary_objects_only(rev_it->first,relation_type,&second_tags_count,&second_tags));
			for( i = 0 ;i < second_tags_count;i++){
				char * second_tag_type = NULL;
				ITKCALL(AOM_ask_value_string(second_tags[i],"object_type",&second_tag_type));
				
				printf(" second_tag_type => %s \r\n",second_tag_type);
				
				if(strcmp(second_tag_type,"PDF")==0){
					insert_pdf(second_tags[i],"pdf");
				}

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

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

	if(attachments!=NULL){
		MEM_free(attachments);
		attachments = NULL;
	}
	POM_AM__set_application_bypass(false);
	return ifail;
}
