#include "util.h"

int bs_test_release_check(EPM_rule_message_t msg)
{
	int ifail = EPM_go, att_count, tag_cnt, rel_cnt;
	tag_t rootTask, *attachments, win, top, *tags, tag,*rels;
	char *val;
	EPM_ask_root_task(msg.task, &rootTask);

	EPM_ask_attachments(rootTask, EPM_target_attachment, &att_count, &attachments);
	TC_argument_list_t * arguments = msg.arguments;
	int arg_cnt = TC_number_of_arguments(arguments), status = 0;

	stringstream name;
	map<string, string> paras;
	for (auto i = 0; i<arg_cnt; i++)
	{
		char *temp_key, *temp_val;
		ITK_ask_argument_named_value(TC_next_argument(arguments), &temp_key, &temp_val);
		paras[temp_key] = temp_val;
	}
	

	for (int i = 0; i<att_count; i++)
	{
		bool pass = true;
		if(!isTypeOf(attachments[i],"JD2_GTSYWTSRevision"))
		{
			continue;
		}
		AOM_ask_value_tags(attachments[i], "JD2_CSJH", &tag_cnt, &tags);
		for(int j=0;j<tag_cnt;j++)
		{
			int tag_cnt2;
			tag_t *tags2,temp_tag;
			ITEM_ask_latest_rev(tags[j], &temp_tag);
			AOM_ask_value_tags(temp_tag, "JD2_CSBG", &tag_cnt2, &tags2);
			printf("release check1\n");

			for(int k=0;k<tag_cnt2;k++)
			{
				ITEM_ask_latest_rev(tags2[k], &tag);
				AOM_ask_value_tags(tag, "release_status_list", &rel_cnt, &rels);
				if (rel_cnt == 0)
				{
					AOM_ask_value_string(tag, "object_string", &val);
					name << val << ",";
					ifail = EPM_nogo;
				}
			}
			AOM_ask_value_tags(temp_tag, "JD2_CSBGHZ", &tag_cnt2, &tags2);
			printf("release check2\n");

			for (int k = 0; k<tag_cnt2; k++)
			{
				ITEM_ask_latest_rev(tags2[k], &tag);
				AOM_ask_value_tags(tag, "release_status_list", &rel_cnt, &rels);
				if (rel_cnt == 0)
				{
					AOM_ask_value_string(tag, "object_string", &val);
					name << val << ",";
					ifail = EPM_nogo;
				}
			}
		}

		
		
	}
	if (ifail == EPM_nogo) {
		name <<"未发布，请先审核发布！";
		EMH_store_error_s1(EMH_severity_user_error, EMH_PROP_error_base, name.str().c_str());
	}
	return ifail;
}

