# include "jk_custom_erp.h"
# include "jk_custom_erp_struct.h"
# include "erp_send_item.h"
# include "common_itk_util.h"
#include <tccore/aom_prop.h>
#include <tc/tc_macros.h>
#include <tccore/item.h>
#include <sa/groupmember.h>
#include <bom/bom.h>
#include <sa/person.h>
#include <epm/epm_task_template_itk.h>
#include <tc/preferences.h>
#include <ics/ics.h>
#include <ics/ics2.h>
#include "hx_custom.h"
#include <tccore/aom.h>
//#include "../../../../../../../../TEAMCENTER/tc/include/ics/ics2.h"
void JK_get_top_bomline_props(tag_t view_tag , 
						      vector<JK_P_BOM_STRUCT> & p_bom_vec ,
							  vector<JK_C_BOM_STRUCT> & c_bom_vec,
							  vector<JK_SUB_BOM_STRUCT> & sub_bom_vec);





/*******************************************************
*
* 获取单个物料的替代件信息  2018.5.4
*
********************************************************/
void JK_get_material_subs(tag_t obj_tag , 
						   vector<JK_RECORD_SUBSTIT_T> & sm_bean_vec
						 )
{
	int ifail = 0 ,
		global_count = 0,
		master_count = 0,
		i = 0;
	tag_t item_tag =NULLTAG,
		*global_tags = NULL,
		* master_tags = NULL,
		master_tag = NULLTAG,
		global_tag = NULLTAG;


	char item_id[ITEM_id_size_c + 1] = "\0";
	

	ITKCALL(AOM_ask_value_tags(obj_tag,"IMAN_master_form_rev",&master_count,&master_tags));
	if(master_count > 0)
	{
		master_tag = master_tags[0];
	}


	ITKCALL(ifail = ITEM_ask_item_of_rev(obj_tag,&item_tag));//通过版本获取item对象
	
	
	ITKCALL(ifail = ITEM_ask_id(item_tag,item_id));//物料编码
	date_t current_date;
	char create_date_str[32] = "\0";
	//获取当前时间
	current_time(&current_date);
	sprintf(create_date_str,"%04d-%02d-%02d",current_date.year,1+ current_date.month,current_date.day);
	

	ITKCALL(ifail = AOM_ask_value_tags(item_tag,"global_alt_list",&global_count,&global_tags));//全局替代件
	if(global_count>0){
		
		printf("存在多个全局替代件");
		for(i = 0;i < global_count;i++)
		{
			char * sub_item_id=NULL;
			ITKCALL(ifail = AOM_ask_value_string(global_tags[i],"item_id",&sub_item_id));//替代件id
			if (sub_item_id!=NULL)
			{
			JK_RECORD_SUBSTIT_T  subBean;
			subBean.NO.assign(item_id);  //物料id
			subBean.SUBSTITNO.assign(sub_item_id);  //全局替代件id
			subBean.STATES.assign("1");//状态  默认传1
			subBean.SUB_TRANS_TIME.assign(create_date_str);
			sm_bean_vec.push_back(subBean);
			}
			if(sub_item_id !=NULL)
			{
				MEM_free(sub_item_id);
				sub_item_id =NULL;
			}
			
		
		}
	}else{
		JK_RECORD_SUBSTIT_T  subBean;
		printf("无全局替代件");
		subBean.NO.assign(item_id);
		subBean.SUBSTITNO.assign("");  //没有全局默认传空
		subBean.STATES.assign("1");
		subBean.SUB_TRANS_TIME.assign(create_date_str);
		sm_bean_vec.push_back(subBean);

	}

	//释放资源
	if(master_tags !=NULL)
	{
		MEM_free(master_tags);
		master_tags = NULL;
	}

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

}


void JK_upadte_material_subs_table(vector<JK_RECORD_SUBSTIT_T> sm_bean_vec)
{
;
	int ifail = 0;

	if(ConnServer(JK_DB_USER_NAME,JK_DB_USER_PWD,JK_DB_URL) == -1)
	{
		ECHO("提示:中间数据表访问失败\n");

		EMH_store_error_s1( EMH_severity_information, 
							ERROR_ERP_LOGIN_FAIL, 
							"中间数据表访问失败" );
		ifail = ERROR_ERP_LOGIN_FAIL;
		return;
	}

	char updateSQL[3000] = "\0";

	for(int i = 0;i < sm_bean_vec.size();i++){
		sprintf(updateSQL,"UPDATE %s SET STATES='4'  WHERE NO='%s' AND STATES='1'",
			JK_RECORD_SUBSTIT_TABLE,sm_bean_vec[i].NO);
		if(ExecuteSQLNoInputParam(updateSQL)==-1)
		{
			printf("提示:插入TABLE表 失败, %s \n",updateSQL);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			//goto end_handler;
		}else{
		printf("提示:插入TABLE表 成功, %s \n",updateSQL);
		}
	}

	ExecuteSQLNoInputParam("commit");
	DisConnServer();
		
}


/*******************************************************
*
* 物料的替代件信息传入中间表  2018.5.4
*
********************************************************/
void JK_write_material_subs_to_DB(vector<JK_RECORD_SUBSTIT_T>  sm_bean_vec
							 )
{
	JK_upadte_material_subs_table(sm_bean_vec);
	int  i = 0,
		 ifail = 0;
	char fields_material[4096]="", 
		insert_values_material[4096]="",
		sql_value[10280] = "\0";
	for( i = 0; i < 4; i++ )
	{
		strcat(fields_material, JK_RECORD_SUBSTIT_fields[i]);
		if( i != 3 ){
			strcat(fields_material,",");
		}
			
	}
	cout<<"111111111111111111"<<endl;

	if(ConnServer(JK_DB_USER_NAME,JK_DB_USER_PWD,JK_DB_URL)== -1)
	{
		ECHO("提示:中间数据表访问失败\n");

		EMH_store_error_s1( EMH_severity_information, 
							ERROR_ERP_LOGIN_FAIL, 
							"中间数据表访问失败" );
		ifail = ERROR_ERP_LOGIN_FAIL;
		return;
	}
	cout<<"共有物料替代件--------------"<<sm_bean_vec.size()<<endl;
	for(i = 0; i < sm_bean_vec.size(); i++ )
	{
		strcpy(insert_values_material,"'");
		strcat(insert_values_material,sm_bean_vec[i].NO.c_str());
		strcat(insert_values_material,"','");//	物料编码
		strcat(insert_values_material,sm_bean_vec[i].SUBSTITNO.c_str());
		strcat(insert_values_material,"','");			//全局替代件编码
		strcat(insert_values_material,sm_bean_vec[i].STATES.c_str());
		strcat(insert_values_material,"','");			//状态
		strcat(insert_values_material,sm_bean_vec[i].SUB_TRANS_TIME.c_str());
		strcat(insert_values_material,"'");		//时间
		cout<<"3333333333333333333"<<endl;

		cout<<"插入物料全局替代件信息-------"<<endl;
		sprintf(sql_value,"insert into %s (%s  ) values (%s )",
				JK_RECORD_SUBSTIT_TABLE,
				fields_material,
				insert_values_material);
		printf("SQL =>%s\n",sql_value);

		if(ExecuteSQLNoInputParam(sql_value)==-1)
		{
			printf("提示:插入TABLE表 失败, %s \n",sql_value);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			//goto end_handler;
		}else{
			printf("提示:插入TABLE表 成功, %s \n",sql_value);
		}
	}
	if(ifail == 0)
	{
		ExecuteSQLNoInputParam("commit");
	}else{
		EMH_store_error_s1(EMH_severity_user_error,ifail,"[物料传递物料全局替代件中间表失败,请联系管理员!!]");//错误弹窗
	}

end_handler:
	
	DisConnServer();

}


/************************************************
*	
*   将物料信息传递到数据库
*
*************************************************/

void JK_upadte_material_table(vector<JK_MATERIAL_STRUCT> sm_bean_vec)
{
	
	cout<<"enter JK_upadte_material_table"<<endl;
	int ifail = 0;
	date_t current_date;
	char create_date_str[32] = "\0";
	current_time(&current_date);
	sprintf(create_date_str,"%04d-%02d-%02d",current_date.year,1+ current_date.month,current_date.day);

	if(ConnServer(JK_DB_USER_NAME,JK_DB_USER_PWD,JK_DB_URL) == -1)
	{
		ECHO("提示:中间数据表访问失败\n");

		EMH_store_error_s1( EMH_severity_information, 
							ERROR_ERP_LOGIN_FAIL, 
							"中间数据表访问失败" );
		ifail = ERROR_ERP_LOGIN_FAIL;
		return;
	}

	char updateSQL[3000] = "\0";

	for(int i = 0;i < sm_bean_vec.size();i++){
		sprintf(updateSQL,"UPDATE %s SET JK_STATUS='4',JK_OPERATE_TIME='%s'  WHERE JK_ITEM_ID='%s' AND JK_STATUS='0'",
			JK_MATERIAL_TABLE,create_date_str,sm_bean_vec[i].JK_ITEM_ID);
		if(ExecuteSQLNoInputParam(updateSQL)==-1)
		{
			printf("提示:插入BOM_TABLE表 失败, %s \n",updateSQL);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			//goto end_handler;
		}
		sprintf(updateSQL,"UPDATE %s SET JK_STATUS='3',JK_OPERATE_TIME='%s' WHERE JK_ITEM_ID='%s' AND JK_STATUS='2'",
			JK_MATERIAL_TABLE,create_date_str,sm_bean_vec[i].JK_ITEM_ID);
		if(ExecuteSQLNoInputParam(updateSQL)==-1)
		{
			printf("提示:插入BOM_TABLE表 失败, %s \n",updateSQL);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			//goto end_handler;
		}
	}

	ExecuteSQLNoInputParam("commit");
	DisConnServer();
		cout<<"aaaaaaaaaaaaaaaaaaaaaa"<<endl;
}

void JK_write_material_to_DB(vector<JK_MATERIAL_STRUCT> sm_bean_vec,
							 vector<JK_MATERIAL_STRUCT> &faild_m_vec)
{
	cout<<"enter JK_write_material_to_DB"<<endl;
	cout<<"sm_bean_vec.size()1---------------------"<<sm_bean_vec.size()<<endl;
	JK_upadte_material_table(sm_bean_vec);
	cout<<"sm_bean_vec.size()2---------------------"<<sm_bean_vec.size()<<endl;
	int  i = 0,
		 ifail = 0;
	char fields_material[4096]="", 
		insert_values_material[4096]="",
		sql_value[10280] = "\0";
	for( i = 0; i < 45; i++ )
	{
		strcat(fields_material, jk_material_fields[i]);
		if( i != 44 )
			strcat(fields_material,",");
	}
	cout<<"111111111111111111"<<endl;

	if(ConnServer(JK_DB_USER_NAME,JK_DB_USER_PWD,JK_DB_URL)== -1)
	{
		ECHO("提示:中间数据表访问失败\n");

		EMH_store_error_s1( EMH_severity_information, 
							ERROR_ERP_LOGIN_FAIL, 
							"中间数据表访问失败" );
		ifail = ERROR_ERP_LOGIN_FAIL;
		return;
	}
		cout<<"2222222222222222"<<endl;
	cout<<"共有物料--------------"<<sm_bean_vec.size()<<endl;
	for(i = 0; i < sm_bean_vec.size(); i++ )
	{
		strcpy(insert_values_material,"'");
		strcat(insert_values_material,sm_bean_vec[i].JK_ITEM_ID.c_str());
		if(strcmp("",sm_bean_vec[i].JK_ITEM_ID.c_str())==0)
		{
			continue;
		}
		strcat(insert_values_material,"','");//	物料编码
		strcat(insert_values_material,sm_bean_vec[i].JK_ITEM_NAME.c_str());
		strcat(insert_values_material,"','");			//	物料名称
		strcat(insert_values_material,sm_bean_vec[i].JK_ITEM_SPEC_MODEL.c_str());
		strcat(insert_values_material,"','");	//	规格型号
		strcat(insert_values_material,sm_bean_vec[i].JK_CLASS_CODE.c_str());
		strcat(insert_values_material,"','");		//	存货大类编码
		strcat(insert_values_material,sm_bean_vec[i].JK_PROD_CODE.c_str());
		strcat(insert_values_material,"','");		//	产品识别号			//5
		strcat(insert_values_material,sm_bean_vec[i].JK_UOM.c_str());
		strcat(insert_values_material,"','");			//	主计量单位
		strcat(insert_values_material,sm_bean_vec[i].JK_CREATION_DATE.c_str());
		strcat(insert_values_material,"','");		//	申请日期
		strcat(insert_values_material,sm_bean_vec[i].JK_SCRAP_DATE.c_str());
		strcat(insert_values_material,"','");		//	TODO 停用日期（如果类型是启用就置空）
		strcat(insert_values_material,sm_bean_vec[i].JK_DESIGN_CODE.c_str());
		strcat(insert_values_material,"','");		//	图号信息
		strcat(insert_values_material,sm_bean_vec[i].JK_IS_SCRAP.c_str());
		strcat(insert_values_material,"','");			//	是否失效			//10
		strcat(insert_values_material,sm_bean_vec[i].JK_FROM.c_str());
		strcat(insert_values_material,"','");				//	发起人
		strcat(insert_values_material,sm_bean_vec[i].JK_TRANS_TIME.c_str());
		strcat(insert_values_material,"','");		//	传递时间
		strcat(insert_values_material,sm_bean_vec[i].JK_STATUS.c_str());
		strcat(insert_values_material,"','");			//	接收状态
		strcat(insert_values_material,sm_bean_vec[i].JK_ERROR_MSG.c_str());
		strcat(insert_values_material,"','");			//	错误信息
		strcat(insert_values_material,sm_bean_vec[i].JK_OPERATE_TIME.c_str());
		strcat(insert_values_material,"','");		//	接收时间			//15
		strcat(insert_values_material,sm_bean_vec[i].JK_PUID.c_str());
		strcat(insert_values_material,"','");				//	唯一编号
		strcat(insert_values_material,sm_bean_vec[i].JK_FROM_SYS.c_str());
		strcat(insert_values_material,"','");			//	传递方
		strcat(insert_values_material,sm_bean_vec[i].JK_ATTR_1.c_str());
		strcat(insert_values_material,"','");			//	扩展字段2
		strcat(insert_values_material,sm_bean_vec[i].JK_MATERIAL_STATUS.c_str());//启用日期，如果类型是（如果类型是停用就置空）
		strcat(insert_values_material,"','");			//	扩展字段1

		strcat(insert_values_material,sm_bean_vec[i].JK_REMARKS.c_str());
		strcat(insert_values_material,"','");			//	扩展字段3			//20
		strcat(insert_values_material,sm_bean_vec[i].JK_PRODUCT_IDNO.c_str());
		strcat(insert_values_material,"','");			//	扩展字段4
		strcat(insert_values_material,sm_bean_vec[i].JK_ITEM_REV.c_str());
		strcat(insert_values_material,"','");			//	扩展字段5
		strcat(insert_values_material,sm_bean_vec[i].JK_ATTR_6.c_str());
		strcat(insert_values_material,"','");			//	扩展字段6
		strcat(insert_values_material,sm_bean_vec[i].JK_ATTR_7.c_str());
		strcat(insert_values_material,"','");			//	扩展字段7
		strcat(insert_values_material,sm_bean_vec[i].JK_ATTR_8.c_str());
		strcat(insert_values_material,"','");			//	扩展字段8			//25
		strcat(insert_values_material,sm_bean_vec[i].JK_CPSBH.c_str());//2019.04.11存储产品识别号
		strcat(insert_values_material,"','");			//	扩展字段9
		strcat(insert_values_material,sm_bean_vec[i].JK_ATTR_10.c_str());//	扩展字段10			//27
		strcat(insert_values_material,"','");			
		strcat(insert_values_material,sm_bean_vec[i].JK_UNIT_WEIGHT.c_str());
		strcat(insert_values_material,"','");			//	单位重量
		strcat(insert_values_material,sm_bean_vec[i].JK_UNIT_VOLUME.c_str());
		strcat(insert_values_material,"','");			//	单位体积
		strcat(insert_values_material,sm_bean_vec[i].JK_DOMSC_MARKET.c_str()); 
		strcat(insert_values_material,"','");			//	是否内销      //30
		strcat(insert_values_material,sm_bean_vec[i].JK_CONSUM.c_str());
		strcat(insert_values_material,"','");			//	是否耗用
		strcat(insert_values_material,sm_bean_vec[i].JK_IS_BUY.c_str());
		strcat(insert_values_material,"','");			//	是否采购
		strcat(insert_values_material,sm_bean_vec[i].JK_IS_MAKE.c_str());
		strcat(insert_values_material,"','");			//	是否自制
		strcat(insert_values_material,sm_bean_vec[i].JK_OUT_SOURCE.c_str());
		strcat(insert_values_material,"','");			//	是否委外
		strcat(insert_values_material,sm_bean_vec[i].JK_ACCOUNT_SET.c_str());
		strcat(insert_values_material,"','");			//	默认账套    //35
		strcat(insert_values_material,sm_bean_vec[i].JK_BUSINESS_TYPE.c_str());
		strcat(insert_values_material,"','");			//	业务类型
		strcat(insert_values_material,sm_bean_vec[i].JK_BUYER.c_str());
		strcat(insert_values_material,"','");			//	采购员
		strcat(insert_values_material,sm_bean_vec[i].JK_PURLEAD_TIME.c_str());
		strcat(insert_values_material,"','");			//	固定提前期
		strcat(insert_values_material,sm_bean_vec[i].JK_SAFE_STOCK.c_str());
		strcat(insert_values_material,"','");			//	安全库存
		strcat(insert_values_material,sm_bean_vec[i].JK_SUPPLY_TYPE1.c_str());
		strcat(insert_values_material,"','");			//	供应类型     //40
		strcat(insert_values_material,sm_bean_vec[i].JK_WARE_HOUSE1.c_str());
		strcat(insert_values_material,"','");			//	默认仓库
		strcat(insert_values_material,sm_bean_vec[i].JK_INNTRANS_COE.c_str());
		strcat(insert_values_material,"','");			//	内部交易价格系数
		strcat(insert_values_material,sm_bean_vec[i].JK_HOUSE_KEEPER.c_str());
		strcat(insert_values_material,"','");			//	库管员
		strcat(insert_values_material,sm_bean_vec[i].JK_IS_INNTRANS.c_str());
		strcat(insert_values_material,"','");			//	是否内部交易
		strcat(insert_values_material,sm_bean_vec[i].JK_PLAN_METHOD.c_str());//计划方式
		
		strcat(insert_values_material," '");
			cout<<"3333333333333333333"<<endl;
		printf("技术型号====%s\n",sm_bean_vec[i].JK_PROD_CODE.c_str());
		printf("insert_values_material====%s\n",insert_values_material);

		/*strcpy(sql_value,"insert into ");
		strcat(sql_value,JK_MATERIAL_TABLE);
		strcat(sql_value," (");
		strcat(sql_value,fields_material);
		strcat(sql_value,"  ) values (");
		strcat(sql_value,insert_values_material);
		strcat(sql_value, ")");*/
		cout<<"插入物料信息-------"<<endl;
		sprintf(sql_value,"insert into %s (%s  ) values (%s )",
				JK_MATERIAL_TABLE,
				fields_material,
				insert_values_material);
		printf("SQL =>%s\n",sql_value);


		/*sprintf(sql_value,"insert into %s (JK_ATTR_1,JK_ATTR_2  ) values ('sssssss','jhkjhj' )",
				JK_MATERIAL_TABLE
				);
		printf("SQL =>%s\n",sql_value);*/

		if(ExecuteSQLNoInputParam(sql_value)==-1)
		{
			printf("提示:插入TABLE表 失败, %s \n",sql_value);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			faild_m_vec.push_back(sm_bean_vec[i]);
			//goto end_handler;
		}else{
			printf("提示:插入TABLE表 成功, %s \n",sql_value);
		}
	}
	if(ifail == 0)
	{
		ExecuteSQLNoInputParam("commit");
	}else{
		EMH_store_error_s1(EMH_severity_user_error,ifail,"[物料传递U8失败,请联系管理员!!]");//错误弹窗
	}

end_handler:
	
	DisConnServer();

}





