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.
186 lines
7.4 KiB
186 lines
7.4 KiB
#include "CSendMail.h"
|
|
#include "boost\algorithm\\string.hpp"
|
|
#include "util.h"
|
|
|
|
int jd_send_mail2(EPM_action_message_t msg) {
|
|
POM_AM__set_application_bypass(true);
|
|
tag_t root_task, *attachments;
|
|
int att_cnt;
|
|
EPM_ask_root_task(msg.task, &root_task);
|
|
EPM_ask_attachments(root_task, EPM_target_attachment, &att_cnt, &attachments);
|
|
TC_argument_list_t *arguments = msg.arguments;
|
|
int arg_cnt = TC_number_of_arguments(arguments);
|
|
map<string, string> paras;
|
|
for (auto i = 0; i < arg_cnt; i++) {
|
|
char *temp_key, *temp_val;
|
|
ITKCALL(ITK_ask_argument_named_value(TC_next_argument(arguments), &temp_key, &temp_val));
|
|
paras[temp_key] = temp_val;
|
|
}
|
|
tag_t parent_task, *signoffs;
|
|
vector<string> mail_address;
|
|
int signoff_cnt;
|
|
ITKCALL(EPM_ask_parent_task(msg.task, &parent_task));
|
|
ITKCALL(AOM_ask_value_tags(parent_task, "valid_signoffs", &signoff_cnt, &signoffs));
|
|
for (int i = 0; i < signoff_cnt; i++) {
|
|
tag_t user, person;
|
|
char *address;
|
|
AOM_ask_value_tag(signoffs[i], "fnd0Assignee", &user);
|
|
ITKCALL(SA_ask_user_person(user, &person));
|
|
ITKCALL(AOM_ask_value_string(person, "PA9", &address));
|
|
mail_address.push_back(address);
|
|
}
|
|
char *target_str;
|
|
//PREF_refresh("jd2_task_target2");
|
|
//PREF_ask_char_value("jd2_task_target2", 0, &target_str);
|
|
//ITKCALL(AOM_refresh(root_task, false));
|
|
ITKCALL(AOM_ask_value_string(root_task, "object_desc", &target_str));
|
|
//for (int i = 0; i < att_cnt; i++) {
|
|
// char *item_id, *item_revision_id;
|
|
// if (isTypeOf(attachments[i], "ItemRevision")) {
|
|
// ITK__convert_tag_to_uid(attachments[i], &target_str);
|
|
// break;
|
|
// }
|
|
//}
|
|
//vector<string> target_vec;
|
|
//ifstream in;
|
|
//stringstream file_location;
|
|
//file_location << getenv("temp");
|
|
//file_location << "\\";
|
|
//file_location << "jd2_task_target2.txt";
|
|
//in.open(file_location.str().c_str(), ios::in);
|
|
//in >> target_str;
|
|
//in.close();
|
|
printf("target_str====>%s\n", target_str);
|
|
if (tc_strlen(target_str) == 0) {
|
|
return EMH_store_error_s1(EMH_severity_error, EMH_AE_error_base, string("»ñÈ¡targetÄÚÈÝÒì³£,Çë¼ì²éhandler:jd_get_target2ÊÇ·ñÅäÖÃ").c_str());;
|
|
}
|
|
//remove(file_location.str().c_str());
|
|
//char **p = (char **)malloc(sizeof(char *));
|
|
//p[0] = (char *)malloc(sizeof(char) * 10);
|
|
//p[0] = "";
|
|
//ITKCALL(PREF_set_char_values("jd2_task_target2", 1, p));
|
|
//free(p);
|
|
vector<string> relations;
|
|
vector<string> file_types;
|
|
tag_t target = NULLTAG, excelx_tag, excel_tag, word_tag, wordx_tag, ppt_tag, pptx_tag;
|
|
vector<string> file_address;
|
|
map<string, vector<string>> pref_map;
|
|
char **pref_temp;
|
|
int pref_cnt;
|
|
PREF_ask_char_values("connor_default_dataset", &pref_cnt, &pref_temp);
|
|
for (int i = 0; i < pref_cnt; i++) {
|
|
string temp1 = string(pref_temp[i]).substr(0, string(pref_temp[i]).find_first_of("="));
|
|
string temp2 = string(pref_temp[i]).substr(string(pref_temp[i]).find_first_of("=") + 1);
|
|
vector<string> temp_vec;
|
|
split(temp2, ",", &temp_vec);
|
|
pref_map[temp1] = temp_vec;
|
|
}
|
|
//TCTYPE_find_type("MSExcel", "Dataset", &excel_tag);
|
|
//TCTYPE_find_type("MSExcelX", "Dataset", &excelx_tag);
|
|
//TCTYPE_find_type("MSWord", "Dataset", &word_tag);
|
|
//TCTYPE_find_type("MSWordX", "Dataset", &wordx_tag);
|
|
//TCTYPE_find_type("MSPowerPoint", "Dataset", &ppt_tag);
|
|
//TCTYPE_find_type("MSPowerPointX", "Dataset", &pptx_tag);
|
|
ITK__convert_uid_to_tag(target_str, &target);
|
|
if (target == NULLTAG) {
|
|
EMH_store_error_s1(EMH_severity_error, EMH_ATTR_error_base, "»ñȡѡÖÐÄ¿±êʧ°Ü£¬¼ì²éÊÇ·ñÅäÖÃÁËjd_get_target2");
|
|
return 1;
|
|
}
|
|
else {
|
|
char *item_id;
|
|
AOM_ask_value_string(target, "item_id", &item_id);
|
|
cout << "item_id:" << item_id << endl;
|
|
}
|
|
split(paras["relation"], ",", &relations);
|
|
split(paras["suffix"], ",", &file_types);
|
|
for (int i = 0; i < relations.size(); i++) {
|
|
tag_t *dataset;
|
|
int dataset_cnt;
|
|
cout << relations[i].c_str() << endl;
|
|
AOM_ask_value_tags(target, relations[i].c_str(), &dataset_cnt, &dataset);
|
|
for (int ii = 0; ii < dataset_cnt; ii++) {
|
|
string temp = getenv("temp");
|
|
tag_t type;
|
|
char *file_name;
|
|
ITKCALL(AOM_UIF_ask_value(dataset[ii], "object_name", &file_name));
|
|
cout << "dataset file name:" << file_name << endl;
|
|
string suffix = string(file_name).substr(string(file_name).find_last_of(".") + 1);
|
|
//ITKCALL(TCTYPE_ask_object_type(dataset[ii], &type));
|
|
if (find(file_types.begin(), file_types.end(), suffix) != file_types.end() && pref_map.find(suffix) != pref_map.end()) {
|
|
temp.append("\\").append(file_name).c_str();
|
|
if (ACCESS(temp.c_str(), 0) == 0) {
|
|
cout << "delete exist file" << endl;
|
|
remove(temp.c_str());
|
|
}
|
|
ITKCALL(AE_export_named_ref(dataset[ii], pref_map[suffix][1].c_str(), temp.c_str()));
|
|
cout << "file path:" << temp.c_str() << endl;
|
|
file_address.push_back(temp);
|
|
}
|
|
//else if (type == excelx_tag&& find(file_types.begin(), file_types.end(), "xlsx") != file_types.end()) {
|
|
// ITKCALL(AOM_UIF_ask_value(dataset[ii], "object_name", &file_name));
|
|
// ITKCALL(AE_export_named_ref(dataset[ii], "excel", temp.append("\\").append(file_name).c_str()));
|
|
// cout << "file path:" << temp.c_str() << endl;
|
|
// file_address.push_back(temp);
|
|
//}
|
|
//else if (type == word_tag && find(file_types.begin(), file_types.end(), "doc") != file_types.end()) {
|
|
// ITKCALL(AOM_UIF_ask_value(dataset[ii], "object_name", &file_name));
|
|
// ITKCALL(AE_export_named_ref(dataset[ii], "word", temp.append("\\").append(file_name).c_str()));
|
|
// cout << "file path:" << temp.c_str() << endl;
|
|
// file_address.push_back(temp);
|
|
//}
|
|
//else if (type == wordx_tag&&find(file_types.begin(), file_types.end(), "docx") != file_types.end()) {
|
|
// ITKCALL(AOM_UIF_ask_value(dataset[ii], "object_name", &file_name));
|
|
// ITKCALL(AE_export_named_ref(dataset[ii], "word", temp.append("\\").append(file_name).c_str()));
|
|
// cout << "file path:" << temp.c_str() << endl;
|
|
// file_address.push_back(temp);
|
|
//}
|
|
//else if (type == ppt_tag && find(file_types.begin(), file_types.end(), "ppt") != file_types.end()) {
|
|
// ITKCALL(AOM_UIF_ask_value(dataset[ii], "object_name", &file_name));
|
|
// ITKCALL(AE_export_named_ref(dataset[ii], "powerpoint", temp.append("\\").append(file_name).c_str()));
|
|
// cout << "file path:" << temp.c_str() << endl;
|
|
// file_address.push_back(temp);
|
|
//}
|
|
//else if (type == pptx_tag&&find(file_types.begin(), file_types.end(), "pptx") != file_types.end()) {
|
|
// ITKCALL(AOM_UIF_ask_value(dataset[ii], "object_name", &file_name));
|
|
|
|
// ITKCALL(AE_export_named_ref(dataset[ii], "powerpoint", temp.append("\\").append(file_name).c_str()));
|
|
// cout << "file path:" << temp.c_str() << endl;
|
|
// file_address.push_back(temp);
|
|
//}
|
|
}
|
|
}
|
|
|
|
POM_AM__set_application_bypass(false);
|
|
|
|
CSendMail sMailer;
|
|
|
|
sMailer.setServerName("smtp.mxhichina.com");
|
|
sMailer.setUserName("lvmh@jide.cn");
|
|
sMailer.setUserPwd("lmh1995815.");
|
|
sMailer.setSenderName("PLM¹ÜÀíÔ±");
|
|
sMailer.setSenderAddress("lvmh@jide.cn");
|
|
|
|
for (int i = 0; i < mail_address.size(); i++) {
|
|
tag_t user;
|
|
char *name;
|
|
AOM_ask_value_tag(signoffs[i], "fnd0Assignee", &user);
|
|
AOM_ask_value_string(user, "user_name", &name);
|
|
sMailer.addReceiver(name, mail_address[i]);
|
|
}
|
|
if (file_address.size() > 0) {
|
|
for (int i = 0; i < file_address.size(); i++) {
|
|
sMailer.AddFilePath(file_address[i].c_str());
|
|
}
|
|
}
|
|
if (sMailer.Connent()) {
|
|
if (sMailer.SendMail(paras["subject"], paras["content"]))
|
|
cout << "Óʼþ·¢Ëͳɹ¦" << endl;
|
|
}
|
|
if (file_address.size() > 0) {
|
|
for (int i = 0; i < file_address.size(); i++) {
|
|
remove(file_address[i].c_str());
|
|
}
|
|
}
|
|
//POM_AM__set_application_bypass(false);
|
|
return 0;
|
|
} |