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.

243 lines
7.8 KiB

#include "HTTPRequest.hpp"
#include "epm_handler_common.h"
#include <tc\tc_macros.h>
#include <tc\emh.h>
#include <tc\preferences.h>
#include <property\propdesc.h>
#include <epm\epm.h>
#include <epm\epm_toolkit_tc_utils.h>
#include <tccore\item.h>
#include <tccore\grmtype.h>
#include <tccore\grm.h>
#include <tccore\imantype.h>
#include <sa\am.h>
#include <sa\sa.h>
#include <tccore\aom.h>
#include <tccore\aom_prop.h>
#include <property\prop_errors.h>
#include <tccore\workspaceobject.h>
#include <qry\qry.h>
#include <bom\bom_attr.h>
#include <bom\bom.h>
#include <epm\signoff.h>
#include <pom\pom\pom.h>
#include <pom\pom\pom_errors.h>
#include <fclasses\tc_date.h>
#include <epm\cr.h>
#include <cfm\cfm.h>
#include <sa\am.h>
#include "tc/envelope.h"
#include <stdio.h>
#include "ae/dataset.h"
#include <ctype.h>
#include <string.h>
#include <string>
#include <iostream>
#include <iterator>
#include <map>
#include <vector>
#include "ce/ce.h"
#include <time.h>
#include <windows.h>
#include <iostream>
#include <sql.h>
#include <sqlext.h>
#include "string"
#include "sstream"
#include <sa/tcfile.h>
#include <tccore/aom.h>
#include <sa/tcfile_cache.h>
#include <form/form.h>
#include "ctime"
#include "tchar.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
extern "C" int POM_AM__set_application_bypass(logical bypass);
string GBKToUTF8(const char* strGBK) {
int len = MultiByteToWideChar(CP_ACP, 0, strGBK, -1, NULL, 0);
wchar_t* wstr = new wchar_t[len + 1];
memset(wstr, 0, len + 1);
MultiByteToWideChar(CP_ACP, 0, strGBK, -1, wstr, len);
len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
char* str = new char[len + 1];
memset(str, 0, len + 1);
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);
string strTemp = str;
if (wstr) delete[] wstr;
if (str) delete[] str;
return strTemp;
}
string Utf8ToGbk(const char *src_str) {
int len = MultiByteToWideChar(CP_UTF8, 0, src_str, -1, NULL, 0);
wchar_t* wszGBK = new wchar_t[len + 1];
memset(wszGBK, 0, len * 2 + 2);
MultiByteToWideChar(CP_UTF8, 0, src_str, -1, wszGBK, len);
len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, NULL, 0, NULL, NULL);
char* szGBK = new char[len + 1];
memset(szGBK, 0, len + 1);
WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, szGBK, len, NULL, NULL);
string strTemp(szGBK);
if (wszGBK) delete[] wszGBK;
if (szGBK) delete[] szGBK;
return strTemp;
}
DWORD WINAPI sendRequest(void* para) {
try {
char *pref_values;
PREF_ask_char_value("jd2_server_ip", 0, &pref_values);
if (strlen(pref_values) != 0) {
stringstream ss;
ss << "http://";
ss << pref_values;
ss << ":8888/api/deleteJob?uid=";
ss << (char *)para;
printf("request url====>%s\n", ss.str().c_str());
http::Request request(ss.str().c_str());
const http::Response response = request.send("GET");
std::cout << std::string(response.body.begin(), response.body.end()) << '\n'; // print the result
}
} catch (const std::exception& e) {
std::cerr << "Request failed, error: " << e.what() << '\n';
}
return 0;
}
int jd_batch_process(EPM_action_message_t msg) {
POM_AM__set_application_bypass(true);
tag_t root_task, *attachments, process_template, new_process, job, *do_tasks, *signoff_tasks, *valids;
int att_count = 0, type = EPM_target_attachment, do_cnt, signoff_cnt, valid_cnt;
char *att_name, *process_name, *temp_str, **names, *uid;
map<string, tag_t> do_designee;
map<string, vector<tag_t>> signoff_designee;
ITEM_attached_object_t *rev_attachments;
stringstream ss;
EPM_ask_root_task(msg.task, &root_task);
EPM_ask_job(msg.task, &job);
EPM_ask_attachments(root_task, EPM_target_attachment, &att_count, &attachments);
if (att_count > 1) {
EPM_get_type_tasks(job, eEPMDoTask, &do_cnt, &do_tasks);
EPM_get_type_tasks(job, eEPMSelectSignoffTask, &signoff_cnt, &signoff_tasks);
printf("do task size====>%d\n", do_cnt);
printf("signoff task size====>%d\n", signoff_cnt);
for (int i = 0;i < do_cnt;i++) {
char *task_name, *designee_name;
tag_t designee;
string temp;
EPM_ask_name2(do_tasks[i], &task_name);
temp = Utf8ToGbk(task_name);
printf("do task name====>%s\n", temp);
AOM_ask_value_tag(do_tasks[i], "fnd0Assignee", &designee);
if (designee != NULLTAG) {
ss << temp;
ss << i;
AOM_ask_value_string(designee, "user_name", &designee_name);
temp = Utf8ToGbk(designee_name);
printf("do designee name====>%s\n", temp);
do_designee[ss.str()] = designee;
ss.str("");
}
}
for (int i = 0;i < signoff_cnt;i++) {
char *task_name, *designee_name;
tag_t parent, designee_tag;
string temp;
vector<tag_t> designee;
EPM_ask_parent_task(signoff_tasks[i], &parent);
EPM_ask_name2(parent, &task_name);
temp = Utf8ToGbk(task_name);
printf("signoff task name====>%s\n", temp);
AOM_ask_value_tags(parent, "valid_signoffs", &valid_cnt, &valids);
for (int ii = 0;ii < valid_cnt;ii++) {
AOM_ask_value_tag(valids[ii], "fnd0Assignee", &designee_tag);
AOM_ask_value_string(designee_tag, "user_name", &designee_name);
temp = Utf8ToGbk(designee_name);
printf("signoff designee name====>%s\n", temp);
designee.push_back(designee_tag);
}
if (designee.size() != 0) {
ss << Utf8ToGbk(task_name);
ss << i;
signoff_designee[ss.str()] = designee;
ss.str("");
}
}
for (int i = 0;i < att_count;i++) {
AOM_ask_value_string(attachments[i], "object_string", &att_name);
printf("object_string====>%s\n", att_name);
AOM_ask_value_tag(job, "process_template", &process_template);
AOM_ask_value_string(process_template, "object_name", &temp_str);
printf("temp_str====>%s\n", Utf8ToGbk(temp_str).c_str());
EPM_create_process(att_name, "", process_template, 1, &attachments[i], &type, &new_process);
char *temp;
AOM_ask_value_string(new_process, "object_type", &temp);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>===>%s\n", Utf8ToGbk(temp).c_str());
tag_t new_root_task, new_job, *new_do_tasks, *new_signoff_tasks;
int new_do_cnt, new_signoff_cnt;
EPM_ask_root_task(new_process, &new_root_task);
EPM_ask_job(new_root_task, &new_job);
EPM_get_type_tasks(new_job, eEPMDoTask, &new_do_cnt, &new_do_tasks);
EPM_get_type_tasks(new_job, eEPMSelectSignoffTask, &new_signoff_cnt, &new_signoff_tasks);
for (int ii = 0;ii < new_do_cnt;ii++) {
char *new_task_name;
string temp;
EPM_ask_name2(new_do_tasks[ii], &new_task_name);
temp = Utf8ToGbk(new_task_name);
printf("new do task name======>%s\n", temp);
ss << temp;
ss << ii;
if (do_designee.find(ss.str()) != do_designee.end()) {
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\"%s\"<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>\n", temp);
EPM_assign_responsible_party(new_do_tasks[ii], do_designee[ss.str()]);
}
ss.str("");
}
for (int ii = 0;ii < new_signoff_cnt;ii++) {
char *new_task_name;
string temp;
tag_t parent, member;
int temp_cnt, mem_cnt;
tag_t *temp_signoffs;
EPM_ask_parent_task(new_signoff_tasks[ii], &parent);
EPM_ask_name2(parent, &new_task_name);
temp = Utf8ToGbk(new_task_name);
printf("new signoff task name====>%s\n", temp);
ss << temp;
ss << ii;
if (signoff_designee.find(ss.str()) != signoff_designee.end()) {
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\"%s\"<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>\n", temp);
int user_cnt = signoff_designee[ss.str()].size();
for (int iii = 0;iii < user_cnt;iii++) {
SA_find_groupmember_by_user(signoff_designee[ss.str()][iii], &mem_cnt, &temp_signoffs);
EPM_create_adhoc_signoff(new_signoff_tasks[ii], temp_signoffs[0], &temp_cnt, &temp_signoffs);
if (temp_cnt) {
MEM_free(temp_signoffs);
}
}
EPM_set_adhoc_signoff_selection_done(new_signoff_tasks[ii], true);
}
ss.str("");
}
}
ITK__convert_tag_to_uid(job, &uid);
printf("delete job_uid======>%s\n", uid);
HANDLE hHandle;
hHandle = CreateThread(NULL, 0, sendRequest, uid, 0, NULL);
CloseHandle(hHandle);
return 0;
}
POM_AM__set_application_bypass(false);
return 0;
}