/************************************************
*	
*   将BOM 表头 信息传递到数据库
*
*************************************************/
void JK_update_bom_tables(vector<JK_P_BOM_STRUCT> p_bom_bean_vec){
	int ifail = 0;
	date_t current_date;
	char create_date_str[32] = "\0";
	current_time(&current_date);
	sprintf(create_date_str,"%04d-%02d-%02d",current_date.year,1+ current_date.month,current_date.day);

	if(ConnServer(JK_DB_USER_NAME,JK_DB_USER_PWD,JK_DB_URL) == -1)
	{
		ECHO("提示:中间数据表访问失败\n");

		EMH_store_error_s1( EMH_severity_information, 
							ERROR_ERP_LOGIN_FAIL, 
							"中间数据表访问失败" );
		ifail = ERROR_ERP_LOGIN_FAIL;
		return;
	}

	char updateSQL[3000] = "\0";

	for(int i = 0;i < p_bom_bean_vec.size();i++){
		sprintf(updateSQL,"UPDATE %s SET JK_STATUS='4',JK_OPERATE_TIME='%s' WHERE JK_BOM_ID='%s' AND JK_BOM_REV='%s' AND JK_STATUS='0'",
			JK_BOM_PARENT_LINE_TABLE ,create_date_str,p_bom_bean_vec[i].JK_BOM_ID,p_bom_bean_vec[i].JK_BOM_REV);
		if(ExecuteSQLNoInputParam(updateSQL)==-1)
		{
			printf("提示:插入BOM_TABLE表 失败, %s \n",updateSQL);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			//goto end_handler;
		}
		sprintf(updateSQL,"UPDATE %s SET JK_STATUS='3',JK_OPERATE_TIME='%s' WHERE JK_BOM_ID='%s' AND JK_BOM_REV='%s' AND JK_STATUS='2'",
			JK_BOM_PARENT_LINE_TABLE ,create_date_str,p_bom_bean_vec[i].JK_BOM_ID,p_bom_bean_vec[i].JK_BOM_REV);
		if(ExecuteSQLNoInputParam(updateSQL)==-1)
		{
			printf("提示:插入BOM_TABLE表 失败, %s \n",updateSQL);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			//goto end_handler;
		}

		sprintf(updateSQL,"DELETE %s  WHERE JK_BOM_ID='%s' AND JK_BOM_REV='%s'",
			JK_BOM_CHILD_LINE_TABLE ,p_bom_bean_vec[i].JK_BOM_ID,p_bom_bean_vec[i].JK_BOM_REV);
		if(ExecuteSQLNoInputParam(updateSQL)==-1)
		{
			printf("提示:插入BOM_TABLE表 失败, %s \n",updateSQL);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			//goto end_handler;
		}
		sprintf(updateSQL,"DELETE %s  WHERE JK_BOM_ID='%s' AND JK_BOM_REV='%s'",
			JK_BOM_SUBSTITUTE_PART_TABLE ,p_bom_bean_vec[i].JK_BOM_ID,p_bom_bean_vec[i].JK_BOM_REV);
		if(ExecuteSQLNoInputParam(updateSQL)==-1)
		{
			printf("提示:插入BOM_TABLE表 失败, %s \n",updateSQL);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			//goto end_handler;
		}
	}

	ExecuteSQLNoInputParam("commit");
	DisConnServer();


}

void JK_write_p_bom_to_DB(vector<JK_P_BOM_STRUCT> p_bom_bean_vec
						  ,vector<JK_P_BOM_STRUCT> & field_p_bean)
{

	JK_update_bom_tables(p_bom_bean_vec);
	int  i = 0,
		 ifail = 0;
	char fields_material[4096]="", 
		insert_values_material[4096]="",
		sql_value[10280] = "\0";
	for( i = 0; i < 24; i++ )
	{
		strcat(fields_material, jk_p_bom_fields[i]);
		if( i != 23 )
			strcat(fields_material,",");
	}

	if(ConnServer(JK_DB_USER_NAME,JK_DB_USER_PWD,JK_DB_URL) == -1)
	{
		ECHO("提示:中间数据表访问失败\n");

		EMH_store_error_s1( EMH_severity_information, 
							ERROR_ERP_LOGIN_FAIL, 
							"中间数据表访问失败" );
		ifail = ERROR_ERP_LOGIN_FAIL;
		return;
	}

	for(i = 0; i < p_bom_bean_vec.size(); i++ )
	{
		strcpy(insert_values_material,"'");
		strcat(insert_values_material,p_bom_bean_vec[i].JK_BOM_ID.c_str());
		strcat(insert_values_material,"','");//	bom编号
		strcat(insert_values_material,p_bom_bean_vec[i].JK_BOM_REV.c_str());
		strcat(insert_values_material,"','");			//	bom版本
		strcat(insert_values_material,p_bom_bean_vec[i].JK_OWNING_USER.c_str());
		strcat(insert_values_material,"','");	//	所有者
		strcat(insert_values_material,p_bom_bean_vec[i].JK_RATE.c_str());
		strcat(insert_values_material,"','");		//	母件损耗率
		strcat(insert_values_material,p_bom_bean_vec[i].JK_CREATION_DATE.c_str());
		strcat(insert_values_material,"','");		//	生效日期			//5
		strcat(insert_values_material,p_bom_bean_vec[i].JK_SCRAP_DATE.c_str());
		strcat(insert_values_material,"','");		//	失效日期
		strcat(insert_values_material,p_bom_bean_vec[i].JK_IS_SCRAP.c_str());
		strcat(insert_values_material,"','");		//	是否失效
		strcat(insert_values_material,p_bom_bean_vec[i].JK_FROM.c_str());
		strcat(insert_values_material,"','");				//	发起人
		strcat(insert_values_material,p_bom_bean_vec[i].JK_TRANS_TIME.c_str());
		strcat(insert_values_material,"','");		//	传递时间
		strcat(insert_values_material,p_bom_bean_vec[i].JK_STATUS.c_str());
		strcat(insert_values_material,"','");			//	接收状态
		strcat(insert_values_material,p_bom_bean_vec[i].JK_ERROR_MSG.c_str());
		strcat(insert_values_material,"','");			//	错误信息
		strcat(insert_values_material,p_bom_bean_vec[i].JK_OPERATE_TIME.c_str());
		strcat(insert_values_material,"','");		//	接收时间			//15
		strcat(insert_values_material,p_bom_bean_vec[i].JK_PUID.c_str());
		strcat(insert_values_material,"','");				//	唯一编号
		strcat(insert_values_material,p_bom_bean_vec[i].JK_FROM_SYS.c_str());
		strcat(insert_values_material,"','");			//	传递方
		strcat(insert_values_material,p_bom_bean_vec[i].JK_ATTR_1.c_str());
		strcat(insert_values_material,"','");			//	扩展字段1
		strcat(insert_values_material,p_bom_bean_vec[i].JK_ATTR_2.c_str());
		strcat(insert_values_material,"','");			//	扩展字段2
		strcat(insert_values_material,p_bom_bean_vec[i].JK_ATTR_3.c_str());
		strcat(insert_values_material,"','");			//	扩展字段3			//20
		strcat(insert_values_material,p_bom_bean_vec[i].JK_ATTR_4.c_str());
		strcat(insert_values_material,"','");			//	扩展字段4
		strcat(insert_values_material,p_bom_bean_vec[i].JK_ATTR_5.c_str());
		strcat(insert_values_material,"','");			//	扩展字段5
		strcat(insert_values_material,p_bom_bean_vec[i].JK_ATTR_6.c_str());
		strcat(insert_values_material,"','");			//	扩展字段6
		strcat(insert_values_material,p_bom_bean_vec[i].JK_ATTR_7.c_str());
		strcat(insert_values_material,"','");			//	扩展字段7
		strcat(insert_values_material,p_bom_bean_vec[i].JK_ATTR_8.c_str());
		strcat(insert_values_material,"','");			//	扩展字段8			//25
		strcat(insert_values_material,p_bom_bean_vec[i].JK_ATTR_9.c_str());
		strcat(insert_values_material,"','");			//	扩展字段9
		strcat(insert_values_material,p_bom_bean_vec[i].JK_ATTR_10.c_str());//	扩展字段10			//27
		strcat(insert_values_material,"'");
		
		sprintf(sql_value,"insert into %s (%s ) values (%s )",
				JK_BOM_PARENT_LINE_TABLE,
				fields_material,
				insert_values_material);
		printf("SQL =>%s\n",sql_value);

		if(ExecuteSQLNoInputParam(sql_value)==-1)
		{
			printf("提示:插入BOM_TABLE表 失败, %s \n",sql_value);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			//goto end_handler;
			field_p_bean.push_back(p_bom_bean_vec[i]);
		}else{
			printf("提示:插入BOM_TABLE表 成功, %s \n",sql_value);
		}
	}
	if(ifail == 0)
	{
		ExecuteSQLNoInputParam("commit");
	}

end_handler:
	
	DisConnServer();

}

