/*===================================================================================================
                    Copyright(c) 2011 Siemens PLM Software Corp. All rights reserved.
                             Unpublished - All rights reserved
====================================================================================================
File description:
    
    Filename : epm_autosign_hander.cpp

    This file describes action handler function : PLA8-signoff

	将流程签审信息写入表单

====================================================================================================
Date               Name                  Description of Change
19-Jan-2013       Ray Li        creation

$HISTORY$
==================================================================================================*/
#pragma warning (disable: 4996) 
#pragma warning (disable: 4819) 
/**
* @headerfile			tcua 头文件
*/

#include <epm/epm.h>
#include <epm/epm_toolkit_tc_utils.h>
#include <ict/ict_userservice.h>
#include <tccore/item.h>
#include <ae/ae.h>
#include <tc/folder.h>
#include <tccore/aom.h>
#include <sa/sa.h>
#include <tccore/aom_prop.h>
#include <property/prop_errors.h>
#include <tccore/workspaceobject.h>
#include <tc/preferences.h>
#include <tccore/imantype.h>
#include <tccore//grm.h>
#include <tccore/grmtype.h>
#include <sa/am.h>
#include <cfm/cfm.h>
#include <bom/bom.h>
#include <tccore/uom.h>
#include <ps/ps.h>
#include <epm/signoff.h>
#include <fclasses/tc_date.h>

/**
* @headerfile			standard c & cpp header files
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
//#include <time.h>
//#include <math.h>
#include <string>
#include <vector>
#include <map>
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;

/**
* @headerfile			user's header files
*/
#include "epm_handler_common.h"
#include "error_handling.h"
#include "common_itk_util.h"
//#include "string_helper.h"

//流程节点信息
struct FLOWNODEINFOS
{
	char taskname[128];
	char username[128];
	char timeinfo[128];
	char group[128];
}flownode_s[64];

//参数人员信息
struct USERINFOS
{
	char taskname[128];
	char propertyname[128];
	char group[128];
}userinfo_s[64];

//参数日期信息
struct TIMEINFOS
{
	char taskname[128];
	char propertyname[128];
	char group[128];
}timeinfo_s[64];

////会签信息
//struct SIGNCOUNTERINFO
//{
//	char taskname[128];
//	char group[128];
//	char propertyname[128];
//}counter_s[64];

int nodecount = 0;
int userinfoscount = 0;
int timeinfoscount = 0;

 
//int counterinfocount = 0;
#define DOFREE(obj)								\
{												\
	if(obj)										\
	{											\
		MEM_free(obj);							\
		obj = NULL;								\
	}											\
}
//struct SIGN_INFO_STRUCT
//{
//	string userid;
//	string username;
//	string taskname;
//	string signdate;
//};
//struct SIGN_PROPS_STRUCT
//{
//	string taskname;
//	string propname;
//};
//struct SIGN_TIME_STRUCT
//{
//	string taskname;
//	string propname;
//};
extern "C" int POM_AM__set_application_bypass(logical bypass);


//void ECHO(char *format, ...)
//{
//    //if( !YFJC_OPT_DEBUG )
//    //    return; 
//
//    char msg[2048];
//    va_list args;
//
//    va_start( args, format );
//    vsprintf( msg, format, args );
//    va_end( args );
//
//    printf( msg );
//    TC_write_syslog( msg );
//}
//分割字符串


