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.

475 lines
12 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
#define EPM_HANDLER_COMMON
#include <tccore/item.h>
#include <tccore/grmtype.h>
#include <tccore/grm.h>
#include <sa/am.h>
#include <tccore/aom.h>
#include <tccore/aom_prop.h>
#include <property/prop_errors.h>
#include <lov/lov_errors.h>
#include <lov/lov.h>
#include <tccore/tctype.h>
#include <res/res_itk.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <string>
#include <vector>
#include <map>
#include <fstream>
#include"kutil.h"
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include "libxl.h"
#include <io.h>
#include <direct.h>
#include <cfm/cfm.h>
#include <wchar.h>
#include <locale>
#include <codecvt>
#include <chrono>
#include <Windows.h>
#include <thread>
#include <regex>
#include <res\reservation.h>
#include "libxl.h"
#include <map>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <filesystem>
#include <sys/stat.h>
#include <iostream>
#include "ado.h"
#include <chrono>
#include <bom/bom.h>
boolean IsRelease(tag_t topLine, char resultString[], vector<char*> referenceValues, char releaseStatus[1024]);
#define DOFREE(obj);
#define MAX_PATH_LENGTH 200
#define MAX_PRINTLINE_LENGTH 400000
std::vector<std::string> split(const std::string& str, const std::string& pattern)
{
std::vector<std::string> resVec;
if ("" == str)
{
return resVec;
}
//·½±ã½ØÈ¡×îºóÒ»¶ÎÊý¾Ý
std::string strs = str + pattern;
size_t pos = strs.find(pattern);
size_t size = strs.size();
while (pos != std::string::npos)
{
std::string x = strs.substr(0, pos);
resVec.push_back(x);
strs = strs.substr(pos + pattern.size(), size);
pos = strs.find(pattern);
}
return resVec;
};
bool count(vector<char*> values, char* value)
{
for (auto referencedValue : values) {
if (strcmp(referencedValue, value) == 0)
{
return true;
}
}
return false;
}
void split(char* src, const char* separator, char** dest, int* num) {
vector<std::string> resultVector = split(src, separator);
int count = 0;
for (auto result : resultVector) {
int nLen = strlen(result.c_str());
char* pCh = new char[nLen + 1];
strcpy(pCh, result.c_str());
dest[count] = pCh;
++count;
}
*num = count;
}
int XY_ChildIsRelease(EPM_action_message_t msg) {
printf("=========================ÅжÏ×Ó¼þÊÇ·ñÈ«²¿·¢²¼ Start===================\n");
auto startTime = std::chrono::high_resolution_clock::now();
//POM_AM__set_application_bypass(true);
int ifail = ITK_ok;
int attachments_num = 0;
tag_t rootTask = NULLTAG, * attachments = NULLTAG, user_tag = NULLTAG;
//»ñÈ¡ÈÎÎñ¶ÔÏó
EPM_ask_root_task(msg.task, &rootTask);
//»ñÈ¡ÈÎÎñÄ¿±ê¶ÔÏó
EPM_ask_attachments(rootTask, EPM_target_attachment, &attachments_num, &attachments);
//»ñÈ¡²ÎÊý
char* argflag = NULL, * argvalue = NULL, * arg = NULL, * user_name = NULL;
char releaseStatus[1024] = "", arg1value[1024] = "", atgltype[1024] = "", atglRev[1024] = "";
bool isExistRev = false;
int arg_cnt = TC_number_of_arguments(msg.arguments);
printf("²ÎÊý¸öÊýΪ£º%d\n", arg_cnt);
ITKCALL(POM_get_user(&user_name, &user_tag));
if (arg_cnt > 0)
{
for (int i = 0; i < arg_cnt; i++)
{
//»ñÈ¡ÏÂÒ»¸ö²ÎÊý£¨´Ó0¿ªÊ¼£©
arg = TC_next_argument(msg.arguments);
//»ñÈ¡²ÎÊýµÄÃû³ÆºÍÖµ
ifail = ITK_ask_argument_named_value((const char*)arg, &argflag, &argvalue);
if (stricmp(argflag, "releaseStatus") == 0)
{
if (argvalue != NULL)
{
strcpy(releaseStatus, argvalue);
}
}
else if (stricmp(argflag, "itemType") == 0)
{
//strcmp("","");
if (argvalue != NULL)
{
strcpy(arg1value, argvalue);
}
}
else if (stricmp(argflag, "itemChildType") == 0) {
if (argvalue != NULL)
{
strcpy(atgltype, argvalue);
}
}
else if (stricmp(argflag, "itemChildRev") == 0) {
if (argvalue != NULL)
{
strcpy(atglRev, argvalue);
}
}
}
// ÅжÏÌõ¼þ
if (strlen(atglRev) > 0) {
printf("atglRev ²»Îª¿Õ\n");
isExistRev = true;
}
else {
printf("atglRev Ϊ¿Õ\n");
}
}
vector<char*> childTypeCheakValues;
if (strstr(atgltype, ",") != NULL)
{
int vectorValueCount = 0;
char** vectorValueChar = new char* [64];
split(atgltype, ",", vectorValueChar, &vectorValueCount);
for (int i = 0; i < vectorValueCount; i++)
{
childTypeCheakValues.push_back(vectorValueChar[i]);
}
}
else
{
childTypeCheakValues.push_back(atgltype);
}
vector<char*> itemTypeValues;
if (strstr(arg1value, ",") != NULL)
{
int vectorValueCount = 0;
char** vectorValueChar = new char* [64];
split(arg1value, ",", vectorValueChar, &vectorValueCount);
for (int i = 0; i < vectorValueCount; i++)
{
itemTypeValues.push_back(vectorValueChar[i]);
}
}
else
{
itemTypeValues.push_back(arg1value);
}
// -referenceValues ==> ÐèÒª±È¶ÔµÄ·¢²¼×´Ì¬£»(¶àֵʱʹÓÃÓ¢ÎÄ,¶ººÅ·Ö¸î)
vector<char*> referenceValues;
if (strstr(releaseStatus, ",") != NULL)
{
int vectorValueCount = 0;
char** vectorValueChar = new char* [64];
split(releaseStatus, ",", vectorValueChar, &vectorValueCount);
for (int i = 0; i < vectorValueCount; i++)
{
referenceValues.push_back(vectorValueChar[i]);
}
}
else
{
referenceValues.push_back(releaseStatus);
}
// -attrName ==> Á÷³ÌÈÎÎñÄ¿±êϵĶÔÏóid
vector<char*> attrName;
char* itemId = NULL;
char* itemType = NULL;
for (int i = 0; i < attachments_num; i++) {
AOM_ask_value_string(attachments[i], "object_type", &itemType);
if (isTypeOf(attachments[i], "ItemRevision")) {
AOM_ask_value_string(attachments[i], "item_id", &itemId);
attrName.push_back(itemId);
}
}
DOFREE(itemId);
DOFREE(itemType);
char resultString[1024] = "";
for (int i = 0; i < attachments_num; i++)
{
char* itemType = NULL;
AOM_ask_value_string(attachments[i], "object_type", &itemType);
printf("type_class : %s \r\n", itemType);
//¹ýÂ˵ô·ÇÎļþ¼ÐµÄ¶ÔÏó
if (!count(itemTypeValues, itemType))
{
DOFREE(itemType);
continue;
}
int viewNum = 0;
tag_t* viewTag = NULL_TAG;
//ÅжÏÊÇ·ñ°üº¬BOMÊÓͼ
/*ITKCALL(AOM_ask_value_tags(attachments[i], "structure_revisions", &viewNum, &viewTag));
if (viewNum <= 0)
{
DOFREE(itemType);
DOFREE(viewTag);
continue;
}*/
//´´½¨BOMWindow
tag_t top_line = NULLTAG, window = NULLTAG;
printf("´´½¨BOMWindow\n");
ITKCALL(BOM_create_window(&window));
//ÉèÖö¥²ãBOM
printf("ÉèÖö¥²ãBOM\n");
ITKCALL(BOM_set_window_top_line(window, NULLTAG, attachments[i], NULLTAG, &top_line));
int count1;
tag_t* children_line = NULLTAG;
printf("»ñÈ¡×ÓÁÐBOM\n");
ITKCALL(BOM_line_ask_all_child_lines(top_line, &count1, &children_line));
for (int j = 0; j < count1; j++)
{
tag_t revisions = NULLTAG;
logical hasPrivilege = false;
char* item_id = NULL;
char* item_rev = NULL;
//Åжϵ±Ç°Óû§ÊÇ·ñÓÐȨÏÞ
printf("»ñÈ¡×ÓÁжÔÓ¦µÄ°æ±¾\n");
ITKCALL(AOM_ask_value_tag(children_line[j], "bl_line_object", &revisions));
//ÅжÏÊÇ·ñÔÚÄ¿±ê¹ØÏµÏ ==> ÔÚÄ¿±ê¹ØÏµÏ¾ͿÉÒÔ·ûºÏ ==> Ϊtrue
char* objectString = NULL;
bool ifaaf = false;
AOM_ask_value_string(revisions, "item_id", &objectString);
AOM_ask_value_string(revisions, "item_revision_id", &item_rev);
for (int a = 0; a < attrName.size();a++) {
char* name = attrName[a];
if (strcmp(name, objectString)==0) {
ifaaf = true;
}
}
//ÅжÏÊÇ·ñ·ûºÏ°æ±¾
if (isExistRev && strcmp(atglRev, item_rev) != 0) {
continue;
}
//ÅжÏÊÇ·ñ·ûºÏÌõ¼þ
char* childType = NULL;
AOM_ask_value_string(revisions, "object_type", &childType);
if (ifaaf || !count(childTypeCheakValues,childType)) {
continue;//´æÔÚÄ¿±êÖлòÕß²»´æÔÚÓÚchildType¼ì²éÀàÐÍ·¶Î§ÄÚÔò²»ÅжÏ
}
//ITKCALL(AM_check_users_privilege(user_tag, children_line[j], "READ", &hasPrivilege));
ITKCALL(AOM_ask_value_string(revisions, "item_id", &item_id));
printf("item_id=%s", item_id);
printf("»ñÈ¡µ±Ç°¶ÔÏó¶ÔÓÚ°æ±¾µÄ¶ÁȨÏÞ\n");
ITKCALL(AM_check_users_privilege(user_tag, revisions, "READ", &hasPrivilege));
printf("user_name=%s,hasPrivilege=%d\n", user_name, hasPrivilege);
if (!hasPrivilege)
{
char* item_id = NULL;
POM_AM__set_application_bypass(true);
ITKCALL(AOM_ask_value_string(revisions, "item_id", &item_id));
strcat(resultString, item_id);
strcat(resultString, "ûÓÐȨÏÞ£¡\n");
POM_AM__set_application_bypass(false);
DOFREE(item_id);
ifail = 1;
continue;
}
//AOM_ask_value_tag(children_line[j], "bl_line_object", &revisions);
tag_t item = NULLTAG;
ITEM_ask_item_of_rev(revisions, &item);
ITEM_ask_latest_rev(item, &revisions);
/*char* revisionId = NULL;
AOM_ask_value_string(revisions, "item_revision_id", &revisionId);
if (strcmp(revisionId, "A") != 0)
{
DOFREE(revisionId);
continue;
}*/
char* releaseString = NULL;
//ÅжÏ×Ó¼þÊÇ·ñ·¢²¼
AOM_ask_value_string(children_line[j], "bl_rev_release_status_list", &releaseString);
char* itemString = NULL;
AOM_ask_value_string(children_line[j], "bl_rev_object_string", &itemString);
printf("·¢²¼×´Ì¬%s====================\n", releaseString);
if (releaseString == NULL || strcmp(releaseString, "") == 0)
{
strcat(resultString, itemString);
strcat(resultString, "\n");
ifail = 1;
}
else
{
bool isHave = false;
for (auto referencedValue : referenceValues) {
if (strstr(releaseString, referencedValue) != NULL)
{
isHave = true;
break;
}
}
if (!isHave)
{
strcat(resultString, itemString);
strcat(resultString, "·¢²¼×´Ì¬²»Îª");
strcat(resultString, releaseStatus);
strcat(resultString, "\n");
ifail = 1;
}
}
/*if (!IsRelease(children_line[j], resultString, referenceValues, releaseStatus))
{
ifail = 1;
}*/
DOFREE(releaseString);
DOFREE(itemString);
DOFREE(item_id);
DOFREE(item_rev);
}
BOM_close_window(window);
DOFREE(itemType);
DOFREE(children_line);
}
DOFREE(attachments);
DOFREE(user_name);
if (ifail == 1)
{
strcat(resultString, "δ·¢²¼£¡");
EMH_store_error_s1(EMH_severity_user_error, EMH_USER_error_base, resultString);
}
auto stopTime = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stopTime - startTime);
//std::cout << "XY_ChildIsReleaseÓÃʱ:" << duration.count() / 1000 << std::endl;
string usetime = "XY_ChildIsReleaseÓÃʱ:";
usetime.append(std::to_string(duration.count() / 1000));
WriteLog(true, usetime.c_str());
printf("=========================ÅжÏ×Ó¼þÊÇ·ñÈ«²¿·¢²¼ End====================\n");
return ifail;
}
boolean IsRelease(tag_t topLine, char resultString[], vector<char*> referenceValues, char releaseStatus[1024])
{
bool reault = true;
int count;
tag_t* children_line = NULLTAG;
BOM_line_ask_all_child_lines(topLine, &count, &children_line);
for (int i = 0; i < count; i++)
{
char* releaseString = NULL;
//ÅжÏ×Ó¼þÊÇ·ñ·¢²¼
AOM_ask_value_string(children_line[i], "bl_rev_release_status_list", &releaseString);
char* itemString = NULL;
AOM_ask_value_string(children_line[i], "bl_rev_object_string", &itemString);
printf("·¢²¼×´Ì¬%s====================\n", releaseString);
if (releaseString == NULL || strcmp(releaseString, "") == 0)
{
strcat(resultString, itemString);
strcat(resultString, "\n");
reault = false;
}
else
{
bool isHave = false;
for (auto referencedValue : referenceValues) {
if (strstr(releaseString, referencedValue) != NULL)
{
isHave = true;
break;
}
}
if (!isHave)
{
strcat(resultString, itemString);
strcat(resultString, "·¢²¼×´Ì¬²»Îª");
strcat(resultString, releaseStatus);
strcat(resultString, "\n");
reault = false;
}
}
if (!IsRelease(children_line[i], resultString, referenceValues, releaseStatus))
{
reault = false;
}
DOFREE(releaseString);
DOFREE(itemString);
}
DOFREE(children_line);
//POM_AM__set_application_bypass(false);
return reault;
}