/************************************************
*	
*   将BOM 结构 信息传递到数据库
*
*************************************************/
void JK_write_c_bom_to_DB(vector<JK_C_BOM_STRUCT> c_bom_bean_vec
						  ,vector<JK_C_BOM_STRUCT> & field_c_bean)
{
	int  i = 0,
		 ifail = 0;
	char fields_material[4096]="", 
		insert_values_material[4096]="",
		sql_value[10280] = "\0";
	for( i = 0; i < 18; i++ )
	{
		strcat(fields_material, jk_c_bom_fields[i]);
		if( i != 17 )
			strcat(fields_material,",");
	}

	if(ConnServer(JK_DB_USER_NAME,JK_DB_USER_PWD,JK_DB_URL) == -1)
	{
		ECHO("提示:中间数据表访问失败\n");

		EMH_store_error_s1( EMH_severity_information, 
							ERROR_ERP_LOGIN_FAIL, 
							"中间数据表访问失败" );
		ifail = ERROR_ERP_LOGIN_FAIL;
		return;
	}

	for(i = 0; i < c_bom_bean_vec.size(); i++ ){
	
		if(strcmp(c_bom_bean_vec[i].JK_BOM_CID.c_str(),"")==0||c_bom_bean_vec[i].JK_BOM_CID.length()==0)
		{
			continue;
		}
		strcpy(insert_values_material,"'");
		strcat(insert_values_material,c_bom_bean_vec[i].JK_BOM_ID.c_str());
		strcat(insert_values_material,"','");//	bom编号
		strcat(insert_values_material,c_bom_bean_vec[i].JK_BOM_REV.c_str());
		strcat(insert_values_material,"','");			//	bom版本
		strcat(insert_values_material,c_bom_bean_vec[i].JK_BOM_CID.c_str());
		strcat(insert_values_material,"','");	//	所有者
		strcat(insert_values_material,c_bom_bean_vec[i].JK_SUPPLY_TYPE.c_str());
		strcat(insert_values_material,"','");		//	母件损耗率
		strcat(insert_values_material,c_bom_bean_vec[i].JK_WAREHOUSE.c_str());
		strcat(insert_values_material,"','");		//	生效日期			//5
		strcat(insert_values_material,c_bom_bean_vec[i].JK_QUANTITY.c_str());
		strcat(insert_values_material,"','");		//	失效日期
		strcat(insert_values_material,c_bom_bean_vec[i].JK_REMARK.c_str());
		strcat(insert_values_material,"','");		//	是否失效
		strcat(insert_values_material,c_bom_bean_vec[i].JK_ATTR_1.c_str());
		strcat(insert_values_material,"','");			//	扩展字段1
		strcat(insert_values_material,c_bom_bean_vec[i].JK_ATTR_2.c_str());
		strcat(insert_values_material,"','");			//	扩展字段2
		strcat(insert_values_material,c_bom_bean_vec[i].JK_ATTR_3.c_str());
		strcat(insert_values_material,"','");			//	扩展字段3			//20
		strcat(insert_values_material,c_bom_bean_vec[i].JK_ATTR_4.c_str());
		strcat(insert_values_material,"','");			//	扩展字段4
		strcat(insert_values_material,c_bom_bean_vec[i].JK_ATTR_5.c_str());
		strcat(insert_values_material,"','");			//	扩展字段5
		strcat(insert_values_material,c_bom_bean_vec[i].JK_ATTR_6.c_str());
		strcat(insert_values_material,"','");			//	扩展字段6
		strcat(insert_values_material,c_bom_bean_vec[i].JK_ATTR_7.c_str());
		strcat(insert_values_material,"','");			//	扩展字段7
		strcat(insert_values_material,c_bom_bean_vec[i].JK_ATTR_8.c_str());
		strcat(insert_values_material,"','");			//	扩展字段8			//25
		strcat(insert_values_material,c_bom_bean_vec[i].JK_ATTR_9.c_str());
		strcat(insert_values_material,"','");			//	扩展字段9
		strcat(insert_values_material,c_bom_bean_vec[i].JK_ATTR_10.c_str());//	扩展字段10			//27
		strcat(insert_values_material,"','");
		strcat(insert_values_material,c_bom_bean_vec[i].JK_BOM_CWR.c_str());//子件损耗率			//27
		strcat(insert_values_material,"'");
		
		sprintf(sql_value,"insert into %s (%s) values (%s)",
				JK_BOM_CHILD_LINE_TABLE,
				fields_material,
				insert_values_material);
		printf("SQL =>%s\n",sql_value);

		if(ExecuteSQLNoInputParam(sql_value)==-1)
		{
			printf("提示:插入BOM_TABLE表 失败, %s \n",sql_value);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			//goto end_handler;
			field_c_bean.push_back(c_bom_bean_vec[i]);
		}else{
			printf("提示:插入BOM_TABLE表 成功, %s \n",sql_value);
		}
	}
	if(ifail == 0)
	{
		ExecuteSQLNoInputParam("commit");
	}

end_handler:
	
	DisConnServer();

}
/************************************************
*	
*   将BOM 替换件 信息传递到数据库
*
*************************************************/
void JK_write_sub_bom_to_DB(vector<JK_SUB_BOM_STRUCT> sub_bom_bean_vec
							,vector<JK_SUB_BOM_STRUCT> & field_sub_bean)
{
	int  i = 0,
		 ifail = 0;
	char fields_material[4096]="", 
		insert_values_material[4096]="",
		sql_value[10280] = "\0";
	for( i = 0; i < 17; i++ )
	{
		strcat(fields_material, jk_sub_bom_fields[i]);
		if( i != 16 )
			strcat(fields_material,",");
	}

	if(ConnServer(JK_DB_USER_NAME,JK_DB_USER_PWD,JK_DB_URL) == -1)
	{
		ECHO("提示:中间数据表访问失败\n");

		EMH_store_error_s1( EMH_severity_information, 
							ERROR_ERP_LOGIN_FAIL, 
							"中间数据表访问失败" );
		ifail = ERROR_ERP_LOGIN_FAIL;
		return;
	}

	for(i = 0; i < sub_bom_bean_vec.size(); i++ )
	{
		if(strcmp(sub_bom_bean_vec[i].JK_BOM_CID.c_str(),"")==0||sub_bom_bean_vec[i].JK_BOM_CID.length()==0)

		{
			continue;
		}
		strcpy(insert_values_material,"'");
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_BOM_ID.c_str());
		strcat(insert_values_material,"','");//	bom编号
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_BOM_REV.c_str());
		strcat(insert_values_material,"','");			//	bom版本
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_BOM_CID.c_str());
		strcat(insert_values_material,"','");	//	所有者
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_SUBSTITUTE_PART_ID.c_str());
		strcat(insert_values_material,"','");		//	母件损耗率
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_SUBSTITUTE_PART_INDEX.c_str());
		strcat(insert_values_material,"','");		//	生效日期			//5
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_SUBSTITUTE_PART_RATIO.c_str());
		strcat(insert_values_material,"','");		//	失效日期
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_SUBSTITUTE_PART_DATE.c_str());
		strcat(insert_values_material,"','");		//	是否失效
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_IS_GLOBAL.c_str());
		strcat(insert_values_material,"','");			//	扩展字段1
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_ATTR_2.c_str());
		strcat(insert_values_material,"','");			//	扩展字段2
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_ATTR_3.c_str());
		strcat(insert_values_material,"','");			//	扩展字段3			//20
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_ATTR_4.c_str());
		strcat(insert_values_material,"','");			//	扩展字段4
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_ATTR_5.c_str());
		strcat(insert_values_material,"','");			//	扩展字段5
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_ATTR_6.c_str());
		strcat(insert_values_material,"','");			//	扩展字段6
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_ATTR_7.c_str());
		strcat(insert_values_material,"','");			//	扩展字段7
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_ATTR_8.c_str());
		strcat(insert_values_material,"','");			//	扩展字段8			//25
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_ATTR_9.c_str());
		strcat(insert_values_material,"','");			//	扩展字段9
		strcat(insert_values_material,sub_bom_bean_vec[i].JK_ATTR_10.c_str());//	扩展字段10			//27
		strcat(insert_values_material,"'");
		
		sprintf(sql_value,"insert into %s (%s) values (%s)",
				JK_BOM_SUBSTITUTE_PART_TABLE,
				fields_material,
				insert_values_material);
		printf("SQL =>%s\n",sql_value);

		if(ExecuteSQLNoInputParam(sql_value)==-1)
		{
			printf("提示:插入BOM_TABLE表 失败, %s \n",sql_value);
			ifail = ERROR_OCI_FAIL;
			EMH_store_error(EMH_severity_error, ifail);
			//goto end_handler;
			field_sub_bean.push_back(sub_bom_bean_vec[i]);
		}else{
			printf("提示:插入BOM_TABLE表 成功, %s \n",sql_value);
		}
	}
	if(ifail == 0)
	{
		ExecuteSQLNoInputParam("commit");
	}

end_handler:
	
	DisConnServer();

}

/*******************************************************
*
* 获取单个物料的属性
*
********************************************************/
void JK_get_material_props(tag_t obj_tag , 
						   vector<JK_MATERIAL_STRUCT> & sm_bean_vec,
						   vector<string> bigCodeVec,
						   vector<string> qrBigCodeVec,
						   map<string,string> uomMapping,
						   string materialStatusName)
{
	int ifail = 0 ,
		status_count = 0,
		design_count = 0,
		master_count = 0,
		i = 0;
	tag_t item_tag =NULLTAG,
		*status_tags = NULL,
		*desin_tags =NULL,
		* master_tags = NULL,
		master_tag = NULLTAG,
		uom_tag =NULLTAG,
		current_user_tag = NULLTAG,
		current_group_mem_tag = NULLTAG,
		person_tag = NULLTAG,
		classification_object = NULLTAG,
		parentTag = NULLTAG,
		status_tag = NULLTAG;

	double dbjk8UnitWeight = 0,//单位重量
		   dbjk8UnitVolume = 0,//单位体积
		   dbjk8PurLeadTime=0,//固定提前期
		   dbjk8SafeStock=0,//安全库存
		   dbjk8InnTransCoe=0;//内部交易价格系数



	char item_id[ITEM_id_size_c + 1] = "\0",
		  *object_name  = NULL,
		  *item_revision_id  = NULL,
		  *status_name  = NULL,
		 *jk8SpecModel = NULL,
	//2019.06.13 新增特殊说明和产品识别号
	*jk8Remarks=NULL,
//	*jk8ProductIdentifyNO=NULL,
		 //*jk8StockBigTypeNo = NULL,
		 *jk8TechModel = NULL,
		 *represented_by =NULL,
		 *jk8UnitWeight1 =NULL,//0
		 *jk8UnitVolume1 =NULL,//0
		 jk8UnitWeight[32 + 1]="\0", //单位重量"
		 jk8UnitVolume[32 + 1]="\0",//单位体积"
		 *jk8IsDomesticMarket =NULL,//是否内销
		 *jk8Isconsumables =NULL,//是否耗用"
		 *jk8IsBuy =NULL,//是否采购"
		 *jk8IsMake =NULL,//是否自制"
		 *jk8IsOutsource =NULL,//是否委外"
		 *jk8AccountSet =NULL,//默认账套"
		 *jk8BusinessType =NULL,//业务类型"
		 *jk8Buyer =NULL,//采购员"
		 *jk8PurLeadTime1 =NULL,//0
		 *jk8SafeStock1 =NULL,//0
		 jk8PurLeadTime[32 + 1]="\0",//固定提前期"
		 jk8SafeStock[32 + 1]="\0",//安全库存"
		 *jk8SupplyType1 =NULL,//供应类型"
		 jk8SupplyType2[40]="\0",
		 *jk8Warehouse1 =NULL,//默认仓库"
		 jk8Warehouse2[40]="\0",
		 *jk8InnTransCoe1 =NULL,//0
		 jk8InnTransCoe[32 + 1]="\0",//内部交易价格系数"
		 *jk8WarehouseKeeper =NULL,//库管员"
		 *jk8IsInnTrans =NULL,//是否内部交易"
		 *jk8PlanMethod =NULL,//计划方式"
		*jk8DisabledDate=NULL,//停用日期
		*jk8EnableDate=NULL,//启用日期
		*jk8ProductIdentifyNO=NULL,//产品识别号
		 create_date_str[32] = "\0",
		 person_name[SA_person_name_size_c + 1]  = "\0",
		 * icsID = NULL,
		 *uom_str = NULL;
	date_t status_date ;
	string is_scrap,scrap_date;
	date_t current_date;
	logical isclassed = false;
	logical isFilter = false;
	//添加物料大类编码的过滤

	//获取分类属性
	ITKCALL(ICS_is_wsobject_classified(obj_tag,&isclassed));//判断是否已经分类
	if(isclassed){
		//char * icOid = NULL;
		ITKCALL(ICS_ask_classification_object(obj_tag,&classification_object));
		
		ITKCALL(ICS_ico_ask_class(classification_object,&icsID));

		//
		vector<string>::iterator it;
		it = find(qrBigCodeVec.begin(),qrBigCodeVec.end(),icsID);
		if(it != qrBigCodeVec.end())
		{
			printf("\n[ %s ]不包含在嵌软里面\n",icsID);
			if(icsID !=NULL)
			{
				MEM_free(icsID);
				icsID =NULL;
			}
			return;
		}

		it = find(bigCodeVec.begin(),bigCodeVec.end(),icsID);

		if(it != bigCodeVec.end()){
			printf("\n[ %s ]需要截取头两位\n",icsID);
			isFilter = true;
		}else{
			printf("\n[ %s ]需要截取头5位\n",icsID);
			isFilter = false;
		}
		
	}else{
		printf("\n 没有发送到分类 \n");
		return ;
	}


	//获取当前时间
	current_time(&current_date);
	sprintf(create_date_str,"%04d-%02d-%02d",current_date.year,1+ current_date.month,current_date.day);
	
	ITKCALL(SA_ask_current_groupmember(&current_group_mem_tag));	
	ITKCALL(SA_ask_groupmember_user(current_group_mem_tag,&current_user_tag));
	ITKCALL(SA_ask_user_person(current_user_tag,&person_tag));
	ITKCALL(SA_ask_person_name(person_tag , person_name));
	printf("person_name=> %s\n",person_name);

	ITKCALL(AOM_ask_value_tags(obj_tag,"IMAN_master_form_rev",&master_count,&master_tags));
	if(master_count > 0)
	{
		master_tag = master_tags[0];
	}

	//获取分类属性
//	ITKCALL(ICS_is_wsobject_classified(obj_tag,&isclassed));//判断是否已经分类
//	if(isclassed){
//		//char * icOid = NULL;
//		ITKCALL(ICS_ask_classification_object(obj_tag,&classification_object));
//		
//		ITKCALL(ICS_ico_ask_class(classification_object,&icsID));
//		
//	}
//

	ITKCALL(ifail = ITEM_ask_item_of_rev(obj_tag,&item_tag));//通过版本获取item对象
	
	
	ITKCALL(ifail = ITEM_ask_id(item_tag,item_id));//物料编码

	
	ITKCALL(ifail = AOM_ask_value_string(item_tag,MATERIAL_jk8DisabledDate,&jk8DisabledDate));//停用日期
	ITKCALL(ifail = AOM_ask_value_string(item_tag,MATERIAL_jk8EnableDate,&jk8EnableDate));//启用日期
	ITKCALL(ifail = AOM_ask_value_string(obj_tag,"object_name",&object_name));//物料名称
	//2019.11.19 发送版本信息
	ITKCALL(ifail = AOM_ask_value_string(obj_tag,"item_revision_id",&item_revision_id));//物料名称
	//2018.12.4 获取状态
//	ITKCALL(ifail = AOM_ask_value_string(obj_tag,"jk8Status",&status_name));//状态
	char  localization_status;
				logical  master  ;
	//2019.1.9把状态的中文发送到中间表
	ITKCALL(ifail = AOM_UIF_ask_localized_value_string(obj_tag,"jk8Status","zh_CN",&status_name,&localization_status,&master));//状态
	materialStatusName=status_name;
	
	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8SpecModel,&jk8SpecModel));//规格型号
	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8Remarks,&jk8Remarks));//特殊说明
	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8ProductIdentifyNO,&jk8ProductIdentifyNO));//产品识别号
	printf("规格型号=%s,\n",jk8SpecModel);
	
	//ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8StockBigTypeNo,&jk8StockBigTypeNo));//存货大类编码

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8TechModel,&jk8TechModel));//产品识别号
	printf("产品识别号=%s,\n",jk8TechModel);

	ITKCALL(ifail = AOM_UIF_ask_value(master_tag,MATERIAL_jk8UnitWeight,&jk8UnitWeight1));

	ITKCALL(ifail = AOM_ask_value_double(master_tag,MATERIAL_jk8UnitWeight,&dbjk8UnitWeight));//单位重量
	sprintf(jk8UnitWeight,"%.8f",dbjk8UnitWeight);

	ITKCALL(ifail = AOM_UIF_ask_value(master_tag,MATERIAL_jk8UnitVolume,&jk8UnitVolume1));
	ITKCALL(ifail = AOM_ask_value_double(master_tag,MATERIAL_jk8UnitVolume,&dbjk8UnitVolume));//单位体积
	sprintf(jk8UnitVolume,"%.8f",dbjk8UnitVolume);

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8IsDomesticMarket,&jk8IsDomesticMarket));//是否内销

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8Isconsumables,&jk8Isconsumables));//是否耗用

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8IsBuy,&jk8IsBuy));//是否采购

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8IsMake,&jk8IsMake));//是否自制
	
	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8IsOutsource,&jk8IsOutsource));//是否委外

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8AccountSet,&jk8AccountSet));//默认账套

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8BusinessType,&jk8BusinessType));//业务类型

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8Buyer,&jk8Buyer));//采购员

	ITKCALL(ifail = AOM_UIF_ask_value(master_tag,MATERIAL_jk8PurLeadTime,&jk8PurLeadTime1));
	ITKCALL(ifail = AOM_ask_value_double(master_tag,MATERIAL_jk8PurLeadTime,&dbjk8PurLeadTime));//固定提前期
	sprintf(jk8PurLeadTime,"%.8f",dbjk8PurLeadTime);

	ITKCALL(ifail = AOM_UIF_ask_value(master_tag,MATERIAL_jk8SafeStock,&jk8SafeStock1));
	ITKCALL(ifail = AOM_ask_value_double(master_tag,MATERIAL_jk8SafeStock,&dbjk8SafeStock));//安全库存
	sprintf(jk8SafeStock,"%.8f",dbjk8SafeStock);

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8SupplyType1,&jk8SupplyType1));//供应类型

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8Warehouse1,&jk8Warehouse1));//默认仓库

	ITKCALL(ifail = AOM_UIF_ask_value(master_tag,MATERIAL_jk8InnTransCoe,&jk8InnTransCoe1));
	ITKCALL(ifail = AOM_ask_value_double(master_tag,MATERIAL_jk8InnTransCoe,&dbjk8InnTransCoe));//内部交易价格系数
	sprintf(jk8InnTransCoe,"%.8f",dbjk8InnTransCoe);

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8WarehouseKeeper,&jk8WarehouseKeeper));//库管员

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8IsInnTrans,&jk8IsInnTrans));//是否内部交易

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8PlanMethod,&jk8PlanMethod));//计划方式
	//ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8ProductIdentifyNO,&jk8ProductIdentifyNO));//2019.04.11获取产品识别号，发送中间表

	ITKCALL(ifail = AOM_UIF_ask_value(obj_tag,"TC_Is_Represented_By",&represented_by));//物料信息
	
	//date_released    name
	ITKCALL(ifail = AOM_UIF_ask_value(item_tag,"uom_tag",&uom_str));//单位
	//ITKCALL(ifail = AOM_ask_value_string(item_tag,"uom_tag",&uom_str));//单位
	tag_t my_uom_tag = NULLTAG;
	//ITKCALL(ifail = ITEM_ask_unit_of_measure(item_tag,&my_uom_tag));
	//ITKCALL(ifail = UOM_ask_symbol(my_uom_tag,&uom_str));

	ITKCALL(ifail = AOM_ask_value_tags(obj_tag,"release_status_list",&status_count,&status_tags));//是否失效

	if(status_count > 0)
	{
		status_tag = status_tags[0];
		AOM_ask_value_date(status_tag,"date_released",&status_date);

	}

	for(i = 1;i < status_count;i++)
	{
		date_t date_t_i ;
		
		AOM_ask_value_date(status_tags[i],"date_released",&date_t_i);
		int day_count1 = sum(status_date.year ,1+status_date.month , status_date.day);
		int day_count2 = sum(date_t_i.year , 1+date_t_i.month , date_t_i.day);
		if(day_count1 < day_count2)
		{
			status_tag = status_tags[i];
			status_date = date_t_i;
		}
	}

	is_scrap.assign("0");
	if(status_tag !=NULLTAG)
	{
		char * status_name = NULL;
		ITKCALL(AOM_ask_value_string(status_tag,"name",&status_name));
		if(strcmp(status_name,SCRAPE_STATUS_NAME) ==0){
			is_scrap.assign("1");
			char scrp_date_str[32] = "\0";
			sprintf(scrp_date_str,"%04d-%02d-%02d",status_date.year,1 + status_date.month,status_date.day);
			scrap_date.assign(scrp_date_str);
			
		}else{
			//scrap_date.assign("2099-12-31");
			scrap_date.assign("\0");
		}

		if(status_name !=NULL){
			MEM_free(status_name);
			status_name = NULL;
		}
	}else{
		//scrap_date.assign("2099-12-31");
		scrap_date.assign("\0");
	}

	//printf("uom_tag => %s TC_Is_Represented_By => %s \n",uom_str,represented_by);

	
	/*cout<<"开始获取产品识别号---------"<<endl;
	logical    isClassified ;
	string cpsbh="";
	ITKCALL(ICS_is_wsobject_classified(obj_tag,&isClassified));//判断是否已经分类
	if(isClassified)
	{
		tag_t classObj,attribute_tag;
		tag_t ics_tag;
		char * class_id = NULL;
		ITKCALL(ifail=ICS_ask_classification_object(obj_tag,&classObj));
		int  	theAttributeCount;
		ICS_view_attribute_descriptor_p_t  attributes;
		ICS_view_descriptor_p_t   theViewDescriptor =NULL;
		ITKCALL( ICS_ico_ask_class_tag(classObj,&ics_tag));
		ITKCALL(ICS_ico_ask_class(classObj,&class_id));

		ITKCALL(ICS_view_describe(class_id,"","",FALSE,&theViewDescriptor));
		theAttributeCount = theViewDescriptor->attributeCount;
		attributes = theViewDescriptor->attributes;
		for(int i = 0; i < theAttributeCount;i++){
		
			string attr_name;
			cout<<"id--------------"<<attributes[i].id<<endl;
			cout<<"format----------------"<<attributes[i].format<<endl;
			cout<<"name-------------------"<<attributes[i].name<<endl;
			if(strcmp(attributes[i].name,"适用产品识别号")==0)
			{
				ITKCALL(ifail=ICS_ask_attribute(ics_tag,"适用产品识别号",&attribute_tag));
				char *classValue=NULL;
				if(ifail==0)
				{
					cout<<"有适用产品识别号------------------>"<<endl;
					ICS_ask_attribute_value(classObj,"适用产品识别号",&classValue);
					cout<<"适用产品识别号为------------------>"<<classValue<<endl;
					cpsbh=classValue;
				}
				if(classValue=NULL)
				{
					MEM_free(classValue);
					classValue=NULL;
				}
			}
		}
	}*/
	JK_MATERIAL_STRUCT m_bean;

	/*****************写入属性*****************/
	m_bean.JK_ITEM_ID.assign(item_id);
	m_bean.JK_CPSBH.assign(jk8ProductIdentifyNO);
	m_bean.JK_REMARKS.assign(jk8Remarks);
	m_bean.JK_PRODUCT_IDNO.assign(jk8ProductIdentifyNO);
	m_bean.JK_ITEM_NAME.assign(object_name);//2019.11.19
	m_bean.JK_ITEM_REV.assign(item_revision_id);
	if(materialStatusName.length()>0)
	{
		//2018.12.26参数设置什么值，传到中间表就是什么值
		//2019.1.9把本地值传到中间表
		m_bean.JK_MATERIAL_STATUS.assign(materialStatusName);
	}else
	{
		m_bean.JK_MATERIAL_STATUS.assign(status_name);
	}
	
	
	m_bean.JK_ITEM_SPEC_MODEL.assign(jk8SpecModel);
	char BIG_CODE[32] = "\0";
	char T_BIG_CODE[6] = "\0";
	sprintf(T_BIG_CODE,"%c%c",item_id[0],item_id[1]);
	if(isFilter){
		if(strcmp(T_BIG_CODE,"E-")==0){
			sprintf(BIG_CODE,"%c%c",item_id[2],item_id[3]);
		}else{
			sprintf(BIG_CODE,"%c%c",item_id[0],item_id[1]);
		}

	}else{
		if(strcmp(T_BIG_CODE,"E-")==0){
			sprintf(BIG_CODE,"%c%c%c%c%c",item_id[2],item_id[3],item_id[4],item_id[5],item_id[6]);
		}else{
			sprintf(BIG_CODE,"%c%c%c%c%c",item_id[0],item_id[1],item_id[2],item_id[3],item_id[4]);
		}
	}
	if (strstr(icsID,"prt")!=NULL)//2018/10/9改classid
	{
		sprintf(BIG_CODE,"%c%c%c%c%c",icsID[3],icsID[4],icsID[5],icsID[6],icsID[7]);
	}
	m_bean.JK_CLASS_CODE.assign(BIG_CODE);//icsID   jk8StockBigTypeNo

	m_bean.JK_PROD_CODE.assign(jk8TechModel);


	map<string,string>::iterator mapit;
	//printf("uom_str = %s \n",uom_str);
	mapit = uomMapping.find(uom_str);
	if(mapit != uomMapping.end()){
		//printf(" find uom %s = %s \n",mapit->first.c_str(),mapit->second.c_str());
		m_bean.JK_UOM.assign(mapit->second.c_str());//
	}else{
		m_bean.JK_UOM.assign("01");//
	}
	m_bean.JK_CREATION_DATE.assign(create_date_str);
	m_bean.JK_SCRAP_DATE.assign(scrap_date);
	m_bean.JK_DESIGN_CODE.assign(represented_by);
	m_bean.JK_IS_SCRAP.assign(is_scrap);

	m_bean.JK_FROM.assign(person_name);
	m_bean.JK_TRANS_TIME.assign(create_date_str);
	m_bean.JK_STATUS.assign("0");
	m_bean.JK_FROM_SYS.assign("TC");
	/******************************************/
	//if(strcmp(jk8UnitWeight1,"")!=0){
	m_bean.JK_UNIT_WEIGHT.assign(jk8UnitWeight);
	//}else{
	//m_bean.JK_UNIT_WEIGHT.assign(jk8UnitWeight1);
	//}