int ORIGIN_ask_sign_info(tag_t task_node, char *output_str,char *task_name,char *arg3value)
{
	int ifail = ITK_ok;
	tag_t cur_perform_task = NULLTAG,tempTask = NULLTAG;
	char cur_task_name[WSO_name_size_c+1]="",buf[128] = "";
	//编制判断变量
	int s = 0;
	EPM_decision_t decision = EPM_nogo;
	char* userName;
	char *timeinfo1 = "",person_name[SA_name_size_c+1]="",*prop_name = "last_mod_date";
	tag_t aUserTag = NULLTAG,responsibleParty = NULLTAG;
	date_t decision_date;
	//其他节点相关
	int perform_count = 0;
	int *attach_type;
	tag_t *perform_attaches = NULLTAG;
	tag_t memberTag = NULLTAG;
	SIGNOFF_TYPE_t memberType;
	CR_signoff_decision_t signoff_decision;
	char comments[CR_comment_size_c+1],*timeinfo="",*group_full_name = NULL;
	tag_t user_tag=NULLTAG, group_tag = NULLTAG;
	//循环判断变量
	int i=0;

	ITKCALL( EPM_ask_name( task_node, cur_task_name ) ); 
	ECHO("cur_task_name = %s\n",cur_task_name);
	if ( stricmp( cur_task_name, "perform-signoffs" ) == 0 )
	{
		cur_perform_task = task_node;
		ITKCALL( EPM_ask_parent_task( cur_perform_task, &tempTask ) );
		ITKCALL( EPM_ask_name( tempTask, cur_task_name ) );
	}
	else if( strcmp( cur_task_name, "编制" ) == 0 )
	{
		cur_perform_task = task_node;
	}
	else
	{
		ITKCALL( EPM_ask_sub_task(task_node, "perform-signoffs", &cur_perform_task) );
		if ( cur_perform_task != NULLTAG )
		{
			ITKCALL( EPM_ask_name( task_node, cur_task_name ) );

			ECHO( "--------->		cur_task_name = %s\n" , cur_task_name );

		}
	}
	if(cur_perform_task != NULLTAG )
	{
		if( strcmp( cur_task_name, "编制" ) == 0 )
		{
			//ECHO("task_name=%s",task_name);
			//s = EPM_ask_responsible_party(cur_perform_task,&responsibleParty);
			//if(responsibleParty != NULLTAG)
			//{
			//	decision = EPM_go;
			//}
			//s = POM_get_user(&userName,&aUserTag);
			//ITKCALL(SA_ask_user_person_name(aUserTag, person_name));
			//strcat(output_str, cur_task_name);
			//strcat(output_str, "=");
			//strcat(output_str, person_name);
			//strcat(output_str, "|");
			//strcat(output_str, cur_task_name);
			//strcat(output_str, "日期=");
			//ITKCALL(AOM_ask_value_date(cur_perform_task,prop_name,&decision_date));
			//ITKCALL(DATE_date_to_string(decision_date,arg3value,&timeinfo1));
			////ECHO("timeinfo : %s",timeinfo1);
			////ITK_date_to_string (decision_date, &timeinfo1);
			//strcat( output_str, timeinfo1 );
			//strcat(output_str,"|");
			//ECHO("timeinfo : %s",timeinfo1);
			//strcpy(flownode_s[nodecount].taskname,cur_task_name);
			//strcpy(flownode_s[nodecount].username,person_name);
			//strcpy(flownode_s[nodecount].timeinfo,timeinfo1);
			//nodecount = nodecount + 1;
			//MEM_free(userName);
		}
		else
		{
			//发起人即所有者
			tag_t owner = NULLTAG;
			date_t date;
			logical is_valid;
			char *d_value = NULL;
			CALL(AOM_ask_owner( cur_perform_task, &owner));
			if( owner != NULLTAG )
				CALL(SA_ask_user_person_name(owner, person_name));
			ITKCALL(AOM_ask_value_date(cur_perform_task,"creation_date", &date));//fnd0StartDate
			DATE_date_to_string(date,arg3value,&d_value);
			//ITKCALL(AOM_UIF_ask_value( cur_perform_task, "fnd0StartDate", &d_value));
			ECHO("d_value : %s",d_value);
			strcat(output_str, "申请人");
			strcat(output_str, "=");
			strcat(output_str, person_name);
			strcat(output_str, "|");
			strcat(output_str, "申请人日期=");
			//CALL(DATE_date_to_string(date,arg3value,&timeinfo));
			//ITKCALL(DATE_string_to_date_t(d_value, &is_valid,&date)); 
			//CALL(DATE_date_to_string(date,arg3value,&timeinfo));
			//ECHO("timeinfo : %s",timeinfo);
			//vector<string> ans;
			//if( d_value != NULL )
			//{
			//	Split(d_value, ' ', ans);
			//	if(ans.size() > 1)
			//		strcat(output_str,ans[0].c_str());
			//}
			strcat(output_str,d_value);
			//DOFREE(timeinfo);
			strcat(output_str, "|");
					strcpy(flownode_s[nodecount].taskname,"申请人");
					strcpy(flownode_s[nodecount].username,person_name);
			//if(ans.size() > 1)
					strcpy(flownode_s[nodecount].timeinfo,d_value);
					nodecount = nodecount + 1;
			ECHO("output_str=%s",output_str);
			ITKCALL(EPM_ask_all_attachments(cur_perform_task,&perform_count,&perform_attaches,&attach_type));
			ECHO("EPM_signoff_attachment Counts = %d", perform_count);
			
			for(i=0;i<perform_count;i++)
			{
				ITKCALL(EPM_ask_signoff_member(perform_attaches[i], &memberTag, &memberType));
				ITKCALL(CR_ask_signoff_decision(perform_attaches[i], &signoff_decision, comments, &decision_date));
				if(memberType == SIGNOFF_GROUPMEMBER)
				{
					ECHO("cur_task_name = %s",cur_task_name);
					CALL(SA_ask_groupmember_user(memberTag, &user_tag));
					CALL(SA_ask_user_person_name(user_tag, person_name));
					strcat(output_str, cur_task_name);
					strcat(output_str, "=");
					strcat(output_str, person_name);
					strcat(output_str, "|");
					strcat(output_str, cur_task_name);
					strcat(output_str, "日期=");
					char date_buf[128]="";
					CALL(DATE_date_to_string(decision_date,arg3value,&timeinfo));
					//ITKCALL(ITK_date_to_string(decision_date, &timeinfo));
					//sprintf( date_buf, "%4d-%02d-%02d", decision_date.year, decision_date.month+1, decision_date.day );
					ECHO("timeinfo : %s",timeinfo);
					strcat(output_str,timeinfo);
					strcat(output_str, "|");
					strcpy(flownode_s[nodecount].taskname,cur_task_name);
					strcpy(flownode_s[nodecount].username,person_name);
					strcpy(flownode_s[nodecount].timeinfo,timeinfo);
					nodecount = nodecount + 1;
				}
			}
		}
	}
	ECHO("output_str=%s",output_str);
	return ifail;
}
//
void SplitUserInfo(char *userinfo)
{
	char* token = NULL, *ptr = NULL, temp[512] = "";

    token = strtok( userinfo, ";");
    while( token != NULL )
    {
        /* While there are tokens in "string" */
		strcpy(temp,token);
        ECHO( "token=%s\n", token );
		ptr = strstr(temp, "=");
		if (ptr != NULL)
		{	
			strcpy(userinfo_s[userinfoscount].propertyname, ptr +1);
			strcpy(ptr,"\0");
			strcpy(userinfo_s[userinfoscount].taskname ,temp);
			ECHO("\nuserinfo_s[userinfoscount].taskname=%s,userinfo_s[userinfoscount].propertyname=%s\n",
				userinfo_s[userinfoscount].taskname,userinfo_s[userinfoscount].propertyname);
		}
		userinfoscount ++;
        /* Get next token: */
        token = strtok( NULL, ";");
    }
}
void SplitTimeInfo(char *userinfo)
{
	char* token = NULL, *ptr = NULL, temp[512] = "";

    token = strtok( userinfo, ";");
    while( token != NULL )
    {
        /* While there are tokens in "string" */
		strcpy(temp,token);
        ECHO( "token=%s\n", token );
		ptr = strstr(temp, "=");
		if (ptr != NULL)
		{	
			strcpy(timeinfo_s[timeinfoscount].propertyname, ptr +1);
			strcpy(ptr,"\0");
			strcpy(timeinfo_s[timeinfoscount].taskname ,temp);
			ECHO("\ntimeinfo_s[timeinfoscount].taskname=%s,timeinfo_s[timeinfoscount].propertyname=%s\n",
				timeinfo_s[timeinfoscount].taskname,timeinfo_s[timeinfoscount].propertyname);
		}
		timeinfoscount ++;
        /* Get next token: */
        token = strtok( NULL, ";");
    }
}
//获取参数1
void getUserinfo(char *userinfo)
{
	int ulen = 0,i=0,tempcount=0;
	char temp[128]="";
	BOOL has =FALSE;
	ulen = strlen(userinfo);
	for(i=0;i < ulen;i++)
	{
		if(userinfo[i] == '=')
		{
			temp[tempcount] = '\0';
			strcpy(userinfo_s[userinfoscount].taskname,temp);
			strcpy(temp,"");
			tempcount = 0;
			has = TRUE;
		}
		else if(userinfo[i] == ';' && has)
		{
			temp[tempcount] = '\0';
			strcpy(userinfo_s[userinfoscount].propertyname,temp);
			strcpy(temp,"");
			tempcount = 0;
			userinfoscount = userinfoscount + 1;
			has = FALSE;
		}
		else
		{
			temp[tempcount] = userinfo[i];
			tempcount = tempcount + 1;
		}
	}
}

