#include "util.h"

boolean save_judge(tag_t top,string &check,string &name,vector<string> &type_vec)
{
	int line_cnt;
	tag_t *lines;
	BOM_line_ask_child_lines(top, &line_cnt, &lines);
	char *val;
	for (int i = 0; i<line_cnt; i++)
	{
		AOM_ask_value_string(lines[i], "bl_item_object_type", &val);
		printf("type :%s\n", val);
		if (find(type_vec.begin(), type_vec.end(), val) != type_vec.end())
			continue;
		AOM_UIF_ask_value(lines[i], "jd2_last_release_status", &val);
		string temp = val;
		printf("length:%llu  status:%s\n", temp.length(), val);

		if (temp.length() == 0 || check.find(temp) != -1)
		{
			AOM_ask_value_string(lines[i], "bl_rev_object_string", &val);
			name = val;
			return false;
		}
		if (!save_judge(lines[i], check, name,type_vec))
			return false;
	}
	return true;
}

int bs_bom_save_check(METHOD_message_t *msg, va_list args)
{
	printf("bs_bom_save_check start11\n");

	logical is_judge = false;
	PREF_ask_logical_value("connor_bom_check", 0, &is_judge);
	if (!is_judge)
		return ITK_ok;
	int ifail = ITK_ok, num;

	//获取属性对象
	tag_t win = va_arg(args, tag_t), top;
	char *check_val,**type_val;
	string name,check;
	int type_cnt;
	PREF_ask_char_value("connor_bom_check_value", 0, &check_val);
	PREF_ask_char_values("connor_bom_check_type", &type_cnt, &type_val);
	vector<string> type_vec(type_val,type_val+type_cnt);

	check = check_val;
	BOM_ask_window_top_line(win, &top);
	if (!save_judge(top, check, name,type_vec)) {
		ifail = 1;
		name += "对象为冻结状态或未发布，不能保存BOM!";
		EMH_store_error_s1(EMH_severity_user_error, EMH_PROP_error_base, name.c_str());
	}

	printf("bs_bom_save_check end11\n");

	return  ifail;
}

