
#pragma warning (disable: 4819) 



#include <server_exits/user_server_exits.h>
#include <tccore/custom.h>
#include <tccore/item_msg.h>
#include <epm/epm.h>

/**
* @headerfile			standard c & cpp header files
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <tc/tc.h>
#include <tccore/method.h>


/**
* @headerfile			user's header files
*/
#include "epm_register_handler.h"//必须引入头文件
#include "epm_handler_common.h"
#include <iostream>
#include "chint_Handler.h"

#define LIMITDAY 2016



//供流程调用的
// 标准的注册供流程调用服务handler的入口 TC_save_msg
extern DLLAPI int USERSERVICE_custom_register_handlers(int *decision, va_list args)
{
	int ifail = ITK_ok, n=0;

	//标准的注册action_handler的入口
	
		*decision = ALL_CUSTOMIZATIONS;
	//标准的注册action_handler的入口
	//后操作
	/*METHOD_id_t mth_tag;
	(ifail = METHOD_find_method("Item",ITEM_create_msg,&mth_tag));
	cout<<"mth_tag.id------------------>"<<mth_tag.id<<endl;
	if (mth_tag.id != 0){
		(ifail = METHOD_add_action(mth_tag, METHOD_post_action_type, HXC_create_item_post, NULL));
		fprintf(stdout,"regist HXC_create_item_post post_action successfully  !\n");
		printf("项目对象后操作注册成功  !\n");
	}else{
		fprintf(stdout,"regist HXC_create_item_post post_action fiald  !\n");
		printf("项目对象后操作注册失败  !\n");
	}
	
	( ifail = EPM_register_rule_handler("WX_Check_Property", "检查属性是否为空",(EPM_rule_handler_t) WX_Check_Property));//汇总表
	if(ifail==0) {
		printf("Registering rule handler WX_Check_Property successful\n");
	} else {
		printf("Registering rule handler WX_Check_Property failed %d\n", ifail);
	}
	( ifail = EPM_register_rule_handler("Modify_Attributes", "批量修改属性",(EPM_rule_handler_t) Modify_Attributes));//汇总表
	if(ifail==0) {
		printf("Registering rule handler Modify_Attributes successful\n");
	} else {
		printf("Registering rule handler Modify_Attributes failed %d\n", ifail);
	}	
	( ifail = EPM_register_rule_handler("Check_range", "检查excel某个单元格是否有值",(EPM_rule_handler_t) Check_range));//汇总表
	if(ifail==0) {
		printf("Registering rule handler Check_range successful\n");
	} else {
		printf("Registering rule handler Check_range failed %d\n", ifail);
	}


	( ifail = EPM_register_action_handler("Remove_Release_Status", "移除发布状态",(EPM_action_handler_t) Remove_Release_Status));//handler名称，handler描述，handler的注册指针
	if(ifail==0) {
		printf("Registering action handler Remove_Release_Status successful\n");
	} else {
		printf("Registering action handler Remove_Release_Status failed %d\n", ifail);
	}

( ifail = EPM_register_action_handler("AddReleaseStatus", "添加发布状态",(EPM_action_handler_t) AddReleaseStatus));//handler名称，handler描述，handler的注册指针
	if(ifail==0) {
		printf("Registering action handler AddReleaseStatus successful\n");
	} else {
		printf("Registering action handler AddReleaseStatus failed %d\n", ifail);
	}

	( ifail = EPM_register_action_handler("AutomaticRelease", "关联零组件自动发布",(EPM_action_handler_t) AutomaticRelease));//handler名称，handler描述，handler的注册指针
	if(ifail==0) {
		printf("Registering action handler AutomaticRelease successful\n");
	} else {
		printf("Registering action handler AutomaticRelease failed %d\n", ifail);
	}*/

	/*( ifail = EPM_register_action_handler("AddTime", "添加时间",(EPM_action_handler_t) AddTime));//handler名称，handler描述，handler的注册指针
	if(ifail==0) {
		printf("Registering action handler AddTime successful\n");
	} else {
		printf("Registering action handler AddTime failed %d\n", ifail);
	}*/
		/*ifail = EPM_register_action_handler("chint_set_prop_1", "修改流程目标属性1", (EPM_action_handler_t)chint_set_prop_1);
	if(ifail==0) {
		printf("Registering action handler chint_set_prop_1 successful\n");
	} else {
		printf("Registering action handler chint_set_prop_1 failed %d\n", ifail);
	}	
	ifail = EPM_register_action_handler("ChintSendMessage_1", "PLM-AM1", (EPM_action_handler_t)ChintSendMessage_1);
	if(ifail==0) {
		printf("Registering action handler ChintSendMessage_1 successful\n");
	} else {
		printf("Registering action handler ChintSendMessage_1 failed %d\n", ifail);
	}
	ifail = EPM_register_action_handler("chintP", "chintP", (EPM_action_handler_t)chintP);
	if(ifail==0) {
		printf("Registering action handler chintP successful\n");
	} else {
		printf("Registering action handler chintP failed %d\n", ifail);
	}*/
	ITKCALL(ifail = EPM_register_action_handler("chintProperty", "chintProperty", (EPM_action_handler_t)chintProperty));
	if(ifail==0) {
		printf("Registering action handler chintProperty successful\n");
	} else {
		printf("Registering action handler chintProperty failed %d\n", ifail);
	}	
	
	ITKCALL(ifail = EPM_register_action_handler("chintSignChange", "chintSignChange", (EPM_action_handler_t)chintSignChange));
	if(ifail==0) {
		printf("Registering action handler chintSignChange successful\n");
	} else {
		printf("Registering action handler chintSignChange failed %d\n", ifail);
	}
	
	ITKCALL(ifail = EPM_register_action_handler("chint_signoff_dataset", "chint_signoff_dataset", (EPM_action_handler_t)chint_signoff_dataset));
	if(ifail==0) {
		printf("Registering action handler chint_signoff_dataset successful\n");
	} else {
		printf("Registering action handler chint_signoff_dataset failed %d\n", ifail);
	}	

	ITKCALL(ifail = EPM_register_action_handler("chint_getChgOrde", "chint_getChgOrde", (EPM_action_handler_t)chint_getChgOrde));
	if (ifail == 0) {
		printf("Registering action handler chint_getChgOrde successful\n");
	}
	else {
		printf("Registering action handler chint_getChgOrde failed %d\n", ifail);
	}

	ITKCALL(ifail = EPM_register_action_handler("chint_getProduct", "chint_getProduct", (EPM_action_handler_t)chint_getProduct));
	if (ifail == 0) {
		printf("Registering action handler chint_getProduct successful\n");
	}
	else {
		printf("Registering action handler chint_getProduct failed %d\n", ifail);
	}

	ITKCALL(ifail = EPM_register_action_handler("chint_DesignProcess", "chint_DesignProcess", (EPM_action_handler_t)chint_DesignProcess));
	if (ifail == 0) {
		printf("Registering action handler chint_DesignProcess successful\n");
	}
	else {
		printf("Registering action handler chint_DesignProcess failed %d\n", ifail);
	}

	ITKCALL(ifail = EPM_register_action_handler("chint_pdf_signoff", "chint_pdf_signoff", (EPM_action_handler_t)chint_pdf_signoff));
	if (ifail == 0) {
		printf("Registering action handler chint_pdf_signoff successful\n");
	}
	else {
		printf("Registering action handler chint_pdf_signoff failed %d\n", ifail);
	}
	ITKCALL(ifail = EPM_register_action_handler("chint_updateToPi", "chint_updateToPi", (EPM_action_handler_t)chint_updateToPi));
	if (ifail == 0) {
		printf("Registering action handler chint_updateToPi successful\n");
	}
	else {
		printf("Registering action handler chint_updateToPi failed %d\n", ifail);
	}
	ITKCALL(ifail = EPM_register_action_handler("chint_add_to_workflow", "chint_add_to_workflow", (EPM_action_handler_t)chint_add_to_workflow));
	if (ifail == 0) {
		printf("Registering action handler chint_add_to_workflow successful\n");
	}
	else {
		printf("Registering action handler chint_add_to_workflow failed %d\n", ifail);
	}
	ITKCALL(ifail = EPM_register_action_handler("chint_remove_other_deisgndata", "chint_remove_other_deisgndata", (EPM_action_handler_t)chint_remove_other_deisgndata));
	if (ifail == 0) {
		printf("Registering action handler chint_remove_other_deisgndata successful\n");
	}
	else {
		printf("Registering action handler chint_remove_other_deisgndata failed %d\n", ifail);
	}
	ITKCALL(ifail = EPM_register_action_handler("chint_check_exist_ebom", "chint_check_exist_ebom", (EPM_action_handler_t)chint_check_exist_ebom));
	if (ifail == 0) {
		printf("Registering action handler chint_check_exist_ebom successful\n");
	}
	else {
		printf("Registering action handler chint_check_exist_ebom failed %d\n", ifail);
	}

	ITKCALL(ifail = EPM_register_action_handler("chint_backCheckTable", "chint_backCheckTable", (EPM_action_handler_t)chint_backCheckTable));
	if (ifail == 0) {
		printf("Registering action handler chint_backCheckTable successful\n");
	}
	else {
		printf("Registering action handler chint_backCheckTable failed %d\n", ifail);
	}

	ITKCALL(ifail = EPM_register_action_handler("chint_CheckTable_State", "chint_CheckTable_State", (EPM_action_handler_t)chint_CheckTable_State));
	if (ifail == 0) {
		printf("Registering action handler chint_CheckTable_State successful\n");
	}
	else {
		printf("Registering action handler chint_CheckTable_State failed %d\n", ifail);
	}
	
	ITKCALL(ifail = EPM_register_action_handler("chint_check_ZC_ZJ_BOM", "chint_check_ZC_ZJ_BOM", (EPM_action_handler_t)chint_check_ZC_ZJ_BOM));
	if (ifail == 0) {
		printf("Registering action handler chint_check_ZC_ZJ_BOM successful\n");
	}
	else {
		printf("Registering action handler chint_check_ZC_ZJ_BOM failed %d\n", ifail);
	}

	ITKCALL(ifail = EPM_register_action_handler("CHINT_task_complete", "CHINT_task_complete", (EPM_action_handler_t)CHINT_task_complete));
	if (ifail == 0) {
		printf("Registering action handler CHINT_task_complete successful\n");
	}
	else {
		printf("Registering action handler CHINT_task_complete failed %d\n", ifail);
	}
	ITKCALL(ifail = EPM_register_action_handler("CHINT_yptask_complete", "CHINT_yptask_complete", (EPM_action_handler_t)CHINT_yptask_complete));
	if (ifail == 0) {
		printf("Registering action handler CHINT_yptask_complete successful\n");
	}
	else {
		printf("Registering action handler CHINT_yptask_complete failed %d\n", ifail);
	}

	ITKCALL(ifail = EPM_register_action_handler("CHINT_cossheet_upgrade", "CHINT_cossheet_upgrade", (EPM_action_handler_t)CHINT_cossheet_upgrade));
	if (ifail == 0) {
		printf("Registering action handler CHINT_cossheet_upgrade successful\n");
	}
	else {
		printf("Registering action handler CHINT_cossheet_upgrade failed %d\n", ifail);
	}
	ITKCALL(ifail = EPM_register_action_handler("CHINT_SendOAMaterial", "CHINT_SendOAMaterial", (EPM_action_handler_t)CHINT_SendOAMaterial));
	if (ifail == 0) {
		printf("Registering action handler CHINT_SendOAMaterial successful\n");
	}
	else {
		printf("Registering action handler CHINT_SendOAMaterial failed %d\n", ifail);
	}
	//oa 版本加入流程
	ITKCALL(ifail = EPM_register_action_handler("CHINT_GetFrock", "CHINT_GetFrock", (EPM_action_handler_t)CHINT_GetFrock));
	if (ifail == 0) {
		printf("Registering action handler CHINT_GetFrock successful\n");
	}
	else {
		printf("Registering action handler CHINT_GetFrock failed %d\n", ifail);
	}
	//oa 变更传递OA
	ITKCALL(ifail = EPM_register_action_handler("chint_ecn_to_oa", "chint_ecn_to_oa", (EPM_action_handler_t)CHINT_ECN_SendOA));
	if (ifail == 0) {
		printf("Registering action handler chint_ecn_to_oa successful\n");
	}
	else {
		printf("Registering action handler chint_ecn_to_oa failed %d\n", ifail);
	}
	//3.9.2.2.1流程指派人员自动获取
	ITKCALL(ifail = EPM_register_action_handler("CHINT_Assignment", "CHINT_Assignment", (EPM_action_handler_t)CHINT_Assignment));
	if (ifail == 0) {
		printf("Registering action handler CHINT_Assignment successful\n");
	}
	else {
		printf("Registering action handler CHINT_Assignment failed %d\n", ifail);
	}
	//更改通知单新版excel文件签名
	ITKCALL(ifail = EPM_register_action_handler("chint_ecn_signoff", "chint_ecn_signoff", (EPM_action_handler_t)chint_ecn_signoff));
	if (ifail == 0) {
		printf("Registering action handler chint_ecn_signoff successful\n");
	}
	else {
		printf("Registering action handler chint_ecn_signoff failed %d\n", ifail);
	}
	//指派变更会签节点
	ITKCALL(ifail = EPM_register_action_handler("chint_ecn_assign", "chint_ecn_assign", (EPM_action_handler_t)chint_ecn_assign));
	if (ifail == 0) {
		printf("Registering action handler chint_ecn_assign successful\n");
	}
	else {
		printf("Registering action handler chint_ecn_assign failed %d\n", ifail);
	}
	//SRM
	ITKCALL(ifail = EPM_register_action_handler("CHINT_DRAWING_TO_SRM", "CHINT_DRAWING_TO_SRM", (EPM_action_handler_t)CHINT_DRAWING_TO_SRM));
	if (ifail == 0) {
		printf("Registering action handler CHINT_DRAWING_TO_SRM successful\n");
	}
	else {
		printf("Registering action handler CHINT_DRAWING_TO_SRM failed %d\n", ifail);
	}
	//飞书通知
	ITKCALL(ifail = EPM_register_action_handler("chint_changenotice", "chint_changenotice", (EPM_action_handler_t)chint_changenotice));
	if (ifail == 0) {
		printf("Registering action handler chint_changenotice successful\n");
	}
	else {
		printf("Registering action handler chint_changenotice failed %d\n", ifail);
	}

	//BOM物料封存停用状态
	ITKCALL(ifail = EPM_register_action_handler("chint_check_materialstatus", "chint_check_materialstatus", (EPM_action_handler_t)chint_check_materialstatus));
	if (ifail == 0) {
		printf("Registering action handler chint_check_materialstatus successful\n");
	}
	else {
		printf("Registering action handler chint_check_materialstatus failed %d\n", ifail);
	}

	//飞书通知bm
	ITKCALL(ifail = EPM_register_action_handler("chint_changenoticebm", "chint_changenoticebm", (EPM_action_handler_t)chint_changenoticebm));
	if (ifail == 0) {
		printf("Registering action handler chint_changenoticebm successful\n");
	}
	else {
		printf("Registering action handler chint_changenoticebm failed %d\n", ifail);
	}

	//PLM推送变更通知单数据流信息
	ITKCALL(ifail = EPM_register_action_handler("CHINT_CHANGEITEM_TO_SRM", "CHINT_CHANGEITEM_TO_SRM", (EPM_action_handler_t)CHINT_CHANGEITEM_TO_SRM));
	if (ifail == 0) {
		printf("Registering action handler CHINT_CHANGEITEM_TO_SRM successful\n");
	}
	else {
		printf("Registering action handler CHINT_CHANGEITEM_TO_SRM failed %d\n", ifail);
	}

	//PLM推送BOM差异表数据流信息
	ITKCALL(ifail = EPM_register_action_handler("CHINT_CHANGEBOM_TO_SRM", "CHINT_CHANGEBOM_TO_SRM", (EPM_action_handler_t)CHINT_CHANGEBOM_TO_SRM));
	if (ifail == 0) {
		printf("Registering action handler CHINT_CHANGEBOM_TO_SRM successful\n");
	}
	else {
		printf("Registering action handler CHINT_CHANGEBOM_TO_SRM failed %d\n", ifail);
	}

	//SRM-修改图纸
	ITKCALL(ifail = EPM_register_action_handler("CHINT_CHANGETZCG_TO_SRM", "CHINT_CHANGETZCG_TO_SRM", (EPM_action_handler_t)CHINT_CHANGETZCG_TO_SRM));
	if (ifail == 0) {
		printf("Registering action handler CHINT_CHANGETZCG_TO_SRM successful\n");
	}
	else {
		printf("Registering action handler CHINT_CHANGETZCG_TO_SRM failed %d\n", ifail);
	}

	//参数化数据校验
	ITKCALL(ifail = EPM_register_rule_handler("chint_csh_check", "", chint_csh_check));
	if (ifail == 0) {
		printf("Registering rule handler chint_csh_check successful\n");
	}
	else {
		printf("Registering rule handler chint_csh_check failed %d\n", ifail);
	}

	return ifail;
}
//
//注册JAVA调用的服务(比如说想在Java里调用的开或者关旁路，设置发布状态的方法都在这里就写在这里面)
//register service method
extern DLLAPI int USERSERVICE_custom_register_methods(int *decision, va_list args)
{
	{	//2023 12 27 新增项目更新后操作
		METHOD_id_t mth_tag;
		ITKCALL(METHOD_find_method("Item", "IMAN_save", &mth_tag));
		if (mth_tag.id != 0) {
			METHOD_add_action(mth_tag, METHOD_post_action_type, (METHOD_function_t)CHINT_SavePost, NULL);
			printf("注册ItemRevision函数成功！\n");
		}
	}
	{
		int  numberOfArguments = 1;
		int  returnValueType = USERARG_STRING_TYPE;
		int *argumentList = NULL;
		USER_function_t functionPtr = NULL;
		functionPtr = DbomToEMethod;
		argumentList = (int*)MEM_alloc(numberOfArguments * sizeof(int));
		argumentList[0] = USERARG_STRING_TYPE;
		//argumentList[1] = USERARG_STRING_TYPE;
		int status = USERSERVICE_register_method("DbomToEMethod", functionPtr, numberOfArguments, argumentList, returnValueType);
		if (status == ITK_ok)
		{
			printf("Registering DbomToEMethod finished\n");
		}
		else
		{
			printf("Registering DbomToEMethod failed %d\n", status);
		}
		MEM_free(argumentList);
	}
	{
		int  numberOfArguments = 1;
		int  returnValueType = USERARG_STRING_TYPE;
		int *argumentList = NULL;
		USER_function_t functionPtr = NULL;
		functionPtr = DbomToEMethodUser;
		argumentList = (int*)MEM_alloc(numberOfArguments * sizeof(int));
		argumentList[0] = USERARG_STRING_TYPE;
		//argumentList[1] = USERARG_STRING_TYPE;
		int status = USERSERVICE_register_method("DbomToEMethodUser", functionPtr, numberOfArguments, argumentList, returnValueType);
		if (status == ITK_ok)
		{
			printf("Registering DbomToEMethodUser finished\n");
		}
		else
		{
			printf("Registering DbomToEMethodUser failed %d\n", status);
		}
		MEM_free(argumentList);
	}
	{
		int  numberOfArguments = 1;
		int  returnValueType = USERARG_STRING_TYPE;
		int *argumentList = NULL;
		USER_function_t functionPtr = NULL;
		functionPtr = EbomToPMethod;
		argumentList = (int*)MEM_alloc(numberOfArguments * sizeof(int));
		argumentList[0] = USERARG_STRING_TYPE;

		int status = USERSERVICE_register_method("EbomToPMethod", functionPtr, 
			numberOfArguments, argumentList, returnValueType);
		if (status == ITK_ok)
		{
			printf("Registering EbomToPMethod finished\n");
		}
		else
		{
			printf("Registering EbomToPMethod failed %d\n", status);
		}
		MEM_free(argumentList);
	}
	{
		int  numberOfArguments = 1;
		int  returnValueType = USERARG_STRING_TYPE;
		int *argumentList = NULL;
		USER_function_t functionPtr = NULL;
		functionPtr = CloneTempProcess;
		argumentList = (int*)MEM_alloc(numberOfArguments * sizeof(int));
		argumentList[0] = USERARG_STRING_TYPE;

		int status = USERSERVICE_register_method("CloneTempProcess", functionPtr,
			numberOfArguments, argumentList, returnValueType);
		if (status == ITK_ok)
		{
			printf("Registering CloneTempProcess finished\n");
		}
		else
		{
			printf("Registering CloneTempProcess failed %d\n", status);
		}
		MEM_free(argumentList);
	}
	{
		int  numberOfArguments = 1;
		int  returnValueType = USERARG_STRING_TYPE;
		int *argumentList = NULL;
		USER_function_t functionPtr = NULL;
		functionPtr = UpdateWorkTime;
		argumentList = (int*)MEM_alloc(numberOfArguments * sizeof(int));
		argumentList[0] = USERARG_STRING_TYPE;

		int status = USERSERVICE_register_method("UpdateWorkTime", functionPtr,
			numberOfArguments, argumentList, returnValueType);
		if (status == ITK_ok)
		{
			printf("Registering UpdateWorkTime finished\n");
		}
		else
		{
			printf("Registering UpdateWorkTime failed %d\n", status);
		}
		MEM_free(argumentList);
	}
	{
		int  numberOfArguments = 1;
		int  returnValueType = USERARG_STRING_TYPE;
		int *argumentList = NULL;
		USER_function_t functionPtr = NULL;
		functionPtr = AutoFeeding;
		argumentList = (int*)MEM_alloc(numberOfArguments * sizeof(int));
		argumentList[0] = USERARG_STRING_TYPE;

		int status = USERSERVICE_register_method("AutoFeeding", functionPtr,
			numberOfArguments, argumentList, returnValueType);
		if (status == ITK_ok)
		{
			printf("Registering AutoFeeding finished\n");
		}
		else
		{
			printf("Registering AutoFeeding failed %d\n", status);
		}
		MEM_free(argumentList);
	}
	{
		//武汉组织BOM汇总清单接口改为C组织数据
		int numberOfArguments = 1;
		int returnValueType = USERARG_STRING_TYPE;
		int *argumentList = NULL;
		USER_function_t functionPtr = NULL;
		functionPtr = getBomDetails;
		argumentList = (int*)MEM_alloc(numberOfArguments * sizeof(int));
		argumentList[0] = USERARG_STRING_TYPE;

		int status = USERSERVICE_register_method("getBomDetails", functionPtr,
			numberOfArguments, argumentList, returnValueType);
		if (status == ITK_ok)
		{
			printf("Registering getBomDetails finished\n");
		}
		else
		{
			printf("Registering getBomDetails failed %d\n", status);
		}
		MEM_free(argumentList);
	}
	{
		/*添加状态*/
		USER_function_t functionPtr = AddReleasedStatus;
		int numberOfArguments = 2;
		int returnValueType = USERARG_VOID_TYPE;
		int *argumentList = (int*)MEM_alloc(numberOfArguments * sizeof(int));
		argumentList[0] = USERARG_TAG_TYPE;
		argumentList[1] = USERARG_STRING_TYPE;
		ITKCALL(USERSERVICE_register_method("AddReleasedStatus", functionPtr, numberOfArguments, argumentList, returnValueType));
		printf("Registering AddReleasedStatus finished\n");
		MEM_free(argumentList);
	}
	return ITK_ok;
}


