|
|
#include"kutil.h"
|
|
|
#include "ado.h"
|
|
|
#define debug true
|
|
|
#define ITK_err 919012
|
|
|
#include <string>
|
|
|
#include <vector>
|
|
|
#include <map>
|
|
|
#include <sstream>
|
|
|
#include <cstring>
|
|
|
#include <iostream>
|
|
|
#define debug true
|
|
|
#define ITK_err 919012
|
|
|
|
|
|
bool inArrays(const std::vector<std::string>& vec, const std::string& value) {
|
|
|
for (const auto& item : vec) {
|
|
|
if (item == value) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
void getVector(const char* value, std::vector<std::string>& targetVector, char delimiter) {
|
|
|
std::string strValue(value);
|
|
|
std::stringstream ss(strValue);
|
|
|
std::string item;
|
|
|
|
|
|
// 尝试用指定的分隔符分割字符串
|
|
|
if (std::getline(ss, item, delimiter)) {
|
|
|
// 如果能成功分割,则继续分割剩余部分
|
|
|
targetVector.push_back(item);
|
|
|
while (std::getline(ss, item, delimiter)) {
|
|
|
targetVector.push_back(item);
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
// 如果不能分割,则将整个字符串添加到vector中
|
|
|
targetVector.push_back(strValue);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void setProcessPointUser(std::string uerID) {
|
|
|
|
|
|
tag_t subtask; //流程节点
|
|
|
string id;//用户id
|
|
|
|
|
|
POM_AM__set_application_bypass(true);
|
|
|
tag_t tmp_select_signoff_task = NULLTAG;
|
|
|
ITKCALL(EPM_ask_sub_task(subtask, EPM_select_signoff_team_task, &tmp_select_signoff_task));
|
|
|
|
|
|
tag_t user;
|
|
|
ITKCALL(SA_find_user2(uerID.c_str(), &user));
|
|
|
|
|
|
int signoff_cnt = 0;
|
|
|
tag_t* signoffs = NULL;
|
|
|
|
|
|
tag_t member = NULL;
|
|
|
SIGNOFF_TYPE_t type;
|
|
|
ITKCALL(EPM_ask_signoff_member(tmp_select_signoff_task, &member, &type));
|
|
|
ITKCALL(EPM_remove_signoffs(tmp_select_signoff_task, 1, &member));
|
|
|
|
|
|
ITKCALL(EPM_create_adhoc_signoff(tmp_select_signoff_task, user, &signoff_cnt, &signoffs));
|
|
|
ITKCALL(EPM_set_adhoc_signoff_selection_done(tmp_select_signoff_task, true));
|
|
|
|
|
|
if (signoffs)
|
|
|
{
|
|
|
MEM_free(signoffs);
|
|
|
signoffs = NULL;
|
|
|
}
|
|
|
POM_AM__set_application_bypass(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
int Connor_ChangeItemNotify_AssignUser(EPM_action_message_t msg) {
|
|
|
printf("=========================流程启动时根据属性值和配置转义为TC人员到流程节点上 Start===================\n");
|
|
|
int ifail = ITK_ok;
|
|
|
int attachments_num = 0;
|
|
|
|
|
|
|
|
|
char* argName = NULL, * argValue = NULL, * arg = NULL;
|
|
|
char objTypes[1024] = "", props[1024] = "";
|
|
|
bool isExistRev = false;
|
|
|
int arg_cnt = TC_number_of_arguments(msg.arguments);
|
|
|
printf("参数个数为:%d\n", arg_cnt);
|
|
|
|
|
|
if (arg_cnt > 0)
|
|
|
{
|
|
|
for (int i = 0; i < arg_cnt; i++)
|
|
|
{
|
|
|
arg = TC_next_argument(msg.arguments);
|
|
|
ifail = ITK_ask_argument_named_value((const char*)arg, &argName, &argValue);
|
|
|
if (strcmp(argName, "objecttype") == 0)
|
|
|
{
|
|
|
if (argValue != NULL)
|
|
|
{
|
|
|
strcpy(objTypes, argValue);
|
|
|
}
|
|
|
}
|
|
|
else if (stricmp(argName, "property") == 0)
|
|
|
{
|
|
|
if (argValue != NULL)
|
|
|
{
|
|
|
strcpy(props, argValue);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
MEM_free(argName);
|
|
|
MEM_free(argValue);
|
|
|
std::vector<std::string> typeVector, propVector;
|
|
|
getVector(objTypes, typeVector, ';');
|
|
|
getVector(props, propVector, ';');
|
|
|
|
|
|
vector<string> values;
|
|
|
getPrefStrings("Connor_ChangeItemNotify_AssignUser", TC_preference_site, values);
|
|
|
|
|
|
printf("解析 values 数组中的字符串");
|
|
|
// 解析 values 数组中的字符串
|
|
|
std::map<std::string, std::map<std::string, std::string>> objectVersionTypeMap;
|
|
|
for (const auto& value : values) {
|
|
|
std::stringstream ss(value);
|
|
|
std::string objectVersionType, userAssignments;
|
|
|
|
|
|
// 分割 objectVersionType 和 userAssignments
|
|
|
if (std::getline(ss, objectVersionType, '|') && std::getline(ss, userAssignments)) {
|
|
|
std::map<std::string, std::string> userMap;
|
|
|
std::stringstream userSS(userAssignments);
|
|
|
std::string userAssignment;
|
|
|
|
|
|
// 解析每个 userAssignment
|
|
|
while (std::getline(userSS, userAssignment, ';')) {
|
|
|
std::stringstream userAssignmentSS(userAssignment);
|
|
|
std::string userName, tcUserId;
|
|
|
|
|
|
// 分割 userName 和 tcUserId
|
|
|
if (std::getline(userAssignmentSS, userName, '=') && std::getline(userAssignmentSS, tcUserId)) {
|
|
|
userMap[userName] = tcUserId; // 选择最后一个 tcUserId 作为最终的值
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 存储解析结果
|
|
|
objectVersionTypeMap[objectVersionType] = userMap;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
tag_t attachmentTag = NULLTAG;
|
|
|
int attachmentCount = 0;
|
|
|
tag_t rootTask = NULLTAG, * attachmentTags = NULLTAG;
|
|
|
ITKCALL(ifail = EPM_ask_root_task(msg.task, &rootTask));
|
|
|
ITKCALL(ifail = EPM_ask_attachments(rootTask, EPM_target_attachment, &attachmentCount, &attachmentTags));
|
|
|
//遍历所有的流程目标下的对象
|
|
|
char* itemType = NULL;
|
|
|
for (int i = 0; i < attachmentCount; i++) {
|
|
|
attachmentTag = attachmentTags[i];
|
|
|
|
|
|
ITKCALL(ifail = AOM_ask_value_string(attachmentTag, "object_type", &itemType));
|
|
|
if (inArrays(typeVector, itemType)) {
|
|
|
ITKCALL(ifail = AOM_lock(attachmentTag));
|
|
|
//ITKCALL(ifail = AOM_set_value_string(attachmentTag, targetPropertyName, &propertyValue));
|
|
|
std::map<std::string, std::string> valueMap;
|
|
|
char* tempValue = NULL;
|
|
|
for (const auto& prop : propVector) {
|
|
|
ITKCALL(ifail = AOM_ask_value_string(attachmentTag, prop.c_str(), &tempValue));
|
|
|
if (tempValue != NULL) {
|
|
|
valueMap[prop] = tempValue;
|
|
|
}
|
|
|
else {
|
|
|
valueMap[prop] = "";
|
|
|
}
|
|
|
}
|
|
|
MEM_free(tempValue);
|
|
|
|
|
|
std::string userID = "";
|
|
|
if (objectVersionTypeMap.find(itemType) != objectVersionTypeMap.end()) {
|
|
|
std::map<std::string, std::string> userMap = objectVersionTypeMap[itemType];
|
|
|
|
|
|
// 循环遍历 valueMap
|
|
|
for (auto it = valueMap.begin(); it != valueMap.end(); ++it) {
|
|
|
printf("Key: %s, Value: %s\n", it->first.c_str(), it->second.c_str());
|
|
|
|
|
|
if (userMap.find(it->second) != userMap.end()) {
|
|
|
userID = userMap[it->second];
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
printf("没有在首选项中找到该类型");
|
|
|
}
|
|
|
|
|
|
if (userID.empty()) {
|
|
|
printf("userID is null !");
|
|
|
}
|
|
|
else {
|
|
|
//setProcessPointUser(userID);
|
|
|
POM_AM__set_application_bypass(true);
|
|
|
int mem_cnt = 0, signoff_cnt = 0, signmem_count = 0, * attach_type;
|
|
|
tag_t user_tag = NULLTAG, login_group = NULLTAG, * members = NULLTAG, * signoffs = NULLTAG, select_signoff_tag = NULLTAG, * attachmentTags = NULLTAG;
|
|
|
EPM_ask_sub_task(msg.task, "select-signoff-team", &select_signoff_tag);
|
|
|
//EPM_ask_sub_task(task_tags[i], "select-signoff-team", &cur_perform_task);
|
|
|
EPM_ask_all_attachments(select_signoff_tag, &signmem_count, &attachmentTags, &attach_type);
|
|
|
if (signmem_count == 0) {
|
|
|
ITKCALL(SA_find_user2(userID.c_str(), &user_tag));
|
|
|
if (user_tag != NULLTAG) {
|
|
|
ITKCALL(SA_ask_user_login_group(user_tag, &login_group));
|
|
|
ITKCALL(SA_find_groupmembers(user_tag, login_group, &mem_cnt, &members));
|
|
|
ITKCALL(EPM_create_adhoc_signoff(select_signoff_tag, members[0], &signoff_cnt, &signoffs));
|
|
|
ITKCALL(EPM_set_adhoc_signoff_selection_done(select_signoff_tag, true));
|
|
|
printf("分配成功");
|
|
|
}
|
|
|
else {
|
|
|
ITKCALL(EPM_promote_task(msg.task, ""));
|
|
|
}
|
|
|
}
|
|
|
POM_AM__set_application_bypass(false);
|
|
|
DOFREE(members);
|
|
|
DOFREE(signoffs);
|
|
|
|
|
|
}
|
|
|
|
|
|
ITKCALL(ifail = AOM_unlock(attachmentTag));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
MEM_free(attachmentTags);
|
|
|
MEM_free(itemType);
|
|
|
} |