#pragma warning (disable: 4996) #pragma warning (disable: 4819) #pragma warning (disable: 4995) #include #include "mdbks_register.h" #include #include #include #include #include #include #include #include "ps/ps.h"; #include "ps/vrule.h" #include "sstream" #include #include "epm/epm.h" #include "sa/sa.h" #include "libxl.h" #include #include "epm/signoff.h" #include #include #include #include #include "ae/dataset.h" #include #include #include #include #include #include #include #include #include #include #include #include #include "tchar.h" #include #include "ocilib.h" #include #include #include #include using namespace std; //#pragma comment(lib, "WS2_32.lib") #pragma comment(lib, "WSOCK32.lib") extern "C" int POM_AM__set_application_bypass(logical bypass); // 比较两个由 char* 表示的纯数字字符串的大小 // 返回值: // 1 : str1 > str2 // 0 : str1 == str2 // -1 : str1 < str2 int compareNumericStrings(const char* str1, const char* str2) { // 处理空指针 if (!str1 || !str2) { std::cerr << "Error: Null pointer provided." << std::endl; return 0; // 或者抛出异常 } int len1 = strlen(str1); int len2 = strlen(str2); // 跳过前导零,找到第一个非零字符的位置 int i = 0, j = 0; while (i < len1 && str1[i] == '0') i++; while (j < len2 && str2[j] == '0') j++; // 计算有效数字长度 int effectiveLen1 = len1 - i; int effectiveLen2 = len2 - j; // 首先比较有效数字的长度 if (effectiveLen1 > effectiveLen2) return 1; if (effectiveLen1 < effectiveLen2) return -1; // 长度相同,逐位比较 while (i < len1 && j < len2) { if (str1[i] > str2[j]) return 1; if (str1[i] < str2[j]) return -1; i++; j++; } // 所有位都相等 return 0; } string getIP() { WSADATA WSAData; char hostName[256]; if (!WSAStartup(MAKEWORD(2, 0), &WSAData)) { if (!gethostname(hostName, sizeof(hostName))) { hostent* host = gethostbyname(hostName); if (host != NULL) { return inet_ntoa(*(struct in_addr*)*host->h_addr_list); } } } return "Get IP failed."; } // 判断字符串str是否以suffix结尾 int endsWith(const char* str, const char* suffix) { size_t lenStr = strlen(str); size_t lenSuffix = strlen(suffix); // 如果suffix比str还要长,肯定不匹配 if (lenSuffix > lenStr) return 0; // 检查str的末尾是否与suffix完全一致 return strncmp(str + lenStr - lenSuffix, suffix, lenSuffix) == 0; } int JK_Send_SRM(EPM_action_message_t msg) { char* log_file = NULL; printf("创建日志文件\n"); //char* TO_SRM = (char*)malloc(sizeof("TO_SRM")); char tc_log_file_name[128] = ""; strcpy(tc_log_file_name, "TO_SRM"); CreateLogFile(tc_log_file_name, &log_file); WriteLog("*******************************************************************************\n"); WriteLog("* JK_Send_SRM is starting *\n"); WriteLog("*******************************************************************************\n"); int ifail = ITK_ok, att_cnt = 0; tag_t task_tag = NULLTAG, rootTask_tag = NULLTAG, * attachments = NULL; string ip = getIP(); WriteLog("ip=================================================%s\n", getIP().c_str()); //获取首选项路径 char* prePath = NULL; char* urlPath = NULL; int c_sql_value_count = 0; char** option_values; ITKCALL(PREF_ask_char_value("JK8_To_SRM_Filepath", 0, &prePath)); ITKCALL(PREF_ask_char_values("JK8_To_SRM_Connet_DB_Info", &c_sql_value_count, &option_values)); if (strcmp(getIP().c_str(), "10.200.2.42") == 0) { ITKCALL(PREF_ask_char_value("JK8_To_SRM_Filepath", 2, &urlPath)); } else { ITKCALL(PREF_ask_char_value("JK8_To_SRM_Filepath", 1, &urlPath)); } WriteLog("获取首选项完成\n"); string errorMessage = ""; //获取当前触发的任务 task_tag = msg.task; //获取根流程节点 ifail = EPM_ask_root_task(task_tag, &rootTask_tag); //获取目标引用对象 ifail = EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments); WriteLog("流程目标个数:%d\n", att_cnt); for (int i = 0; i < att_cnt; i++) { tag_t tagt = NULLTAG; tagt = attachments[i]; char* itemId = NULL; char* revision = NULL; char* ChangeNo = NULL; char* MaterialDesc = NULL; char* EcrNo = NULL; char* type = NULL; ITKCALL(AOM_ask_value_string(tagt, "object_type", &type)); WriteLog("类型===%s\n", type); if (strcmp(type, "JK8PartDraw_CADRevision") == 0) { //获取当前时间 string newTime = ""; time_t curtime2; time(&curtime2); tm* nowtime = localtime(&curtime2); // 输出tm结构的年月日 cout << "年: " << 1900 + nowtime->tm_year << endl; cout << "月: " << 1 + nowtime->tm_mon << endl; cout << "日: " << nowtime->tm_mday << endl; newTime.append(std::to_string(1900 + nowtime->tm_year)).append("-").append(std::to_string(1 + nowtime->tm_mon)).append("-").append(std::to_string(nowtime->tm_mday)).append(" ").append(std::to_string(nowtime->tm_hour)).append(":").append(std::to_string(nowtime->tm_min)).append(":").append(std::to_string(nowtime->tm_sec)); WriteLog("newTime===%s\n", newTime.c_str()); ITKCALL(AOM_ask_value_string(tagt, "item_id", &itemId)); WriteLog("itemId===%s\n", itemId); printf("0000000000000000\n"); if (strstr(itemId, "DWG")) { //获取图纸属性 // 获取图纸的文件路径 //创建id的文件夹 string tzFinalPath = ""; string bgFinalPath = ""; string tzPath = ""; string tzUrlPath = ""; string mdTz = "md "; tzPath.append(prePath).append("/").append(itemId); tzUrlPath.append(urlPath).append("/").append(itemId); printf("tzPath===%s\n", tzPath.c_str()); //创建id的文件夹 //if (_access(tzPath.c_str(), 0) != 0) {//判断ID的文件夹否存在 //创建文件夹 system(mdTz.append("\"").append(tzPath).append("\"").c_str()); // } //获取版本下的数据集 int dataset_num = 0; tag_t* dataset_tags = NULL; char* origin_file_name = NULL; tag_t* ref_object = NULL; int n_found = 0; char* file_type = NULL; ITKCALL(AOM_ask_value_tags(tagt, "IMAN_specification", &dataset_num, &dataset_tags)); for (int k = 0; k < dataset_num; k++) { string exportName = ""; ITKCALL(AOM_ask_value_string(dataset_tags[k], "object_type", &file_type)); if (strstr(file_type, "JK8_AutoCAD")) { ITKCALL(AE_ask_dataset_named_refs(dataset_tags[k], &n_found, &ref_object)); if (n_found > 0) { int timeS = 0; int timeF = 0; tag_t ref_objectF = NULLTAG; string origin_file_nameStr; for (int x = 0; x < n_found; x++) { ITKCALL(AOM_ask_value_string(ref_object[x], "original_file_name", &origin_file_name)); ITKCALL(AOM_ask_value_int(ref_object[x], "time_last_modified", &timeS)); printf("current_name========%s\n", origin_file_name); printf("timeS========%d\n", timeS); if (endsWith(origin_file_name, ".dwg")) { printf("%s 结尾是 .dwg\n", origin_file_name); if (timeF == 0) { origin_file_nameStr = origin_file_name; ref_objectF = ref_object[x]; timeF = timeS; printf("timeF========%d\n", timeF); } else { if (timeS > timeF) { origin_file_nameStr = origin_file_name; ref_objectF = ref_object[x]; timeF = timeS; printf("timeF2========%d\n", timeF); } } } } if (ref_objectF != NULLTAG) { // 使用 remove() 函数删除文件 if (remove(exportName.append(tzPath).append("/").append(origin_file_nameStr).c_str()) == 0) { printf("---------------D。\n"); } else { printf("FFFFFFFFFFFFFFFF"); } ITKCALL(IMF_export_file(ref_objectF, exportName.c_str())); printf("exportName========%s\n", exportName.c_str()); tzFinalPath.append(tzUrlPath).append("/").append(origin_file_nameStr).append(";"); } } } } DOFREE(origin_file_name); DOFREE(file_type); //获取版本 ITKCALL(AOM_ask_value_string(tagt, "item_revision_id", &revision)); std::string str(revision); // 找到第一个非零字符的位置 size_t pos = str.find_first_not_of('0'); if (pos != std::string::npos) { // 如果找到了非零字符,从该位置开始截取字符串 str = str.substr(pos); } else { // 如果全是零,设置为空字符串 str.clear(); } //versionStr.erase(versionStr.begin()); //变更单号 int bgdh_num = 0; tag_t* bgdh_tags = NULL; ITKCALL(AOM_ask_value_tags(tagt, "JK8CADRelation", &bgdh_num, &bgdh_tags)); if (bgdh_num > 0) { ITKCALL(AOM_ask_value_string(bgdh_tags[0], "item_id", &EcrNo)); string bgPath = ""; string bgUrlPath = ""; string mdBg = "md "; string mdBgBg = "md "; bgPath.append(prePath).append("/").append(itemId); bgUrlPath.append(urlPath).append("/").append(itemId); //创建id的文件夹 //if (_access(bgPath.c_str(), 0) != 0) {//判断ID的文件夹否存在 //创建文件夹 system(mdBg.append("\"").append(bgPath).append("\"").c_str()); //} bgPath.append("/").append("变更通知单"); bgUrlPath.append("/").append("变更通知单"); system(mdBgBg.append("\"").append(bgPath).append("\"").c_str()); //变更单文件路径 //获取版本下的数据集 int dataset_num = 0; tag_t* dataset_tags = NULL; char* origin_file_name = NULL; tag_t* ref_object = NULL; int n_found = 0; char* file_type = NULL; ITKCALL(AOM_ask_value_tags(bgdh_tags[0], "IMAN_specification", &dataset_num, &dataset_tags)); for (int k = 0; k < dataset_num; k++) { string exportName = ""; ITKCALL(AOM_ask_value_string(dataset_tags[k], "object_type", &file_type)); printf("file_type===%s\n", file_type); if (strstr(file_type, "MSWordX") || strstr(file_type, "MS WordX")) { ITKCALL(AE_ask_dataset_named_refs(dataset_tags[k], &n_found, &ref_object)); if (n_found > 0) { ITKCALL(AOM_ask_value_string(ref_object[0], "original_file_name", &origin_file_name)); printf("current_name========%s\n", origin_file_name); // 使用 remove() 函数删除文件 if (remove(exportName.append(bgPath).append("/").append(origin_file_name).c_str()) == 0) { printf("---------------D。\n"); } else { printf("FFFFFFFFFFFFFFFF"); } ITKCALL(IMF_export_file(ref_object[0], exportName.c_str())); printf("exportName========%s\n", exportName.c_str()); bgFinalPath.append(bgUrlPath).append("/").append(origin_file_name).append(";"); } } } DOFREE(origin_file_name); DOFREE(file_type); } //获取文件路径 //获取物料 char* wlItenId = ""; int material_num = 0; tag_t* material_tags = NULL; ITKCALL(AOM_ask_value_tags(tagt, "representation_for", &material_num, &material_tags)); WriteLog("representation_for下对象个数%d\n", material_num); for (int j = 0; j < material_num; j++) {//一个物料一个数据 ITKCALL(AOM_ask_value_string(material_tags[j], "object_desc", &MaterialDesc)); ITKCALL(AOM_ask_value_string(material_tags[j], "item_id", &wlItenId)); string sql = "select * from CHINT_CHECK_TITLE_TEMPLATE where drawingno = '%s' "; if (ConnServer(option_values[0], option_values[1], option_values[2]))//"tc11","infodba","//172.16.50.40/tc11" "TC12","infodba","172.16.68.13/tc1" { WriteLog("提示:中间数据表访问失败\n"); EMH_store_error_s1(EMH_severity_user_error, EMH_USER_error_base, "中间数据表访问失败!\n"); //错误弹窗 return ifail; } else { string selectSql = "select * from TC_TO_SRM where MaterialCode = '%s' and ChangeNo = '%s' and DesignID = '%s'"; char selectRecord[400]; sprintf(selectRecord, selectSql.c_str(), wlItenId, str.c_str(), itemId); printf("selectSql ===> %s\n", selectRecord); int outputColumn = 0, outputValueCount = 0; char*** outputValue = NULL; QuerySQLNoInputParam(selectRecord, &outputColumn, &outputValueCount, &outputValue); printf("outputValueCount===%d\n", outputValueCount); if (outputValueCount > 0) { char sql[1024] = "\0"; sprintf(sql, "update TC_TO_SRM set MaterialDesc = '%s',FilePath = '%s',EcrNo = '%s',EcrFile = '%s',SendTime = TO_DATE('%s', 'YYYY-MM-DD HH24:MI:SS') where MaterialCode = '%s' and ChangeNo = '%s' and DesignID = '%s'" , MaterialDesc, tzFinalPath.c_str(), EcrNo, bgFinalPath.c_str(), newTime.c_str(), wlItenId, str.c_str(), itemId); WriteLog("提示:sql==%s\n", sql); if (ExecuteSQLNoInputParam(sql) == -1) { WriteLog("提示:数据更新 失败, %s \n", sql); EMH_store_error_s1(EMH_severity_user_error, EMH_USER_error_base, "数据库更新失败!\n"); //错误弹窗 return 0; } else { ExecuteSQLNoInputParam("commit"); WriteLog("id:%s更新完成!\n", itemId); } } else { char sql[1024] = "\0"; sprintf(sql, "insert into TC_TO_SRM(MaterialCode,ChangeNo,MaterialDesc,DesignID,FilePath,EcrNo,EcrFile,SendTime) values('%s','%s','%s','%s','%s','%s','%s',TO_DATE('%s', 'YYYY-MM-DD HH24:MI:SS'))", wlItenId, str.c_str(), MaterialDesc, itemId, tzFinalPath.c_str(), EcrNo, bgFinalPath.c_str(), newTime.c_str()); WriteLog("提示:sql==%s\n", sql); if (ExecuteSQLNoInputParam(sql) == -1) { WriteLog("提示:数据插入 失败, %s \n", sql); EMH_store_error_s1(EMH_severity_user_error, EMH_USER_error_base, "数据库插入失败!\n"); //错误弹窗 return 0; } else { ExecuteSQLNoInputParam("commit"); WriteLog("id:%s插入完成!\n",itemId); } } } } DOFREE(wlItenId); } } WriteLog("DOFREE start\n"); DOFREE(itemId); DOFREE(revision); DOFREE(ChangeNo); DOFREE(MaterialDesc); DOFREE(EcrNo); DOFREE(type); WriteLog("DOFREE end\n"); } WriteLog("JK_Send_SRM正常退出1!\n"); WriteLog("*******************************************************************************\n"); WriteLog("* JK_Send_SRM is ending *\n"); WriteLog("*******************************************************************************\n"); CloseLog(); return 0; }