//#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 "ado.h"
//#include "ocilib.h"
////根据首选项信息获取m_code
//
//
////查询数据库信息 PartSqlUtil.getConnection()
////SQL.URL = jdbc:sqlserver://10.128.20.35:1433;DatabaseName=BDP2020
////SQL.DRIVER = com.microsoft.sqlserver.jdbc.SQLServerDriver
////SQL.USER = PLMUser
////SQL.PASSWORD = PLMUser
//
////1ZDB 2ZDB 4ZDB
//string groupId;
//string Sql2 = "select t.PrhName,t.PrdLine,t.PrdNo,t.PrdFeatureCode,t.FeatureName,t.PrdCanInput,t.PrdSign from CcemVW_Prd t where t.prhcode = '%s' order by t.PrdNo";
//string Sql1 = "select t.PmpcPrhCode, t.PmpcPType,t.PmpcMType from CcemVW_Pmpc t where t.PmpcCode='%s'";
//string m_code1 = "230101001";
//string m_code2 = "220101001";
//
//string sql_query = "select FeatureList from CcemVW_GoodsFeature where GoodsCode ='%s' ";
//struct PRD
//{
//	string prdFeatureCode;
//	string featureName;
//};
//struct PMPC
//{
//	string m_code;
//	string pmpcPrhCode;
//	string pmpcPType;
//	string pmpcMType;
//};
//vector<PRD> prds2;
//vector<PRD> prds;
//PMPC pmpc;
//PMPC pmpc2;
//void listBom(tag_t bom_line, vector<tag_t> &bomLineVec) {
//
//	int c_line_count;
//	tag_t *c_line_tags;
//	ITKCALL(BOM_line_ask_all_child_lines(bom_line, &c_line_count, &c_line_tags));
//	for (int i = 0; i < c_line_count; i++) {
//
//		tag_t c_line_tag = c_line_tags[i];
//		bomLineVec.push_back(c_line_tag);
//		listBom(c_line_tag, bomLineVec);
//	}
//	
//
//}
//boolean isNeedApply(tag_t rev){
//	char *type,*zt2_Diagram,*zt2_Source;
//	AOM_ask_value_string(rev,"object_type", &type);
//	if (strcmp(type,"ZT2_Design3DRevision")==0)
//		return false;
//	// 虚拟项不申请
//	AOM_ask_value_string(rev, "zt2_Diagram", &zt2_Diagram);
//	if (strcmp(zt2_Diagram, "Y") == 0 || strcmp(zt2_Diagram, "是") == 0) {
//		return false;
//	}
//	int cnt = 0;
//	tag_t *children;
//	AOM_UIF_ask_value(rev,"zt2_Source", &zt2_Source);
//	printf("zt2_Source ==> %s\n", zt2_Source);
//	AOM_ask_value_tags(rev,"ZT2_FactoryNumber",&cnt, &children);
//	if (cnt > 0) {
//		return false;
//	}
//	return true;
//}
//void getRevs(tag_t line,string &errBuff,map<tag_t,vector<string>> &general_maps) {
//
//	tag_t rev;
//	ITKCALL(AOM_ask_value_tag(line, "bl_line_object", &rev));
//	if (isNeedApply(rev)) {
//		char *itemId,*ZT2_TYSpecifications;
//		AOM_ask_value_string(rev, "item_id", &itemId);
//		if (strstr("1ZDB", itemId) == 0 || strstr("2ZDB", itemId) == 0 || strstr("4ZDB", itemId) == 0) {
//			int cnt=0;
//			tag_t *comps;
//			AOM_ask_value_string(line,"ZT2_TYSpecifications",&ZT2_TYSpecifications);
//			if (strcmp(ZT2_TYSpecifications,"") == 0) {
//				AOM_ask_value_tags(rev,"representation_for",&cnt,&comps);
//				char *zt2_Specifications;
//				if (cnt == 0) {
//					AOM_ask_value_string(rev, "zt2_Specifications", &zt2_Specifications);
//					if (general_maps.count(rev) == 1) {
//						vector<string> vec = general_maps[rev];
//						if (std::find(vec.begin(), vec.end(), zt2_Specifications) == vec.end()) {
//							vec.push_back(zt2_Specifications);
//						}
//					}
//					else {
//						vector<string> vec;
//						vec.push_back(zt2_Specifications);
//						general_maps[rev] = vec;
//					}
//				}
//			}
//			else {
//				string qryVal;
//				tag_t query = NULLTAG, *tags;
//				map<string, tag_t> map_revs;
//				qryVal.append("*").append(itemId).append("*").append(ZT2_TYSpecifications).append("*");
//				//fields.put("描述", "*" + item_id + "*" + zt2_TYJNo + "*");
//				ITKCALL(QRY_find2("chint_query_material_test", &query));
//				char* qry_entries[2] = { "描述","关联的图号" }, *qry_values[2] = { (char *)qryVal.c_str(),itemId };
//				int n_found;
//				ITKCALL(QRY_execute(query, 2, qry_entries, qry_values, &n_found, &tags));
//				if (n_found == 0) {
//					if (general_maps.count(rev) == 1) {
//						vector<string> vec = general_maps[rev];
//						if (std::find(vec.begin(), vec.end(), ZT2_TYSpecifications) == vec.end()) {
//							vec.push_back(ZT2_TYSpecifications);
//						}
//					}
//					else {
//						vector<string> vec;
//						vec.push_back(ZT2_TYSpecifications);
//						general_maps[rev] = vec;
//					}
//				}
//				else {
//					boolean flag2 = true;
//					for (int i = 0; i < n_found; i++) {
//						if (!flag2) {
//							break;
//						}
//						char *zt2_MaterialNo;
//						tag_t matnrTag = tags[i];
//						AOM_ask_value_string(matnrTag,"zt2_MaterialNo",&zt2_MaterialNo);
//						char selectRecord[200];
//						int outputColumn = 0, outputValueCount = 0;
//						char*** outputValue = NULL;
//						sprintf(selectRecord, sql_query.c_str(), zt2_MaterialNo);
//						ado_QuerySQLNoInputParam(selectRecord, &outputColumn, &outputValueCount, &outputValue);
//						string pmpcPrhCode, pmpcPType, pmpcMType;
//						for (int j = 0; j < outputValueCount; j++) {
//							string featureList = outputValue[j][0];
//							vector<string> vec2;
//							Split(featureList, ",", vec2);
//							for (int x = 0, len2 = vec2.size(); x < len2; x++) {
//								if (vec2[x].rfind("F064:", 0) == 0) {
//									string temp = "F064:";
//									temp.append(ZT2_TYSpecifications);
//									if (vec2[x].compare(temp)==0) {
//										flag2 = false;
//									}
//									break;
//								}
//							}
//						}
//					}
//					if (flag2) {
//						if (general_maps.count(rev) == 1) {
//							vector<string> vec = general_maps[rev];
//							if (std::find(vec.begin(), vec.end(), ZT2_TYSpecifications) == vec.end()) {
//								vec.push_back(ZT2_TYSpecifications);
//							}
//						}
//						else {
//							vector<string> vec;
//							vec.push_back(ZT2_TYSpecifications);
//							general_maps[rev] = vec;
//						}
//					}
//				}
//			}
//		}
//	}
//}
//void send1(map<tag_t, vector<string>> general_maps,string now,
//	char *user_id,vector<string> &jsons) {
//	map<tag_t, vector<string>>::iterator it;
//	for (it = general_maps.begin(); it != general_maps.end(); it++) {
//		tag_t rev = it->first;
//		char *item_id, *object_name, *zt2_DrawingNo1, *zt2_MaterialMark, *zt2_ProductModel
//			, *object_desc, *zt2_SurfaceTreatment,*zt2_Source;
//		vector<string> specs = it->second;
//		AOM_ask_value_string(rev,"item_id", &item_id); //groupId
//		AOM_ask_value_string(rev, "object_name", &object_name);
//		AOM_ask_value_string(rev, "zt2_DrawingNo", &zt2_DrawingNo1);
//		AOM_ask_value_string(rev, "zt2_MaterialMark", &zt2_MaterialMark);
//		AOM_ask_value_string(rev, "zt2_ProductModel", &zt2_ProductModel);
//		AOM_ask_value_string(rev, "object_desc", &object_desc);
//		AOM_ask_value_string(rev, "zt2_SurfaceTreatment", &zt2_SurfaceTreatment);
//		AOM_UIF_ask_value(rev, "zt2_Source", &zt2_Source);
//		PMPC m_pmpc;
//		vector<PRD> m_prds;
//		if (strstr(item_id,"1ZDB") == 0) {
//			m_prds = prds;
//			m_pmpc = pmpc;
//		}
//		else {
//			m_prds = prds2;
//			m_pmpc = pmpc2;
//		}
//		string pmpcCode = m_pmpc.m_code;
//		string prhCode = m_pmpc.pmpcPrhCode;
//		string pmpcType = m_pmpc.pmpcMType;
//		if (pmpcType.length() == 0) {
//			continue;
//		}
//		string goodsCode = ""; // 申请时为空
//		string goodsName = object_name;//rev.getProperty("object_name");
//		string unitCode = "ST"; // 默认件，真实值ST
//		string companyCode = groupId;
//		string mp = "M";
//		if (strcmp(zt2_Source,"外购")==0) {
//			mp = "P";
//			pmpcType = m_pmpc.pmpcPType;
//		}
//		string bpNo = item_id;//rev.getProperty("item_id"); // 非必填
//		string zt2_DrawingNo = zt2_DrawingNo1;//rev.getProperty("zt2_DrawingNo");
//		if (!zt2_DrawingNo.empty()) {
//			if (strcmp(item_id, zt2_DrawingNo1)!=0)
//				bpNo = zt2_DrawingNo1;
//		}
//		string materialMark = zt2_MaterialMark;//rev.getProperty("zt2_MaterialMark"); // 非必填
//
//		if (materialMark.compare("--")==0) {
//			materialMark = "";
//		}
//		// 产品型号 //所属产品
//		string productModel = zt2_ProductModel;//rev.getProperty("zt2_ProductModel");
//		string teRe = "";
//		string state = ""; // 申请时为空
//		string wbs = "";
//		string product = "";
//		string user = user_id;
//		string time = now;
//		string condition = "审核中";// 默认审核中
//		string desc = object_desc;// properties[5];//rev.getProperty("object_desc");
//		for (int i = 0; i < specs.size(); i++) {
//			string json = "{";
//			string sql22 = "select CHINT_MATERIAL_SEQ.nextval as sid from dual";
//			int colmun2 = 0, count2 = 0;
//			char ***outputValue2 = NULL;
//			QuerySQLNoInputParam((char *)sql22.c_str(), &colmun2, &count2, &outputValue2);
//			char *projn;
//			if (count2 > 0) {
//				projn = outputValue2[0][0];
//			}
//			json.append("\"Code\":").append(projn);
//			string spec = specs[i]; // 非必填
//			string feature = "\"Feature\":{";
//			for (int j = 0; j < m_prds.size(); j++) {
//				PRD prd = m_prds[j];
//				//System.out.println(prd.prdFeatureCode + "-" + prd.featureName);
//				if (strstr(prd.featureName.c_str(),"材质")!=NULL) {
//					feature.append("\"").append(prd.prdFeatureCode).append("\":\"")
//						.append(zt2_MaterialMark).append("\",");
//				}else if (strstr(prd.featureName.c_str(), "名称") != NULL) {
//					feature.append("\"").append(prd.prdFeatureCode).append("\":\"")
//						.append(goodsName).append("\",");
//				}
//				else if (strstr(prd.featureName.c_str(), "型号") != NULL|| strstr(prd.featureName.c_str(), "规格") != NULL) {
//					feature.append("\"").append(prd.prdFeatureCode).append("\":\"")
//						.append(spec).append("\",");
//				}
//				else if (strstr(prd.featureName.c_str(), "图样代号") != NULL) {
//					feature.append("\"").append(prd.prdFeatureCode).append("\":\"")
//						.append(bpNo).append("\",");
//				}
//				else if (strstr(prd.featureName.c_str(), "所属产品") != NULL) {
//					feature.append("\"").append(prd.prdFeatureCode).append("\":\"")
//						.append(zt2_ProductModel).append("\",");
//				}
//				else{
//					feature.append("\"").append(prd.prdFeatureCode).append("\":\"").append("\",");
//				}
//			}
//			if (strcmp(zt2_SurfaceTreatment, "") != 0) {
//				feature.append("\"").append("F067").append("\":\"").append(zt2_SurfaceTreatment).append("\",");
//			}
//			feature.substr(0, feature.length());
//			feature.append("},");
//			string data = "\"data\":[{";
//			data.append("\"PrhCode").append("\":\"").append(prhCode).append("\",");
//			data.append("\"PmpcCode").append("\":\"").append(pmpcCode).append("\",");
//			data.append("\"PmpcType").append("\":\"").append(pmpcType).append("\",");
//			data.append("\"UnitCode").append("\":\"").append(unitCode).append("\",");
//			data.append("\"CompanyCode").append("\":\"").append(companyCode).append("\",");
//			data.append("\"UserCode").append("\":\"").append(user).append("\",");
//			data.append("\"MP").append("\":\"").append(mp).append("\",");
//			data.append(feature);
//			data.append("\"ProductGroupCode").append("\":\"").append("\",");
//			data.append("\"AssistUnitCode").append("\":\"").append("\",");
//			data.append("\"UnitQty").append("\":\"").append("\",");
//			data.append("\"AssistUnitQty").append("\":\"").append("\",");
//			data.append("\"Desc").append("\":\"").append(desc).append("\",");
//			data.append("}]");
//			jsons.push_back(data);
//			/*uid = "";
//			Object params[] = new Object[15];
//			params[0] = code;
//			params[1] = uid;
//			params[2] = pmpcCode;
//			params[3] = goodsCode;
//			params[4] = goodsName;
//			params[5] = unitCode;
//			params[6] = companyCode;
//			params[7] = bpNo;
//			params[8] = spec;
//			params[9] = teRe;
//			params[10] = state;
//			params[11] = user;
//			params[12] = time;
//			params[13] = condition;
//			params[14] = "";
//			drequests.add(obj.toString());
//			self_lists.add(new SelfMPartBean(code, params, rev, spec, m_code1));*/
//		}
//	}
//}
//
//int ApplyMatnr(void* returnValue)
//{
//	prds2.clear();
//	prds.clear();
//	int ifail = ITK_ok;
//	//SQLSERVER链接数据库
//	if (open("PLMUser", "PLMUser", "BDP2020", "10.128.20.35")) {
//		printf("链接SQLSERVER失败\n");
//	}
//	else {
//		printf("链接SQLSERVER成功\n");
//	}
//	{
//		char selectRecord[200], selectRecord1[200];
//		sprintf(selectRecord, Sql1.c_str(), m_code1.c_str());
//		printf("执行查询 %s\n", selectRecord);
//		int outputColumn = 0, outputValueCount = 0;
//		char*** outputValue = NULL;
//		ado_QuerySQLNoInputParam(selectRecord, &outputColumn, &outputValueCount, &outputValue);
//		string pmpcPrhCode, pmpcPType, pmpcMType;
//		for (int j = 0; j < outputValueCount; j++) {
//			pmpcPrhCode = outputValue[j][0];
//			pmpcPType = outputValue[j][1];
//			pmpcMType = outputValue[j][2];
//			pmpc.m_code = m_code1;
//			pmpc.pmpcPrhCode = pmpcPrhCode;
//			pmpc.pmpcPType = pmpcPType;
//			pmpc.pmpcMType = pmpcMType;
//		}
//		sprintf(selectRecord1, Sql2.c_str(), pmpcPrhCode.c_str());
//		int outputColumn1 = 0, outputValueCount1 = 0;
//		char*** outputValue1 = NULL;
//		ado_QuerySQLNoInputParam(selectRecord1, &outputColumn1, &outputValueCount1, &outputValue1);
//		for (int j = 0; j < outputValueCount1; j++) {
//			string prdFeatureCode = outputValue1[j][3];
//			string featureName = outputValue1[j][4];
//			PRD prd;
//			prd.prdFeatureCode = prdFeatureCode;
//			prd.featureName = featureName;
//			prds.push_back(prd);
//		}
//	}
//	{
//		char selectRecord[200], selectRecord1[200];
//		sprintf(selectRecord, Sql1.c_str(), m_code2.c_str());
//		printf("执行查询 %s\n", selectRecord);
//		int outputColumn = 0, outputValueCount = 0;
//		char*** outputValue = NULL;
//		ado_QuerySQLNoInputParam(selectRecord, &outputColumn, &outputValueCount, &outputValue);
//		string pmpcPrhCode, pmpcPType, pmpcMType;
//		for (int j = 0; j < outputValueCount; j++) {
//			pmpcPrhCode = outputValue[j][0];
//			pmpcPType = outputValue[j][1];
//			pmpcMType = outputValue[j][2];
//			pmpc2.m_code = m_code2;
//			pmpc2.pmpcPrhCode = pmpcPrhCode;
//			pmpc2.pmpcPType = pmpcPType;
//			pmpc2.pmpcMType = pmpcMType;
//		}
//		sprintf(selectRecord1, Sql2.c_str(), pmpcPrhCode.c_str());
//		int outputColumn1 = 0, outputValueCount1 = 0;
//		char*** outputValue1 = NULL;
//		ado_QuerySQLNoInputParam(selectRecord1, &outputColumn1, &outputValueCount1, &outputValue1);
//		for (int j = 0; j < outputValueCount1; j++) {
//			string prdFeatureCode = outputValue1[j][3];
//			string featureName = outputValue1[j][4];
//			PRD prd;
//			prd.prdFeatureCode = prdFeatureCode;
//			prd.featureName = featureName;
//			prds2.push_back(prd);
//		}
//	}
//	printf("prds2.size()%d\n", prds2.size());
//	printf("prds1.size()%d\n", prds.size());
//	char *revUid;
//	tag_t tzRev;
//	ITKCALL(ifail = USERARG_get_string_argument(&revUid));
//	ITK__convert_uid_to_tag(revUid, &tzRev);
//	vector<tag_t> bomLineVec;
//	int bvr_count = 0, c_line_count;
//	tag_t ebom_window = NULLTAG;
//	tag_t bom_line = NULLTAG;
//	tag_t item_tag = NULLTAG, *c_line_tags;
//	(BOM_create_window(&ebom_window));
//	tag_t* bvr_list = NULL, owning_group, owning_user;
//	char *grpId,*user_id;
//	AOM_ask_value_tag(tzRev, "owning_user", &owning_user);
//	AOM_ask_value_tag(tzRev,"owning_group",&owning_group);
//	AOM_ask_value_string(owning_group,"name",&grpId);
//	AOM_ask_value_string(owning_user, "user_id", &user_id);
//	
//	groupId = grpId;
//	(ITEM_rev_list_bom_view_revs(tzRev, &bvr_count, &bvr_list));
//
//	ITKCALL(BOM_set_window_top_line_bvr(ebom_window, bvr_list[0], &bom_line)); //顶层bom获取
//	bomLineVec.push_back(bom_line);
//	listBom(bom_line, bomLineVec);
//	string error;
//	map<tag_t, vector<string>> general_maps;
//	for (int i = 0; i < bomLineVec.size(); i++) {
//		getRevs(bomLineVec[i], error, general_maps);
//	}
//
//	close();
//	time_t now;
//	struct tm *p;
//	time(&now);
//	p = localtime(&now);
//	char buffer[80];
//	sprintf_s(buffer, "%04d%02d%02d %02d:%02d:%02d", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
//	string now1 = buffer;
//
//	int url_num = 0;
//	char ** url_vals = NULL;
//	PREF_ask_char_values("database_tc", &url_num, &url_vals);
//	string url = url_vals[0];
//	url.append("/").append(url_vals[2]);
//
//	printf("url ==> %s \n", url.c_str());
//	if (ConnServer(url_vals[3], url_vals[4], (char *)url.c_str()) == -1)
//	{
//		printf("提示:中间数据表访问失败\n");
//		ifail = 1;
//		return ifail;
//	}
//	vector<string> jsons;
//	send1(general_maps, now1, user_id, jsons);
//
//	DisConnServer();
//	BOM_close_window(ebom_window);
//	
//	//ORACLE数据库插入
//}	
//
//
//
//
//
//