//	if(strcmp(jk8UnitVolume1,"")!=0){
	m_bean.JK_UNIT_VOLUME.assign(jk8UnitVolume);
	//}else{
	//m_bean.JK_UNIT_VOLUME.assign(jk8UnitVolume1);
	//}
	m_bean.JK_DOMSC_MARKET.assign(jk8IsDomesticMarket);
	m_bean.JK_CONSUM.assign(jk8Isconsumables);
	m_bean.JK_IS_BUY.assign(jk8IsBuy);
	m_bean.JK_IS_MAKE.assign(jk8IsMake);
	m_bean.JK_OUT_SOURCE.assign(jk8IsOutsource);
	m_bean.JK_ACCOUNT_SET.assign(jk8AccountSet);
	m_bean.JK_BUSINESS_TYPE.assign(jk8BusinessType);
	m_bean.JK_BUYER.assign(jk8Buyer);
	m_bean.JK_SCRAP_DATE.assign(jk8DisabledDate);
	m_bean.JK_ATTR_1.assign(jk8EnableDate);
	//if(strcmp.(jk8PurLeadTime1,"")!=0){
		m_bean.JK_PURLEAD_TIME.assign(jk8PurLeadTime);
	//}else{
	//	m_bean.JK_PURLEAD_TIME.assign(jk8PurLeadTime1);
	//}
	printf("jk8PurLeadTime1=%s\n",jk8PurLeadTime1);
	//if(strcmp(jk8SafeStock1,"")!=0){
		m_bean.JK_SAFE_STOCK.assign(jk8SafeStock);
	//}else{
	//	m_bean.JK_SAFE_STOCK.assign(jk8SafeStock1);
	//}
	printf("jk8SafeStock1=%s\n",jk8SafeStock1);
	if(strcmp(jk8SupplyType1,"")!=0){
		strncpy(jk8SupplyType2,jk8SupplyType1, 1);//截取第一个
		printf("jk8SafeStock2=%s\n",jk8SupplyType2);
		m_bean.JK_SUPPLY_TYPE1.assign(jk8SupplyType2);
	}else{
		m_bean.JK_SUPPLY_TYPE1.assign("3");
	}
	
	printf("jk8Warehouse1=%s\n",jk8SafeStock1);

	if(strcmp(jk8Warehouse1,"")!=0){
		strncpy(jk8Warehouse2,jk8Warehouse1, 2);//截取第一个
		
		m_bean.JK_WARE_HOUSE1.assign(jk8Warehouse2);
	}else{
		m_bean.JK_WARE_HOUSE1.assign("01");
	}
	
	//if(strcmp(jk8InnTransCoe1,"")!=0){
		m_bean.JK_INNTRANS_COE.assign(jk8InnTransCoe);
	//}else{
	//	m_bean.JK_INNTRANS_COE.assign(jk8InnTransCoe1);
	//}
	m_bean.JK_HOUSE_KEEPER.assign(jk8WarehouseKeeper);
	m_bean.JK_IS_INNTRANS.assign(jk8IsInnTrans);
	m_bean.JK_PLAN_METHOD.assign(jk8PlanMethod);


	sm_bean_vec.push_back(m_bean);
	
	//释放资源
	if(master_tags !=NULL)
	{
		MEM_free(master_tags);
		master_tags = NULL;
	}

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

	
	
	
	if(jk8ProductIdentifyNO !=NULL)
	{
		MEM_free(jk8ProductIdentifyNO);
		jk8ProductIdentifyNO =NULL;
	}
	if(jk8Remarks !=NULL)
	{
		MEM_free(jk8Remarks);
		jk8Remarks =NULL;
	}
	if(jk8TechModel !=NULL)
	{
		MEM_free(jk8TechModel);
		jk8TechModel =NULL;
	}	
	if(jk8DisabledDate !=NULL)
	{
		MEM_free(jk8DisabledDate);
		jk8DisabledDate =NULL;
	}	
	if(jk8EnableDate !=NULL)
	{
		MEM_free(jk8EnableDate);
		jk8EnableDate =NULL;
	}

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

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

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

	if(object_name != NULL)
	{
		MEM_free(object_name);
		object_name = NULL;
	
	}
	if(item_revision_id != NULL)
	{
		MEM_free(item_revision_id);
		item_revision_id = NULL;
	
	}	
	if(status_name != NULL)
	{
		MEM_free(status_name);
		status_name = NULL;
	
	}
	if(represented_by !=NULL){
		MEM_free(represented_by);
		represented_by = NULL;
	}
	
	if(icsID !=NULL)
	{
		MEM_free(icsID);
		icsID =NULL;
	}


	if(jk8IsDomesticMarket !=NULL)
	{
		MEM_free(jk8IsDomesticMarket);
		jk8IsDomesticMarket =NULL;
	}
	if(jk8Isconsumables !=NULL)
	{
		MEM_free(jk8Isconsumables);
		jk8Isconsumables =NULL;
	}
	if(jk8IsBuy !=NULL)
	{
		MEM_free(jk8IsBuy);
		jk8IsBuy =NULL;
	}
	if(jk8IsMake !=NULL)
	{
		MEM_free(jk8IsMake);
		jk8IsMake =NULL;
	}
	if(jk8IsOutsource !=NULL)
	{
		MEM_free(jk8IsOutsource);
		jk8IsOutsource =NULL;
	}
	if(jk8AccountSet !=NULL)
	{
		MEM_free(jk8AccountSet);
		jk8AccountSet =NULL;
	}
	if(jk8BusinessType !=NULL)
	{
		MEM_free(jk8BusinessType);
		jk8BusinessType =NULL;
	}
	if(jk8Buyer !=NULL)
	{
		MEM_free(jk8Buyer);
		jk8Buyer =NULL;
	}
	if(jk8SupplyType1 !=NULL)
	{
		MEM_free(jk8SupplyType1);
		jk8SupplyType1 =NULL;
	}
	if(jk8Warehouse1 !=NULL)
	{
		MEM_free(jk8Warehouse1);
		jk8Warehouse1 =NULL;
	}
	if(jk8WarehouseKeeper !=NULL)
	{
		MEM_free(jk8WarehouseKeeper);
		jk8WarehouseKeeper =NULL;
	}

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

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


	if(jk8UnitWeight1 !=NULL)
	{
		MEM_free(jk8UnitWeight1);
		jk8UnitWeight1 =NULL;
	}
	if(jk8UnitVolume1 !=NULL)
	{
		MEM_free(jk8UnitVolume1);
		jk8UnitVolume1 =NULL;
	}
	if(jk8PurLeadTime1 !=NULL)
	{
		MEM_free(jk8PurLeadTime1);
		jk8PurLeadTime1 =NULL;
	}
	if(jk8SafeStock1 !=NULL)
	{
		MEM_free(jk8SafeStock1);
		jk8SafeStock1 =NULL;
	}
	if(jk8InnTransCoe1 !=NULL)
	{
		MEM_free(jk8InnTransCoe1);
		jk8InnTransCoe1 =NULL;
	}

}

