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.

563 lines
17 KiB

#include "util.h"
#include "test.h"
#include <wincrypt.h>
#include <set>
#include <sa/person.h>
#include <tccore/aom.h>
#include <tc/preferences.h>
struct user_info
{
string time;
string img_path;
string id;
bool operator < (const user_info &a) const
{
return a.id < id;
}
};
int wx_signoff2(tag_t task)
{
//USES_CONVERSION;
int index, size, att_count, rowFirst, rowLast, colFirst,
colLast, pref_count, forms_count;
//Book* book = nullptr;
tag_t img_tag, rootTask, *attachments, type_tag, word_tag, wordx_tag, ref_obj, excel_ref, excel_tag, excelx_tag, user_tag, person_tag, forms_tag, *forms_tags;
char *comp_name, *type_class, *temp_path, *user_name, **pref_val, *wx3_psbm = nullptr, *wx3_psr = nullptr, *wx3_fwdw = nullptr, *wx3_qsr = nullptr;
//森威新增
char *wx3_jgb = NULLTAG, *wx3_cgb = NULLTAG, *wx3_cwb = NULLTAG, *wx3_jdb = NULLTAG, *wx3_jszx = NULLTAG, *wx3_mjzx = NULLTAG, *wx3_scb = NULLTAG, *wx3_scwlzx = NULLTAG, *wx3_zlb = NULLTAG;
date_t creation_date;
string wx_empty;
time_t t;
time(&t);
tm* local = localtime(&t);
string pre, cmp, bz_val, bz_date_val, word_path;
vector<string> empty_imgs, wx_vec, wx_sw;
map<string, string> user_map, role_sign_map;
map<string, vector<string>> role_map;
map<string, boolean> role_is_sign_map;
vector<vector<user_info>> user_info_vec2;
map<tag_t, vector<vector<user_info>>> map_user_info_vec;
map<tag_t, vector<vector<string>>> map_user_info_ids;
vector<set<user_info>> user_id_set;
AE_reference_type_t ae_ref;
for (auto i = 0; i < 6; i++)
{
vector<user_info> temp;
set<user_info> temp_set;
user_id_set.push_back(temp_set);
user_info_vec2.push_back(temp);
}
TCHAR *excel_names[6] = { L"编制", L"会签", L"审核", L"批准", L"校对", L"标准化" };
TCHAR *excel_dates[6] = { L"编制日期", L"会签日期", L"审核日期", L"批准日期", L"校对日期", L"标准化日期" };
char *img_suffix[6] = { "编制人.jpg", "会签人.jpg", "审核人.jpg", "批准人.jpg", "校对人.jpg", "标准化人.jpg" };
char *word_names[6] = { "编制人", "会签人", "审核人", "批准人", "校对人", "标准化人" };
char *word_times[6] = { "编制日期", "会签日期", "审核日期", "批准日期", "校对日期", "标准化日期" };
char *date_suffix[5] = { " \\* MERGEFORMAT", "", " \\@ \"yyyy-MM-dd\"", " \\@ \"yyyy-MM-DD\"", " \\@ \"YYYY-MM-dd\"" };
char *reviews[5] = { "质量", "设计", "工艺", "生产", "财务" };
POM_AM__set_application_bypass(true);
EPM_ask_root_task(task, &rootTask);
PREF_ask_char_values("WXSignoffMapping", &pref_count, &pref_val);
AOM_ask_owner(rootTask, &user_tag);
SA_ask_user_identifier2(user_tag, &user_name);
SA_ask_user_person(user_tag, &person_tag);
SA_ask_person_attribute2(person_tag, "PA6", &comp_name);
for (auto i = 0; i < pref_count; i++)
{
string str(pref_val[i]);
index = str.find('=');
if (index != -1)
{
printf("user_map[%s] = %s\n", str.substr(0, index), str.substr(index + 1));
user_map[str.substr(0, index)] = str.substr(index + 1);
}
}
if (pref_count)
MEM_free(pref_val);
PREF_ask_char_values("WXGroupNameMapping", &pref_count, &pref_val);
if (comp_name && strlen(comp_name) > 0)
{
cmp = comp_name;
for (auto i = 0; i < pref_count; i++)
{
string str(pref_val[i]);
if (str.find(comp_name) != -1)
{
int index1 = str.find(',');
if (index1 == -1)
break;
int index2 = str.find(',', index1 + 1);
if (index2 == -1)
break;
cmp = str.substr(index1 + 1, index2 - index1 - 1);
break;
}
}
MEM_free(comp_name);
}
if (pref_count)
MEM_free(pref_val);
PREF_ask_char_values("WX_ECR_RoleMapping", &pref_count, &pref_val);
for (auto i = 0; i < pref_count; i++)
{
string str(pref_val[i]);
int index = str.find('=');
if (index == -1)
continue;
vector<string> temp;
split(str.substr(index + 1), ",", &temp);
role_map[str.substr(0, index)] = temp;
}
if (pref_count)
MEM_free(pref_val);
TCTYPE_find_type("MSExcelX", "Dataset", &excelx_tag);
TCTYPE_find_type("MSExcel", "Dataset", &excel_tag);
TCTYPE_find_type("MSWord", "Dataset", &word_tag);
TCTYPE_find_type("MSWordX", "Dataset", &wordx_tag);
temp_path = getenv("temp");
{
stringstream ss;
ss << temp_path;
ss << "\\export";
ss << local->tm_year;
ss << local->tm_mon;
ss << local->tm_mday;
ss << local->tm_hour;
ss << local->tm_min;
ss << local->tm_sec;
pre = ss.str();
}
char * temp_date_val;
AOM_UIF_ask_value(rootTask, "creation_date", &temp_date_val);
stringstream temp_date_ss;
int len = strlen(temp_date_val);
for (auto i = 0; i < len; i++)
{
if (temp_date_val[i] == ' ')
break;
if (temp_date_val[i + 1] == '-'&&temp_date_val[i - 1] == '-')
temp_date_ss << '0';
temp_date_ss << temp_date_val[i];
}
bz_date_val = temp_date_ss.str();
printf("bz_date_val:%s\n", bz_date_val.c_str());
ITK__convert_uid_to_tag(user_map[user_name].c_str(), &img_tag);
char *object_name;
if (img_tag != NULLTAG)
{
AE_ask_dataset_named_ref2(img_tag, "Image", &ae_ref, &ref_obj);
stringstream img_path;
img_path << pre;
img_path << user_name;
MEM_free(user_name);
img_path << "编制人.jpg";
IMF_export_file(ref_obj, img_path.str().c_str());
bz_val = img_path.str();
printf("bz_val:%s\n", bz_val.c_str());
}
EPM_ask_attachments(rootTask, EPM_target_attachment, &att_count, &attachments);
for (auto i = 0; i < att_count; i++)
{
if (checkIsTypeOrSubtype(attachments[i], "ChangeRequestRevision"))
{
printf("ChangeRequestRevision属性获取\n");
AOM_ask_value_string(attachments[i], "wx3_psbm", &wx3_psbm);
AOM_ask_value_string(attachments[i], "wx3_psr", &wx3_psr);
AOM_ask_value_tags(attachments[i], "IMAN_master_form_rev", &forms_count, &forms_tags);//获取子件的版本主表单
if (forms_count > 0) {
forms_tag = forms_tags[0];
//森威新增
AOM_ask_value_string(forms_tag, "wx3_ggpsr_cgb", &wx3_cgb);
AOM_ask_value_string(forms_tag, "wx3_ggpsr_cwb", &wx3_cwb);
AOM_ask_value_string(forms_tag, "wx3_ggpsr_jdb", &wx3_jdb);
AOM_ask_value_string(forms_tag, "wx3_ggpsr_jgb", &wx3_jgb);
AOM_ask_value_string(forms_tag, "wx3_ggpsr_jszx", &wx3_jszx);
AOM_ask_value_string(forms_tag, "wx3_ggpsr_mjzx", &wx3_mjzx);
AOM_ask_value_string(forms_tag, "wx3_ggpsr_scb", &wx3_scb);
AOM_ask_value_string(forms_tag, "wx3_ggpsr_scwlzx", &wx3_scwlzx);
AOM_ask_value_string(forms_tag, "wx3_ggpsr_zlb", &wx3_zlb);
printf("wx3_cgb:%s\n", wx3_cgb);
printf("wx3_cwb:%s\n", wx3_cwb);
printf("wx3_jdb:%s\n", wx3_jdb);
printf("wx3_jgb:%s\n", wx3_jgb);
printf("wx3_jszx:%s\n", wx3_jszx);
printf("wx3_mjzx:%s\n", wx3_mjzx);
printf("wx3_scb:%s\n", wx3_scb);
printf("wx3_scwlzx:%s\n", wx3_scwlzx);
printf("wx3_zlb:%s\n", wx3_zlb);
}
split(wx3_psr, ",", &wx_vec);
for (auto j = 0; j<wx_vec.size(); j++)
{
ITK__convert_uid_to_tag(user_map[wx_vec[j]].c_str(), &img_tag);
if (img_tag == NULLTAG)
continue;
AE_ask_dataset_named_ref2(img_tag, "Image", &ae_ref, &ref_obj);
stringstream img_path;
img_path << pre;
img_path << wx_vec[j];
img_path << "评审人员.jpg";
IMF_export_file(ref_obj, img_path.str().c_str());
wx_vec[j] = img_path.str();
}
}
if (checkIsTypeOrSubtype(attachments[i], "ChangeNoticeRevision"))
{
printf("ChangeNoticeRevision属性获取\n");
AOM_ask_value_string(attachments[i], "wx3_fwdw", &wx3_fwdw);
AOM_ask_value_string(attachments[i], "wx3_qsr", &wx3_qsr);
split(wx3_qsr, ",", &wx_vec);
for (auto j = 0; j<wx_vec.size(); j++)
{
printf("签收人: %s\n", wx_vec[j]);
ITK__convert_uid_to_tag(user_map[wx_vec[j]].c_str(), &img_tag);
if (img_tag == NULLTAG)
continue;
AE_ask_dataset_named_ref2(img_tag, "Image", &ae_ref, &ref_obj);
stringstream img_path;
img_path << pre;
img_path << wx_vec[j];
img_path << "签收人.jpg";
IMF_export_file(ref_obj, img_path.str().c_str());
wx_vec[j] = img_path.str();
}
split(wx3_qsr, ",", &wx_sw);
for (auto j = 0; j < wx_sw.size(); j++)
{
printf("签收人: %s\n", wx_sw[j]);
ITK__convert_uid_to_tag(user_map[wx_sw[j]].c_str(), &img_tag);
if (img_tag == NULLTAG)
continue;
AE_ask_dataset_named_ref2(img_tag, "Image", &ae_ref, &ref_obj);
stringstream img_path;
img_path << pre;
img_path << wx_sw[j];
img_path << "签收人.jpg";
IMF_export_file(ref_obj, img_path.str().c_str());
wx_sw[j] = img_path.str();
}
}
TCTYPE_ask_object_type(attachments[i], &type_tag);
TCTYPE_ask_class_name2(type_tag, &type_class);
if ((strstr(type_class, "Revision") != NULL || strstr(type_class, "revision") != NULL) && strstr(type_class, "Master") == NULL && strstr(type_class, "master") == NULL && strstr(type_class, "BOM") == NULL && strstr(type_class, "bom") == NULL)
{
char * val;
AOM_ask_value_string(attachments[i], "wx3_signoff_info", &val);
vector<vector<user_info>> user_info_vec;
vector<vector<string>> user_info_ids;
for (auto z = 0; z < 6; z++)
{
vector<user_info> temp;
user_info_vec.push_back(temp);
vector<string> ids;
user_info_ids.push_back(ids);
}
AOM_ask_value_string(attachments[i],"object_name",&object_name);
LINFO<<"对象"<<object_name<<"---wx3_signoff_info=["<<val<<"]";
map_user_info_vec[attachments[i]] = user_info_vec;
map_user_info_ids[attachments[i]] = user_info_ids;
if (val == NULL || tc_strlen(val) == 0)
continue;
printf("val:%s\n", val);
string temp(val);
vector<string> temp_vec;
split(temp, " ", &temp_vec);
printf("temp_vec.size:%d\n", temp_vec.size());
for (auto j = 0; j < temp_vec.size(); j++)
{
index = temp_vec[j].find("=");
if (index == -1)
continue;
vector<string> temp_vec2;
split(temp_vec[j].substr(index + 1), ",", &temp_vec2);
index = temp_vec[j][0] - '0';
if (index > 6 || index < 0)
continue;
for (auto k = 0; k < temp_vec2.size(); k++)
{
user_info temp_info;
int temp_index = temp_vec2[k].find(":");
if (temp_index == -1)
continue;
temp_info.id = temp_vec2[k].substr(0, temp_index);
temp_info.time = temp_vec2[k].substr(temp_index + 1);
user_id_set[index].insert(temp_info);
map_user_info_ids[attachments[i]][index].push_back(temp_info.id);
LINFO<<"对象"<<object_name<<"添加用户["<<temp_info.id.c_str()<<"]";
}
}
MEM_free(val);
}
MEM_free(type_class);
}
for (auto i = 0; i < user_id_set.size(); i++)
{
for (auto j = user_id_set[i].begin(); j != user_id_set[i].end(); j++)
{
ITK__convert_uid_to_tag(user_map[j->id].c_str(), &img_tag);
if (img_tag == NULLTAG)
continue;
AE_ask_dataset_named_ref2(img_tag, "Image", &ae_ref, &ref_obj);
stringstream img_path;
img_path << pre;
img_path << j->id;
img_path << img_suffix[i];
IMF_export_file(ref_obj, img_path.str().c_str());
user_info temp = *j;
temp.img_path = img_path.str();
user_info_vec2[i].push_back(temp);
for (auto it = map_user_info_ids.begin(); it != map_user_info_ids.end(); it++)
{
vector<vector<string>> user_info_ids = it->second;
vector<string> ids = user_info_ids[i];
if (find(ids.begin(), ids.end(), temp.id.c_str()) != ids.end())
{
map_user_info_vec[it->first][i].push_back(temp);
}
}
if (i == 2)
{
bool find = false;
for (auto k = role_map.begin(); k != role_map.end(); k++)
{
for (auto l = 0; l < k->second.size(); l++)
{
if (k->second[l].find(j->id) != -1)
{
string temp_str = img_path.str();
int temp_index = temp_str.find(j->id);
role_sign_map[k->first] = temp_str.substr(0, temp_index) + k->first + temp_str.substr(temp_index);
find = true;
IMF_export_file(ref_obj, role_sign_map[k->first].c_str());
printf("k->first:%s", k->first.c_str());
role_is_sign_map[k->first] = true;
break;
}
}
if (find)
break;
}
}
}
}
ITK__convert_uid_to_tag(user_map["empty"].c_str(), &img_tag);
if (img_tag != NULLTAG)
{
AE_ask_dataset_named_ref2(img_tag, "Image", &ae_ref, &ref_obj);
for (auto i = 0; i < 10; i++)
{
stringstream img_path;
img_path << pre;
img_path << "empty";
if (i >= 5)
{
img_path << reviews[i - 5];
img_path << img_suffix[2];
}
else
img_path << img_suffix[i];
IMF_export_file(ref_obj, img_path.str().c_str());
empty_imgs.push_back(img_path.str());
}
if (tc_strlen(wx3_psr) || tc_strlen(wx3_qsr))
{
stringstream img_path;
img_path << pre;
img_path << "empty";
img_path << (tc_strlen(wx3_psr) == 0 ? "评审人员" : "签收人");
img_path << ".jpg";
IMF_export_file(ref_obj, img_path.str().c_str());
wx_empty = img_path.str();
}
}
LINFO<<"-----遍历自定义Map---------------------------------";
int v_index = 0;
for(auto it = map_user_info_vec.begin();it!=map_user_info_vec.end();it++)
{
AOM_ask_value_string(it->first,"object_name",&object_name);
LINFO<<""<<v_index<<"个[object_name="<<object_name<<"]";
v_index++;
}
LINFO<<"-----------遍历结束开始签字----------";
int cout;
tag_t tag_signoff;
//tag_t *refs;
//tag_t relation_type, relation_type2, relation_type3;
//ITKCALL(GRM_find_relation_type(TC_attaches_rtype, &relation_type3));
//ITKCALL(GRM_find_relation_type(TC_specification_rtype, &relation_type2));
//ITKCALL(GRM_find_relation_type(TC_reference_rtype, &relation_type));
int cnt, *levels;
tag_t* refs;
char** relations;
for (auto i = 0; i < att_count; i++)
{
TCTYPE_ask_object_type(attachments[i], &type_tag);
char* excelname;
AOM_ask_value_string(attachments[i], "object_name", &excelname);
string excelname_s = excelname;
if (type_tag == excel_tag || type_tag == excelx_tag)
{
stringstream ss;
ss << pre;
ss << i;
AE_ask_dataset_named_ref2(attachments[i], "excel", &ae_ref, &excel_ref);
char *file_name;
AOM_UIF_ask_value(excel_ref, "file_name", &file_name);
printf("ss:%s\n", ss.str().c_str());
printf("open excel.....\n");
//修改各个签名内容
LINFO<<"文件名称:"<<file_name;
WSOM_where_referenced(attachments[i], 1, &cout, &levels, &refs, &relations);
MEM_free(relations);
LINFO<<"引用个数--"<<cout;
tag_signoff = NULLTAG;
vector<vector<user_info>> user_info_vec;
for (auto s = 0; s < cout; s++)
{
AOM_ask_value_string(refs[s],"object_name",&object_name);
LINFO<<""<<s<<"个[object_name="<<object_name<<"]";
if (map_user_info_vec.find(refs[s]) != map_user_info_vec.end())
{
tag_signoff = refs[s];
user_info_vec = map_user_info_vec[refs[s]];
printf("需要控制签名个数\r\n");
break;
}
}
MEM_free(levels);
MEM_free(refs);
/*
GRM_list_primary_objects_only(type_tag, relation_type3, &cout, &refs);
LINFO<<"TC_Attaches"<<"引用个数--"<<cout;
tag_signoff = NULLTAG;
vector<vector<user_info>> user_info_vec;
for (auto s = 0; s < cout; s++)
{
AOM_ask_value_string(refs[s],"object_name",&object_name);
LINFO<<"第"<<s<<"个[object_name="<<object_name<<"]";
if (map_user_info_vec.find(refs[s]) != map_user_info_vec.end())
{
tag_signoff = refs[s];
user_info_vec = map_user_info_vec[refs[s]];
printf("需要控制签名个数\r\n");
break;
}
}
if (tag_signoff == NULLTAG)
{
GRM_list_primary_objects_only(type_tag, relation_type2, &cout, &refs);
LINFO<<"IMAN_specification"<<"引用个数--"<<cout;
for (auto s = 0; s < cout; s++)
{
AOM_ask_value_string(refs[s],"object_name",&object_name);
LINFO<<"第"<<s<<"个[object_name="<<object_name<<"]";
if (map_user_info_vec.find(refs[s]) != map_user_info_vec.end())
{
tag_signoff = refs[s];
user_info_vec = map_user_info_vec[refs[s]];
printf("需要控制签名个数\r\n");
break;
}
}
}
if (tag_signoff == NULLTAG)
{
GRM_list_primary_objects_only(type_tag, relation_type, &cout, &refs);
for (auto s = 0; s < cout; s++)
{
AOM_ask_value_string(refs[s],"object_name",&object_name);
LINFO<<"第"<<s<<"个[object_name="<<object_name<<"]";
if (map_user_info_vec.find(refs[s]) != map_user_info_vec.end())
{
tag_signoff = refs[s];
user_info_vec = map_user_info_vec[refs[s]];
printf("需要控制签名个数\r\n");
break;
}
}
}
*/
if (tag_signoff == NULLTAG)
{
user_info_vec = user_info_vec2;
printf("不需要控制\r\n");
LINFO<<"不需要控制";
}else
{
AOM_ask_value_string(tag_signoff,"object_name",&object_name);
LINFO<<"找到版本对象[object_name="<<object_name<<"]";
}
LINFO<<"开始遍历签字内容";
for(auto f=0;f<user_info_vec.size();f++)
{
vector<user_info> vecs = user_info_vec[f];
int f_vecs = vecs.size();
LINFO<<""<<f<<"需要签字个数:"<<f_vecs;
for(auto it = vecs.begin();it!=vecs.end();it++)
{
LINFO<<"签字人员="<<(*it).id.c_str()<<";路径="<<(*it).img_path.c_str()<<";日期="<<(*it).time.c_str()<<";";
}
}
}
}
POM_AM__set_application_bypass(false);
return 0;
}