#pragma warning (disable: 4996) 
#pragma warning (disable: 4819) 
#pragma warning (disable: 4995) 
#include <epm/epm_task_template_itk.h>
#include <tc/tc.h>
#include <ics/ics.h>
#include "epm_handler_common.h"
#include "ado.h"
#include <ict/ict_userservice.h>
#include <tccore/custom.h>
#include <epm/epm_toolkit_tc_utils.h>
#include <tccore/aom.h>
#include <tccore/aom_prop.h>
#include <tccore/item.h>
#include <bom/bom.h>
#include "ps/ps.h";
#include "ps/vrule.h"
#include "sstream"
#include <tccore/grm.h>
#include "epm/epm.h"
#include "sa/sa.h"
#include "libxl.h"
#include <map>
#include "epm/signoff.h"
#include <ctime>
#include <vector>
#include <locale>
#include <codecvt>
#include "ae/dataset.h"
#include <iostream>
#include <stdlib.h>
#include <tccore/aom.h>
#include <tc/emh.h>
#include <ict/ict_userservice.h>
#include <tc/tc.h>
#include <tccore/tctype.h>
#include <sa/tcfile.h>
#include <ss/ss_errors.h>
#include <ae/datasettype.h>
// #include "hx_custom.h"
#include <regex>
#include "tc_log.h"
// #include "jk_custom.h"
#include "chint_Handler.h"
#include "tc_util.h"
#include "ocilib.h"
static void get_current_time(char *date_time)
{
    time_t the_time;
    struct tm *time_ptr;
    char *time_format = "%Y-%m-%d %H-%M-%S ";

    the_time = time((time_t *)0);
    time_ptr = localtime (&the_time);
    strftime(date_time, 128, time_format, time_ptr);
}
// 把char *转换为TCHAR *或WCHAR *
TCHAR convertTemp3[256] = {0};
TCHAR convertTemp4[256] = {0};
bool convertBufferSwitch2(false);
TCHAR* Char2Tchar(const char* str, int len)
{
	#ifdef _UNICODE 
	TCHAR* temp = convertBufferSwitch2 ? convertTemp3 : convertTemp4; 
	convertBufferSwitch2 = !convertBufferSwitch2; 
	memset(temp, 0, sizeof(convertTemp3)); 
	MultiByteToWideChar(CP_UTF8, 0, str, len, temp, 256); 
	return temp;
	#else 
	return str;
	#endif
}

int create_dataset(char *type_name, const char *name,  tag_t excelTag)
{
	
	// cout<<"添加命名引用------------------"<<endl;
	tag_t spec_dataset_rev = NULLTAG,
		ref_object = NULLTAG;
	AE_reference_type_t reference_type;
	ITKCALL(AE_ask_dataset_latest_rev(excelTag, &spec_dataset_rev));//获得数据集的最新版本
	char ref_name[WSO_name_size_c + 1] = "excel";
	ITKCALL(AE_ask_dataset_named_ref(spec_dataset_rev, ref_name, &reference_type, &ref_object));//获得数据集命名引用的文件对象

	// cout<<"开始添加----------------"<<endl;
		//pdf的系统路径
		char *temp_dir = getenv("temp");//获得缓存路径
		
		char output_file[SS_MAXPATHLEN] = "";
		strcpy(output_file, temp_dir);
		strcat(output_file, "\\");
//		strcat(output_file, newDatasetName.c_str());
		strcat(output_file, name);

		// cout<<"名称-----------"<<name<<endl;
		tag_t new_file_tag1 = NULLTAG;
		IMF_file_t file_descriptor1;	
		int ifail=0;
		ITKCALL(ifail=IMF_import_file(output_file, name, SS_BINARY, &new_file_tag1, &file_descriptor1));//将缓存路径下生成的文件导入tc，获得tc中的这个文件对象
//		ITKCALL(ifail=IMF_set_original_file_name(new_file_tag1, origin_file_name));//设置文件对象的数据集的原始文件名称
		ITKCALL(ifail=IMF_set_original_file_name(new_file_tag1, name));//设置文件对象的数据集的原始文件名称
		ITKCALL(ifail=IMF_close_file(file_descriptor1));
		ITKCALL(ifail=AOM_save(new_file_tag1));
		ITKCALL(ifail=AOM_unlock(new_file_tag1));

		ITKCALL(ifail=AOM_lock(spec_dataset_rev));
			ITKCALL(ifail=AE_remove_dataset_named_ref_by_tag(spec_dataset_rev, ref_name, ref_object));//删除数据集的命名引用对象
		ITKCALL(ifail=AE_add_dataset_named_ref(spec_dataset_rev, ref_name, AE_PART_OF, new_file_tag1));
		ITKCALL(ifail=AOM_save(spec_dataset_rev));
		ITKCALL(ifail=AOM_unlock(spec_dataset_rev));

    //ITKCALL(AOM_save(excelTag));
	return 0;
}
string GenerateGuid()
{
    GUID guid;
    CoCreateGuid(&guid);
    char cBuffer[64] = {0};
    sprintf_s(cBuffer, sizeof(cBuffer),
    "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
    guid.Data1, guid.Data2,
    guid.Data3, guid.Data4[0],
    guid.Data4[1], guid.Data4[2],
    guid.Data4[3], guid.Data4[4],
    guid.Data4[5], guid.Data4[6],
    guid.Data4[7]);
    return string(cBuffer);
}