void JK_get_material_props1(tag_t obj_tag , 
						   vector<JK_MATERIAL_STRUCT> & sm_bean_vec,
						   vector<string> bigCodeVec,
						   vector<string> qrBigCodeVec,
						   map<string,string> uomMapping,
						   string dateType)
{

	cout<<"enter  JK_get_material_props1"<<endl;
	int ifail = 0 ,
		status_count = 0,
		design_count = 0,
		master_count = 0,
		i = 0;
	tag_t item_tag =NULLTAG,
		*status_tags = NULL,
		*desin_tags =NULL,
		* master_tags = NULL,
		master_tag = NULLTAG,
		uom_tag =NULLTAG,
		current_user_tag = NULLTAG,
		current_group_mem_tag = NULLTAG,
		person_tag = NULLTAG,
		classification_object = NULLTAG,
		parentTag = NULLTAG,
		status_tag = NULLTAG;

	double dbjk8UnitWeight = 0,//单位重量
		   dbjk8UnitVolume = 0,//单位体积
		   dbjk8PurLeadTime=0,//固定提前期
		   dbjk8SafeStock=0,//安全库存
		   dbjk8InnTransCoe=0;//内部交易价格系数



	char item_id[ITEM_id_size_c + 1] = "\0",
		  *object_name  = NULL,
		 *jk8SpecModel = NULL,
	//2019.06.13 新增特殊说明和产品识别号
	*jk8Remarks=NULL,
	*jk8ProductIdentifyNO=NULL,
		 //*jk8StockBigTypeNo = NULL,
		 *jk8TechModel = NULL,
		 *represented_by =NULL,
		 *jk8UnitWeight1 =NULL,//0
		 *jk8UnitVolume1 =NULL,//0
		 jk8UnitWeight[32 + 1]="\0", //单位重量"
		 jk8UnitVolume[32 + 1]="\0",//单位体积"
		 *jk8IsDomesticMarket =NULL,//是否内销
		 *jk8Isconsumables =NULL,//是否耗用"
		 *jk8IsBuy =NULL,//是否采购"
		 *jk8IsMake =NULL,//是否自制"
		 *jk8IsOutsource =NULL,//是否委外"
		 *jk8AccountSet =NULL,//默认账套"
		 *jk8BusinessType =NULL,//业务类型"
		 *jk8Buyer =NULL,//采购员"
		 *jk8PurLeadTime1 =NULL,//0
		 *jk8SafeStock1 =NULL,//0
		 jk8PurLeadTime[32 + 1]="\0",//固定提前期"
		 jk8SafeStock[32 + 1]="\0",//安全库存"
		 *jk8SupplyType1 =NULL,//供应类型"
		 jk8SupplyType2[40]="\0",
		 *jk8Warehouse1 =NULL,//默认仓库"
		 jk8Warehouse2[40]="\0",
		 *jk8InnTransCoe1 =NULL,//0
		 jk8InnTransCoe[32 + 1]="\0",//内部交易价格系数"
		 *jk8WarehouseKeeper =NULL,//库管员"
		 *jk8IsInnTrans =NULL,//是否内部交易"
		 *jk8PlanMethod =NULL,//计划方式"
		*jk8DisabledDate=NULL,//停用日期
		*jk8EnableDate=NULL,//启用日期
		 create_date_str[32] = "\0",
		 person_name[SA_person_name_size_c + 1]  = "\0",
		 * icsID = NULL,
		 *uom_str = NULL;
	date_t status_date ;
	string is_scrap,scrap_date;
	date_t current_date;
	logical isclassed = false;
	logical isFilter = false;
	//添加物料大类编码的过滤

	//获取分类属性
	ITKCALL(ICS_is_wsobject_classified(obj_tag,&isclassed));//判断是否已经分类
	if(isclassed){
		//char * icOid = NULL;
		ITKCALL(ICS_ask_classification_object(obj_tag,&classification_object));
		
		ITKCALL(ICS_ico_ask_class(classification_object,&icsID));

		//
		vector<string>::iterator it;
		it = find(qrBigCodeVec.begin(),qrBigCodeVec.end(),icsID);
		if(it != qrBigCodeVec.end())
		{
			printf("\n[ %s ]不包含在嵌软里面\n",icsID);
			if(icsID !=NULL)
			{
				MEM_free(icsID);
				icsID =NULL;
			}
			return;
		}

		it = find(bigCodeVec.begin(),bigCodeVec.end(),icsID);

		if(it != bigCodeVec.end()){
			printf("\n[ %s ]需要截取头两位\n",icsID);
			isFilter = true;
		}else{
			printf("\n[ %s ]需要截取头5位\n",icsID);
			isFilter = false;
		}
		
	}else{
		printf("\n 没有发送到分类 \n");
		return ;
	}


	//获取当前时间
	current_time(&current_date);
	sprintf(create_date_str,"%04d-%02d-%02d",current_date.year,1+ current_date.month,current_date.day);
	
	ITKCALL(SA_ask_current_groupmember(&current_group_mem_tag));	
	ITKCALL(SA_ask_groupmember_user(current_group_mem_tag,&current_user_tag));
	ITKCALL(SA_ask_user_person(current_user_tag,&person_tag));
	ITKCALL(SA_ask_person_name(person_tag , person_name));
	printf("person_name=> %s\n",person_name);

	ITKCALL(AOM_ask_value_tags(obj_tag,"IMAN_master_form_rev",&master_count,&master_tags));
	if(master_count > 0)
	{
		master_tag = master_tags[0];
	}

	//获取分类属性
//	ITKCALL(ICS_is_wsobject_classified(obj_tag,&isclassed));//判断是否已经分类
//	if(isclassed){
//		//char * icOid = NULL;
//		ITKCALL(ICS_ask_classification_object(obj_tag,&classification_object));
//		
//		ITKCALL(ICS_ico_ask_class(classification_object,&icsID));
//		
//	}
//

	ITKCALL(ifail = ITEM_ask_item_of_rev(obj_tag,&item_tag));//通过版本获取item对象
	
	
	ITKCALL(ifail = ITEM_ask_id(item_tag,item_id));//物料编码

	
	ITKCALL(ifail = AOM_ask_value_string(item_tag,MATERIAL_jk8DisabledDate,&jk8DisabledDate));//停用日期
	ITKCALL(ifail = AOM_ask_value_string(item_tag,MATERIAL_jk8EnableDate,&jk8EnableDate));//启用日期
	ITKCALL(ifail = AOM_ask_value_string(obj_tag,"object_name",&object_name));//物料名称

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8SpecModel,&jk8SpecModel));//规格型号
	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8Remarks,&jk8Remarks));//特殊说明
	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8ProductIdentifyNO,&jk8ProductIdentifyNO));//产品识别号
	printf("规格型号=%s,\n",jk8SpecModel);
	
	//ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8StockBigTypeNo,&jk8StockBigTypeNo));//存货大类编码

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8TechModel,&jk8TechModel));//产品识别号
	printf("产品识别号=%s,\n",jk8TechModel);

	ITKCALL(ifail = AOM_UIF_ask_value(master_tag,MATERIAL_jk8UnitWeight,&jk8UnitWeight1));

	ITKCALL(ifail = AOM_ask_value_double(master_tag,MATERIAL_jk8UnitWeight,&dbjk8UnitWeight));//单位重量
	sprintf(jk8UnitWeight,"%.8f",dbjk8UnitWeight);

	ITKCALL(ifail = AOM_UIF_ask_value(master_tag,MATERIAL_jk8UnitVolume,&jk8UnitVolume1));
	ITKCALL(ifail = AOM_ask_value_double(master_tag,MATERIAL_jk8UnitVolume,&dbjk8UnitVolume));//单位体积
	sprintf(jk8UnitVolume,"%.8f",dbjk8UnitVolume);

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8IsDomesticMarket,&jk8IsDomesticMarket));//是否内销

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8Isconsumables,&jk8Isconsumables));//是否耗用

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8IsBuy,&jk8IsBuy));//是否采购

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8IsMake,&jk8IsMake));//是否自制
	
	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8IsOutsource,&jk8IsOutsource));//是否委外

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8AccountSet,&jk8AccountSet));//默认账套

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8BusinessType,&jk8BusinessType));//业务类型

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8Buyer,&jk8Buyer));//采购员

	ITKCALL(ifail = AOM_UIF_ask_value(master_tag,MATERIAL_jk8PurLeadTime,&jk8PurLeadTime1));
	ITKCALL(ifail = AOM_ask_value_double(master_tag,MATERIAL_jk8PurLeadTime,&dbjk8PurLeadTime));//固定提前期
	sprintf(jk8PurLeadTime,"%.8f",dbjk8PurLeadTime);

	ITKCALL(ifail = AOM_UIF_ask_value(master_tag,MATERIAL_jk8SafeStock,&jk8SafeStock1));
	ITKCALL(ifail = AOM_ask_value_double(master_tag,MATERIAL_jk8SafeStock,&dbjk8SafeStock));//安全库存
	sprintf(jk8SafeStock,"%.8f",dbjk8SafeStock);

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8SupplyType1,&jk8SupplyType1));//供应类型

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8Warehouse1,&jk8Warehouse1));//默认仓库

	ITKCALL(ifail = AOM_UIF_ask_value(master_tag,MATERIAL_jk8InnTransCoe,&jk8InnTransCoe1));
	ITKCALL(ifail = AOM_ask_value_double(master_tag,MATERIAL_jk8InnTransCoe,&dbjk8InnTransCoe));//内部交易价格系数
	sprintf(jk8InnTransCoe,"%.8f",dbjk8InnTransCoe);

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8WarehouseKeeper,&jk8WarehouseKeeper));//库管员

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8IsInnTrans,&jk8IsInnTrans));//是否内部交易

	ITKCALL(ifail = AOM_ask_value_string(master_tag,MATERIAL_jk8PlanMethod,&jk8PlanMethod));//计划方式

	ITKCALL(ifail = AOM_UIF_ask_value(obj_tag,"TC_Is_Represented_By",&represented_by));//物料信息
	
	//date_released    name
	ITKCALL(ifail = AOM_UIF_ask_value(item_tag,"uom_tag",&uom_str));//单位
	//ITKCALL(ifail = AOM_ask_value_string(item_tag,"uom_tag",&uom_str));//单位
	tag_t my_uom_tag = NULLTAG;
	//ITKCALL(ifail = ITEM_ask_unit_of_measure(item_tag,&my_uom_tag));
	//ITKCALL(ifail = UOM_ask_symbol(my_uom_tag,&uom_str));

	ITKCALL(ifail = AOM_ask_value_tags(obj_tag,"release_status_list",&status_count,&status_tags));//是否失效

	if(status_count > 0)
	{
		status_tag = status_tags[0];
		AOM_ask_value_date(status_tag,"date_released",&status_date);

	}

	for(i = 1;i < status_count;i++)
	{
		date_t date_t_i ;
		
		AOM_ask_value_date(status_tags[i],"date_released",&date_t_i);
		int day_count1 = sum(status_date.year ,1+status_date.month , status_date.day);
		int day_count2 = sum(date_t_i.year , 1+date_t_i.month , date_t_i.day);
		if(day_count1 < day_count2)
		{
			status_tag = status_tags[i];
			status_date = date_t_i;
		}
	}

	is_scrap.assign("0");
	if(status_tag !=NULLTAG)
	{
		char * status_name = NULL;
		ITKCALL(AOM_ask_value_string(status_tag,"name",&status_name));
		if(strcmp(status_name,SCRAPE_STATUS_NAME) ==0){
			is_scrap.assign("1");
			char scrp_date_str[32] = "\0";
			sprintf(scrp_date_str,"%04d-%02d-%02d",status_date.year,1 + status_date.month,status_date.day);
			scrap_date.assign(scrp_date_str);
			
		}else{
			//scrap_date.assign("2099-12-31");
			scrap_date.assign("\0");
		}

		if(status_name !=NULL){
			MEM_free(status_name);
			status_name = NULL;
		}
	}else{
		//scrap_date.assign("2099-12-31");
		scrap_date.assign("\0");
	}

	//printf("uom_tag => %s TC_Is_Represented_By => %s \n",uom_str,represented_by);

	JK_MATERIAL_STRUCT m_bean;

	/*****************写入属性*****************/
	m_bean.JK_ITEM_ID.assign(item_id);
	m_bean.JK_ITEM_NAME.assign(object_name);
	m_bean.JK_ITEM_SPEC_MODEL.assign(jk8SpecModel);
	m_bean.JK_REMARKS.assign(jk8Remarks);
	m_bean.JK_PRODUCT_IDNO.assign(jk8ProductIdentifyNO);
	char BIG_CODE[32] = "\0";
	char T_BIG_CODE[6] = "\0";
	sprintf(T_BIG_CODE,"%c%c",item_id[0],item_id[1]);
	if(isFilter){
		if(strcmp(T_BIG_CODE,"E-")==0){
			sprintf(BIG_CODE,"%c%c",item_id[2],item_id[3]);
		}else{
			sprintf(BIG_CODE,"%c%c",item_id[0],item_id[1]);
		}

	}else{
		if(strcmp(T_BIG_CODE,"E-")==0){
			sprintf(BIG_CODE,"%c%c%c%c%c",item_id[2],item_id[3],item_id[4],item_id[5],item_id[6]);
		}else{
			sprintf(BIG_CODE,"%c%c%c%c%c",item_id[0],item_id[1],item_id[2],item_id[3],item_id[4]);
		}
	}
	if (strstr(icsID,"prt")!=NULL)//2018/10/9改classid
	{
		sprintf(BIG_CODE,"%c%c%c%c%c",icsID[3],icsID[4],icsID[5],icsID[6],icsID[7]);
	}
	m_bean.JK_CLASS_CODE.assign(BIG_CODE);//icsID   jk8StockBigTypeNo

	m_bean.JK_PROD_CODE.assign(jk8TechModel);


	map<string,string>::iterator mapit;
	//printf("uom_str = %s \n",uom_str);
	mapit = uomMapping.find(uom_str);
	if(mapit != uomMapping.end()){
		//printf(" find uom %s = %s \n",mapit->first.c_str(),mapit->second.c_str());
		m_bean.JK_UOM.assign(mapit->second.c_str());//
	}else{
		m_bean.JK_UOM.assign("01");//
	}
	m_bean.JK_CREATION_DATE.assign(create_date_str);
	m_bean.JK_SCRAP_DATE.assign(scrap_date);
	m_bean.JK_DESIGN_CODE.assign(represented_by);
	m_bean.JK_IS_SCRAP.assign(is_scrap);

	m_bean.JK_FROM.assign(person_name);
	m_bean.JK_TRANS_TIME.assign(create_date_str);
	m_bean.JK_STATUS.assign("0");
	m_bean.JK_FROM_SYS.assign("TC");
	/******************************************/
	//if(strcmp(jk8UnitWeight1,"")!=0){
	m_bean.JK_UNIT_WEIGHT.assign(jk8UnitWeight);
	//}else{
	//m_bean.JK_UNIT_WEIGHT.assign(jk8UnitWeight1);
	//}
