#include "util.h" bool startsWith(const char* str, const char* prefix) { return strncmp(str, prefix, strlen(prefix)) == 0; } bool endsWith(const char* str, const char* suffix) { if (!str || !suffix) return str == suffix; size_t lenStr = strlen(str); size_t lenSuffix = strlen(suffix); if (lenSuffix > lenStr) return false; return strncmp(str + lenStr - lenSuffix, suffix, lenSuffix) == 0; } bool isJD2_BJRevision(const char* type) { return startsWith(type, "JD2") && endsWith(type, "BJRevision"); } /* * 获取包含中文字符的字符串长度 */ int getCharLength(char str[]) { int count = 0; for (int i = 0; str[i]; i++) { if (str[i] < 0) i++; count++; } return count; } /* * 选中对象版本发起任意流程时,检查版本表单中的SAP物料描述属性 */ int jd_check_wlms_length(EPM_rule_message_t msg) { printf("Sample_confirmation_sheet is begin! \n"); int ifail = ITK_ok, result_tag = EPM_go; tag_t rootTask = NULLTAG; int attachmentCount = 0; tag_t* attachmentTags = NULL, attachmentTag = NULLTAG; char* wlms = NULL, * type = NULL, * name = NULL, * jz = NULL; int form_cnt = 0; tag_t* forms = NULL; ITKCALL(ifail = EPM_ask_root_task(msg.task, &rootTask)); ITKCALL(ifail = EPM_ask_attachments(rootTask, EPM_target_attachment, &attachmentCount, &attachmentTags)); //便利所有的流程目标下的对象 for (int i = 0; i < attachmentCount; i++) { attachmentTag = attachmentTags[i];//PartRevisionMaster ITKCALL(ifail = AOM_ask_value_string(attachmentTag, "object_type", &type)); ITKCALL(ifail = AOM_ask_value_string(attachmentTag, "object_name", &name)); printf(">>>当前流程下对象的类型为==[%s]\n", type); //获取版本对象下的表单 ITKCALL(ifail = AOM_ask_value_tags(attachmentTag, "IMAN_master_form_rev", &form_cnt, &forms)); //=================================下面是检查版本表单中的描述长度================================================================================================ if (form_cnt > 0) { printf(">>>当前流程下对象存在表单,表单数量=[%d]\n", form_cnt); //默认取第一个表单 ITKCALL(ifail = AOM_ask_value_string(forms[0], "jd2_wlms", &wlms)); //string wlms_string = wlms; printf(">>>物料描述为:[%s]\n >>>长度为:[%d]\n", wlms, getCharLength(wlms)); //printf("wlms_string.length() = %d, \n wlms_string.size() = %d, \n strlen(wlms) = %d, count_utf8_characters(wlms_string)=%d \n", wlms_string.length(), wlms_string.size(), strlen(wlms), count_utf8_characters(wlms_string)); if (wlms != NULL && getCharLength(wlms) > 40) { printf(">>>物料描述超过40个字符,不允许发起流程,请检查!!\n"); char* message = "SAP物料描述超过40个字符,不允许发起流程,请检查!!"; cout << "Exception:" << message << endl; EMH_store_error_s1(EMH_severity_error, EMH_IDGENERATION_ERROR_BASE, message); result_tag = EPM_nogo; break; } else { printf(">>>物料描述长度小于40,验证通过!\n"); } } else { printf(">>>当前流程下对象不存在表单,无法验证表单属性中的“物料描述长度”,跳过验证!\n"); } } MEM_free(wlms); MEM_free(forms); MEM_free(name); MEM_free(type); MEM_free(attachmentTags); return result_tag; }