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.

655 lines
16 KiB

#define _CRT_SECURE_NO_WARNINGS
#include "epm_handler_common.h"
using namespace std;
#define DOFREE(obj) \
{ \
if(obj) \
{ \
MEM_free(obj); \
obj = NULL; \
} \
}
/**
*判断某个对象是否是类或者子类
*objtag 要判断的对象
*type_name 类型的名称
*/
int checkIsTypeOrSubtype(tag_t objtag, char * type_name) {
printf("判断是否是%s及其子类\n", type_name);
tag_t type = NULLTAG;
ITKCALL(TCTYPE_ask_object_type(objtag, &type));
tag_t item_type = NULLTAG;
ITKCALL(TCTYPE_find_type(type_name, "", &item_type));
int is_type = 0;
if (item_type != NULLTAG) {
printf("找到%s类\n", type_name);
//printf(" find Folder type ok !!!! \n");
logical isok = FALSE;
ITKCALL(TCTYPE_is_type_of(type, item_type, &isok));
if (isok) {
printf("是%s类及其子类\n\n", type_name);
is_type = 1;
}
else {
printf("不是%s类及其子类\n\n", type_name);
is_type = 0;
}
}
else {
printf("没有找到%s类\n\n", type_name);
}
return is_type;
}
void Split(string strArg, string spliter, vector<string> &ans)
{
ans.clear();
size_t index0;
string one_arg;
if (strArg.find_first_not_of(' ') == string::npos)
strArg = "";
while (strArg.size()>0)
{
index0 = strArg.find(spliter);
if (index0 != string::npos)
{
one_arg = strArg.substr(0, index0);
strArg = strArg.substr(index0 + spliter.size());
ans.push_back(one_arg);
}
else
{
ans.push_back(strArg);
break;
}
}
}
//str havenum数字 isneg负 havedec小数 havelow大写 havecap小写
int checkstr(string str, boolean havenum, boolean isneg, boolean havedec, boolean havelow, boolean havecap, int decsize, int intsize, int size)
{
int zsnum = 0;//整数长度
int xsnum = 0;//小数长度
boolean isdian = false;
int xxx_num = str.size();//字符长度
int size_num = 0;//带中文长度
int x = 0;
for (int i = 0; i < xxx_num; i++)
{
int tmp = (int)str[i];
if (tmp != '-'&&tmp != '.')
{
if (!isdian)
{
zsnum++;
}
else {
xsnum++;
}
}
if (tmp == '.')
{
isdian = true;
}
}
while (x < xxx_num)
{
int tmp = (int)str[x];
if (tmp>0 && tmp<255)
{
x++;
size_num++;
}
else
{
x += 2;
size_num++;
}
}
printf("整数位数:%d,小数位数:%d,总长度:%d\n", zsnum, xsnum, size_num);
printf("限制:整数位数:%d,小数位数:%d,总长度:%d\n", intsize, decsize, size);
if (zsnum> intsize&&intsize != -1)
{
return 2;
}
if (xsnum>decsize&&decsize != -1)
{
return 2;
}
if (size_num > size&&size != -1)
{
return 2;
}
if (havenum || isneg || havedec || havelow || havecap)
{
for (int i = 0; i < xxx_num; i++)
{
int tmp = (int)str[i];
if (isneg && i == 0)
{
if (tmp == '-')
{
continue;
}
}
if (havenum)
{
if (tmp >= '0' && tmp <= '9')
{
continue;
}
}
if (havedec&&i != 0 && i != (str.size() - 1))
{
if (tmp == '.')
{
continue;
}
}
if (havelow)
{
if (tmp >= 'A' && tmp <= 'Z')
{
continue;
}
}
if (havecap)
{
if (tmp >= 'a' && tmp <= 'z')
{
continue;
}
}
return 1;
}
}
return 0;
}
string& replace_all(string& str, const string& old_value, const string& new_value)
{
while (true)
{
string::size_type pos(0);
if ((pos = str.find(old_value)) != string::npos)
{
str.replace(pos, old_value.length(), new_value);
}
else { break; }
}
return str;
}
/*******************************************************************************
*判断属性
* type 版本类型
* site 属性位置
* name 属性名称 ,分隔
* size 长度
* decsize 小数长度
* intsize 整数长度
* havenum 是否允许数字
* isneg 是否允许负数
* havedec 是否允许小数点
* havelow 是否允许大写
* havecap 是否允许小写
* lessthan 小于
* greaterthan 大于
* rev_rule 版本规则
* isnull 是否判断是空
* noequals 不能为指定值
*********************************************************************************/
int Judge_attribute(EPM_rule_message_t msg) {
//是否进行下去
EPM_decision_t decision = EPM_go;
printf("开始Judge_attribute\n");
auto startTime = std::chrono::high_resolution_clock::now();
//流程中的参数
int ifail = ITK_ok, att_cnt = 0, i = 0, arg_cnt = 0, arg_num;
//任务
tag_t task_tag = NULL_TAG, rootTask_tag = NULL_TAG;
//进流程的对象
tag_t * attachments = NULL, rev_tag = NULLTAG, rev_rule_tag = NULLTAG;
//对象的类名
char type_class[TCTYPE_class_name_size_c + 1] = "\0";
//流程的参数
char * argflag = NULL, *argvalue = NULL, *arg = NULL;
//错误信息
map<string, int> errMap;
char type[128] = "";//版本类型
char site[64] = "";//属性位置
char names[1024] = "";//属性名称
char size[64] = "";//长度
char decsize[64] = "";//小数长度
char intsize[64] = "";//整数长度
char havenum[64] = "";//是否允许数字
char isneg[64] = "";//是否允许负数
char havedec[64] = "";//是否允许小数点
char havelow[64] = "";//是否允许大写
char havecap[64] = "";//是否允许小写
char lessthan[64] = "";//小于
char greaterthan[64] = "";//大于
char rev_rule[128] = "";//版本规则
char isnull[64] = "";//是否判断是空
char noequals[64] = "";//不能为指定值
task_tag = msg.task;
//找任务
EPM_ask_root_task(task_tag, &rootTask_tag);
//找任务附加物
EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments);
//参数个数
arg_num = TC_number_of_arguments(msg.arguments);
//找配置的参数
for (size_t i = 0; i < arg_num; i++)
{
arg = TC_next_argument(msg.arguments);
ifail = ITK_ask_argument_named_value(arg, &argflag, &argvalue);
if (strcmp(argflag, "type") == 0) {//版本类型
if (argvalue != NULL) {
strcpy(type, argvalue);
}
}
if (strcmp(argflag, "site") == 0) {
if (argvalue != NULL) {
strcpy(site, argvalue);
}
}
if (strcmp(argflag, "name") == 0) {
if (argvalue != NULL) {
strcpy(names, argvalue);
}
}
if (strcmp(argflag, "size") == 0) {
if (argvalue != NULL) {
strcpy(size, argvalue);
}
}
if (strcmp(argflag, "decsize") == 0) {
if (argvalue != NULL) {
strcpy(decsize, argvalue);
}
}
if (strcmp(argflag, "intsize") == 0) {
if (argvalue != NULL) {
strcpy(intsize, argvalue);
}
}
if (strcmp(argflag, "havenum") == 0) {
if (argvalue != NULL) {
strcpy(havenum, argvalue);
}
}
if (strcmp(argflag, "isneg") == 0) {
if (argvalue != NULL) {
strcpy(isneg, argvalue);
}
}
if (strcmp(argflag, "havedec") == 0) {
if (argvalue != NULL) {
strcpy(havedec, argvalue);
}
}
if (strcmp(argflag, "havelow") == 0) {
if (argvalue != NULL) {
strcpy(havelow, argvalue);
}
}
if (strcmp(argflag, "havecap") == 0) {
if (argvalue != NULL) {
strcpy(havecap, argvalue);
}
}
if (strcmp(argflag, "lessthan") == 0) {
if (argvalue != NULL) {
strcpy(lessthan, argvalue);
}
}
if (strcmp(argflag, "greaterthan") == 0) {
if (argvalue != NULL) {
strcpy(greaterthan, argvalue);
}
}
if (strcmp(argflag, "rev_rule") == 0) {
if (argvalue != NULL) {
strcpy(rev_rule, argvalue);
}
}
if (strcmp(argflag, "isnull") == 0) {
if (argvalue != NULL) {
strcpy(isnull, argvalue);
}
}
if (strcmp(argflag, "noequals") == 0) {
if (argvalue != NULL) {
strcpy(noequals, argvalue);
}
}
//释放资源
DOFREE(argflag);
DOFREE(argvalue);
}
printf("参数rev_rule----%s", rev_rule);
if (strcmp(rev_rule, "") != 0)
{
ITKCALL(CFM_find(rev_rule, &rev_rule_tag));
}
printf("参数type----%s\n", type);
printf("参数site----%s\n", site);
printf("参数name----%s\n", names);
printf("参数size----%s\n", size);
printf("参数decsize----%s\n", decsize);
printf("参数intsize----%s\n", intsize);
printf("参数havenum----%s\n", havenum);
printf("参数isneg----%s\n", isneg);
printf("参数havedec----%s\n", havedec);
printf("参数havelow----%s\n", havelow);
printf("参数havecap----%s\n", havecap);
printf("参数lessthan----%s\n", lessthan);
printf("参数greaterthan----%s\n", greaterthan);
printf("参数isnull----%s\n", isnull);
printf("参数noequals----%s\n", noequals);
vector<string> name_vec;//关系类型
Split(names, ",", name_vec);
for (int i = 0; i < att_cnt; i++)
{
char *type_class = NULL;
tag_t rev_tag = attachments[i];
tag_t obj_tag = rev_tag;
ITKCALL(WSOM_ask_object_type2(rev_tag, &type_class));
printf("类型----%s", type_class);
//判断目标类型是否与参数相同
if (checkIsTypeOrSubtype(rev_tag, type) == 1) //SET8_ProductRevision
{
char* obj_str = NULL;
ITKCALL(AOM_ask_value_string(rev_tag, "object_string", &obj_str));
printf("名称----%s", obj_str);
for (int f = 0; f < name_vec.size(); f++)
{
char name[64] = "";
strcpy(name, name_vec[f].c_str());
tag_t prop_tag;
vector<string> vet_str;
vector<string> vet_dis_str;
if (strcmp(site, "ITEM") == 0)
{
ITKCALL(ITEM_ask_item_of_rev(rev_tag, &obj_tag));
//char *disname_char = NULL;
char* rev_str = NULL;
//char disname[128] = "";
char propval[128] = "";
//ITKCALL(PROP_ask_property_by_name(obj_tag, name, &prop_tag));
//ITKCALL(PROP_UIF_ask_name(prop_tag, &disname_char));
//ITKCALL(PROP_UIF_ask_value(prop_tag, &rev_str));
AOM_UIF_ask_value(obj_tag, name, &rev_str);
//strcpy(disname, disname_char);
strcpy(propval, rev_str);
vet_str.push_back(propval);
vet_dis_str.push_back(name);
DOFREE(rev_str);
//DOFREE(disname_char);
}
else if (strcmp(site, "FORM") == 0)
{
int formnum = 0;
tag_t* tag_forms;
ITKCALL(AOM_ask_value_tags(rev_tag, "IMAN_master_form_rev", &formnum, &tag_forms));
obj_tag = tag_forms[0];
//char *disname_char = NULL;
char* rev_str = NULL;
//char disname[128] = "";
char propval[128] = "";
//ITKCALL(PROP_ask_property_by_name(obj_tag, name, &prop_tag));
//ITKCALL(PROP_UIF_ask_name(prop_tag, &disname_char));
//ITKCALL(PROP_UIF_ask_value(prop_tag, &rev_str));
AOM_UIF_ask_value(obj_tag, name, &rev_str);
//strcpy(disname, disname_char);
strcpy(propval, rev_str);
vet_str.push_back(propval);
vet_dis_str.push_back(name);
DOFREE(rev_str);
//DOFREE(disname_char);
}
else if (strcmp(site, "BOM") == 0)
{
char* rev_str = NULL;
char disname[512] = "";
char propval[128] = "";
int bvr_count = 0;
tag_t ebom_window = NULLTAG;
tag_t *bvr_list = NULL, bom_line = NULLTAG;
ITKCALL(ITEM_rev_list_bom_view_revs(rev_tag, &bvr_count, &bvr_list));
if (bvr_count == 0)
{
printf("BOM没有视图----%s\n", obj_str);
continue;
}
ITKCALL(BOM_create_window(&ebom_window));
if (rev_rule_tag != NULLTAG)
ITKCALL(BOM_set_window_config_rule(ebom_window, rev_rule_tag));
ITKCALL(BOM_set_window_top_line_bvr(ebom_window, bvr_list[0], &bom_line));
int child_cnt = 0;
tag_t *child_lines = NULL;
ITKCALL(BOM_line_ask_child_lines(bom_line, &child_cnt, &child_lines));
if (child_cnt<1)
{
printf("BOM没有子件----%s\n", obj_str);
ITKCALL(BOM_close_window(ebom_window));
continue;
}
for (int t = 0; t < child_cnt; t++)
{
char *object_string = NULL;
ITKCALL(AOM_UIF_ask_value(child_lines[t], "bl_child_id", &object_string));
ITKCALL(AOM_UIF_ask_value(child_lines[t], name, &rev_str));
sprintf(disname, "子件%s属性%s", object_string, name);
strcpy(propval, rev_str);
vet_str.push_back(propval);
vet_dis_str.push_back(disname);
DOFREE(rev_str);
}
ITKCALL(BOM_close_window(ebom_window));
}
else
{
obj_tag = rev_tag;
//char *disname_char = NULL;
char* rev_str = NULL;
//char disname[128] = "";
char propval[128] = "";
//ITKCALL(PROP_ask_property_by_name(obj_tag, name, &prop_tag));
//ITKCALL(PROP_UIF_ask_name(prop_tag, &disname_char));
//ITKCALL(PROP_UIF_ask_value(prop_tag, &rev_str));
AOM_UIF_ask_value(obj_tag, name, &rev_str);
//strcpy(disname, disname_char);
strcpy(propval, rev_str);
vet_str.push_back(propval);
vet_dis_str.push_back(name);
DOFREE(rev_str);
//DOFREE(disname_char);
}
if (vet_str.size()>0)
{
for (int j = 0; j < vet_str.size(); j++)
{
string rev_str = vet_str[j];
string disname = vet_dis_str[j];
printf("开始判断属性值----%s\n", rev_str.c_str());
if (strcmp(isnull, "TRUE") == 0)
{
if (strcmp(rev_str.c_str(), "") == 0)
{
string errMsg;
errMsg.assign(obj_str).append("的属性").append(disname.c_str()).append("不允许为空,请检查!");
errMap.insert(pair<string, int>(errMsg, EMH_USER_error_base + 5));
continue;
}
}
if (strcmp(noequals, "") != 0)
{
if (strcmp(rev_str.c_str(), noequals) == 0)
{
string errMsg;
errMsg.assign(obj_str).append("的属性").append(disname.c_str()).append("不允许为").append(noequals).append(",请检查!");
errMap.insert(pair<string, int>(errMsg, EMH_USER_error_base + 5));
continue;
}
}
int decsize_num = -1;
int intsize_num = -1;
int size_num = -1;
boolean havenum_is = false;
boolean isneg_is = false;
boolean havedec_is = false;
boolean havelow_is = false;
boolean havecap_is = false;
if (strcmp(size, "") != 0)
{
size_num = atof(size);
}
if (strcmp(intsize, "") != 0)
{
intsize_num = atof(intsize);
}
if (strcmp(decsize, "") != 0)
{
decsize_num = atof(decsize);
}
if (strcmp(havenum, "TRUE") == 0)
{
havenum_is = true;
}
if (strcmp(isneg, "TRUE") == 0)
{
isneg_is = true;
}
if (strcmp(havedec, "TRUE") == 0)
{
havedec_is = true;
}
if (strcmp(havelow, "TRUE") == 0)
{
havelow_is = true;
}
if (strcmp(havecap, "TRUE") == 0)
{
havecap_is = true;
}
int errnum = checkstr(rev_str, havenum_is, isneg_is, havedec_is, havelow_is, havecap_is, decsize_num, intsize_num, size_num);
if (errnum == 1)
{
string errMsg;
errMsg.assign(obj_str).append("").append(disname.c_str()).append("不符合规则,请检查!");
errMap.insert(pair<string, int>(errMsg, EMH_USER_error_base + 5));
continue;
}
if (errnum == 2)
{
string errMsg;
errMsg.assign(obj_str).append("").append(disname.c_str()).append("长度不符,请检查!");
errMap.insert(pair<string, int>(errMsg, EMH_USER_error_base + 5));
continue;
}
if (havenum_is&&strcmp(greaterthan, "") != 0 && strcmp(rev_str.c_str(), "") != 0)
{
double greaterthan_dou = atof(greaterthan);
double rev_str_dou = atof(rev_str.c_str());
const double EPS = 1e-6;
if (greaterthan_dou > rev_str_dou + EPS)//浮点判断
{
string errMsg;
errMsg.assign(obj_str).append("").append(disname.c_str()).append("数值大小不符,请检查!");
errMap.insert(pair<string, int>(errMsg, EMH_USER_error_base + 5));
}
}
if (havenum_is&&strcmp(lessthan, "") != 0 && strcmp(rev_str.c_str(), "") != 0)
{
double lessthan_dou = atof(lessthan);
double rev_str_dou = atof(rev_str.c_str());
const double EPS = 1e-6;
if (rev_str_dou > lessthan_dou + EPS)//浮点判断
{
string errMsg;
errMsg.assign(obj_str).append("").append(disname.c_str()).append("数值大小不符,请检查!");
errMap.insert(pair<string, int>(errMsg, EMH_USER_error_base + 5));
}
}
}
}
}
}
}
if (errMap.size() > 0)
decision = EPM_nogo;
else
decision = EPM_go;
map<string, int>::iterator err_it;
for (err_it = errMap.begin(); err_it != errMap.end(); err_it++)
{
EMH_store_error_s1(EMH_severity_information, err_it->second, err_it->first.c_str());
}
errMap.clear();
auto stopTime = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stopTime - startTime);
//std::cout << "Judge_attribute用时:" << duration.count() / 1000 << std::endl;
string usetime = "Judge_attribute用时:";
usetime.append(std::to_string(duration.count() / 1000));
WriteLog(true, usetime.c_str());
printf("结束Judge_attribute\n");
return decision;
}