//	if(strcmp(jk8UnitVolume1,"")!=0){
	m_bean.JK_UNIT_VOLUME.assign(jk8UnitVolume);
	//}else{
	//m_bean.JK_UNIT_VOLUME.assign(jk8UnitVolume1);
	//}
	m_bean.JK_DOMSC_MARKET.assign(jk8IsDomesticMarket);
	m_bean.JK_CONSUM.assign(jk8Isconsumables);
	m_bean.JK_IS_BUY.assign(jk8IsBuy);
	m_bean.JK_IS_MAKE.assign(jk8IsMake);
	m_bean.JK_OUT_SOURCE.assign(jk8IsOutsource);
	m_bean.JK_ACCOUNT_SET.assign(jk8AccountSet);
	m_bean.JK_BUSINESS_TYPE.assign(jk8BusinessType);
	m_bean.JK_BUYER.assign(jk8Buyer);
	m_bean.JK_SCRAP_DATE.assign(jk8DisabledDate);
	m_bean.JK_ATTR_1.assign(jk8EnableDate);
	//如果是失效状态dis，启用日期为空；如果是启用状态ena，失效日期置空
	if(strcmp(dateType.c_str(),"dis")==0)
	{
	
		m_bean.JK_ATTR_1.assign("\0");
	}else if(strcmp(dateType.c_str(),"ena")==0)
	{
		m_bean.JK_SCRAP_DATE.assign("\0");
		
	}
	//if(strcmp.(jk8PurLeadTime1,"")!=0){
		m_bean.JK_PURLEAD_TIME.assign(jk8PurLeadTime);
	//}else{
	//	m_bean.JK_PURLEAD_TIME.assign(jk8PurLeadTime1);
	//}
	printf("jk8PurLeadTime1=%s\n",jk8PurLeadTime1);
	//if(strcmp(jk8SafeStock1,"")!=0){
		m_bean.JK_SAFE_STOCK.assign(jk8SafeStock);
	//}else{
	//	m_bean.JK_SAFE_STOCK.assign(jk8SafeStock1);
	//}
	printf("jk8SafeStock1=%s\n",jk8SafeStock1);
	if(strcmp(jk8SupplyType1,"")!=0){
		strncpy(jk8SupplyType2,jk8SupplyType1, 1);//截取第一个
		printf("jk8SafeStock2=%s\n",jk8SupplyType2);
		m_bean.JK_SUPPLY_TYPE1.assign(jk8SupplyType2);
	}else{
		m_bean.JK_SUPPLY_TYPE1.assign("3");
	}
	
	printf("jk8Warehouse1=%s\n",jk8SafeStock1);

	if(strcmp(jk8Warehouse1,"")!=0){
		strncpy(jk8Warehouse2,jk8Warehouse1, 2);//截取第一个
		
		m_bean.JK_WARE_HOUSE1.assign(jk8Warehouse2);
	}else{
		m_bean.JK_WARE_HOUSE1.assign("01");
	}
	
	//if(strcmp(jk8InnTransCoe1,"")!=0){
		m_bean.JK_INNTRANS_COE.assign(jk8InnTransCoe);
	//}else{
	//	m_bean.JK_INNTRANS_COE.assign(jk8InnTransCoe1);
	//}
	m_bean.JK_HOUSE_KEEPER.assign(jk8WarehouseKeeper);
	m_bean.JK_IS_INNTRANS.assign(jk8IsInnTrans);
	m_bean.JK_PLAN_METHOD.assign(jk8PlanMethod);


	sm_bean_vec.push_back(m_bean);
	
	//释放资源
	if(master_tags !=NULL)
	{
		MEM_free(master_tags);
		master_tags = NULL;
	}

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

	if(jk8Remarks !=NULL)
	{
		MEM_free(jk8Remarks);
		jk8Remarks =NULL;
	}
	if(jk8ProductIdentifyNO !=NULL)
	{
		MEM_free(jk8ProductIdentifyNO);
		jk8ProductIdentifyNO =NULL;
	}

	if(jk8TechModel !=NULL)
	{
		MEM_free(jk8TechModel);
		jk8TechModel =NULL;
	}	
	if(jk8DisabledDate !=NULL)
	{
		MEM_free(jk8DisabledDate);
		jk8DisabledDate =NULL;
	}	
	if(jk8EnableDate !=NULL)
	{
		MEM_free(jk8EnableDate);
		jk8EnableDate =NULL;
	}

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

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

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

	if(object_name != NULL)
	{
		MEM_free(object_name);
		object_name = NULL;
	
	}
	if(represented_by !=NULL){
		MEM_free(represented_by);
		represented_by = NULL;
	}
	
	if(icsID !=NULL)
	{
		MEM_free(icsID);
		icsID =NULL;
	}


	if(jk8IsDomesticMarket !=NULL)
	{
		MEM_free(jk8IsDomesticMarket);
		jk8IsDomesticMarket =NULL;
	}
	if(jk8Isconsumables !=NULL)
	{
		MEM_free(jk8Isconsumables);
		jk8Isconsumables =NULL;
	}
	if(jk8IsBuy !=NULL)
	{
		MEM_free(jk8IsBuy);
		jk8IsBuy =NULL;
	}
	if(jk8IsMake !=NULL)
	{
		MEM_free(jk8IsMake);
		jk8IsMake =NULL;
	}
	if(jk8IsOutsource !=NULL)
	{
		MEM_free(jk8IsOutsource);
		jk8IsOutsource =NULL;
	}
	if(jk8AccountSet !=NULL)
	{
		MEM_free(jk8AccountSet);
		jk8AccountSet =NULL;
	}
	if(jk8BusinessType !=NULL)
	{
		MEM_free(jk8BusinessType);
		jk8BusinessType =NULL;
	}
	if(jk8Buyer !=NULL)
	{
		MEM_free(jk8Buyer);
		jk8Buyer =NULL;
	}
	if(jk8SupplyType1 !=NULL)
	{
		MEM_free(jk8SupplyType1);
		jk8SupplyType1 =NULL;
	}
	if(jk8Warehouse1 !=NULL)
	{
		MEM_free(jk8Warehouse1);
		jk8Warehouse1 =NULL;
	}
	if(jk8WarehouseKeeper !=NULL)
	{
		MEM_free(jk8WarehouseKeeper);
		jk8WarehouseKeeper =NULL;
	}

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

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

	if(jk8UnitWeight1 !=NULL)
	{
		MEM_free(jk8UnitWeight1);
		jk8UnitWeight1 =NULL;
	}
	if(jk8UnitVolume1 !=NULL)
	{
		MEM_free(jk8UnitVolume1);
		jk8UnitVolume1 =NULL;
	}
	if(jk8PurLeadTime1 !=NULL)
	{
		MEM_free(jk8PurLeadTime1);
		jk8PurLeadTime1 =NULL;
	}
	if(jk8SafeStock1 !=NULL)
	{
		MEM_free(jk8SafeStock1);
		jk8SafeStock1 =NULL;
	}
	if(jk8InnTransCoe1 !=NULL)
	{
		MEM_free(jk8InnTransCoe1);
		jk8InnTransCoe1 =NULL;
	}

}

/*******************************************************
*
* 获取替代件信息
*
*******************************************************/
void JK_get_subline_props(string bom_id,
						  string bom_rev,
						  string c_line_id, 
						  tag_t bom_line_tag,
						  vector<JK_SUB_BOM_STRUCT> & sub_bom_vec){

	int sub_obj_count = 0,
		effectiveDate_count = 0,
		order_count = 0,
		ratio_count = 0,
		n_substitute = 0,
		golbal_alt_count = 0,
		golbal_Date_count = 0,
		golbal_order_count = 0,
		golbal_ratio_count = 0;


	tag_t *substitute_tags = NULL,
		  *golbal_alt_tags = NULL,
		  bl_item = NULLTAG,
		  bl_rev = NULLTAG;

	char ** golbalDate_str_s = NULL,
		 ** golbalorder_str_s = NULL,
		 ** golbalratio_str_s = NULL;
	/*char ** effectiveDate_str_s = NULL,
		 ** order_str_s = NULL,
		 ** ratio_str_s = NULL,
		 item_id_2[ITEM_id_size_c + 1] = "\0";*/

	char * effectiveDate_str = NULL,
		 * order_str = NULL,
		 * ratio_str = NULL,
		item_id_2[ITEM_id_size_c + 1] = "\0";
	if(bom_line_tag==NULL)
	{
		return;
	}
	ITKCALL(AOM_ask_value_tag(bom_line_tag,"bl_line_object",&bl_rev));
	if(bl_rev==NULL)
	{
		return;
	}
	ITKCALL(ITEM_ask_item_of_rev(bl_rev,&bl_item));
	ITKCALL(AOM_ask_value_tags(bl_item,"global_alt_list",&golbal_alt_count,&golbal_alt_tags));
	ITKCALL(BOM_line_list_substitutes(bom_line_tag,&n_substitute,&substitute_tags));

	/*ITKCALL(AOM_ask_value_strings(bom_line_tag,JK_SUBSTITUTE_EffectiveDate,&effectiveDate_count,&effectiveDate_str_s));
	ITKCALL(AOM_ask_value_strings(bom_line_tag,JK_SUBSTITUTE_Order,&order_count,&order_str_s));
	ITKCALL(AOM_ask_value_strings(bom_line_tag,JK_SUBSTITUTE_Ratio,&ratio_count,&ratio_str_s));*/

	ITKCALL(AOM_ask_value_strings(bl_item,"jk8OvrlSubstitTime",&golbal_Date_count,&golbalDate_str_s));  //2018.3.15改全局替代件
	ITKCALL(AOM_ask_value_strings(bl_item,"jk8OvrlSubstitOrder",&golbal_order_count,&golbalorder_str_s));
	ITKCALL(AOM_ask_value_strings(bl_item,"jk8OvrlSubstitRatio",&golbal_ratio_count,&golbalratio_str_s));
	
	ITKCALL(AOM_ask_value_string(bom_line_tag,JK_SUBSTITUTE_EffectiveDate1,&effectiveDate_str));
	ITKCALL(AOM_ask_value_string(bom_line_tag,JK_SUBSTITUTE_Order1,&order_str));
	ITKCALL(AOM_ask_value_string(bom_line_tag,JK_SUBSTITUTE_Ratio1,&ratio_str));

	vector<string> orderVecs ;
	vector<string> ratioVecs ;
	vector<string> effectiveVecs ;
	Split(effectiveDate_str,",",effectiveVecs);
	Split(order_str,",",orderVecs);
	Split(ratio_str,",",ratioVecs);

	if(n_substitute == effectiveVecs.size() 
		&& n_substitute == ratioVecs.size()
		&& n_substitute == orderVecs.size()){
			printf("替换件，替换比例，替换日期，替换顺序 数量一致，给予传递\n");
			for(int i = 0;i < n_substitute;i++){
				JK_SUB_BOM_STRUCT sub_struct ;
				char index[12] = "\0";
				sprintf(index,"%d",i);
				char * item_id =NULL;
				ITKCALL(AOM_ask_value_string(substitute_tags[i],"bl_item_item_id",&item_id));
				sub_struct.JK_BOM_ID.assign(bom_id);
				sub_struct.JK_BOM_REV.assign(bom_rev);
				sub_struct.JK_BOM_CID.assign(c_line_id);
				sub_struct.JK_SUBSTITUTE_PART_ID.assign(item_id);

				string orderVec1="1";
				string ratioVec1="1";
				string effectiveVec1="2001-01-01";
				for(int j = 0;j < n_substitute;j++){
					vector<string> orderVec ;
					vector<string> ratioVec ;
					vector<string> effectiveVec ;
					printf("orderVecs=%s\n",orderVecs[i]);
					printf("ratioVecs=%s\n",orderVecs[i]);
					printf("effectiveVecs=%s\n",orderVecs[i]);
					Split(orderVecs[i],"&",orderVec);
					Split(ratioVecs[i],"&",ratioVec);
					Split(effectiveVecs[i],"&",effectiveVec);
					if(orderVec.empty()){

					}else{
						if(orderVec.size()>1&&stricmp(item_id,orderVec[0].c_str()) == 0){
							if(strcmp(orderVec[1].c_str(),"")==0){

							}else{
								orderVec1=orderVec[1];
							}

						}
					}

					if(ratioVec.empty()){

					}else{
						if(ratioVec.size()>1&&stricmp(item_id,ratioVec[0].c_str()) == 0){
							if(strcmp(ratioVec[1].c_str(),"")==0){

							}else{
								ratioVec1=ratioVec[1];
							}
						}
					}

					if(effectiveVec.empty()){

					}else{
						if(effectiveVec.size()>1&&stricmp(item_id,effectiveVec[0].c_str()) == 0){
							if(strcmp(effectiveVec[1].c_str(),"")==0){

							}else{
								effectiveVec1=effectiveVec[1];
							}

						}
					}


				}
				printf("id =%s ,orderVec1= %s /n",item_id,orderVec1);
				printf("id =%s ,ratioVec1= %s /n",item_id,ratioVec1);
				printf("id =%s ,effectiveVec1= %s /n",item_id,effectiveVec1);

				sub_struct.JK_SUBSTITUTE_PART_INDEX.assign(orderVec1);

				sub_struct.JK_SUBSTITUTE_PART_RATIO.assign(ratioVec1);

				sub_struct.JK_SUBSTITUTE_PART_DATE.assign(effectiveVec1);
				sub_struct.JK_IS_GLOBAL.assign("2");

				sub_bom_vec.push_back(sub_struct);
				if(item_id!=NULL){
					MEM_free(item_id);
					item_id =NULL;
				}
			}
	}else{
		printf("替换件，替换比例，替换日期，替换顺序 数量不一致，给予默认传递\n");
		for(int i = 0;i < n_substitute;i++){
			JK_SUB_BOM_STRUCT sub_struct ;
			char index[12] = "\0";
			sprintf(index,"%d",i);
			char * item_id =NULL;
			ITKCALL(AOM_ask_value_string(substitute_tags[i],"bl_item_item_id",&item_id));
			sub_struct.JK_BOM_ID.assign(bom_id);
			sub_struct.JK_BOM_REV.assign(bom_rev);
			sub_struct.JK_BOM_CID.assign(c_line_id);
			sub_struct.JK_SUBSTITUTE_PART_ID.assign(item_id);
			sub_struct.JK_SUBSTITUTE_PART_INDEX.assign(index);
			sub_struct.JK_SUBSTITUTE_PART_RATIO.assign("1");
			sub_struct.JK_SUBSTITUTE_PART_DATE.assign("2001-01-01");
			sub_struct.JK_IS_GLOBAL.assign("2");

			sub_bom_vec.push_back(sub_struct);
			if(item_id!=NULL){
				MEM_free(item_id);
				item_id =NULL;
			}
		}

	}
	//处理全局替换件
	if(golbal_alt_count == golbal_Date_count 
		&& golbal_alt_count == golbal_order_count
		&& golbal_alt_count == golbal_ratio_count){
			printf("全局替换件，替换比例，替换日期，替换顺序 数量一致，给予传递\n");
			for(int i = 0 ;i < golbal_alt_count;i++){
				ITKCALL(ITEM_ask_id(golbal_alt_tags[i],item_id_2));
				JK_SUB_BOM_STRUCT sub_struct ;
				char index[12] = "\0";
				sprintf(index,"%d",i);
				char orderVec1[100]="1";
				char ratioVec1[100]="1";
				char effectiveVec1[100]="2001-01-01";

				if(strcmp(golbalorder_str_s[i],"")==0){
					strcpy(orderVec1,"1");

				}else{
					strcpy(orderVec1,golbalorder_str_s[i]);
				}
				if(strcmp(golbalratio_str_s[i],"")==0){
					strcpy(ratioVec1,"1");
				}else{
					strcpy(ratioVec1,golbalratio_str_s[i]);
				}
				if(strcmp(golbalDate_str_s[i],"")==0){
					strcpy(effectiveVec1,"2001-01-01");
				}else{
					strcpy(effectiveVec1,golbalDate_str_s[i]);
				}


				sub_struct.JK_BOM_ID.assign(bom_id);
				sub_struct.JK_BOM_REV.assign(bom_rev);
				sub_struct.JK_BOM_CID.assign(c_line_id);
				sub_struct.JK_SUBSTITUTE_PART_ID.assign(item_id_2);
				sub_struct.JK_SUBSTITUTE_PART_INDEX.assign(orderVec1);
				sub_struct.JK_SUBSTITUTE_PART_RATIO.assign(ratioVec1);
				sub_struct.JK_SUBSTITUTE_PART_DATE.assign(effectiveVec1);
				sub_struct.JK_IS_GLOBAL.assign("1");
				sub_bom_vec.push_back(sub_struct);
			}



	}else{
		printf("全局替换件，替换比例，替换日期，替换顺序 数量不一致，给予默认传递\n");
		for(int i = 0 ;i < golbal_alt_count;i++){
			ITKCALL(ITEM_ask_id(golbal_alt_tags[i],item_id_2));
			JK_SUB_BOM_STRUCT sub_struct ;
			char index[12] = "\0";
			sprintf(index,"%d",i);
			sub_struct.JK_BOM_ID.assign(bom_id);
			sub_struct.JK_BOM_REV.assign(bom_rev);
			sub_struct.JK_BOM_CID.assign(c_line_id);
			sub_struct.JK_SUBSTITUTE_PART_ID.assign(item_id_2);
			sub_struct.JK_SUBSTITUTE_PART_INDEX.assign(index);
			sub_struct.JK_SUBSTITUTE_PART_RATIO.assign("1");
			sub_struct.JK_SUBSTITUTE_PART_DATE.assign("2001-01-01");
			sub_struct.JK_IS_GLOBAL.assign("1");
			sub_bom_vec.push_back(sub_struct);
		}
	}


	if(substitute_tags!=NULL){
		MEM_free(substitute_tags);
		substitute_tags =NULL;
	}
	if(golbal_alt_tags !=NULL){
		MEM_free(golbal_alt_tags);
		golbal_alt_tags =NULL;
	}


}

