#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 <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 "tc_log.h"
// #include "jk_custom.h"
#include "chint_Handler.h"
#include "tc_util.h"
#include <regex>
#include <ics/ics.h>
#include "ado.h"
#include "ocilib.h"
#include <property/nr.h>
#include "CRUL_server_call_httpserver.h"
int CHINT_GetFrock(EPM_action_message_t msg) {

	int ifail = ITK_ok;
	tag_t root_task = NULLTAG, * sub_tasks = NULL, current_task = NULLTAG, type_tag = NULLTAG;
	int sub_task_count = 0, occur_of_counts = 0; tag_t* taskAttches = NULLTAG;
	int attachment_types = EPM_target_attachment;

	current_task = msg.task;
	ECHO("=========================================================\n");
	ECHO("CHINT_GetFrock 开始执行\n");
	ECHO("=========================================================\n");

	EPM_ask_root_task(msg.task, &root_task);
	EPM_ask_sub_tasks(root_task, &sub_task_count, &sub_tasks);
	EPM_ask_attachments(root_task, EPM_target_attachment, &occur_of_counts, &taskAttches);


	for (int count = 0; count < occur_of_counts; count++)
	{

		char* type;
		int num2 = 0;
		tag_t* second;
		tag_t taskTag = taskAttches[count];
		
		AOM_ask_value_string(taskTag, "object_type", &type);
		if (strcmp(type, "ZT2_Design3DRevision") == 0) {
			int n_references = 0;
			int* levels = 0;
			tag_t* references_tag = NULLTAG;
			char** relation_type_name = NULL;
			//通过引用关系查找到变更单
			ITKCALL(WSOM_where_referenced(taskTag, 1, &n_references, &levels, &references_tag, &relation_type_name));
			for (int i = 0; i < n_references; i++) {
				//增加到流程中
				char* objtype;
				ITKCALL(AOM_ask_value_string(references_tag[i], "object_type", &objtype));
				if (strcmp("ZT2_FrockRevision", objtype) == 0) {
					EPM_add_attachments(root_task, 1, &references_tag[i], &attachment_types);
					printf("999\n");
				}
				
			}
		}

		ECHO("=========================================================\n");
		ECHO("CHINT_GetFrock 结束执行\n");
		ECHO("=========================================================\n");

		
	}
	return ifail;
}