From 161e19925cedb87a0b6db5b48cb6335e4f3df5fd Mon Sep 17 00:00:00 2001 From: "lidy@connor.net.cn" Date: Fri, 19 Apr 2024 10:29:46 +0800 Subject: [PATCH] =?UTF-8?q?20240419lidy=E4=BB=A3=E7=A0=81=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- General/General/CHINT_DRAWING_TO_SRM.cpp | 211 +++ .../General/CRUL_server_call_httpserver.cpp | 8 +- General/General/CloneProcess.cpp | 9 +- General/General/CloneProcess0.cpp | 1407 ++++++++++++++++ General/General/CloneProcess1.cpp | 1408 +++++++++++++++++ General/General/DtoEBOM2.cpp | 73 +- General/General/EbomToPMethod.cpp | 115 +- General/General/General.vcxproj | 4 + General/General/General.vcxproj.filters | 12 + General/General/chint_changenotice.cpp | 328 ++++ .../General/chint_check_materialstatus.cpp | 299 ++++ General/General/connor_sign_pdf.cpp | 424 ++--- General/General/epm_handler_common.h | 4 + General/General/epm_register_handler.cpp | 72 +- General/General/tc_log.cxx | 157 ++ General/General/tc_log.h | 15 +- 16 files changed, 4234 insertions(+), 312 deletions(-) create mode 100644 General/General/CHINT_DRAWING_TO_SRM.cpp create mode 100644 General/General/CloneProcess0.cpp create mode 100644 General/General/CloneProcess1.cpp create mode 100644 General/General/chint_changenotice.cpp create mode 100644 General/General/chint_check_materialstatus.cpp create mode 100644 General/General/tc_log.cxx diff --git a/General/General/CHINT_DRAWING_TO_SRM.cpp b/General/General/CHINT_DRAWING_TO_SRM.cpp new file mode 100644 index 0000000..ac807cf --- /dev/null +++ b/General/General/CHINT_DRAWING_TO_SRM.cpp @@ -0,0 +1,211 @@ +#include "cJSON.h" + +#include +#include "epm_handler_common.h" +#include +#include +#include +#include +#include +#include +#include +#include "ps/ps.h"; +#include "ps/vrule.h" +#include "sstream" +#include +#include "epm/epm.h" +#include "sa/sa.h" +#include "libxl.h" +#include +#include "epm/signoff.h" +#include +#include +#include +#include +#include "ae/dataset.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "chint_Handler.h" +#include +#include +#include "ado.h" +#include "ocilib.h" +#include +#include "CRUL_server_call_httpserver.h" +#include "common_itk_util.h" +#define EPM_HANDLER_COMMON +#define MAX_PATH_LENGTH 200 +#define MAX_PRINTLINE_LENGTH 400000 +void WriteLog3(logical debug, const char* format, ...) +{ + va_list arg; + char tmp[MAX_PRINTLINE_LENGTH]; + char date_string[MAX_PATH_LENGTH]; + time_t now; + struct tm* p; + + //get the message + memset(tmp, 0, sizeof(tmp)); + va_start(arg, format); + vsprintf(tmp, format, arg); + va_end(arg); + //----------print to command window for trace--------// + //printf("%s\n", tmp); + printf("%s\n", tmp); + //print message to log file + TC_write_syslog("%s\n", tmp); +} +int CHINT_DRAWING_TO_SRM(EPM_action_message_t msg) { + + tag_t task_tag = NULL_TAG, + root_task_tag = NULLTAG, + * attachments;; + task_tag = msg.task; + int att_cnt = 0, ifail = 0; + int c_sql_value_count = 0; + char** c_sql_values; + ITKCALL(PREF_ask_char_values("CHINT_SRM_SQL_CONNECT", &c_sql_value_count, &c_sql_values)); + + WriteLog3(true, "------------------------------------------------------------------------------------"); + WriteLog3(true, "========================="); + WriteLog3(true, "CHINT_SRM_SQL_CONNECT start"); + WriteLog3(true, "========================="); + + EPM_ask_root_task(task_tag, &root_task_tag); + EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnt, &attachments); + WriteLog3(true, "流程目标下的对象数量:%d", att_cnt); + for (int i = 0; i < att_cnt; i++) + { + tag_t tagt = NULLTAG; + tagt = attachments[i]; + char* type1; + //获取版本下的数据集 + int dataset_num = 0; + tag_t* dataset_tags = NULL; + char* tempValue = NULL; + char taskpuid[56] = "\0"; + ITK__convert_tag_to_uid(task_tag, &tempValue); + tc_strcpy(taskpuid, tempValue); + ITKCALL(AOM_ask_value_string(tagt, "object_type", &type1)); + printf("object_type=%s\n", type1); + //获取当前登入人组 + char* groupName = NULL; + tag_t t_group = NULLTAG; + ITKCALL(POM_ask_group(&groupName, &t_group)); + printf("g=%s\n", groupName); + //获取当前登入人的名称和id + char* name; + char* id; + tag_t user; + POM_get_user(&name, &user); + POM_get_user_id(&id); + printf("name================%s\n", name); + printf("id================%s\n", id); + + + + if (strcmp("ZT2_ProcureRevision", type1) == 0) { + //判断是否存在dwg文件 + //获取版本下的数据集 + + + char* file_name; + char* origin_file_name; + tag_t* ref_object = NULL; + int n_found = 0; + ITKCALL(AOM_ask_value_tags(tagt, "IMAN_specification", &dataset_num, &dataset_tags)); + + + + for (int k = 0; k < dataset_num; k++) + { + + ITKCALL(AOM_ask_value_string(dataset_tags[k], "object_name", &file_name)); + printf("file_name=%s\n", file_name); + if (strstr(file_name, "pdf") || strstr(file_name, "PDF")) { + //获取数据集文件名称 + ITKCALL(AOM_ask_value_string(dataset_tags[k], "current_name", &origin_file_name)); + ITKCALL(AE_ask_dataset_named_refs(dataset_tags[k], &n_found, &ref_object)); + printf("n_found=%d\n", n_found); + if (n_found > 0) { + //存在.dwg数据集 + //DFL_ DRAWING_TO_SRM_TASK存储信息 + + if (ConnServer(c_sql_values[1], c_sql_values[2], c_sql_values[0]))//"tc11","infodba","//172.16.50.40/tc11" "TC12","infodba","172.16.68.13/tc1" + { + printf("提示:中间数据表访问失败\n"); + return ifail; + } + else { + printf("提示:中间数据表访问成功\n"); + char sql1[1024] = "\0"; + + + sprintf(sql1, "insert into CHINT_DRAWING_TO_SRM_TASK(tasksource,flowid,status,factory,username,userid) values ('%s','%s','%s','%s','%s','%s')", "工作流程", taskpuid, "未开始", groupName, name, id); + printf("提示:sql1==%s\n", sql1); + if (ExecuteSQLNoInputParam(sql1) == -1) + { + printf("提示:数据插入 失败, %s \n", sql1); + ifail = 1; + } + else { + ExecuteSQLNoInputParam("commit"); + } + break; + } + } + } + } + break;//如果发起多个对象,只写一条数据 + } + else if (strcmp("ZT2_Design3DRevision", type1) == 0) { + + //判断是否存在物料 + int material_num = 0; + tag_t* material_tags = NULL; + ITKCALL(AOM_ask_value_tags(tagt, "representation_for", &material_num, &material_tags)); + if (material_num > 0) { + if (ConnServer(c_sql_values[1], c_sql_values[2], c_sql_values[0]))//"tc11","infodba","//172.16.50.40/tc11" "TC12","infodba","172.16.68.13/tc1" + { + printf("提示:中间数据表访问失败\n"); + return ifail; + } + else { + printf("提示:中间数据表访问成功\n"); + char sql1[1024] = "\0"; + sprintf(sql1, "insert into CHINT_DRAWING_TO_SRM_TASK(tasksource,flowid,status,factory,username,userid) values ('%s','%s','%s','%s','%s','%s')", "工作流程", taskpuid, "未开始", groupName, name, id); + printf("提示:sql1==%s\n", sql1); + if (ExecuteSQLNoInputParam(sql1) == -1) + { + printf("提示:数据插入 失败, %s \n", sql1); + ifail = 1; + } + else { + ExecuteSQLNoInputParam("commit"); + } + break; + } + } + } + + + } + + if (ifail == 1) + { + EMH_store_error_s1(EMH_severity_user_error, EMH_USER_error_base, "插入数据失败\n"); //错误弹窗 + } + DOFREE(attachments); + WriteLog3(true, "========================="); + WriteLog3(true, "DFL_DRAWING_TO_SRM end"); + WriteLog3(true, "========================="); + return ifail; +} \ No newline at end of file diff --git a/General/General/CRUL_server_call_httpserver.cpp b/General/General/CRUL_server_call_httpserver.cpp index 0b1af7d..543f862 100644 --- a/General/General/CRUL_server_call_httpserver.cpp +++ b/General/General/CRUL_server_call_httpserver.cpp @@ -17,6 +17,7 @@ string callHttpserver(string signinfoJsonString, string url){ CURLcode res; curl = curl_easy_init(); std::stringstream out; + string result = ""; if (curl) { curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); @@ -32,13 +33,18 @@ string callHttpserver(string signinfoJsonString, string url){ res = curl_easy_perform(curl); if (res != 0) { string errMessage = curl_easy_strerror(res); + result.append("errMessage =>").append(errMessage); } printf("返回值:%d\n", res); + char code[16] = ""; + sprintf(code, "%d", res); + result.append("\n返回值 =>").append(code); } string str_json = out.str(); curl_easy_cleanup(curl); printf("str_json===>%s\n", str_json.c_str()); - return str_json; + result.append("\nstr_json =>").append(str_json); + return result; } string sendOA() { diff --git a/General/General/CloneProcess.cpp b/General/General/CloneProcess.cpp index 6ce52ea..887ebbe 100644 --- a/General/General/CloneProcess.cpp +++ b/General/General/CloneProcess.cpp @@ -185,13 +185,13 @@ string getCshVal(string name,string code) { string schVal = ""; //cmd指令 char cmd[256] = ""; - strcpy(cmd, "java -jar \""); + strcpy(cmd, "java -jar "); //strcat(cmd, jar_file); strcat(cmd, getenv("TC_ROOT")); strcat(cmd, "\\bin\\findCshSql.jar"); - strcat(cmd, "\" "); + strcat(cmd, "\" \""); strcat(cmd, name.c_str()); - strcat(cmd, "\" "); + strcat(cmd, "\" \""); strcat(cmd, code.c_str()); printf("路径:\n%s\n", cmd); char buf[8000] = { 0 }; @@ -311,7 +311,8 @@ void setZljyx(string gxbm2, string th,string lastId,string name,tag_t towGx) { } } else if (!parameterization.empty()) { - string csh = getCshVal(lastId, code); + //string csh = getCshVal(lastId, code); + string csh = getCshVal(lastId, parameterization); bean.mentResult = csh; } } diff --git a/General/General/CloneProcess0.cpp b/General/General/CloneProcess0.cpp new file mode 100644 index 0000000..6ce52ea --- /dev/null +++ b/General/General/CloneProcess0.cpp @@ -0,0 +1,1407 @@ +#include +#include "epm_handler_common.h" +#include +#include +#include +#include +#include +#include +#include +#include "ps/ps.h"; +#include "ps/vrule.h" +#include "sstream" +#include +#include "epm/epm.h" +#include "sa/sa.h" +#include "libxl.h" +#include +#include "epm/signoff.h" +#include +#include +#include +#include +#include "ae/dataset.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// #include "hx_custom.h" +#include "tc_log.h" +// #include "jk_custom.h" +#include "chint_Handler.h" +#include "tc_util.h" +#include +#include +#include "ocilib.h" +#include +#include +#include +#include +#include +#include +using namespace std; + +typedef struct { + string cpxh;//产品型号 低、中、高、调、稳 + string dyxq; + string zyxq; + string gyxq; + string tyxq; + string wyxq; +}ByqBean; +typedef struct { + string rgsj;//产品型号 低、中、高、调、稳 + string jqsj; + string zbsj; + string zrsczq; +}TimeBean; +typedef struct { + string temGxCode; + string temGxName; + +}TemGxBean; +struct FlBean +{ + tag_t flTag=NULLTAG; + string blQty; +}; +string getCshVal(string name, string code); + +string sqlProTime = "select GYNAME,GXNAME from CHINT_WORKHOUR where \"PRODUCTXH\" = '%s' and GYID = '%s' and COMPANYCODE ='M060' and \"ProCycle\"<1 "; +string sqlProTime2 = "select GYNAME,GXNAME from CHINT_WORKHOUR where \"PRODUCTXH\" = '%s' and GYID = '%s' and JSASK = '%s' and COMPANYCODE ='M060' and \"ProCycle\"<1 "; + +string sqlRxfs = "select \"TarGXCODE\", \"TarGXNAME\", \"TemGXCODE\", \"TemGXNAME\" from \"CHINT_WORKHOUR_WhGXName\" where \"WindStyle\" = '%s' and COMPANYCODE ='M060'"; +string sqlGyRule = "select GYID from \"CHINT_WORKHOUR_WhGYRule\" where \"ProductZu\" = '%s' and \"TuHao\" = '%s' and COMPANYCODE ='M060'"; +string sqlCpxh = "SELECT \"ProductZu\" FROM \"CHINT_WORKHOUR_WhProductXH\" where \"ProductXH\" = '%s' and COMPANYCODE ='M060' "; +string sqlGxTime = "select GXCODE,ARTIFICIALTIME,MACHINETIME,READINESSTIME,\"ProCycle\" from CHINT_WORKHOUR where \"PRODUCTXH\" = '%s' and GYID = '%s' and COMPANYCODE ='M060'"; +string sqlGxTime2 = "select GXCODE,ARTIFICIALTIME,MACHINETIME,READINESSTIME,\"ProCycle\" from CHINT_WORKHOUR where \"PRODUCTXH\" = '%s' and GYID = '%s' and JSASK = '%s' and COMPANYCODE ='M060'"; +void save_representation2(tag_t primaryTag, tag_t secondTag, char* relationType) +{ + tag_t typeTag = NULLTAG; + ITKCALL(GRM_find_relation_type(relationType, &typeTag)); + + ITKCALL(AOM_refresh(primaryTag, TRUE)); + ITKCALL(AOM_refresh(secondTag, TRUE)); + tag_t relationTag = NULLTAG; + ITKCALL(GRM_create_relation(primaryTag, secondTag, typeTag, NULLTAG, &relationTag));//如果关系已经存在,那么就是增加对象 + + ITKCALL(GRM_save_relation(relationTag));//很必要 + ITKCALL(AOM_save(primaryTag)); + ITKCALL(AOM_save(secondTag)); + ITKCALL(AOM_refresh(primaryTag, FALSE)); + ITKCALL(AOM_refresh(secondTag, FALSE)); +} +void updateTemGxCode(tag_t processTag, map temGxMap) { + int bvr_count = 0; + tag_t ebom_window = NULLTAG; + tag_t bom_line = NULLTAG; + tag_t item_tag = NULLTAG, *c_line_tags; + ITKCALL(BOM_create_window(&ebom_window)); + tag_t* bvr_list = NULL; + ITKCALL(ITEM_rev_list_bom_view_revs(processTag, &bvr_count, &bvr_list)); + printf("bvr_count=%d", bvr_count); + + ITKCALL(BOM_set_window_top_line_bvr(ebom_window, bvr_list[0], &bom_line)); //顶层bom获取 + //bom_line工艺 + int c_line_count; + ITKCALL(BOM_line_ask_all_child_lines(bom_line, &c_line_count, &c_line_tags)); // 一级工序 + for (int i = 0; i < c_line_count; i++) { + tag_t oneGxLine = c_line_tags[i], *towGxLines, oneGx, gxItem; + char* gxbm1; + AOM_ask_value_string(oneGxLine, "bl_ZT2_FirstOPRevision_zt2_ClassificationCode", &gxbm1); + + printf("gxbm1===>%s\n", gxbm1); + if (temGxMap.count(gxbm1) > 0) { + char* oldName; + TemGxBean temGxBean = temGxMap[gxbm1]; + ITKCALL(AOM_lock(oneGxLine)); + ITKCALL(AOM_set_value_string(oneGxLine, "bl_ZT2_FirstOPRevision_zt2_ClassificationCode", temGxBean.temGxCode.c_str())); + ITKCALL(AOM_save(oneGxLine)); + AOM_unlock(oneGxLine); + ITKCALL(AOM_ask_value_tag(oneGxLine, "bl_line_object", &oneGx)); + ITKCALL(ITEM_ask_item_of_rev(oneGx, &gxItem)); + ITKCALL(AOM_lock(gxItem)); + ITKCALL(AOM_ask_value_string(gxItem, "object_name", &oldName)); + ITKCALL(AOM_set_value_string(gxItem, "object_name", temGxBean.temGxName.c_str())); + ITKCALL(AOM_save(gxItem)); + ITKCALL(AOM_unlock(gxItem)); + ITKCALL(AOM_lock(oneGx)); + ITKCALL(AOM_set_value_string(oneGx, "object_name", temGxBean.temGxName.c_str())); + ITKCALL(AOM_save(oneGx)); + ITKCALL(AOM_unlock(oneGx)); + printf("oldName===>%s\n", oldName); + printf("temGxName===>%s\n", temGxBean.temGxName.c_str()); + printf("temGxCode===>%s\n", temGxBean.temGxCode.c_str()); + } + + int c_cnt = 0; + BOM_line_ask_all_child_lines(oneGxLine, &c_cnt, &towGxLines); + for (int j = 0; j < c_cnt; j++) { + tag_t towGxLine = towGxLines[j]; + tag_t towGx, gxItem2; + char* gxbm2; + ITKCALL(AOM_ask_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ClassificationCode", &gxbm2)); + + printf("gxbm2===>%s\n", gxbm2); + if (temGxMap.count(gxbm2) > 0) { + TemGxBean temGxBean = temGxMap[gxbm2]; + AOM_lock(towGxLine); + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ClassificationCode", temGxBean.temGxCode.c_str())); + AOM_save(towGxLine); + AOM_unlock(towGxLine); + char* oldName, *oldName2; + ITKCALL(AOM_ask_value_tag(towGxLine, "bl_line_object", &towGx)); + ITKCALL(ITEM_ask_item_of_rev(towGx, &gxItem2)); + ITKCALL(AOM_lock(gxItem2)); + ITKCALL(AOM_ask_value_string(gxItem2, "object_name", &oldName)); + ITKCALL(AOM_set_value_string(gxItem2, "object_name", temGxBean.temGxName.c_str())); + ITKCALL(AOM_save(gxItem2)); + ITKCALL(AOM_unlock(gxItem2)); + ITKCALL(AOM_ask_value_string(gxItem2, "object_name", &oldName2)); + printf("oldName===>%s\n", oldName); + printf("oldName2===>%s\n", oldName2); + printf("temGxName===>%s\n", temGxBean.temGxName.c_str()); + printf("temGxCode===>%s\n", temGxBean.temGxCode.c_str()); + ITKCALL(AOM_lock(towGx)); + ITKCALL(AOM_set_value_string(towGx, "object_name", temGxBean.temGxName.c_str())); + ITKCALL(AOM_save(towGx)); + ITKCALL(AOM_unlock(towGx)); + + } + + } + } + BOM_close_window(ebom_window); +} +string getCshVal(string name,string code) { + + string strResult; + string schVal = ""; + //cmd指令 + char cmd[256] = ""; + strcpy(cmd, "java -jar \""); + //strcat(cmd, jar_file); + strcat(cmd, getenv("TC_ROOT")); + strcat(cmd, "\\bin\\findCshSql.jar"); + strcat(cmd, "\" "); + strcat(cmd, name.c_str()); + strcat(cmd, "\" "); + strcat(cmd, code.c_str()); + printf("路径:\n%s\n", cmd); + char buf[8000] = { 0 }; + FILE* pf = NULL; + if ((pf = _popen(cmd, "r")) == NULL) { + printf("接口返回:\n%s", "1"); + } + + while (fgets(buf, sizeof buf, pf)) { + strResult += buf; + } + _pclose(pf); + vector vec; + Split(strResult,"CSHVAL:[",vec); + if (vec.size() > 0) { + Split(vec[1], "]", vec); + schVal = vec[0]; + } + + return schVal; +} +string getJdbVal(string name,string yqz,string checkcode,string draw,string modelVersion,string code,string checkCode) { + string drawingno = draw.append("-").append(name); + string getCode = "select checkno,NUMBEROFCHECKS from CHINT_CHECK_TITLE WHERE drawingno = '%s' and modelversion='%s' order by NUMBEROFCHECKS desc "; + string getNo = "select NO from CHINT_CHECK_DETAILS_TEMPLATE where code ='%s' and modelversion = '%s' and checkCode = '%s' "; + string val = ""; + char selectRxfs[500]; + sprintf(selectRxfs, getNo.c_str(), code.c_str(), modelVersion.c_str(), checkCode.c_str()); + int outputColumn1 = 0, outputValueCount1 = 0; + char*** outputValue1 = NULL; + QuerySQLNoInputParam(selectRxfs, &outputColumn1, &outputValueCount1, &outputValue1); + printf("selectRxfs ===>%s\n", selectRxfs); + if (outputValueCount1 > 0) { + string no = outputValue1[0][0]; + char selectRxfs2[500]; + outputValueCount1 = 0; + outputColumn1 = 0; + outputValue1 = NULL; + sprintf(selectRxfs2, getCode.c_str(), drawingno.c_str(), modelVersion.c_str()); + printf("selectRxfs2 ===>%s\n", selectRxfs2); + QuerySQLNoInputParam(selectRxfs2, &outputColumn1, &outputValueCount1, &outputValue1); + if (outputValueCount1 > 0) { + string checkNo = outputValue1[0][0]; + string numofCheck = outputValue1[0][1]; + string getNo = "select %s from CHINT_CHECK_DETAILS where no ='%s' and NUMBEROFCHECKS = '%s' and checkno = '%s' and modelversion = '%s' "; + char selectRxfs3[500]; + sprintf(selectRxfs3, getNo.c_str(), yqz.c_str(), no.c_str(), numofCheck.c_str(), checkNo.c_str(), modelVersion.c_str()); + printf("selectRxfs3 ===>%s\n", selectRxfs3); + + int outputColumn2 = 0, outputValueCount2 = 0; + char*** outputValue2 = NULL; + QuerySQLNoInputParam(selectRxfs3, &outputColumn2, &outputValueCount2, &outputValue2); + if (outputValueCount1 > 0) { + val = outputValue2[0][0]; + } + } + } + return val; +} +typedef struct { + string no;//产品型号 低、中、高、调、稳 + string mentNo; + string mentDesc; + string mentResult; +}JYXBean; +void setZljyx(string gxbm2, string th,string lastId,string name,tag_t towGx) { + + string code; + printf("th == >%s \n", th.c_str()); + if (strstr(th.c_str(),"-") != NULL) { + vector vec; + Split(th, "-", vec); + code.append(vec[0]).append("-").append("X"); + } + else { + code = th; + } + printf("code == >%s \n", code.c_str()); + string sql = "select cqmodelnno,drawingno,cqmanagementno,cqmanagementdesc,cqmanagementresult,datasource, checkline, checkcode, parameterization, code, modelversion from CHINT_QUALITY_MANAGEMENT_SYSTEM where cpcmcode like '%s' and cdrawingno = '%s' order by cqmodelnno asc"; + char selectRxfs[500]; + string gxbmMsg; + gxbmMsg.append("%").append(gxbm2).append("%"); + sprintf(selectRxfs, sql.c_str(), gxbmMsg.c_str(), code.c_str()); + int outputColumn1 = 0, outputValueCount1 = 0; + char*** outputValue1 = NULL; + printf("search3 ===> %s\n", selectRxfs); + QuerySQLNoInputParam(selectRxfs, &outputColumn1, &outputValueCount1, &outputValue1); + printf("search result ===> %d\n", outputValueCount1); + vector< JYXBean> beans; + + for (int num = 0; num < outputValueCount1; num++) { + //TarGXCODE\", \"TarGXNAME\", \"TemGXCODE\", \"TemGXNAME + JYXBean bean; + string cqmodelnno = outputValue1[num][0]; //序号 + string drawingno = outputValue1[num][1]; //校对表图号 + string cqmanagementno = outputValue1[num][2]; //属性no + string cqmanagementdesc = outputValue1[num][3]; //属性描述 + string cqmanagementresult = outputValue1[num][4]; //属性 + string datasource = outputValue1[num][5]; //校对表或参数化 + string checkline = outputValue1[num][6]; // 要求值,设计值 designresult,PROOFREADRESULT + string checkcode = outputValue1[num][7]; //checkcode + string parameterization = outputValue1[num][8]; //code + string code = outputValue1[num][9]; //校对表模板 + string modelversion = outputValue1[num][10]; //校对表模板版本 + bean.mentDesc = cqmanagementdesc; + bean.mentNo = cqmanagementno; + bean.no = cqmodelnno; + if (cqmanagementresult.empty()) { + + if (datasource.compare("校对表") == 0) { + // string getCode = "select code,NUMBEROFCHECKS from CHINT_CHECK_TITLE WHERE drawingno = '?' order by NUMBEROFCHECKS desc "; + if (checkline.compare("要求值") == 0 && !checkcode.empty()) { + bean.mentResult = getJdbVal(lastId,"designresult", checkcode, drawingno, modelversion,code, checkcode); //designresult,PROOFREADRESULT + } + else if (checkline.compare("设计值") == 0 && !checkcode.empty()) { + bean.mentResult = getJdbVal(lastId, "PROOFREADRESULT", checkcode, drawingno, modelversion, code, checkcode); + } + } + else if (!parameterization.empty()) { + string csh = getCshVal(lastId, code); + bean.mentResult = csh; + } + } + else { + bean.mentResult = cqmanagementresult; + } + beans.push_back(bean); + } + tag_t item, rev; + string objName = "质量检验-"; + objName.append(name); + + if (beans.size()>0) { + tag_t *tableRow; + ITKCALL(ITEM_create_item(NULL, objName.c_str(), "ZT2_QCHECK", NULL, &item, &rev)); + ITKCALL(AOM_save(item)); + ITKCALL(AOM_save(rev)); + ITKCALL(AOM_lock(item)); + ITKCALL(AOM_lock(rev)); + ITKCALL(AOM_insert_table_rows(rev, "zt2_QCHECKS", 0, beans.size(), &tableRow)); + ITKCALL(AOM_save(rev)); + ITKCALL(AOM_unlock(rev)); + ITKCALL(AOM_save(item)); + ITKCALL(AOM_unlock(item)); + for (int i = 0; i < beans.size(); i++) { + tag_t table = tableRow[i]; + ITKCALL(AOM_lock(table)); + ITKCALL(AOM_set_value_string(table,"zt2_code", beans[i].no.c_str())); + ITKCALL(AOM_set_value_string(table, "zt2_jjxbh", beans[i].mentNo.c_str())); + ITKCALL(AOM_set_value_string(table, "zt2_jyxmc", beans[i].mentDesc.c_str())); + ITKCALL(AOM_set_value_string(table, "zt2_jyxsjjg", beans[i].mentResult.c_str())); + ITKCALL(AOM_save(table)); + ITKCALL(AOM_unlock(table)); + } + ITKCALL(AOM_save(towGx)); + save_representation2(towGx, item, "ZT2_QualityCheckRelation"); + } + +} +void getGxbmMap(tag_t processTag, map& gxDocMap, map timebeans, + map> flBeanMap,string th,string lastId) { + int bvr_count = 0; + tag_t ebom_window = NULLTAG; + tag_t bom_line = NULLTAG; + tag_t item_tag = NULLTAG, *c_line_tags; + ITKCALL(BOM_create_window(&ebom_window)); + tag_t* bvr_list = NULL; + ITKCALL(ITEM_rev_list_bom_view_revs(processTag, &bvr_count, &bvr_list)); + printf("bvr_count=%d", bvr_count); + + ITKCALL(BOM_set_window_top_line_bvr(ebom_window, bvr_list[0], &bom_line)); //顶层bom获取 + //bom_line工艺 + int c_line_count; + ITKCALL(BOM_line_ask_all_child_lines(bom_line, &c_line_count, &c_line_tags)); // 一级工序 + + //修改工时 + for (int i = 0; i < c_line_count; i++) { + tag_t oneGx = c_line_tags[i], *towGxLines; + char* gxbm1; + ITKCALL(AOM_ask_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_ClassificationCode", &gxbm1)); + if (timebeans.count(gxbm1) > 0) { + ITKCALL(AOM_lock(oneGx)); + TimeBean tbean = timebeans[gxbm1]; + ITKCALL(AOM_set_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_ArtificialTime", tbean.rgsj.c_str())); + ITKCALL(AOM_set_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_MachineTime", tbean.jqsj.c_str())); + ITKCALL(AOM_set_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_ReadinessTime", tbean.zbsj.c_str())); + ITKCALL(AOM_set_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_ProCycle", tbean.zrsczq.c_str())); + ITKCALL(AOM_save(oneGx)); + ITKCALL(AOM_unlock(oneGx)); + } + int c_cnt = 0; + ITKCALL(BOM_line_ask_all_child_lines(oneGx, &c_cnt, &towGxLines)); + for (int j = 0; j < c_cnt; j++) { + tag_t towGxLine = towGxLines[j]; + tag_t towGx; + char* gxbm2; + ITKCALL(AOM_ask_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ClassificationCode", &gxbm2)); + if (timebeans.count(gxbm2) > 0) { + ITKCALL(AOM_lock(towGxLine)); + TimeBean tbean = timebeans[gxbm2]; + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ArtificialTime", tbean.rgsj.c_str())); + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_MachineTime", tbean.jqsj.c_str())); + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ReadinessTime", tbean.zbsj.c_str())); + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ProCycle", tbean.zrsczq.c_str())); + ITKCALL(AOM_save(towGxLine)); + ITKCALL(AOM_unlock(towGxLine)); + } + char* name = NULL; + ITKCALL(AOM_ask_value_tag(towGxLine, "bl_line_object", &towGx)); + ITKCALL(AOM_ask_value_string(towGx, "object_name", &name)); + //设置质检项 + setZljyx(gxbm2,th, lastId, name, towGx); + if (flBeanMap.count(gxbm2) > 0) { + vector beansVec = flBeanMap[gxbm2]; + printf("beansVec===>%zd\n", beansVec.size()); + if (beansVec.size() > 0) { + tag_t axqPmatnr; + ITKCALL(AOM_ask_value_tag(towGxLine, "bl_line_object", &axqPmatnr)); + ITKCALL(ITEM_rev_list_bom_view_revs(axqPmatnr, &bvr_count, &bvr_list)); + printf("bvr_count=%d\n", bvr_count); + if (bvr_count == 0) { + tag_t newView, newViewBvr, pitem; + ITKCALL(ITEM_ask_item_of_rev(axqPmatnr, &pitem)); + ITKCALL(PS_create_bom_view(NULL, NULL, NULL, pitem, &newView)); + ITKCALL(AOM_save(newView)); + ITKCALL(PS_create_bvr(newView, NULL, NULL, FALSE, axqPmatnr, &newViewBvr)); + ITKCALL(AOM_save(newViewBvr)); + ITKCALL(AOM_save(axqPmatnr)); + } + } + //投辅料 + for (int n = 0; n < beansVec.size(); n++) { + tag_t cLine; + FlBean cBean = beansVec[n]; + if (cBean.flTag == NULLTAG) { + continue; + } + ITKCALL(BOM_line_add(towGxLine, NULL, cBean.flTag, NULL, &cLine)); + ITKCALL(AOM_lock(cLine)); + string num = cBean.blQty; + ITKCALL(AOM_set_value_string(cLine, "bl_quantity", num.c_str())); + string seqNo = to_string((n + 1) * 10); + ITKCALL(AOM_set_value_string(cLine, "bl_sequence_no", seqNo.c_str())); + ITKCALL(AOM_set_value_string(cLine, "bl_occ_type", "ZT2_FuLiao")); + ITKCALL(AOM_save(cLine)); + //最后unlock + ITKCALL(AOM_unlock(cLine)); + ITKCALL(AOM_refresh(cLine, FALSE)); + } + + } + + gxDocMap[gxbm2] = towGx; + } + } + ITKCALL(BOM_save_window(ebom_window)); + ITKCALL(BOM_close_window(ebom_window)); +} +void getGxbmMap(tag_t processTag, map& gxDocMap, map timebeans) { + int bvr_count = 0; + tag_t ebom_window = NULLTAG, bom_line = NULLTAG, item_tag = NULLTAG, *c_line_tags = NULLTAG; + ITKCALL(BOM_create_window(&ebom_window)); + tag_t* bvr_list = NULL; + ITKCALL(ITEM_rev_list_bom_view_revs(processTag, &bvr_count, &bvr_list)); + printf("bvr_count=%d", bvr_count); + + ITKCALL(BOM_set_window_top_line_bvr(ebom_window, bvr_list[0], &bom_line)); //顶层bom获取 + //bom_line工艺 + int c_line_count; + ITKCALL(BOM_line_ask_all_child_lines(bom_line, &c_line_count, &c_line_tags)); // 一级工序 + + for (int i = 0; i < c_line_count; i++) { + tag_t oneGx = c_line_tags[i], *towGxLines; + char* gxbm1; + ITKCALL(AOM_ask_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_ClassificationCode", &gxbm1)); + if (timebeans.count(gxbm1) > 0) { + ITKCALL(AOM_lock(oneGx)); + TimeBean tbean = timebeans[gxbm1]; + ITKCALL(AOM_set_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_ArtificialTime", tbean.rgsj.c_str())); + ITKCALL(AOM_set_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_MachineTime", tbean.jqsj.c_str())); + ITKCALL(AOM_set_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_ReadinessTime", tbean.zbsj.c_str())); + ITKCALL(AOM_set_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_ProCycle", tbean.zrsczq.c_str())); + ITKCALL(AOM_save(oneGx)); + ITKCALL(AOM_unlock(oneGx)); + } + int c_cnt = 0; + ITKCALL(BOM_line_ask_all_child_lines(oneGx, &c_cnt, &towGxLines)); + for (int j = 0; j < c_cnt; j++) { + tag_t towGxLine = towGxLines[j]; + tag_t towGx; + char* gxbm2; + ITKCALL(AOM_ask_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ClassificationCode", &gxbm2)); + if (timebeans.count(gxbm2) > 0) { + ITKCALL(AOM_lock(towGxLine)); + TimeBean tbean = timebeans[gxbm2]; + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ArtificialTime", tbean.rgsj.c_str())); + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_MachineTime", tbean.jqsj.c_str())); + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ReadinessTime", tbean.zbsj.c_str())); + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ProCycle", tbean.zrsczq.c_str())); + ITKCALL(AOM_save(towGxLine)); + ITKCALL(AOM_unlock(towGxLine)); + } + ITKCALL(AOM_ask_value_tag(towGxLine, "bl_line_object", &towGx)); + gxDocMap[gxbm2] = towGx; + } + } + ITKCALL(BOM_close_window(ebom_window)); +} + +//查询ID +tag_t * queryItem(char* itemId,tag_t newGx,char *relation) { + tag_t query_tag = NULLTAG,*tags=NULLTAG; + ITKCALL(QRY_find("零组件...", &query_tag)); + char* qry_entries[1] = { "零组件 ID" }, *qry_values[1] = { itemId }; + int n_found; + ITKCALL(QRY_execute(query_tag, 1, qry_entries, qry_values, &n_found, &tags)); + if (n_found > 0) { + ITKCALL(AOM_set_value_tags(newGx, relation, n_found, tags)); + } + return tags; +} +//根据数据库获取ID 2023/12/19 新增逻辑 +void queryProcessRule(char *windWay, boolean isXq, char *processCode, tag_t &newGx) { + + char selectGyId[200]; //根据工厂M060 二级工序编码 绕线方式(线圈) 获取工时信息 + if (isXq) { + string sqlRuleId = "select \"processroutefiles\",\"esopfiles\" from CHINT_PROCESS_SOP_RULE where \"companycode\" = 'M060' and \"windway\" = '%s' and \"gxcode\" = '%s' "; + sprintf(selectGyId, sqlRuleId.c_str(), windWay, processCode); + } + else { + string sqlRuleId = "select \"processroutefiles\",\"esopfiles\" from CHINT_PROCESS_SOP_RULE where \"companycode\" = 'M060' and \"gxcode\" = '%s' "; + sprintf(selectGyId, sqlRuleId.c_str(), processCode); + } + printf("selectGyId %s \n", selectGyId); + int outputColumn3 = 0, outputValueCount3 = 0; + char*** outputValue3 = NULL; + QuerySQLNoInputParam(selectGyId, &outputColumn3, &outputValueCount3, &outputValue3); + printf("outputValueCount3 %d \n", outputValueCount3); + string processIds, esopIds; + for (int j = 0; j < outputValueCount3; j++) { + char* processId = outputValue3[j][0]; + char* esopId = outputValue3[j][1]; + if (strcmp(processId, "") != 0) { + processIds.append(processId).append(";"); + } + if (strcmp(esopId, "") != 0) { + esopIds.append(esopId).append(";"); + } + } + queryItem((char*)processIds.c_str(), newGx,"ZT2_ProcessRuleRelation"); + queryItem((char*)esopIds.c_str(), newGx, "ZT2_ProcGuidBookRelation"); +} + +tag_t clone_process_from_template(char* process_item_id, boolean isXq, string productZu, string xqfs,string th, string lastId) +{ + tag_t item_tag = NULLTAG; + ITKCALL(ITEM_find_item(process_item_id, &item_tag)); + if (item_tag == NULLTAG) + { + printf("\n MEProcess NOT found! \n"); + return NULLTAG; + } + tag_t revision_tag = NULLTAG; + ITKCALL(ITEM_ask_latest_rev(item_tag, &revision_tag)); + char* nameOld, *item_revision_id; + ITKCALL(AOM_ask_value_string(revision_tag, "item_revision_id", &item_revision_id)); + ITKCALL(AOM_ask_value_string(revision_tag, "object_name", &nameOld)); + ITKCALL(MEBOM_init_module()); + + tag_t window_tag = NULLTAG; + ITKCALL(ME_create_bop_window(&window_tag)); + + tag_t rule_tag = NULLTAG; + ITKCALL(CFM_find("Latest Working", &rule_tag)); + + ITKCALL(BOM_set_window_config_rule(window_tag, rule_tag)); + //AOM_ask + char* next_id = NULL; + ITKCALL(NR_next_value("MEProcess", "item_id", NULLTAG, "", "", "", + NULLTAG, "", "", &next_id)); + + tag_t clone_tag = NULLTAG; + ITKCALL(ME_create_process_from_template(next_id, item_revision_id, + nameOld, "", revision_tag, rule_tag, window_tag, + "Process.Template.Mapping_Consumes", &clone_tag)); + + if (next_id) MEM_free(next_id); + + ITKCALL(AOM_refresh(clone_tag, TRUE)); + ITKCALL(AOM_save(clone_tag)); + ITKCALL(AOM_refresh(clone_tag, FALSE)); + + char* item_id = NULL; + ITKCALL(WSOM_ask_id_string(clone_tag, &item_id)); + + printf("\n\t MEProcess Clone ID: %s\n", item_id); + ITKCALL(AOM_unload(clone_tag)); + + if (item_id != NULL) + MEM_free(item_id); + + //复制“工艺守则”、“工序作业指导书” + + if (isXq) { + char selectRxfs[200]; + sprintf(selectRxfs, sqlRxfs.c_str(), xqfs.c_str()); + int outputColumn1 = 0, outputValueCount1 = 0; + char*** outputValue1 = NULL; + printf("search3 ===> %s\n", selectRxfs); + QuerySQLNoInputParam(selectRxfs, &outputColumn1, &outputValueCount1, &outputValue1); + map temGxMap; + printf("search result ===> %d\n", outputValueCount1); + for (int num = 0; num < outputValueCount1; num++) { + //TarGXCODE\", \"TarGXNAME\", \"TemGXCODE\", \"TemGXNAME + string tarGxCode = outputValue1[num][0]; + string tarGxName = outputValue1[num][1]; + string temGxCode = outputValue1[num][2]; + TemGxBean bean; + bean.temGxCode = tarGxCode; + bean.temGxName = tarGxName; + temGxMap[temGxCode] = bean; + } + //更新 根据数据库配置更新工序编码和名称 + updateTemGxCode(clone_tag, temGxMap); + } + //if (!isXq) { + map tmpProcessMap; //存放的是二级工序编码对应的二级工序版本 模板的 + //vector timeVec; + //工艺模板 + map beanMap; + //根据数据库配置修改工时 + getGxbmMap(revision_tag, tmpProcessMap, beanMap); + map newProcessMap;//存放的是二级工序编码对应的二级工序版本 克隆出来的 + char selectGyId[200]; //根据产品族 模板id 绕线方式(线圈) 获取工时信息 + if (isXq) { + sprintf(selectGyId, sqlGxTime2.c_str(), productZu.c_str(), process_item_id, xqfs.c_str()); + } + else { + sprintf(selectGyId, sqlGxTime.c_str(), productZu.c_str(), process_item_id); + } + int outputColumn1 = 0, outputValueCount1 = 0; + char*** outputValue1 = NULL; + string gyId; + printf("search3 ===> %s\n", selectGyId); + QuerySQLNoInputParam(selectGyId, &outputColumn1, &outputValueCount1, &outputValue1); + //查询结果 四种工时 + for (int num = 0; num < outputValueCount1; num++) { + string gxbm = outputValue1[num][0]; + string rgsj = outputValue1[num][1]; + if (rgsj.rfind(".", 0) == 0) { + string a = "0"; + rgsj = a.append(rgsj); + printf("rgsj === >%s\n", rgsj.c_str()); + } + string jqsj = outputValue1[num][2]; + if (jqsj.rfind(".", 0) == 0) { + string a = "0"; + jqsj = a.append(jqsj); + } + string zbsj = outputValue1[num][3]; + if (zbsj.rfind(".", 0) == 0) { + string a = "0"; + zbsj = a.append(zbsj); + printf("zbsj === >%s\n", zbsj.c_str()); + } + string zrsczq = outputValue1[num][4]; + if (zrsczq.rfind(".", 0) == 0) { + string a = "0"; + zrsczq = a.append(zrsczq); + printf("zrsczq === >%s\n", zrsczq.c_str()); + } + TimeBean bean; + bean.rgsj = rgsj; + bean.jqsj = jqsj; + bean.zbsj = zbsj; + bean.zrsczq = zrsczq; + beanMap[gxbm] = bean; + } + //克隆出来的工艺路线 + regex qq_reg22("^1ZDB5.*\\d{2,}000X.*"); //\\d{5,}$ + smatch result; + bool ret = regex_match(th, result, qq_reg22); + string searchTh = th; + if (ret) { + searchTh = "1ZDB5**000X"; + } + //查询二级工序编码的信息,更新克隆出来的BOM的工序编码 + string sqlFl = "select \"materialno\",\"EJBM\",\"quantity\",\"xuhao\" from CHINT_GYFL_001 where \"ProductZu\" = '%s' and \"TuHao\" ='%s' and \"quantity\" !='/' ORDER BY CAST(\"xuhao\" AS DECIMAL) asc"; + char selectFlId[600]; + sprintf(selectFlId, sqlFl.c_str(), productZu.c_str(), searchTh); + printf("selectFlId==>%s\n", selectFlId); + map> flBeanMap; + { + int outputColumn3 = 0, outputValueCount3 = 0; + char*** outputValue3 = NULL; + QuerySQLNoInputParam(selectFlId, &outputColumn3, &outputValueCount3, &outputValue3); + for (int j = 0; j < outputValueCount3; j++) { + string materialno = outputValue3[j][0]; + string ejbm = outputValue3[j][1]; + string quantity = outputValue3[j][2]; + tag_t fltag,flRev; + ITEM_find_item(materialno.c_str(),&fltag); + ITEM_ask_latest_rev(fltag,&flRev); + printf("materialno%s ejbm==%sEnd\n", materialno.c_str(), ejbm.c_str()); + FlBean bean; + bean.blQty = quantity; + bean.flTag = flRev; + if (flBeanMap.count(ejbm) > 0) { + flBeanMap[ejbm].push_back(bean); + } + else { + vector beansVec; + beansVec.push_back(bean); + flBeanMap[ejbm] = beansVec; + } + } + } + + getGxbmMap(clone_tag, newProcessMap, beanMap, flBeanMap,th, lastId); + map::iterator it; + //复制“工艺守则”、“工序作业指导书” 旧逻辑 + /*for (it = tmpProcessMap.begin(); it != tmpProcessMap.end(); it++) { + string gxbm = it->first; + tag_t tmpGx = it->second; + if (newProcessMap.count(gxbm) != 0) { + tag_t* procGuidBooks, *processRules; + int cnt2 = 0, cnt3 = 0; + tag_t newGx = newProcessMap[gxbm]; + ITKCALL(AOM_ask_value_tags(tmpGx, "ZT2_ProcGuidBookRelation", &cnt2, &procGuidBooks)); + ITKCALL(AOM_ask_value_tags(tmpGx, "ZT2_ProcessRuleRelation", &cnt3, &processRules)); + AOM_lock(newGx); + if (cnt2 > 0) { + ITKCALL(AOM_set_value_tags(newGx, "ZT2_ProcGuidBookRelation", cnt2, procGuidBooks)); + } + if (cnt3 > 0) { + ITKCALL(AOM_set_value_tags(newGx, "ZT2_ProcessRuleRelation", cnt3, processRules)); + } + AOM_save(newGx); + AOM_unlock(newGx); + } + }*/ + //复制“工艺守则”、“工序作业指导书” 2023/12/19新增逻辑 CHINT_PROCESS_SOP_RULE 表中查询 + for (it = newProcessMap.begin(); it != newProcessMap.end(); it++) { + string gxbm = it->first; + tag_t newGx = it->second; + queryProcessRule((char*)xqfs.c_str(), isXq, (char*)gxbm.c_str(), newGx); + /*if (newProcessMap.count(gxbm) != 0) { + tag_t* procGuidBooks, *processRules; + int cnt2 = 0, cnt3 = 0; + if (isXq) { + sprintf(selectGyId, sqlGxTime2.c_str(), productZu.c_str(), process_item_id, xqfs.c_str()); + } + tag_t newGx = newProcessMap[gxbm]; + ITKCALL(AOM_ask_value_tags(tmpGx, "ZT2_ProcGuidBookRelation", &cnt2, &procGuidBooks)); + ITKCALL(AOM_ask_value_tags(tmpGx, "ZT2_ProcessRuleRelation", &cnt3, &processRules)); + AOM_lock(newGx); + if (cnt2 > 0) { + ITKCALL(AOM_set_value_tags(newGx, "ZT2_ProcGuidBookRelation", cnt2, procGuidBooks)); + } + if (cnt3 > 0) { + ITKCALL(AOM_set_value_tags(newGx, "ZT2_ProcessRuleRelation", cnt3, processRules)); + } + AOM_save(newGx); + AOM_unlock(newGx); + }*/ + } + //} + return clone_tag; +} +//实体且有BOM往下 +boolean isXn(tag_t matnr) { + int cnt2, numFac, cnt3; + boolean flag = false; + char** procureType, ** factorys, ** specialProcureType; + AOM_ask_value_strings(matnr, "zt2_SZSpecialProcuretype", &cnt3, &specialProcureType); //为/ + AOM_ask_value_strings(matnr, "zt2_SZProcuretype", &cnt2, &procureType); //包含自制 + AOM_ask_value_strings(matnr, "zt2_SZFactory", &numFac, &factorys); + for (int i = 0; i < numFac; i++) { + if (strcmp(factorys[i], "M060") == 0 && cnt2 > i && cnt3 > i) { + if (strstr(procureType[i], "自制") != NULL && strcmp(specialProcureType[i], "/") == 0) { + flag = true; + } + } + } + return flag; +} +//获取分类属性 判断是否整除 +string getClassVal(tag_t top_rev_tag, string& errMessage, ByqBean &bean) { + //, string className + tag_t top_classificationObject = NULLTAG, item = NULLTAG; + ITKCALL(ITEM_ask_item_of_rev(top_rev_tag, &item)); + ITKCALL(ICS_ask_classification_object(item, &top_classificationObject)); + if (top_classificationObject == NULL_TAG) + { + errMessage.append("顶层对象没有发送到分类\n"); + return ""; + } + char* top_class_id = NULL, *top_class_name = NULL; + //ICS_ask_class_of_classification_obj(top_classificationObject, &top_class_tag); + //ICS_ask_id_name(top_class_tag, &top_class_id, &top_class_name); + printf("BOM TOP LINE CLASS ID = %s | NAME = %s \n", top_class_id, top_class_name); + int n_attrs; + char** attr_names = NULL, ** attr_vals = NULL; + ITKCALL(ICS_ask_attributes_of_classification_obj(top_classificationObject, &n_attrs, &attr_names, &attr_vals)); + cout << n_attrs << endl; + // int num = 1; + string cpxh; + for (int ii = 0; ii < n_attrs; ii++) + { + if (strcmp(attr_names[ii], "产品型号") == 0) { + if (strcmp(attr_vals[ii], "") == 0) { + errMessage.append("分类属性产品型号为空,请检查。\n"); + return ""; + } + else { + cpxh = (attr_vals[ii]); + } + //break; + } + else if (strcmp(attr_names[ii], "低压线圈绕线方式") == 0) { + if (strcmp(attr_vals[ii], "") == 0) { + //errMessage.append("分类属性低压线圈绕线方式为空,请检查。\n"); + //return ""; + } + else { + bean.dyxq = attr_vals[ii];//cpxh = (attr_vals[ii]); + } + //break; + } + else if (strcmp(attr_names[ii], "中压线圈绕线方式") == 0) { + if (strcmp(attr_vals[ii], "") == 0) { + //errMessage.append("分类属性中压线圈绕线方式为空,请检查。\n"); + //return ""; + } + else { + bean.zyxq = attr_vals[ii];//cpxh = (attr_vals[ii]); + } + //break; + } + else if (strcmp(attr_names[ii], "高压线圈绕线方式") == 0) { + if (strcmp(attr_vals[ii], "") == 0) { + //errMessage.append("分类属性高压线圈绕线方式为空,请检查。\n"); + //return ""; + } + else { + bean.gyxq = attr_vals[ii];//cpxh = (attr_vals[ii]); + } + //break; + } + else if (strcmp(attr_names[ii], "调压线圈绕线方式") == 0) { + if (strcmp(attr_vals[ii], "") == 0) { + //errMessage.append("分类属性调压线圈绕线方式为空,请检查。\n"); + //return ""; + } + else { + bean.tyxq = attr_vals[ii];//cpxh = (attr_vals[ii]); + } + //break; + } + else if (strcmp(attr_names[ii], "稳压线圈绕线方式") == 0) { + if (strcmp(attr_vals[ii], "") == 0) { + // errMessage.append("分类属性稳压线圈绕线方式为空,请检查。\n"); + //return ""; + } + else { + bean.wyxq = attr_vals[ii];//cpxh = (attr_vals[ii]); + } + //break; + } + //五柱铁心 + cout << attr_names[ii] << "\t" + << attr_vals[ii] << endl; + } + return cpxh; +} +//包含线圈 + +//不包含线圈 +void Split2(string strArg, string spliter, vector& ans) +{ + ans.clear(); + size_t index0 = 0; + string one_arg; + if (strArg.find_first_not_of(' ') == string::npos) + strArg = ""; + while (strArg.size() > 0) + { + index0 = strArg.find_first_of(spliter); + if (index0 != string::npos) + { + one_arg = strArg.substr(0, index0); + strArg = strArg.substr(index0 + 1); + ans.push_back(one_arg); + } + else + { + ans.push_back(strArg); + break; + } + } +} +tag_t getTmpProcess(string cpxh, string th, string& errBuff, string& oldGyId, boolean isXq, string xqfs,string lastId) { + char selectCPZ[300], selectGyId[200]; + sprintf(selectCPZ, sqlCpxh.c_str(), cpxh.c_str()); + int outputColumn = 0, outputValueCount = 0; + char*** outputValue = NULL; + string productZu; + printf("search1 %s \n", selectCPZ); + QuerySQLNoInputParam(selectCPZ, &outputColumn, &outputValueCount, &outputValue); + printf("search11\n"); + if (outputValueCount == 0) { + string buffMsg = ""; + buffMsg.append("当前变压器产品型号:").append(cpxh).append(",在数据库表中无对应典型产品族值,请联系管理员维护.\n"); + size_t found = errBuff.find(buffMsg); + if (found == std::string::npos) { + errBuff.append(buffMsg); + } + //errBuff.append("当前变压器产品型号:").append(cpxh).append(",在数据库表中无对应典型产品族值,请联系管理员维护.\n"); + return NULLTAG; + } + for (int j = 0; j < outputValueCount; j++) { + productZu = outputValue[j][0]; + printf("productZu===>%s\n", productZu.c_str()); + } + + sprintf(selectGyId, sqlGyRule.c_str(), productZu.c_str(), th.c_str()); + + int outputColumn1 = 0, outputValueCount1 = 0; + char*** outputValue1 = NULL; + string gyId; + printf("search2 %s \n", selectGyId); + QuerySQLNoInputParam(selectGyId, &outputColumn1, &outputValueCount1, &outputValue1); + if (outputValueCount1 == 0) { + errBuff.append("图号:").append(th).append("无对应工艺模板ID,请维护后再指派工艺路线.\n"); + return NULLTAG; + } + printf("search22\n"); + for (int j = 0; j < outputValueCount1; j++) { + gyId = outputValue1[j][0]; + printf("gyId===>%s\n", gyId.c_str()); + } + oldGyId = gyId; + //新增逻辑校验时间和绕线方式 + { + char selectGyId[200]; + if (isXq) { + sprintf(selectGyId, sqlProTime2.c_str(), productZu.c_str(), (char*)gyId.c_str(), xqfs.c_str()); + } + else { + sprintf(selectGyId, sqlProTime.c_str(), productZu.c_str(), (char*)gyId.c_str()); + } + int outputColumn2 = 0, outputValueCount2 = 0; + char*** outputValue2 = NULL; + string gyId; + printf("search3 ===> %s\n", selectGyId); + boolean hasErr = false; + QuerySQLNoInputParam(selectGyId, &outputColumn2, &outputValueCount2, &outputValue2); + for (int t = 0; t < outputValueCount2; t++) { + string gyName = outputValue2[t][0]; + string gxName = outputValue2[t][1]; + errBuff.append("一级工序名称:").append(gyName).append(" 对应的二级工序:").append(gxName).append("的自然生产周期数据不正确,请及时维护.\n"); + } + if (outputValue2>0) { + hasErr = true; + } + if (isXq) { + char selectRxfs[200]; + sprintf(selectRxfs, sqlRxfs.c_str(), xqfs.c_str()); + int outputColumn3 = 0, outputValueCount3 = 0; + char*** outputValue3 = NULL; + printf("search3 ===> %s\n", selectRxfs); + QuerySQLNoInputParam(selectRxfs, &outputColumn3, &outputValueCount3, &outputValue3); + printf("search result ===> %d\n", outputValueCount3); + if (outputValueCount3 == 0) { + errBuff.append("绕线方式:").append(xqfs).append(" 未在CHINT_WORKHOUR_WhGXName表中配置,请及时维护"); + hasErr = true; + } + } + if (hasErr) { + return NULLTAG; + } + } + tag_t clone_tag = clone_process_from_template((char*)gyId.c_str(), isXq, productZu, xqfs, th, lastId); + printf("克隆完成===>\n"); + return clone_tag; +} +boolean isTcmOnNot(tag_t process) { + int structs = 0; + boolean flag = false; + tag_t *structure_revisions; + AOM_ask_value_tags(process, "structure_revisions", &structs, &structure_revisions); + if (structs > 0) { + int statusNum = 0; + char *revUid; + tag_t *release_status_list; + tag_t struct_revision = structure_revisions[0]; + AOM_ask_value_tags(struct_revision, "release_status_list", &statusNum, &release_status_list); + if (statusNum > 0) { + flag = true; + } + } + return flag; +} +void readProcessBom(tag_t bom_line, string& errorBuff, boolean &flag, tag_t &topProcess, string ¬TcmBuff, string back) { + + int c_line_count; + tag_t mantr, *c_line_tags; + ITKCALL(AOM_ask_value_tag(bom_line, "bl_line_object", &mantr)); + ITKCALL(BOM_line_ask_all_child_lines(bom_line, &c_line_count, &c_line_tags)); + char *objName; + AOM_ask_value_string(mantr, "object_name", &objName); + if (c_line_count > 0 && (isXn(mantr)|| strstr(objName, "变压器") != NULL)) { + printf("实体\n"); + flag = true; + //检查是否有工艺路线 + int n_references = 0; + int* levels = 0; + tag_t* references_tag = NULLTAG; + char** relation_type_name = NULL; + //通过引用关系查找到变更单 + ITKCALL(WSOM_where_referenced(mantr, 1, &n_references, &levels, &references_tag, &relation_type_name)); + boolean hasProcess = false; + for (int i = 0; i < n_references; i++) + { + char* refType; + tag_t refTag = references_tag[i]; + ITKCALL(AOM_ask_value_string(refTag, "object_type", &refType)); + if (strcmp(refType, "MEProcessRevision") == 0) { + hasProcess = true; + break; + } + } + printf("hasProcess==%d\n", hasProcess); + if (!hasProcess) { + char* bl_desc = NULL, * itemID = NULL; + ITKCALL(AOM_ask_value_string(mantr, "item_id", &itemID)); + printf("back==%zd\n", back.size()); + if (back.size() > 0) { + vector backs; + Split2(back, "@", backs); + tag_t processTag = NULLTAG; + string tmpGyId; + processTag = getTmpProcess(backs[0], backs[1], errorBuff, tmpGyId, false, "", ""); + topProcess = processTag; + if (processTag != NULLTAG) { + printf("save_representation2\n"); + save_representation2(processTag, mantr, "IMAN_METarget"); + } + } + else if (strstr(objName, "变压器") != NULL) { + tag_t* byqRev = NULLTAG; + string tmpGyId; + char* uid = NULL; + int cnt3 = 0; + ITKCALL(AOM_ask_value_tags(mantr, "TC_Is_Represented_By", &cnt3, &byqRev)); + ByqBean bean; + ITK__convert_tag_to_uid(byqRev[0], &uid); + printf("objName%s %s\n", objName, uid); + string cpxh = getClassVal(byqRev[0], errorBuff, bean); + char* thId = NULL; + ITKCALL(AOM_ask_value_string(byqRev[0], "item_id", &thId)); + printf("cpxh===>%s\n", cpxh.c_str()); + tag_t processTag = NULLTAG; + if (strstr(objName, "线圈") == NULL) { + vector idVec; + Split2(thId, "-", idVec); + processTag = getTmpProcess(cpxh, "1ZDB300000P", errorBuff, tmpGyId, false, "", idVec[1]); + topProcess = processTag; + if (processTag != NULLTAG) { + save_representation2(processTag, mantr, "IMAN_METarget"); + } + } + } + else { + ITKCALL(AOM_ask_value_string(bom_line, "bl_rev_object_desc", &bl_desc)); + vector descVec1; + Split2(bl_desc, " ", descVec1); + if (descVec1.size() > 1) { + string drawNos = descVec1[1]; + vector drawNoVec1; + Split2(drawNos, "-", drawNoVec1); + if (drawNoVec1.size() > 1) { + string wordNo = drawNoVec1[1]; //工程号 拼接1ZDB300000P 查找分类属性 + string drawNo = drawNoVec1[0]; //图号 + if (drawNoVec1.size() == 3) { + drawNo = drawNoVec1[0].append("-").append(drawNoVec1[1]); + wordNo = drawNoVec1[2]; + } + string byqId = "1ZDB300000P-", tmpGyId; + tag_t byqTag = NULLTAG, byqRev = NULLTAG, processTag = NULLTAG; + byqId.append(wordNo); + ITKCALL(ITEM_find_item(byqId.c_str(), &byqTag)); + ITKCALL(ITEM_ask_latest_rev(byqTag, &byqRev)); + ByqBean bean; + string cpxh = getClassVal(byqRev, errorBuff, bean); + printf("cpxh===>%s\n", cpxh.c_str()); + if (strstr(objName, "线圈") == NULL) { + processTag = getTmpProcess(cpxh, drawNo, errorBuff, tmpGyId, false, "", wordNo); + if (processTag != NULLTAG) { + save_representation2(processTag, mantr, "IMAN_METarget"); + } + } + else { + string xqfs; + if (strstr(objName, "低压线圈") != NULL) { + //当前XXX线圈未在变压器参数表中维护绕线方式分类属性,请前往维护 + if (bean.dyxq.empty()) { + errorBuff.append("当前低压线圈未在变压器参数表中维护绕线方式分类属性,请前往维护\n"); + return; + } + xqfs = bean.dyxq; + } + else if (strstr(objName, "中压线圈") != NULL) { + //当前XXX线圈未在变压器参数表中维护绕线方式分类属性,请前往维护 + if (bean.zyxq.empty()) { + errorBuff.append("当前中压线圈未在变压器参数表中维护绕线方式分类属性,请前往维护\n"); + return; + } + xqfs = bean.zyxq; + } + else if (strstr(objName, "高压线圈") != NULL) { + //当前XXX线圈未在变压器参数表中维护绕线方式分类属性,请前往维护 + if (bean.gyxq.empty()) { + errorBuff.append("当前高压线圈未在变压器参数表中维护绕线方式分类属性,请前往维护\n"); + return; + } + xqfs = bean.gyxq; + } + else if (strstr(objName, "调压线圈") != NULL) { + //当前XXX线圈未在变压器参数表中维护绕线方式分类属性,请前往维护 + if (bean.tyxq.empty()) { + errorBuff.append("当前调压线圈未在变压器参数表中维护绕线方式分类属性,请前往维护\n"); + return; + } + xqfs = bean.tyxq; + } + else if (strstr(objName, "稳压线圈") != NULL) { + //当前XXX线圈未在变压器参数表中维护绕线方式分类属性,请前往维护 + if (bean.wyxq.empty()) { + errorBuff.append("当前稳压线圈未在变压器参数表中维护绕线方式分类属性,请前往维护\n"); + return; + } + xqfs = bean.wyxq; + } + processTag = getTmpProcess(cpxh, drawNo, errorBuff, tmpGyId, true, xqfs, wordNo); + if (processTag != NULLTAG) { + save_representation2(processTag, mantr, "IMAN_METarget"); + } + } + } + } + } + } + } + printf("sub readProcessBom\n"); + for (int i = 0; i < c_line_count; i++) { + tag_t c_line_tag = c_line_tags[i]; + readProcessBom(c_line_tag, errorBuff, flag, topProcess, notTcmBuff, ""); + } +} + +tag_t getProcess(tag_t designRev) { + int n_references = 0; + int* levels = 0; + tag_t process = NULLTAG; + tag_t* references_tag = NULLTAG; + char** relation_type_name = NULL; + //通过引用关系查找到变更单 + ITKCALL(WSOM_where_referenced(designRev, 1, &n_references, &levels, &references_tag, &relation_type_name)); + boolean hasProcess = false; + for (int i = 0; i < n_references; i++) + { + char* refType; + tag_t refTag = references_tag[i]; + ITKCALL(AOM_ask_value_string(refTag, "object_type", &refType)); + if (strcmp(refType, "MEProcessRevision") == 0) { + hasProcess = true; + process = refTag; + break; + } + } + return process; +} +int CloneTempProcess(void *returnValue) +{ + int ifail = ITK_ok; + char* sql = NULL, *revUid; + tag_t designRev; + ITKCALL(ifail = USERARG_get_string_argument(&revUid)); + ITK__convert_uid_to_tag(revUid, &designRev); + int bvr_count = 0, c_line_count; + tag_t ebom_window = NULLTAG; + tag_t bom_line = NULLTAG; + tag_t item_tag = NULLTAG, *c_line_tags = NULLTAG; + (BOM_create_window(&ebom_window)); + tag_t* bvr_list = NULL; + ITKCALL(ITEM_rev_list_bom_view_revs(designRev, &bvr_count, &bvr_list)); + printf("bvr_count=%d", bvr_count); + + ITKCALL(BOM_set_window_top_line_bvr(ebom_window, bvr_list[0], &bom_line)); //顶层bom获取 + string errorBuff; + string notTcmBuff; + char *bl_desc; + ITKCALL(AOM_ask_value_string(bom_line, "bl_rev_object_desc", &bl_desc)); + + int n_references = 0; + int* levels = 0; + tag_t* references_tag = NULLTAG; + char** relation_type_name = NULL; + //通过引用关系查找到变更单 + ITKCALL(WSOM_where_referenced(designRev, 1, &n_references, &levels, &references_tag, &relation_type_name)); + boolean hasProcess = false; + tag_t processTagTop = NULLTAG; + for (int i = 0; i < n_references; i++) + { + char* refType; + tag_t refTag = references_tag[i]; + ITKCALL(AOM_ask_value_string(refTag, "object_type", &refType)); + if (strcmp(refType, "MEProcessRevision") == 0) { + hasProcess = true; + processTagTop = refTag; + break; + } + } + int url_num = 0; + char** url_vals = NULL; + ITKCALL(PREF_ask_char_values("database_tc", &url_num, &url_vals)); + string url = url_vals[0]; + url.append("/").append(url_vals[2]); + + //map %s \n", url.c_str()); + if (ConnServer(url_vals[3], url_vals[4], (char*)url.c_str()) == -1) + { + printf("提示:中间数据表访问失败\n"); + ifail = 1; + } + boolean isback = false; + tag_t meProcess = NULLTAG; + char* objName = NULL, * topId = NULL; + string backs = ""; + ITKCALL(AOM_ask_value_string(designRev, "object_name", &objName)); + ITKCALL(AOM_ask_value_string(designRev, "item_id", &topId)); + map mapByq; + //如果是产成品的话, 判断是否存在多个P物料 + //20240203备件包工艺路线指派 + int back_num = 0; + char** back_vals = NULL, * group_name = NULL; + tag_t group = NULLTAG; + string tuhao; + vector group_names; + ITKCALL(POM_ask_group(&group_name, &group)); + Split(group_name, ".", group_names); + printf("group_name=======%s\n", group_names[0].c_str()); + ITKCALL(PREF_ask_char_values("CHINT_PROCESS_RULE", &back_num, &back_vals)); + //首选项格式:组名:匹配字段1;匹配字段2 + for (int i = 0; i < back_num; i++) { + vector group_backs; + Split(back_vals[i], ":", group_backs); + if (tc_strcmp(group_backs[0].c_str(), group_names[0].c_str()) == 0) { + vector backs; + Split(group_backs[1], ";", backs); + for (int j = 0; j < backs.size(); j++) { + if (tc_strstr(objName, backs[j].c_str()) != NULL) { + tuhao = backs[j]; + isback = true; + break; + } + } + if(isback) + break; + } + } + if (isback) { + isback = false; + int b_refs = 0; + int* b_levels = 0; + tag_t* b_refs_tag = NULLTAG; + char** b_rel_name = NULL, * pcode = NULL; + string cpxh = ""; + //判断当前物料对象是否在“产成品”文件夹(ZT2_ProjectFolder)中 + ITKCALL(ITEM_ask_item_of_rev(designRev, &item_tag)); + ITKCALL(WSOM_where_referenced2(item_tag, 1, &b_refs, &b_levels, &b_refs_tag, &b_rel_name)); + for (int i = 0; i < b_refs; i++) { + char* ref_type = NULL; + ITKCALL(AOM_ask_value_string(b_refs_tag[i], "object_type", &ref_type)); + printf("ref_type:%s\n", ref_type); + if (tc_strcmp(ref_type, "ZT2_ProjectFolder") != 0) + continue; + int n_projs = 0; + tag_t* projs = NULLTAG; + ITKCALL(AOM_ask_value_tags(b_refs_tag[i], "contents", &n_projs, &projs)); + for (int j = 0; j < n_projs; j++) { + int n_drows = 0; + tag_t proj_rev = NULLTAG, * drows = NULLTAG; + ITKCALL(ITEM_ask_latest_rev(projs[j], &proj_rev)); + ITKCALL(AOM_ask_value_tags(proj_rev, "TC_Is_Represented_By", &n_drows, &drows)); + printf("n_drows:%d\n", n_drows); + if (n_drows == 0) + continue; + ByqBean bean; + cpxh = getClassVal(drows[0], errorBuff, bean); + isback = true; + break; + } + if (isback) + break; + } + backs.append(cpxh).append("@").append(tuhao); + /*string sql = "select a.GYID from CHINT_WORKHOUR_WhProductXH a,CHINT_WORKHOUR_WhGYRule b "; + sql.append("where a.COMPANYCODE=b.COMPANYCODE and a.ProductZu=b.ProductZu ") + .append("and a.COMPANYCODE='").append(group_name) + .append("' and a.ProductXH='").append(cpxh) + .append("' and b.TuHao='").append(tuhao) + .append("'"); + int outputColumn = 0, outputValueCount = 0; + char*** outputValue = NULL, sqlc[1024]; + tc_strcpy(sqlc, sql.c_str()); + QuerySQLNoInputParam(sqlc, &outputColumn, &outputValueCount, &outputValue); + if (outputValueCount > 0) { + gyid = outputValue[0][0]; + } + for (int i = 0; i < outputValueCount; i++) { + + }*/ + } + else if (strstr(objName, "变压器") != NULL) { + tag_t *topMatnrs,*pMaterials; + int num = 0, num2=0; + ITKCALL(AOM_ask_value_tags(designRev, "TC_Is_Represented_By", &num, &topMatnrs)); + printf("num===>%d\n", num); + if (num >= 1) { + tag_t tzRev = topMatnrs[0]; + ITKCALL(AOM_ask_value_tags(tzRev, "representation_for", &num2, &pMaterials)); + for (int x = 0; x < num2; x++) { + char *pId,*zt2_ifpbom; + tag_t pMatr = pMaterials[x]; + ITKCALL(AOM_ask_value_string(pMatr, "item_id", &pId)); + ITKCALL(AOM_ask_value_string(pMatr, "zt2_ifpbom", &zt2_ifpbom)); + if (strcmp(pId, topId) != 0 && strcmp(zt2_ifpbom,"P")==0) { + tag_t process = getProcess(pMatr); + if (process != NULLTAG) { + meProcess = process; + } + else { + mapByq[pId] = pMatr; + } + } + } + } + if (meProcess != NULLTAG) { + if (!hasProcess) { + save_representation2(meProcess, designRev, "IMAN_METarget"); + } + map::iterator it; + //名称模糊匹配 + for (it = mapByq.begin(); it != mapByq.end(); it++) { + string s = it->first; + tag_t matnrPrev = mapByq[s]; + save_representation2(meProcess, matnrPrev, "IMAN_METarget"); + } + printf("=======\n"); + errorBuff = "当前选中的物料已经存在工艺路线.\n"; + } + else if (processTagTop != NULLTAG) { + map::iterator it; + printf("=======22\n"); + //名称模糊匹配 + for (it = mapByq.begin(); it != mapByq.end(); it++) { + string s = it->first; + tag_t matnrPrev = mapByq[s]; + save_representation2(processTagTop, matnrPrev, "IMAN_METarget"); + } + errorBuff = "当前选中的物料已经存在工艺路线.\n"; + } + } + printf("mapByq===>%zd\n", mapByq.size()); + if (hasProcess) { + errorBuff = "当前选中的物料已经存在工艺路线.\n"; + }else if ((strcmp(bl_desc, "") == 0 || strstr(bl_desc,"-")==NULL) && strstr(objName, "变压器") == NULL && !isback) { + errorBuff = "当前选中的物料版本没有图号信息,请检查.\n"; + } + else { + POM_AM__set_application_bypass(true); + + tag_t topProcess = NULLTAG; + boolean flag = false; + printf("errorBuff==>%s\n", errorBuff.c_str()); + readProcessBom(bom_line, errorBuff, flag, topProcess, notTcmBuff, backs); + if (topProcess != NULLTAG) { + map::iterator it; + for (it = mapByq.begin(); it != mapByq.end(); it++) { + string s = it->first; + tag_t matnrPrev = mapByq[s]; + save_representation2(topProcess, matnrPrev, "IMAN_METarget"); + } + } + if (!flag) { + errorBuff = "当前选中的PBOM没有实件,无需做工艺路线."; + } + POM_AM__set_application_bypass(false); + } + DisConnServer(); + errorBuff.append(notTcmBuff); + if (errorBuff.empty()) { + errorBuff = "succ"; + } + printf("errorBuff==>%s\n", errorBuff.c_str()); + ITKCALL(BOM_close_window(ebom_window)); + *((char**)returnValue) = (char*)MEM_alloc((strlen(errorBuff.c_str()) + 1) * sizeof(char)); + tc_strcpy(*((char**)returnValue), errorBuff.c_str()); + return ifail; +} \ No newline at end of file diff --git a/General/General/CloneProcess1.cpp b/General/General/CloneProcess1.cpp new file mode 100644 index 0000000..ef74926 --- /dev/null +++ b/General/General/CloneProcess1.cpp @@ -0,0 +1,1408 @@ +#include +#include "epm_handler_common.h" +#include +#include +#include +#include +#include +#include +#include +#include "ps/ps.h"; +#include "ps/vrule.h" +#include "sstream" +#include +#include "epm/epm.h" +#include "sa/sa.h" +#include "libxl.h" +#include +#include "epm/signoff.h" +#include +#include +#include +#include +#include "ae/dataset.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// #include "hx_custom.h" +#include "tc_log.h" +// #include "jk_custom.h" +#include "chint_Handler.h" +#include "tc_util.h" +#include +#include +#include "ocilib.h" +#include +#include +#include +#include +#include +#include +using namespace std; + +typedef struct { + string cpxh;//产品型号 低、中、高、调、稳 + string dyxq; + string zyxq; + string gyxq; + string tyxq; + string wyxq; +}ByqBean; +typedef struct { + string rgsj;//产品型号 低、中、高、调、稳 + string jqsj; + string zbsj; + string zrsczq; +}TimeBean; +typedef struct { + string temGxCode; + string temGxName; + +}TemGxBean; +struct FlBean +{ + tag_t flTag=NULLTAG; + string blQty; +}; +string getCshVal(string name, string code); + +string sqlProTime = "select GYNAME,GXNAME from CHINT_WORKHOUR where \"PRODUCTXH\" = '%s' and GYID = '%s' and COMPANYCODE ='M060' and \"ProCycle\"<1 "; +string sqlProTime2 = "select GYNAME,GXNAME from CHINT_WORKHOUR where \"PRODUCTXH\" = '%s' and GYID = '%s' and JSASK = '%s' and COMPANYCODE ='M060' and \"ProCycle\"<1 "; + +string sqlRxfs = "select \"TarGXCODE\", \"TarGXNAME\", \"TemGXCODE\", \"TemGXNAME\" from \"CHINT_WORKHOUR_WhGXName\" where \"WindStyle\" = '%s' and COMPANYCODE ='M060'"; +string sqlGyRule = "select GYID from \"CHINT_WORKHOUR_WhGYRule\" where \"ProductZu\" = '%s' and \"TuHao\" = '%s' and COMPANYCODE ='M060'"; +string sqlCpxh = "SELECT \"ProductZu\" FROM \"CHINT_WORKHOUR_WhProductXH\" where \"ProductXH\" = '%s' and COMPANYCODE ='M060' "; +string sqlGxTime = "select GXCODE,ARTIFICIALTIME,MACHINETIME,READINESSTIME,\"ProCycle\" from CHINT_WORKHOUR where \"PRODUCTXH\" = '%s' and GYID = '%s' and COMPANYCODE ='M060'"; +string sqlGxTime2 = "select GXCODE,ARTIFICIALTIME,MACHINETIME,READINESSTIME,\"ProCycle\" from CHINT_WORKHOUR where \"PRODUCTXH\" = '%s' and GYID = '%s' and JSASK = '%s' and COMPANYCODE ='M060'"; +void save_representation2(tag_t primaryTag, tag_t secondTag, char* relationType) +{ + tag_t typeTag = NULLTAG; + ITKCALL(GRM_find_relation_type(relationType, &typeTag)); + + ITKCALL(AOM_refresh(primaryTag, TRUE)); + ITKCALL(AOM_refresh(secondTag, TRUE)); + tag_t relationTag = NULLTAG; + ITKCALL(GRM_create_relation(primaryTag, secondTag, typeTag, NULLTAG, &relationTag));//如果关系已经存在,那么就是增加对象 + + ITKCALL(GRM_save_relation(relationTag));//很必要 + ITKCALL(AOM_save(primaryTag)); + ITKCALL(AOM_save(secondTag)); + ITKCALL(AOM_refresh(primaryTag, FALSE)); + ITKCALL(AOM_refresh(secondTag, FALSE)); +} +void updateTemGxCode(tag_t processTag, map temGxMap) { + int bvr_count = 0; + tag_t ebom_window = NULLTAG; + tag_t bom_line = NULLTAG; + tag_t item_tag = NULLTAG, *c_line_tags; + ITKCALL(BOM_create_window(&ebom_window)); + tag_t* bvr_list = NULL; + ITKCALL(ITEM_rev_list_bom_view_revs(processTag, &bvr_count, &bvr_list)); + printf("bvr_count=%d", bvr_count); + + ITKCALL(BOM_set_window_top_line_bvr(ebom_window, bvr_list[0], &bom_line)); //顶层bom获取 + //bom_line工艺 + int c_line_count; + ITKCALL(BOM_line_ask_all_child_lines(bom_line, &c_line_count, &c_line_tags)); // 一级工序 + for (int i = 0; i < c_line_count; i++) { + tag_t oneGxLine = c_line_tags[i], *towGxLines, oneGx, gxItem; + char* gxbm1; + AOM_ask_value_string(oneGxLine, "bl_ZT2_FirstOPRevision_zt2_ClassificationCode", &gxbm1); + + printf("gxbm1===>%s\n", gxbm1); + if (temGxMap.count(gxbm1) > 0) { + char* oldName; + TemGxBean temGxBean = temGxMap[gxbm1]; + ITKCALL(AOM_lock(oneGxLine)); + ITKCALL(AOM_set_value_string(oneGxLine, "bl_ZT2_FirstOPRevision_zt2_ClassificationCode", temGxBean.temGxCode.c_str())); + ITKCALL(AOM_save(oneGxLine)); + AOM_unlock(oneGxLine); + ITKCALL(AOM_ask_value_tag(oneGxLine, "bl_line_object", &oneGx)); + ITKCALL(ITEM_ask_item_of_rev(oneGx, &gxItem)); + ITKCALL(AOM_lock(gxItem)); + ITKCALL(AOM_ask_value_string(gxItem, "object_name", &oldName)); + ITKCALL(AOM_set_value_string(gxItem, "object_name", temGxBean.temGxName.c_str())); + ITKCALL(AOM_save(gxItem)); + ITKCALL(AOM_unlock(gxItem)); + ITKCALL(AOM_lock(oneGx)); + ITKCALL(AOM_set_value_string(oneGx, "object_name", temGxBean.temGxName.c_str())); + ITKCALL(AOM_save(oneGx)); + ITKCALL(AOM_unlock(oneGx)); + printf("oldName===>%s\n", oldName); + printf("temGxName===>%s\n", temGxBean.temGxName.c_str()); + printf("temGxCode===>%s\n", temGxBean.temGxCode.c_str()); + } + + int c_cnt = 0; + BOM_line_ask_all_child_lines(oneGxLine, &c_cnt, &towGxLines); + for (int j = 0; j < c_cnt; j++) { + tag_t towGxLine = towGxLines[j]; + tag_t towGx, gxItem2; + char* gxbm2; + ITKCALL(AOM_ask_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ClassificationCode", &gxbm2)); + + printf("gxbm2===>%s\n", gxbm2); + if (temGxMap.count(gxbm2) > 0) { + TemGxBean temGxBean = temGxMap[gxbm2]; + AOM_lock(towGxLine); + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ClassificationCode", temGxBean.temGxCode.c_str())); + AOM_save(towGxLine); + AOM_unlock(towGxLine); + char* oldName, *oldName2; + ITKCALL(AOM_ask_value_tag(towGxLine, "bl_line_object", &towGx)); + ITKCALL(ITEM_ask_item_of_rev(towGx, &gxItem2)); + ITKCALL(AOM_lock(gxItem2)); + ITKCALL(AOM_ask_value_string(gxItem2, "object_name", &oldName)); + ITKCALL(AOM_set_value_string(gxItem2, "object_name", temGxBean.temGxName.c_str())); + ITKCALL(AOM_save(gxItem2)); + ITKCALL(AOM_unlock(gxItem2)); + ITKCALL(AOM_ask_value_string(gxItem2, "object_name", &oldName2)); + printf("oldName===>%s\n", oldName); + printf("oldName2===>%s\n", oldName2); + printf("temGxName===>%s\n", temGxBean.temGxName.c_str()); + printf("temGxCode===>%s\n", temGxBean.temGxCode.c_str()); + ITKCALL(AOM_lock(towGx)); + ITKCALL(AOM_set_value_string(towGx, "object_name", temGxBean.temGxName.c_str())); + ITKCALL(AOM_save(towGx)); + ITKCALL(AOM_unlock(towGx)); + + } + + } + } + BOM_close_window(ebom_window); +} +string getCshVal(string name,string code) { + + string strResult; + string schVal = ""; + //cmd指令 + char cmd[256] = ""; + strcpy(cmd, "java -jar \""); + //strcat(cmd, jar_file); + strcat(cmd, getenv("TC_ROOT")); + strcat(cmd, "\\bin\\findCshSql.jar"); + strcat(cmd, "\" "); + strcat(cmd, name.c_str()); + strcat(cmd, "\" "); + strcat(cmd, code.c_str()); + printf("路径:\n%s\n", cmd); + char buf[8000] = { 0 }; + FILE* pf = NULL; + if ((pf = _popen(cmd, "r")) == NULL) { + printf("接口返回:\n%s", "1"); + } + + while (fgets(buf, sizeof buf, pf)) { + strResult += buf; + } + _pclose(pf); + vector vec; + Split(strResult,"CSHVAL:[",vec); + if (vec.size() > 0) { + Split(vec[1], "]", vec); + schVal = vec[0]; + } + + return schVal; +} +string getJdbVal(string name,string yqz,string checkcode,string draw,string modelVersion,string code,string checkCode) { + string drawingno = draw.append("-").append(name); + string getCode = "select checkno,NUMBEROFCHECKS from CHINT_CHECK_TITLE WHERE drawingno = '%s' and modelversion='%s' order by NUMBEROFCHECKS desc "; + string getNo = "select NO from CHINT_CHECK_DETAILS_TEMPLATE where code ='%s' and modelversion = '%s' and checkCode = '%s' "; + string val = ""; + char selectRxfs[500]; + sprintf(selectRxfs, getNo.c_str(), code.c_str(), modelVersion.c_str(), checkCode.c_str()); + int outputColumn1 = 0, outputValueCount1 = 0; + char*** outputValue1 = NULL; + QuerySQLNoInputParam(selectRxfs, &outputColumn1, &outputValueCount1, &outputValue1); + printf("selectRxfs ===>%s\n", selectRxfs); + if (outputValueCount1 > 0) { + string no = outputValue1[0][0]; + char selectRxfs2[500]; + outputValueCount1 = 0; + outputColumn1 = 0; + outputValue1 = NULL; + sprintf(selectRxfs2, getCode.c_str(), drawingno.c_str(), modelVersion.c_str()); + printf("selectRxfs2 ===>%s\n", selectRxfs2); + QuerySQLNoInputParam(selectRxfs2, &outputColumn1, &outputValueCount1, &outputValue1); + if (outputValueCount1 > 0) { + string checkNo = outputValue1[0][0]; + string numofCheck = outputValue1[0][1]; + string getNo = "select %s from CHINT_CHECK_DETAILS where no ='%s' and NUMBEROFCHECKS = '%s' and checkno = '%s' and modelversion = '%s' "; + char selectRxfs3[500]; + sprintf(selectRxfs3, getNo.c_str(), yqz.c_str(), no.c_str(), numofCheck.c_str(), checkNo.c_str(), modelVersion.c_str()); + printf("selectRxfs3 ===>%s\n", selectRxfs3); + + int outputColumn2 = 0, outputValueCount2 = 0; + char*** outputValue2 = NULL; + QuerySQLNoInputParam(selectRxfs3, &outputColumn2, &outputValueCount2, &outputValue2); + if (outputValueCount1 > 0) { + val = outputValue2[0][0]; + } + } + } + return val; +} +typedef struct { + string no;//产品型号 低、中、高、调、稳 + string mentNo; + string mentDesc; + string mentResult; +}JYXBean; +void setZljyx(string gxbm2, string th,string lastId,string name,tag_t towGx) { + + string code; + printf("th == >%s \n", th.c_str()); + if (strstr(th.c_str(),"-") != NULL) { + vector vec; + Split(th, "-", vec); + code.append(vec[0]).append("-").append("X"); + } + else { + code = th; + } + printf("code == >%s \n", code.c_str()); + string sql = "select cqmodelnno,drawingno,cqmanagementno,cqmanagementdesc,cqmanagementresult,datasource, checkline, checkcode, parameterization, code, modelversion from CHINT_QUALITY_MANAGEMENT_SYSTEM where cpcmcode like '%s' and cdrawingno = '%s' order by cqmodelnno asc"; + char selectRxfs[500]; + string gxbmMsg; + gxbmMsg.append("%").append(gxbm2).append("%"); + sprintf(selectRxfs, sql.c_str(), gxbmMsg.c_str(), code.c_str()); + int outputColumn1 = 0, outputValueCount1 = 0; + char*** outputValue1 = NULL; + printf("search3 ===> %s\n", selectRxfs); + QuerySQLNoInputParam(selectRxfs, &outputColumn1, &outputValueCount1, &outputValue1); + printf("search result ===> %d\n", outputValueCount1); + vector< JYXBean> beans; + + for (int num = 0; num < outputValueCount1; num++) { + //TarGXCODE\", \"TarGXNAME\", \"TemGXCODE\", \"TemGXNAME + JYXBean bean; + string cqmodelnno = outputValue1[num][0]; //序号 + string drawingno = outputValue1[num][1]; //校对表图号 + string cqmanagementno = outputValue1[num][2]; //属性no + string cqmanagementdesc = outputValue1[num][3]; //属性描述 + string cqmanagementresult = outputValue1[num][4]; //属性 + string datasource = outputValue1[num][5]; //校对表或参数化 + string checkline = outputValue1[num][6]; // 要求值,设计值 designresult,PROOFREADRESULT + string checkcode = outputValue1[num][7]; //checkcode + string parameterization = outputValue1[num][8]; //code + string code = outputValue1[num][9]; //校对表模板 + string modelversion = outputValue1[num][10]; //校对表模板版本 + bean.mentDesc = cqmanagementdesc; + bean.mentNo = cqmanagementno; + bean.no = cqmodelnno; + if (cqmanagementresult.empty()) { + + if (datasource.compare("校对表") == 0) { + // string getCode = "select code,NUMBEROFCHECKS from CHINT_CHECK_TITLE WHERE drawingno = '?' order by NUMBEROFCHECKS desc "; + if (checkline.compare("要求值") == 0 && !checkcode.empty()) { + bean.mentResult = getJdbVal(lastId,"designresult", checkcode, drawingno, modelversion,code, checkcode); //designresult,PROOFREADRESULT + } + else if (checkline.compare("设计值") == 0 && !checkcode.empty()) { + bean.mentResult = getJdbVal(lastId, "PROOFREADRESULT", checkcode, drawingno, modelversion, code, checkcode); + } + } + else if (!parameterization.empty()) { + //string csh = getCshVal(lastId, code); + string csh = getCshVal(lastId, parameterization); + bean.mentResult = csh; + } + } + else { + bean.mentResult = cqmanagementresult; + } + beans.push_back(bean); + } + tag_t item, rev; + string objName = "质量检验-"; + objName.append(name); + + if (beans.size()>0) { + tag_t *tableRow; + ITKCALL(ITEM_create_item(NULL, objName.c_str(), "ZT2_QCHECK", NULL, &item, &rev)); + ITKCALL(AOM_save(item)); + ITKCALL(AOM_save(rev)); + ITKCALL(AOM_lock(item)); + ITKCALL(AOM_lock(rev)); + ITKCALL(AOM_insert_table_rows(rev, "zt2_QCHECKS", 0, beans.size(), &tableRow)); + ITKCALL(AOM_save(rev)); + ITKCALL(AOM_unlock(rev)); + ITKCALL(AOM_save(item)); + ITKCALL(AOM_unlock(item)); + for (int i = 0; i < beans.size(); i++) { + tag_t table = tableRow[i]; + ITKCALL(AOM_lock(table)); + ITKCALL(AOM_set_value_string(table,"zt2_code", beans[i].no.c_str())); + ITKCALL(AOM_set_value_string(table, "zt2_jjxbh", beans[i].mentNo.c_str())); + ITKCALL(AOM_set_value_string(table, "zt2_jyxmc", beans[i].mentDesc.c_str())); + ITKCALL(AOM_set_value_string(table, "zt2_jyxsjjg", beans[i].mentResult.c_str())); + ITKCALL(AOM_save(table)); + ITKCALL(AOM_unlock(table)); + } + ITKCALL(AOM_save(towGx)); + save_representation2(towGx, item, "ZT2_QualityCheckRelation"); + } + +} +void getGxbmMap(tag_t processTag, map& gxDocMap, map timebeans, + map> flBeanMap,string th,string lastId) { + int bvr_count = 0; + tag_t ebom_window = NULLTAG; + tag_t bom_line = NULLTAG; + tag_t item_tag = NULLTAG, *c_line_tags; + ITKCALL(BOM_create_window(&ebom_window)); + tag_t* bvr_list = NULL; + ITKCALL(ITEM_rev_list_bom_view_revs(processTag, &bvr_count, &bvr_list)); + printf("bvr_count=%d", bvr_count); + + ITKCALL(BOM_set_window_top_line_bvr(ebom_window, bvr_list[0], &bom_line)); //顶层bom获取 + //bom_line工艺 + int c_line_count; + ITKCALL(BOM_line_ask_all_child_lines(bom_line, &c_line_count, &c_line_tags)); // 一级工序 + + //修改工时 + for (int i = 0; i < c_line_count; i++) { + tag_t oneGx = c_line_tags[i], *towGxLines; + char* gxbm1; + ITKCALL(AOM_ask_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_ClassificationCode", &gxbm1)); + if (timebeans.count(gxbm1) > 0) { + ITKCALL(AOM_lock(oneGx)); + TimeBean tbean = timebeans[gxbm1]; + ITKCALL(AOM_set_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_ArtificialTime", tbean.rgsj.c_str())); + ITKCALL(AOM_set_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_MachineTime", tbean.jqsj.c_str())); + ITKCALL(AOM_set_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_ReadinessTime", tbean.zbsj.c_str())); + ITKCALL(AOM_set_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_ProCycle", tbean.zrsczq.c_str())); + ITKCALL(AOM_save(oneGx)); + ITKCALL(AOM_unlock(oneGx)); + } + int c_cnt = 0; + ITKCALL(BOM_line_ask_all_child_lines(oneGx, &c_cnt, &towGxLines)); + for (int j = 0; j < c_cnt; j++) { + tag_t towGxLine = towGxLines[j]; + tag_t towGx; + char* gxbm2; + ITKCALL(AOM_ask_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ClassificationCode", &gxbm2)); + if (timebeans.count(gxbm2) > 0) { + ITKCALL(AOM_lock(towGxLine)); + TimeBean tbean = timebeans[gxbm2]; + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ArtificialTime", tbean.rgsj.c_str())); + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_MachineTime", tbean.jqsj.c_str())); + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ReadinessTime", tbean.zbsj.c_str())); + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ProCycle", tbean.zrsczq.c_str())); + ITKCALL(AOM_save(towGxLine)); + ITKCALL(AOM_unlock(towGxLine)); + } + char* name = NULL; + ITKCALL(AOM_ask_value_tag(towGxLine, "bl_line_object", &towGx)); + ITKCALL(AOM_ask_value_string(towGx, "object_name", &name)); + //设置质检项 + setZljyx(gxbm2,th, lastId, name, towGx); + if (flBeanMap.count(gxbm2) > 0) { + vector beansVec = flBeanMap[gxbm2]; + printf("beansVec===>%zd\n", beansVec.size()); + if (beansVec.size() > 0) { + tag_t axqPmatnr; + ITKCALL(AOM_ask_value_tag(towGxLine, "bl_line_object", &axqPmatnr)); + ITKCALL(ITEM_rev_list_bom_view_revs(axqPmatnr, &bvr_count, &bvr_list)); + printf("bvr_count=%d\n", bvr_count); + if (bvr_count == 0) { + tag_t newView, newViewBvr, pitem; + ITKCALL(ITEM_ask_item_of_rev(axqPmatnr, &pitem)); + ITKCALL(PS_create_bom_view(NULL, NULL, NULL, pitem, &newView)); + ITKCALL(AOM_save(newView)); + ITKCALL(PS_create_bvr(newView, NULL, NULL, FALSE, axqPmatnr, &newViewBvr)); + ITKCALL(AOM_save(newViewBvr)); + ITKCALL(AOM_save(axqPmatnr)); + } + } + //投辅料 + for (int n = 0; n < beansVec.size(); n++) { + tag_t cLine; + FlBean cBean = beansVec[n]; + if (cBean.flTag == NULLTAG) { + continue; + } + ITKCALL(BOM_line_add(towGxLine, NULL, cBean.flTag, NULL, &cLine)); + ITKCALL(AOM_lock(cLine)); + string num = cBean.blQty; + ITKCALL(AOM_set_value_string(cLine, "bl_quantity", num.c_str())); + string seqNo = to_string((n + 1) * 10); + ITKCALL(AOM_set_value_string(cLine, "bl_sequence_no", seqNo.c_str())); + ITKCALL(AOM_set_value_string(cLine, "bl_occ_type", "ZT2_FuLiao")); + ITKCALL(AOM_save(cLine)); + //最后unlock + ITKCALL(AOM_unlock(cLine)); + ITKCALL(AOM_refresh(cLine, FALSE)); + } + + } + + gxDocMap[gxbm2] = towGx; + } + } + ITKCALL(BOM_save_window(ebom_window)); + ITKCALL(BOM_close_window(ebom_window)); +} +void getGxbmMap(tag_t processTag, map& gxDocMap, map timebeans) { + int bvr_count = 0; + tag_t ebom_window = NULLTAG, bom_line = NULLTAG, item_tag = NULLTAG, *c_line_tags = NULLTAG; + ITKCALL(BOM_create_window(&ebom_window)); + tag_t* bvr_list = NULL; + ITKCALL(ITEM_rev_list_bom_view_revs(processTag, &bvr_count, &bvr_list)); + printf("bvr_count=%d", bvr_count); + + ITKCALL(BOM_set_window_top_line_bvr(ebom_window, bvr_list[0], &bom_line)); //顶层bom获取 + //bom_line工艺 + int c_line_count; + ITKCALL(BOM_line_ask_all_child_lines(bom_line, &c_line_count, &c_line_tags)); // 一级工序 + + for (int i = 0; i < c_line_count; i++) { + tag_t oneGx = c_line_tags[i], *towGxLines; + char* gxbm1; + ITKCALL(AOM_ask_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_ClassificationCode", &gxbm1)); + if (timebeans.count(gxbm1) > 0) { + ITKCALL(AOM_lock(oneGx)); + TimeBean tbean = timebeans[gxbm1]; + ITKCALL(AOM_set_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_ArtificialTime", tbean.rgsj.c_str())); + ITKCALL(AOM_set_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_MachineTime", tbean.jqsj.c_str())); + ITKCALL(AOM_set_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_ReadinessTime", tbean.zbsj.c_str())); + ITKCALL(AOM_set_value_string(oneGx, "bl_ZT2_FirstOPRevision_zt2_ProCycle", tbean.zrsczq.c_str())); + ITKCALL(AOM_save(oneGx)); + ITKCALL(AOM_unlock(oneGx)); + } + int c_cnt = 0; + ITKCALL(BOM_line_ask_all_child_lines(oneGx, &c_cnt, &towGxLines)); + for (int j = 0; j < c_cnt; j++) { + tag_t towGxLine = towGxLines[j]; + tag_t towGx; + char* gxbm2; + ITKCALL(AOM_ask_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ClassificationCode", &gxbm2)); + if (timebeans.count(gxbm2) > 0) { + ITKCALL(AOM_lock(towGxLine)); + TimeBean tbean = timebeans[gxbm2]; + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ArtificialTime", tbean.rgsj.c_str())); + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_MachineTime", tbean.jqsj.c_str())); + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ReadinessTime", tbean.zbsj.c_str())); + ITKCALL(AOM_set_value_string(towGxLine, "bl_ZT2_FirstOPRevision_zt2_ProCycle", tbean.zrsczq.c_str())); + ITKCALL(AOM_save(towGxLine)); + ITKCALL(AOM_unlock(towGxLine)); + } + ITKCALL(AOM_ask_value_tag(towGxLine, "bl_line_object", &towGx)); + gxDocMap[gxbm2] = towGx; + } + } + ITKCALL(BOM_close_window(ebom_window)); +} + +//查询ID +tag_t * queryItem(char* itemId,tag_t newGx,char *relation) { + tag_t query_tag = NULLTAG,*tags=NULLTAG; + ITKCALL(QRY_find("零组件...", &query_tag)); + char* qry_entries[1] = { "零组件 ID" }, *qry_values[1] = { itemId }; + int n_found; + ITKCALL(QRY_execute(query_tag, 1, qry_entries, qry_values, &n_found, &tags)); + if (n_found > 0) { + ITKCALL(AOM_set_value_tags(newGx, relation, n_found, tags)); + } + return tags; +} +//根据数据库获取ID 2023/12/19 新增逻辑 +void queryProcessRule(char *windWay, boolean isXq, char *processCode, tag_t &newGx) { + + char selectGyId[200]; //根据工厂M060 二级工序编码 绕线方式(线圈) 获取工时信息 + if (isXq) { + string sqlRuleId = "select \"processroutefiles\",\"esopfiles\" from CHINT_PROCESS_SOP_RULE where \"companycode\" = 'M060' and \"windway\" = '%s' and \"gxcode\" = '%s' "; + sprintf(selectGyId, sqlRuleId.c_str(), windWay, processCode); + } + else { + string sqlRuleId = "select \"processroutefiles\",\"esopfiles\" from CHINT_PROCESS_SOP_RULE where \"companycode\" = 'M060' and \"gxcode\" = '%s' "; + sprintf(selectGyId, sqlRuleId.c_str(), processCode); + } + printf("selectGyId %s \n", selectGyId); + int outputColumn3 = 0, outputValueCount3 = 0; + char*** outputValue3 = NULL; + QuerySQLNoInputParam(selectGyId, &outputColumn3, &outputValueCount3, &outputValue3); + printf("outputValueCount3 %d \n", outputValueCount3); + string processIds, esopIds; + for (int j = 0; j < outputValueCount3; j++) { + char* processId = outputValue3[j][0]; + char* esopId = outputValue3[j][1]; + if (strcmp(processId, "") != 0) { + processIds.append(processId).append(";"); + } + if (strcmp(esopId, "") != 0) { + esopIds.append(esopId).append(";"); + } + } + queryItem((char*)processIds.c_str(), newGx,"ZT2_ProcessRuleRelation"); + queryItem((char*)esopIds.c_str(), newGx, "ZT2_ProcGuidBookRelation"); +} + +tag_t clone_process_from_template(char* process_item_id, boolean isXq, string productZu, string xqfs,string th, string lastId) +{ + tag_t item_tag = NULLTAG; + ITKCALL(ITEM_find_item(process_item_id, &item_tag)); + if (item_tag == NULLTAG) + { + printf("\n MEProcess NOT found! \n"); + return NULLTAG; + } + tag_t revision_tag = NULLTAG; + ITKCALL(ITEM_ask_latest_rev(item_tag, &revision_tag)); + char* nameOld, *item_revision_id; + ITKCALL(AOM_ask_value_string(revision_tag, "item_revision_id", &item_revision_id)); + ITKCALL(AOM_ask_value_string(revision_tag, "object_name", &nameOld)); + ITKCALL(MEBOM_init_module()); + + tag_t window_tag = NULLTAG; + ITKCALL(ME_create_bop_window(&window_tag)); + + tag_t rule_tag = NULLTAG; + ITKCALL(CFM_find("Latest Working", &rule_tag)); + + ITKCALL(BOM_set_window_config_rule(window_tag, rule_tag)); + //AOM_ask + char* next_id = NULL; + ITKCALL(NR_next_value("MEProcess", "item_id", NULLTAG, "", "", "", + NULLTAG, "", "", &next_id)); + + tag_t clone_tag = NULLTAG; + ITKCALL(ME_create_process_from_template(next_id, item_revision_id, + nameOld, "", revision_tag, rule_tag, window_tag, + "Process.Template.Mapping_Consumes", &clone_tag)); + + if (next_id) MEM_free(next_id); + + ITKCALL(AOM_refresh(clone_tag, TRUE)); + ITKCALL(AOM_save(clone_tag)); + ITKCALL(AOM_refresh(clone_tag, FALSE)); + + char* item_id = NULL; + ITKCALL(WSOM_ask_id_string(clone_tag, &item_id)); + + printf("\n\t MEProcess Clone ID: %s\n", item_id); + ITKCALL(AOM_unload(clone_tag)); + + if (item_id != NULL) + MEM_free(item_id); + + //复制“工艺守则”、“工序作业指导书” + + if (isXq) { + char selectRxfs[200]; + sprintf(selectRxfs, sqlRxfs.c_str(), xqfs.c_str()); + int outputColumn1 = 0, outputValueCount1 = 0; + char*** outputValue1 = NULL; + printf("search3 ===> %s\n", selectRxfs); + QuerySQLNoInputParam(selectRxfs, &outputColumn1, &outputValueCount1, &outputValue1); + map temGxMap; + printf("search result ===> %d\n", outputValueCount1); + for (int num = 0; num < outputValueCount1; num++) { + //TarGXCODE\", \"TarGXNAME\", \"TemGXCODE\", \"TemGXNAME + string tarGxCode = outputValue1[num][0]; + string tarGxName = outputValue1[num][1]; + string temGxCode = outputValue1[num][2]; + TemGxBean bean; + bean.temGxCode = tarGxCode; + bean.temGxName = tarGxName; + temGxMap[temGxCode] = bean; + } + //更新 根据数据库配置更新工序编码和名称 + updateTemGxCode(clone_tag, temGxMap); + } + //if (!isXq) { + map tmpProcessMap; //存放的是二级工序编码对应的二级工序版本 模板的 + //vector timeVec; + //工艺模板 + map beanMap; + //根据数据库配置修改工时 + getGxbmMap(revision_tag, tmpProcessMap, beanMap); + map newProcessMap;//存放的是二级工序编码对应的二级工序版本 克隆出来的 + char selectGyId[200]; //根据产品族 模板id 绕线方式(线圈) 获取工时信息 + if (isXq) { + sprintf(selectGyId, sqlGxTime2.c_str(), productZu.c_str(), process_item_id, xqfs.c_str()); + } + else { + sprintf(selectGyId, sqlGxTime.c_str(), productZu.c_str(), process_item_id); + } + int outputColumn1 = 0, outputValueCount1 = 0; + char*** outputValue1 = NULL; + string gyId; + printf("search3 ===> %s\n", selectGyId); + QuerySQLNoInputParam(selectGyId, &outputColumn1, &outputValueCount1, &outputValue1); + //查询结果 四种工时 + for (int num = 0; num < outputValueCount1; num++) { + string gxbm = outputValue1[num][0]; + string rgsj = outputValue1[num][1]; + if (rgsj.rfind(".", 0) == 0) { + string a = "0"; + rgsj = a.append(rgsj); + printf("rgsj === >%s\n", rgsj.c_str()); + } + string jqsj = outputValue1[num][2]; + if (jqsj.rfind(".", 0) == 0) { + string a = "0"; + jqsj = a.append(jqsj); + } + string zbsj = outputValue1[num][3]; + if (zbsj.rfind(".", 0) == 0) { + string a = "0"; + zbsj = a.append(zbsj); + printf("zbsj === >%s\n", zbsj.c_str()); + } + string zrsczq = outputValue1[num][4]; + if (zrsczq.rfind(".", 0) == 0) { + string a = "0"; + zrsczq = a.append(zrsczq); + printf("zrsczq === >%s\n", zrsczq.c_str()); + } + TimeBean bean; + bean.rgsj = rgsj; + bean.jqsj = jqsj; + bean.zbsj = zbsj; + bean.zrsczq = zrsczq; + beanMap[gxbm] = bean; + } + //克隆出来的工艺路线 + regex qq_reg22("^1ZDB5.*\\d{2,}000X.*"); //\\d{5,}$ + smatch result; + bool ret = regex_match(th, result, qq_reg22); + string searchTh = th; + if (ret) { + searchTh = "1ZDB5**000X"; + } + //查询二级工序编码的信息,更新克隆出来的BOM的工序编码 + string sqlFl = "select \"materialno\",\"EJBM\",\"quantity\",\"xuhao\" from CHINT_GYFL_001 where \"ProductZu\" = '%s' and \"TuHao\" ='%s' and \"quantity\" !='/' ORDER BY CAST(\"xuhao\" AS DECIMAL) asc"; + char selectFlId[600]; + sprintf(selectFlId, sqlFl.c_str(), productZu.c_str(), searchTh); + printf("selectFlId==>%s\n", selectFlId); + map> flBeanMap; + { + int outputColumn3 = 0, outputValueCount3 = 0; + char*** outputValue3 = NULL; + QuerySQLNoInputParam(selectFlId, &outputColumn3, &outputValueCount3, &outputValue3); + for (int j = 0; j < outputValueCount3; j++) { + string materialno = outputValue3[j][0]; + string ejbm = outputValue3[j][1]; + string quantity = outputValue3[j][2]; + tag_t fltag,flRev; + ITEM_find_item(materialno.c_str(),&fltag); + ITEM_ask_latest_rev(fltag,&flRev); + printf("materialno%s ejbm==%sEnd\n", materialno.c_str(), ejbm.c_str()); + FlBean bean; + bean.blQty = quantity; + bean.flTag = flRev; + if (flBeanMap.count(ejbm) > 0) { + flBeanMap[ejbm].push_back(bean); + } + else { + vector beansVec; + beansVec.push_back(bean); + flBeanMap[ejbm] = beansVec; + } + } + } + + getGxbmMap(clone_tag, newProcessMap, beanMap, flBeanMap,th, lastId); + map::iterator it; + //复制“工艺守则”、“工序作业指导书” 旧逻辑 + /*for (it = tmpProcessMap.begin(); it != tmpProcessMap.end(); it++) { + string gxbm = it->first; + tag_t tmpGx = it->second; + if (newProcessMap.count(gxbm) != 0) { + tag_t* procGuidBooks, *processRules; + int cnt2 = 0, cnt3 = 0; + tag_t newGx = newProcessMap[gxbm]; + ITKCALL(AOM_ask_value_tags(tmpGx, "ZT2_ProcGuidBookRelation", &cnt2, &procGuidBooks)); + ITKCALL(AOM_ask_value_tags(tmpGx, "ZT2_ProcessRuleRelation", &cnt3, &processRules)); + AOM_lock(newGx); + if (cnt2 > 0) { + ITKCALL(AOM_set_value_tags(newGx, "ZT2_ProcGuidBookRelation", cnt2, procGuidBooks)); + } + if (cnt3 > 0) { + ITKCALL(AOM_set_value_tags(newGx, "ZT2_ProcessRuleRelation", cnt3, processRules)); + } + AOM_save(newGx); + AOM_unlock(newGx); + } + }*/ + //复制“工艺守则”、“工序作业指导书” 2023/12/19新增逻辑 CHINT_PROCESS_SOP_RULE 表中查询 + for (it = newProcessMap.begin(); it != newProcessMap.end(); it++) { + string gxbm = it->first; + tag_t newGx = it->second; + queryProcessRule((char*)xqfs.c_str(), isXq, (char*)gxbm.c_str(), newGx); + /*if (newProcessMap.count(gxbm) != 0) { + tag_t* procGuidBooks, *processRules; + int cnt2 = 0, cnt3 = 0; + if (isXq) { + sprintf(selectGyId, sqlGxTime2.c_str(), productZu.c_str(), process_item_id, xqfs.c_str()); + } + tag_t newGx = newProcessMap[gxbm]; + ITKCALL(AOM_ask_value_tags(tmpGx, "ZT2_ProcGuidBookRelation", &cnt2, &procGuidBooks)); + ITKCALL(AOM_ask_value_tags(tmpGx, "ZT2_ProcessRuleRelation", &cnt3, &processRules)); + AOM_lock(newGx); + if (cnt2 > 0) { + ITKCALL(AOM_set_value_tags(newGx, "ZT2_ProcGuidBookRelation", cnt2, procGuidBooks)); + } + if (cnt3 > 0) { + ITKCALL(AOM_set_value_tags(newGx, "ZT2_ProcessRuleRelation", cnt3, processRules)); + } + AOM_save(newGx); + AOM_unlock(newGx); + }*/ + } + //} + return clone_tag; +} +//实体且有BOM往下 +boolean isXn(tag_t matnr) { + int cnt2, numFac, cnt3; + boolean flag = false; + char** procureType, ** factorys, ** specialProcureType; + AOM_ask_value_strings(matnr, "zt2_SZSpecialProcuretype", &cnt3, &specialProcureType); //为/ + AOM_ask_value_strings(matnr, "zt2_SZProcuretype", &cnt2, &procureType); //包含自制 + AOM_ask_value_strings(matnr, "zt2_SZFactory", &numFac, &factorys); + for (int i = 0; i < numFac; i++) { + if (strcmp(factorys[i], "M060") == 0 && cnt2 > i && cnt3 > i) { + if (strstr(procureType[i], "自制") != NULL && strcmp(specialProcureType[i], "/") == 0) { + flag = true; + } + } + } + return flag; +} +//获取分类属性 判断是否整除 +string getClassVal(tag_t top_rev_tag, string& errMessage, ByqBean &bean) { + //, string className + tag_t top_classificationObject = NULLTAG, item = NULLTAG; + ITKCALL(ITEM_ask_item_of_rev(top_rev_tag, &item)); + ITKCALL(ICS_ask_classification_object(item, &top_classificationObject)); + if (top_classificationObject == NULL_TAG) + { + errMessage.append("顶层对象没有发送到分类\n"); + return ""; + } + char* top_class_id = NULL, *top_class_name = NULL; + //ICS_ask_class_of_classification_obj(top_classificationObject, &top_class_tag); + //ICS_ask_id_name(top_class_tag, &top_class_id, &top_class_name); + printf("BOM TOP LINE CLASS ID = %s | NAME = %s \n", top_class_id, top_class_name); + int n_attrs; + char** attr_names = NULL, ** attr_vals = NULL; + ITKCALL(ICS_ask_attributes_of_classification_obj(top_classificationObject, &n_attrs, &attr_names, &attr_vals)); + cout << n_attrs << endl; + // int num = 1; + string cpxh; + for (int ii = 0; ii < n_attrs; ii++) + { + if (strcmp(attr_names[ii], "产品型号") == 0) { + if (strcmp(attr_vals[ii], "") == 0) { + errMessage.append("分类属性产品型号为空,请检查。\n"); + return ""; + } + else { + cpxh = (attr_vals[ii]); + } + //break; + } + else if (strcmp(attr_names[ii], "低压线圈绕线方式") == 0) { + if (strcmp(attr_vals[ii], "") == 0) { + //errMessage.append("分类属性低压线圈绕线方式为空,请检查。\n"); + //return ""; + } + else { + bean.dyxq = attr_vals[ii];//cpxh = (attr_vals[ii]); + } + //break; + } + else if (strcmp(attr_names[ii], "中压线圈绕线方式") == 0) { + if (strcmp(attr_vals[ii], "") == 0) { + //errMessage.append("分类属性中压线圈绕线方式为空,请检查。\n"); + //return ""; + } + else { + bean.zyxq = attr_vals[ii];//cpxh = (attr_vals[ii]); + } + //break; + } + else if (strcmp(attr_names[ii], "高压线圈绕线方式") == 0) { + if (strcmp(attr_vals[ii], "") == 0) { + //errMessage.append("分类属性高压线圈绕线方式为空,请检查。\n"); + //return ""; + } + else { + bean.gyxq = attr_vals[ii];//cpxh = (attr_vals[ii]); + } + //break; + } + else if (strcmp(attr_names[ii], "调压线圈绕线方式") == 0) { + if (strcmp(attr_vals[ii], "") == 0) { + //errMessage.append("分类属性调压线圈绕线方式为空,请检查。\n"); + //return ""; + } + else { + bean.tyxq = attr_vals[ii];//cpxh = (attr_vals[ii]); + } + //break; + } + else if (strcmp(attr_names[ii], "稳压线圈绕线方式") == 0) { + if (strcmp(attr_vals[ii], "") == 0) { + // errMessage.append("分类属性稳压线圈绕线方式为空,请检查。\n"); + //return ""; + } + else { + bean.wyxq = attr_vals[ii];//cpxh = (attr_vals[ii]); + } + //break; + } + //五柱铁心 + cout << attr_names[ii] << "\t" + << attr_vals[ii] << endl; + } + return cpxh; +} +//包含线圈 + +//不包含线圈 +void Split2(string strArg, string spliter, vector& ans) +{ + ans.clear(); + size_t index0 = 0; + string one_arg; + if (strArg.find_first_not_of(' ') == string::npos) + strArg = ""; + while (strArg.size() > 0) + { + index0 = strArg.find_first_of(spliter); + if (index0 != string::npos) + { + one_arg = strArg.substr(0, index0); + strArg = strArg.substr(index0 + 1); + ans.push_back(one_arg); + } + else + { + ans.push_back(strArg); + break; + } + } +} +tag_t getTmpProcess(string cpxh, string th, string& errBuff, string& oldGyId, boolean isXq, string xqfs,string lastId) { + char selectCPZ[300], selectGyId[200]; + sprintf(selectCPZ, sqlCpxh.c_str(), cpxh.c_str()); + int outputColumn = 0, outputValueCount = 0; + char*** outputValue = NULL; + string productZu; + printf("search1 %s \n", selectCPZ); + QuerySQLNoInputParam(selectCPZ, &outputColumn, &outputValueCount, &outputValue); + printf("search11\n"); + if (outputValueCount == 0) { + string buffMsg = ""; + buffMsg.append("当前变压器产品型号:").append(cpxh).append(",在数据库表中无对应典型产品族值,请联系管理员维护.\n"); + size_t found = errBuff.find(buffMsg); + if (found == std::string::npos) { + errBuff.append(buffMsg); + } + //errBuff.append("当前变压器产品型号:").append(cpxh).append(",在数据库表中无对应典型产品族值,请联系管理员维护.\n"); + return NULLTAG; + } + for (int j = 0; j < outputValueCount; j++) { + productZu = outputValue[j][0]; + printf("productZu===>%s\n", productZu.c_str()); + } + + sprintf(selectGyId, sqlGyRule.c_str(), productZu.c_str(), th.c_str()); + + int outputColumn1 = 0, outputValueCount1 = 0; + char*** outputValue1 = NULL; + string gyId; + printf("search2 %s \n", selectGyId); + QuerySQLNoInputParam(selectGyId, &outputColumn1, &outputValueCount1, &outputValue1); + if (outputValueCount1 == 0) { + errBuff.append("图号:").append(th).append("无对应工艺模板ID,请维护后再指派工艺路线.\n"); + return NULLTAG; + } + printf("search22\n"); + for (int j = 0; j < outputValueCount1; j++) { + gyId = outputValue1[j][0]; + printf("gyId===>%s\n", gyId.c_str()); + } + oldGyId = gyId; + //新增逻辑校验时间和绕线方式 + { + char selectGyId[200]; + if (isXq) { + sprintf(selectGyId, sqlProTime2.c_str(), productZu.c_str(), (char*)gyId.c_str(), xqfs.c_str()); + } + else { + sprintf(selectGyId, sqlProTime.c_str(), productZu.c_str(), (char*)gyId.c_str()); + } + int outputColumn2 = 0, outputValueCount2 = 0; + char*** outputValue2 = NULL; + string gyId; + printf("search3 ===> %s\n", selectGyId); + boolean hasErr = false; + QuerySQLNoInputParam(selectGyId, &outputColumn2, &outputValueCount2, &outputValue2); + for (int t = 0; t < outputValueCount2; t++) { + string gyName = outputValue2[t][0]; + string gxName = outputValue2[t][1]; + errBuff.append("一级工序名称:").append(gyName).append(" 对应的二级工序:").append(gxName).append("的自然生产周期数据不正确,请及时维护.\n"); + } + if (outputValue2>0) { + hasErr = true; + } + if (isXq) { + char selectRxfs[200]; + sprintf(selectRxfs, sqlRxfs.c_str(), xqfs.c_str()); + int outputColumn3 = 0, outputValueCount3 = 0; + char*** outputValue3 = NULL; + printf("search3 ===> %s\n", selectRxfs); + QuerySQLNoInputParam(selectRxfs, &outputColumn3, &outputValueCount3, &outputValue3); + printf("search result ===> %d\n", outputValueCount3); + if (outputValueCount3 == 0) { + errBuff.append("绕线方式:").append(xqfs).append(" 未在CHINT_WORKHOUR_WhGXName表中配置,请及时维护"); + hasErr = true; + } + } + if (hasErr) { + return NULLTAG; + } + } + tag_t clone_tag = clone_process_from_template((char*)gyId.c_str(), isXq, productZu, xqfs, th, lastId); + printf("克隆完成===>\n"); + return clone_tag; +} +boolean isTcmOnNot(tag_t process) { + int structs = 0; + boolean flag = false; + tag_t *structure_revisions; + AOM_ask_value_tags(process, "structure_revisions", &structs, &structure_revisions); + if (structs > 0) { + int statusNum = 0; + char *revUid; + tag_t *release_status_list; + tag_t struct_revision = structure_revisions[0]; + AOM_ask_value_tags(struct_revision, "release_status_list", &statusNum, &release_status_list); + if (statusNum > 0) { + flag = true; + } + } + return flag; +} +void readProcessBom(tag_t bom_line, string& errorBuff, boolean &flag, tag_t &topProcess, string ¬TcmBuff, string back) { + + int c_line_count; + tag_t mantr, *c_line_tags; + ITKCALL(AOM_ask_value_tag(bom_line, "bl_line_object", &mantr)); + ITKCALL(BOM_line_ask_all_child_lines(bom_line, &c_line_count, &c_line_tags)); + char *objName; + AOM_ask_value_string(mantr, "object_name", &objName); + if (c_line_count > 0 && (isXn(mantr)|| strstr(objName, "变压器") != NULL)) { + printf("实体\n"); + flag = true; + //检查是否有工艺路线 + int n_references = 0; + int* levels = 0; + tag_t* references_tag = NULLTAG; + char** relation_type_name = NULL; + //通过引用关系查找到变更单 + ITKCALL(WSOM_where_referenced(mantr, 1, &n_references, &levels, &references_tag, &relation_type_name)); + boolean hasProcess = false; + for (int i = 0; i < n_references; i++) + { + char* refType; + tag_t refTag = references_tag[i]; + ITKCALL(AOM_ask_value_string(refTag, "object_type", &refType)); + if (strcmp(refType, "MEProcessRevision") == 0) { + hasProcess = true; + break; + } + } + printf("hasProcess==%d\n", hasProcess); + if (!hasProcess) { + char* bl_desc = NULL, * itemID = NULL; + ITKCALL(AOM_ask_value_string(mantr, "item_id", &itemID)); + printf("back==%zd\n", back.size()); + if (back.size() > 0) { + vector backs; + Split2(back, "@", backs); + tag_t processTag = NULLTAG; + string tmpGyId; + processTag = getTmpProcess(backs[0], backs[1], errorBuff, tmpGyId, false, "", ""); + topProcess = processTag; + if (processTag != NULLTAG) { + printf("save_representation2\n"); + save_representation2(processTag, mantr, "IMAN_METarget"); + } + } + else if (strstr(objName, "变压器") != NULL) { + tag_t* byqRev = NULLTAG; + string tmpGyId; + char* uid = NULL; + int cnt3 = 0; + ITKCALL(AOM_ask_value_tags(mantr, "TC_Is_Represented_By", &cnt3, &byqRev)); + ByqBean bean; + ITK__convert_tag_to_uid(byqRev[0], &uid); + printf("objName%s %s\n", objName, uid); + string cpxh = getClassVal(byqRev[0], errorBuff, bean); + char* thId = NULL; + ITKCALL(AOM_ask_value_string(byqRev[0], "item_id", &thId)); + printf("cpxh===>%s\n", cpxh.c_str()); + tag_t processTag = NULLTAG; + if (strstr(objName, "线圈") == NULL) { + vector idVec; + Split2(thId, "-", idVec); + processTag = getTmpProcess(cpxh, "1ZDB300000P", errorBuff, tmpGyId, false, "", idVec[1]); + topProcess = processTag; + if (processTag != NULLTAG) { + save_representation2(processTag, mantr, "IMAN_METarget"); + } + } + } + else { + ITKCALL(AOM_ask_value_string(bom_line, "bl_rev_object_desc", &bl_desc)); + vector descVec1; + Split2(bl_desc, " ", descVec1); + if (descVec1.size() > 1) { + string drawNos = descVec1[1]; + vector drawNoVec1; + Split2(drawNos, "-", drawNoVec1); + if (drawNoVec1.size() > 1) { + string wordNo = drawNoVec1[1]; //工程号 拼接1ZDB300000P 查找分类属性 + string drawNo = drawNoVec1[0]; //图号 + if (drawNoVec1.size() == 3) { + drawNo = drawNoVec1[0].append("-").append(drawNoVec1[1]); + wordNo = drawNoVec1[2]; + } + string byqId = "1ZDB300000P-", tmpGyId; + tag_t byqTag = NULLTAG, byqRev = NULLTAG, processTag = NULLTAG; + byqId.append(wordNo); + ITKCALL(ITEM_find_item(byqId.c_str(), &byqTag)); + ITKCALL(ITEM_ask_latest_rev(byqTag, &byqRev)); + ByqBean bean; + string cpxh = getClassVal(byqRev, errorBuff, bean); + printf("cpxh===>%s\n", cpxh.c_str()); + if (strstr(objName, "线圈") == NULL) { + processTag = getTmpProcess(cpxh, drawNo, errorBuff, tmpGyId, false, "", wordNo); + if (processTag != NULLTAG) { + save_representation2(processTag, mantr, "IMAN_METarget"); + } + } + else { + string xqfs; + if (strstr(objName, "低压线圈") != NULL) { + //当前XXX线圈未在变压器参数表中维护绕线方式分类属性,请前往维护 + if (bean.dyxq.empty()) { + errorBuff.append("当前低压线圈未在变压器参数表中维护绕线方式分类属性,请前往维护\n"); + return; + } + xqfs = bean.dyxq; + } + else if (strstr(objName, "中压线圈") != NULL) { + //当前XXX线圈未在变压器参数表中维护绕线方式分类属性,请前往维护 + if (bean.zyxq.empty()) { + errorBuff.append("当前中压线圈未在变压器参数表中维护绕线方式分类属性,请前往维护\n"); + return; + } + xqfs = bean.zyxq; + } + else if (strstr(objName, "高压线圈") != NULL) { + //当前XXX线圈未在变压器参数表中维护绕线方式分类属性,请前往维护 + if (bean.gyxq.empty()) { + errorBuff.append("当前高压线圈未在变压器参数表中维护绕线方式分类属性,请前往维护\n"); + return; + } + xqfs = bean.gyxq; + } + else if (strstr(objName, "调压线圈") != NULL) { + //当前XXX线圈未在变压器参数表中维护绕线方式分类属性,请前往维护 + if (bean.tyxq.empty()) { + errorBuff.append("当前调压线圈未在变压器参数表中维护绕线方式分类属性,请前往维护\n"); + return; + } + xqfs = bean.tyxq; + } + else if (strstr(objName, "稳压线圈") != NULL) { + //当前XXX线圈未在变压器参数表中维护绕线方式分类属性,请前往维护 + if (bean.wyxq.empty()) { + errorBuff.append("当前稳压线圈未在变压器参数表中维护绕线方式分类属性,请前往维护\n"); + return; + } + xqfs = bean.wyxq; + } + processTag = getTmpProcess(cpxh, drawNo, errorBuff, tmpGyId, true, xqfs, wordNo); + if (processTag != NULLTAG) { + save_representation2(processTag, mantr, "IMAN_METarget"); + } + } + } + } + } + } + } + printf("sub readProcessBom\n"); + for (int i = 0; i < c_line_count; i++) { + tag_t c_line_tag = c_line_tags[i]; + readProcessBom(c_line_tag, errorBuff, flag, topProcess, notTcmBuff, ""); + } +} + +tag_t getProcess(tag_t designRev) { + int n_references = 0; + int* levels = 0; + tag_t process = NULLTAG; + tag_t* references_tag = NULLTAG; + char** relation_type_name = NULL; + //通过引用关系查找到变更单 + ITKCALL(WSOM_where_referenced(designRev, 1, &n_references, &levels, &references_tag, &relation_type_name)); + boolean hasProcess = false; + for (int i = 0; i < n_references; i++) + { + char* refType; + tag_t refTag = references_tag[i]; + ITKCALL(AOM_ask_value_string(refTag, "object_type", &refType)); + if (strcmp(refType, "MEProcessRevision") == 0) { + hasProcess = true; + process = refTag; + break; + } + } + return process; +} +int CloneTempProcess(void *returnValue) +{ + int ifail = ITK_ok; + char* sql = NULL, *revUid; + tag_t designRev; + ITKCALL(ifail = USERARG_get_string_argument(&revUid)); + ITK__convert_uid_to_tag(revUid, &designRev); + int bvr_count = 0, c_line_count; + tag_t ebom_window = NULLTAG; + tag_t bom_line = NULLTAG; + tag_t item_tag = NULLTAG, *c_line_tags = NULLTAG; + (BOM_create_window(&ebom_window)); + tag_t* bvr_list = NULL; + ITKCALL(ITEM_rev_list_bom_view_revs(designRev, &bvr_count, &bvr_list)); + printf("bvr_count=%d", bvr_count); + + ITKCALL(BOM_set_window_top_line_bvr(ebom_window, bvr_list[0], &bom_line)); //顶层bom获取 + string errorBuff; + string notTcmBuff; + char *bl_desc; + ITKCALL(AOM_ask_value_string(bom_line, "bl_rev_object_desc", &bl_desc)); + + int n_references = 0; + int* levels = 0; + tag_t* references_tag = NULLTAG; + char** relation_type_name = NULL; + //通过引用关系查找到变更单 + ITKCALL(WSOM_where_referenced(designRev, 1, &n_references, &levels, &references_tag, &relation_type_name)); + boolean hasProcess = false; + tag_t processTagTop = NULLTAG; + for (int i = 0; i < n_references; i++) + { + char* refType; + tag_t refTag = references_tag[i]; + ITKCALL(AOM_ask_value_string(refTag, "object_type", &refType)); + if (strcmp(refType, "MEProcessRevision") == 0) { + hasProcess = true; + processTagTop = refTag; + break; + } + } + int url_num = 0; + char** url_vals = NULL; + ITKCALL(PREF_ask_char_values("database_tc", &url_num, &url_vals)); + string url = url_vals[0]; + url.append("/").append(url_vals[2]); + + //map %s \n", url.c_str()); + if (ConnServer(url_vals[3], url_vals[4], (char*)url.c_str()) == -1) + { + printf("提示:中间数据表访问失败\n"); + ifail = 1; + } + boolean isback = false; + tag_t meProcess = NULLTAG; + char* objName = NULL, * topId = NULL; + string backs = ""; + ITKCALL(AOM_ask_value_string(designRev, "object_name", &objName)); + ITKCALL(AOM_ask_value_string(designRev, "item_id", &topId)); + map mapByq; + //如果是产成品的话, 判断是否存在多个P物料 + //20240203备件包工艺路线指派 + int back_num = 0; + char** back_vals = NULL, * group_name = NULL; + tag_t group = NULLTAG; + string tuhao; + vector group_names; + ITKCALL(POM_ask_group(&group_name, &group)); + Split(group_name, ".", group_names); + printf("group_name=======%s\n", group_names[0].c_str()); + ITKCALL(PREF_ask_char_values("CHINT_PROCESS_RULE", &back_num, &back_vals)); + //首选项格式:组名:匹配字段1;匹配字段2 + for (int i = 0; i < back_num; i++) { + vector group_backs; + Split(back_vals[i], ":", group_backs); + if (tc_strcmp(group_backs[0].c_str(), group_names[0].c_str()) == 0) { + vector backs; + Split(group_backs[1], ";", backs); + for (int j = 0; j < backs.size(); j++) { + if (tc_strstr(objName, backs[j].c_str()) != NULL) { + tuhao = backs[j]; + isback = true; + break; + } + } + if(isback) + break; + } + } + if (isback) { + isback = false; + int b_refs = 0; + int* b_levels = 0; + tag_t* b_refs_tag = NULLTAG; + char** b_rel_name = NULL, * pcode = NULL; + string cpxh = ""; + //判断当前物料对象是否在“产成品”文件夹(ZT2_ProjectFolder)中 + ITKCALL(ITEM_ask_item_of_rev(designRev, &item_tag)); + ITKCALL(WSOM_where_referenced2(item_tag, 1, &b_refs, &b_levels, &b_refs_tag, &b_rel_name)); + for (int i = 0; i < b_refs; i++) { + char* ref_type = NULL; + ITKCALL(AOM_ask_value_string(b_refs_tag[i], "object_type", &ref_type)); + printf("ref_type:%s\n", ref_type); + if (tc_strcmp(ref_type, "ZT2_ProjectFolder") != 0) + continue; + int n_projs = 0; + tag_t* projs = NULLTAG; + ITKCALL(AOM_ask_value_tags(b_refs_tag[i], "contents", &n_projs, &projs)); + for (int j = 0; j < n_projs; j++) { + int n_drows = 0; + tag_t proj_rev = NULLTAG, * drows = NULLTAG; + ITKCALL(ITEM_ask_latest_rev(projs[j], &proj_rev)); + ITKCALL(AOM_ask_value_tags(proj_rev, "TC_Is_Represented_By", &n_drows, &drows)); + printf("n_drows:%d\n", n_drows); + if (n_drows == 0) + continue; + ByqBean bean; + cpxh = getClassVal(drows[0], errorBuff, bean); + isback = true; + break; + } + if (isback) + break; + } + backs.append(cpxh).append("@").append(tuhao); + /*string sql = "select a.GYID from CHINT_WORKHOUR_WhProductXH a,CHINT_WORKHOUR_WhGYRule b "; + sql.append("where a.COMPANYCODE=b.COMPANYCODE and a.ProductZu=b.ProductZu ") + .append("and a.COMPANYCODE='").append(group_name) + .append("' and a.ProductXH='").append(cpxh) + .append("' and b.TuHao='").append(tuhao) + .append("'"); + int outputColumn = 0, outputValueCount = 0; + char*** outputValue = NULL, sqlc[1024]; + tc_strcpy(sqlc, sql.c_str()); + QuerySQLNoInputParam(sqlc, &outputColumn, &outputValueCount, &outputValue); + if (outputValueCount > 0) { + gyid = outputValue[0][0]; + } + for (int i = 0; i < outputValueCount; i++) { + + }*/ + } + else if (strstr(objName, "变压器") != NULL) { + tag_t *topMatnrs,*pMaterials; + int num = 0, num2=0; + ITKCALL(AOM_ask_value_tags(designRev, "TC_Is_Represented_By", &num, &topMatnrs)); + printf("num===>%d\n", num); + if (num >= 1) { + tag_t tzRev = topMatnrs[0]; + ITKCALL(AOM_ask_value_tags(tzRev, "representation_for", &num2, &pMaterials)); + for (int x = 0; x < num2; x++) { + char *pId,*zt2_ifpbom; + tag_t pMatr = pMaterials[x]; + ITKCALL(AOM_ask_value_string(pMatr, "item_id", &pId)); + ITKCALL(AOM_ask_value_string(pMatr, "zt2_ifpbom", &zt2_ifpbom)); + if (strcmp(pId, topId) != 0 && strcmp(zt2_ifpbom,"P")==0) { + tag_t process = getProcess(pMatr); + if (process != NULLTAG) { + meProcess = process; + } + else { + mapByq[pId] = pMatr; + } + } + } + } + if (meProcess != NULLTAG) { + if (!hasProcess) { + save_representation2(meProcess, designRev, "IMAN_METarget"); + } + map::iterator it; + //名称模糊匹配 + for (it = mapByq.begin(); it != mapByq.end(); it++) { + string s = it->first; + tag_t matnrPrev = mapByq[s]; + save_representation2(meProcess, matnrPrev, "IMAN_METarget"); + } + printf("=======\n"); + errorBuff = "当前选中的物料已经存在工艺路线.\n"; + } + else if (processTagTop != NULLTAG) { + map::iterator it; + printf("=======22\n"); + //名称模糊匹配 + for (it = mapByq.begin(); it != mapByq.end(); it++) { + string s = it->first; + tag_t matnrPrev = mapByq[s]; + save_representation2(processTagTop, matnrPrev, "IMAN_METarget"); + } + errorBuff = "当前选中的物料已经存在工艺路线.\n"; + } + } + printf("mapByq===>%zd\n", mapByq.size()); + if (hasProcess) { + errorBuff = "当前选中的物料已经存在工艺路线.\n"; + }else if ((strcmp(bl_desc, "") == 0 || strstr(bl_desc,"-")==NULL) && strstr(objName, "变压器") == NULL && !isback) { + errorBuff = "当前选中的物料版本没有图号信息,请检查.\n"; + } + else { + POM_AM__set_application_bypass(true); + + tag_t topProcess = NULLTAG; + boolean flag = false; + printf("errorBuff==>%s\n", errorBuff.c_str()); + readProcessBom(bom_line, errorBuff, flag, topProcess, notTcmBuff, backs); + if (topProcess != NULLTAG) { + map::iterator it; + for (it = mapByq.begin(); it != mapByq.end(); it++) { + string s = it->first; + tag_t matnrPrev = mapByq[s]; + save_representation2(topProcess, matnrPrev, "IMAN_METarget"); + } + } + if (!flag) { + errorBuff = "当前选中的PBOM没有实件,无需做工艺路线."; + } + POM_AM__set_application_bypass(false); + } + DisConnServer(); + errorBuff.append(notTcmBuff); + if (errorBuff.empty()) { + errorBuff = "succ"; + } + printf("errorBuff==>%s\n", errorBuff.c_str()); + ITKCALL(BOM_close_window(ebom_window)); + *((char**)returnValue) = (char*)MEM_alloc((strlen(errorBuff.c_str()) + 1) * sizeof(char)); + tc_strcpy(*((char**)returnValue), errorBuff.c_str()); + return ifail; +} \ No newline at end of file diff --git a/General/General/DtoEBOM2.cpp b/General/General/DtoEBOM2.cpp index e5f45f5..00449ab 100644 --- a/General/General/DtoEBOM2.cpp +++ b/General/General/DtoEBOM2.cpp @@ -58,7 +58,7 @@ bool isTcm(tag_t mantr) { int releaseCount = 0; tag_t* releaseTags = NULL; //判断子件是否发布 - AOM_ask_value_tags(mantr, "release_status_list", &releaseCount, &releaseTags); + ITKCALL(AOM_ask_value_tags(mantr, "release_status_list", &releaseCount, &releaseTags)); if (releaseCount > 0) { return true; } @@ -71,7 +71,7 @@ bool isBomViewTcm(tag_t mantr) { int structs = 0; tag_t *structure_revisions; //版本有BOM视图且发布 - AOM_ask_value_tags(mantr, "structure_revisions", &structs, &structure_revisions); + ITKCALL(AOM_ask_value_tags(mantr, "structure_revisions", &structs, &structure_revisions)); if (structs > 0) { return isTcm(structure_revisions[0]); } @@ -322,13 +322,13 @@ void askLineVal(NodeBean& bean, tag_t bom_line, tag_t designRev, string& errBuff if (part != NULLTAG) { //BOM_writer char* name, *partId, **sealeds, **factorys, *matnr, **procureType; - AOM_refresh(part, false); - AOM_ask_value_string(part, "object_name", &name); + ITKCALL(AOM_refresh(part, false)); + ITKCALL(AOM_ask_value_string(part, "object_name", &name)); printf("name%s\n", name); int cnt2, numFac, cnt3; //检查物料是否可用 ITKCALL(AOM_ask_value_string(part, "item_id", &partId)); - AOM_ask_value_string(part, "zt2_MaterialNo", &matnr); + ITKCALL(AOM_ask_value_string(part, "zt2_MaterialNo", &matnr)); if (strcmp(matnr, "") == 0) { string buffErr = ""; buffErr.append("物料:").append(partId).append("/").append(name).append("没有物料编码.\n"); @@ -340,9 +340,9 @@ void askLineVal(NodeBean& bean, tag_t bom_line, tag_t designRev, string& errBuff //return; } boolean numFlag = true; - AOM_ask_value_strings(part, "zt2_SZSealedornot", &cnt2, &sealeds); - AOM_ask_value_strings(part, "zt2_SZFactory", &numFac, &factorys); - AOM_ask_value_strings(part, "zt2_SZProcuretype", &cnt3, &procureType); //包含自制 + ITKCALL(AOM_ask_value_strings(part, "zt2_SZSealedornot", &cnt2, &sealeds)); + ITKCALL(AOM_ask_value_strings(part, "zt2_SZFactory", &numFac, &factorys)); + ITKCALL(AOM_ask_value_strings(part, "zt2_SZProcuretype", &cnt3, &procureType)); //包含自制 for (int i = 0; i < numFac; i++) { if (strcmp(factorys[i], "M060") == 0) { numFlag = false; @@ -495,7 +495,7 @@ void recyReadBom(tag_t bom_line, NodeBean& pBean, string& errBuff, string dbName ITKCALL(AOM_ask_value_string(designRev, "object_name", &object_name)); //printf("type===>%s\n", type); if (strcmp(type, "ZT2_Design3DRevision") == 0) { - AOM_ask_value_string(designRev, "zt2_Diagram", &zt2_Diagram); + ITKCALL(AOM_ask_value_string(designRev, "zt2_Diagram", &zt2_Diagram)); if (strcmp(zt2_Diagram, "Y") == 0 || strcmp(zt2_Diagram, "是") == 0) { return; } @@ -517,8 +517,8 @@ void recyReadBom(tag_t bom_line, NodeBean& pBean, string& errBuff, string dbName askLineVal(pBean, bom_line, designRev, errBuff, flagMat); tag_t tagUser; char *tagId; - AOM_ask_value_tag(designRev, "owning_user", &tagUser); - AOM_ask_value_string(tagUser, "user_id", &tagId); + ITKCALL(AOM_ask_value_tag(designRev, "owning_user", &tagUser)); + ITKCALL(AOM_ask_value_string(tagUser, "user_id", &tagId)); //检查权限 if (strcmp(type, "ZT2_Design3DRevision") == 0 && strcmp(loginUserId, tagId) != 0 && strstr(itemId, "2ZD") == NULL) { pBean.isOutBuy = true; @@ -535,7 +535,7 @@ void recyReadBom(tag_t bom_line, NodeBean& pBean, string& errBuff, string dbName } } if (strstr(itemId, "1ZD") != NULL) { - AOM_ask_value_string(designRev, "zt2_Source", &source); + ITKCALL(AOM_ask_value_string(designRev, "zt2_Source", &source)); if (strcmp(source, "S2") == 0 || strcmp(source, "外购") == 0) { pBean.isOutBuy = true; return; @@ -557,7 +557,7 @@ void recyReadBom(tag_t bom_line, NodeBean& pBean, string& errBuff, string dbName strstr(itemId, "2ZD") != NULL || strstr(itemId, "4ZD") != NULL)) { //原材料展开 char *zt2_MaterialMark; - AOM_ask_value_string(designRev, "zt2_MaterialMark", &zt2_MaterialMark); + ITKCALL(AOM_ask_value_string(designRev, "zt2_MaterialMark", &zt2_MaterialMark)); //String zt2_MaterialMark = rev.getProperty("zt2_MaterialMark") string sql = "select materialno, materialutilization, materialunit FROM %s where materialmark = '%s'"; char selectRxfs[500]; @@ -581,8 +581,8 @@ void recyReadBom(tag_t bom_line, NodeBean& pBean, string& errBuff, string dbName string materialutilization = outputValue1[t][1]; string materialunit = outputValue1[t][2]; tag_t material, materialRev; - ITEM_find_item(materialno.c_str(), &material); - ITEM_ask_latest_rev(material, &materialRev); + ITKCALL(ITEM_find_item(materialno.c_str(), &material)); + ITKCALL(ITEM_ask_latest_rev(material, &materialRev)); string bl_qty = getTyjZl(bom_line, materialutilization, designRev, errBuff); printf("bl_qty%s\n", bl_qty.c_str()); NodeBean cBean; @@ -602,20 +602,20 @@ void recyReadBom(tag_t bom_line, NodeBean& pBean, string& errBuff, string dbName bool ret = regex_match(item_id, result, qq_reg2); for (int i = 0; i < c_line_count; i++) { logical suppressed; - AOM_ask_value_logical(c_line_tags[i], "bl_is_occ_suppressed", &suppressed); + ITKCALL(AOM_ask_value_logical(c_line_tags[i], "bl_is_occ_suppressed", &suppressed)); if (suppressed) { continue; } //修改过之后之前已经是解包的状态了 logical flag; - BOM_line_is_packed(c_line_tags[i], &flag); + ITKCALL(BOM_line_is_packed(c_line_tags[i], &flag)); //printf("flag===>%d\n", flag); if (flag) { int count = 0; char *topNum; - AOM_ask_value_string(c_line_tags[i], "bl_quantity", &topNum); + ITKCALL(AOM_ask_value_string(c_line_tags[i], "bl_quantity", &topNum)); tag_t* packLines; - BOM_line_ask_packed_lines(c_line_tags[i], &count, &packLines); + ITKCALL(BOM_line_ask_packed_lines(c_line_tags[i], &count, &packLines)); for (int t = 0; t < count; t++) { tag_t c_Rev; ITKCALL(AOM_ask_value_tag(packLines[t], "bl_line_object", &c_Rev)); @@ -1239,9 +1239,11 @@ string createEbom(NodeBean topBean, boolean isTop, string &hasChange, map 0) { string num = cBean.bl_quantity; num = to_string(cBean.topNum / cBean.packNum); @@ -1312,10 +1314,10 @@ string createEbom(NodeBean topBean, boolean isTop, string &hasChange, map%s\n", buff.c_str()); + *((char**)returnValue) = (char*)MEM_alloc((strlen(buff.c_str()) + 1) * sizeof(char)); + tc_strcpy(*((char**)returnValue), buff.c_str()); + return ifail; + } + } TCMAndOwner(mantr); //return; } diff --git a/General/General/EbomToPMethod.cpp b/General/General/EbomToPMethod.cpp index 0823f4b..0d7b729 100644 --- a/General/General/EbomToPMethod.cpp +++ b/General/General/EbomToPMethod.cpp @@ -264,14 +264,14 @@ tag_t send1(tag_t rev, string now, //for (it = general_maps.begin(); it != general_maps.end(); it++) { char* item_id, *object_name, *zt2_DrawingNo1, *zt2_MaterialMark, *zt2_ProductModel , *object_desc, *zt2_SurfaceTreatment, *zt2_Source; - AOM_ask_value_string(rev, "item_id", &item_id); //groupId - AOM_ask_value_string(rev, "object_name", &object_name); - AOM_ask_value_string(rev, "zt2_DrawingNo", &zt2_DrawingNo1); - AOM_ask_value_string(rev, "zt2_MaterialMark", &zt2_MaterialMark); - AOM_ask_value_string(rev, "zt2_ProductModel", &zt2_ProductModel); - AOM_ask_value_string(rev, "object_desc", &object_desc); - AOM_ask_value_string(rev, "zt2_SurfaceTreatment", &zt2_SurfaceTreatment); - AOM_UIF_ask_value(rev, "zt2_Source", &zt2_Source); + ITKCALL(AOM_ask_value_string(rev, "item_id", &item_id)); //groupId + ITKCALL(AOM_ask_value_string(rev, "object_name", &object_name)); + ITKCALL(AOM_ask_value_string(rev, "zt2_DrawingNo", &zt2_DrawingNo1)); + ITKCALL(AOM_ask_value_string(rev, "zt2_MaterialMark", &zt2_MaterialMark)); + ITKCALL(AOM_ask_value_string(rev, "zt2_ProductModel", &zt2_ProductModel)); + ITKCALL(AOM_ask_value_string(rev, "object_desc", &object_desc)); + ITKCALL(AOM_ask_value_string(rev, "zt2_SurfaceTreatment", &zt2_SurfaceTreatment)); + ITKCALL(AOM_UIF_ask_value(rev, "zt2_Source", &zt2_Source)); PMPC m_pmpc; vector m_prds; //if (strcmp(item_id, "1ZDB") == 0) { @@ -282,7 +282,7 @@ tag_t send1(tag_t rev, string now, string pmpcCode = m_pmpc.m_code; string prhCode = m_pmpc.pmpcPrhCode; string pmpcType = m_pmpc.pmpcMType; - printf("pmpcType===>%s\n", pmpcType.c_str()); + WriteTcLog("pmpcType===>%s\n", pmpcType.c_str()); if (pmpcType.length() == 0) { return NULLTAG; } @@ -315,7 +315,7 @@ tag_t send1(tag_t rev, string now, char* qry_entries[1] = { "描述" }, *qry_values[1] = { (char *)queryMsg.c_str() }; int n_found; ITKCALL(QRY_execute(query, 1, qry_entries, qry_values, &n_found, &tags)); - printf("n_found===>%d %s \n", n_found, queryMsg.c_str()); + WriteTcLog("n_found===>%d %s \n", n_found, queryMsg.c_str()); if (n_found > 0) { return tags[0]; } @@ -350,7 +350,7 @@ tag_t send1(tag_t rev, string now, if (count2 > 0) { projn = outputValue2[0][0]; } - printf("projn===>%s\n", projn); + WriteTcLog("projn===>%s\n", projn); json.append("\"Code\":\"").append(projn).append("\","); //string spec = specs[i]; // 非必填 string feature = "\"Feature\":{"; @@ -394,11 +394,11 @@ tag_t send1(tag_t rev, string now, data.append("\"Data\":[{"); data.append("\"PrhCode").append("\":\"").append(prhCode).append("\","); data.append("\"PmpcCode").append("\":\"").append(pmpcCode).append("\","); - data.append("\"PmpcType").append("\":\"").append(pmpcType).append("\","); + data.append("\"PmpcType").append("\":\"").append("ZPFG").append("\",");//pmpcType data.append("\"UnitCode").append("\":\"").append(unitCode).append("\","); data.append("\"CompanyCode").append("\":\"").append(companyCode).append("\","); data.append("\"UserCode").append("\":\"").append(user).append("\","); - data.append("\"MP").append("\":\"").append(mp).append("\","); + data.append("\"MP").append("\":\"").append("M").append("\",");//mp data.append(feature); data.append("\"ProductGroupCode").append("\":\"").append("\","); data.append("\"AssistUnitCode").append("\":\"").append("\","); @@ -431,6 +431,7 @@ tag_t send1(tag_t rev, string now, char selectGyId[400]; sprintf(selectGyId, insertSql.c_str(), projn, newUid, pmpcCode.c_str(), "", goodsName.c_str(), "ST", companyCode.c_str(), bpNo.c_str(), spec.c_str(), "", "", user_id, now.c_str(), "审核中", ""); + WriteTcLog("selectGyId===>%s", selectGyId); ExecuteSQLNoInputParam(selectGyId); ExecuteSQLNoInputParam("commit"); return newRev; @@ -600,7 +601,7 @@ void replaceBom(EBomBean& childPm, map& map, int len, tag_t dcpro tag_t ebom_window = NULLTAG; tag_t bom_line = NULLTAG, *c_line_tags; tag_t* bvr_list = NULL; - (ITEM_rev_list_bom_view_revs(axqPmatnr, &bvr_count, &bvr_list)); + ITKCALL(ITEM_rev_list_bom_view_revs(axqPmatnr, &bvr_count, &bvr_list)); printf("bvr_count=%d\n", bvr_count); //没有物料视图的时候需要创建一个 if (bvr_count == 0) { @@ -612,24 +613,24 @@ void replaceBom(EBomBean& childPm, map& map, int len, tag_t dcpro AOM_save(newViewBvr); AOM_save(axqPmatnr); tag_t dsuser, *structure_revisions, *bom_view_tags; - AOM_ask_value_tag(tzRev, "owning_user", &dsuser); + ITKCALL(AOM_ask_value_tag(tzRev, "owning_user", &dsuser)); tag_t defGroup; ITKCALL(AOM_ask_value_tag(dsuser, "default_group", &defGroup)); ITKCALL(AOM_set_ownership(newView, dsuser, defGroup)); ITKCALL(AOM_set_ownership(newViewBvr, dsuser, defGroup)); //return; - (ITEM_rev_list_bom_view_revs(axqPmatnr, &bvr_count, &bvr_list)); + ITKCALL(ITEM_rev_list_bom_view_revs(axqPmatnr, &bvr_count, &bvr_list)); } - (BOM_create_window(&ebom_window)); - (BOM_set_window_top_line_bvr(ebom_window, bvr_list[0], &bom_line)); //顶层bom获取 + ITKCALL(BOM_create_window(&ebom_window)); + ITKCALL(BOM_set_window_top_line_bvr(ebom_window, bvr_list[0], &bom_line)); //顶层bom获取 //ITKCALL(AOM_ask_value_tag(bom_line, "bl_line_object", &mantr)); //线圈转PBOM时候的特殊处理:申请物料 A、B、C项线圈 然后把原来的线圈的子项拆分数量复制 ITKCALL(BOM_line_ask_all_child_lines(bom_line, &c_line_count, &c_line_tags)); - printf("int===>%d\n", len); + WriteTcLog("int===>%d\n", len); vector newPAmatnrs; for (int i = 0; i < len; i++) { //创建A项物料 - printf("names[i]===>%s\n", names[i]); + WriteTcLog("names[i]===>%s\n", names[i]); tag_t newPAmatnr = send1(tzRev, now1, user_id, jsons, grpId, specs[0], names[i], idss[i], dcproxy); newPAmatnrs.push_back(newPAmatnr); //如果名称中包含 线的 拆分后多余的放到最后 @@ -651,11 +652,12 @@ void replaceBom(EBomBean& childPm, map& map, int len, tag_t dcpro ITKCALL(BOM_save_window(ebom_window)); ITKCALL(BOM_close_window(ebom_window)); for (int i = 0; i < jsons.size(); i++) { - printf("jsons ===> %s \n", jsons[i].c_str()); + WriteTcLog("jsons ===> %s \n", jsons[i].c_str()); string url = "http://10.128.20.35:9002/Post/PLM_Goods"; string jsonUf = G2U222(jsons[i].c_str()); //调用接口申请物料 string msg = callHttpserver(jsonUf, url); + WriteTcLog("result===>%s\n", msg.c_str()); } } } @@ -1114,10 +1116,12 @@ tag_t saveAsUpdate(tag_t eRev, tag_t newChild) { void createAXxq(tag_t eRev, tag_t pRev, int len, tag_t dcproxy) { tag_t owning_group, owning_user; - char* grpId, *user_id; + char* grpId = NULL, *user_id = NULL, *os = NULL; int num = 0; tag_t* mantrs, designRev; string errBuff; + ITKCALL(AOM_ask_value_string(eRev, "object_string", &os)); + WriteTcLog("createAXxq:%s", os); ITKCALL(AOM_ask_value_tags(eRev, "TC_Is_Represented_By", &num, &mantrs)); if (num > 0) { tag_t tzRev = mantrs[0]; @@ -1127,7 +1131,7 @@ void createAXxq(tag_t eRev, tag_t pRev, int len, tag_t dcproxy) { ITKCALL(AOM_ask_value_string(owning_user, "user_id", &user_id)); vector specs; getSpecs(tzRev, specs); - printf("获取规格结束 \n"); + WriteTcLog("获取规格结束:%zd\n", specs.size()); time_t now; struct tm* p; time(&now); @@ -1144,8 +1148,8 @@ void createAXxq(tag_t eRev, tag_t pRev, int len, tag_t dcproxy) { tag_t ebom_window = NULLTAG; tag_t bom_line = NULLTAG, *c_line_tags; tag_t* bvr_list = NULL; - (ITEM_rev_list_bom_view_revs(axqPmatnr, &bvr_count, &bvr_list)); - printf("bvr_count=%d\n", bvr_count); + ITKCALL(ITEM_rev_list_bom_view_revs(axqPmatnr, &bvr_count, &bvr_list)); + WriteTcLog("bvr_count=%d\n", bvr_count); if (bvr_count == 0) { tag_t newView, newViewBvr, pitem; @@ -1157,22 +1161,22 @@ void createAXxq(tag_t eRev, tag_t pRev, int len, tag_t dcproxy) { AOM_save(axqPmatnr); //return; tag_t dsuser, *structure_revisions, *bom_view_tags; - AOM_ask_value_tag(tzRev, "owning_user", &dsuser); + ITKCALL(AOM_ask_value_tag(tzRev, "owning_user", &dsuser)); tag_t defGroup; ITKCALL(AOM_ask_value_tag(dsuser, "default_group", &defGroup)); ITKCALL(AOM_set_ownership(newView, dsuser, defGroup)); ITKCALL(AOM_set_ownership(newViewBvr, dsuser, defGroup)); - (ITEM_rev_list_bom_view_revs(axqPmatnr, &bvr_count, &bvr_list)); + ITKCALL(ITEM_rev_list_bom_view_revs(axqPmatnr, &bvr_count, &bvr_list)); } - (BOM_create_window(&ebom_window)); - (BOM_set_window_top_line_bvr(ebom_window, bvr_list[0], &bom_line)); //顶层bom获取 + ITKCALL(BOM_create_window(&ebom_window)); + ITKCALL(BOM_set_window_top_line_bvr(ebom_window, bvr_list[0], &bom_line)); //顶层bom获取 //ITKCALL(AOM_ask_value_tag(bom_line, "bl_line_object", &mantr)); ITKCALL(BOM_line_ask_all_child_lines(bom_line, &c_line_count, &c_line_tags)); - printf("int===>%d\n", len); + WriteTcLog("int===>%d\n", len); vector newPAmatnrs; for (int i = 0; i < len; i++) { //创建A项物料 idss[i] - printf("names[i]===>%s\n", names[i]); + WriteTcLog("names[i]===>%s\n", names[i]); tag_t newPAmatnr = send1(tzRev, now1, user_id, jsons, grpId, specs[0], names[i], idss[i], dcproxy); newPAmatnrs.push_back(newPAmatnr); boolean lastFlag = false; @@ -1193,10 +1197,11 @@ void createAXxq(tag_t eRev, tag_t pRev, int len, tag_t dcproxy) { ITKCALL(BOM_save_window(ebom_window)); ITKCALL(BOM_close_window(ebom_window)); for (int i = 0; i < jsons.size(); i++) { - printf("jsons ===> %s \n", jsons[i].c_str()); + WriteTcLog("jsons ===> %s \n", jsons[i].c_str()); string url = "http://10.128.20.35:9002/Post/PLM_Goods"; string jsonUf = G2U222(jsons[i].c_str()); string msg = callHttpserver(jsonUf, url); + WriteTcLog("result===>%s\n", msg.c_str()); } } } @@ -1438,8 +1443,8 @@ tag_t saveAsMaterial(EBomUpBean topBean, boolean isTop, printf("dddd=====\n"); return pMaterial; } - printf("dBomMesg[%d]", dBomMesg.size()); - printf("eBomMesg[%d]\n", eBomMesg.size()); + printf("eBomMesg[%d]", dBomMesg.size()); + printf("pBomMesg[%d]\n", eBomMesg.size()); boolean needAs = false; if (dBomMesg.size() != eBomMesg.size()) { //升版 + 发布 @@ -1664,17 +1669,23 @@ void copyBomLine(tag_t matnrTop, tag_t otherPbom) { ITKCALL(BOM_create_window(&ebom_window2)); ITKCALL(BOM_set_window_top_line_bvr(ebom_window2, bvr_list2[0], &bom_line2)); //顶层bom获取 ITKCALL(BOM_line_ask_all_child_lines(bom_line2, &c_line_count2, &c_line_tags2)); + POM_AM__set_application_bypass(true); for (int i = 0; i < c_line_count2; i++) { - BOM_line_cut(c_line_tags2[i]); + ITKCALL(BOM_line_cut(c_line_tags2[i])); } for (int i = 0; i < c_line_count; i++) { - tag_t newChild; - char *bl_seqNo; + tag_t newChild = NULLTAG; + char *bl_seqNo = NULL; ITKCALL(BOM_line_copy(bom_line2, c_line_tags[i], NULLTAG, &newChild)); + + char* pos = NULL; + ITKCALL(AOM_ask_value_string(c_line_tags[i], "object_string", &pos)); + printf("copyBomLine:%s\n", pos); + ITKCALL(AOM_ask_value_string(c_line_tags[i], "bl_sequence_no", &bl_seqNo)); - ITKCALL(AOM_lock(newChild)); + AOM_lock(newChild); ITKCALL(AOM_set_value_string(newChild, "bl_sequence_no", bl_seqNo)); - ITKCALL(AOM_save(newChild)); + AOM_save(newChild); //最后unlock AOM_unlock(newChild); } @@ -1693,7 +1704,11 @@ int EbomToPMethod(void* returnValue) { tag_t matnrRev1; ITKCALL(ifail = USERARG_get_string_argument(&revUid)); ITK__convert_uid_to_tag(revUid, &matnrRev1); - + + string log_path = "D:\\Siemens\\logs\\material\\"; + log_path.append(getNow("yyyyMMdd")).append(".log"); + CreateTcLogFile(log_path.c_str()); + WriteTcLog("******************* EbomToPMethod start %s *******************", getNow("LOG").c_str()); //链接mdm数据库获取物料申请需要的信息 if (open("PLMUser", "PLMUser", "BDP2020", "10.128.20.35")) { printf("链接SQLSERVER失败\n"); @@ -1988,6 +2003,8 @@ int EbomToPMethod(void* returnValue) { //ITKCALL(BOM_save_window(ebom_window2)); ////ITKCALL(AOM_unlock(ebom_window2)); //ITKCALL(BOM_close_window(ebom_window2)); + char* oldUid = NULL; + ITK__convert_tag_to_uid(pBomTop, &oldUid); ITKCALL(BOM_close_window(ebom_window)); printf("keyNum===>%s\n", keyNum.c_str()); @@ -2004,8 +2021,10 @@ int EbomToPMethod(void* returnValue) { int structs = 0, statusNum = 0; tag_t* structure_revisions, *release_status_list; ITKCALL(AOM_ask_value_tags(newRev, "structure_revisions", &structs, &structure_revisions)); - if (structs > 0 && hasChange.compare("true") != 0) { + printf("structs%d hasChange=>%s\n", structs, hasChange.c_str()); + if (structs > 0 && hasChange.compare("true") == 0) {// && hasChange.compare("true") != 0 ITKCALL(AOM_ask_value_tags(structure_revisions[0], "release_status_list", &statusNum, &release_status_list)); + printf("statusNum===>%d\n", statusNum); if (statusNum > 0) { int revNum = 0; tag_t *mantrsAs, dsuser; @@ -2023,7 +2042,18 @@ int EbomToPMethod(void* returnValue) { } } } - copyBomLine(pBomTop, newRev); + tag_t newP = NULLTAG; + if (saveAsMap[oldUid] == NULL) { + newP = pBomTop; + } + else { + newP = saveAsMap[oldUid]; + } + char* pos = NULL, *nos = NULL; + ITKCALL(AOM_ask_value_string(newP, "object_string", &pos)); + ITKCALL(AOM_ask_value_string(newRev, "object_string", &nos)); + printf("copyBomLine:%s ==> %s\n", pos, nos); + copyBomLine(newP, newRev); } } @@ -2034,6 +2064,7 @@ int EbomToPMethod(void* returnValue) { if (buff.empty()) { buff = "succ"; } + CloseTcLog(); *((char**)returnValue) = (char*)MEM_alloc((strlen(buff.c_str()) + 1) * sizeof(char)); tc_strcpy(*((char**)returnValue), buff.c_str()); return ifail; diff --git a/General/General/General.vcxproj b/General/General/General.vcxproj index 166effd..f0d97a9 100644 --- a/General/General/General.vcxproj +++ b/General/General/General.vcxproj @@ -181,8 +181,11 @@ + + + @@ -221,6 +224,7 @@ + diff --git a/General/General/General.vcxproj.filters b/General/General/General.vcxproj.filters index 8a24121..565b1fd 100644 --- a/General/General/General.vcxproj.filters +++ b/General/General/General.vcxproj.filters @@ -221,5 +221,17 @@ epm-handler + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + \ No newline at end of file diff --git a/General/General/chint_changenotice.cpp b/General/General/chint_changenotice.cpp new file mode 100644 index 0000000..65942eb --- /dev/null +++ b/General/General/chint_changenotice.cpp @@ -0,0 +1,328 @@ +#include "cJSON.h" + +#include +#include "epm_handler_common.h" +#include +#include +#include +#include +#include +#include +#include +#include "ps/ps.h"; +#include "ps/vrule.h" +#include "sstream" +#include +#include "epm/epm.h" +#include "sa/sa.h" +#include "libxl.h" +#include +#include "epm/signoff.h" +#include +#include +#include +#include +#include "ae/dataset.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "chint_Handler.h" +#include +#include +#include "ado.h" +#include "ocilib.h" +#include +#include "CRUL_server_call_httpserver.h" +#include "common_itk_util.h" +#define EPM_HANDLER_COMMON +#define MAX_PATH_LENGTH 200 +#define MAX_PRINTLINE_LENGTH 400000 + +char* utog(const char* src_str) +{ + int len = MultiByteToWideChar(CP_UTF8, 0, src_str, -1, NULL, 0); + wchar_t* wszGBK = (wchar_t*)MEM_alloc((len + 1) * sizeof(wchar_t)); + memset(wszGBK, 0, len * 2 + 2); + MultiByteToWideChar(CP_UTF8, 0, src_str, -1, wszGBK, len); + len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, NULL, 0, NULL, NULL); + char* szGBK = (char*)MEM_alloc((len + 1) * sizeof(char)); + + memset(szGBK, 0, len + 1); + WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, szGBK, len, NULL, NULL); + return szGBK; +} + +char* gtou(const char* src_str) +{ + int len = MultiByteToWideChar(CP_ACP, 0, src_str, -1, NULL, 0); + wchar_t* wstr = (wchar_t*)MEM_alloc((len + 1) * sizeof(wchar_t)); + memset(wstr, 0, len + 1); + MultiByteToWideChar(CP_ACP, 0, src_str, -1, wstr, len); + len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL); + char* str = (char*)MEM_alloc((len + 1) * sizeof(char)); + + memset(str, 0, len + 1); + WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL); + return str; +} + + +// 写入回调函数实现 +size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) { + size_t totalSize = size * nmemb; + char* buffer = (char*)userp; + + // 追加内容到缓冲区 + strncat(buffer, (char*)contents, totalSize); + + return totalSize; // 返回实际接收的字节数 +} + +void feishuSplit(string strArg, string spliter, vector& ans) +{ + ans.clear(); + size_t index0 = 0; + string one_arg; + if (strArg.find_first_not_of(' ') == string::npos) + strArg = ""; + while (strArg.size() > 0) + { + index0 = strArg.find_first_of(spliter); + if (index0 != string::npos) + { + one_arg = strArg.substr(0, index0); + strArg = strArg.substr(index0 + 1); + ans.push_back(one_arg); + } + else + { + ans.push_back(strArg); + break; + } + } +} + + +void WriteLog4(logical debug, const char* format, ...) +{ + va_list arg; + char tmp[MAX_PRINTLINE_LENGTH]; + char date_string[MAX_PATH_LENGTH]; + time_t now; + struct tm* p; + + //get the message + memset(tmp, 0, sizeof(tmp)); + va_start(arg, format); + vsprintf(tmp, format, arg); + va_end(arg); + //----------print to command window for trace--------// + //printf("%s\n", tmp); + printf("%s\n", tmp); + //print message to log file + TC_write_syslog("%s\n", tmp); +} +int chint_changenotice(EPM_action_message_t msg) { + + tag_t task_tag = NULL_TAG, + root_task_tag = NULLTAG, + * attachments;; + task_tag = msg.task; + int att_cnt = 0, ifail = 0; + int c_sql_value_count = 0; + char** c_sql_values = NULL; + ITKCALL(PREF_ask_char_values("CHINT_ChangeNotice", &c_sql_value_count, &c_sql_values)); + + WriteLog4(true, "------------------------------------------------------------------------------------"); + WriteLog4(true, "========================="); + WriteLog4(true, "chint_changenotice start"); + WriteLog4(true, "========================="); + + EPM_ask_root_task(task_tag, &root_task_tag); + EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnt, &attachments); + WriteLog4(true, "流程目标下的对象数量:%d", att_cnt); + + //分割首选项 + std::map prefMap;//统计集合 + for (int j = 0; j < c_sql_value_count; j++) { + + /*值:第一行为通知信息。 + 其余行为通知的人员,“组真实值”:“邮箱域名前缀”,多个用户之间用“; ”隔开。 + 例:用户“邵俊齐”所在的组真实值为M060,邮箱为shaojq@chint.com, + 则值为M060 : shaojq*/ + if (j != 0) { + vector ans; + feishuSplit(c_sql_values[j], ":", ans); + prefMap[ans[0]] = ans[1]; + } + + } + WriteLog4(true, "首选项条数:%d", prefMap.size()); + for (int i = 0; i < att_cnt; i++) + { + tag_t tagt = NULLTAG; + tagt = attachments[i]; + char* type; + //获取版本下的数据集 + int dataset_num = 0; + tag_t* dataset_tags = NULL; + char* tempValue = NULL; + char taskpuid[56] = "\0"; + ITK__convert_tag_to_uid(task_tag, &tempValue); + tc_strcpy(taskpuid, tempValue); + ITKCALL(AOM_ask_value_string(tagt, "object_type", &type)); + printf("object_type=%s\n", type); + //获取当前登入人组 + //char* groupName = NULL; + //tag_t t_group = NULLTAG; + //ITKCALL(POM_ask_group(&groupName, &t_group)); + //printf("g=%s\n", groupName); + //获取当前登入人的名称和id + + tag_t group; + char* group_name; + AOM_ask_value_tag(tagt, "owning_group", &group); + AOM_ask_value_string(group, "name", &group_name); + + + char* name; + char* id; + tag_t user; + POM_get_user(&name, &user); + POM_get_user_id(&id); + printf("name================%s\n", name); + printf("id================%s\n", id); + string users = ""; + //判断组是否在首选项中存在 + for (auto it = prefMap.begin(); it != prefMap.end(); it++) { + //当前组和首选项中组匹配 + if (strcmp(it->first.c_str(), group_name) == 0) { + users = it->second; + break; + } + } + + printf("users================%s\n", users); + if (strcmp(users.c_str(), "") != 0) { + //判断目标下是否存在 ZT2_Change + + if (strcmp("ZT2_Change", type) == 0) { + + + + + //拼接json + char* json = NULL; + string contentStr; + cJSON* top = cJSON_CreateObject(); + cJSON* emails = cJSON_CreateArray(); + cJSON* mobiles = cJSON_CreateArray(); + + + + //拼接emails + vector usersVector; + + + + + + feishuSplit(users, ";", usersVector); + for (int h = 0; h < usersVector.size(); h++) { + cJSON* new_string = cJSON_CreateString(usersVector[h].c_str()); + cJSON_AddItemToArray(emails, new_string); + } + + //拼接content + tag_t user; + char* duser,* itemId; + AOM_ask_value_string(tagt, "item_id", &itemId); + AOM_ask_value_tag(tagt, "owning_user", &user); + AOM_ask_value_string(user, "user_name", &duser); + contentStr.append(duser).append(" 发起的").append(itemId).append(c_sql_values[0]); + cJSON_AddStringToObject(top, "content", contentStr.c_str()); + + //sms + cJSON_AddStringToObject(top, "sms", "false"); + + + + cJSON_AddItemToObject(top, "emails", emails); + cJSON_AddItemToObject(top, "mobiles", mobiles); + + json = cJSON_Print(top); + + printf("json================%s\n", json); + + + + + + //调用接口 + CURL* curl; + CURLcode res; + char readBuffer[10000]; + memset(readBuffer, 0, 10000); + curl = curl_easy_init(); + if (curl) { + curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST"); + curl_easy_setopt(curl, CURLOPT_URL, "http://10.128.10.170/api/feishu/Message/sendMessages"); + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); + curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https"); + struct curl_slist* headers = NULL; + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); + // 设置写入数据的目标缓冲区 + + curl_easy_setopt(curl, CURLOPT_WRITEDATA, readBuffer); + headers = curl_slist_append(headers, "Content-Type: application/json"); + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); + //const char* data = "{\"emails\":[\"shaojq@chint.com\",\"zouy5@chint.com\"],\"mobiles\":[],\"sms\":false,\"content\":\"项目编号:P2303344售前资料已经获取完毕,请 登陆PLM系统查看。\"}"; + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, gtou(json)); + res = curl_easy_perform(curl); + } + curl_easy_cleanup(curl); + + + char* gbk_readBuffer = utog(readBuffer); + printf("json================%s\n", gbk_readBuffer); + cJSON* result_json = cJSON_Parse(gbk_readBuffer); + cJSON* code = cJSON_GetObjectItem(result_json, "code"); + + int code_int = code->valueint; + + if (code_int != 0) { + printf("发送飞书失败\n"); + } + + } + + + + } + + + + + + + + + + + + } + + + DOFREE(attachments); + WriteLog4(true, "========================="); + WriteLog4(true, "chint_changenotice end"); + WriteLog4(true, "========================="); + return ifail; +} \ No newline at end of file diff --git a/General/General/chint_check_materialstatus.cpp b/General/General/chint_check_materialstatus.cpp new file mode 100644 index 0000000..f97a6a9 --- /dev/null +++ b/General/General/chint_check_materialstatus.cpp @@ -0,0 +1,299 @@ +#include "cJSON.h" + +#include +#include "epm_handler_common.h" +#include +#include +#include +#include +#include +#include +#include +#include "ps/ps.h"; +#include "ps/vrule.h" +#include "sstream" +#include +#include "epm/epm.h" +#include "sa/sa.h" +#include "libxl.h" +#include +#include "epm/signoff.h" +#include +#include +#include +#include +#include "ae/dataset.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "chint_Handler.h" +#include +#include +#include "ado.h" +#include "ocilib.h" +#include +#include "CRUL_server_call_httpserver.h" +#include "common_itk_util.h" +#define EPM_HANDLER_COMMON +#define MAX_PATH_LENGTH 200 +#define MAX_PRINTLINE_LENGTH 400000 +using namespace std; + + + + +void WriteLog5(logical debug, const char* format, ...) +{ + va_list arg; + char tmp[MAX_PRINTLINE_LENGTH]; + char date_string[MAX_PATH_LENGTH]; + time_t now; + struct tm* p; + + //get the message + memset(tmp, 0, sizeof(tmp)); + va_start(arg, format); + vsprintf(tmp, format, arg); + va_end(arg); + //----------print to command window for trace--------// + //printf("%s\n", tmp); + printf("%s\n", tmp); + //print message to log file + TC_write_syslog("%s\n", tmp); +} +int chint_check_materialstatus(EPM_action_message_t msg) { + + tag_t task_tag = NULL_TAG, + root_task_tag = NULLTAG, + * attachments;; + task_tag = msg.task; + int att_cnt = 0, ifail = 0; + + int count = 1; + + WriteLog5(true, "------------------------------------------------------------------------------------"); + WriteLog5(true, "========================="); + WriteLog5(true, "chint_check_materialstatus start"); + WriteLog5(true, "========================="); + + EPM_ask_root_task(task_tag, &root_task_tag); + EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnt, &attachments); + WriteLog5(true, "流程目标下的对象数量:%d", att_cnt); + + //停用集合 + std::map tyMap; + //封存集合 + std::map fcMap; + for (int i = 0; i < att_cnt; i++) + { + tag_t target = NULLTAG; + target = attachments[i]; + char* objectType = NULL; + char* fcStr = NULL,* tyStr = NULL,* zt2_State = NULL; + //三种处理逻辑 物料 物料bom 图纸 + ITKCALL(AOM_ask_value_string(target, "object_type", &objectType)); + //物料 + printf("objectType======%s\n", objectType); + if (strcmp(objectType,"Part Revision") == 0) { + //获取物料编码和物料名称 + char* zt2_MaterialNo = NULL; + char* object_name = NULL; + ITKCALL(AOM_ask_value_string(target, "object_name", &object_name)); + ITKCALL(AOM_ask_value_string(target, "zt2_MaterialNo", &zt2_MaterialNo)); + ITKCALL(AOM_ask_value_string(target, "object_desc", &tyStr)); + ITKCALL(AOM_UIF_ask_value(target, "zt2_State", &zt2_State)); + printf("tyStr======%s\n", tyStr); + if (strstr(tyStr,"停用")) { + //放入停用map + tyMap[zt2_MaterialNo] = object_name; + continue; + } + else if (strstr(zt2_State, "封存")) { + //放入封存map + fcMap[zt2_MaterialNo] = object_name; + continue; + } + + } + + //物料bom :获取第一层 + if (strcmp(objectType, "BOMView Revision") == 0) { + //获取第一层 + ////遍历子BOM获取属性 + //tag_t window_0_; + //tag_t top_bom_line; + //tag_t* childs; + //int childNum; + //char* json = NULL; + ////遍历BOM结构 + //ITKCALL(BOM_create_window(&window_0_)); + + //tag_t topRev = NULLTAG; + ////bomline + //int top_bl_line_object; + //ITKCALL(BOM_line_look_up_attribute("bl_line_object", &top_bl_line_object)); + //ITKCALL(BOM_line_ask_attribute_tag(target, top_bl_line_object, &topRev)); + + //ITKCALL(BOM_set_window_top_line(window_0_, NULLTAG, topRev, NULLTAG, &top_bom_line)); + //获取子 + + tag_t bom_window_tag = NULLTAG, + top_line_tag = NULLTAG; + ITKCALL(BOM_create_window(&bom_window_tag));//创建window视图 + ITKCALL(BOM_set_window_top_line_bvr(bom_window_tag, target, &top_line_tag));//获取顶层bomline + + + tag_t* childs; + int childNum; + ITKCALL(BOM_line_ask_child_lines(top_line_tag, &childNum, &childs)); + + printf("childNum======%d\n", childNum); + for (int i = 0; i < childNum; i++) { + tag_t rev = NULLTAG; + //bomline + int bl_line_object; + ITKCALL(BOM_line_look_up_attribute("bl_line_object", &bl_line_object)); + ITKCALL(BOM_line_ask_attribute_tag(childs[i], bl_line_object, &rev)); + char* objectType_rev = NULL; + //获取rev属性判断 + ITKCALL(AOM_ask_value_string(rev, "object_type", &objectType_rev)); + //物料 + + if (strcmp(objectType_rev, "Part Revision") == 0) { + //获取物料编码和物料名称 + char* zt2_MaterialNo = NULL; + char* object_name = NULL; + ITKCALL(AOM_ask_value_string(rev, "object_name", &object_name)); + ITKCALL(AOM_ask_value_string(rev, "zt2_MaterialNo", &zt2_MaterialNo)); + ITKCALL(AOM_ask_value_string(rev, "object_desc", &tyStr)); + ITKCALL(AOM_UIF_ask_value(rev, "zt2_State", &zt2_State)); + if (strstr(tyStr, "停用")) { + //放入停用map + tyMap[zt2_MaterialNo] = object_name; + continue; + } + else if (strstr(zt2_State, "封存")) { + //放入封存map + fcMap[zt2_MaterialNo] = object_name; + continue; + } + + } + } + } + ////图纸 + //if (strcmp(objectType, "ZT2_Design3DRevision") == 0) { + // //获取关系文件夹下的物料 + // int gxNum; tag_t* gxTags; char* object_string = NULL; + // ITKCALL(AOM_ask_value_tags(target, "pseudo_folder", &gxNum, &gxTags)); + // for (int i = 0; i < gxNum; i++) { + // ITKCALL(AOM_ask_value_string(gxTags[i], "object_string", &object_string)); + // if (strcmp(object_string,"物料")) { + // //获取物料文件夹下的对象 + // int wlNum; tag_t* wlTags; + // ITKCALL(AOM_ask_value_tags(target, "representation_for", &wlNum, &wlTags)); + // for (int j = 0; j < gxNum; j++) { + // //获取rev属性判断 + // char* objectType_rev = NULL; + // ITKCALL(AOM_ask_value_string(wlTags[j], "object_type", &objectType_rev)); + // //物料 + + // if (strcmp(objectType_rev, "Part Revision") == 0) { + // //获取物料编码和物料名称 + // char* zt2_MaterialNo = NULL; + // char* object_name = NULL; + // ITKCALL(AOM_ask_value_string(wlTags[j], "object_name", &object_name)); + // ITKCALL(AOM_ask_value_string(wlTags[j], "zt2_MaterialNo", &zt2_MaterialNo)); + // ITKCALL(AOM_ask_value_string(wlTags[j], "object_desc", &tyStr)); + // ITKCALL(AOM_UIF_ask_value(wlTags[j], "zt2_State", &zt2_State)); + // if (strstr(tyStr, "停用")) { + // //放入停用map + // tyMap[zt2_MaterialNo] = object_name; + // continue; + // } + // else if (strstr(zt2_State, "封存")) { + // //放入封存map + // fcMap[zt2_MaterialNo] = object_name; + // continue; + // } + + // } + // } + // } + // } + //} + + + //图纸 + if (strcmp(objectType, "ZT2_Design3DRevision") == 0) { + //获取关系文件夹下的物料 + + int wlNum; tag_t* wlTags; + ITKCALL(AOM_ask_value_tags(target, "representation_for", &wlNum, &wlTags)); + printf("wlNum======%d\n", wlNum); + for (int j = 0; j < wlNum; j++) { + //获取rev属性判断 + char* objectType_rev = NULL; + ITKCALL(AOM_ask_value_string(wlTags[j], "object_type", &objectType_rev)); + //物料 + printf("objectType_rev======%s\n", objectType_rev); + if (strcmp(objectType_rev, "Part Revision") == 0) { + //获取物料编码和物料名称 + char* zt2_MaterialNo = NULL; + char* object_name = NULL; + ITKCALL(AOM_ask_value_string(wlTags[j], "object_name", &object_name)); + ITKCALL(AOM_ask_value_string(wlTags[j], "zt2_MaterialNo", &zt2_MaterialNo)); + ITKCALL(AOM_ask_value_string(wlTags[j], "object_desc", &tyStr)); + ITKCALL(AOM_UIF_ask_value(wlTags[j], "zt2_State", &zt2_State)); + printf("zt2_State======%s\n", zt2_State); + if (strstr(tyStr, "停用")) { + //放入停用map + tyMap[zt2_MaterialNo] = object_name; + printf("00000000000000000000000000\n"); + continue; + } + else if (strstr(zt2_State, "封存")) { + //放入封存map + fcMap[zt2_MaterialNo] = object_name; + printf("11111111111111111111111111\n"); + continue; + } + } + } + } + + } + //收集完map数据,进行拼接报错 + string errMsg = ""; + for (auto it = tyMap.begin(); it != tyMap.end(); it++) { + errMsg.append(std::to_string(count++)).append(".").append(it->first).append("-").append(it->second).append(":物料已停用\n"); + } + + for (auto it = fcMap.begin(); it != fcMap.end(); it++) { + errMsg.append(std::to_string(count++)).append(".").append(it->first).append("-").append(it->second).append(":物料已封存\n"); + } + + if (fcMap.size() > 0) { + EMH_store_error_s1(EMH_severity_error, EMH_USER_error_base, errMsg.c_str()); //错误弹窗 + return -1; + } + + + if (tyMap.size() > 0) { + EMH_store_error_s1(EMH_severity_warning, EMH_USER_error_base, errMsg.c_str()); //错误弹窗 + } + + + DOFREE(attachments); + WriteLog5(true, "========================="); + WriteLog5(true, "chint_check_materialstatus end"); + WriteLog5(true, "========================="); + return ifail; +} \ No newline at end of file diff --git a/General/General/connor_sign_pdf.cpp b/General/General/connor_sign_pdf.cpp index 834c564..d1d6fc3 100644 --- a/General/General/connor_sign_pdf.cpp +++ b/General/General/connor_sign_pdf.cpp @@ -45,238 +45,238 @@ using namespace std; //电子签名 int chint_pdf_signoff(EPM_action_message_t msg) { int ifail = ITK_ok; - + /**/ //流程节点相关 - tag_t root_task = NULLTAG, *sub_tasks = NULL, current_task = NULLTAG, type_tag = NULLTAG; - int sub_task_count = 0; - char root_task_name[128] = "", task_name[128] = ""; - int occur_of_counts = 0; - tag_t* taskAttches = NULLTAG; - char tgt_type[WSO_name_size_c + 1] = "", *type_class; - ////循环内部变量 - tag_t cur_task = NULLTAG; - //循环变量 - int count = 0; + //tag_t root_task = NULLTAG, *sub_tasks = NULL, current_task = NULLTAG, type_tag = NULLTAG; + //int sub_task_count = 0; + //char root_task_name[128] = "", task_name[128] = ""; + //int occur_of_counts = 0; + //tag_t* taskAttches = NULLTAG; + //char tgt_type[WSO_name_size_c + 1] = "", *type_class; + //////循环内部变量 + //tag_t cur_task = NULLTAG; + ////循环变量 + //int count = 0; - //节点循环处理变量 - tag_t itemrevision = NULLTAG, master_form_rel_type = NULLTAG; - int form_count = 0; - tag_t* form_list = NULL, master_form = NULLTAG; + ////节点循环处理变量 + //tag_t itemrevision = NULLTAG, master_form_rel_type = NULLTAG; + //int form_count = 0; + //tag_t* form_list = NULL, master_form = NULLTAG; - current_task = msg.task; - //CreateLogFile("PLA8_signoff",&txtfile); - ECHO("=========================================================\n"); - ECHO("电子签名 开始执行\n"); - ECHO("=========================================================\n"); - //参数相关 + //current_task = msg.task; + ////CreateLogFile("PLA8_signoff",&txtfile); + //ECHO("=========================================================\n"); + //ECHO("电子签名 开始执行\n"); + //ECHO("=========================================================\n"); + ////参数相关 - POM_AM__set_application_bypass(true); + //POM_AM__set_application_bypass(true); - int url_num = 0; - char** url_vals = NULL; - PREF_ask_char_values("CHINT_SignPic", &url_num, &url_vals); - tag_t group; - char *groupId; - AOM_ask_value_tag(msg.task, "owning_group", &group); - AOM_ask_value_string(group,"name", &groupId); - printf("groupId==>%s\n", groupId); - map typeUidMap; - for (int i = 0; i < url_num;i++) { - vector vec2; - Split(url_vals[i], ";", vec2); - if (vec2.size() == 3 && vec2[0].compare(groupId)==0) { - tag_t tz_target; - ITK__convert_uid_to_tag(vec2[2].c_str(), &tz_target); - typeUidMap[vec2[1]] = tz_target; - } - } + //int url_num = 0; + //char** url_vals = NULL; + //PREF_ask_char_values("CHINT_SignPic", &url_num, &url_vals); + //tag_t group; + //char *groupId; + //AOM_ask_value_tag(msg.task, "owning_group", &group); + //AOM_ask_value_string(group,"name", &groupId); + //printf("groupId==>%s\n", groupId); + //map typeUidMap; + //for (int i = 0; i < url_num;i++) { + // vector vec2; + // Split(url_vals[i], ";", vec2); + // if (vec2.size() == 3 && vec2[0].compare(groupId)==0) { + // tag_t tz_target; + // ITK__convert_uid_to_tag(vec2[2].c_str(), &tz_target); + // typeUidMap[vec2[1]] = tz_target; + // } + //} - //获取属性 - EPM_ask_root_task(msg.task, &root_task); - EPM_ask_sub_tasks(root_task, &sub_task_count, &sub_tasks); - EPM_ask_attachments(root_task, EPM_target_attachment, &occur_of_counts, &taskAttches); - ECHO("%d target attachment found", occur_of_counts); + ////获取属性 + //EPM_ask_root_task(msg.task, &root_task); + //EPM_ask_sub_tasks(root_task, &sub_task_count, &sub_tasks); + //EPM_ask_attachments(root_task, EPM_target_attachment, &occur_of_counts, &taskAttches); + //ECHO("%d target attachment found", occur_of_counts); - for (count = 0; count < occur_of_counts; count++) - { - ITKCALL(TCTYPE_ask_object_type(taskAttches[count], &type_tag)); - ITKCALL(ifail = TCTYPE_ask_class_name2(type_tag, &type_class)); + //for (count = 0; count < occur_of_counts; count++) + //{ + // ITKCALL(TCTYPE_ask_object_type(taskAttches[count], &type_tag)); + // ITKCALL(ifail = TCTYPE_ask_class_name2(type_tag, &type_class)); - //过滤掉非版本对象 - if (typeUidMap.count(type_class)>0) - { - tag_t tz_target = typeUidMap[type_class]; - char tz_path[512] = ""; - int target_count = 0; - tag_t* target_tags = NULL; - char* target_type; - ITKCALL(AOM_ask_value_tags(tz_target, "ref_list", &target_count, &target_tags)); - ITKCALL(AOM_ask_value_string(target_tags[0], "file_ext", &target_type)); - time_t now; - struct tm* p; - time(&now); - p = localtime(&now); + // //过滤掉非版本对象 + // if (typeUidMap.count(type_class)>0) + // { + // tag_t tz_target = typeUidMap[type_class]; + // char tz_path[512] = ""; + // int target_count = 0; + // tag_t* target_tags = NULL; + // char* target_type; + // ITKCALL(AOM_ask_value_tags(tz_target, "ref_list", &target_count, &target_tags)); + // ITKCALL(AOM_ask_value_string(target_tags[0], "file_ext", &target_type)); + // time_t now; + // struct tm* p; + // time(&now); + // p = localtime(&now); - sprintf_s(tz_path, "%s\\TZ_[%d-%d-%d-%d-%02d-%02d].%s", getenv("TEMP"), 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, target_type); + // sprintf_s(tz_path, "%s\\TZ_[%d-%d-%d-%d-%02d-%02d].%s", getenv("TEMP"), 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, target_type); - IMF_export_file(target_tags[0], tz_path); + // IMF_export_file(target_tags[0], tz_path); - itemrevision = taskAttches[count]; - ITKCALL(GRM_find_relation_type(TC_master_form_rtype, &master_form_rel_type)); - ITKCALL(GRM_list_secondary_objects_only(itemrevision, master_form_rel_type, &form_count, &form_list)); - //获得数据集 - tag_t relation_type = NULLTAG; - //tag_t attach_relation_type = NULLTAG; - ITKCALL(GRM_find_relation_type(TC_specification_rtype, &relation_type)); - tag_t* secondary_objects = NULLTAG; - int ds_count = 0; - char* dataset_type = NULL, *desc_value = NULL, *file_path = NULL, *desc_path; + // itemrevision = taskAttches[count]; + // ITKCALL(GRM_find_relation_type(TC_master_form_rtype, &master_form_rel_type)); + // ITKCALL(GRM_list_secondary_objects_only(itemrevision, master_form_rel_type, &form_count, &form_list)); + // //获得数据集 + // tag_t relation_type = NULLTAG; + // //tag_t attach_relation_type = NULLTAG; + // ITKCALL(GRM_find_relation_type(TC_specification_rtype, &relation_type)); + // tag_t* secondary_objects = NULLTAG; + // int ds_count = 0; + // char* dataset_type = NULL, *desc_value = NULL, *file_path = NULL, *desc_path; - ITKCALL(GRM_list_secondary_objects_only(itemrevision, relation_type, &ds_count, &secondary_objects)); + // ITKCALL(GRM_list_secondary_objects_only(itemrevision, relation_type, &ds_count, &secondary_objects)); - for (int j = 0; j < ds_count; j++) - { - printf("进1\n"); - ITKCALL(AOM_ask_value_string(secondary_objects[j], "object_type", &dataset_type)); - int des_count = 0; - tag_t* dess = NULL; + // for (int j = 0; j < ds_count; j++) + // { + // printf("进1\n"); + // ITKCALL(AOM_ask_value_string(secondary_objects[j], "object_type", &dataset_type)); + // int des_count = 0; + // tag_t* dess = NULL; - printf("dataset_type=%s\n", dataset_type); - if (strcmp(dataset_type, "PDF") != 0) { - if (dataset_type != NULL) { - MEM_free(dataset_type); - dataset_type = NULL; - } + // printf("dataset_type=%s\n", dataset_type); + // if (strcmp(dataset_type, "PDF") != 0) { + // if (dataset_type != NULL) { + // MEM_free(dataset_type); + // dataset_type = NULL; + // } - continue; - } - ITKCALL(AOM_ask_value_tags(secondary_objects[j], "ref_list", &des_count, &dess)); - if (des_count < 1) { - printf("该数据集引用数量错误\n"); - continue; - } - else { - char* sizeFile; - AOM_ask_value_string(dess[0], "file_size", &sizeFile); - printf("sizeFile %s \n", sizeFile); - if (strcmp(sizeFile, "0 bytes") == 0) { - printf("文件大小是0bytes\n"); - continue; - } - } - tag_t spec_dataset_rev = NULLTAG, - ref_object = NULLTAG; - char* ref_object_name = NULL; - AE_reference_type_t reference_type; - char* datasetName = NULL; - char* pathname; - char* origin_file_name; - vector type_vec; - printf("开始判断类型\n"); - if (strcmp(dataset_type, "PDF") == 0) { - printf("pdf类型\n"); + // continue; + // } + // ITKCALL(AOM_ask_value_tags(secondary_objects[j], "ref_list", &des_count, &dess)); + // if (des_count < 1) { + // printf("该数据集引用数量错误\n"); + // continue; + // } + // else { + // char* sizeFile; + // AOM_ask_value_string(dess[0], "file_size", &sizeFile); + // printf("sizeFile %s \n", sizeFile); + // if (strcmp(sizeFile, "0 bytes") == 0) { + // printf("文件大小是0bytes\n"); + // continue; + // } + // } + // tag_t spec_dataset_rev = NULLTAG, + // ref_object = NULLTAG; + // char* ref_object_name = NULL; + // AE_reference_type_t reference_type; + // char* datasetName = NULL; + // char* pathname; + // char* origin_file_name; + // vector type_vec; + // printf("开始判断类型\n"); + // if (strcmp(dataset_type, "PDF") == 0) { + // printf("pdf类型\n"); - AOM_ask_value_string(secondary_objects[j], "object_name", &datasetName); - AE_ask_dataset_latest_rev(secondary_objects[j], &spec_dataset_rev); - AOM_ask_value_string(spec_dataset_rev, "object_name", &ref_object_name); - printf("ref_object_name=%s\n", ref_object_name); - char ref_name[WSO_name_size_c + 1] = "PDF_Reference"; + // AOM_ask_value_string(secondary_objects[j], "object_name", &datasetName); + // AE_ask_dataset_latest_rev(secondary_objects[j], &spec_dataset_rev); + // AOM_ask_value_string(spec_dataset_rev, "object_name", &ref_object_name); + // printf("ref_object_name=%s\n", ref_object_name); + // char ref_name[WSO_name_size_c + 1] = "PDF_Reference"; - AE_ask_dataset_named_ref2(spec_dataset_rev, ref_name, &reference_type, &ref_object); - if (ref_object == NULLTAG) - { - printf("\nref_object is NULLTAG\n"); - return ITK_ok; - } - printf("reference_type=%d\n", reference_type); - if (reference_type == AE_PART_OF) - { - ITKCALL(IMF_ask_file_pathname2(ref_object, SS_WNT_MACHINE, &pathname)); - IMF_ask_original_file_name2(ref_object, &origin_file_name); - char new_ds_name[WSO_name_size_c + 1] = ""; - char* new_file_name = USER_new_file_name(new_ds_name, ref_name, "pdf", 0); - char* temp_dir = getenv("temp"); - char temp_file[SS_MAXPATHLEN] = ""; - char temp_file2[SS_MAXPATHLEN] = ""; - strcpy(temp_file, temp_dir); - strcat(temp_file, "\\"); - strcat(temp_file, new_file_name); - IMF_export_file(ref_object, temp_file); - - if (strstr(new_file_name, ".pdf") != NULL) { - sprintf(temp_file2, "%s\\1%s", temp_dir, new_file_name); - } - else { - sprintf(temp_file2, "%s\\1%s.pdf", temp_dir, new_file_name); - } - //sprintf(temp_file2, "%s.pdf", temp_file); - printf("\ntemp_file=%s\n", temp_file); - char cmd[256] = ""; - char* tc_root_dir = getenv("tc_root"); - strcpy(cmd, "java -jar "); - strcat(cmd, tc_root_dir); - strcat(cmd, "\\bin\\CHINT_PDFSignoff.jar"); - strcat(cmd, " \""); - /*strcat(cmd, path); - strcat(cmd, "\" \"");*/ - strcat(cmd, temp_file); - strcat(cmd, "\" \""); - strcat(cmd, temp_file2); - strcat(cmd, "\" \""); - strcat(cmd, tz_path); - strcat(cmd, "\""); - printf("\n%s\n", cmd); - system(cmd); - /*char txtPath[256] = ""; - strcpy(txtPath, "DEL /f "); - strcat(txtPath, path); - system(txtPath);*/ - tag_t new_file_tag = NULLTAG; - IMF_file_t file_descriptor; - if (temp_file2 != NULL) { - IMF_import_file(temp_file2, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor); - } - else - { - IMF_import_file(temp_file, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor); - } - IMF_set_original_file_name2(new_file_tag, origin_file_name); - IMF_close_file(file_descriptor); - AOM_save(new_file_tag); - AOM_unlock(new_file_tag); + // AE_ask_dataset_named_ref2(spec_dataset_rev, ref_name, &reference_type, &ref_object); + // if (ref_object == NULLTAG) + // { + // printf("\nref_object is NULLTAG\n"); + // return ITK_ok; + // } + // printf("reference_type=%d\n", reference_type); + // if (reference_type == AE_PART_OF) + // { + // ITKCALL(IMF_ask_file_pathname2(ref_object, SS_WNT_MACHINE, &pathname)); + // IMF_ask_original_file_name2(ref_object, &origin_file_name); + // char new_ds_name[WSO_name_size_c + 1] = ""; + // char* new_file_name = USER_new_file_name(new_ds_name, ref_name, "pdf", 0); + // char* temp_dir = getenv("temp"); + // char temp_file[SS_MAXPATHLEN] = ""; + // char temp_file2[SS_MAXPATHLEN] = ""; + // strcpy(temp_file, temp_dir); + // strcat(temp_file, "\\"); + // strcat(temp_file, new_file_name); + // IMF_export_file(ref_object, temp_file); + // + // if (strstr(new_file_name, ".pdf") != NULL) { + // sprintf(temp_file2, "%s\\1%s", temp_dir, new_file_name); + // } + // else { + // sprintf(temp_file2, "%s\\1%s.pdf", temp_dir, new_file_name); + // } + // //sprintf(temp_file2, "%s.pdf", temp_file); + // printf("\ntemp_file=%s\n", temp_file); + // char cmd[256] = ""; + // char* tc_root_dir = getenv("tc_root"); + // strcpy(cmd, "java -jar "); + // strcat(cmd, tc_root_dir); + // strcat(cmd, "\\bin\\CHINT_PDFSignoff.jar"); + // strcat(cmd, " \""); + // /*strcat(cmd, path); + // strcat(cmd, "\" \"");*/ + // strcat(cmd, temp_file); + // strcat(cmd, "\" \""); + // strcat(cmd, temp_file2); + // strcat(cmd, "\" \""); + // strcat(cmd, tz_path); + // strcat(cmd, "\""); + // printf("\n%s\n", cmd); + // system(cmd); + // /*char txtPath[256] = ""; + // strcpy(txtPath, "DEL /f "); + // strcat(txtPath, path); + // system(txtPath);*/ + // tag_t new_file_tag = NULLTAG; + // IMF_file_t file_descriptor; + // if (temp_file2 != NULL) { + // IMF_import_file(temp_file2, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor); + // } + // else + // { + // IMF_import_file(temp_file, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor); + // } + // IMF_set_original_file_name2(new_file_tag, origin_file_name); + // IMF_close_file(file_descriptor); + // AOM_save(new_file_tag); + // AOM_unlock(new_file_tag); - AOM_lock(spec_dataset_rev); + // AOM_lock(spec_dataset_rev); - AE_remove_dataset_named_ref_by_tag2(spec_dataset_rev, ref_name, ref_object); + // AE_remove_dataset_named_ref_by_tag2(spec_dataset_rev, ref_name, ref_object); - AE_add_dataset_named_ref2(spec_dataset_rev, ref_name, AE_PART_OF, new_file_tag); - AOM_save(spec_dataset_rev); - AOM_unlock(spec_dataset_rev); - char tempPath[256] = ""; - char tempPath2[256] = ""; - char tempPath3[256] = ""; - strcpy(tempPath, "DEL /f "); - strcat(tempPath, temp_file); - system(tempPath); - strcpy(tempPath2, "DEL /f "); - strcat(tempPath2, temp_file2); - system(tempPath2); - /*strcpy(tempPath3, "DEL /f "); - strcat(tempPath3, tz_path); - system(tempPath3);*/ - //ITKCALL(ifail = import_dataset_file(secondary_objects[j], "T2_DWG", "dwg", temp_file, datasetName)); - } - } - MEM_free(dataset_type); - } - DOFREE(secondary_objects); - } - } + // AE_add_dataset_named_ref2(spec_dataset_rev, ref_name, AE_PART_OF, new_file_tag); + // AOM_save(spec_dataset_rev); + // AOM_unlock(spec_dataset_rev); + // char tempPath[256] = ""; + // char tempPath2[256] = ""; + // char tempPath3[256] = ""; + // strcpy(tempPath, "DEL /f "); + // strcat(tempPath, temp_file); + // system(tempPath); + // strcpy(tempPath2, "DEL /f "); + // strcat(tempPath2, temp_file2); + // system(tempPath2); + // /*strcpy(tempPath3, "DEL /f "); + // strcat(tempPath3, tz_path); + // system(tempPath3);*/ + // //ITKCALL(ifail = import_dataset_file(secondary_objects[j], "T2_DWG", "dwg", temp_file, datasetName)); + // } + // } + // MEM_free(dataset_type); + // } + // DOFREE(secondary_objects); + // } + //} - POM_AM__set_application_bypass(false); - DOFREE(taskAttches); - ECHO("=========================================================\n"); - ECHO("电子签名 结束\n"); - ECHO("=========================================================\n"); + //POM_AM__set_application_bypass(false); + //DOFREE(taskAttches); + //ECHO("=========================================================\n"); + //ECHO("电子签名 结束\n"); + //ECHO("=========================================================\n"); return ifail; } \ No newline at end of file diff --git a/General/General/epm_handler_common.h b/General/General/epm_handler_common.h index b3023f9..4db2bcc 100644 --- a/General/General/epm_handler_common.h +++ b/General/General/epm_handler_common.h @@ -61,6 +61,10 @@ int CHINT_yptask_complete(EPM_action_message_t msg); int chint_ecn_signoff(EPM_action_message_t msg); int chint_ecn_assign(EPM_action_message_t msg); + +int CHINT_DRAWING_TO_SRM(EPM_action_message_t msg); +int chint_changenotice(EPM_action_message_t msg); +int chint_check_materialstatus(EPM_action_message_t msg); //user service end #ifdef __cplusplus } diff --git a/General/General/epm_register_handler.cpp b/General/General/epm_register_handler.cpp index 2fca164..7c6d33c 100644 --- a/General/General/epm_register_handler.cpp +++ b/General/General/epm_register_handler.cpp @@ -120,28 +120,28 @@ extern DLLAPI int USERSERVICE_custom_register_handlers(int *decision, va_list ar } else { printf("Registering action handler chintP failed %d\n", ifail); }*/ - ifail = EPM_register_action_handler("chintProperty", "chintProperty", (EPM_action_handler_t)chintProperty); + ITKCALL(ifail = EPM_register_action_handler("chintProperty", "chintProperty", (EPM_action_handler_t)chintProperty)); if(ifail==0) { printf("Registering action handler chintProperty successful\n"); } else { printf("Registering action handler chintProperty failed %d\n", ifail); } - ifail = EPM_register_action_handler("chintSignChange", "chintSignChange", (EPM_action_handler_t)chintSignChange); + ITKCALL(ifail = EPM_register_action_handler("chintSignChange", "chintSignChange", (EPM_action_handler_t)chintSignChange)); if(ifail==0) { printf("Registering action handler chintSignChange successful\n"); } else { printf("Registering action handler chintSignChange failed %d\n", ifail); } - ifail = EPM_register_action_handler("chint_signoff_dataset", "chint_signoff_dataset", (EPM_action_handler_t)chint_signoff_dataset); + ITKCALL(ifail = EPM_register_action_handler("chint_signoff_dataset", "chint_signoff_dataset", (EPM_action_handler_t)chint_signoff_dataset)); if(ifail==0) { printf("Registering action handler chint_signoff_dataset successful\n"); } else { printf("Registering action handler chint_signoff_dataset failed %d\n", ifail); } - ifail = EPM_register_action_handler("chint_getChgOrde", "chint_getChgOrde", (EPM_action_handler_t)chint_getChgOrde); + ITKCALL(ifail = EPM_register_action_handler("chint_getChgOrde", "chint_getChgOrde", (EPM_action_handler_t)chint_getChgOrde)); if (ifail == 0) { printf("Registering action handler chint_getChgOrde successful\n"); } @@ -149,7 +149,7 @@ extern DLLAPI int USERSERVICE_custom_register_handlers(int *decision, va_list ar printf("Registering action handler chint_getChgOrde failed %d\n", ifail); } - ifail = EPM_register_action_handler("chint_getProduct", "chint_getProduct", (EPM_action_handler_t)chint_getProduct); + ITKCALL(ifail = EPM_register_action_handler("chint_getProduct", "chint_getProduct", (EPM_action_handler_t)chint_getProduct)); if (ifail == 0) { printf("Registering action handler chint_getProduct successful\n"); } @@ -157,7 +157,7 @@ extern DLLAPI int USERSERVICE_custom_register_handlers(int *decision, va_list ar printf("Registering action handler chint_getProduct failed %d\n", ifail); } - ifail = EPM_register_action_handler("chint_DesignProcess", "chint_DesignProcess", (EPM_action_handler_t)chint_DesignProcess); + ITKCALL(ifail = EPM_register_action_handler("chint_DesignProcess", "chint_DesignProcess", (EPM_action_handler_t)chint_DesignProcess)); if (ifail == 0) { printf("Registering action handler chint_DesignProcess successful\n"); } @@ -165,35 +165,35 @@ extern DLLAPI int USERSERVICE_custom_register_handlers(int *decision, va_list ar printf("Registering action handler chint_DesignProcess failed %d\n", ifail); } - ifail = EPM_register_action_handler("chint_pdf_signoff", "chint_pdf_signoff", (EPM_action_handler_t)chint_pdf_signoff); + ITKCALL(ifail = EPM_register_action_handler("chint_pdf_signoff", "chint_pdf_signoff", (EPM_action_handler_t)chint_pdf_signoff)); if (ifail == 0) { printf("Registering action handler chint_pdf_signoff successful\n"); } else { printf("Registering action handler chint_pdf_signoff failed %d\n", ifail); } - ifail = EPM_register_action_handler("chint_updateToPi", "chint_updateToPi", (EPM_action_handler_t)chint_updateToPi); + ITKCALL(ifail = EPM_register_action_handler("chint_updateToPi", "chint_updateToPi", (EPM_action_handler_t)chint_updateToPi)); if (ifail == 0) { printf("Registering action handler chint_updateToPi successful\n"); } else { printf("Registering action handler chint_updateToPi failed %d\n", ifail); } - ifail = EPM_register_action_handler("chint_add_to_workflow", "chint_add_to_workflow", (EPM_action_handler_t)chint_add_to_workflow); + ITKCALL(ifail = EPM_register_action_handler("chint_add_to_workflow", "chint_add_to_workflow", (EPM_action_handler_t)chint_add_to_workflow)); if (ifail == 0) { printf("Registering action handler chint_add_to_workflow successful\n"); } else { printf("Registering action handler chint_add_to_workflow failed %d\n", ifail); } - ifail = EPM_register_action_handler("chint_remove_other_deisgndata", "chint_remove_other_deisgndata", (EPM_action_handler_t)chint_remove_other_deisgndata); + ITKCALL(ifail = EPM_register_action_handler("chint_remove_other_deisgndata", "chint_remove_other_deisgndata", (EPM_action_handler_t)chint_remove_other_deisgndata)); if (ifail == 0) { printf("Registering action handler chint_remove_other_deisgndata successful\n"); } else { printf("Registering action handler chint_remove_other_deisgndata failed %d\n", ifail); } - ifail = EPM_register_action_handler("chint_check_exist_ebom", "chint_check_exist_ebom", (EPM_action_handler_t)chint_check_exist_ebom); + ITKCALL(ifail = EPM_register_action_handler("chint_check_exist_ebom", "chint_check_exist_ebom", (EPM_action_handler_t)chint_check_exist_ebom)); if (ifail == 0) { printf("Registering action handler chint_check_exist_ebom successful\n"); } @@ -201,7 +201,7 @@ extern DLLAPI int USERSERVICE_custom_register_handlers(int *decision, va_list ar printf("Registering action handler chint_check_exist_ebom failed %d\n", ifail); } - ifail = EPM_register_action_handler("chint_backCheckTable", "chint_backCheckTable", (EPM_action_handler_t)chint_backCheckTable); + ITKCALL(ifail = EPM_register_action_handler("chint_backCheckTable", "chint_backCheckTable", (EPM_action_handler_t)chint_backCheckTable)); if (ifail == 0) { printf("Registering action handler chint_backCheckTable successful\n"); } @@ -209,7 +209,7 @@ extern DLLAPI int USERSERVICE_custom_register_handlers(int *decision, va_list ar printf("Registering action handler chint_backCheckTable failed %d\n", ifail); } - ifail = EPM_register_action_handler("chint_CheckTable_State", "chint_CheckTable_State", (EPM_action_handler_t)chint_CheckTable_State); + ITKCALL(ifail = EPM_register_action_handler("chint_CheckTable_State", "chint_CheckTable_State", (EPM_action_handler_t)chint_CheckTable_State)); if (ifail == 0) { printf("Registering action handler chint_CheckTable_State successful\n"); } @@ -217,7 +217,7 @@ extern DLLAPI int USERSERVICE_custom_register_handlers(int *decision, va_list ar printf("Registering action handler chint_CheckTable_State failed %d\n", ifail); } - ifail = EPM_register_action_handler("chint_check_ZC_ZJ_BOM", "chint_check_ZC_ZJ_BOM", (EPM_action_handler_t)chint_check_ZC_ZJ_BOM); + ITKCALL(ifail = EPM_register_action_handler("chint_check_ZC_ZJ_BOM", "chint_check_ZC_ZJ_BOM", (EPM_action_handler_t)chint_check_ZC_ZJ_BOM)); if (ifail == 0) { printf("Registering action handler chint_check_ZC_ZJ_BOM successful\n"); } @@ -225,14 +225,14 @@ extern DLLAPI int USERSERVICE_custom_register_handlers(int *decision, va_list ar printf("Registering action handler chint_check_ZC_ZJ_BOM failed %d\n", ifail); } - ifail = EPM_register_action_handler("CHINT_task_complete", "CHINT_task_complete", (EPM_action_handler_t)CHINT_task_complete); + ITKCALL(ifail = EPM_register_action_handler("CHINT_task_complete", "CHINT_task_complete", (EPM_action_handler_t)CHINT_task_complete)); if (ifail == 0) { printf("Registering action handler CHINT_task_complete successful\n"); } else { printf("Registering action handler CHINT_task_complete failed %d\n", ifail); } - ifail = EPM_register_action_handler("CHINT_yptask_complete", "CHINT_yptask_complete", (EPM_action_handler_t)CHINT_yptask_complete); + ITKCALL(ifail = EPM_register_action_handler("CHINT_yptask_complete", "CHINT_yptask_complete", (EPM_action_handler_t)CHINT_yptask_complete)); if (ifail == 0) { printf("Registering action handler CHINT_yptask_complete successful\n"); } @@ -240,14 +240,14 @@ extern DLLAPI int USERSERVICE_custom_register_handlers(int *decision, va_list ar printf("Registering action handler CHINT_yptask_complete failed %d\n", ifail); } - ifail = EPM_register_action_handler("CHINT_cossheet_upgrade", "CHINT_cossheet_upgrade", (EPM_action_handler_t)CHINT_cossheet_upgrade); + ITKCALL(ifail = EPM_register_action_handler("CHINT_cossheet_upgrade", "CHINT_cossheet_upgrade", (EPM_action_handler_t)CHINT_cossheet_upgrade)); if (ifail == 0) { printf("Registering action handler CHINT_cossheet_upgrade successful\n"); } else { printf("Registering action handler CHINT_cossheet_upgrade failed %d\n", ifail); } - ifail = EPM_register_action_handler("CHINT_SendOAMaterial", "CHINT_SendOAMaterial", (EPM_action_handler_t)CHINT_SendOAMaterial); + ITKCALL(ifail = EPM_register_action_handler("CHINT_SendOAMaterial", "CHINT_SendOAMaterial", (EPM_action_handler_t)CHINT_SendOAMaterial)); if (ifail == 0) { printf("Registering action handler CHINT_SendOAMaterial successful\n"); } @@ -255,7 +255,7 @@ extern DLLAPI int USERSERVICE_custom_register_handlers(int *decision, va_list ar printf("Registering action handler CHINT_SendOAMaterial failed %d\n", ifail); } //oa 版本加入流程 - ifail = EPM_register_action_handler("CHINT_GetFrock", "CHINT_GetFrock", (EPM_action_handler_t)CHINT_GetFrock); + ITKCALL(ifail = EPM_register_action_handler("CHINT_GetFrock", "CHINT_GetFrock", (EPM_action_handler_t)CHINT_GetFrock)); if (ifail == 0) { printf("Registering action handler CHINT_GetFrock successful\n"); } @@ -263,7 +263,7 @@ extern DLLAPI int USERSERVICE_custom_register_handlers(int *decision, va_list ar printf("Registering action handler CHINT_GetFrock failed %d\n", ifail); } //oa 变更传递OA - ifail = EPM_register_action_handler("chint_ecn_to_oa", "chint_ecn_to_oa", (EPM_action_handler_t)CHINT_ECN_SendOA); + ITKCALL(ifail = EPM_register_action_handler("chint_ecn_to_oa", "chint_ecn_to_oa", (EPM_action_handler_t)CHINT_ECN_SendOA)); if (ifail == 0) { printf("Registering action handler chint_ecn_to_oa successful\n"); } @@ -271,7 +271,7 @@ extern DLLAPI int USERSERVICE_custom_register_handlers(int *decision, va_list ar printf("Registering action handler chint_ecn_to_oa failed %d\n", ifail); } //3.9.2.2.1流程指派人员自动获取 - ifail = EPM_register_action_handler("CHINT_Assignment", "CHINT_Assignment", (EPM_action_handler_t)CHINT_Assignment); + ITKCALL(ifail = EPM_register_action_handler("CHINT_Assignment", "CHINT_Assignment", (EPM_action_handler_t)CHINT_Assignment)); if (ifail == 0) { printf("Registering action handler CHINT_Assignment successful\n"); } @@ -279,7 +279,7 @@ extern DLLAPI int USERSERVICE_custom_register_handlers(int *decision, va_list ar printf("Registering action handler CHINT_Assignment failed %d\n", ifail); } //更改通知单新版excel文件签名 - ifail = EPM_register_action_handler("chint_ecn_signoff", "chint_ecn_signoff", (EPM_action_handler_t)chint_ecn_signoff); + ITKCALL(ifail = EPM_register_action_handler("chint_ecn_signoff", "chint_ecn_signoff", (EPM_action_handler_t)chint_ecn_signoff)); if (ifail == 0) { printf("Registering action handler chint_ecn_signoff successful\n"); } @@ -287,14 +287,38 @@ extern DLLAPI int USERSERVICE_custom_register_handlers(int *decision, va_list ar printf("Registering action handler chint_ecn_signoff failed %d\n", ifail); } //指派变更会签节点 - ifail = EPM_register_action_handler("chint_ecn_assign", "chint_ecn_assign", (EPM_action_handler_t)chint_ecn_assign); + ITKCALL(ifail = EPM_register_action_handler("chint_ecn_assign", "chint_ecn_assign", (EPM_action_handler_t)chint_ecn_assign)); if (ifail == 0) { printf("Registering action handler chint_ecn_assign successful\n"); } else { printf("Registering action handler chint_ecn_assign failed %d\n", ifail); } - + //SRM + ITKCALL(ifail = EPM_register_action_handler("CHINT_DRAWING_TO_SRM", "CHINT_DRAWING_TO_SRM", (EPM_action_handler_t)CHINT_DRAWING_TO_SRM)); + if (ifail == 0) { + printf("Registering action handler CHINT_DRAWING_TO_SRM successful\n"); + } + else { + printf("Registering action handler CHINT_DRAWING_TO_SRM failed %d\n", ifail); + } + //飞书通知 + ITKCALL(ifail = EPM_register_action_handler("chint_changenotice", "chint_changenotice", (EPM_action_handler_t)chint_changenotice)); + if (ifail == 0) { + printf("Registering action handler chint_changenotice successful\n"); + } + else { + printf("Registering action handler chint_changenotice failed %d\n", ifail); + } + + //BOM物料封存停用状态 + ITKCALL(ifail = EPM_register_action_handler("chint_check_materialstatus", "chint_check_materialstatus", (EPM_action_handler_t)chint_check_materialstatus)); + if (ifail == 0) { + printf("Registering action handler chint_check_materialstatus successful\n"); + } + else { + printf("Registering action handler chint_check_materialstatus failed %d\n", ifail); + } return ifail; } diff --git a/General/General/tc_log.cxx b/General/General/tc_log.cxx new file mode 100644 index 0000000..476eecc --- /dev/null +++ b/General/General/tc_log.cxx @@ -0,0 +1,157 @@ +/** +* @file common_itk_util.cpp +* @brief itk warpper utility function +* @author James +* @history +* =================================================================================== +* Date Name Description of Change +* 18-July-2008 Ray +*/ +//#include +#include +#include +#include +#include + +#include +#include +#include +#include +using namespace std; +// +#ifdef WIN32 +#include +#include +#else +#include +#endif +// +#include "tc_log.h" + +#define ARGS_LENGTH 200 +#define MAX_PRINTLINE_LENGTH 2000 +#define MAX_PATH_LENGTH 2000 +#define MAX_ARGUMENT_LENGTH 400 +#define MAX_PARAMNAME_LENGTH 50 +#define MAX_FILE_EXT_LENGTH 10 +#define TRUE_FLAG 1 +#define FALSE_FLAG 0 +#define DETAILLOG 1 + +#define DOFREE(obj) \ +{ \ + if(obj) \ + { \ + MEM_free(obj); \ + obj = NULL; \ + } \ +} + + +FILE* log_file = NULL; +char *log_path = NULL; + +void CreateTcLogFile(const char* logFileName) +{ + int i=0; + + log_file = NULL; + if (log_path) { + MEM_free(log_path); + log_path = NULL; + } + + log_path = (char*)MEM_alloc((strlen(logFileName) + 1) * sizeof(char*)); + strcpy(log_path, logFileName); + + //get lidy_logFileName + //sprintf(lidy_logFileName, "%s", lidy_logFileName); + printf("log file name: %s\n", logFileName); + + + //create log file + if((log_file = fopen(logFileName, "a"))==NULL) + { + printf("log file create failed\n"); + } + +} + +void WriteTcLog(const char* format, ...) +{ + va_list arg; + char tmp[8192]; + + if(log_file) + { + //get the message + memset(tmp, 0, sizeof(tmp)); + va_start(arg, format); + vsprintf(tmp, format, arg); + va_end(arg); + + //----------print to command window for trace--------// + printf("%s\n", tmp); + + //print message to log file + fprintf(log_file, "%s\n", tmp); + fflush(log_file); + } + else + { + printf("*!Error!*: Log File Not Exist\n"); + } +} + +void CloseTcLog(void) +{ + if(log_file) + { + fclose(log_file); + log_file = NULL; + } + + if (log_path) { + MEM_free(log_path); + log_path = NULL; + } +} + +void log_open(void) { + if (log_path) { + if ((log_file = fopen(log_path, "a")) == NULL) { + printf("log file create failed\n"); + } + } +} + +void log_close(void) { + if (log_file) { + fclose(log_file); + log_file = NULL; + } +} + +string getNum(int num) { + char str[3] = ""; + sprintf(str, "%02d", num); + return str; +} + +string getNow(char* format) { + time_t now = time(NULL); + tm* tm_t = localtime(&now); + string str = ""; + if (tc_strcmp(format, "yyyyMMdd") == 0) { + str.append(to_string(tm_t->tm_year + 1900)).append(getNum(tm_t->tm_mon + 1)).append(getNum(tm_t->tm_mday)); + } + else if (tc_strcmp(format, "LOG") == 0) {//yyyy-MM-dd HH:mi:ss + str.append(to_string(tm_t->tm_year + 1900)).append("-") + .append(getNum(tm_t->tm_mon + 1)).append("-") + .append(getNum(tm_t->tm_mday)).append(" ") + .append(getNum(tm_t->tm_hour)).append(":") + .append(getNum(tm_t->tm_min)).append(":") + .append(getNum(tm_t->tm_sec)); + } + return str; +} diff --git a/General/General/tc_log.h b/General/General/tc_log.h index 81d2584..95615bb 100644 --- a/General/General/tc_log.h +++ b/General/General/tc_log.h @@ -7,6 +7,7 @@ * Date Name Description of Change * 09-July-2008 Ray */ + #ifndef TC_LOG_H #define TC_LOG_H @@ -14,10 +15,16 @@ extern "C" { #endif -//void CreateLogFile(char* logFileName); -//void WriteLog(const char* format, ...); -//void CloseLog(void); - +void CreateTcLogFile(const char* logFileName); +void WriteTcLog(const char* format, ...); +void CloseTcLog(void); +void log_open(void); +void log_close(void); +string getNow(char* format); +//int FindDatasetReferenceExt( tag_t datasettype, const char *datasettype_ref, char ext[10] ); +//int CompareDate( date_t date1, date_t date2 ); +//int GetRandomTempFile( char tempFile[256] ); +//logical IsItemRevisionType( char object_type[WSO_name_size_c + 1] ); #ifdef __cplusplus }