#pragma warning (disable: 4996) 
#pragma warning (disable: 4819) 
#pragma warning (disable: 4995) 

#include <tc/tc.h>
#include "epm_handler_common.h"

#include <ict/ict_userservice.h>
#include <tccore/custom.h>
#include <epm/epm_toolkit_tc_utils.h>
#include <tccore/aom.h>
#include <tccore/aom_prop.h>
#include <tccore/item.h>
#include <tccore/item_errors.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 "common_itk_util.h"
#include <fclasses/tc_date.h>
#include "string_utils.h"
#include <tc/folder.h>
extern "C" int POM_AM__set_application_bypass(logical bypass);


int AddTime(EPM_action_message_t msg)
{
	cout<<"设置触发handler的当前时间"<<endl;
	time_t now;
	struct tm *p;	
	time(&now);//获取当前时间
	p = localtime(&now);//本地化时间，可以细分为年月日时分秒等
	int  year=1900+p->tm_year;
	int month=p->tm_mon;
	int day=p->tm_mday;
	int hour=p->tm_hour;
	int min=p->tm_min;
	int second=p->tm_sec;
	date_t timesss;
	char date_str_act[30]="\0";
	sprintf(date_str_act,"%d-%d-%d %d:%d",year,month +1,day,hour,min);		
//	string timesss=date_str_act;
//	cout<<"timesss--------------"<<timesss<<endl;
	tag_t task_tag = NULLTAG, rootTask_tag = NULLTAG, *attachments = NULL;
	int ifail=0;int att_cnt=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);
	char *object_TYPE_1=NULL;
	for (int i = 0; i < att_cnt; i++) {
	//下载数据集
		tag_t rev_tag=attachments[i];
		AOM_ask_value_string(rev_tag,"object_type",&object_TYPE_1);
		cout<<object_TYPE_1<<endl;
		date_t creation_date;
//		AOM_ask_value_date(rev_tag,"creation_date", &creation_date);//fnd0StartDate
//		DATE_date_to_string(creation_date,arg3value,&d_value);
//		//ITKCALL(AOM_UIF_ask_value( cur_perform_task, "fnd0StartDate", &d_value));
//		ECHO("d_value : %s",d_value);
		if(strcmp(object_TYPE_1,"B2sypfRevision")==0||strcmp(object_TYPE_1,"B2sytsRevision")==0||strcmp(object_TYPE_1,"LP2_Elc_CompRevision")==0)
		{
			POM_AM__set_application_bypass(true);
			ITKCALL(AOM_load(rev_tag));
			ITKCALL(AOM_lock(rev_tag));
			ITKCALL(AOM_refresh(rev_tag,1));

			ITK_string_to_date(date_str_act, &timesss);
			AOM_set_value_date(rev_tag,"b2llsj",timesss);//实际开始日期


			POM_AM__set_application_bypass(false); 
			AOM_save(rev_tag);
			AOM_refresh(rev_tag,0);
			AOM_unlock(rev_tag);
			
		}
	
	
	}
	if(object_TYPE_1!=NULL)
	{
		MEM_free(object_TYPE_1);
		object_TYPE_1=NULL;
	}
	if(attachments!=NULL)
	{
		MEM_free(attachments);
		attachments=NULL;
	}

	

	return 0;
}



		