int writeToExcel(int page,tag_t excelTag,const char *zt2_Design,const char *zt2_DesignTime,const char *zt2_Proofread,
				 const char *zt2_ProofreadTime,const char *zt2_Normalization,
				 const char *zt2_NormalizationTime,const char *zt2_Review,const char *zt2_ReviewTime,
				 const char *zt2_Approve,const char *zt2_ApproveTime,
				 const char *zt2_Countersign,const char *zt2_CountersignTime)
{
	int ifail=0;
	libxl::Book* book = nullptr;
	book = xlCreateBook();//xls文件用xlCreateBook() 函数打开，xlsx文件是xml结构，所以得用xlCreateXMLBook() 函数来打开。
	book->setKey(L"Halil Kural", L"windows-2723210a07c4e90162b26966a8jcdboe");//如果购买了该库，则设置相应的key，若没有购买，则不用这行
	  // book->setKey(L"TommoT", L"windows-2421220b07c2e10a6eb96768a2p7r6gc");//新版
	int n_refs = 0;
	tag_t* refs = NULL;

	ifail = AE_ask_all_dataset_named_refs(excelTag, "excel", &n_refs, &refs);
	if (ifail != ITK_ok) { /* your error logic here */ }

	char current_date_time_str[128 + 1] = {"\0"};
	get_current_time(current_date_time_str);
	

	string time_now=current_date_time_str;
	string sGuid = GenerateGuid();
	string datasetName=time_now;
	datasetName=datasetName.append(sGuid);
	datasetName=datasetName.append(".xls");
	time_now= getenv("temp");
	time_now=time_now.append("\\").append(datasetName);

	cout<<"文件路径----------"<<time_now<<endl;
	cout<<"-------1----------"<<endl;
	ifail = AE_export_named_ref(excelTag, "excel", time_now.c_str());
	cout<<"--------2---------"<<endl;
	if (ifail != ITK_ok) { /* your error logic here */ }
	//检查是否存在单元格名称为“xxxx”
	wstringstream excel_path;
	
//	excel_path<<"C:\\TEMP\\export_text.xls";
	excel_path<<time_now.c_str();
	cout<<"--------3---------"<<endl;
	libxl::Sheet* sheet=NULL;
	cout<<"---------4--------"<<endl;
	if (book->load(excel_path.str().c_str()))
	{
		 sheet = book->getSheet(0);//获得第1个sheet页
	}
	cout<<"--------5---------"<<endl;
	//写到表格中
	TCHAR array2[100];
	cout<<"---------6--------"<<endl;
	string value = zt2_Countersign;
	vector<string> vecs ;
	Split(value,",",vecs);
	if(page==0)
	{
		MultiByteToWideChar(CP_ACP, 0, zt2_Design, -1, array2, 100);
		sheet->writeStr(21, 8,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_DesignTime, -1, array2, 100);
		sheet->writeStr(22, 8,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_Proofread, -1, array2, 100);
		sheet->writeStr(21, 9,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_ProofreadTime, -1, array2, 100);
		sheet->writeStr(22, 9,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_Normalization, -1, array2, 100);
		sheet->writeStr(21, 10,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_NormalizationTime, -1, array2, 100);
		sheet->writeStr(22, 10,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_Review, -1, array2, 100);
		sheet->writeStr(21, 12,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_ReviewTime, -1, array2, 100);
		sheet->writeStr(22, 12,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_Approve, -1, array2, 100);
		sheet->writeStr(21, 14,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_ApproveTime, -1, array2, 100);
		sheet->writeStr(22, 14,array2 );
		for(int j=0;j<vecs.size();j++)
		{
			switch (j)
			{
			case 0:
			case 1:
				MultiByteToWideChar(CP_ACP, 0, vecs[j].c_str(), -1, array2, 100);
				sheet->writeStr(21, j+2,array2 );
				MultiByteToWideChar(CP_ACP, 0, zt2_CountersignTime, -1, array2, 100);
				sheet->writeStr(21, j+2,array2 );
				break;
			case 2:
				MultiByteToWideChar(CP_ACP, 0, vecs[j].c_str(), -1, array2, 100);
				sheet->writeStr(21, 6,array2 );
				MultiByteToWideChar(CP_ACP, 0, zt2_CountersignTime, -1, array2, 100);
				sheet->writeStr(21, 6,array2 );
				break;
			default:
				break;
			}
		}
	}
	cout<<"-------7----------"<<endl;
	for (int i=0;i<page;i++)
	{
		MultiByteToWideChar(CP_ACP, 0, zt2_Design, -1, array2, 100);
		sheet->writeStr(i*23+21, 8,array2 );	
		MultiByteToWideChar(CP_ACP, 0, zt2_DesignTime, -1, array2, 100);
		sheet->writeStr(i*23+22, 8,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_Proofread, -1, array2, 100);
		sheet->writeStr(i*23+21, 9,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_ProofreadTime, -1, array2, 100);
		sheet->writeStr(i*23+22, 9,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_Normalization, -1, array2, 100);
		sheet->writeStr(i*23+21, 10,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_NormalizationTime, -1, array2, 100);
		sheet->writeStr(i*23+22, 10,array2 );

		MultiByteToWideChar(CP_ACP, 0, zt2_Review, -1, array2, 100);
		sheet->writeStr(i*23+21, 12,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_ReviewTime, -1, array2, 100);
		sheet->writeStr(i*23+22, 12,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_Approve, -1, array2, 100);
		sheet->writeStr(i*23+21, 14,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_ApproveTime, -1, array2, 100);
		sheet->writeStr(i*23+22, 14,array2 );			
		for(int j=0;j<vecs.size();j++)
		{
			switch (j)
			{
			case 0:
			case 1:
				MultiByteToWideChar(CP_ACP, 0, vecs[j].c_str(), -1, array2, 100);
				sheet->writeStr(i*23+21, j+2,array2 );
				MultiByteToWideChar(CP_ACP, 0, zt2_CountersignTime, -1, array2, 100);
				sheet->writeStr(i*23+22, j+2,array2 );
				break;
			case 2:
				MultiByteToWideChar(CP_ACP, 0, vecs[j].c_str(), -1, array2, 100);
				sheet->writeStr(i*23+21, 6,array2 );
				MultiByteToWideChar(CP_ACP, 0, zt2_CountersignTime, -1, array2, 100);
				sheet->writeStr(i*23+22, 6,array2 );
				break;
			default:
				break;
			}
		}
	}
	cout<<"---------8--------"<<endl;
	if (book->save(excel_path.str().c_str()))//保存到example.xls
	{
		//.....
	}
	else
	{
		std::cout << book->errorMessage() << std::endl;
	}
	book->release();//释放对象！！！！
	//创建数据集，挂到版本的规范关系下
	cout<<"---------9--------"<<endl;
	create_dataset("MSExcel",datasetName.c_str(),excelTag);//数据集类型(object_type)，数据集名称，版本
	return 0;
}