/*******************************************************
*
* 获取子bomline属性的属性
*
********************************************************/
void JK_get_bomline_props(string bom_id,
						  string bom_rev,  
						  tag_t line_tag , 
						  vector<JK_P_BOM_STRUCT> & p_bom_vec ,
						  vector<JK_C_BOM_STRUCT> & c_bom_vec,
						  vector<JK_SUB_BOM_STRUCT> & sub_bom_vec)
{
	int child_count = 0 ,
		i = 0;
	tag_t * child_tags = NULL;
	POM_AM__set_application_bypass(true);
	ITKCALL(BOM_line_ask_all_child_lines(line_tag,&child_count,&child_tags));
	for( i  = 0 ; i < child_count ; i++){
		char * bl_item_id =NULL,
			 * bl_item_rev_id = NULL,
			 * Jk8SupplyType = NULL,
			 Jk8SupplyType1[40]="\0",
			 *Jk8Warehouse =NULL,
			 Jk8Warehouse1[40]="\0",
			 *bl_quantity =NULL,
			 *JK_BOM_CWR = NULL,
			 *Jk8RemarkDesc = NULL;
		char* type_class=NULL;
		tag_t rev_tag = NULLTAG,
			  *view_tags =NULL;
		int view_count = 0;
		string bl_rev_id ;
		 //因为生产代码做了权限管控所以读取不到bl_item_object_type，要开旁路
		POM_AM__set_application_bypass(true);
		ITKCALL( AOM_ask_value_string(child_tags[i],"bl_item_object_type",&type_class));
		printf("type_class=%s\n",type_class);
		if(strcmp(type_class, "JK8EmbSoftware" ) ==0){//生产代码不传 2017.9.27
			printf("生产代码JK8EmbSoftware不传跳过");
			continue;

		}
	
		ITKCALL(AOM_ask_value_string(child_tags[i],"bl_item_item_id",&bl_item_id));//bl_item_item_id
		if(strcmp(bl_item_id,"LS")==1){  //临时物料不传 2018.1.22
			continue;
		}
		ITKCALL(AOM_ask_value_tag(child_tags[i],"bl_line_object",&rev_tag));
		
		ITKCALL(AOM_ask_value_string(child_tags[i],"bl_rev_item_revision_id",&bl_item_rev_id));//bl_item_id
		ITKCALL(AOM_ask_value_string(child_tags[i],BOM_Jk8SupplyType,&Jk8SupplyType));//Jk8SupplyType  供应类型
		ITKCALL(AOM_ask_value_string(child_tags[i],BOM_Jk8Warehouse,&Jk8Warehouse));//Jk8Warehouse    仓库
		ITKCALL(AOM_UIF_ask_value(child_tags[i],BOM_JK_BOM_CWR,&JK_BOM_CWR));//BOM_JK_BOM_CWR
		ITKCALL(AOM_ask_value_string(child_tags[i],"bl_quantity",&bl_quantity));//
		ITKCALL(AOM_ask_value_string(child_tags[i],BOM_Jk8RemarkDesc,&Jk8RemarkDesc));//Jk8RemarkDesc  备注

		bl_rev_id.assign(bl_item_rev_id);
		JK_C_BOM_STRUCT c_bean;

		c_bean.JK_BOM_ID.assign(bom_id);
		c_bean.JK_BOM_REV.assign(bom_rev);
		c_bean.JK_BOM_CID.assign(bl_item_id);

		if(Jk8SupplyType==NULL || strlen(Jk8SupplyType) ==0){
			c_bean.JK_SUPPLY_TYPE.assign("3");//Jk8SupplyType
		}else{
			strncpy(Jk8SupplyType1,Jk8SupplyType, 1);//截取第一个
			c_bean.JK_SUPPLY_TYPE.assign(Jk8SupplyType1);//Jk8SupplyType
		}
		if(Jk8Warehouse == NULL || strlen(Jk8Warehouse) == 0){
			c_bean.JK_WAREHOUSE.assign("");//Jk8Warehouse

		}else{
			strncpy(Jk8Warehouse1,Jk8Warehouse, 2);//截取第2个
			c_bean.JK_WAREHOUSE.assign(Jk8Warehouse1);//Jk8Warehouse
		}
		

		if(bl_quantity == NULL ||strlen(bl_quantity) ==0){
			c_bean.JK_QUANTITY.assign("1");
		}else{
			c_bean.JK_QUANTITY.assign(bl_quantity);
		}
		c_bean.JK_REMARK.assign(Jk8RemarkDesc);

		if(JK_BOM_CWR == NULL|| strlen(JK_BOM_CWR)==0){
			c_bean.JK_BOM_CWR.assign("0");//JK_BOM_CWR//2017/10.23子件损耗率默认值1改为0
		//}else if(strcmp(JK_BOM_CWR,"")==0){
		}else{
			c_bean.JK_BOM_CWR.assign(JK_BOM_CWR);//JK_BOM_CWR
		}

		c_bom_vec.push_back(c_bean);
		if(child_tags[i]!=NULL)
		{
			JK_get_subline_props(bom_id,bom_rev,c_bean.JK_BOM_CID,child_tags[i],sub_bom_vec);
		}

		
		// ITKCALL(AOM_ask_value_tags(rev_tag,"structure_revisions",&view_count,&view_tags));
		if(view_count > 0){

			//获取子BOM结构开始
			//JK_get_top_bomline_props(view_tags[0],p_bom_vec,c_bom_vec,sub_bom_vec);
		}

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

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

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

		if(bl_item_id!=NULL){
			MEM_free(bl_item_id);
			bl_item_id = NULL;
		}
		if(Jk8SupplyType != NULL){
			MEM_free(Jk8SupplyType);
			Jk8SupplyType =NULL;
		}
		if(Jk8Warehouse != NULL){
			MEM_free(Jk8Warehouse);
			Jk8Warehouse =NULL;
		}
		if(bl_quantity != NULL){
			MEM_free(bl_quantity);
			bl_quantity =NULL;
		}
		if(Jk8RemarkDesc != NULL){
			MEM_free(Jk8RemarkDesc);
			Jk8RemarkDesc =NULL;
		}
		if(JK_BOM_CWR !=NULL){
			MEM_free(JK_BOM_CWR);
			JK_BOM_CWR =NULL;

		}
		
	}
	POM_AM__set_application_bypass(false);
	if(child_tags!=NULL){
		MEM_free(child_tags);
		child_tags =NULL;
	}
}



/*******************************************************
*
* 获取子TOP Bomline属性的属性
*
********************************************************/
void JK_get_top_bomline_props(tag_t view_tag , 
						      vector<JK_P_BOM_STRUCT> & p_bom_vec ,
							  vector<JK_C_BOM_STRUCT> & c_bom_vec,
							  vector<JK_SUB_BOM_STRUCT> & sub_bom_vec)
{
	int ifail = 0 ,
		i = 0,
		status_count = 0 ,
		c_line_count = 0 ,
		rev_form_cnt = 0 ;
	tag_t rev_tag =NULLTAG,
		  item_tag = NULLTAG,
		  owning_user_tag = NULLTAG,
		  current_user_tag = NULLTAG,
		  current_group_mem_tag = NULLTAG,
		  person_tag = NULLTAG,
		  bom_window_tag = NULLTAG,
		  *status_tags = NULL,
		  status_tag = NULLTAG,
		  top_line_tag = NULLTAG,
		  *c_line_tags = NULL,
		  *rev_form_tags = NULL;

	char item_id[ITEM_id_size_c + 1] = "\0",
		 rev_id[ITEM_id_size_c + 1]  = "\0",
		 *user_name = NULL,
		 *jk8_mjshl = NULL,
		 create_date_str[32] = "\0",
		 send_date_str[32] = "\0",
		 person_name[SA_person_name_size_c + 1]  = "\0";
	date_t status_date ;
	date_t create_date ;
	string is_scrap,scrap_date;
	date_t current_date;

	current_time(&current_date);
	sprintf(send_date_str,"%04d-%02d-%02d",current_date.year,1+ current_date.month,current_date.day);
	
	ITKCALL(ifail = BOM_create_window(&bom_window_tag));//创建window视图
	ITKCALL(ifail = BOM_set_window_top_line_bvr(bom_window_tag,view_tag,&top_line_tag));//获取顶层bomline
	ITKCALL(BOM_line_ask_all_child_lines(top_line_tag,&c_line_count,&c_line_tags));
	if(c_line_count == 0){
		printf("没有BOM结构");
		ITKCALL(ifail = BOM_close_window(bom_window_tag));
		return;
	}
	//获取当前用户名称
	ITKCALL(SA_ask_current_groupmember(&current_group_mem_tag));	
	ITKCALL(SA_ask_groupmember_user(current_group_mem_tag,&current_user_tag));
	ITKCALL(SA_ask_user_person(current_user_tag,&person_tag));
	ITKCALL(SA_ask_person_name(person_tag , person_name));
	printf("current person_name=> %s\n",person_name);
	
	ITKCALL(AOM_ask_value_tag(top_line_tag,"bl_line_object",&rev_tag));//获取BOMLINE关联的版本
	ITKCALL(ITEM_ask_item_of_rev(rev_tag,&item_tag));
	ITKCALL(ITEM_ask_id(item_tag,item_id));//物料编码

	if(strcmp(item_id,"E-")==1){
		return;
	}
	if(strcmp(item_id,"LS")==1){
		return;
	}


	ITKCALL(ITEM_ask_rev_id(rev_tag,rev_id));//获取版本号

	ITKCALL(AOM_ask_value_date(rev_tag,"creation_date", &create_date));//add 版本创建时间 creation_date
	
	if(create_date.year !=0){
		sprintf(create_date_str,"%04d-%02d-%02d",create_date.year,1+ create_date.month,create_date.day);
	}

	ITKCALL(AOM_ask_value_tags(rev_tag,"IMAN_master_form_rev",&rev_form_cnt,&rev_form_tags));
	ITKCALL(AOM_ask_value_tag(view_tag,"owning_user",&owning_user_tag));//bvr的所有者
	ITKCALL(AOM_ask_value_string(owning_user_tag,"user_name",&user_name));//获取所有者名称

	ITKCALL(ifail = AOM_UIF_ask_value(rev_form_tags[i],BOM_jk8_mjshl,&jk8_mjshl));//母件损耗率  jk8_mjshl
	ITKCALL(ifail = AOM_ask_value_tags(view_tag,"release_status_list",&status_count,&status_tags));//是否失效

	if(rev_form_tags!=NULL){
		MEM_free(rev_form_tags);
		rev_form_tags =NULL;
	}
	if(status_count > 0)
	{
		status_tag = status_tags[0];
		AOM_ask_value_date(status_tag,"date_released",&status_date);
	}

	for(i = 1;i < status_count;i++)
	{
		date_t date_t_i ;
		AOM_ask_value_date(status_tags[i],"date_released",&date_t_i);
		int day_count1 = sum(status_date.year ,1+status_date.month , status_date.day);
		int day_count2 = sum(date_t_i.year , 1+date_t_i.month , date_t_i.day);
		if(day_count1 < day_count2)
		{
			status_tag = status_tags[i];
			status_date = date_t_i;
		}
	}

	is_scrap.assign("0");
	if(status_tag !=NULLTAG)
	{
		char * status_name = NULL;
		ITKCALL(AOM_ask_value_string(status_tag,"name",&status_name));
		if(strcmp(status_name, SCRAPE_STATUS_NAME ) ==0){
			is_scrap.assign("1");
			char scrp_date_str[32] = "\0";
			sprintf(scrp_date_str,"%04d-%02d-%02d",status_date.year,1 + status_date.month,status_date.day);
			scrap_date.assign(scrp_date_str);	
		}else{
			scrap_date.assign("2099-12-31");	
		}

		if(status_name !=NULL){
			MEM_free(status_name);
			status_name = NULL;
		}
	}else{
		scrap_date.assign("2099-12-31");
	}

	JK_P_BOM_STRUCT p_bean;

	/*****************写入属性*****************/
	p_bean.JK_BOM_ID.assign(item_id);
	p_bean.JK_BOM_REV.assign(rev_id);
	p_bean.JK_OWNING_USER.assign(user_name);
	if(jk8_mjshl == NULL){
		p_bean.JK_RATE.assign("0");//jk8_mjshl//2017/10/23母件损耗率默认值1改为0
	}else if(strlen(jk8_mjshl)==0){
		p_bean.JK_RATE.assign("0");//jk8_mjshl//2017/10/23母件损耗率默认值1改为0
	}else{
		p_bean.JK_RATE.assign(jk8_mjshl);//jk8_mjshl
	}
	p_bean.JK_CREATION_DATE.assign(create_date_str);
	p_bean.JK_SCRAP_DATE.assign(scrap_date.c_str());
	p_bean.JK_IS_SCRAP.assign(is_scrap);

	p_bean.JK_FROM.assign(person_name);
	p_bean.JK_TRANS_TIME.assign(send_date_str);
	p_bean.JK_STATUS.assign("0");
	p_bean.JK_FROM_SYS.assign("TC");
	/******************************************/
	p_bom_vec.push_back(p_bean);
	printf("====>1");
	JK_get_bomline_props(p_bean.JK_BOM_ID,p_bean.JK_BOM_REV,top_line_tag,p_bom_vec,c_bom_vec,sub_bom_vec);
	printf("====>2");
	//释放资源
	if(c_line_tags !=NULL){
		MEM_free(c_line_tags);
		c_line_tags = NULL;
	}
	if(user_name !=NULL)
	{
		MEM_free(user_name);
		user_name = NULL;
	}
	if(jk8_mjshl !=NULL)
	{
		MEM_free(jk8_mjshl);
		jk8_mjshl =NULL;
	}
	if(status_tags !=NULL)
	{
		MEM_free(status_tags);
		status_tags =NULL;
	}
	ITKCALL(ifail = BOM_close_window(bom_window_tag));
}


