|
|
|
|
|
#include "SendSap.h"
|
|
|
|
|
|
void addLastRevisions(map<tag_t, vector<tag_t>> items2, vector<tag_t>& cParts) {
|
|
|
for (map<tag_t, vector<tag_t>>::iterator it = items2.begin(); it != items2.end(); it++) {
|
|
|
vector<tag_t> revs = it->second;
|
|
|
if (revs.size() == 1) {
|
|
|
cParts.push_back(revs[0]);
|
|
|
continue;
|
|
|
}
|
|
|
else if (revs.size() > 1) {
|
|
|
tag_t max_Rev = NULLTAG;
|
|
|
string s = "";
|
|
|
int index = -1;
|
|
|
for (int i = 0; i < revs.size(); i++) {
|
|
|
char* item_id = NULL;
|
|
|
ITKCALL(AOM_UIF_ask_value(revs[i], "item_revision_id", &item_id));
|
|
|
if (s.length() == 0) {
|
|
|
s = item_id;
|
|
|
max_Rev = revs[i];
|
|
|
for (int j = 0; j < s.length(); j++) {
|
|
|
if (s[j] >= '0' && s[j] <= '9') {
|
|
|
index = j;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
string temp = item_id;
|
|
|
if (index != -1) {
|
|
|
int compare = tc_strcmp(temp.substr(0, index).c_str(), s.substr(0, index).c_str());
|
|
|
if (compare > 0) {
|
|
|
s = temp;
|
|
|
max_Rev = revs[i];
|
|
|
}
|
|
|
else if (compare == 0) {
|
|
|
string s1 = s.substr(index, s.length() - index);
|
|
|
string temp1 = temp.substr(index, temp.length() - index);
|
|
|
int min = s1.length();
|
|
|
if (min > temp1.length())
|
|
|
min = temp1.length();
|
|
|
for (int k = 0; k < min; k++) {
|
|
|
if (temp1[k] > s1[k]) {
|
|
|
s = temp;
|
|
|
max_Rev = revs[i];
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (temp1.length() > min) {
|
|
|
s = temp;
|
|
|
max_Rev = revs[i];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else if (tc_strcmp(temp.c_str(), s.c_str()) > 0) {
|
|
|
s = temp;
|
|
|
max_Rev = revs[i];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
cParts.push_back(max_Rev);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void getAllNum(char* id, char* revid, double n, map<string, vector<string>>& allcomp) {
|
|
|
char nums[8] = "";
|
|
|
if (allcomp.count(id) > 0) {
|
|
|
double num = stod(allcomp[id][1]);
|
|
|
sprintf(nums, "%f", num + n);
|
|
|
}
|
|
|
else {
|
|
|
sprintf(nums, "%f", n);
|
|
|
}
|
|
|
vector<string> value;// = { revid, nums };
|
|
|
value.push_back(revid);
|
|
|
value.push_back(nums);
|
|
|
allcomp[id] = value;
|
|
|
}
|
|
|
|
|
|
void getAllItem(tag_t parent_line, double parent_num, vector<tag_t>& _list, map<string, vector<string>>& allcomp) {
|
|
|
tag_t rev = NULLTAG;
|
|
|
ITKCALL(AOM_ask_value_tag(parent_line, "bl_line_object", &rev));
|
|
|
char* type = NULL, *zt2_Source = NULL;
|
|
|
ITKCALL(WSOM_ask_object_type2(rev, &type));
|
|
|
ITKCALL(AOM_UIF_ask_value(rev, "zt2_Source", &zt2_Source));
|
|
|
if (tc_strcmp(type, "zt2_Design3DRevision") == 0 && (tc_strcmp(zt2_Source, "<EFBFBD>") == 0 || tc_strcmp(zt2_Source, "S2") == 0)) {
|
|
|
return;
|
|
|
}
|
|
|
int c_line_count = 0;
|
|
|
tag_t *c_line_tags = NULL;
|
|
|
ITKCALL(BOM_line_ask_all_child_lines(parent_line, &c_line_count, &c_line_tags));
|
|
|
for (int i = 0; i < c_line_count; i++) {
|
|
|
tag_t child = NULLTAG;
|
|
|
ITKCALL(AOM_ask_value_tag(c_line_tags[i], "bl_line_object", &child));
|
|
|
char* child_id = NULL, *child_revid = NULL, *child_quantity = NULL;
|
|
|
ITKCALL(AOM_UIF_ask_value(child, "item_id", &child_id));
|
|
|
ITKCALL(AOM_UIF_ask_value(child, "item_revision_id", &child_revid));
|
|
|
ITKCALL(AOM_UIF_ask_value(c_line_tags[i], "bl_quantity", &child_quantity));
|
|
|
if (!child_quantity || tc_strlen(child_quantity) == 0) {
|
|
|
DOFREE(child_quantity);
|
|
|
child_quantity = (char *)MEM_alloc(2 * sizeof(char));
|
|
|
tc_strcpy(child_quantity, "1");
|
|
|
}
|
|
|
double child_num = parent_num * stod(child_quantity);
|
|
|
getAllNum(child_id, child_revid, child_num, allcomp);
|
|
|
getAllItem(c_line_tags[i], child_num, _list, allcomp);
|
|
|
int c_line_count2 = 0;
|
|
|
tag_t *c_line_tags2 = NULL;
|
|
|
ITKCALL(BOM_line_ask_all_child_lines(c_line_tags[i], &c_line_count2, &c_line_tags2));
|
|
|
if (c_line_count2 > 0) {
|
|
|
_list.push_back(child);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void ProcessMemoryTree() {
|
|
|
|
|
|
}
|
|
|
|
|
|
void sendRev(tag_t rev) {
|
|
|
|
|
|
}
|
|
|
|
|
|
void readBomInfo(tag_t ccp, vector<tag_t> schemes, vector<_ns1__DT_USCOREBOM_USCORES4_USCOREREQ_LIST>& list, char* groupName, char* now) {
|
|
|
|
|
|
_ns1__DT_USCOREBOM_USCORES4_USCOREREQ_LIST_HEAD head;
|
|
|
char* zt2_MaterialNo = NULL, *zt2_WBSNo = NULL, *zt2_unit = NULL, *type = NULL, *zt2_BOMScheme = NULL;
|
|
|
ITKCALL(AOM_UIF_ask_value(ccp, "zt2_MaterialNo", &zt2_MaterialNo));
|
|
|
ITKCALL(AOM_UIF_ask_value(ccp, "zt2_WBSNo", &zt2_WBSNo));
|
|
|
tag_t item = NULLTAG;
|
|
|
ITKCALL(ITEM_ask_item_of_rev(ccp, &item));
|
|
|
ITKCALL(AOM_ask_value_string(item, "zt2_unit", &zt2_unit));
|
|
|
//char* unit = getUnti(zt2_unit);
|
|
|
log("str = [%s] \n", zt2_unit);
|
|
|
|
|
|
head.PSPNR = zt2_WBSNo;
|
|
|
head.MATNR = zt2_MaterialNo;
|
|
|
head.STLAN = (char*)"1";
|
|
|
head.STLAL = (char*)"1";
|
|
|
head.BMENG = (char*)"1";
|
|
|
ITKCALL(WSOM_ask_object_type2(ccp, &type));
|
|
|
ITKCALL(AOM_UIF_ask_value(ccp, "zt2_BOMScheme", &zt2_BOMScheme));
|
|
|
if (tc_strcmp(type, "Part Revision") == 0 && tc_strcmp(zt2_BOMScheme, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>") == 0) {
|
|
|
char* zt2_Quantity = NULL;
|
|
|
ITKCALL(AOM_UIF_ask_value(ccp, "zt2_Quantity", &zt2_Quantity));
|
|
|
if (zt2_Quantity && tc_strlen(zt2_Quantity) != 0 && tc_strcmp(zt2_Quantity, "0") != 0) {
|
|
|
head.BMENG = zt2_Quantity;
|
|
|
}
|
|
|
}
|
|
|
head.WERKS = groupName;
|
|
|
head.BMEIN = zt2_unit;
|
|
|
head.DATUV = now;
|
|
|
|
|
|
int c_line_count = schemes.size();
|
|
|
_ns1__DT_USCOREBOM_USCORES4_USCOREREQ_LIST_ITEMS_ITEM* items_items =
|
|
|
new _ns1__DT_USCOREBOM_USCORES4_USCOREREQ_LIST_ITEMS_ITEM[c_line_count];
|
|
|
_ns1__DT_USCOREBOM_USCORES4_USCOREREQ_LIST_ITEMS items;
|
|
|
for (int i = 0; i < c_line_count; i++) {
|
|
|
_ns1__DT_USCOREBOM_USCORES4_USCOREREQ_LIST_ITEMS_ITEM items_item;
|
|
|
tag_t rev2 = schemes[i];
|
|
|
char* cName = NULL, bl_seq_no[8] = "", *zt2_MaterialNo2 = NULL, *zt2_unit2 = NULL;
|
|
|
ITKCALL(AOM_ask_value_string(rev2, "object_name", &cName));
|
|
|
if (tc_strstr(cName, "һ<EFBFBD>ι淶<EFBFBD><EFBFBD>") != NULL) {
|
|
|
tc_strcpy(bl_seq_no, "0010");
|
|
|
}else if (tc_strstr(cName, "<EFBFBD><EFBFBD><EFBFBD>ι淶<EFBFBD><EFBFBD>") != NULL) {
|
|
|
tc_strcpy(bl_seq_no, "0020");
|
|
|
}
|
|
|
else if(tc_strstr(cName, "<EFBFBD>ṹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>") != NULL) {
|
|
|
tc_strcpy(bl_seq_no, "0030");
|
|
|
}
|
|
|
items_item.DATUV = now;
|
|
|
items_item.POSTP = (char*)"L";
|
|
|
items_item.POSNR = bl_seq_no;
|
|
|
ITKCALL(AOM_UIF_ask_value(rev2, "zt2_MaterialNo", &zt2_MaterialNo2));
|
|
|
items_item.IDNRK = zt2_MaterialNo2;
|
|
|
items_item.MENGE = (char*)"1";
|
|
|
items_item.SORTF = getZYCCPSortNo(rev2);
|
|
|
if (tc_strstr(zt2_MaterialNo2, "9900000191") != NULL) {
|
|
|
items_item.POTX1 = "PCM00825";
|
|
|
}
|
|
|
else {
|
|
|
items_item.POTX1 = "";
|
|
|
}
|
|
|
tag_t item2 = NULLTAG;
|
|
|
ITKCALL(ITEM_ask_item_of_rev(rev2, &item2));
|
|
|
ITKCALL(AOM_ask_value_string(item2, "zt2_unit", &zt2_unit2));
|
|
|
items_item.MEINS = zt2_unit2;
|
|
|
|
|
|
items_items[i] = items_item;
|
|
|
}
|
|
|
items.ITEM = items_items;
|
|
|
items.__sizeITEM = c_line_count;
|
|
|
_ns1__DT_USCOREBOM_USCORES4_USCOREREQ_LIST list1;
|
|
|
list1.HEAD = head;
|
|
|
log("list1.HEAD %s ", list1.HEAD.BMEIN);
|
|
|
list1.ITEMS = items;
|
|
|
list.push_back(list1);
|
|
|
}
|
|
|
|
|
|
void sendToSap2(vector<tag_t> ccpVector, char* groupName, char* now, char* code, char* wbs) {
|
|
|
log("************** SAPZYGG2 **************");
|
|
|
int pref_cnt = 0;
|
|
|
char **urls = NULL;
|
|
|
ITKCALL(PREF_ask_char_values("CHINT_BomUrl_YB", &pref_cnt, &urls));
|
|
|
|
|
|
map<tag_t, vector<tag_t>> cPart_schemes;
|
|
|
vector<tag_t> bom_revs;
|
|
|
vector<tag_t> isCheck_FactoryNos;
|
|
|
map<string, vector<string>> inCcpMap;//<2F><>¼<EFBFBD><C2BC>Ԫ<EFBFBD><D4AA>Ӧ<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD>ϱ<EFBFBD><CFB1><EFBFBD>
|
|
|
for (int len = 0; len < ccpVector.size(); len++) {
|
|
|
tag_t rev = ccpVector[len], *factoryNos;
|
|
|
char* revUid = NULL;
|
|
|
ITK__convert_tag_to_uid(rev, &revUid);
|
|
|
log("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƷUID:%s", revUid);
|
|
|
int num = 0;
|
|
|
ITKCALL(AOM_ask_value_tags(rev, "ZT2_FactoryNumber", &num, &factoryNos));
|
|
|
if (num == 0) {
|
|
|
bom_revs.push_back(rev);
|
|
|
}
|
|
|
else {
|
|
|
map<tag_t, vector<tag_t>> items2;
|
|
|
vector<tag_t> revs;
|
|
|
for (int i = 0; i < num; i++) {
|
|
|
if (find(isCheck_FactoryNos.begin(), isCheck_FactoryNos.end(), factoryNos[i]) != isCheck_FactoryNos.end())
|
|
|
continue;
|
|
|
isCheck_FactoryNos.push_back(factoryNos[i]);
|
|
|
int n_references = 0;
|
|
|
int* levels = 0;
|
|
|
tag_t* references_tag;
|
|
|
char** relation_type_name = NULL;
|
|
|
//ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD><C5B2>ҵ<EFBFBD>ͼֽ
|
|
|
ITKCALL(WSOM_where_referenced(factoryNos[i], 1, &n_references, &levels, &references_tag, &relation_type_name));
|
|
|
for (int i = 0; i < n_references; i++) {
|
|
|
if (tc_strcmp(relation_type_name[i], "ZT2_FactoryNumber") != 0)
|
|
|
continue;
|
|
|
char *type2 = NULL;
|
|
|
ITKCALL(WSOM_ask_object_type2(references_tag[i], &type2));
|
|
|
if (tc_strcmp(type2, "Part Revision") != 0)
|
|
|
continue;
|
|
|
char* revUid2 = NULL;
|
|
|
ITK__convert_tag_to_uid(references_tag[i], &revUid2);
|
|
|
if (tc_strcmp(revUid, revUid2) == 0)
|
|
|
continue;
|
|
|
char *name2 = NULL;
|
|
|
ITKCALL(AOM_UIF_ask_value(references_tag[i], "object_name", &name2));
|
|
|
if (tc_strstr(name2, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>") == NULL)
|
|
|
continue;
|
|
|
tag_t item2 = NULLTAG;
|
|
|
ITKCALL(ITEM_ask_item_of_rev(references_tag[i], &item2));
|
|
|
if (items2.count(item2) > 0) {
|
|
|
items2[item2].push_back(references_tag[i]);
|
|
|
}
|
|
|
else {
|
|
|
vector<tag_t> revs2;
|
|
|
revs2.push_back(references_tag[i]);
|
|
|
items2[item2] = revs2;
|
|
|
}
|
|
|
addLastRevisions(items2, revs);
|
|
|
if (revs.size() > 0) {
|
|
|
cPart_schemes[rev] = revs;
|
|
|
}
|
|
|
else {
|
|
|
bom_revs.push_back(rev);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
map<tag_t, vector<_ns1__DT_USCOREBOM_USCORES4_USCOREREQ_LIST>> mapList;
|
|
|
for (map<tag_t, vector<tag_t>>::iterator it = cPart_schemes.begin(); it != cPart_schemes.end(); it++) {
|
|
|
tag_t ccp = it->first;
|
|
|
vector<tag_t> schemes = it->second;
|
|
|
//if (schemes.size() > 0) {}
|
|
|
char* revUid = NULL, *zt2_MaterialNo = NULL;
|
|
|
ITK__convert_tag_to_uid(ccp, &revUid);
|
|
|
log("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƷUID:%s", revUid);
|
|
|
if (inCcpMap.count(revUid) > 0) {
|
|
|
log("folderName =>%s", zt2_MaterialNo);
|
|
|
inCcpMap[revUid].push_back(zt2_MaterialNo);
|
|
|
continue;
|
|
|
}
|
|
|
vector<string> ccpMaterialMap;
|
|
|
ccpMaterialMap.push_back(zt2_MaterialNo);
|
|
|
inCcpMap[revUid] = ccpMaterialMap;
|
|
|
|
|
|
vector<_ns1__DT_USCOREBOM_USCORES4_USCOREREQ_LIST> list;
|
|
|
readBomInfo(ccp, schemes, list, groupName, now);
|
|
|
if (list.size() > 0) {
|
|
|
mapList[ccp] = list;
|
|
|
}
|
|
|
}
|
|
|
startSplitSend(groupName, mapList, code, wbs, inCcpMap, urls[2]);
|
|
|
} |