//生产信息传递通知单
int writeToExcel2(int page,tag_t excelTag,const char *zt2_Design,const char *zt2_DesignTime,const char *zt2_Proofread,
				 const char *zt2_ProofreadTime,const char *zt2_Normalization,
				 const char *zt2_NormalizationTime,const char *zt2_Review,const char *zt2_ReviewTime,
				 const char *zt2_Approve,const char *zt2_ApproveTime,
				 const char *zt2_Technology,char *zt2_TechnologyTime,
				 const char *zt2_Countersign,const char *zt2_CountersignTime)
{
	cout<<"writeToExcel2 start"<<endl;
	int ifail=0;
	libxl::Book* book = nullptr;
	book = xlCreateBook();//xls文件用xlCreateBook() 函数打开，xlsx文件是xml结构，所以得用xlCreateXMLBook() 函数来打开。
	book->setKey(L"Halil Kural", L"windows-2723210a07c4e90162b26966a8jcdboe");//如果购买了该库，则设置相应的key，若没有购买，则不用这行
	  // book->setKey(L"TommoT", L"windows-2421220b07c2e10a6eb96768a2p7r6gc");//新版
	int n_refs = 0;
	tag_t* refs = NULL;

	ifail = AE_ask_all_dataset_named_refs(excelTag, "excel", &n_refs, &refs);
	if (ifail != ITK_ok) { /* your error logic here */ }

	char current_date_time_str[128 + 1] = {"\0"};
	get_current_time(current_date_time_str);
	

	string time_now=current_date_time_str;
	string sGuid = GenerateGuid();
	string datasetName=time_now;
	datasetName=datasetName.append(sGuid);
	datasetName=datasetName.append(".xls");
	time_now= getenv("temp");
	time_now=time_now.append("\\").append(datasetName);

	cout<<"文件路径----------"<<time_now<<endl;
	cout<<"-------1----------"<<endl;
	ifail = AE_export_named_ref(excelTag, "excel", time_now.c_str());
	cout<<"--------2---------"<<endl;
	if (ifail != ITK_ok) { /* your error logic here */ }
	//检查是否存在单元格名称为“xxxx”
	wstringstream excel_path;
	
//	excel_path<<"C:\\TEMP\\export_text.xls";
	excel_path<<time_now.c_str();
	cout<<"--------3---------"<<endl;
	libxl::Sheet* sheet=NULL;
	cout<<"---------4--------"<<endl;
	if (book->load(excel_path.str().c_str()))
	{
		 sheet = book->getSheet(0);//获得第1个sheet页
	}
	cout<<"--------5---------"<<endl;
	//写到表格中
	TCHAR array2[100];
	cout<<"---------6--------"<<endl;
	if(page==0)
	{
		try{
		//编制
		MultiByteToWideChar(CP_ACP, 0, zt2_Design, -1, array2, 100);
		sheet->writeStr(23, 9,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_DesignTime, -1, array2, 100);
		sheet->writeStr(24, 9,array2 );
		//校对
		MultiByteToWideChar(CP_ACP, 0, zt2_Proofread, -1, array2, 100);
		sheet->writeStr(23, 10,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_ProofreadTime, -1, array2, 100);
		sheet->writeStr(24, 10,array2 );
		//工艺
		MultiByteToWideChar(CP_ACP, 0, zt2_Technology, -1, array2, 100);
		sheet->writeStr(23, 12,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_TechnologyTime, -1, array2, 100);
		sheet->writeStr(24, 12,array2 );
		//审定
		MultiByteToWideChar(CP_ACP, 0, zt2_Review, -1, array2, 100);
		sheet->writeStr(23, 14,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_ReviewTime, -1, array2, 100);
		sheet->writeStr(24, 14,array2 );
		//批准
		MultiByteToWideChar(CP_ACP, 0, zt2_Approve, -1, array2, 100);
		sheet->writeStr(23, 15, array2);
		MultiByteToWideChar(CP_ACP, 0, zt2_ApproveTime, -1, array2, 100);
		sheet->writeStr(24, 15, array2);
		string value = zt2_Countersign;
		vector<string> vecs ;
		Split(value,",",vecs);
		for(int j=0;j<vecs.size();j++)
		{
			if(j<3)
			{
				MultiByteToWideChar(CP_ACP, 0, vecs[j].c_str(), -1, array2, 100);
				sheet->writeStr(22+j%3, 2,array2 );
				MultiByteToWideChar(CP_ACP, 0, zt2_CountersignTime, -1, array2, 100);
				sheet->writeStr(22+j%3, 3,array2 );
			}else if(3<=j && j<=5)
			{
				MultiByteToWideChar(CP_ACP, 0, vecs[j].c_str(), -1, array2, 100);
				sheet->writeStr(22+j%3, 6,array2 );
				MultiByteToWideChar(CP_ACP, 0, zt2_CountersignTime, -1, array2, 100);
				sheet->writeStr(22+j%3, 8,array2 );			
			}
		}




		}catch(exception e)
		{
			cout<<"-------异常----------"<<e.what()<<endl;
		}
	}
	cout<<"-------7----------"<<endl;
	for (int i=0;i<page;i++)
	{
		cout<<"-------7-1----------"<<endl;
		MultiByteToWideChar(CP_ACP, 0, zt2_Design, -1, array2, 100);
		cout<<"-------7-2----------"<<endl;
		try{
		sheet->writeStr(i*24+23, 9,array2 );	
		MultiByteToWideChar(CP_ACP, 0, zt2_DesignTime, -1, array2, 100);
		sheet->writeStr(i*24+24, 9,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_Proofread, -1, array2, 100);
		sheet->writeStr(i*24+23, 10,array2 );
		MultiByteToWideChar(CP_ACP, 0, zt2_ProofreadTime, -1, array2, 100);
		sheet->writeStr(i*24+24, 10,array2 ) ;
		MultiByteToWideChar(CP_ACP, 0, zt2_Technology, -1, array2, 100);
		sheet->writeStr(i*24+23, 12,array2 ) ;
		MultiByteToWideChar(CP_ACP, 0, zt2_TechnologyTime, -1, array2, 100);
		sheet->writeStr(i*24+24, 12,array2 ) ;
		MultiByteToWideChar(CP_ACP, 0, zt2_Review, -1, array2, 100);
		sheet->writeStr(i*24+23, 14,array2 ) ;
		MultiByteToWideChar(CP_ACP, 0, zt2_ReviewTime, -1, array2, 100);
		sheet->writeStr(i*24+24, 14,array2 ) ;
		//批准
		MultiByteToWideChar(CP_ACP, 0, zt2_Approve, -1, array2, 100);
		sheet->writeStr(i * 24 + 23, 15, array2);
		MultiByteToWideChar(CP_ACP, 0, zt2_ApproveTime, -1, array2, 100);
		sheet->writeStr(i * 24 + 24, 15, array2);




		string value = zt2_Countersign;
		vector<string> vecs ;
		Split(value,",",vecs);
		for(int j=0;j<vecs.size();j++)
		{
			if(j<3)
			{
				MultiByteToWideChar(CP_ACP, 0, vecs[j].c_str(), -1, array2, 100);
				sheet->writeStr(i*24+22+j%3, 2,array2 );
				MultiByteToWideChar(CP_ACP, 0, zt2_CountersignTime, -1, array2, 100);
				sheet->writeStr(i*24+22+j%3, 3,array2 );
			}else if(3<=j && j<=5)
			{
				MultiByteToWideChar(CP_ACP, 0, vecs[j].c_str(), -1, array2, 100);
				sheet->writeStr(i*24+22+j%3, 6,array2 );
				MultiByteToWideChar(CP_ACP, 0, zt2_CountersignTime, -1, array2, 100);
				sheet->writeStr(i*24+22+j%3, 8,array2 );			
			}
		}


		}catch(exception e)
		{
			cout<<"-------异常----------"<<e.what()<<endl;
		}
			
	}
	cout<<"---------8--------"<<endl;
	if (book->save(excel_path.str().c_str()))//保存到example.xls
	{
		//.....
	}
	else
	{
		std::cout << book->errorMessage() << std::endl;
	}
	book->release();//释放对象！！！！
	//创建数据集，挂到版本的规范关系下
	cout<<"---------9--------"<<endl;
	create_dataset("MSExcel",datasetName.c_str(),excelTag);//数据集类型(object_type)，数据集名称，版本
	cout<<"writeToExcel2 end"<<endl;
	return 0;
}