/*******************************************************
* 
* 物料发送到ERP
*   handler 参数：
*   include_type  需要包含哪些类型		多种类型用/分开，eg：ItemRevision/JK8MaterialRevision/JK8LSMaterialRevision
*	debug         是否需要记录log日志（默认false）   true需要/false不需要 eg：true
*
*******************************************************/
int JK_send_material(EPM_action_message_t msg)
{
	ECHO("\n********************************");
	ECHO("\n********传递物料开始************");
	ECHO("\n********************************\n");
	//参数定义
	int ifail = EPM_go , 
		arg_cnt = 0 , 
		i = 0 ,
		att_cnt = 0;

	tag_t task_tag  = NULLTAG , 
		root_task_tag =NULLTAG , 
		*attachments = NULL;
	
	char * argflag = NULL ,
		*argvalue =NULL ,
		*arg = NULL , 
		arg_value[1024] = "\0",
	statusName[1024]="\0",
	statusMark[1024]="\0",
		type_class[WSO_object_type_size_c+1] ="\0";

	string materialStatusName="";

	logical is_debug = false;
	logical add_mark=false;

	//记录错误信息
	map<string,int> errMap;

	vector<string> type_vec;

	vector<JK_MATERIAL_STRUCT> material_vec;
	vector<JK_RECORD_SUBSTIT_T> material_sub_vec;

	vector<string> bigCodeVec;//vector<string> bigCodeVec,vector<string> qrBigCodeVec
	vector<string> qrBigCodeVec;
	vector<string> uomVec;
	map<string,string> uomMapping;
	//获取需要获取两为编码的分类编码
	getPrefStrings("JK_U8_BIG_CODE_TOW",TC_preference_site,bigCodeVec);
	//获取不传递的分类编码
	getPrefStrings("JK_U8_QR_BIG_CODE",TC_preference_site,qrBigCodeVec);
	//获取单位
	getPrefStrings("JK_UOM_PLM_U8",TC_preference_site,uomVec);
	for(i = 0 ; i < uomVec.size() ; i++){
		string uom_u8 = uomVec[i];
		vector<string> uV;
		Split(uom_u8,"=",uV);
		//printf("%s%d \n",uom_u8.c_str(),uV.size());
		if(uV.size() == 2){
			printf("%s  %s \n",uV[1],uV[0]);
			uomMapping.insert(pair<string,string>(uV[1],uV[0]));
		}
	}
	//获取handler参数的个数
	arg_cnt = TC_number_of_arguments(msg.arguments);
	ECHO("参数个数为：%d\n",arg_cnt);
	if (arg_cnt > 0)
	{
		for (i=0;i<arg_cnt;i++)
		{
			//获取下一个参数（从0开始）
			arg = TC_next_argument(msg.arguments);
			//获取参数的名称和值
			ifail = ITK_ask_argument_named_value((const char*)arg, &argflag, &argvalue);
			//需要检查哪些对象的类型
			if (stricmp(argflag, "include_type") == 0)
			{
				if(argvalue != NULL)
				{
					strcpy(arg_value,argvalue);
					Split(arg_value,"/",type_vec);
				}else{
					string key_id;
					key_id.assign("缺少include_type参数");
					errMap.insert(pair<string,int>(key_id,HANDLER_ARGUMENT_ERROR));
				}
			}
			//是否需要记录log日志
			else if(stricmp(argflag, "debug") == 0)
			{
				if(argvalue != NULL)
				{
					if(strcmp(argvalue,"true")==0)
					{
						is_debug = true;
					}
					else
					{
						is_debug = false;
					}
				}
				else
				{
				
					string key_id;
					key_id.assign("缺少debug参数");
					errMap.insert(pair<string,int>(key_id,HANDLER_ARGUMENT_ERROR));
				}
			}
				//2018.12.26给状态设置什么值（如果有这个参数，传到中间表以这个值为准，如果没有就以属性值为准）
			else if(stricmp(argflag, "addStatus_name") == 0)
			{
				if(argvalue != NULL)
				{
					strcpy(statusName,argvalue);
					materialStatusName=statusName;
				}
				/*else
				{
				
					string key_id;
					key_id.assign("缺少addStatus_name参数");
					errMap.insert(pair<string,int>(key_id,HANDLER_ARGUMENT_ERROR));
				}*/
			}
				//给状态标记设置真实值
			else if(stricmp(argflag, "addStatus_mark") == 0)
			{
				if(argvalue != NULL)
				{
					strcpy(statusMark,argvalue);
					add_mark=true;
				}
				else
				{
				
					string key_id;
					key_id.assign("缺少addStatus_mark参数");
					errMap.insert(pair<string,int>(key_id,HANDLER_ARGUMENT_ERROR));
				}
			}
		}
		MEM_free(argflag);
		MEM_free(argvalue);
	}

	//获取目标对象
	task_tag = msg.task;
	if(task_tag == NULLTAG)
	{
		
		return EPM_nogo;
	}
	EPM_ask_root_task(task_tag, &root_task_tag);
	EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnt, &attachments);
	for(i = 0 ;i < att_cnt;i++){
		tag_t target_tag = attachments[i];
		//获取对象的类型
		ITKCALL( WSOM_ask_object_type(target_tag, type_class));
		ECHO("对象类型%s\n",type_class);
		string type_str ;
		type_str.assign(type_class);
		vector<string>::iterator it;
		it = find(type_vec.begin(),type_vec.end(),type_str);
		if(it == type_vec.end()){
			ECHO("此类型不包含在include_type中\n");
			continue;
		}
		char * item_id_temp = NULL;
		ITKCALL(AOM_ask_value_string(target_tag,"item_id",&item_id_temp));
		if(strcmp(item_id_temp,"E-") == 1 ){
			ECHO("E-开头的物料不需要传递\n");
			if(item_id_temp !=NULL){
				MEM_free(item_id_temp);
				item_id_temp = NULL;
			}
			continue;
		}
		if(item_id_temp !=NULL){
			MEM_free(item_id_temp);
			item_id_temp = NULL;
		}
		//2018.12.4 根据参数给版本添加状态 2018.12.26 不设置属性，只传属性
		//2019.1.9 根据参数给版本添加状态
		if(materialStatusName.length()>0)
		{
			POM_AM__set_application_bypass(true);
			ITKCALL(AOM_load(target_tag));
			ITKCALL(AOM_lock(target_tag));
			ITKCALL(AOM_refresh(target_tag,1));
//			 ITKCALL(ifail=AOM_set_value_string(target_tag,"jk8TecModel1",statusName));
//			 ITKCALL(ifail=AOM_set_value_string(target_tag,"jk8Status",statusName));
		   ITKCALL(ifail=AOM_UIF_set_value(target_tag,"jk8Status",statusName));
			POM_AM__set_application_bypass(false); 
			AOM_save(target_tag);
			AOM_refresh(target_tag,0);
			AOM_unlock(target_tag);
		}
		
		//2018.12.4 根据参数给版本添加状态标记 通过系统handler添加，代码无需添加
		if(add_mark==true)
		{
			tag_t release_stat = NULLTAG;
			ITKCALL(ifail=RELSTAT_create_release_status(statusMark, &release_stat));//TCM Released  jk8Disabled
			POM_AM__set_application_bypass(true);
			ITKCALL(ifail=RELSTAT_add_release_status(release_stat, 1, &target_tag, true));
			POM_AM__set_application_bypass(false);
		}
		
		JK_get_material_props(target_tag , material_vec,bigCodeVec,qrBigCodeVec,uomMapping,materialStatusName);

		JK_get_material_subs(target_tag , material_sub_vec);
	}

	if(attachments!=NULL){
		MEM_free(attachments);
		attachments =NULL;
	}
	vector<JK_MATERIAL_STRUCT> faild_vec ;
	JK_write_material_to_DB(material_vec,faild_vec);
	material_vec.clear();

	JK_write_material_subs_to_DB(material_sub_vec);
	material_sub_vec.clear();

	ECHO("\n********************************");
	ECHO("\n********传递物料结束************");
	ECHO("\n********************************\n");
	return ifail;
}





int JK_send_material1(vector<tag_t>  attachments,string dateType)
{
	ECHO("\n********************************");
	ECHO("\n********传递物料开始JK_send_material1************");
	ECHO("\n********************************\n");
	//参数定义
	int ifail = EPM_go , 
		arg_cnt = 0 , 
		i = 0 ,
		att_cnt = attachments.size();

//	tag_t task_tag  = NULLTAG , 
//		root_task_tag =NULLTAG , 
//		*attachments = NULL;
	
//	char * argflag = NULL ,
//		*argvalue =NULL ,
//		*arg = NULL , 
//		arg_value[1024] = "\0",
		char type_class[WSO_object_type_size_c+1] ="\0";

	logical is_debug = true;

	//记录错误信息
	map<string,int> errMap;

	vector<string> type_vec;
	type_vec.push_back("JK8MaterialRevision");

	vector<JK_MATERIAL_STRUCT> material_vec;

	vector<string> bigCodeVec;//vector<string> bigCodeVec,vector<string> qrBigCodeVec
	vector<string> qrBigCodeVec;
	vector<string> uomVec;
	map<string,string> uomMapping;
	//获取需要获取两为编码的分类编码
	getPrefStrings("JK_U8_BIG_CODE_TOW",TC_preference_site,bigCodeVec);
	//获取不传递的分类编码
	getPrefStrings("JK_U8_QR_BIG_CODE",TC_preference_site,qrBigCodeVec);
	//获取单位
	getPrefStrings("JK_UOM_PLM_U8",TC_preference_site,uomVec);
	for(i = 0 ; i < uomVec.size() ; i++){
		string uom_u8 = uomVec[i];
		vector<string> uV;
		Split(uom_u8,"=",uV);
		//printf("%s%d \n",uom_u8.c_str(),uV.size());
		if(uV.size() == 2){
			printf("%s  %s \n",uV[1],uV[0]);
			uomMapping.insert(pair<string,string>(uV[1],uV[0]));
		}
	}
	//获取handler参数的个数
//	arg_cnt = TC_number_of_arguments(msg.arguments);
//	ECHO("参数个数为：%d\n",arg_cnt);
//	if (arg_cnt > 0)
//	{
//		for (i=0;i<arg_cnt;i++)
//		{
//			//获取下一个参数（从0开始）
//			arg = TC_next_argument(msg.arguments);
//			//获取参数的名称和值
//			ifail = ITK_ask_argument_named_value((const char*)arg, &argflag, &argvalue);
//			//需要检查哪些对象的类型
//			if (stricmp(argflag, "include_type") == 0)
//			{
//				if(argvalue != NULL)
//				{
//					strcpy(arg_value,argvalue);
//					Split(arg_value,"/",type_vec);
//				}else{
//					string key_id;
//					key_id.assign("缺少include_type参数");
//					errMap.insert(pair<string,int>(key_id,HANDLER_ARGUMENT_ERROR));
//				}
//			}
//			//是否需要记录log日志
//			else if(stricmp(argflag, "debug") == 0)
//			{
//				if(argvalue != NULL)
//				{
//					if(strcmp(argvalue,"true")==0)
//					{
//						is_debug = true;
//					}
//					else
//					{
//						is_debug = false;
//					}
//				}
//				else
//				{
//				
//					string key_id;
//					key_id.assign("缺少secondary_type参数");
//					errMap.insert(pair<string,int>(key_id,HANDLER_ARGUMENT_ERROR));
//				}
//			}
//		}
//		MEM_free(argflag);
//		MEM_free(argvalue);
//	}

	//获取目标对象
//	task_tag = msg.task;
//	if(task_tag == NULLTAG)
//	{
//		
//		return EPM_nogo;
//	}
//	EPM_ask_root_task(task_tag, &root_task_tag);
//	EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnt, &attachments);
	for(i = 0 ;i < att_cnt;i++){
		tag_t target_tag = attachments[i];
		//获取对象的类型
		ITKCALL( WSOM_ask_object_type(target_tag, type_class));
		ECHO("对象类型%s\n",type_class);
		string type_str ;
		type_str.assign(type_class);
		vector<string>::iterator it;
		it = find(type_vec.begin(),type_vec.end(),type_str);
		if(it == type_vec.end()){
			ECHO("此类型不包含在include_type中\n");
			continue;
		}
		char * item_id_temp = NULL;
		ITKCALL(AOM_ask_value_string(target_tag,"item_id",&item_id_temp));
		if(strcmp(item_id_temp,"E-") == 1 ){
			ECHO("E-开头的物料不需要传递\n");
			if(item_id_temp !=NULL){
				MEM_free(item_id_temp);
				item_id_temp = NULL;
			}
			continue;
		}
		if(item_id_temp !=NULL){
			MEM_free(item_id_temp);
			item_id_temp = NULL;
		}
		cout<<"material_vec.size()1---------------------"<<material_vec.size()<<endl;
		JK_get_material_props1(target_tag , material_vec,bigCodeVec,qrBigCodeVec,uomMapping,dateType);
			cout<<"material_vec.size()---------------------"<<material_vec.size()<<endl;
	}

//	if(attachments!=NULL){
//		MEM_free(attachments);
//		attachments =NULL;
//	}
	vector<JK_MATERIAL_STRUCT> faild_vec ;
	JK_write_material_to_DB(material_vec,faild_vec);
	material_vec.clear();

	ECHO("\n********************************");
	ECHO("\n********传递物料结束************");
	ECHO("\n********************************\n");
	return ifail;
}


/*******************************************************
* 
* BOM发送到ERP
*   handler 参数：
*   include_type  需要包含哪些类型		多种类型用/分开，eg：ItemRevision/JK8MaterialRevision/JK8LSMaterialRevision
*	debug         是否需要记录log日志（默认false）   true需要/false不需要 eg：true
*
********************************************************/
int JK_send_bom(EPM_action_message_t msg)
{
	ECHO("\n********************************\n");
	ECHO("\n********传递BOM开始************\n");
	ECHO("\n*******************************\n");
	//参数定义
	int ifail = EPM_go , 
		arg_cnt = 0 , 
		i = 0 ,
		att_cnt = 0;

	tag_t task_tag  = NULLTAG , 
		root_task_tag =NULLTAG , 
		*attachments = NULL;
	
	char * argflag = NULL ,
		*argvalue =NULL ,
		*arg = NULL , 
		arg_value[1024] = "\0",
		type_class[WSO_object_type_size_c+1] ="\0";

	logical is_debug = false;

	//记录错误信息
	map<string,int> errMap;

	vector<string> type_vec;

	vector<JK_P_BOM_STRUCT> p_bom_vec;
	vector<JK_C_BOM_STRUCT> c_bom_vec;
	vector<JK_SUB_BOM_STRUCT> sub_bom_vec;

	//获取handler参数的个数
	arg_cnt = TC_number_of_arguments(msg.arguments);
	ECHO("参数个数为：%d\n",arg_cnt);
	if (arg_cnt > 0)
	{
		for (i=0;i<arg_cnt;i++)
		{
			//获取下一个参数（从0开始）
			arg = TC_next_argument(msg.arguments);
			//获取参数的名称和值
			ifail = ITK_ask_argument_named_value((const char*)arg, &argflag, &argvalue);
			//需要检查哪些对象的类型
			if (stricmp(argflag, "include_type") == 0)
			{
				if(argvalue != NULL)
				{
					strcpy(arg_value,argvalue);
					Split(arg_value,"/",type_vec);
				}else{
				
					string key_id;
					key_id.assign("缺少include_type参数");
					errMap.insert(pair<string,int>(key_id,HANDLER_ARGUMENT_ERROR));
				}
			}
			//是否需要记录log日志
			else if(stricmp(argflag, "debug") == 0)
			{
				if(argvalue != NULL)
				{
					if(strcmp(argvalue,"true")==0)
					{
						is_debug = true;
					}
					else
					{
						is_debug = false;
					}
				}
				else
				{
				
					string key_id;
					key_id.assign("缺少secondary_type参数");
					errMap.insert(pair<string,int>(key_id,HANDLER_ARGUMENT_ERROR));
				}
			}
		}
		MEM_free(argflag);
		MEM_free(argvalue);
	}

	//获取目标对象
	task_tag = msg.task;
	if(task_tag == NULLTAG)
	{
		
		return EPM_nogo;
	}
	EPM_ask_root_task(task_tag, &root_task_tag);
	EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnt, &attachments);
	for(i = 0 ;i < att_cnt;i++){

		tag_t target_tag = attachments[i];
		//获取对象的类型 PSBOMViewRevision
		ITKCALL( WSOM_ask_object_type(target_tag, type_class));
		ECHO("对象类型%s\n",type_class);
		string type_str ;
		type_str.assign(type_class);
		vector<string>::iterator it;
		it = find(type_vec.begin(),type_vec.end(),type_str);
		if(it == type_vec.end()){
			ECHO("此类型不包含在include_type中\n");
			continue;
		}
		JK_get_top_bomline_props(target_tag,p_bom_vec,c_bom_vec,sub_bom_vec);
	}

	if(attachments!=NULL)
	{
		MEM_free(attachments);
		attachments =NULL;
	}
	vector<JK_P_BOM_STRUCT> faild_p_vec;
	vector<JK_C_BOM_STRUCT> faild_c_vec;
	vector<JK_SUB_BOM_STRUCT> faild_sub_vec;
	//将bom信息信息写入到中间表
	JK_write_p_bom_to_DB(p_bom_vec,faild_p_vec);
	//将bom结构信息写入到中间表
	JK_write_c_bom_to_DB(c_bom_vec,faild_c_vec);
	JK_write_sub_bom_to_DB(sub_bom_vec,faild_sub_vec);
	printf("faild_p_vec.size = %d \n",faild_p_vec.size());
	printf("faild_c_vec.size = %d \n",faild_c_vec.size());
	printf("faild_sub_vec.size = %d \n",faild_sub_vec.size());
	p_bom_vec.clear();
	c_bom_vec.clear();
	sub_bom_vec.clear();

	ECHO("\n********************************");
	ECHO("\n********传递BOM结束************");
	ECHO("\n********************************\n");
	return 0;

}




