#include "util.h" #include #include 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; } /* * 选中对象版本发起任意流程时,检查版本净重 */ int jd_check_jz(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* 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)); //==========================下面是检查特定版本类型(JD2_XXBJRevision)下的表单属性:净重=========================================================================================================== if (isJD2_BJRevision(type)) { //检查版本表单是否存在属性:jd2_jz ITKCALL(ifail = AOM_ask_value_string(forms[0], "jd2_jz", &jz)); printf("获取净重属性的ifail结果 = [%d] \n", ifail); if (ifail != 0 && ifail != 2) { //未获取到净重属性,流程正常发起 printf("未获取到净重属性,流程正常发起 \n"); continue; }else { if (jz != NULL && stricmp(jz, "") == 0) { //弹出弹窗提示,且终止流程 printf(">>>部件净重为空,不允许发起流程,请检查!!\n"); char* message = "部件净重为空,不允许发起流程,请检查!!"; cout << "Exception:" << message << endl; EMH_store_error_s1(EMH_severity_error, EMH_IDGENERATION_ERROR_BASE, message); result_tag = EPM_nogo; break; }else if (jz != NULL && stricmp(jz, "0.001") < 0) { //弹出弹窗提示,且终止流程 printf(">>>部件净重小于0.001,不允许发起流程,请检查!!\n"); char* message = "部件净重小于0.001,不允许发起流程,请检查!!"; cout << "Exception:" << message << endl; EMH_store_error_s1(EMH_severity_error, EMH_IDGENERATION_ERROR_BASE, message); result_tag = EPM_nogo; break; }else { //正常发起流程 printf(">>>净重=[%s],允许发起流程!\n",jz); } } } else { printf(">>>当前流程下对象[%s]类型为[%s],类型非部件类型:JD2_[XX]BJRevision,不必检查净重!!\n", name,type); } } MEM_free(forms); MEM_free(name); MEM_free(type); MEM_free(attachmentTags); return result_tag; } /* * 修改单位值的userservice方法 */ int USERSEVICE_getProperties(void* returnValue) { int ifail = ITK_ok; tag_t tag = NULL_TAG; char* uomName = NULL; tag_t* release_objs = NULL; //接收参数 USERARG_get_tag_argument(&tag); USERARG_get_string_argument(&uomName); int num_could = 0; tag_t* uoms = NULL, uom = NULLTAG; // 获取所有单位的列表 ITKCALL(UOM_extent(&num_could, &uoms)); for (int i = 0; i < num_could; i++) { char* name = NULL; UOM_ask_name(uoms[i], &name); if (strcmp(name, uomName) == 0) { uom = uoms[i]; break; } } // 初始化类ID、属性ID和标签变量 char* class_id = NULL; tag_t attr_id = NULLTAG, class_tag = NULLTAG, tag_instance = NULLTAG; // 锁定对象以防止在操作过程中被修改 ITKCALL(AOM_lock(tag)); // 获取对象所属类的标签和名称 ITKCALL(POM_class_of_instance(tag, &class_tag)); ITKCALL(POM_name_of_class(class_tag, &class_id)); // 获取类中名为"uom_tag"的属性的标签 ITKCALL(POM_attr_id_of_attr("uom_tag", class_id, &attr_id)); // 刷新对象的实例以确保数据是最新的 ITKCALL(POM_refresh_instances_any_class(1, &tag, POM_modify_lock)); // 将对象的单位属性设置为之前找到的单位标签 ITKCALL(POM_set_attr_tag(1, &tag, attr_id, uom)); // 保存对对象所做的更改 ITKCALL(POM_save_instances(1, &tag, true)); // 解锁对象 ITKCALL(AOM_unlock(tag)); // 刷新对象的状态 ITKCALL(AOM_refresh(tag, false)); return ifail; }