int chintSignChange(EPM_action_message_t msg)
{

	cout<<"chintSignChange start"<<endl;
	//20200113
	POM_AM__set_application_bypass(true);

	EPM_decision_t decision = EPM_go;
	int ifail = ITK_ok, arg_cnt = 0, i = 0, att_cnt = 0;
	tag_t task_tag = NULLTAG, rootTask_tag = NULLTAG, *attachments = NULL;
	// char * ref_type=NULL;
	// int actualNum=0;
	//获取当前触发的任务
	task_tag = msg.task;
	//获取根流程节点
	ifail = EPM_ask_root_task(task_tag, &rootTask_tag);
	//获取目标引用对象
	ifail = EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments);
	int reference_count=0;tag_t * reference_attachment=NULLTAG;
	ifail = EPM_ask_attachments(rootTask_tag, EPM_reference_attachment, &reference_count, &reference_attachment);
	map<tag_t,string>	rev_map;
	char *zt2_Design=NULL;
	char *zt2_DesignTime=NULL;
	char *zt2_Proofread=NULL;
	char *zt2_ProofreadTime=NULL;
	char *zt2_Normalization=NULL;
	char *zt2_NormalizationTime=NULL;
	char *zt2_Review=NULL;
	char *zt2_ReviewTime=NULL;
	char *zt2_Approve=NULL;
	char *zt2_ApproveTime =NULL;
	char *zt2_Technology=NULL;
	char *zt2_TechnologyTime =NULL;
	char *zt2_Countersign = NULL;
	char *zt2_CountersignTime = NULL;

	int eCount=0;
	tag_t *eTag=NULLTAG;
