#pragma warning (disable: 4996) #pragma warning (disable: 4819) #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "tc_util.h" #include "tc_log.h" #include #include #include #include "string_utils.h" #include "tinyxml.h" #include "ado.h" #include #include #include "k_util.h" #include "curl_utils.h" #include #include #include using namespace std; #define GUID_LEN 64 struct CHILD { tag_t line; tag_t rev; tag_t item; string clone_id; }; struct FlowBean { vector flowList; tag_t flow_split = NULLTAG; tag_t flow_combine = NULLTAG; tag_t flow_end = NULLTAG; char* BEZFL; // 参考顺序 string PLNFL = ""; // 序列 boolean isMain = true; boolean isOther = false; vector flow_combine_list; }; struct FlowInfo { string pre_id; string pre_rev_id; string suc_id; string suc_rev_id; }; struct MaxFlowInfo { tag_t start_line; vector all_line; }; extern "C" int POM_AM__set_application_bypass(logical bypass); string getGuid() { char buffer[GUID_LEN] = { 0 }; GUID guid; if (CoCreateGuid(&guid)) { return "ERROR"; } _snprintf(buffer, sizeof(buffer), "%08X-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); return buffer; } vector getFlowStartsYH(int num, tag_t* c_line_tags) { vector starts; for (int i = 0; i < num; i++) { tag_t gxLine = c_line_tags[i], * successors, * Mfg0predecessors; int sucCnt = 0, preCnt = 0; ITKCALL(AOM_ask_value_tags(gxLine, "Mfg0successors", &sucCnt, &successors)); ITKCALL(AOM_ask_value_tags(gxLine, "Mfg0predecessors", &preCnt, &Mfg0predecessors)); if (preCnt == 0 && sucCnt > 0) { starts.push_back(gxLine); } } return starts; } MaxFlowInfo copy(MaxFlowInfo old_info) { MaxFlowInfo new_info; new_info.start_line = old_info.start_line; for (int num = 0; num < old_info.all_line.size(); num++) { new_info.all_line.push_back(old_info.all_line[num]); } return new_info; } bool UploadUsingSystemFTP(string server, string username, string password, string local_file, string rev_type, string dataset_type, string idAndRev, string remote_file) { //std::string server = "192.168.120.92"; //std::string username = "ftp1"; //std::string password = "Jd@tc00"; // 需要实际密码 //std::string local_file = "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\2\\WD00000644_ceshiwen.docx"; //std::string remote_dir = "/DocumentRevision/MS WordX/WD00000644-10"; //std::string remote_file = "WD00000644_ceshiwen.docx"; // 创建临时脚本文件 std::string script_content = "open " + server + "\n" "user " + username + "\n" "" + password + "\n" "binary\n" "mkdir \"" + rev_type + "\"\n" "cd \"" + rev_type + "\"\n" "mkdir \"" + dataset_type + "\"\n" "cd \"" + dataset_type + "\"\n" "mkdir \"" + idAndRev + "\"\n" "cd \"" + idAndRev + "\"\n" //"cd \"" + remote_dir + "\"\n" "put \"" + local_file + "\" \"" + remote_file + "\"\n" "quit\n"; // 写入脚本文件到临时目录 char temp_path[MAX_PATH]; GetTempPathA(MAX_PATH, temp_path); std::string script_file = std::string(temp_path) + "ftp_script.txt"; std::ofstream script(script_file); if (!script) { WriteLog("无法创建脚本文件\n"); return false; } script << script_content; script.close(); WriteLog("创建脚本文件: %s\n", script_file.c_str()); // 执行 ftp 命令 std::string command = "ftp -n -s:\"" + script_file + "\""; WriteLog("执行命令: %s\n", command.c_str()); // 创建进程执行命令 STARTUPINFOA si = { sizeof(si) }; PROCESS_INFORMATION pi; si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; // 隐藏窗口 if (CreateProcessA(NULL, (LPSTR)command.c_str(), NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) { // 等待命令完成(最多60秒) WaitForSingleObject(pi.hProcess, 60000); DWORD exit_code; GetExitCodeProcess(pi.hProcess, &exit_code); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); // 删除临时脚本文件 DeleteFileA(script_file.c_str()); if (exit_code == 0) { WriteLog("FTP 上传成功!\n"); return true; } else { WriteLog("FTP 上传失败,退出代码: %d\n", exit_code); return false; } } else { DWORD err = GetLastError(); WriteLog("无法启动 FTP 进程,错误: %d\n", err); DeleteFileA(script_file.c_str()); return false; } } void readGXFlow(tag_t gxLine, vector& all_line_info, map& line_info, MaxFlowInfo max_info) { FlowInfo flow_info; tag_t* successors, * Mfg0predecessors; int sucCnt = 0, preCnt = 0; char* gx_clone_id = NULL; ITKCALL(AOM_ask_value_tags(gxLine, "Mfg0successors", &sucCnt, &successors)); ITKCALL(AOM_ask_value_tags(gxLine, "Mfg0predecessors", &preCnt, &Mfg0predecessors)); ITKCALL(AOM_ask_value_string(gxLine, "bl_clone_stable_occurrence_id", &gx_clone_id)); string pre_id = ""; string pre_rev_id = ""; string suc_id = ""; string suc_rev_id = ""; if (preCnt > 0) { for (int g = 0; g < preCnt; g++) { char* pre_item_id = NULL, * pre_revision_id = NULL; tag_t pre_gxRev; ITKCALL(AOM_ask_value_tag(Mfg0predecessors[g], "bl_line_object", &pre_gxRev)); ITKCALL(AOM_ask_value_string(pre_gxRev, "item_id", &pre_item_id)); ITKCALL(AOM_ask_value_string(pre_gxRev, "item_revision_id", &pre_revision_id)); if (g > 0) { pre_id.append(";"); pre_rev_id.append(";"); } pre_id.append(string(pre_item_id)); pre_rev_id.append(string(pre_revision_id)); DOFREE(pre_item_id); DOFREE(pre_revision_id); } } flow_info.pre_id = pre_id; flow_info.pre_rev_id = pre_rev_id; if (sucCnt == 0) { max_info.all_line.push_back(gxLine); flow_info.suc_id = suc_id; flow_info.suc_rev_id = suc_rev_id; all_line_info.push_back(max_info); line_info[string(gx_clone_id)] = flow_info; return; } if (sucCnt > 0) { for (int g = 0; g < sucCnt; g++) { char* suc_item_id = NULL, * suc_revision_id = NULL; tag_t suc_gxRev; ITKCALL(AOM_ask_value_tag(successors[g], "bl_line_object", &suc_gxRev)); ITKCALL(AOM_ask_value_string(suc_gxRev, "item_id", &suc_item_id)); ITKCALL(AOM_ask_value_string(suc_gxRev, "item_revision_id", &suc_revision_id)); if (g > 0) { suc_id.append(";"); suc_rev_id.append(";"); } suc_id.append(string(suc_item_id)); suc_rev_id.append(string(suc_revision_id)); DOFREE(suc_item_id); DOFREE(suc_revision_id); } } flow_info.suc_id = suc_id; flow_info.suc_rev_id = suc_rev_id; line_info[string(gx_clone_id)] = flow_info; if (sucCnt > 0) { max_info.all_line.push_back(gxLine); for (int i = 0; i < sucCnt; i++) { // 后驱工序存在多个新增多条线 MaxFlowInfo curr_max_info; curr_max_info = copy(max_info); readGXFlow(successors[i], all_line_info, line_info, curr_max_info); } } DOFREE(gx_clone_id); DOFREE(successors); DOFREE(Mfg0predecessors); } void getMainProcess(tag_t* c_line_tags, int c_line_count, map& main_flow, map& line_info) { int maxLen = 0; vector all_line_info; if (c_line_count == 0) { return; } vector startLines = getFlowStartsYH(c_line_count, c_line_tags); if (startLines.size() > 0) { char* itemID; ITKCALL(AOM_ask_value_string(startLines[0], "item_id", &itemID)); WriteLog("找到工序流起始点 :%s\n", itemID); DOFREE(itemID); } for (int i = 0; i < startLines.size(); i++) { MaxFlowInfo max_flow_info; max_flow_info.start_line = startLines[i]; readGXFlow(startLines[i], all_line_info, line_info, max_flow_info); } auto it = std::max_element(all_line_info.begin(), all_line_info.end(), [](const MaxFlowInfo& a, const MaxFlowInfo& b) { return a.all_line.size() <= b.all_line.size(); // 注意这里用 <= // 当 a.size <= b.size 时,认为 a 不大于 b // 所以当遇到相等的时,不会替换当前的最大值 }); if (it != all_line_info.end()) { WriteLog("主流程的长度为>%d,路线如下:\n", it->all_line.size()); for (int i = 0; i < it->all_line.size(); i++) { char* gx_clone_id = NULL; char* item_id = NULL; ITKCALL(AOM_ask_value_string(it->all_line[i], "bl_clone_stable_occurrence_id", &gx_clone_id)); ITKCALL(AOM_ask_value_string(it->all_line[i], "bl_item_item_id", &item_id)); WriteLog("->%s", item_id); main_flow[gx_clone_id] = gx_clone_id; DOFREE(gx_clone_id); DOFREE(item_id); } WriteLog("\n"); } } // 存在问题,工序明显表的主键未取到,孙子节点获取到的是子节点的对象需要处理 string readBOPXML(map, vector>>& xmlMap, string xmlPath) { time_t currentTime; struct tm* timeInfo; char timeString[80]; // 获取当前时间 time(¤tTime); // 将时间转换为本地时间 timeInfo = localtime(¤tTime); TiXmlDocument* pDoc = new TiXmlDocument(); pDoc->LoadFile(xmlPath.c_str()); //pDoc->Print(); //char labelName[50]=""; //获取根节点 TiXmlElement* pRoot = pDoc->RootElement(); string rootName = pRoot->Value(); TiXmlElement* itemElement = pRoot->FirstChildElement("BOMCONTENTS");// string t_Item_info = rootName;// string itemLable = itemElement->Value();//中间表表名 //循环遍历根节点下的兄弟节点 char type[50] = ""; char sessionId[50] = ""; char transNowTime[50] = ""; char transStatus[50] = ""; char itemId[50] = ""; char itemRev[50] = ""; char itemName[50] = ""; char itemRelease[50] = ""; map, vector> propertyMap;//字段名集合,值的集合 vector nameVec; vector valueVec; TiXmlElement* pChild = itemElement->FirstChildElement(); const char* attribute_value = NULL; if (pChild != NULL) { string childLabnelName = pChild->Value(); attribute_value = pChild->Attribute("val"); if (attribute_value == NULL) { strcpy(sessionId, " "); } else { strcpy(sessionId, attribute_value); } string tempValue = sessionId; nameVec.push_back(childLabnelName); valueVec.push_back(tempValue); } pChild = pChild->NextSiblingElement(); while (true) { if (pChild != NULL) { string childLabnelName = pChild->Value(); attribute_value = pChild->Attribute("val"); if (attribute_value == NULL) { strcpy(sessionId, " "); } else { strcpy(sessionId, attribute_value); } string tempValue = sessionId; //propertyMap[childLabnelName]=tempValue; if (strcmp("TRANSNO", childLabnelName.c_str()) == 0) { //转换时间, 将时间按照指定格式转换为字符串 strftime(timeString, sizeof(timeString), sessionId, timeInfo); // 打印转换后的时间字符串 tempValue = timeString; } else if (strcmp("SONPZLIST", childLabnelName.c_str()) == 0) { } else if (strcmp("SUNPZLIST", childLabnelName.c_str()) == 0) { } if (strcmp("SONPZLIST", childLabnelName.c_str()) != 0 && strcmp("SUNPZLIST", childLabnelName.c_str()) != 0) { nameVec.push_back(childLabnelName);; valueVec.push_back(tempValue); } pChild = pChild->NextSiblingElement(); if (pChild == NULL) { break; } } } propertyMap[nameVec] = valueVec; xmlMap["父"] = propertyMap; pChild = itemElement->FirstChildElement("SONPZLIST"); vector childNameVec; vector childValueVec; map, vector> childPropertyMap;//字段名集合,值的集合 TiXmlElement* sonChild = pChild; TiXmlElement* cChild = sonChild->FirstChildElement(); if (cChild != NULL) { string LabnelName = cChild->Value(); attribute_value = cChild->Attribute("val"); strcpy(sessionId, attribute_value); // 将 str 复制给 copy string tempValue = sessionId; childNameVec.push_back(LabnelName); childValueVec.push_back(tempValue); } cChild = cChild->NextSiblingElement(); while (true) { if (cChild != NULL) { string LabnelName = cChild->Value(); attribute_value = cChild->Attribute("val"); if (attribute_value == NULL) { strcpy(sessionId, " "); // 将 str 复制给 copy } else { strcpy(sessionId, attribute_value); // 将 str 复制给 copy } string tempValue = sessionId; childNameVec.push_back(LabnelName); childValueVec.push_back(tempValue); } cChild = cChild->NextSiblingElement(); if (cChild == NULL) { break; } } childPropertyMap[childNameVec] = childValueVec; xmlMap["子"] = childPropertyMap; pChild = itemElement->FirstChildElement("SUNPZLIST"); if (pChild != NULL) { vector childLevel2NameVec; vector childLevel2ValueVec; map, vector> childLevel2PropertyMap;//字段名集合,值的集合 TiXmlElement* sunChild = pChild; TiXmlElement* sChild = sunChild->FirstChildElement(); if (sChild != NULL) { string LabnelName = sChild->Value(); attribute_value = sChild->Attribute("val"); strcpy(sessionId, attribute_value); // 将 str 复制给 copy string tempValue = sessionId; childLevel2NameVec.push_back(LabnelName); childLevel2ValueVec.push_back(tempValue); } sChild = sChild->NextSiblingElement(); while (true) { if (sChild != NULL) { string LabnelName = sChild->Value(); attribute_value = sChild->Attribute("val"); if (attribute_value == NULL) { strcpy(sessionId, " "); // 将 str 复制给 copy } else { strcpy(sessionId, attribute_value); // 将 str 复制给 copy } string tempValue = sessionId; childLevel2NameVec.push_back(LabnelName); childLevel2ValueVec.push_back(tempValue); } sChild = sChild->NextSiblingElement(); if (sChild == NULL) { break; } } childLevel2PropertyMap[childLevel2NameVec] = childLevel2ValueVec; xmlMap["孙"] = childLevel2PropertyMap; } delete pDoc;//应该是必要的 return t_Item_info; } string loadXml(string xmlUid, map, vector>>& xmlMap) { tag_t bomInfoXml = NULL; ITK__convert_uid_to_tag(xmlUid.c_str(), &bomInfoXml); //获取文件 char* temp_dir = getenv("temp");//获得缓存路径 char output_file_xml_temp[SS_MAXPATHLEN] = ""; strcpy(output_file_xml_temp, temp_dir); strcat(output_file_xml_temp, "\\"); strcat(output_file_xml_temp, xmlUid.c_str()); strcat(output_file_xml_temp, ".xml"); if (access(output_file_xml_temp, 0) == 0) {//存在 if (remove(output_file_xml_temp) == 0) { cout << "exist" << output_file_xml_temp << "delete" << endl; } } POM_AM__set_application_bypass(true); ITKCALL(AE_export_named_ref(bomInfoXml, "XMLRendering", output_file_xml_temp)); POM_AM__set_application_bypass(false); string path = output_file_xml_temp; string tableName = readBOPXML(xmlMap, path); return tableName; } void loadBom(tag_t top_bom_line_tag, map& child_level1, map>& level1_level2, map& child_level2, map> &gx_gb_bom, map>& gx_gb_zy, map& main_flow, map& line_info) { int child_count = 0; tag_t* child_tags = NULLTAG; //ITKCALL(BOM_line_ask_child_lines(top_bom_line_tag, &child_count, &child_tags)); //ITKCALL(ME_line_ask_child_lines(top_bom_line_tag, &child_count, &child_tags)); ITKCALL(AOM_ask_value_tags(top_bom_line_tag, "Mfg0sub_elements", &child_count, &child_tags)); // 遍历工艺下工序层级 WriteLog("工序个数为:%d\n", child_count); //loadPret(child_tags, child_count); getMainProcess(child_tags, child_count, main_flow, line_info); for (int x = 0; x < child_count; x++) { char* gx_clone_id = NULL; CHILD child; tag_t gx_rev = NULLTAG, gx_item = NULLTAG, * gx_child_tags = NULLTAG, gxgb = NULLTAG, * child_gbs = NULLTAG; int gx_child_count = 0, gb_child_count = 0; vector child_vec; vector gb_vec; ITKCALL(AOM_ask_value_tag(child_tags[x], "bl_line_object", &gx_rev)); ITKCALL(AOM_ask_value_string(child_tags[x], "bl_clone_stable_occurrence_id", &gx_clone_id)); ITEM_ask_item_of_rev(gx_rev, &gx_item); string gx_key = string(gx_clone_id); child.item = gx_item; child.line = child_tags[x]; child.rev = gx_rev; child.clone_id = gx_key; child_level1[gx_key] = child; // 遍历工工序下的工艺资源及文件 ITKCALL(BOM_line_ask_child_lines(child_tags[x], &gx_child_count, &gx_child_tags)); WriteLog("工序下级个数为:%d\n", gx_child_count); //ITKCALL(AOM_ask_value_tags(child_tags[x], "Mfg0sub_elements", &gx_child_count, &gx_child_tags)); for (int y = 0; y < gx_child_count; y++) { char* zy_clone_id = NULL; CHILD gxChild; tag_t zy_rev = NULLTAG, zy_Item = NULLTAG; ITKCALL(AOM_ask_value_tag(gx_child_tags[y], "bl_line_object", &zy_rev)); ITKCALL(AOM_ask_value_string(gx_child_tags[y], "bl_clone_stable_occurrence_id", &zy_clone_id)); string zy_key = string(zy_clone_id); ITEM_ask_item_of_rev(zy_rev, &zy_Item); gxChild.item = zy_Item; gxChild.line = gx_child_tags[y]; gxChild.rev = zy_rev; gxChild.clone_id = zy_key; child_level2[zy_key] = gxChild; child_vec.push_back(zy_key); DOFREE(zy_clone_id); } level1_level2[gx_key] = child_vec; // 遍历工工序下的工步 ITKCALL(AOM_ask_value_tag(child_tags[x], "bl_me_activity_lines", &gxgb)); ITKCALL(AOM_ask_value_tags(gxgb, "me_cl_child_lines", &gb_child_count, &child_gbs)); WriteLog("工步下级数量:%d\n", gb_child_count); if (gb_child_count > 0) { for (int z = 0; z < gb_child_count; z++) { char* puid = NULL; CHILD gbChild; tag_t gb = NULLTAG, * gb_zys = NULLTAG; int tool_cnt = 0; vector gbzy_vec; ITKCALL(AOM_ask_value_tag(child_gbs[z], "al_object", &gb)); ITK__convert_tag_to_uid(gb, &puid); string key = string(gx_clone_id) + string(puid); ITKCALL(AOM_ask_value_tags(child_gbs[z], "al_activity_tool_bl_list", &tool_cnt, &gb_zys)); if (tool_cnt > 0) { for (int a = 0; a < tool_cnt; a++) { CHILD gbzyChild; tag_t gbzy_rev = NULLTAG, gbzy_Item = NULLTAG; ITKCALL(AOM_ask_value_tag(gb_zys[a], "bl_line_object", &gbzy_rev)); ITEM_ask_item_of_rev(gbzy_rev, &gbzy_Item); gbzyChild.rev = gbzy_rev; gbzyChild.item = gbzy_Item; gbzyChild.line = gb_zys[a]; gbzy_vec.push_back(gbzyChild); } } gbChild.item = gb; gbChild.line = child_gbs[z]; gb_vec.push_back(gbChild); gx_gb_zy[key] = gbzy_vec; DOFREE(puid); DOFREE(gb_zys); } } gx_gb_bom[gx_clone_id] = gb_vec; DOFREE(child_gbs); DOFREE(gx_clone_id); DOFREE(gx_child_tags); } DOFREE(child_tags); } // 下载数据集文件到指定地址并发送到Ftp指定位置 string downloadDataset(tag_t dataset, string ftp_ip, string port, char* type_name, string idAndRev, string username, string pwd) { tag_t spec_dataset_rev = NULLTAG, * ref_objects = NULLTAG; int ref_cnt = 0; char* dataset_type_name = NULL, * pathname = NULL, * origin_file_name = NULL; string path, dir, server; ITKCALL(AE_ask_dataset_named_refs(dataset, &ref_cnt, &ref_objects)); //ITKCALL(AOM_UIF_ask_value(dataset, "object_type", &dataset_type_name)); ITKCALL(AOM_ask_value_string(dataset, "object_type", &dataset_type_name)); for (int jy = 0; jy < ref_cnt; jy++) { ITKCALL(IMF_ask_original_file_name2(ref_objects[jy], &origin_file_name)); char temp_file[SS_MAXPATHLEN] = ""; strcpy(temp_file, getenv("TEMP")); strcat(temp_file, "\\"); strcat(temp_file, origin_file_name); ITKCALL(IMF_export_file(ref_objects[jy], temp_file)); server = server.assign(ftp_ip).append(" ").append(port); dir = dir.assign(string(type_name)).append("/").append(string(dataset_type_name)).append("/").append(idAndRev); path = path.assign("ftp://").append(ftp_ip).append(":").append(port).append("/").append(dir).append("/").append(string(origin_file_name)); WriteLog("开始传递FTP,temp_file:%s,path:%s\,username:%s\n", temp_file, path.c_str(), username.c_str()); bool result = UploadUsingSystemFTP(server, username, pwd, temp_file, type_name, dataset_type_name, idAndRev, origin_file_name); if (!result) { path = "FTP传递文件失败!"; } break; } DOFREE(pathname); DOFREE(ref_objects); DOFREE(origin_file_name); DOFREE(origin_file_name); return path; } // 工艺路线工序明细表 void insertGyGxBom(string xmlUid, bool &showError, ado ado0, tag_t gy_line, tag_t gy_item, tag_t gy_rev, map child_level1, map &gx_cloneid_key, map main_flow, map line_info) { WriteLog("记录工艺路线工序明细表数据库\n"); int ifail = 0; // string sqlStr = "insert into "; string updateStr = "update "; string selectStr = "select * from "; string selectAfterUpdateStr = "select * from "; string updateWhere = ""; // 加载工艺路线工序明显表数据 // 解析xml文件 // 创建一个XML结构并载入文件内容 map, vector>> xmlMap;//物料类型,<字段名,属性取值> string tableName = loadXml(xmlUid, xmlMap); map, vector> parentPropertyMap = xmlMap["父"];//父级 vector parentNameVec; vector parentValueVec; map, vector>::iterator rev_it2; for (rev_it2 = parentPropertyMap.begin(); rev_it2 != parentPropertyMap.end(); rev_it2++) { parentNameVec = rev_it2->first; parentValueVec = rev_it2->second; } map, vector> childPropertyMap = xmlMap["子"];//子级 vector childNameVec; vector childValueVec; map, vector>::iterator rev_it; for (rev_it = childPropertyMap.begin(); rev_it != childPropertyMap.end(); rev_it++) { childNameVec = rev_it->first; childValueVec = rev_it->second; } vector updateVec; vector selectVec; vector insertVec; vector selectAfterUpdateVec; vector insertClonIdVec; sqlStr = sqlStr.append(tableName).append("("); selectStr = selectStr.append(tableName).append(" "); selectAfterUpdateStr = selectAfterUpdateStr.append(tableName).append(" "); string valueStr = " VALUES ("; //获取父属性 string parentColumnStr = "insert into "; parentColumnStr = parentColumnStr.append(tableName).append(" ("); string parentValueStr = " values("; for (int j = 0; j < parentNameVec.size(); j++) { string columnName = parentNameVec[j]; parentColumnStr = parentColumnStr.append(columnName); if (j < parentNameVec.size() - 1) { parentColumnStr = parentColumnStr.append(","); } string propertyName = parentValueVec[j]; string tempValue = " "; string updateValue = ""; if (strcmp(columnName.c_str(), "SESSIONID") == 0) { tempValue = propertyName;//固定值 } else if (strcmp(columnName.c_str(), "TRANSNO") == 0) { tempValue = propertyName;//已处理 if (updateWhere.length() == 0) { updateWhere = updateWhere.append(" where "); updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and "); selectStr = selectStr.append(" where "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(" where "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } else { updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } } else if (strcmp(columnName.c_str(), "TRANSSTATUS") == 0) { //首次传递空值 updateValue = propertyName; updateStr = updateStr.append(tableName).append(" set ").append(columnName).append("='").append(updateValue).append("' "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(updateValue).append("' and "); } else if (strcmp(columnName.c_str(), "PPUID") == 0) { char* puid = NULL; ITK__convert_tag_to_uid(gy_rev, &puid); tempValue = puid; //selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); if (updateWhere.length() == 0) { updateWhere = updateWhere.append(" where "); updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and "); selectStr = selectStr.append(" where "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(" where "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } else { updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and "); selectStr = selectStr.append(columnName).append("='").append(puid).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(puid).append("' and "); } DOFREE(puid); } else { vector propertyVec; Split(propertyName, ".", propertyVec); if (propertyVec.size() == 2) { string propertyPosition = propertyVec[0]; tag_t propertyTag = NULL; if (strcmp("item", propertyPosition.c_str()) == 0) { propertyTag = gy_item; } else if (strcmp("rev", propertyPosition.c_str()) == 0) { propertyTag = gy_rev; } else if (strcmp("bomline", propertyPosition.c_str()) == 0) { propertyTag = gy_line; } string propertyName = propertyVec[1]; char* propertyValue = NULL; if (strcmp("puid", propertyName.c_str()) == 0) { ITK__convert_tag_to_uid(propertyTag, &propertyValue); } else { ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue)); } EMH_clear_errors(); if (ifail == 0) { tempValue = propertyValue; } else { showError = true; WriteLog("属性异常:%s\n", propertyName.c_str()); tempValue = " "; } DOFREE(propertyValue); } } parentValueStr = parentValueStr.append("'").append(tempValue).append("'"); if (j < parentNameVec.size() - 1) { parentValueStr = parentValueStr.append(","); } } map::iterator child_it; for (child_it = child_level1.begin(); child_it != child_level1.end(); child_it++) { char* occ_type = NULL; bool isContinue = false; string childColumnStr = ""; string childSelectStr = ""; string childUpdateSelectStr = ""; string childUpdateWhere = ""; string childValueStr = ""; tag_t line = child_it->second.line; tag_t item = child_it->second.item; tag_t rev = child_it->second.rev; string clone_id = child_it->second.clone_id; string primay_key = ""; FlowInfo flow_info = line_info[clone_id]; ITKCALL(ifail = AOM_ask_value_string(line, "bl_occ_type", &occ_type)); for (int j = 0; j < childNameVec.size(); j++) { string columnName = childNameVec[j]; string propertyName = childValueVec[j]; string tempValue = " "; bool isInt = false; if (strcmp(columnName.c_str(), "_bl_occ_type") == 0) { if (strcmp(propertyName.c_str(), "ALL") == 0) { continue; } else { vectortypeVec; Split(propertyName, ";", typeVec); if (hasElement(typeVec, occ_type) == 0) { continue; } else { isContinue = true; break; } } } else if (strcmp(columnName.c_str(), "CPUID") == 0) { char* puid = NULL; ITK__convert_tag_to_uid(rev, &puid); tempValue = puid; DOFREE(puid); childSelectStr = childSelectStr.append(columnName).append("='").append(tempValue).append("' "); childUpdateSelectStr = childUpdateSelectStr.append(columnName).append("='").append(tempValue).append("' "); childUpdateWhere = childUpdateWhere.append(columnName).append("='").append(tempValue).append("'"); } else if (strcmp(columnName.c_str(), "MES_PRE_BP_ID") == 0) { tempValue = flow_info.pre_id; } else if (strcmp(columnName.c_str(), "MES_PRE_BP_VERSION") == 0) { tempValue = flow_info.pre_rev_id; } else if (strcmp(columnName.c_str(), "MES_NEXT_BP_ID") == 0) { tempValue = flow_info.suc_id; } else if (strcmp(columnName.c_str(), "MES_NEXT_BP_VERSION") == 0) { tempValue = flow_info.suc_rev_id; } else if (strcmp(columnName.c_str(), "MES_CRITICAL_PATH") == 0) { isInt = true; auto it = main_flow.find(clone_id); if (it != main_flow.end()) { tempValue = "1"; } else { tempValue = "0"; } } else { vector propertyVec; Split(propertyName, ".", propertyVec); if (propertyVec.size() == 2) { string propertyPosition = propertyVec[0]; tag_t propertyTag = NULL; if (strcmp("item", propertyPosition.c_str()) == 0) { propertyTag = item; } else if (strcmp("rev", propertyPosition.c_str()) == 0) { propertyTag = rev; } else if (strcmp("bomline", propertyPosition.c_str()) == 0) { propertyTag = line; } string propertyName = propertyVec[1]; char* propertyValue = NULL; if (strcmp("puid", propertyName.c_str()) == 0) { ITK__convert_tag_to_uid(propertyTag, &propertyValue); } else { ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue)); } EMH_clear_errors(); if (ifail == 0) { tempValue = propertyValue; } else { showError = true; WriteLog("属性异常:%s\n", propertyName.c_str()); tempValue = " "; } DOFREE(propertyValue); } else if (strcmp("key", propertyName.c_str()) == 0) { primay_key = getGuid(); tempValue = primay_key; } else { tempValue = " "; } } childColumnStr = childColumnStr.append(columnName); if (j < childNameVec.size() - 1) { childColumnStr = childColumnStr.append(","); } if (isInt) { childValueStr = childValueStr.append("").append(tempValue); if (j < childNameVec.size() - 1) { childValueStr = childValueStr.append(","); } } else { childValueStr = childValueStr.append("'").append(tempValue); if (j < childNameVec.size() - 1) { childValueStr = childValueStr.append("',"); } else { childValueStr = childValueStr.append("'"); } } } if (isContinue) { continue; } string insertSql = ""; string selectSql = ""; string updateSelectSql = ""; string updateSql = ""; if (childColumnStr.size() > 0) { insertSql = insertSql.append(parentColumnStr).append(",").append(childColumnStr).append(")").append(parentValueStr).append(",").append(childValueStr).append(")"); } else { insertSql = insertSql.append(parentColumnStr).append(")").append(parentValueStr).append(")"); } selectSql = selectSql.append(selectStr).append(childSelectStr); updateSelectSql = updateSelectSql.append(selectAfterUpdateStr).append(childUpdateSelectStr); updateSql = updateSql.append(updateStr).append(updateWhere).append(childUpdateWhere); //updateStr = updateStr.append(updateWhere); insertSql = Utf8ToGbk(insertSql.c_str()); updateSql = Utf8ToGbk(updateSql.c_str()); selectSql = Utf8ToGbk(selectSql.c_str()); updateSelectSql = Utf8ToGbk(updateSelectSql.c_str()); WriteLog("工序明细插入语句:%s\n", insertSql.c_str()); //WriteLog("工序明细更新语句:%s\n", updateSql.c_str()); WriteLog("工序明细查询语句:%s\n", selectSql.c_str()); //WriteLog("工序明细更新后查询语句:%s\n", updateSelectSql.c_str()); insertVec.push_back(insertSql); updateVec.push_back(updateSql); selectVec.push_back(selectSql); selectAfterUpdateVec.push_back(updateSelectSql); insertClonIdVec.push_back(clone_id); char sendChar[512] = ""; strcpy(sendChar, insertSql.c_str()); char sendChar2[1024] = ""; strcpy(sendChar2, selectSql.c_str()); int result = ado0.ado_QuerySQLNoInputParam(sendChar2); bool resultSql = ado0.executeInsert(sendChar2, sendChar, result); gx_cloneid_key[clone_id] = primay_key; //if (!resultSql) { // WriteLog("数据库语句插入失败\n"); //} DOFREE(occ_type); } } // 工序工步关系表 void insertGxGb(string xmlUid, bool& showError, ado ado0, map child_level1, map gx_cloneid_key, map> gx_gbs_bom, map& gx_gb_key) { WriteLog("记录工序工步关系表数据库\n"); int ifail = 0; char* gx_occ_type = NULL; vector updateVec; vector selectVec; vector insertVec; vector selectAfterUpdateVec; vector insertPuidVec; // 解析xml文件 // 创建一个XML结构并载入文件内容 map, vector>> xmlMap;//物料类型,<字段名,属性取值> string tableName = loadXml(xmlUid, xmlMap); map, vector> parentPropertyMap = xmlMap["父"];//父级 vector parentNameVec; vector parentValueVec; map, vector>::iterator rev_it2; for (rev_it2 = parentPropertyMap.begin(); rev_it2 != parentPropertyMap.end(); rev_it2++) { parentNameVec = rev_it2->first; parentValueVec = rev_it2->second; } map, vector> childPropertyMap = xmlMap["子"];//子级 vector childNameVec; vector childValueVec; map, vector>::iterator rev_it; for (rev_it = childPropertyMap.begin(); rev_it != childPropertyMap.end(); rev_it++) { childNameVec = rev_it->first; childValueVec = rev_it->second; } map::iterator child_it; for (child_it = child_level1.begin(); child_it != child_level1.end(); child_it++) { bool isGxContinue = false; char* gb_occ_type = NULL; string sqlStr = "insert into "; string updateStr = "update "; string selectStr = "select * from "; string selectAfterUpdateStr = "select * from "; string updateWhere = ""; string gx_clone_id = child_it->first; tag_t gx_line = child_it->second.line; tag_t gx_item = child_it->second.item; tag_t gx_rev = child_it->second.rev; vector gbs = gx_gbs_bom[gx_clone_id]; ITKCALL(ifail = AOM_ask_value_string(gx_line, "bl_occ_type", &gx_occ_type)); sqlStr = sqlStr.append(tableName).append("("); selectStr = selectStr.append(tableName).append(" "); selectAfterUpdateStr = selectAfterUpdateStr.append(tableName).append(" "); string valueStr = " VALUES ("; //获取父属性 string parentColumnStr = "insert into "; parentColumnStr = parentColumnStr.append(tableName).append(" ("); string parentValueStr = " values("; for (int j = 0; j < parentNameVec.size(); j++) { string columnName = parentNameVec[j]; parentColumnStr = parentColumnStr.append(columnName); if (j < parentNameVec.size() - 1) { parentColumnStr = parentColumnStr.append(","); } string propertyName = parentValueVec[j]; string tempValue = " "; string updateValue = ""; if (strcmp(columnName.c_str(), "_bl_occ_type") == 0) { if (strcmp(propertyName.c_str(), "ALL") == 0) { continue; } else { vectortypeVec; Split(propertyName, ";", typeVec); if (hasElement(typeVec, gx_occ_type) == 0) { continue; } else { isGxContinue = true; break; } } } else if (strcmp(columnName.c_str(), "SESSIONID") == 0) { tempValue = propertyName;//固定值 } else if (strcmp(columnName.c_str(), "PROCESS_DETAILS_ID") == 0) { tempValue = gx_cloneid_key[gx_clone_id];// 工序明细表ID(外键) } else if (strcmp(columnName.c_str(), "TRANSNO") == 0) { tempValue = propertyName;//已处理 if (updateWhere.length() == 0) { updateWhere = updateWhere.append(" where "); updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and "); selectStr = selectStr.append(" where "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(" where "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } else { updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } } else if (strcmp(columnName.c_str(), "TRANSSTATUS") == 0) { //首次传递空值 updateValue = propertyName; updateStr = updateStr.append(tableName).append(" set ").append(columnName).append("='").append(updateValue).append("' "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(updateValue).append("' and "); } else if (strcmp(columnName.c_str(), "PPUID") == 0) { char* puid = NULL; ITK__convert_tag_to_uid(gx_rev, &puid); tempValue = puid; //selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); if (updateWhere.length() == 0) { updateWhere = updateWhere.append(" where "); updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and "); selectStr = selectStr.append(" where "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(" where "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } else { updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and "); selectStr = selectStr.append(columnName).append("='").append(puid).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(puid).append("' and "); } DOFREE(puid); } else { vector propertyVec; Split(propertyName, ".", propertyVec); if (propertyVec.size() == 2) { string propertyPosition = propertyVec[0]; tag_t propertyTag = NULL; if (strcmp("item", propertyPosition.c_str()) == 0) { propertyTag = gx_item; } else if (strcmp("rev", propertyPosition.c_str()) == 0) { propertyTag = gx_rev; } else if (strcmp("bomline", propertyPosition.c_str()) == 0) { propertyTag = gx_line; } string propertyName = propertyVec[1]; char* propertyValue = NULL; if (strcmp("puid", propertyName.c_str()) == 0) { ITK__convert_tag_to_uid(propertyTag, &propertyValue); } else { ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue)); } EMH_clear_errors(); if (ifail == 0) { tempValue = propertyValue; } else { showError = true; WriteLog("属性异常:%s\n", propertyName.c_str()); tempValue = " "; } DOFREE(propertyValue); } } parentValueStr = parentValueStr.append("'").append(tempValue).append("'"); if (j < parentNameVec.size() - 1) { parentValueStr = parentValueStr.append(","); } } if (isGxContinue) { continue; } int gb_count = gbs.size(); if (gb_count > 0) { for (int x = 0; x < gb_count; x++) { bool isContinue = false; tag_t gb_line = gbs[x].line; tag_t gb_item = gbs[x].item; string childColumnStr = ""; string childSelectStr = ""; string childUpdateSelectStr = ""; string childUpdateWhere = ""; string childValueStr = ""; string gb_puid = "";; string primay_key = ""; ITKCALL(ifail = AOM_ask_value_string(gb_line, "bl_occ_type", &gb_occ_type)); for (int j = 0; j < childNameVec.size(); j++) { string columnName = childNameVec[j]; string propertyName = childValueVec[j]; string tempValue = " "; if (strcmp(columnName.c_str(), "_bl_occ_type") == 0) { if (strcmp(propertyName.c_str(), "ALL") == 0) { continue; } else { vectortypeVec; Split(propertyName, ";", typeVec); if (hasElement(typeVec, gb_occ_type) == 0) { continue; } else { isContinue = true; break; } } } else if (strcmp(columnName.c_str(), "CPUID") == 0) { char* puid = NULL; ITK__convert_tag_to_uid(gb_item, &puid); tempValue = puid; gb_puid = string(puid); childSelectStr = childSelectStr.append(columnName).append("='").append(tempValue).append("' "); childUpdateSelectStr = childUpdateSelectStr.append(columnName).append("='").append(tempValue).append("' "); childUpdateWhere = childUpdateWhere.append(columnName).append("='").append(tempValue).append("'"); DOFREE(puid); } else { vector propertyVec; Split(propertyName, ".", propertyVec); if (propertyVec.size() == 2) { string propertyPosition = propertyVec[0]; tag_t propertyTag = NULL; if (strcmp("item", propertyPosition.c_str()) == 0) { propertyTag = gb_item; } else if (strcmp("bomline", propertyPosition.c_str()) == 0) { propertyTag = gb_line; } string propertyName = propertyVec[1]; char* propertyValue = NULL; if (strcmp("puid", propertyName.c_str()) == 0) { ITK__convert_tag_to_uid(propertyTag, &propertyValue); } else { ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue)); } EMH_clear_errors(); if (ifail == 0) { tempValue = propertyValue; } else { showError = true; WriteLog("属性异常:%s\n", propertyName.c_str()); tempValue = " "; } DOFREE(propertyValue); } else if (strcmp("key", propertyName.c_str()) == 0) { primay_key = getGuid(); tempValue = primay_key; } else { tempValue = " "; } } childColumnStr = childColumnStr.append(columnName); if (j < childNameVec.size() - 1) { childColumnStr = childColumnStr.append(","); } childValueStr = childValueStr.append("'").append(tempValue); if (j < childNameVec.size() - 1) { childValueStr = childValueStr.append("',"); } else { childValueStr = childValueStr.append("'"); } } if (isContinue) { continue; } string insertSql = ""; string selectSql = ""; string updateSelectSql = ""; string updateSql = ""; if (childColumnStr.size() > 0) { insertSql = insertSql.append(parentColumnStr).append(",").append(childColumnStr).append(")").append(parentValueStr).append(",").append(childValueStr).append(")"); } else { insertSql = insertSql.append(parentColumnStr).append(")").append(parentValueStr).append(")"); } selectSql = selectSql.append(selectStr).append(childSelectStr); updateSelectSql = updateSelectSql.append(selectAfterUpdateStr).append(childUpdateSelectStr); updateSql = updateSql.append(updateStr).append(updateWhere).append(childUpdateWhere); //updateStr = updateStr.append(updateWhere); insertSql = Utf8ToGbk(insertSql.c_str()); updateSql = Utf8ToGbk(updateSql.c_str()); selectSql = Utf8ToGbk(selectSql.c_str()); updateSelectSql = Utf8ToGbk(updateSelectSql.c_str()); WriteLog("工步插入语句:%s\n", insertSql.c_str()); //WriteLog("工步更新语句:%s\n", updateSql.c_str()); WriteLog("工步查询语句:%s\n", selectSql.c_str()); //WriteLog("工步更新后查询语句:%s\n", updateSelectSql.c_str()); insertVec.push_back(insertSql); updateVec.push_back(updateSql); selectVec.push_back(selectSql); selectAfterUpdateVec.push_back(updateSelectSql); insertPuidVec.push_back(gx_clone_id + gb_puid); char sendChar[400] = ""; strcpy(sendChar, insertSql.c_str()); char sendChar2[400] = ""; strcpy(sendChar2, selectSql.c_str()); int result = ado0.ado_QuerySQLNoInputParam(sendChar2); bool resultSql = ado0.executeInsert(sendChar2, sendChar, result); string key = gx_clone_id + gb_puid; gx_gb_key[key] = primay_key; //if (!resultSql) { // WriteLog("数据库语句插入失败\n"); //} } } DOFREE(gb_occ_type); } DOFREE(gx_occ_type); //更新数据库 //for (int i = 0; i < updateVec.size(); i++) { // int outputColumn = 0, outputValueCount = 0; // char*** outputValue = NULL; // string updateSql = updateVec[i]; // string selectSql = selectVec[i]; // string insertSql = insertVec[i]; // string selectUpdate = selectAfterUpdateVec[i]; // string key = insertPuidVec[i]; // char sendChar[400] = ""; // char sendChar2[400] = ""; // char sendChar3[400] = ""; // strcpy(sendChar, updateSql.c_str()); // strcpy(sendChar2, selectSql.c_str()); // strcpy(sendChar3, selectUpdate.c_str()); // int result = ado0.ado_QuerySQLNoInputParam(sendChar2); // if (result == 0) { // showError = true; // WriteLog("工步插入失败:%s\n", insertSql.c_str()); // } // else { // //bool resultSql = ado0.execute2(sendChar2, sendChar, result); // result = ado0.ado_QuerySQLNoInputParam2(sendChar3, &outputColumn, &outputValueCount, &outputValue); // if (result == 0) { // showError = true; // WriteLog("工步更新失败:%s\n", updateSql.c_str()); // } // else { // if (outputValueCount > 0) { // gx_gb_key[key] = string(outputValue[0][0]); // } // } // } //} } // 工艺路线-工序属性表 void insertGyGxProp(string xmlUid, bool& showError, ado ado0, tag_t gy_line, tag_t gy_item, tag_t gy_rev, map child_level1, map gx_cloneid_key) { WriteLog("记录工艺路线-工序属性表数据库\n"); int ifail = 0; char* occ_type = NULL; // string sqlStr = "insert into "; string updateStr = "update "; string selectStr = "select * from "; string selectAfterUpdateStr = "select * from "; string updateWhere = ""; // 加载工艺路线工序明显表数据 // 解析xml文件 // 创建一个XML结构并载入文件内容 map, vector>> xmlMap;//物料类型,<字段名,属性取值> string tableName = loadXml(xmlUid, xmlMap); map, vector> parentPropertyMap = xmlMap["父"];//父级 vector parentNameVec; vector parentValueVec; map, vector>::iterator rev_it2; for (rev_it2 = parentPropertyMap.begin(); rev_it2 != parentPropertyMap.end(); rev_it2++) { parentNameVec = rev_it2->first; parentValueVec = rev_it2->second; } map, vector> childPropertyMap = xmlMap["子"];//子级 vector childNameVec; vector childValueVec; map, vector>::iterator rev_it; for (rev_it = childPropertyMap.begin(); rev_it != childPropertyMap.end(); rev_it++) { childNameVec = rev_it->first; childValueVec = rev_it->second; } vector updateVec; vector selectVec; vector insertVec; vector selectAfterUpdateVec; sqlStr = sqlStr.append(tableName).append("("); selectStr = selectStr.append(tableName).append(" "); selectAfterUpdateStr = selectAfterUpdateStr.append(tableName).append(" "); string valueStr = " VALUES ("; //获取父属性 string parentColumnStr = "insert into "; parentColumnStr = parentColumnStr.append(tableName).append(" ("); string parentValueStr = " values("; for (int j = 0; j < parentNameVec.size(); j++) { string columnName = parentNameVec[j]; parentColumnStr = parentColumnStr.append(columnName); if (j < parentNameVec.size() - 1) { parentColumnStr = parentColumnStr.append(","); } string propertyName = parentValueVec[j]; string tempValue = " "; string updateValue = ""; if (strcmp(columnName.c_str(), "SESSIONID") == 0) { tempValue = propertyName;//固定值 } else if (strcmp(columnName.c_str(), "TRANSNO") == 0) { tempValue = propertyName;//已处理 if (updateWhere.length() == 0) { updateWhere = updateWhere.append(" where "); updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and "); selectStr = selectStr.append(" where "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(" where "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } else { updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } } else if (strcmp(columnName.c_str(), "TRANSSTATUS") == 0) { //首次传递空值 updateValue = propertyName; updateStr = updateStr.append(tableName).append(" set ").append(columnName).append("='").append(updateValue).append("' "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(updateValue).append("' and "); } else if (strcmp(columnName.c_str(), "PPUID") == 0) { char* puid = NULL; ITK__convert_tag_to_uid(gy_rev, &puid); tempValue = puid; //selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); if (updateWhere.length() == 0) { updateWhere = updateWhere.append(" where "); updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and "); selectStr = selectStr.append(" where "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(" where "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } else { updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and "); selectStr = selectStr.append(columnName).append("='").append(puid).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(puid).append("' and "); } DOFREE(puid); } else { vector propertyVec; Split(propertyName, ".", propertyVec); if (propertyVec.size() == 2) { string propertyPosition = propertyVec[0]; tag_t propertyTag = NULL; if (strcmp("item", propertyPosition.c_str()) == 0) { propertyTag = gy_item; } else if (strcmp("rev", propertyPosition.c_str()) == 0) { propertyTag = gy_rev; } else if (strcmp("bomline", propertyPosition.c_str()) == 0) { propertyTag = gy_line; } string propertyName = propertyVec[1]; char* propertyValue = NULL; if (strcmp("puid", propertyName.c_str()) == 0) { ITK__convert_tag_to_uid(propertyTag, &propertyValue); } else { ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue)); } EMH_clear_errors(); if (ifail == 0) { tempValue = propertyValue; } else { showError = true; WriteLog("属性异常:%s\n", propertyName.c_str()); tempValue = " "; } DOFREE(propertyValue); } } parentValueStr = parentValueStr.append("'").append(tempValue).append("'"); if (j < parentNameVec.size() - 1) { parentValueStr = parentValueStr.append(","); } } map::iterator child_it; for (child_it = child_level1.begin(); child_it != child_level1.end(); child_it++) { bool isContinue = false; string childColumnStr = ""; string childSelectStr = ""; string childUpdateSelectStr = ""; string childUpdateWhere = ""; string childValueStr = ""; tag_t line = child_it->second.line; tag_t item = child_it->second.item; tag_t rev = child_it->second.rev; string clone_id = child_it->second.clone_id; ITKCALL(ifail = AOM_ask_value_string(line, "bl_occ_type", &occ_type)); for (int j = 0; j < childNameVec.size(); j++) { string columnName = childNameVec[j]; string propertyName = childValueVec[j]; string tempValue = " "; if (strcmp(columnName.c_str(), "_bl_occ_type") == 0) { if (strcmp(propertyName.c_str(), "ALL") == 0) { continue; } else { vectortypeVec; Split(propertyName, ";", typeVec); if (hasElement(typeVec, occ_type) == 0) { continue; } else { isContinue = true; break; } } } else if (strcmp(columnName.c_str(), "CPUID") == 0) { char* puid = NULL; ITK__convert_tag_to_uid(rev, &puid); tempValue = puid; childSelectStr = childSelectStr.append(columnName).append("='").append(tempValue).append("' "); childUpdateSelectStr = childUpdateSelectStr.append(columnName).append("='").append(tempValue).append("' "); childUpdateWhere = childUpdateWhere.append(columnName).append("='").append(tempValue).append("'"); DOFREE(puid); } else if (strcmp(columnName.c_str(), "PRD_ID") == 0) { // 取明显表中的主键 WriteLog("属clone_id:%s\n", clone_id.c_str()); tempValue = gx_cloneid_key[clone_id]; WriteLog("明显表中的主键:%s\n", tempValue.c_str()); } else { vector propertyVec; Split(propertyName, ".", propertyVec); if (propertyVec.size() == 2) { string propertyPosition = propertyVec[0]; tag_t propertyTag = NULL; if (strcmp("item", propertyPosition.c_str()) == 0) { propertyTag = item; } else if (strcmp("rev", propertyPosition.c_str()) == 0) { propertyTag = rev; } else if (strcmp("bomline", propertyPosition.c_str()) == 0) { propertyTag = line; } string propertyName = propertyVec[1]; char* propertyValue = NULL; if (strcmp("puid", propertyName.c_str()) == 0) { ITK__convert_tag_to_uid(propertyTag, &propertyValue); } else { ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue)); } EMH_clear_errors(); if (ifail == 0) { tempValue = propertyValue; } else { showError = true; WriteLog("属性异常:%s\n", propertyName.c_str()); tempValue = " "; } DOFREE(propertyValue); } else if (strcmp("key", propertyName.c_str()) == 0){ tempValue = getGuid(); } else { tempValue = " "; } } childColumnStr = childColumnStr.append(columnName); if (j < childNameVec.size() - 1) { childColumnStr = childColumnStr.append(","); } childValueStr = childValueStr.append("'").append(tempValue); if (j < childNameVec.size() - 1) { childValueStr = childValueStr.append("',"); } else { childValueStr = childValueStr.append("'"); } } if (isContinue) { continue; } string insertSql = ""; string selectSql = ""; string updateSelectSql = ""; string updateSql = ""; if (childColumnStr.size() > 0) { insertSql = insertSql.append(parentColumnStr).append(",").append(childColumnStr).append(")").append(parentValueStr).append(",").append(childValueStr).append(")"); } else { insertSql = insertSql.append(parentColumnStr).append(")").append(parentValueStr).append(")"); } selectSql = selectSql.append(selectStr).append(childSelectStr); updateSelectSql = updateSelectSql.append(selectAfterUpdateStr).append(childUpdateSelectStr); updateSql = updateSql.append(updateStr).append(updateWhere).append(childUpdateWhere); //updateStr = updateStr.append(updateWhere); insertSql = Utf8ToGbk(insertSql.c_str()); updateSql = Utf8ToGbk(updateSql.c_str()); selectSql = Utf8ToGbk(selectSql.c_str()); updateSelectSql = Utf8ToGbk(updateSelectSql.c_str()); WriteLog("工序属性插入语句:%s\n", insertSql.c_str()); //WriteLog("工序属性更新语句:%s\n", updateSql.c_str()); WriteLog("工序属性查询语句:%s\n", selectSql.c_str()); //WriteLog("工序属性更新后查询语句:%s\n", updateSelectSql.c_str()); insertVec.push_back(insertSql); updateVec.push_back(updateSql); selectVec.push_back(selectSql); selectAfterUpdateVec.push_back(updateSelectSql); char sendChar[400] = ""; strcpy(sendChar, insertSql.c_str()); char sendChar2[400] = ""; strcpy(sendChar2, selectSql.c_str()); int result = ado0.ado_QuerySQLNoInputParam(sendChar2); bool resultSql = ado0.executeInsert(sendChar2, sendChar, result); } DOFREE(occ_type); //更新数据库 /*for (int i = 0; i < updateVec.size(); i++) { string updateSql = updateVec[i]; string selectSql = selectVec[i]; string insertSql = insertVec[i]; string selectUpdate = selectAfterUpdateVec[i]; char sendChar[200] = ""; char sendChar2[200] = ""; char sendChar3[200] = ""; strcpy(sendChar, updateSql.c_str()); strcpy(sendChar2, selectSql.c_str()); strcpy(sendChar3, selectUpdate.c_str()); int result = ado0.ado_QuerySQLNoInputParam(sendChar2); if (result == 0) { showError = true; WriteLog("工序属性插入失败:%s\n", insertSql.c_str()); } else { bool resultSql = ado0.execute2(sendChar2, sendChar, result); result = ado0.ado_QuerySQLNoInputParam(sendChar3); if (result == 0) { showError = true; WriteLog("工序属性更新失败:%s\n", updateSql.c_str()); } } }*/ } // 工序工艺文件 void insertGyGxGywj(string xmlUid, string ftp_ip, string ftp_port, string username, string pwd, bool& showError, ado ado0, tag_t gy_line, tag_t gy_item, tag_t gy_rev, map child_level1, map> level1_level2, map child_level2) { WriteLog("记录工序工艺文件数据库\n"); int ifail = 0; char* occ_type = NULL; // string sqlStr = "insert into "; string updateStr = "update "; string selectStr = "select * from "; string selectAfterUpdateStr = "select * from "; string updateWhere = ""; // 解析xml文件 // 创建一个XML结构并载入文件内容 map, vector>> xmlMap;//物料类型,<字段名,属性取值> string tableName = loadXml(xmlUid, xmlMap); map, vector> parentPropertyMap = xmlMap["父"];//父级 vector parentNameVec; vector parentValueVec; map, vector>::iterator rev_it2; for (rev_it2 = parentPropertyMap.begin(); rev_it2 != parentPropertyMap.end(); rev_it2++) { parentNameVec = rev_it2->first; parentValueVec = rev_it2->second; } map, vector> childPropertyMap = xmlMap["子"];//子级 vector childNameVec; vector childValueVec; map, vector>::iterator rev_it; for (rev_it = childPropertyMap.begin(); rev_it != childPropertyMap.end(); rev_it++) { childNameVec = rev_it->first; childValueVec = rev_it->second; } map, vector> childLevel2PropertyMap = xmlMap["孙"];//子级的子级 vector childLevel2NameVec; vector childLevel2ValueVec; map, vector>::iterator rev_it_level2; for (rev_it_level2 = childLevel2PropertyMap.begin(); rev_it_level2 != childLevel2PropertyMap.end(); rev_it_level2++) { childLevel2NameVec = rev_it_level2->first; childLevel2ValueVec = rev_it_level2->second; } vector updateVec; vector selectVec; vector insertVec; vector selectAfterUpdateVec; sqlStr = sqlStr.append(tableName).append("("); selectStr = selectStr.append(tableName).append(" "); selectAfterUpdateStr = selectAfterUpdateStr.append(tableName).append(" "); string valueStr = " VALUES ("; //获取父属性 string parentColumnStr = "insert into "; parentColumnStr = parentColumnStr.append(tableName).append(" ("); string parentValueStr = " values("; for (int j = 0; j < parentNameVec.size(); j++) { string columnName = parentNameVec[j]; parentColumnStr = parentColumnStr.append(columnName); if (j < parentNameVec.size() - 1) { parentColumnStr = parentColumnStr.append(","); } string propertyName = parentValueVec[j]; string tempValue = " "; string updateValue = ""; if (strcmp(columnName.c_str(), "SESSIONID") == 0) { tempValue = propertyName;//固定值 } else if (strcmp(columnName.c_str(), "TRANSNO") == 0) { tempValue = propertyName;//已处理 if (updateWhere.length() == 0) { updateWhere = updateWhere.append(" where "); updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and "); selectStr = selectStr.append(" where "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(" where "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } else { updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } } else if (strcmp(columnName.c_str(), "TRANSSTATUS") == 0) { //首次传递空值 updateValue = propertyName; updateStr = updateStr.append(tableName).append(" set ").append(columnName).append("='").append(updateValue).append("' "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(updateValue).append("' and "); } else if (strcmp(columnName.c_str(), "PPUID") == 0) { char* puid = NULL; ITK__convert_tag_to_uid(gy_rev, &puid); tempValue = puid; //selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); if (updateWhere.length() == 0) { updateWhere = updateWhere.append(" where "); updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and "); selectStr = selectStr.append(" where "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(" where "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } else { updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and "); selectStr = selectStr.append(columnName).append("='").append(puid).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(puid).append("' and "); } DOFREE(puid); } else { vector propertyVec; Split(propertyName, ".", propertyVec); if (propertyVec.size() == 2) { string propertyPosition = propertyVec[0]; tag_t propertyTag = NULL; if (strcmp("item", propertyPosition.c_str()) == 0) { propertyTag = gy_item; } else if (strcmp("rev", propertyPosition.c_str()) == 0) { propertyTag = gy_rev; } else if (strcmp("bomline", propertyPosition.c_str()) == 0) { propertyTag = gy_line; } string propertyName = propertyVec[1]; char* propertyValue = NULL; if (strcmp("puid", propertyName.c_str()) == 0) { ITK__convert_tag_to_uid(propertyTag, &propertyValue); } else { ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue)); } EMH_clear_errors(); if (ifail == 0) { tempValue = propertyValue; } else { showError = true; WriteLog("属性异常:%s\n", propertyName.c_str()); tempValue = " "; } DOFREE(propertyValue); } } parentValueStr = parentValueStr.append("'").append(tempValue).append("'"); if (j < parentNameVec.size() - 1) { parentValueStr = parentValueStr.append(","); } } // 获取子对象的属性 map::iterator child_it; for (child_it = child_level1.begin(); child_it != child_level1.end(); child_it++) { bool isContinue = false; string childColumnStr = ""; string childSelectStr = ""; string childUpdateSelectStr = ""; string childUpdateWhere = ""; string childValueStr = ""; tag_t line = child_it->second.line; tag_t item = child_it->second.item; tag_t rev = child_it->second.rev; string clone_id = child_it->second.clone_id; vector level2_vec = level1_level2[clone_id]; int level2_cnt = level2_vec.size(); ITKCALL(ifail = AOM_ask_value_string(line, "bl_occ_type", &occ_type)); for (int j = 0; j < childNameVec.size(); j++) { string columnName = childNameVec[j]; string propertyName = childValueVec[j]; string tempValue = " "; if (strcmp(columnName.c_str(), "_bl_occ_type") == 0) { if (strcmp(propertyName.c_str(), "ALL") == 0) { continue; } else { vectortypeVec; Split(propertyName, ";", typeVec); if (hasElement(typeVec, occ_type) == 0) { continue; } else { isContinue = true; break; } } } else if (strcmp(columnName.c_str(), "CPUID") == 0) { char* puid = NULL; ITK__convert_tag_to_uid(rev, &puid); tempValue = puid; childSelectStr = childSelectStr.append(columnName).append("='").append(tempValue).append("' and "); childUpdateSelectStr = childUpdateSelectStr.append(columnName).append("='").append(tempValue).append("' and "); childUpdateWhere = childUpdateWhere.append(columnName).append("='").append(tempValue).append("' and "); DOFREE(puid); } else { vector propertyVec; Split(propertyName, ".", propertyVec); if (propertyVec.size() == 2) { string propertyPosition = propertyVec[0]; tag_t propertyTag = NULL; if (strcmp("item", propertyPosition.c_str()) == 0) { propertyTag = item; } else if (strcmp("rev", propertyPosition.c_str()) == 0) { propertyTag = rev; } else if (strcmp("bomline", propertyPosition.c_str()) == 0) { propertyTag = line; } string propertyName = propertyVec[1]; char* propertyValue = NULL; if (strcmp("puid", propertyName.c_str()) == 0) { ITK__convert_tag_to_uid(propertyTag, &propertyValue); } else { ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue)); } EMH_clear_errors(); if (ifail == 0) { tempValue = propertyValue; } else { showError = true; WriteLog("属性异常:%s\n", propertyName.c_str()); tempValue = " "; } DOFREE(propertyValue); } else { tempValue = " "; } } childColumnStr = childColumnStr.append(columnName); if (j < childNameVec.size() - 1) { childColumnStr = childColumnStr.append(","); } childValueStr = childValueStr.append("'").append(tempValue); if (j < childNameVec.size() - 1) { childValueStr = childValueStr.append("',"); } else { childValueStr = childValueStr.append("'"); } } if (isContinue) { continue; } if (level2_cnt > 0) { char* zy_occ_type = NULL; for (int k = 0; k < level2_cnt; k++) { bool isZyContinue = false; CHILD level2_child = child_level2[level2_vec[k]]; string childLevel2ColumnStr = ""; string childLevel2SelectStr = ""; string childLevel2UpdateSelectStr = ""; string childLevel2UpdateWhere = ""; string childLevel2ValueStr = ""; tag_t zy_line = level2_child.line; tag_t zy_item = level2_child.item; tag_t zy_rev = level2_child.rev; string zy_clone_id = level2_child.clone_id; ITKCALL(ifail = AOM_ask_value_string(zy_line, "bl_occ_type", &zy_occ_type)); for (int z = 0; z < childLevel2NameVec.size(); z++) { string columnName = childLevel2NameVec[z]; string propertyName = childLevel2ValueVec[z]; string tempValue2 = " "; if (strcmp(columnName.c_str(), "_bl_occ_type") == 0) { if (strcmp(propertyName.c_str(), "ALL") == 0) { continue; } else { vectortypeVec; Split(propertyName, ";", typeVec); if (hasElement(typeVec, zy_occ_type) == 0) { continue; } else { isZyContinue = true; break; } } } else if (strcmp(columnName.c_str(), "SPUID") == 0) { char* spuid = NULL; ITK__convert_tag_to_uid(zy_rev, &spuid); tempValue2 = spuid; WriteLog("资源类型:%s,puid:%s\n", zy_occ_type, spuid); childLevel2SelectStr = childLevel2SelectStr.append(columnName).append("='").append(tempValue2).append("' "); childLevel2UpdateSelectStr = childLevel2UpdateSelectStr.append(columnName).append("='").append(tempValue2).append("' "); childLevel2UpdateWhere = childLevel2UpdateWhere.append(columnName).append("='").append(tempValue2).append("'"); DOFREE(spuid); } else if (strcmp(columnName.c_str(), "FILE_PATH") == 0) { // 数据集通过ftp传递 int related_cnt = 0; char* type_name = NULL, * item_id = NULL, * rev_id = NULL; GRM_relation_t* related_objects = NULL; ITKCALL(ifail = AOM_ask_value_string(zy_rev, "item_id", &item_id)); ITKCALL(ifail = AOM_ask_value_string(zy_rev, "item_revision_id", &rev_id)); ITKCALL(AOM_ask_value_string(zy_rev, "object_type", &type_name)); //ITKCALL(AOM_UIF_ask_value(zy_rev, "object_type", &type_name)); ITKCALL(GRM_list_all_related_objects(zy_rev, &related_cnt, &related_objects)); string idAndRev = string(item_id) + "-" + string(rev_id); for (int i = 0; i < related_cnt; i++) { // 判断是否为数据集 if (checkIsTypeOrSubtype(related_objects[i].secondary, "Dataset") == 1) { string path = downloadDataset(related_objects[i].secondary, ftp_ip, ftp_port, type_name, idAndRev, username, pwd); WriteLog("文件路径:%s\n", path.c_str()); if (tempValue2.length() > 1) { tempValue2 = tempValue2.append(";"); } tempValue2 = tempValue2.append(path); } } DOFREE(type_name); DOFREE(item_id); DOFREE(rev_id); } else { vector propertyVec; Split(propertyName, ".", propertyVec); if (propertyVec.size() == 2) { string propertyPosition = propertyVec[0]; tag_t propertyTag = NULL; if (strcmp("item", propertyPosition.c_str()) == 0) { propertyTag = zy_item; } else if (strcmp("rev", propertyPosition.c_str()) == 0) { propertyTag = zy_rev; } else if (strcmp("bomline", propertyPosition.c_str()) == 0) { propertyTag = zy_line; } string propertyName = propertyVec[1]; char* propertyValue = NULL; if (strcmp("puid", propertyName.c_str()) == 0) { ITK__convert_tag_to_uid(propertyTag, &propertyValue); } else { ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue)); } EMH_clear_errors(); if (ifail == 0) { tempValue2 = propertyValue; } else { showError = true; WriteLog("属性异常:%s\n", propertyName.c_str()); tempValue2 = " "; } DOFREE(propertyValue); } else { tempValue2 = " "; } } childLevel2ColumnStr = childLevel2ColumnStr.append(columnName); if (z < childLevel2NameVec.size() - 1) { childLevel2ColumnStr = childLevel2ColumnStr.append(","); } childLevel2ValueStr = childLevel2ValueStr.append("'").append(tempValue2); if (z < childLevel2NameVec.size() - 1) { childLevel2ValueStr = childLevel2ValueStr.append("',"); } else { childLevel2ValueStr = childLevel2ValueStr.append("'"); } } if (isZyContinue) { continue; } string insertSql = ""; string selectSql = ""; string updateSelectSql = ""; string updateSql = ""; if (parentColumnStr.size() > 0 && childColumnStr.size() > 0 && childLevel2ColumnStr.size() > 0) { insertSql = insertSql.append(parentColumnStr).append(",").append(childColumnStr).append(",").append(childLevel2ColumnStr).append(")").append(parentValueStr).append(",").append(childValueStr).append(",").append(childLevel2ValueStr).append(")"); } selectSql = selectSql.append(selectStr).append(childSelectStr).append(childLevel2SelectStr); updateSelectSql = updateSelectSql.append(selectAfterUpdateStr).append(childUpdateSelectStr).append(childLevel2UpdateSelectStr); updateSql = updateSql.append(updateStr).append(updateWhere).append(childUpdateWhere).append(childLevel2UpdateWhere); //updateStr = updateStr.append(updateWhere); insertSql = Utf8ToGbk(insertSql.c_str()); updateSql = Utf8ToGbk(updateSql.c_str()); selectSql = Utf8ToGbk(selectSql.c_str()); updateSelectSql = Utf8ToGbk(updateSelectSql.c_str()); WriteLog("工艺文件插入语句:%s\n", insertSql.c_str()); //WriteLog("工艺文件更新语句:%s\n", updateSql.c_str()); WriteLog("工艺文件查询语句:%s\n", selectSql.c_str()); //WriteLog("工艺文件更新后查询语句:%s\n", updateSelectSql.c_str()); insertVec.push_back(insertSql); updateVec.push_back(updateSql); selectVec.push_back(selectSql); selectAfterUpdateVec.push_back(updateSelectSql); char sendChar[400] = ""; strcpy(sendChar, insertSql.c_str()); char sendChar2[400] = ""; strcpy(sendChar2, selectSql.c_str()); int result = ado0.ado_QuerySQLNoInputParam(sendChar2); bool resultSql = ado0.executeInsert(sendChar2, sendChar, result); } DOFREE(zy_occ_type); } } DOFREE(occ_type); //更新数据库 /*for (int i = 0; i < updateVec.size(); i++) { string updateSql = updateVec[i]; string selectSql = selectVec[i]; string insertSql = insertVec[i]; string selectUpdate = selectAfterUpdateVec[i]; char sendChar[400] = ""; char sendChar2[400] = ""; char sendChar3[400] = ""; strcpy(sendChar, updateSql.c_str()); strcpy(sendChar2, selectSql.c_str()); strcpy(sendChar3, selectUpdate.c_str()); int result = ado0.ado_QuerySQLNoInputParam(sendChar2); if (result == 0) { showError = true; WriteLog("工艺文件插入失败:%s\n", insertSql.c_str()); } else { bool resultSql = ado0.execute2(sendChar2, sendChar, result); result = ado0.ado_QuerySQLNoInputParam(sendChar3); if (result == 0) { showError = true; WriteLog("工艺文件更新失败:%s\n", updateSql.c_str()); } } }*/ } // 工艺资源 void insertGyGxGyzy(string xmlUid, bool& showError, ado ado0, tag_t gy_line, tag_t gy_item, tag_t gy_rev, map child_level1, map> level1_level2, map child_level2) { WriteLog("记录工艺资源数据库\n"); int ifail = 0; char* occ_type = NULL; // string sqlStr = "insert into "; string updateStr = "update "; string selectStr = "select * from "; string selectAfterUpdateStr = "select * from "; string updateWhere = ""; // 解析xml文件 // 创建一个XML结构并载入文件内容 map, vector>> xmlMap;//物料类型,<字段名,属性取值> string tableName = loadXml(xmlUid, xmlMap); map, vector> parentPropertyMap = xmlMap["父"];//父级 vector parentNameVec; vector parentValueVec; map, vector>::iterator rev_it2; for (rev_it2 = parentPropertyMap.begin(); rev_it2 != parentPropertyMap.end(); rev_it2++) { parentNameVec = rev_it2->first; parentValueVec = rev_it2->second; } map, vector> childPropertyMap = xmlMap["子"];//子级 vector childNameVec; vector childValueVec; map, vector>::iterator rev_it; for (rev_it = childPropertyMap.begin(); rev_it != childPropertyMap.end(); rev_it++) { childNameVec = rev_it->first; childValueVec = rev_it->second; } map, vector> childLevel2PropertyMap = xmlMap["孙"];//子级的子级 vector childLevel2NameVec; vector childLevel2ValueVec; map, vector>::iterator rev_it_level2; for (rev_it_level2 = childLevel2PropertyMap.begin(); rev_it_level2 != childLevel2PropertyMap.end(); rev_it_level2++) { childLevel2NameVec = rev_it_level2->first; childLevel2ValueVec = rev_it_level2->second; } vector updateVec; vector selectVec; vector insertVec; vector selectAfterUpdateVec; sqlStr = sqlStr.append(tableName).append("("); selectStr = selectStr.append(tableName).append(" "); selectAfterUpdateStr = selectAfterUpdateStr.append(tableName).append(" "); string valueStr = " VALUES ("; //获取父属性 string parentColumnStr = "insert into "; parentColumnStr = parentColumnStr.append(tableName).append(" ("); string parentValueStr = " values("; for (int j = 0; j < parentNameVec.size(); j++) { string columnName = parentNameVec[j]; parentColumnStr = parentColumnStr.append(columnName); if (j < parentNameVec.size() - 1) { parentColumnStr = parentColumnStr.append(","); } string propertyName = parentValueVec[j]; string tempValue = " "; string updateValue = ""; if (strcmp(columnName.c_str(), "SESSIONID") == 0) { tempValue = propertyName;//固定值 } else if (strcmp(columnName.c_str(), "TRANSNO") == 0) { tempValue = propertyName;//已处理 if (updateWhere.length() == 0) { updateWhere = updateWhere.append(" where "); updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and "); selectStr = selectStr.append(" where "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(" where "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } else { updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } } else if (strcmp(columnName.c_str(), "TRANSSTATUS") == 0) { //首次传递空值 updateValue = propertyName; updateStr = updateStr.append(tableName).append(" set ").append(columnName).append("='").append(updateValue).append("' "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(updateValue).append("' and "); } else if (strcmp(columnName.c_str(), "PPUID") == 0) { char* puid = NULL; ITK__convert_tag_to_uid(gy_rev, &puid); tempValue = puid; //selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); if (updateWhere.length() == 0) { updateWhere = updateWhere.append(" where "); updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and "); selectStr = selectStr.append(" where "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(" where "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } else { updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and "); selectStr = selectStr.append(columnName).append("='").append(puid).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(puid).append("' and "); } DOFREE(puid); } else { vector propertyVec; Split(propertyName, ".", propertyVec); if (propertyVec.size() == 2) { string propertyPosition = propertyVec[0]; tag_t propertyTag = NULL; if (strcmp("item", propertyPosition.c_str()) == 0) { propertyTag = gy_item; } else if (strcmp("rev", propertyPosition.c_str()) == 0) { propertyTag = gy_rev; } else if (strcmp("bomline", propertyPosition.c_str()) == 0) { propertyTag = gy_line; } string propertyName = propertyVec[1]; char* propertyValue = NULL; if (strcmp("puid", propertyName.c_str()) == 0) { ITK__convert_tag_to_uid(propertyTag, &propertyValue); } else { ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue)); } EMH_clear_errors(); if (ifail == 0) { tempValue = propertyValue; } else { showError = true; WriteLog("属性异常:%s\n", propertyName.c_str()); tempValue = " "; } DOFREE(propertyValue); } } parentValueStr = parentValueStr.append("'").append(tempValue).append("'"); if (j < parentNameVec.size() - 1) { parentValueStr = parentValueStr.append(","); } } // 获取子对象的属性 map::iterator child_it; for (child_it = child_level1.begin(); child_it != child_level1.end(); child_it++) { bool isContinue = false; string childColumnStr = ""; string childSelectStr = ""; string childUpdateSelectStr = ""; string childUpdateWhere = ""; string childValueStr = ""; tag_t line = child_it->second.line; tag_t item = child_it->second.item; tag_t rev = child_it->second.rev; string clone_id = child_it->second.clone_id; vector level2_vec = level1_level2[clone_id]; int level2_cnt = level2_vec.size(); ITKCALL(ifail = AOM_ask_value_string(line, "bl_occ_type", &occ_type)); for (int j = 0; j < childNameVec.size(); j++) { string columnName = childNameVec[j]; string propertyName = childValueVec[j]; string tempValue = " "; if (strcmp(columnName.c_str(), "_bl_occ_type") == 0) { if (strcmp(propertyName.c_str(), "ALL") == 0) { continue; } else { vectortypeVec; Split(propertyName, ";", typeVec); if (hasElement(typeVec, occ_type) == 0) { continue; } else { isContinue = true; break; } } } else if (strcmp(columnName.c_str(), "CPUID") == 0) { char* puid = NULL; ITK__convert_tag_to_uid(rev, &puid); tempValue = puid; childSelectStr = childSelectStr.append(columnName).append("='").append(tempValue).append("' and "); childUpdateSelectStr = childUpdateSelectStr.append(columnName).append("='").append(tempValue).append("' and "); childUpdateWhere = childUpdateWhere.append(columnName).append("='").append(tempValue).append("' and "); DOFREE(puid); } else { vector propertyVec; Split(propertyName, ".", propertyVec); if (propertyVec.size() == 2) { string propertyPosition = propertyVec[0]; tag_t propertyTag = NULL; if (strcmp("item", propertyPosition.c_str()) == 0) { propertyTag = item; } else if (strcmp("rev", propertyPosition.c_str()) == 0) { propertyTag = rev; } else if (strcmp("bomline", propertyPosition.c_str()) == 0) { propertyTag = line; } string propertyName = propertyVec[1]; char* propertyValue = NULL; if (strcmp("puid", propertyName.c_str()) == 0) { ITK__convert_tag_to_uid(propertyTag, &propertyValue); } else { ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue)); } EMH_clear_errors(); if (ifail == 0) { tempValue = propertyValue; } else { showError = true; WriteLog("属性异常:%s\n", propertyName.c_str()); tempValue = " "; } DOFREE(propertyValue); } else { tempValue = " "; } } childColumnStr = childColumnStr.append(columnName); if (j < childNameVec.size() - 1) { childColumnStr = childColumnStr.append(","); } childValueStr = childValueStr.append("'").append(tempValue); if (j < childNameVec.size() - 1) { childValueStr = childValueStr.append("',"); } else { childValueStr = childValueStr.append("'"); } } if (isContinue) { continue; } if (level2_cnt > 0) { char* zy_occ_type = NULL; for (int k = 0; k < level2_cnt; k++) { bool isZyContinue = false; CHILD level2_child = child_level2[level2_vec[k]]; string childLevel2ColumnStr = ""; string childLevel2SelectStr = ""; string childLevel2UpdateSelectStr = ""; string childLevel2UpdateWhere = ""; string childLevel2ValueStr = ""; tag_t zy_line = level2_child.line; tag_t zy_item = level2_child.item; tag_t zy_rev = level2_child.rev; string zy_clone_id = level2_child.clone_id; ITKCALL(ifail = AOM_ask_value_string(zy_line, "bl_occ_type", &zy_occ_type)); for (int z = 0; z < childLevel2NameVec.size(); z++) { string columnName = childLevel2NameVec[z]; string propertyName = childLevel2ValueVec[z]; string tempValue2 = ""; if (strcmp(columnName.c_str(), "_bl_occ_type") == 0) { if (strcmp(propertyName.c_str(), "ALL") == 0) { continue; } else { vectortypeVec; Split(propertyName, ";", typeVec); WriteLog("资源类型:%s, val:%s,是否包含:%d\n", zy_occ_type, propertyName.c_str(), hasElement(typeVec, zy_occ_type)); if (hasElement(typeVec, zy_occ_type) == 0) { continue; } else { isZyContinue = true; break; } } } else if (strcmp(columnName.c_str(), "SPUID") == 0) { char* spuid = NULL; ITK__convert_tag_to_uid(zy_rev, &spuid); tempValue2 = spuid; WriteLog("资源类型:%s,puid:%s\n", zy_occ_type, spuid); childLevel2SelectStr = childLevel2SelectStr.append(columnName).append("='").append(tempValue2).append("' "); childLevel2UpdateSelectStr = childLevel2UpdateSelectStr.append(columnName).append("='").append(tempValue2).append("' "); childLevel2UpdateWhere = childLevel2UpdateWhere.append(columnName).append("='").append(tempValue2).append("'"); DOFREE(spuid); } else { vector propertyVec; Split(propertyName, ".", propertyVec); if (propertyVec.size() == 2) { string propertyPosition = propertyVec[0]; tag_t propertyTag = NULL; if (strcmp("item", propertyPosition.c_str()) == 0) { propertyTag = zy_item; } else if (strcmp("rev", propertyPosition.c_str()) == 0) { propertyTag = zy_rev; } else if (strcmp("bomline", propertyPosition.c_str()) == 0) { propertyTag = zy_line; } string propertyName = propertyVec[1]; char* propertyValue = NULL; if (strcmp("puid", propertyName.c_str()) == 0) { ITK__convert_tag_to_uid(propertyTag, &propertyValue); } else { ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue)); } EMH_clear_errors(); if (ifail == 0) { tempValue2 = propertyValue; } else { showError = true; WriteLog("属性异常:%s\n", propertyName.c_str()); tempValue2 = " "; } DOFREE(propertyValue); } else { tempValue2 = " "; } } childLevel2ColumnStr = childLevel2ColumnStr.append(columnName); if (z < childLevel2NameVec.size() - 1) { childLevel2ColumnStr = childLevel2ColumnStr.append(","); } childLevel2ValueStr = childLevel2ValueStr.append("'").append(tempValue2); if (z < childLevel2NameVec.size() - 1) { childLevel2ValueStr = childLevel2ValueStr.append("',"); } else { childLevel2ValueStr = childLevel2ValueStr.append("'"); } } if (isZyContinue) { continue; } string insertSql = ""; string selectSql = ""; string updateSelectSql = ""; string updateSql = ""; if (parentColumnStr.size() > 0 && childColumnStr.size() > 0 && childLevel2ColumnStr.size() > 0) { insertSql = insertSql.append(parentColumnStr).append(",").append(childColumnStr).append(",").append(childLevel2ColumnStr).append(")").append(parentValueStr).append(",").append(childValueStr).append(",").append(childLevel2ValueStr).append(")"); } selectSql = selectSql.append(selectStr).append(childSelectStr).append(childLevel2SelectStr); updateSelectSql = updateSelectSql.append(selectAfterUpdateStr).append(childUpdateSelectStr).append(childLevel2UpdateSelectStr); updateSql = updateSql.append(updateStr).append(updateWhere).append(childUpdateWhere).append(childLevel2UpdateWhere); //updateStr = updateStr.append(updateWhere); insertSql = Utf8ToGbk(insertSql.c_str()); updateSql = Utf8ToGbk(updateSql.c_str()); selectSql = Utf8ToGbk(selectSql.c_str()); updateSelectSql = Utf8ToGbk(updateSelectSql.c_str()); WriteLog("插入语句:%s\n", insertSql.c_str()); //WriteLog("更新语句:%s\n", updateSql.c_str()); WriteLog("查询语句:%s\n", selectSql.c_str()); //WriteLog("更新后查询语句:%s\n", updateSelectSql.c_str()); insertVec.push_back(insertSql); updateVec.push_back(updateSql); selectVec.push_back(selectSql); selectAfterUpdateVec.push_back(updateSelectSql); char sendChar[400] = ""; strcpy(sendChar, insertSql.c_str()); char sendChar2[400] = ""; strcpy(sendChar2, selectSql.c_str()); int result = ado0.ado_QuerySQLNoInputParam(sendChar2); bool resultSql = ado0.executeInsert(sendChar2, sendChar, result); } DOFREE(zy_occ_type); } } DOFREE(occ_type); //更新数据库 /*for (int i = 0; i < updateVec.size(); i++) { string updateSql = updateVec[i]; string selectSql = selectVec[i]; string insertSql = insertVec[i]; string selectUpdate = selectAfterUpdateVec[i]; char sendChar[400] = ""; char sendChar2[400] = ""; char sendChar3[400] = ""; strcpy(sendChar, updateSql.c_str()); strcpy(sendChar2, selectSql.c_str()); strcpy(sendChar3, selectUpdate.c_str()); int result = ado0.ado_QuerySQLNoInputParam(sendChar2); if (result == 0) { showError = true; WriteLog("插入失败:%s\n", insertSql.c_str()); } else { bool resultSql = ado0.execute2(sendChar2, sendChar, result); result = ado0.ado_QuerySQLNoInputParam(sendChar3); if (result == 0) { showError = true; WriteLog("更新失败:%s\n", updateSql.c_str()); } } }*/ } // 工步资源 void insertGbzy(string xmlUid, bool& showError, ado ado0, map child_level1, map gx_gb_key, map> gx_gbs_bom, map> gx_gb_zy) { WriteLog("记录工步资源数据库\n"); int ifail = 0; vector updateVec; vector selectVec; vector insertVec; vector selectAfterUpdateVec; // 解析xml文件 // 创建一个XML结构并载入文件内容 map, vector>> xmlMap;//物料类型,<字段名,属性取值> string tableName = loadXml(xmlUid, xmlMap); map, vector> parentPropertyMap = xmlMap["父"];//父级 vector parentNameVec; vector parentValueVec; map, vector>::iterator rev_it2; for (rev_it2 = parentPropertyMap.begin(); rev_it2 != parentPropertyMap.end(); rev_it2++) { parentNameVec = rev_it2->first; parentValueVec = rev_it2->second; } map, vector> childPropertyMap = xmlMap["子"];//子级 vector childNameVec; vector childValueVec; map, vector>::iterator rev_it; for (rev_it = childPropertyMap.begin(); rev_it != childPropertyMap.end(); rev_it++) { childNameVec = rev_it->first; childValueVec = rev_it->second; } map::iterator child_it; for (child_it = child_level1.begin(); child_it != child_level1.end(); child_it++) { char* gb_occ_type = NULL; string gx_clone_id = child_it->first; vector gbs = gx_gbs_bom[gx_clone_id]; int gb_count = gbs.size(); if (gb_count > 0) { for (int x = 0; x < gb_count; x++) { bool isGbContinue = false; tag_t gb_line = gbs[x].line; tag_t gb_item = gbs[x].item; char* zy_occ_type = NULL; string sqlStr = "insert into "; string updateStr = "update "; string selectStr = "select * from "; string selectAfterUpdateStr = "select * from "; string updateWhere = ""; string gb_puid = ""; //ITKCALL(ifail = AOM_ask_value_string(gb_line, "bl_occ_type", &gb_occ_type)); sqlStr = sqlStr.append(tableName).append("("); selectStr = selectStr.append(tableName).append(" "); selectAfterUpdateStr = selectAfterUpdateStr.append(tableName).append(" "); string valueStr = " VALUES ("; //获取父属性 string parentColumnStr = "insert into "; parentColumnStr = parentColumnStr.append(tableName).append(" ("); string parentValueStr = " values("; for (int j = 0; j < parentNameVec.size(); j++) { string columnName = parentNameVec[j]; parentColumnStr = parentColumnStr.append(columnName); if (j < parentNameVec.size() - 1) { parentColumnStr = parentColumnStr.append(","); } string propertyName = parentValueVec[j]; string tempValue = " "; string updateValue = ""; if (strcmp(columnName.c_str(), "_bl_occ_type") == 0) { if (strcmp(propertyName.c_str(), "ALL") == 0) { continue; } else { vectortypeVec; Split(propertyName, ";", typeVec); if (hasElement(typeVec, gb_occ_type) == 0) { continue; } else { isGbContinue = true; break; } } } else if (strcmp(columnName.c_str(), "SESSIONID") == 0) { tempValue = propertyName;//固定值 } else if (strcmp(columnName.c_str(), "TRANSNO") == 0) { tempValue = propertyName;//已处理 if (updateWhere.length() == 0) { updateWhere = updateWhere.append(" where "); updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and "); selectStr = selectStr.append(" where "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(" where "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } else { updateWhere = updateWhere.append(columnName).append("='").append(tempValue).append("' and "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } } else if (strcmp(columnName.c_str(), "TRANSSTATUS") == 0) { //首次传递空值 updateValue = propertyName; updateStr = updateStr.append(tableName).append(" set ").append(columnName).append("='").append(updateValue).append("' "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(updateValue).append("' and "); } else if (strcmp(columnName.c_str(), "PPUID") == 0) { char* puid = NULL; ITK__convert_tag_to_uid(gb_item, &puid); gb_puid = string(puid); tempValue = puid; //selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); if (updateWhere.length() == 0) { updateWhere = updateWhere.append(" where "); updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and "); selectStr = selectStr.append(" where "); selectStr = selectStr.append(columnName).append("='").append(tempValue).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(" where "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(tempValue).append("' and "); } else { updateWhere = updateWhere.append(columnName).append("='").append(puid).append("' and "); selectStr = selectStr.append(columnName).append("='").append(puid).append("' and "); selectAfterUpdateStr = selectAfterUpdateStr.append(columnName).append("='").append(puid).append("' and "); } DOFREE(puid); } else { vector propertyVec; Split(propertyName, ".", propertyVec); if (propertyVec.size() == 2) { string propertyPosition = propertyVec[0]; tag_t propertyTag = NULL; if (strcmp("item", propertyPosition.c_str()) == 0) { propertyTag = gb_item; } else if (strcmp("bomline", propertyPosition.c_str()) == 0) { propertyTag = gb_line; } string propertyName = propertyVec[1]; char* propertyValue = NULL; if (strcmp("puid", propertyName.c_str()) == 0) { ITK__convert_tag_to_uid(propertyTag, &propertyValue); } else { ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue)); } EMH_clear_errors(); if (ifail == 0) { tempValue = propertyValue; } else { showError = true; WriteLog("属性异常:%s\n", propertyName.c_str()); tempValue = " "; } DOFREE(propertyValue); } } parentValueStr = parentValueStr.append("'").append(tempValue).append("'"); if (j < parentNameVec.size() - 1) { parentValueStr = parentValueStr.append(","); } } if (isGbContinue) { continue; } string key = gx_clone_id + gb_puid; string other_key = gx_gb_key[key]; vector gbzys = gx_gb_zy[key]; int gbzy_count = gbzys.size(); if (gbzy_count > 0) { for (int y = 0; y < gbzy_count; y++) { bool isContinue = false; tag_t gbzy_rev = gbzys[y].rev; tag_t gbzy_item = gbzys[y].item; tag_t gbzy_line = gbzys[y].line; string childColumnStr = ""; string childSelectStr = ""; string childUpdateSelectStr = ""; string childUpdateWhere = ""; string childValueStr = ""; ITKCALL(ifail = AOM_ask_value_string(gbzy_line, "bl_occ_type", &zy_occ_type)); for (int j = 0; j < childNameVec.size(); j++) { string columnName = childNameVec[j]; string propertyName = childValueVec[j]; string tempValue = " "; if (strcmp(columnName.c_str(), "_bl_occ_type") == 0) { if (strcmp(propertyName.c_str(), "ALL") == 0) { continue; } else { vectortypeVec; Split(propertyName, ";", typeVec); if (hasElement(typeVec, zy_occ_type) == 0) { continue; } else { isContinue = true; break; } } } else if (strcmp(columnName.c_str(), "CPUID") == 0) { char* puid = NULL; ITK__convert_tag_to_uid(gbzy_rev, &puid); tempValue = puid; childSelectStr = childSelectStr.append(columnName).append("='").append(tempValue).append("' "); childUpdateSelectStr = childUpdateSelectStr.append(columnName).append("='").append(tempValue).append("' "); childUpdateWhere = childUpdateWhere.append(columnName).append("='").append(tempValue).append("'"); DOFREE(puid); } else if (strcmp(columnName.c_str(), "BP_BASIC_PROCESS_ID") == 0) { tempValue = other_key; } else { vector propertyVec; Split(propertyName, ".", propertyVec); if (propertyVec.size() == 2) { string propertyPosition = propertyVec[0]; tag_t propertyTag = NULL; if (strcmp("item", propertyPosition.c_str()) == 0) { propertyTag = gbzy_item; } else if (strcmp("rev", propertyPosition.c_str()) == 0) { propertyTag = gbzy_rev; } else if (strcmp("bomline", propertyPosition.c_str()) == 0) { propertyTag = gbzy_line; } string propertyName = propertyVec[1]; char* propertyValue = NULL; if (strcmp("puid", propertyName.c_str()) == 0) { ITK__convert_tag_to_uid(propertyTag, &propertyValue); } else { ITKCALL(ifail = AOM_UIF_ask_value(propertyTag, propertyName.c_str(), &propertyValue)); } EMH_clear_errors(); if (ifail == 0) { tempValue = propertyValue; } else { showError = true; WriteLog("属性异常:%s\n", propertyName.c_str()); tempValue = " "; } DOFREE(propertyValue); } else { tempValue = " "; } } childColumnStr = childColumnStr.append(columnName); if (j < childNameVec.size() - 1) { childColumnStr = childColumnStr.append(","); } childValueStr = childValueStr.append("'").append(tempValue); if (j < childNameVec.size() - 1) { childValueStr = childValueStr.append("',"); } else { childValueStr = childValueStr.append("'"); } } if (isContinue) { continue; } string insertSql = ""; string selectSql = ""; string updateSelectSql = ""; string updateSql = ""; if (childColumnStr.size() > 0) { insertSql = insertSql.append(parentColumnStr).append(",").append(childColumnStr).append(")").append(parentValueStr).append(",").append(childValueStr).append(")"); } else { insertSql = insertSql.append(parentColumnStr).append(")").append(parentValueStr).append(")"); } selectSql = selectSql.append(selectStr).append(childSelectStr); updateSelectSql = updateSelectSql.append(selectAfterUpdateStr).append(childUpdateSelectStr); updateSql = updateSql.append(updateStr).append(updateWhere).append(childUpdateWhere); //updateStr = updateStr.append(updateWhere); insertSql = Utf8ToGbk(insertSql.c_str()); updateSql = Utf8ToGbk(updateSql.c_str()); selectSql = Utf8ToGbk(selectSql.c_str()); updateSelectSql = Utf8ToGbk(updateSelectSql.c_str()); WriteLog("工步资源插入语句:%s\n", insertSql.c_str()); //WriteLog("工步资源更新语句:%s\n", updateSql.c_str()); WriteLog("工步资源查询语句:%s\n", selectSql.c_str()); //WriteLog("工步资源更新后查询语句:%s\n", updateSelectSql.c_str()); insertVec.push_back(insertSql); updateVec.push_back(updateSql); selectVec.push_back(selectSql); selectAfterUpdateVec.push_back(updateSelectSql); char sendChar[400] = ""; strcpy(sendChar, insertSql.c_str()); char sendChar2[400] = ""; strcpy(sendChar2, selectSql.c_str()); int result = ado0.ado_QuerySQLNoInputParam(sendChar2); bool resultSql = ado0.executeInsert(sendChar2, sendChar, result); } } DOFREE(zy_occ_type); } } DOFREE(gb_occ_type); } //更新数据库 /*for (int i = 0; i < updateVec.size(); i++) { string updateSql = updateVec[i]; string selectSql = selectVec[i]; string insertSql = insertVec[i]; string selectUpdate = selectAfterUpdateVec[i]; char sendChar[200] = ""; char sendChar2[200] = ""; char sendChar3[200] = ""; strcpy(sendChar, updateSql.c_str()); strcpy(sendChar2, selectSql.c_str()); strcpy(sendChar3, selectUpdate.c_str()); int result = ado0.ado_QuerySQLNoInputParam(sendChar2); if (result == 0) { showError = true; WriteLog("工步资源插入失败:%s\n", insertSql.c_str()); } else { bool resultSql = ado0.execute2(sendChar2, sendChar, result); result = ado0.ado_QuerySQLNoInputParam(sendChar3); if (result == 0) { showError = true; WriteLog("工步资源更新失败:%s\n", updateSql.c_str()); } } }*/ } int JD_BOPInfoToMediDatabase(EPM_action_message_t msg) { bool showError = false; nowTime(); time_t now; struct tm* p; //获取当前时间 time(&now); //本地化时间,可以细分为年月日时分秒等 p = localtime(&now); createDir();//创建日志目录 char TC_LOG_FILE[128] = ""; // 把日志名称赋予给某变量 sprintf_s(TC_LOG_FILE, "%s\\tmplog\\JD_BOPInfoToMediDatabase_log_[%d-%d-%d-%d-%02d-%02d].txt", getenv("TEMP"), 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec); ECHO("创建日志文件[%s]\n", TC_LOG_FILE); CreateLogFile(TC_LOG_FILE); //流程节点相关 tag_t root_task = NULLTAG, * sub_tasks = NULL, current_task = NULLTAG, type_tag = NULLTAG; int arg_cnt = 0, ifail = 0; char arg1value[1024] = "";//物料类型 char* argflag = NULL, * argvalue = NULL, * arg = NULL; //得到触发此函数的节点 current_task = msg.task; WriteLog("=========================================================\n"); WriteLog("JD_BOPInfoToMediDatabase 开始执行\n"); WriteLog("=========================================================\n"); //获取handler的参数的个数 arg_cnt = TC_number_of_arguments(msg.arguments); WriteLog("参数个数为:%d\n", arg_cnt); if (arg_cnt > 0) { for (int i = 0; i < arg_cnt; i++) { //获取下一个参数(从0开始) arg = TC_next_argument(msg.arguments); //获取参数的名称和值 ITKCALL(ifail = ITK_ask_argument_named_value((const char*)arg, &argflag, &argvalue)); if (stricmp(argflag, "PartItem") == 0) { if (argvalue != NULL) { strcpy(arg1value, argvalue); } } } MEM_free(argflag); MEM_free(argvalue); } //先获取首选项Jd_MES_Info_Connect,解析其中的用户名,密码,配置文件等信息 vector pref_vec1, pref_vec2; getPrefStrings1("Jd_MES_Info_Connect", TC_preference_site, pref_vec1); getPrefStrings1("Jd_MES_FTP_Info_Connect", TC_preference_site, pref_vec2); string ip = pref_vec1[0]; string databaseName = pref_vec1[1]; string user = pref_vec1[2]; string password = pref_vec1[3]; string xmlUid1 = pref_vec1[4]; string xmlUid2 = pref_vec1[5]; string xmlUid3 = pref_vec1[6]; string xmlUid4 = pref_vec1[7]; string xmlUid5 = pref_vec1[8]; string xmlUid6 = pref_vec1[9]; string ftp_ip = pref_vec2[0]; string ftp_port = pref_vec2[1]; string username = pref_vec2[2]; string ftp_pwd = pref_vec2[3]; WriteLog("ip:%s\n", ip.c_str()); WriteLog("databaseName:%s\n", databaseName.c_str()); WriteLog("user:%s\n", user.c_str()); WriteLog("password:%s\n", password.c_str()); WriteLog("工艺路线工序明细表xmlUid:%s\n", xmlUid1.c_str()); WriteLog("工序工步关系表xmlUid:%s\n", xmlUid2.c_str()); WriteLog("工艺路线-工序属性表xmlUid:%s\n", xmlUid3.c_str()); WriteLog("工序工艺文件xmlUid:%s\n", xmlUid4.c_str()); WriteLog("工艺资源xmlUid:%s\n", xmlUid5.c_str()); WriteLog("工步资源 xmlUid:%s\n", xmlUid6.c_str()); WriteLog("FTP地址:%s\n", ftp_ip.c_str()); WriteLog("FTP端口:%s\n", ftp_port.c_str()); ado ado0; char userName[100]; strcpy(userName, user.c_str()); char pwd[100]; strcpy(pwd, password.c_str()); string info = "Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog="; info.append(databaseName).append(";Data Source=").append(ip); WriteLog("连接信息:%s\n", info.c_str()); bool log = ado0.open(userName, pwd, info.c_str()); //遍历map所有层级 string revType = arg1value; vector revTypeVec; Split(revType, ";", revTypeVec); int att_cnt = 0; tag_t* attachments = NULL; //获取根流程节点 tag_t task_tag = msg.task; tag_t rootTask_tag = NULL; ifail = EPM_ask_root_task(task_tag, &rootTask_tag); //获取目标引用对象 ifail = EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments); for (int i = 0; i < att_cnt; i++) { char* object_TYPE_1 = NULL; ifail = AOM_ask_value_string(attachments[i], "object_type", &object_TYPE_1);//对象类型 WriteLog("当前类型对象为 %s\n", object_TYPE_1); string partType = object_TYPE_1; if (hasElement(revTypeVec, partType) == 0) { //包含类型,连接数据库 if (log == false) { WriteLog("登录成功\n"); tag_t partItem = NULL; ITEM_ask_item_of_rev(attachments[i], &partItem); char* itemType = NULL; AOM_ask_value_string(partItem, "object_type", &itemType); //TODO 获取BOM结构 //获取版本下的bom视图 int bom_num = 0; tag_t* bom_tags = NULLTAG; AOM_ask_value_tags(attachments[i], "structure_revisions", &bom_num, &bom_tags); if (bom_num > 0) { tag_t only_bom = bom_tags[0]; tag_t bom_window_tag = NULLTAG, top_bom_line_tag = NULLTAG; map gx_cloneid_key; map gx_gb_key; map child_level1; map> gx_gbs_bom; map> level1_level2; map child_level2; map> gx_gb_zy; map main_flow; map line_info; ITKCALL(ifail = ME_create_bop_window(&bom_window_tag)); ITKCALL(ifail = BOM_set_window_top_line_bvr(bom_window_tag, only_bom, &top_bom_line_tag)); /*ITKCALL(ifail = BOM_create_window(&bom_window_tag)); ITKCALL(ifail = BOM_set_window_top_line_bvr(bom_window_tag, only_bom, &top_bom_line_tag));*/ loadBom(top_bom_line_tag, child_level1, level1_level2, child_level2, gx_gbs_bom, gx_gb_zy, main_flow, line_info); map::iterator it1; for (it1 = child_level1.begin(); it1 != child_level1.end(); it1++) { WriteLog("工序clone:%s\n", it1->first.c_str()); } map>::iterator it2; for (it2 = gx_gbs_bom.begin(); it2 != gx_gbs_bom.end(); it2++) { WriteLog("工序clone:%s,工部数量:%d\n", it2->first.c_str(), it2->second.size()); } map>::iterator it3; for (it3 = level1_level2.begin(); it3 != level1_level2.end(); it3++) { int cnt = it3->second.size(); for (int f = 0; f < cnt; f++) { WriteLog("工序clone:%s,工序下级clone:%s\n", it3->first.c_str(), it3->second[f].c_str()); } } map::iterator it4; for (it4 = child_level2.begin(); it4 != child_level2.end(); it4++) { WriteLog("工序下级clone:%s\n", it4->first.c_str()); } map>::iterator it5; for (it5 = gx_gb_zy.begin(); it5 != gx_gb_zy.end(); it5++) { WriteLog("工序clone及工部uid:%s,工部资源数量:%d\n", it5->first.c_str(), it5->second.size()); } map::iterator it5_5; for (it5_5 = main_flow.begin(); it5_5 != main_flow.end(); it5_5++) { WriteLog("主路线工序clone:%s\n", it5_5->first.c_str()); } map::iterator it5_6; for (it5_6 = line_info.begin(); it5_6 != line_info.end(); it5_6++) { WriteLog("工序clone:%s,前驱:%s,后驱:%s\n", it5_6->first.c_str(), it5_6->second.pre_id.c_str(), it5_6->second.suc_id.c_str()); } insertGyGxBom(xmlUid1, showError, ado0, top_bom_line_tag, partItem, attachments[i], child_level1, gx_cloneid_key, main_flow, line_info); map::iterator it6; for (it6 = gx_cloneid_key.begin(); it6 != gx_cloneid_key.end(); it6++) { WriteLog("工序gx_cloneid_key,key:%s,val:%s\n", it6->first.c_str(), it6->second.c_str()); } insertGxGb(xmlUid2, showError, ado0, child_level1, gx_cloneid_key, gx_gbs_bom, gx_gb_key); map::iterator it7; for (it7 = gx_gb_key.begin(); it7 != gx_gb_key.end(); it7++) { WriteLog("工序gx_gb_key,key:%s,val:%s\n", it7->first.c_str(), it7->second.c_str()); } insertGyGxProp(xmlUid3, showError, ado0, top_bom_line_tag, partItem, attachments[i], child_level1, gx_cloneid_key); insertGyGxGywj(xmlUid4, ftp_ip, ftp_port, username, ftp_pwd, showError, ado0, top_bom_line_tag, partItem, attachments[i], child_level1, level1_level2, child_level2); insertGyGxGyzy(xmlUid5, showError, ado0, top_bom_line_tag, partItem, attachments[i], child_level1, level1_level2, child_level2); insertGbzy(xmlUid6, showError, ado0, child_level1, gx_gb_key, gx_gbs_bom, gx_gb_zy); ITKCALL(ifail = ME_close_bop_window(bom_window_tag));//有开必有关 //ITKCALL(ifail = BOM_close_window(bom_window_tag));//有开必有关 } DOFREE(bom_tags); } else { WriteLog("登录失败====\n"); } } DOFREE(object_TYPE_1); } ado0.close(); //EMH_clear_errors(); DOFREE(attachments); //if (showError == true) { // string logName = "数据异常,详见服务器日志:"; // logName = logName.append(TC_LOG_FILE); // EMH_store_error_s1(EMH_severity_warning, EMH_AE_error_base, logName.c_str()); //} WriteLog("=========================================================\n"); WriteLog("JD_BOPInfoToMediDatabase 完成\n"); WriteLog("=========================================================\n"); return 0; }