//获取参数2
void getTimeinfo(char *timeinfo)
{
	int ulen = 0,i=0,tempcount=0;
	char temp[128]="";
	BOOL has =FALSE;
	ulen = strlen(timeinfo);
	for(i=0;i < ulen;i++)
	{
		if(timeinfo[i] == '=')
		{
			temp[tempcount] = '\0';
			if(strcmp(temp,"") == 0)
				continue;
			strcpy(timeinfo_s[timeinfoscount].taskname,temp);
			strcpy(temp,"");
			tempcount = 0;
			has = TRUE;
		}
		else if(timeinfo[i] == ';' && has)
		{
			temp[tempcount] = '\0';
			strcpy(timeinfo_s[timeinfoscount].propertyname,temp);
			strcpy(temp,"");
			tempcount = 0;
			timeinfoscount = timeinfoscount + 1;
			has = FALSE;
		}
		else
		{
			temp[tempcount] = timeinfo[i];
			tempcount = tempcount + 1;
		}
	}
}

/*************************************************************************************************
* jf_sign_ir_master()
*
* Description:
*    This handler will set signoff infomation to properties of form
*
* Syntax:
*         jf-signoff   [-debug=true|false]
*
*		  -SignUserName: 编制=c7Formation;设计=c7Design;审核=c7Review
*              
*         -SignDate: 编制=c7Formationtime;校对=c7DesignTime;审核=c7ReviewTime
*
*		  -SignDateFormate: %Y-%m-%d
*         
*		  -bypass
* Placement:
*    no request
*
**************************************************************************************************/
int jf_sign_ir_master(EPM_action_message_t msg)
{
	int ifail = ITK_ok, rcode = 0;
	//参数相关
	char arg1value[1024] = "",arg2value[1024] = "",arg3value[1024]="",arg4value[1024]="",
		signcounter_info[1024] = "";
	char *argflag =NULL,*argvalue=NULL ,*arg = NULL;
	BOOL bypass = FALSE;
	int arg_cnt = 0;
	//流程节点相关
	tag_t root_task = NULLTAG,*sub_tasks = NULL,current_task = NULLTAG,type_tag = NULLTAG;
	int sub_task_count = 0;
	char root_task_name[128]="",task_name[128] = "";
	int occur_of_counts = 0;
	tag_t *taskAttches = NULLTAG;
	char tgt_type[WSO_name_size_c+1]="",type_class[TCTYPE_class_name_size_c+1]="";
	////循环内部变量
	tag_t cur_task = NULLTAG;
	char task_type[WSO_name_size_c+1] = "";
	//循环变量
	int i=0, j=0, k=0, count = 0, n = 0;
	//节点信息变量
	char sign_info[2048]="";
	//节点循环处理变量
	tag_t itemrevision = NULLTAG,master_form_rel_type = NULLTAG;
	char rev_id[ITEM_id_size_c+1]="";
	char item_id[ITEM_id_size_c+1]="";
	int form_count = 0;
	tag_t *form_list = NULL,master_form = NULLTAG;
	char local_path[128]="";
	//编制节点
	int s=0;
	char *timeinfo2="";
	EPM_decision_t decision = EPM_nogo;
	tag_t aUserTag,responsibleParty;
	char *userName;
	date_t decision_date;
	char person_name[SA_name_size_c + 1] = "";
	char *prop_name="last_mod_date";
	////登录信息
	//char *user_name = NULL, *group_full_name = NULL;
	//tag_t user_tag = NULLTAG, group_tag = NULLTAG;

	//char *txtfile = NULL;
	//会签相关
	int n_prop=0, q = 0;
	char **prop_names=NULL, hq_name[128] = "", hq_time_name[128] = "", *hq_value=NULL;
	char exclude_type[256]="", item_type[ITEM_type_size_c+ 1]= "";
	tag_t item = NULLTAG;
	logical is_sign = false;

	
	current_task = msg.task;
	//CreateLogFile("PLA8_signoff",&txtfile);
	ECHO("=========================================================\n");
	ECHO("jf_sign_ir_master 开始执行\n");
	ECHO("=========================================================\n");
	
	arg_cnt = TC_number_of_arguments(msg.arguments);
	ECHO("参数个数为：%d\n",arg_cnt);
	if (arg_cnt > 0)
	{
		for (i=0;i<arg_cnt;i++)
		{
			arg = TC_next_argument(msg.arguments);
			ITKCALL(ifail = ITK_ask_argument_named_value((const char*)arg, &argflag, &argvalue));
			if (stricmp(argflag, "SignUserName") == 0)
			{
				if(argvalue != NULL)
				{
					strcpy(arg1value,argvalue);
				}
			}
			else if(stricmp(argflag, "SignDate") == 0)
			{
				if(argvalue != NULL)
				{
					strcpy(arg2value,argvalue);
				}
			}
			else if(stricmp(argflag,"SignDateFormat") == 0)
			{
				if(argvalue != NULL)
				{
					strcpy(arg3value,argvalue);
				}
			}
			else if(stricmp(argflag,"bypass") == 0)
			{
				bypass = TRUE;
			}
			//else if(stricmp(argflag,"exclude_type") == 0)
			//{
			//	if(argvalue != NULL)
			//	{
			//		strcpy(exclude_type,argvalue);
			//	}
			//} 

		}
		MEM_free(argflag);
		MEM_free(argvalue);
	}
	//if(bypass)
	//	AM__set_application_bypass(TRUE);
	ITK_set_bypass(TRUE);
	ECHO("SignUserName : %s\n",arg1value);
	ECHO("SignDate : %s\n",arg2value);
	ECHO("SignDateFormat : %s\n",arg3value);
	//ECHO("exclude_type : %s",exclude_type);
	//getUserinfo(arg1value);
	SplitUserInfo(arg1value);
	
	//getTimeinfo(arg2value);
	SplitTimeInfo(arg2value);
	//getCounterinfo(signcounter_info);

	vector<string> type_vec;

	//Split(exclude_type,";",type_vec);

	ECHO("参数1个数：%d\n",userinfoscount);
	ECHO("参数2个数：%d\n",timeinfoscount);

	ITKCALL( EPM_ask_root_task( msg.task, &root_task ) );
	ITKCALL( EPM_ask_sub_tasks( root_task, &sub_task_count, &sub_tasks) ); 
	ITKCALL( EPM_ask_name( root_task, root_task_name ) );
	ECHO("root_task_name=%s\n",root_task_name);
	ITKCALL( EPM_ask_name( current_task, task_name ) );
	ECHO( "sub_task_count = %d\n", sub_task_count );

//test==========================
	//tag_t user = NULLTAG, *tasks = NULL;
	//int n_task= 0;
	//ITKCALL(SA_find_user( "admin", &user ));
	//ITKCALL(SA_ask_user_work_contexts ( user, &n_task, &tasks)); 
	//ECHO("==========n_task=%d",n_task);
//==============================

	//单独处理DO节点
	if(strcmp(task_name,"编制") == 0)
	{
		ECHO("task_name:%s",task_name);
		s = EPM_ask_responsible_party(current_task,&responsibleParty);
		if(responsibleParty != NULLTAG)
		{
			decision = EPM_go;
		}
		s = POM_get_user(&userName,&aUserTag);
		ITKCALL(SA_ask_user_person_name(aUserTag,person_name));
		strcat(sign_info,task_name);
		strcat(sign_info,"=");
		strcat(sign_info,person_name);
		strcat(sign_info,"|");
		strcat(sign_info,task_name);
		strcat(sign_info,"日期=");
		AOM_ask_value_date(current_task,prop_name,&decision_date);
		//AOM_UIF_ask_value(current_task,prop_name, &timeinfo2);
		DATE_date_to_string(decision_date,arg3value,&timeinfo2);
		ECHO("timeinfo2=%s",timeinfo2);
		strcat(sign_info,timeinfo2);
		strcat(sign_info,"|");
		strcpy(flownode_s[nodecount].taskname,task_name);
		strcpy(flownode_s[nodecount].username,person_name);
		strcpy(flownode_s[nodecount].timeinfo,timeinfo2);
		nodecount = nodecount + 1;

	}
	else //perform节点
	{
		for(i=0;i<sub_task_count;i++)
		{
			cur_task = sub_tasks[i];
			ITKCALL(WSOM_ask_object_type(cur_task,task_type));
			ECHO("current task type = %s\n", task_type);
			ORIGIN_ask_sign_info( cur_task, sign_info, task_name,arg3value); 
		}
	}

	ECHO("sign_info = %s\n", sign_info);
	ECHO("the node number is %d",nodecount);
	if(current_task != NULLTAG)
	{
		ITKCALL(EPM_ask_attachments(root_task, EPM_target_attachment, &occur_of_counts, &taskAttches));
		ECHO("%d target attachment found",occur_of_counts);
		
		for( count=0; count<occur_of_counts; count++ )
		{
			ECHO("the %dth work",count);
			ITKCALL(TCTYPE_ask_object_type(taskAttches[count], &type_tag));
			ITKCALL(ifail = TCTYPE_ask_class_name(type_tag, type_class));
			ECHO("type_class : %s",type_class);
			
			//过滤掉非版本对象
			if (((strstr(type_class,"Revision") != NULL) || (strstr(type_class,"revision") != NULL))
				&&(strstr(type_class,"Master") == NULL) &&(strstr(type_class,"master") == NULL)
				&& (strstr(type_class,"BOM") ==NULL) && (strstr(type_class,"bom") ==NULL) && (strstr(type_class,"Bom") == NULL))
			{
				ECHO("==================WORKING======================");
				is_sign = true;
				itemrevision = taskAttches[count];
				ITKCALL(ITEM_ask_rev_id(itemrevision,rev_id));
				ITKCALL(ITEM_ask_item_of_rev( itemrevision, &item));
				//ITKCALL(ITEM_ask_type( item, item_type));
				//for( q = 0; q <type_vec.size(); q++)
				//{
				//	if( type_vec[q].compare(item_type) == 0)
				//	{
				//		is_sign = false;
				//	}
				//}
				//if( !is_sign )
				//{
				//	ECHO("item_type=%s, don't sign.",item_type);
				//	continue;
				//}
				
				ITKCALL( GRM_find_relation_type( TC_master_form_rtype, &master_form_rel_type ) );
				ITKCALL(GRM_list_secondary_objects_only(itemrevision, master_form_rel_type, &form_count, &form_list ));
				if( form_count ==0 )
				{
					ECHO("未找到签名form,继续...");
					continue;
				}
				master_form = form_list[0]; //属性写到版本上

				ECHO("Begin set properties for name\n");
				ITKCALL(AOM_load (master_form));
				//if(bypass)
				//	AM__set_application_bypass(TRUE);
				POM_AM__set_application_bypass(true);
				

				for(j=0; j<userinfoscount; j++)
				{
					//ECHO("userinfo_s[j].taskname:%s",userinfo_s[j].taskname);
					for(k=0; k<nodecount; k++)
					{
						ECHO("userinfo_s[%d].taskname=%s, flownode_s[%d].taskname=%s, flownode_s[%d].username=%s\n",j,userinfo_s[j].taskname,k,flownode_s[k].taskname,k,flownode_s[k].username);
						
						if(strcmp(userinfo_s[j].taskname,flownode_s[k].taskname) == 0)
						{
							POM_AM__set_application_bypass(true);
							ITKCALL(AOM_lock(master_form));
							ECHO("set prop %s=%s\n",userinfo_s[j].propertyname,flownode_s[k].username);
							ITKCALL( AOM_set_value_string( master_form, userinfo_s[j].propertyname, flownode_s[k].username) );
							ITKCALL( AOM_save( master_form ) );
							ITKCALL( AOM_unlock( master_form ) );
							//break;
						}
						else if (strcmp(userinfo_s[j].taskname,flownode_s[k].taskname) != 0 
							//&& strstr(flownode_s[k].taskname, userinfo_s[j].taskname) != NULL
							//&& strstr(userinfo_s[j].taskname,group_full_name) != NULL
							&& strstr(userinfo_s[j].taskname,flownode_s[k].group) != NULL)
						{
							////printf("flownode_s[k].username=%s\n",flownode_s[k].username);
							//set_bypass(true);
							//CALL(AOM_lock(master_form));
							//CALL( AOM_set_value_string( master_form, userinfo_s[j].propertyname, flownode_s[k].username) );
							//CALL( AOM_save( master_form ) );
							//CALL( AOM_unlock( master_form ) );	
							////break;
						}
					}
				}
				ECHO("Begin set properties for time\n");
				POM_AM__set_application_bypass(true);
				
				for(j=0;j< timeinfoscount;j++)
				{
					//ECHO("%s : ",timeinfo_s[j].taskname);
					for(k=0;k<nodecount;k++)
					{
						//printf("group_full_name =%s, timeinfo_s[j].taskname=%s\n",group_full_name,timeinfo_s[j].taskname);
						ECHO("timeinfo_s[%d].taskname=%s, flownode_s[%d].taskname=%s,flownode_s[%d].username=%s\n",j,timeinfo_s[j].taskname,k, flownode_s[k].taskname,k,flownode_s[k].username);
						if(strcmp(timeinfo_s[j].taskname,flownode_s[k].taskname) == 0)
						{
							ECHO("set time prop:%s value:%s\n",timeinfo_s[j].propertyname,flownode_s[k].timeinfo);
							POM_AM__set_application_bypass(true);
							ITKCALL(AOM_lock(master_form));
							PROP_value_type_t valtype;
							char *valtype_n = NULL;
							ITKCALL(AOM_ask_value_type( master_form, timeinfo_s[j].propertyname, &valtype, &valtype_n));
							if( valtype == PROP_date )
							{
								date_t a_date;
								ITK_string_to_date(flownode_s[k].timeinfo, &a_date);
								EMH_clear_errors();
								AOM_set_value_date(master_form, timeinfo_s[j].propertyname, a_date);
								//ITKCALL(AOM_UIF_set_value(itemrevision, timeinfo_s[j].propertyname,flownode_s[k].timeinfo));
							}
							else
								ITKCALL( AOM_set_value_string( master_form, timeinfo_s[j].propertyname, flownode_s[k].timeinfo) );
							DOFREE(valtype_n);
							ITKCALL( AOM_save( master_form ) );
							ITKCALL( AOM_unlock( master_form ) );
							//break;
						}
						else if(strcmp(timeinfo_s[j].taskname,flownode_s[k].taskname) != 0
							//&& strstr(flownode_s[k].taskname,timeinfo_s[j].taskname) != NULL
							//&& strstr(timeinfo_s[j].taskname,group_full_name ) != NULL
							&& strstr(timeinfo_s[j].taskname,flownode_s[k].group ) != NULL)
						{
							//ECHO("222 set prop:%s value:%s",timeinfo_s[j].propertyname,flownode_s[k].timeinfo);
							//set_bypass(true);
							//ITKCALL(AOM_lock(master_form));
							//ITKCALL( AOM_set_value_string( master_form, timeinfo_s[j].propertyname, "222") );
							//ITKCALL( AOM_save( master_form ) );
							//ITKCALL( AOM_unlock( master_form ) );
							////break;				
						}
					}
				}
				ECHO("==================WORK  END====================");
			}
		}
		ECHO("close bypass...");
		//AM__set_application_bypass(FALSE);
		POM_AM__set_application_bypass(false);

	}
	EMH_clear_errors();
	MEM_free(form_list);
	//CloseLog();
	nodecount = 0;
	userinfoscount = 0;
	timeinfoscount = 0;
end_handler:
	//CloseLog();
	DOFREE(taskAttches);
	//DOFREE(pref_values);

	//if (debug)
	{
		printf("=========================================================\n");
		printf("hander jf_sign_ir_master 执行完成\n");
		printf("=========================================================\n");
	}
	return rcode;
}

