You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
5.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#define _CRT_SECURE_NO_WARNINGS
#include "epm_handler_common.h"
int ML_ItemRevPreUpdate(METHOD_message_t* msg, va_list args)
{
printf("=========================版本修订前操作 Start===================\n");
int ifail = ITK_ok;
tag_t new_rev = va_arg(args, tag_t);//修订的旧版本
char* operation = va_arg(args, char*);//rev_id
tag_t parent_rev = va_arg(args, tag_t);//修订前版本
printf("operation%s\n", operation);
//如果是修订操作
if (strcmp(operation, "Revise") == 0)
{
int pref_cnt = 0;
char ** pref_vals = NULL;
//获取首选项的值
PREF_ask_char_values("ML_ItemRevPreUpdate", &pref_cnt, &pref_vals);
map<string, string> typePropertyType;
for (int j = 0; j < pref_cnt; j++)
{
if (strstr(pref_vals[j], "-") != NULL)
{
//按照-进行拆分。拆分条件
int valueCount = 0;
char ** valueChar = new char *[64];
//分割字符串
split(pref_vals[j], "-", valueChar, &valueCount);
typePropertyType[valueChar[0]] = valueChar[1];// .insert(std::pair<char*, char*>(valueChar[0], valueChar[1]));
}
}
//获取对象类型
char * itemType = NULL;
AOM_ask_value_string(parent_rev, "object_type", &itemType);
printf("itemType : %s \r\n", itemType);
//判断
tag_t item = NULLTAG;
ITEM_ask_item_of_rev(parent_rev, &item);
tag_t class_tag = NULL, attr_id = NULL;
char * class_id = NULL;
POM_class_of_instance(item, &class_tag);
POM_name_of_class(class_tag, &class_id);
int ifail2 = POM_attr_id_of_attr("ml8_Status", class_id, &attr_id);
if (ifail2 == ITK_ok && attr_id != NULL)
{
//获取drawmark属性的值
char * generalIdentify = NULL;
AOM_ask_value_string(item, "ml8_Status", &generalIdentify);
printf("限用:%s====================\n", generalIdentify);
//if (generalIdentify != NULL && (strcmp(generalIdentify, "限用") == 0 || strcmp(generalIdentify, "冻结") == 0))
//if (generalIdentify != NULL && (strcmp(generalIdentify, "限用") == 0 || strcmp(generalIdentify, "冻结") == 0 || strcmp(generalIdentify, "RestrictPart") == 0 || strcmp(generalIdentify, "FreezePart") == 0))//20230928添加BOM时限制添加冻结、限用物料处理步骤
if (generalIdentify != NULL && (strcmp(generalIdentify, "RestrictPart") == 0 || strcmp(generalIdentify, "FreezePart") == 0 || strcmp(generalIdentify, "ObsoletePart") == 0))//20250116海外要求增加废止状态
{
printf("物料状态不匹配 \r\n");
ifail = 1;
}
DOFREE(generalIdentify);
}
if (ifail == 1)
{
}
else
{
string propertyNames = typePropertyType[itemType];
if (propertyNames.c_str() != NULL)
{
const char * statusName = propertyNames.c_str();
char* name = new char[2048];//足够长
strcpy(name, statusName);
printf("name : %s \r\n", name);
char * revPuid = NULL;
//获取PUID
ITK__convert_tag_to_uid(parent_rev, &revPuid);
if (strstr(name, "=") > 0)
{
//按照-进行拆分。拆分条件
int valueCount = 0;
char ** valueChar = new char *[64];
//分割字符串
split(name, "=", valueChar, &valueCount);
char * whereValue = valueChar[1];
bool isHaveItem = false;
if (strstr(whereValue, ".") > 0)
{
int itemTypeCount = 0;
char ** itemTypeChar = new char *[64];
//分割字符串
split(whereValue, ".", itemTypeChar, &itemTypeCount);
char * stringItemType = itemTypeChar[0];
char * referencedName = itemTypeChar[1];
//判断是否在指定的关系下
int n_references = 0;
int *levels = 0;
tag_t * references_tag = NULLTAG;
char ** relation_type_name = NULL;
//通过引用关系查找到变更单
WSOM_where_referenced(parent_rev, 1, &n_references, &levels, &references_tag, &relation_type_name);
for (int i = 0; i < n_references; i++)
{
char *objectType = NULL;
AOM_ask_value_string(references_tag[i], "object_type", &objectType);
printf("object_type : %s \r\n", objectType);
printf("stringItemType : %s \r\n", stringItemType);
if (strcmp(stringItemType, objectType) == 0)
{
int itemNum = 0;
tag_t * items = NULL;
printf("referencedName : %s \r\n", referencedName);
//获取指定关系下的对象
AOM_ask_value_tags(references_tag[i], referencedName, &itemNum, &items);
printf("itemNum : %d \r\n", itemNum);
for (int ii = 0; ii < itemNum; ii++)
{
char * puid = NULL;
//获取PUID
ITK__convert_tag_to_uid(items[ii], &puid);
printf("puid : %s \r\n", puid);
if (strcmp(revPuid, puid) == 0)
{
isHaveItem = true;
break;
}
}
}
}
}
if (!isHaveItem)
{
printf("不在变更单的指定关系下 \r\n");
ifail = 1;
}
else
{
//判断是否发布
int releaseCount = 0;
tag_t * releaseTags = NULL;
//判断子件是否发布
AOM_ask_value_tags(parent_rev, "release_status_list", &releaseCount, &releaseTags);
bool isHave = false;
for (int i = 0; i < releaseCount; i++)
{
char * releaseString = NULL;
AOM_ask_value_string(releaseTags[i], "object_name", &releaseString);
printf("releaseString : %s \r\n", releaseString);
if (strcmp(releaseString, valueChar[0]) == 0)
{
isHave = true;
DOFREE(releaseString);
break;
}
DOFREE(releaseString);
}
if (!isHave)
{
ifail = 1;
}
DOFREE(releaseTags);
}
}
}
}
DOFREE(class_id);
DOFREE(itemType);
//DOFREE(releaseTags);
}
//DOFREE(operation);
if (ifail == 1)
{
printf("ifail%d \r\n", ifail);
EMH_store_error_s1(EMH_severity_user_error, EMH_USER_error_base, "发布状态、物料状态不匹配,或不在变更单的指定关系下!不能进行修订!");
}
printf("=========================版本修订修订前操作 End===================\n");
return ifail;
}