//	vector.clear();//清空所有元素
	//循环目标对象
	for (i = 0; i < att_cnt; i++)
	{
		tag_t  targetTag=attachments[i];
		//如果是版本类型的就查找上层
		char * object_type=NULL;
		ITKCALL(ifail=AOM_ask_value_string(targetTag,"object_type",&object_type));
		cout<<i<<"--object_type:"<<object_type<<endl;
		if(strstr(object_type,"ZT2_Change")!=NULL)
		{
			//获取对象的上签名属性

			AOM_ask_value_string(targetTag,"zt2_Design",&zt2_Design);
			AOM_ask_value_string(targetTag,"zt2_DesignTime",&zt2_DesignTime);
			AOM_ask_value_string(targetTag,"zt2_Proofread",&zt2_Proofread);
			AOM_ask_value_string(targetTag,"zt2_ProofreadTime",&zt2_ProofreadTime);
			AOM_ask_value_string(targetTag,"zt2_Normalization",&zt2_Normalization);
			AOM_ask_value_string(targetTag,"zt2_NormalizationTime",&zt2_NormalizationTime);
			AOM_ask_value_string(targetTag,"zt2_Review",&zt2_Review);
			AOM_ask_value_string(targetTag,"zt2_ReviewTime",&zt2_ReviewTime);
			AOM_ask_value_string(targetTag,"zt2_Approve",&zt2_Approve);
			AOM_ask_value_string(targetTag,"zt2_ApproveTime",&zt2_ApproveTime);
			AOM_ask_value_string(targetTag,"zt2_Countersign",&zt2_Countersign);
			AOM_ask_value_string(targetTag,"zt2_CountersignTime",&zt2_CountersignTime);
			//获取对象的数据集

			AOM_ask_value_tags(targetTag,"IMAN_reference",&eCount,&eTag);
			for(int j=0;j<eCount;j++)
			{
				char *eType=NULL;
				AOM_ask_value_string(eTag[j],"object_type",&eType);

				if(strcmp(eType,"MSExcel")==0)
				{
					int num=0;
					char**values=NULL;
					AOM_ask_value_strings(targetTag,"zt2_ChangeDrawingNo",&num,&values);
					int modules=num%5;
					int delivery=num/5;
					int page=0;
					if(modules>0)
					{
						page=delivery+1;
					}else
					{
						page=delivery;
					}
					writeToExcel(page,eTag[j],zt2_Design,zt2_DesignTime,zt2_Proofread,zt2_ProofreadTime,zt2_Normalization,
						zt2_NormalizationTime,zt2_Review,zt2_ReviewTime,zt2_Approve,zt2_ApproveTime,zt2_Countersign,zt2_CountersignTime);
					if(values!=NULL)
					{
						for(int t=0;t<num;t++)
						{
							if(values[t]!=NULL)
							{
								MEM_free(values[t]);
								values[t]=NULL;
							}
						}
						values=NULL;

					}
					
				}
				DOFREE(eType);
			}
		}else if(strstr(object_type,"ZT2_SCXXCDTZD")!=NULL)
		{
			//获取对象的上签名属性

			AOM_ask_value_string(targetTag,"zt2_Design",&zt2_Design);
			AOM_ask_value_string(targetTag,"zt2_DesignTime",&zt2_DesignTime);
			AOM_ask_value_string(targetTag,"zt2_Proofread",&zt2_Proofread);
			AOM_ask_value_string(targetTag,"zt2_ProofreadTime",&zt2_ProofreadTime);
			AOM_ask_value_string(targetTag,"zt2_Normalization",&zt2_Normalization);
			AOM_ask_value_string(targetTag,"zt2_NormalizationTime",&zt2_NormalizationTime);
			AOM_ask_value_string(targetTag,"zt2_Review",&zt2_Review);
			AOM_ask_value_string(targetTag,"zt2_ReviewTime",&zt2_ReviewTime);
			AOM_ask_value_string(targetTag,"zt2_Approve",&zt2_Approve);
			AOM_ask_value_string(targetTag,"zt2_ApproveTime",&zt2_ApproveTime);
			AOM_ask_value_string(targetTag,"zt2_Technology",&zt2_Technology);
			AOM_ask_value_string(targetTag,"zt2_TechnologyTime",&zt2_TechnologyTime);
			AOM_ask_value_string(targetTag,"zt2_Countersign",&zt2_Countersign);
			AOM_ask_value_string(targetTag,"zt2_CountersignTime",&zt2_CountersignTime);
			//获取对象的数据集

			AOM_ask_value_tags(targetTag,"IMAN_reference",&eCount,&eTag);
			tag_t rev = NULLTAG;
			ITEM_ask_latest_rev(targetTag,&rev);
			char *object_desc = NULL;
			AOM_ask_value_string(rev,"object_desc",&object_desc);
			string desc = object_desc;
			int pages = 0;
			if(!desc.empty())
			{
				pages = atol(desc.c_str());
			}
			cout<<"ZT2_SCXXCDTZD--eCount:"<<eCount<<endl;
			for(int j=0;j<eCount;j++)
			{
				char *eType=NULL;
				AOM_ask_value_string(eTag[j],"object_type",&eType);
				cout<<j<<"--eType:"<<eType<<endl;
				if(strcmp(eType,"MSExcel")==0)
				{
					int num=0;
					char**values=NULL;
					/*
					AOM_ask_value_strings(targetTag,"zt2_ChangeDrawingNo",&num,&values);
					int modules=num%5;
					int delivery=num/5;
					int page=0;
					if(modules>0)
					{
						page=delivery+1;
					}else
					{
						page=delivery;
					}
					*/
					
					writeToExcel2(pages,eTag[j],zt2_Design,zt2_DesignTime,zt2_Proofread,zt2_ProofreadTime,
						zt2_Normalization,zt2_NormalizationTime,zt2_Review,zt2_ReviewTime,
						zt2_Approve,zt2_ApproveTime,zt2_Technology,zt2_TechnologyTime,zt2_Countersign,zt2_CountersignTime);
					if(values!=NULL)
					{
						for(int t=0;t<num;t++)
						{
							if(values[t]!=NULL)
							{
								MEM_free(values[t]);
								values[t]=NULL;
							}
						}
						values=NULL;

					}
					
				}
				DOFREE(eType);
			}
		
		
		}

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

	DOFREE(eTag);
	DOFREE(zt2_Design);
	DOFREE(zt2_DesignTime);
	DOFREE(zt2_Proofread);
	DOFREE(zt2_ProofreadTime);
	DOFREE(zt2_Normalization);
	DOFREE(zt2_NormalizationTime);
	DOFREE(zt2_Review);
	DOFREE(zt2_ReviewTime);
	DOFREE(zt2_Approve);
	DOFREE(zt2_ApproveTime);
	DOFREE(zt2_Technology);
	DOFREE(zt2_TechnologyTime);
	cout<<"chintSignChange end"<<endl;
	// CloseLog_jk();
	POM_AM__set_application_bypass(false);
	return 0;
}