|
|
#define _CRT_SECURE_NO_WARNINGS
|
|
|
#include "epm_handler_common.h"
|
|
|
#include "OracleDB.h"
|
|
|
|
|
|
|
|
|
map<string, int> getClassAttrMapRule(map<string, map<string, int>> classMap, char* classId) {
|
|
|
map<string, int> attrMap;
|
|
|
//分类属性名称对应id map存储
|
|
|
if (classMap.find(classId) == classMap.end()) {
|
|
|
int count = 0;
|
|
|
int* ids;
|
|
|
int* arraySize;
|
|
|
int* formats;
|
|
|
int* options;
|
|
|
char** names;
|
|
|
char** shortNames;
|
|
|
char** annotations;
|
|
|
char** unit;
|
|
|
char** minValues;
|
|
|
char** maxValues;
|
|
|
char** defaultValues;
|
|
|
char** descriptions;
|
|
|
ITKCALL(ICS_class_describe_attributes(classId, &count, &ids, &names, &shortNames, &annotations, &arraySize,
|
|
|
&formats, &unit, &minValues, &maxValues, &defaultValues, &descriptions, &options));
|
|
|
for (int i = 0; i < count; i++)
|
|
|
{
|
|
|
attrMap.insert(pair<string, int>(names[i], ids[i]));
|
|
|
}
|
|
|
classMap.insert(pair<string, map<string, int>>(classId, attrMap));
|
|
|
if (ids != NULL) {
|
|
|
DOFREE(ids);
|
|
|
}
|
|
|
if (arraySize != NULL) {
|
|
|
DOFREE(arraySize);
|
|
|
}
|
|
|
if (formats != NULL) {
|
|
|
DOFREE(formats);
|
|
|
}
|
|
|
if (options != NULL) {
|
|
|
DOFREE(options);
|
|
|
}
|
|
|
if (names != NULL) {
|
|
|
DOFREE(names);
|
|
|
}
|
|
|
if (shortNames != NULL) {
|
|
|
DOFREE(shortNames);
|
|
|
}
|
|
|
if (annotations != NULL) {
|
|
|
DOFREE(annotations);
|
|
|
}
|
|
|
if (unit != NULL) {
|
|
|
DOFREE(unit);
|
|
|
}
|
|
|
if (minValues != NULL) {
|
|
|
DOFREE(minValues);
|
|
|
}
|
|
|
if (maxValues != NULL) {
|
|
|
DOFREE(maxValues);
|
|
|
}
|
|
|
if (defaultValues != NULL) {
|
|
|
DOFREE(defaultValues);
|
|
|
}
|
|
|
if (descriptions != NULL) {
|
|
|
DOFREE(descriptions);
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
attrMap = classMap[classId];
|
|
|
}
|
|
|
return attrMap;
|
|
|
}
|
|
|
void getItemClassRule(char** c_sql_values, char* itemType, tag_t ico_tag, tag_t zi_rev, map<string, int> attrMap, char* classId, char** classCode,string& errMsg,char* itemId1) {
|
|
|
WriteLog("-----------------getItemClass------------------------\n");
|
|
|
|
|
|
char* field1 = NULL;
|
|
|
char* field2 = NULL;
|
|
|
int outputColumn = 0, outputValueCount = 0;
|
|
|
char*** outputValue = NULL;
|
|
|
//物料分类特殊处理,通过数据库表匹配
|
|
|
char sql[1024] = "\0";
|
|
|
if (strcmp("RB3_LBJRevision", itemType) == 0 || strcmp("RB3_GNZCRevision", itemType) == 0 || strcmp("RB3_GNLBJRevision", itemType) == 0 || strcmp("RB3_GYZYRevision", itemType) == 0) {
|
|
|
if (strcmp("RB3_LBJRevision", itemType) == 0 && ico_tag != NULLTAG)
|
|
|
{
|
|
|
ITKCALL(AOM_UIF_ask_value(zi_rev, "object_name", &field1));
|
|
|
char* value = NULL;
|
|
|
ICS_ask_attribute_value(ico_tag, "类别", &value);
|
|
|
if (value != NULL) {
|
|
|
int id = attrMap["类别"];
|
|
|
getClassValue(value, id, &field2);
|
|
|
DOFREE(value);
|
|
|
}
|
|
|
}
|
|
|
else if (strcmp("RB3_GNZCRevision", itemType) == 0 && ico_tag != NULLTAG)
|
|
|
{
|
|
|
char* value = NULL;
|
|
|
ICS_ask_attribute_value(ico_tag, "产品类别", &value);
|
|
|
if (value != NULL) {
|
|
|
int id = attrMap["产品类别"];
|
|
|
getClassValue(value, id, &field1);
|
|
|
DOFREE(value);
|
|
|
}
|
|
|
ITKCALL(AOM_UIF_ask_value(zi_rev, "object_name", &field2));
|
|
|
}
|
|
|
else if (strcmp("RB3_GNLBJRevision", itemType) == 0 && ico_tag != NULLTAG)
|
|
|
{
|
|
|
ITKCALL(AOM_UIF_ask_value(zi_rev, "object_name", &field1));
|
|
|
char* value = NULL;
|
|
|
ICS_ask_attribute_value(ico_tag, "产品类别", &value);
|
|
|
if (value != NULL) {
|
|
|
int id = attrMap["产品类别"];
|
|
|
getClassValue(value, id, &field2);
|
|
|
DOFREE(value);
|
|
|
}
|
|
|
}
|
|
|
else if (strcmp("RB3_GYZYRevision", itemType) == 0 && ico_tag != NULLTAG)
|
|
|
{
|
|
|
char* new_classId = NULL;
|
|
|
if (startsWith(classId, '1', '2') || startsWith(classId, '1', '7'))
|
|
|
{
|
|
|
new_classId = getFirstStr(classId, 2);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
new_classId = getFirstStr(classId, 4);
|
|
|
}
|
|
|
tag_t classTag = NULLTAG;
|
|
|
char* id = NULL;
|
|
|
if (new_classId != NULL) {
|
|
|
ITKCALL(ICS_find_class(new_classId, &classTag));
|
|
|
if (classTag != NULLTAG)
|
|
|
{
|
|
|
ITKCALL(ICS_ask_id_name(classTag, &id, &field1));
|
|
|
}
|
|
|
}
|
|
|
if (id != NULL) {
|
|
|
DOFREE(id);
|
|
|
}
|
|
|
if (classTag != NULL) {
|
|
|
DOFREE(classTag);
|
|
|
}
|
|
|
if (new_classId != NULL) {
|
|
|
DOFREE(new_classId);
|
|
|
}
|
|
|
}
|
|
|
if (field1 != NULL) {
|
|
|
if (field1 != NULL && field2 != NULL) {
|
|
|
sprintf(sql, "select PCLASSCODE,PCLASSNAME,NEW_COLUMN,PUNIT from PLM_ERP_CLASS_TABLE where PFIELD01= '%s' and PFIELD02= '%s'", field1, field2);
|
|
|
}
|
|
|
else {
|
|
|
sprintf(sql, "select PCLASSCODE,PCLASSNAME,NEW_COLUMN,PUNIT from PLM_ERP_CLASS_TABLE where PFIELD01= '%s'", field1);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
if (strcmp("RB3_ZCRevision", itemType) == 0)
|
|
|
{
|
|
|
ITKCALL(AOM_UIF_ask_value(zi_rev, "rb3_zclx", &field1));
|
|
|
}
|
|
|
else if (strcmp("RB3_BZJRevision", itemType) == 0 || strcmp("RB3_BZJBJRevision", itemType) == 0
|
|
|
|| strcmp("RB3_YZRevision", itemType) == 0 || strcmp("RB3_GQRevision", itemType) == 0
|
|
|
|| strcmp("RB3_GQBJRevision", itemType) == 0 || strcmp("RB3_GZRevision", itemType) == 0
|
|
|
|| strcmp("RB3_GZBJRevision", itemType) == 0)
|
|
|
{
|
|
|
ITKCALL(AOM_UIF_ask_value(zi_rev, "object_name", &field1));
|
|
|
WriteLog("提示:field1T==%s\n", field1);
|
|
|
}
|
|
|
else if (strcmp("RB3_YCLRevision", itemType) == 0 || strcmp("RB3_SLRevision", itemType) == 0
|
|
|
|| strcmp("RB3_XJRevision", itemType) == 0 || strcmp("RB3_WJTLRevision", itemType) == 0)
|
|
|
{
|
|
|
ITKCALL(AOM_UIF_ask_value(zi_rev, "rb3_bjlx", &field1));
|
|
|
}
|
|
|
else if (strcmp("RB3_XZCPRevision", itemType) == 0)
|
|
|
{
|
|
|
ITKCALL(AOM_UIF_ask_value(zi_rev, "rb3_cplx2", &field1));
|
|
|
}
|
|
|
else if (strcmp("RB3_XZLBJRevision", itemType) == 0 && ico_tag != NULLTAG)
|
|
|
{
|
|
|
char* value = NULL;
|
|
|
ICS_ask_attribute_value(ico_tag, "零件类别", &value);
|
|
|
if (value != NULL) {
|
|
|
int id = attrMap["零件类别"];
|
|
|
getClassValue(value, id, &field1);
|
|
|
DOFREE(value);
|
|
|
}
|
|
|
}
|
|
|
if (field1 != NULL) {
|
|
|
sprintf(sql, "select PCLASSCODE,PCLASSNAME,NEW_COLUMN,PUNIT from PLM_ERP_CLASS_TABLE where PTYPE= '%s' and PFIELD01= '%s'", itemType, field1);
|
|
|
|
|
|
//sprintf(sql, "select PCLASSCODE,PCLASSNAME,NEW_COLUMN,PUNIT from PLM_ERP_CLASS_TABLE where PFIELD01= '%s'", field1);
|
|
|
}
|
|
|
}
|
|
|
if (strcmp("", sql) != 0) {
|
|
|
WriteLog("提示:sqlT==%s\n", sql);
|
|
|
WriteLog("提示:sqlT==%s\n", sql);
|
|
|
// 初始化 OCILIB 环境
|
|
|
if (!OCI_Initialize(nullptr, nullptr, OCI_ENV_DEFAULT)) {
|
|
|
std::cerr << "OCILIB 初始化失败" << std::endl;
|
|
|
}
|
|
|
OracleDB db;
|
|
|
boolean status = db.connect(c_sql_values[1], c_sql_values[2], c_sql_values[0]);
|
|
|
if (!status) { // 替换为实际的连接信息
|
|
|
std::cerr << "数据库连接失败" << std::endl;
|
|
|
OCI_Cleanup();
|
|
|
}
|
|
|
else {
|
|
|
if (db.executeQuery(sql, &outputColumn, &outputValueCount, &outputValue) == -1 || outputValueCount == 0)
|
|
|
{
|
|
|
WriteLog("提示:物料分类查询 失败, %s \n", sql);
|
|
|
if (field1 != NULL) {
|
|
|
char sql2[128] = "\0";
|
|
|
sprintf(sql2, "select PCLASSCODE,PCLASSNAME from PLM_ERP_CLASS_TABLE where PFIELD01= '%s'", field1);
|
|
|
WriteLog("提示:sql2T==%s\n", sql2);
|
|
|
if (db.executeQuery(sql2, &outputColumn, &outputValueCount, &outputValue) == -1)
|
|
|
{
|
|
|
WriteLog("提示:物料分类查询 失败, %s \n", sql2);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
db.disconnect();
|
|
|
WriteLog("outputValueCount=%d\n", outputValueCount);
|
|
|
WriteLog("outputColumn=%d\n", outputColumn);
|
|
|
//free(sql);
|
|
|
if (outputValueCount > 0) {
|
|
|
*classCode = outputValue[0][0];
|
|
|
WriteLog("物料分类====%s\n", *classCode);
|
|
|
}
|
|
|
else {
|
|
|
|
|
|
errMsg.append(itemId1);
|
|
|
errMsg.append("物料分类查询失败,请检查表PLM_ERP_FACTORY_TABLE");
|
|
|
//EMH_store_error_s2(EMH_severity_error, 919031, errMsg.c_str(), "失败");
|
|
|
if (outputValue != NULL) {
|
|
|
DOFREE(outputValue);
|
|
|
}
|
|
|
if (field1 != NULL) {
|
|
|
DOFREE(field1);
|
|
|
}
|
|
|
if (field2 != NULL) {
|
|
|
DOFREE(field2);
|
|
|
}
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
if (outputValue != NULL) {
|
|
|
DOFREE(outputValue);
|
|
|
}
|
|
|
if (field1 != NULL) {
|
|
|
DOFREE(field1);
|
|
|
}
|
|
|
if (field2 != NULL) {
|
|
|
DOFREE(field2);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
void getBomLinePropertyNewRule(tag_t topLine, char** c_sql_values, vector<string>* parameters_vec, map<string, map<string, int>> classMap, map<string, vector<string>> factoryMap, map<string, string> unitMap,string& errMsg,char* itemId1)
|
|
|
{
|
|
|
WriteLog("开始获取子件信息\n");
|
|
|
tag_t fu_rev = NULLTAG;
|
|
|
AOM_ask_value_tag(topLine, "bl_line_object", &fu_rev);
|
|
|
|
|
|
tag_t* children_line = NULLTAG;
|
|
|
int count = 0;
|
|
|
|
|
|
BOM_line_ask_all_child_lines(topLine, &count, &children_line);
|
|
|
if (count > 0) {
|
|
|
|
|
|
char* fu_item_id = NULL;
|
|
|
char* fu_smzqzt = NULL;
|
|
|
char* fu_item_revision_id = NULL;
|
|
|
char* fu_object_name = NULL;
|
|
|
char* fu_object_type = NULL;
|
|
|
char* fu_cph = NULL;
|
|
|
char** fu_scgc = NULL;
|
|
|
int factoryCount = 0;
|
|
|
ITKCALL(AOM_UIF_ask_value(fu_rev, "item_id", &fu_item_id));
|
|
|
|
|
|
ITKCALL(AOM_UIF_ask_value(fu_rev, "item_revision_id", &fu_item_revision_id));
|
|
|
ITKCALL(AOM_UIF_ask_value(fu_rev, "object_name", &fu_object_name));
|
|
|
ITKCALL(AOM_UIF_ask_value(fu_rev, "rb3_cph", &fu_cph));
|
|
|
char* itemType = NULL;
|
|
|
AOM_ask_value_string(fu_rev, "object_type", &itemType);
|
|
|
|
|
|
|
|
|
if (strcmp("RB3_GNLBJRevision", itemType) == 0) {
|
|
|
ITKCALL(AOM_UIF_ask_value(fu_rev, "rb3_smzqtz", &fu_smzqzt));
|
|
|
}
|
|
|
else {
|
|
|
ITKCALL(AOM_UIF_ask_value(fu_rev, "rb3_smzqzt", &fu_smzqzt));
|
|
|
}
|
|
|
|
|
|
|
|
|
if (strcmp("RB3_XZCPRevision", itemType) == 0 || strcmp("RB3_XZLBJRevision", itemType) == 0) {
|
|
|
ITKCALL(AOM_UIF_ask_values(fu_rev, "rb3_xzscgc", &factoryCount, &fu_scgc));
|
|
|
}
|
|
|
else if (strcmp("RB3_GNZCRevision", itemType) == 0 || strcmp("RB3_GNLBJRevision", itemType) == 0
|
|
|
|| strcmp("RB3_GYZYRevision", itemType) == 0 || strcmp("RB3_BZJRevision", itemType) == 0) {
|
|
|
ITKCALL(AOM_UIF_ask_values(fu_rev, "rb3_scgc", &factoryCount, &fu_scgc));
|
|
|
}
|
|
|
else if (strcmp("RB3_YCLRevision", itemType) == 0 || strcmp("RB3_XJRevision", itemType) == 0 || strcmp("RB3_WJTLRevision", itemType) == 0 || strcmp("RB3_SLRevision", itemType) == 0) {
|
|
|
ITKCALL(AOM_UIF_ask_values(fu_rev, "rb3_sygc1", &factoryCount, &fu_scgc));
|
|
|
}
|
|
|
else {
|
|
|
ITKCALL(AOM_UIF_ask_values(fu_rev, "rb3_scgc1", &factoryCount, &fu_scgc));
|
|
|
}
|
|
|
ITKCALL(AOM_ask_value_string(fu_rev, "object_type", &fu_object_type));
|
|
|
|
|
|
WriteLog("111\n");
|
|
|
char facttoryNameStr[20000] = "\0";
|
|
|
char factoryCodeStr[20000] = "\0";
|
|
|
char organizeNameStr[20000] = "\0";
|
|
|
char organizeCodeStr[30000] = "\0";
|
|
|
WriteLog("222\n");
|
|
|
//这里写服务名,不能用实例名(名称相同除外)
|
|
|
//工厂组织编码特殊处理,通过数据库表匹配
|
|
|
|
|
|
for (int i = 0; i < factoryCount; i++)
|
|
|
{
|
|
|
if (factoryMap.find(fu_scgc[i]) == factoryMap.end()) {
|
|
|
char* factoryCode = NULL;
|
|
|
char* factoryName = NULL;
|
|
|
int factoryColumn = 0, factoryValueCount = 0;
|
|
|
char*** factoryValue = NULL;
|
|
|
char factorySql[128] = "\0";
|
|
|
if (fu_scgc[i] == NULL || strcmp(fu_scgc[i], "") == 0 || strcmp(fu_scgc[i], "0") == 0) {
|
|
|
sprintf(factorySql, "select PFACTORYCODE,PFACTORYNAME from PLM_ERP_FACTORY_TABLE where PFACTORY= 'globa100'");
|
|
|
|
|
|
}
|
|
|
else {
|
|
|
sprintf(factorySql, "select PFACTORYCODE,PFACTORYNAME from PLM_ERP_FACTORY_TABLE where PFACTORY= '%s'", fu_scgc[i]);
|
|
|
|
|
|
}
|
|
|
WriteLog("提示:factorySql==%s\n", factorySql);
|
|
|
if (!OCI_Initialize(nullptr, nullptr, OCI_ENV_DEFAULT)) {
|
|
|
std::cerr << "OCILIB 初始化失败" << std::endl;
|
|
|
}
|
|
|
OracleDB db;
|
|
|
boolean status = db.connect(c_sql_values[1], c_sql_values[2], c_sql_values[0]);
|
|
|
if (!status) { // 替换为实际的连接信息
|
|
|
std::cerr << "数据库连接失败" << std::endl;
|
|
|
OCI_Cleanup();
|
|
|
}
|
|
|
else {
|
|
|
if (db.executeQuery(factorySql, &factoryColumn, &factoryValueCount, &factoryValue) == -1)
|
|
|
{
|
|
|
WriteLog("提示:组织编码查询 失败, %s \n", factorySql);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
db.disconnect();
|
|
|
//WriteLog("factoryValueCount=%d\n", factoryValueCount);
|
|
|
//WriteLog("factoryColumn=%d\n", factoryColumn);
|
|
|
if (factoryValueCount > 0) {
|
|
|
factoryCode = factoryValue[0][0];
|
|
|
factoryName = factoryValue[0][1];
|
|
|
vector<string> factoryVec;
|
|
|
factoryVec.push_back(factoryCode);
|
|
|
factoryVec.push_back(factoryName);
|
|
|
factoryMap[fu_scgc[i]] = factoryVec;
|
|
|
//WriteLog("组织编码====%s\n", factoryCode);
|
|
|
//WriteLog("组织名称====%s\n", factoryName);
|
|
|
if (strcmp(facttoryNameStr, "") != 0) {
|
|
|
strcat(facttoryNameStr, ",");
|
|
|
strcat(factoryCodeStr, ",");
|
|
|
}
|
|
|
if (factoryName != NULL) {
|
|
|
strcat(facttoryNameStr, factoryName);
|
|
|
}
|
|
|
if (factoryCode != NULL) {
|
|
|
strcat(factoryCodeStr, factoryCode);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else {
|
|
|
|
|
|
|
|
|
errMsg.append(itemId1);
|
|
|
errMsg.append("组织编码查询失败,请检查表PLM_ERP_FACTORY_TABLE");
|
|
|
//EMH_store_error_s2(EMH_severity_error, 919031, errMsg.c_str(), "失败");
|
|
|
if (factoryValue != NULL) {
|
|
|
DOFREE(factoryValue);
|
|
|
}
|
|
|
if (factoryCode != NULL) {
|
|
|
DOFREE(factoryCode);
|
|
|
}
|
|
|
if (factoryName != NULL) {
|
|
|
DOFREE(factoryName);
|
|
|
}
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
if (factoryValue != NULL) {
|
|
|
DOFREE(factoryValue);
|
|
|
}
|
|
|
if (factoryCode != NULL) {
|
|
|
DOFREE(factoryCode);
|
|
|
}
|
|
|
if (factoryName != NULL) {
|
|
|
DOFREE(factoryName);
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
vector<string> factoryVec = factoryMap[fu_scgc[i]];
|
|
|
if (strcmp(facttoryNameStr, "") != 0) {
|
|
|
strcat(facttoryNameStr, ",");
|
|
|
strcat(factoryCodeStr, ",");
|
|
|
}
|
|
|
strcat(factoryCodeStr, factoryVec[0].c_str());
|
|
|
strcat(facttoryNameStr, factoryVec[1].c_str());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
char* fu_class_code = NULL;
|
|
|
tag_t fu_ico_tag = NULLTAG;
|
|
|
char* fu_class_id = NULL;
|
|
|
map<string, int> fuAttrMap;
|
|
|
ICS_ask_classification_object(fu_rev, &fu_ico_tag);
|
|
|
if (fu_ico_tag != NULLTAG) {
|
|
|
ICS_ico_ask_class(fu_ico_tag, &fu_class_id);
|
|
|
WriteLog(">> fu_class_id: %s\n", fu_class_id);
|
|
|
fuAttrMap = getClassAttrMapRule(classMap, fu_class_id);
|
|
|
}
|
|
|
getItemClassRule(c_sql_values, fu_object_type, fu_ico_tag, fu_rev, fuAttrMap, fu_class_id, &fu_class_code,errMsg,itemId1);
|
|
|
|
|
|
if (errMsg.size() > 0) {
|
|
|
if (fu_class_code != NULL) {
|
|
|
DOFREE(fu_class_code);
|
|
|
}
|
|
|
if (fu_class_id != NULL) {
|
|
|
DOFREE(fu_class_id);
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
//处理组织工厂逻辑
|
|
|
char* organizeCode = NULL;
|
|
|
char* organizeName = NULL;
|
|
|
char* organizeFactory = NULL;
|
|
|
char factorySql2[128] = "\0";
|
|
|
int organizeColumn = 0, organizeValueCount = 0;
|
|
|
char*** organizeValue = NULL;
|
|
|
WriteLog("fu_object_type: %s\n", fu_object_type);
|
|
|
WriteLog("fu_class_code: %s\n", fu_class_code);
|
|
|
WriteLog("fu_item_id: %s\n", fu_item_id);
|
|
|
if (strcmp("RB3_LBJRevision", fu_object_type) == 0) {
|
|
|
sprintf(factorySql2, "select PFACTORY,PFACTORYCODE,PFACTORYNAME from PLM_FACTORY_ORGANIZE_TABLE where CLASSCODE= '%s'", fu_class_code);
|
|
|
WriteLog("提示:factorySql2==%s\n", factorySql2);
|
|
|
if (!OCI_Initialize(nullptr, nullptr, OCI_ENV_DEFAULT)) {
|
|
|
std::cerr << "OCILIB 初始化失败" << std::endl;
|
|
|
}
|
|
|
OracleDB db;
|
|
|
boolean status = db.connect(c_sql_values[1], c_sql_values[2], c_sql_values[0]);
|
|
|
if (!status) { // 替换为实际的连接信息
|
|
|
std::cerr << "数据库连接失败" << std::endl;
|
|
|
OCI_Cleanup();
|
|
|
}
|
|
|
else {
|
|
|
|
|
|
|
|
|
if (db.executeQuery(factorySql2, &organizeColumn, &organizeValueCount, &organizeValue) == -1)
|
|
|
{
|
|
|
WriteLog("提示:组织编码查询 失败, %s \n", factorySql2);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
db.disconnect();
|
|
|
//WriteLog("factoryValueCount=%d\n", organizeValueCount);
|
|
|
//WriteLog("factoryColumn=%d\n", organizeColumn);
|
|
|
if (organizeValueCount > 0) {
|
|
|
organizeFactory = organizeValue[0][0];
|
|
|
organizeCode = organizeValue[0][1];
|
|
|
organizeName = organizeValue[0][2];
|
|
|
WriteLog("组织工厂====%s\n", organizeFactory);
|
|
|
WriteLog("组织名称2====%s\n", organizeName);
|
|
|
WriteLog("组织编码2====%s\n", organizeCode);
|
|
|
}
|
|
|
else {
|
|
|
strcpy(organizeNameStr, facttoryNameStr);
|
|
|
strcpy(organizeCodeStr, factoryCodeStr);
|
|
|
|
|
|
}
|
|
|
if (organizeFactory != NULL && strcmp("", organizeFactory) != 0 && strcmp("NULL", organizeFactory) != 0) {
|
|
|
strcpy(organizeNameStr, facttoryNameStr);
|
|
|
strcpy(organizeCodeStr, factoryCodeStr);
|
|
|
}
|
|
|
if (organizeName != NULL && strcmp("NULL", organizeName) != 0 && strcmp("", organizeName) != 0) {
|
|
|
if (strcmp(organizeNameStr, "") != 0) {
|
|
|
strcat(organizeNameStr, ",");
|
|
|
}
|
|
|
strcat(organizeNameStr, organizeName);
|
|
|
}
|
|
|
if (organizeCode != NULL && strcmp("NULL", organizeCode) != 0 && strcmp("", organizeCode) != 0) {
|
|
|
if (strcmp(organizeCodeStr, "") != 0) {
|
|
|
strcat(organizeCodeStr, ",");
|
|
|
}
|
|
|
strcat(organizeCodeStr, organizeCode);
|
|
|
}
|
|
|
}
|
|
|
else if (strcmp("RB3_XZCPRevision", fu_object_type) == 0) {
|
|
|
char* field1 = NULL;
|
|
|
int outputColumn = 0, outputValueCount = 0;
|
|
|
char*** outputValue = NULL;
|
|
|
//物料分类特殊处理,通过数据库表匹配
|
|
|
char sql[1024] = "\0";
|
|
|
ITKCALL(AOM_UIF_ask_value(fu_rev, "rb3_cplx2", &field1));
|
|
|
if (!OCI_Initialize(nullptr, nullptr, OCI_ENV_DEFAULT)) {
|
|
|
std::cerr << "OCILIB 初始化失败" << std::endl;
|
|
|
}
|
|
|
OracleDB db;
|
|
|
boolean status = db.connect(c_sql_values[1], c_sql_values[2], c_sql_values[0]);
|
|
|
if (!status) { // 替换为实际的连接信息
|
|
|
std::cerr << "数据库连接失败" << std::endl;
|
|
|
OCI_Cleanup();
|
|
|
}
|
|
|
else {
|
|
|
|
|
|
if (db.executeQuery(sql, &outputColumn, &outputValueCount, &outputValue) == -1 || outputValueCount == 0)
|
|
|
{
|
|
|
WriteLog("提示:父级物料分类查询 失败, %s \n", sql);
|
|
|
strcpy(organizeNameStr, facttoryNameStr);
|
|
|
strcpy(organizeCodeStr, factoryCodeStr);
|
|
|
}
|
|
|
else {
|
|
|
//WriteLog("outputValueCount=%d\n", outputValueCount);
|
|
|
//WriteLog("outputColumn=%d\n", outputColumn);
|
|
|
//free(sql);
|
|
|
char* fuClassCode = NULL;
|
|
|
if (outputValueCount > 0) {
|
|
|
fuClassCode = outputValue[0][0];
|
|
|
//WriteLog("父级物料分类====%s\n", fuClassCode);
|
|
|
}
|
|
|
if (strcmp("IN07", fuClassCode) == 0) {
|
|
|
sprintf(factorySql2, "select PFACTORYCODE,PFACTORYNAME from PLM_FACTORY_ORGANIZE_TABLE where PTYPE= 'RB3_GNZCRevision' and PFIELD01= '滚动体类'");
|
|
|
WriteLog("提示:factorySql2==%s\n", factorySql2);
|
|
|
if (db.executeQuery(factorySql2, &organizeColumn, &organizeValueCount, &organizeValue) == -1)
|
|
|
{
|
|
|
WriteLog("提示:组织编码查询 失败, %s \n", factoryCodeStr);
|
|
|
}
|
|
|
//WriteLog("factoryValueCount=%d\n", organizeValueCount);
|
|
|
//WriteLog("factoryColumn=%d\n", organizeColumn);
|
|
|
if (organizeValueCount > 0) {
|
|
|
organizeCode = organizeValue[0][0];
|
|
|
organizeName = organizeValue[0][1];
|
|
|
WriteLog("组织名称2====%s\n", organizeName);
|
|
|
WriteLog("组织编码2====%s\n", organizeCode);
|
|
|
}
|
|
|
else {
|
|
|
strcpy(organizeNameStr, facttoryNameStr);
|
|
|
strcpy(organizeCodeStr, factoryCodeStr);
|
|
|
|
|
|
}
|
|
|
if (organizeName != NULL && strcmp("NULL", organizeName) != 0) {
|
|
|
strcpy(organizeNameStr, organizeName);
|
|
|
}
|
|
|
if (organizeCode != NULL && strcmp("NULL", organizeCode) != 0) {
|
|
|
strcpy(organizeCodeStr, organizeCode);
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
strcpy(organizeNameStr, facttoryNameStr);
|
|
|
strcpy(organizeCodeStr, factoryCodeStr);
|
|
|
}
|
|
|
if (fuClassCode != NULL) {
|
|
|
DOFREE(fuClassCode);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
db.disconnect();
|
|
|
|
|
|
if (field1 != NULL) {
|
|
|
DOFREE(field1);
|
|
|
}
|
|
|
if (outputValue != NULL) {
|
|
|
DOFREE(outputValue);
|
|
|
}
|
|
|
}
|
|
|
else if (strcmp("RB3_BZJRevision", fu_object_type) == 0) {
|
|
|
char* field1 = NULL;
|
|
|
int outputColumn = 0, outputValueCount = 0;
|
|
|
char*** outputValue = NULL;
|
|
|
//物料分类特殊处理,通过数据库表匹配
|
|
|
char sql[1024] = "\0";
|
|
|
ITKCALL(AOM_UIF_ask_value(fu_rev, "object_name", &field1));
|
|
|
if (field1 != NULL) {
|
|
|
sprintf(sql, "select PCLASSCODE from PLM_ERP_CLASS_TABLE where PFIELD01= '%s'", field1);
|
|
|
}
|
|
|
if (!OCI_Initialize(nullptr, nullptr, OCI_ENV_DEFAULT)) {
|
|
|
std::cerr << "OCILIB 初始化失败" << std::endl;
|
|
|
}
|
|
|
OracleDB db;
|
|
|
boolean status = db.connect(c_sql_values[1], c_sql_values[2], c_sql_values[0]);
|
|
|
if (!status) { // 替换为实际的连接信息
|
|
|
std::cerr << "数据库连接失败" << std::endl;
|
|
|
OCI_Cleanup();
|
|
|
}
|
|
|
else {
|
|
|
if (db.executeQuery(sql, &outputColumn, &outputValueCount, &outputValue) == -1 || outputValueCount == 0)
|
|
|
{
|
|
|
WriteLog("提示:父级物料分类查询 失败, %s \n", sql);
|
|
|
strcpy(organizeNameStr, facttoryNameStr);
|
|
|
strcpy(organizeCodeStr, factoryCodeStr);
|
|
|
}
|
|
|
else {
|
|
|
//WriteLog("outputValueCount=%d\n", outputValueCount);
|
|
|
//WriteLog("outputColumn=%d\n", outputColumn);
|
|
|
//free(sql);
|
|
|
char* fuClassCode = NULL;
|
|
|
if (outputValueCount > 0) {
|
|
|
fuClassCode = outputValue[0][0];
|
|
|
//WriteLog("父级物料分类====%s\n", fuClassCode);
|
|
|
}
|
|
|
if (strcmp("IN07", fuClassCode) == 0) {
|
|
|
sprintf(factorySql2, "select PFACTORY,PFACTORYCODE,PFACTORYNAME from PLM_FACTORY_ORGANIZE_TABLE where CLASSCODE= '%s'", fuClassCode);
|
|
|
WriteLog("提示:factorySql2==%s\n", factorySql2);
|
|
|
|
|
|
|
|
|
if (db.executeQuery(factorySql2, &organizeColumn, &organizeValueCount, &organizeValue) == -1)
|
|
|
{
|
|
|
WriteLog("提示:组织编码查询 失败, %s \n", factoryCodeStr);
|
|
|
}
|
|
|
|
|
|
|
|
|
//WriteLog("factoryValueCount=%d\n", organizeValueCount);
|
|
|
//WriteLog("factoryColumn=%d\n", organizeColumn);
|
|
|
if (organizeValueCount > 0) {
|
|
|
organizeFactory = organizeValue[0][0];
|
|
|
organizeCode = organizeValue[0][1];
|
|
|
organizeName = organizeValue[0][2];
|
|
|
WriteLog("组织工厂====%s\n", organizeFactory);
|
|
|
WriteLog("组织名称2====%s\n", organizeName);
|
|
|
WriteLog("组织编码2====%s\n", organizeCode);
|
|
|
}
|
|
|
else {
|
|
|
strcpy(organizeNameStr, facttoryNameStr);
|
|
|
strcpy(organizeCodeStr, factoryCodeStr);
|
|
|
|
|
|
}
|
|
|
if (organizeFactory != NULL && strcmp("", organizeFactory) != 0 && strcmp("NULL", organizeFactory) != 0) {
|
|
|
strcpy(organizeNameStr, facttoryNameStr);
|
|
|
strcpy(organizeCodeStr, factoryCodeStr);
|
|
|
}
|
|
|
if (organizeName != NULL && strcmp("NULL", organizeName) != 0 && strcmp("", organizeName) != 0) {
|
|
|
if (strcmp(organizeNameStr, "") != 0) {
|
|
|
strcat(organizeNameStr, ",");
|
|
|
}
|
|
|
strcat(organizeNameStr, organizeName);
|
|
|
}
|
|
|
if (organizeCode != NULL && strcmp("NULL", organizeCode) != 0 && strcmp("", organizeCode) != 0) {
|
|
|
if (strcmp(organizeCodeStr, "") != 0) {
|
|
|
strcat(organizeCodeStr, ",");
|
|
|
}
|
|
|
strcat(organizeCodeStr, organizeCode);
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
strcpy(organizeNameStr, facttoryNameStr);
|
|
|
strcpy(organizeCodeStr, factoryCodeStr);
|
|
|
}
|
|
|
if (fuClassCode != NULL) {
|
|
|
DOFREE(fuClassCode);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
db.disconnect();
|
|
|
if (field1 != NULL) {
|
|
|
DOFREE(field1);
|
|
|
}
|
|
|
if (outputValue != NULL) {
|
|
|
DOFREE(outputValue);
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
strcpy(organizeNameStr, facttoryNameStr);
|
|
|
strcpy(organizeCodeStr, factoryCodeStr);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (organizeCode != NULL) {
|
|
|
DOFREE(organizeCode);
|
|
|
}
|
|
|
if (organizeName != NULL) {
|
|
|
DOFREE(organizeName);
|
|
|
}
|
|
|
if (organizeFactory != NULL) {
|
|
|
DOFREE(organizeFactory);
|
|
|
}
|
|
|
if (organizeValue != NULL) {
|
|
|
DOFREE(organizeValue);
|
|
|
}
|
|
|
if (fu_class_code != NULL) {
|
|
|
DOFREE(fu_class_code);
|
|
|
}
|
|
|
if (fu_class_id != NULL) {
|
|
|
DOFREE(fu_class_id);
|
|
|
}
|
|
|
DOFREE(facttoryNameStr);
|
|
|
DOFREE(factoryCodeStr);
|
|
|
|
|
|
WriteLog("count:%d\n", count);
|
|
|
// 初始化变量和预估最大长度
|
|
|
size_t buffer_size = 150000; // 初始大小,可根据实际情况调整
|
|
|
char* parameters = static_cast<char*>(malloc(buffer_size));
|
|
|
|
|
|
parameters[0] = '\0'; // 确保字符串以空字符开始
|
|
|
strcat(parameters, "{");
|
|
|
|
|
|
//AOM_ask_value_string(children_line[i], "fnd0bl_line_object_type", &itemType);
|
|
|
strcat(parameters, "\"parentPartCode\":\"");
|
|
|
strcat(parameters, fu_item_id == NULL ? "" : fu_item_id);
|
|
|
strcat(parameters, "\",");
|
|
|
strcat(parameters, "\"lifeCycleStages\":\"");
|
|
|
strcat(parameters, fu_smzqzt == NULL ? "" : fu_smzqzt);
|
|
|
strcat(parameters, "\",");
|
|
|
strcat(parameters, "\"version\":\"");
|
|
|
strcat(parameters, fu_item_revision_id == NULL ? "" : fu_item_revision_id);
|
|
|
strcat(parameters, "\",");
|
|
|
strcat(parameters, "\"componentType\":\"");
|
|
|
strcat(parameters, fu_object_name == NULL ? "" : fu_object_name);
|
|
|
strcat(parameters, "\",");
|
|
|
strcat(parameters, "\"bomProductNumber1\":\"");
|
|
|
strcat(parameters, fu_cph == NULL ? "" : fu_cph);
|
|
|
strcat(parameters, "\",");
|
|
|
strcat(parameters, "\"usingOrgName\":\"");
|
|
|
strcat(parameters, organizeNameStr == NULL ? "" : organizeNameStr);
|
|
|
strcat(parameters, "\",");
|
|
|
strcat(parameters, "\"usingOrgCode\":\"");
|
|
|
strcat(parameters, organizeCodeStr == NULL ? "" : organizeCodeStr);
|
|
|
strcat(parameters, "\",");
|
|
|
strcat(parameters, "\"bomDetail\":[");
|
|
|
|
|
|
DOFREE(organizeNameStr);
|
|
|
DOFREE(organizeCodeStr);
|
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
{
|
|
|
tag_t zi_rev = NULLTAG;
|
|
|
AOM_ask_value_tag(children_line[i], "bl_line_object", &zi_rev);
|
|
|
tag_t ico_tag = NULLTAG;
|
|
|
char* classId = NULL;
|
|
|
map<string, int> attrMap;
|
|
|
ICS_ask_classification_object(zi_rev, &ico_tag);
|
|
|
if (ico_tag != NULLTAG) {
|
|
|
ICS_ico_ask_class(ico_tag, &classId);
|
|
|
WriteLog(">> classId: %s\n", classId);
|
|
|
attrMap = getClassAttrMapRule(classMap, classId);
|
|
|
}
|
|
|
char* itemType = NULL;
|
|
|
AOM_ask_value_string(zi_rev, "object_type", &itemType);
|
|
|
WriteLog("object_type: %s\n", itemType);
|
|
|
char* zi_item_id = NULL;
|
|
|
char* zi_smzqzt = NULL;
|
|
|
char* zi_item_revision_id = NULL;
|
|
|
char* zi_object_name = NULL;
|
|
|
char* zi_cph = NULL;
|
|
|
ITKCALL(AOM_UIF_ask_value(zi_rev, "item_id", &zi_item_id));
|
|
|
|
|
|
|
|
|
if (strcmp("RB3_GNLBJRevision", itemType) == 0) {
|
|
|
ITKCALL(AOM_UIF_ask_value(zi_rev, "rb3_smzqtz", &fu_smzqzt));
|
|
|
}
|
|
|
else {
|
|
|
ITKCALL(AOM_UIF_ask_value(zi_rev, "rb3_smzqzt", &zi_smzqzt));
|
|
|
}
|
|
|
|
|
|
|
|
|
ITKCALL(AOM_UIF_ask_value(zi_rev, "item_revision_id", &zi_item_revision_id));
|
|
|
ITKCALL(AOM_UIF_ask_value(zi_rev, "object_name", &zi_object_name));
|
|
|
ITKCALL(AOM_UIF_ask_value(zi_rev, "rb3_cph", &zi_cph));
|
|
|
char* zi_uom = NULL;
|
|
|
char* zi_quantity = NULL;
|
|
|
ITKCALL(AOM_UIF_ask_value(children_line[i], "bl_uom", &zi_uom));
|
|
|
ITKCALL(AOM_UIF_ask_value(children_line[i], "bl_quantity", &zi_quantity));
|
|
|
strcat(parameters, "{");
|
|
|
strcat(parameters, "\"componentCode\":\"");
|
|
|
strcat(parameters, zi_item_id == NULL ? "" : zi_item_id);
|
|
|
strcat(parameters, "\",");
|
|
|
strcat(parameters, "\"theLifecycle\":\"");
|
|
|
strcat(parameters, zi_smzqzt == NULL ? "" : zi_smzqzt);
|
|
|
strcat(parameters, "\",");
|
|
|
strcat(parameters, "\"bomObjectVersion\":\"");
|
|
|
strcat(parameters, zi_item_revision_id == NULL ? "" : zi_item_revision_id);
|
|
|
strcat(parameters, "\",");
|
|
|
strcat(parameters, "\"bomObjectType\":\"");
|
|
|
strcat(parameters, zi_object_name == NULL ? "" : zi_object_name);
|
|
|
strcat(parameters, "\",");
|
|
|
strcat(parameters, "\"bomProductNumber\":\"");
|
|
|
strcat(parameters, zi_cph == NULL ? "" : zi_cph);
|
|
|
strcat(parameters, "\",");
|
|
|
strcat(parameters, "\"bomQuantity\":");
|
|
|
strcat(parameters, zi_quantity == NULL ? "" : zi_quantity);
|
|
|
strcat(parameters, ",");
|
|
|
char* classCode = NULL;
|
|
|
getItemClassRule(c_sql_values, itemType, ico_tag, zi_rev, attrMap, classId, &classCode,errMsg,itemId1);
|
|
|
|
|
|
|
|
|
if (errMsg.size() > 0) {
|
|
|
//EMH_store_error_s2(EMH_severity_error, 919031, errMsg.c_str(), "失败");
|
|
|
if (zi_item_id != NULL)
|
|
|
{
|
|
|
DOFREE(fu_item_id);
|
|
|
}
|
|
|
if (zi_smzqzt != NULL)
|
|
|
{
|
|
|
DOFREE(fu_smzqzt);
|
|
|
}
|
|
|
if (zi_item_revision_id != NULL)
|
|
|
{
|
|
|
DOFREE(fu_item_revision_id);
|
|
|
}
|
|
|
if (zi_object_name != NULL)
|
|
|
{
|
|
|
DOFREE(fu_object_name);
|
|
|
}
|
|
|
if (zi_cph != NULL)
|
|
|
{
|
|
|
DOFREE(fu_cph);
|
|
|
}
|
|
|
if (zi_uom != NULL)
|
|
|
{
|
|
|
DOFREE(zi_uom);
|
|
|
}
|
|
|
if (zi_quantity != NULL)
|
|
|
{
|
|
|
DOFREE(zi_quantity);
|
|
|
}
|
|
|
if (classCode != NULL)
|
|
|
{
|
|
|
DOFREE(classCode);
|
|
|
}
|
|
|
if (itemType != NULL) {
|
|
|
DOFREE(itemType);
|
|
|
}
|
|
|
if (fu_item_id != NULL)
|
|
|
{
|
|
|
DOFREE(fu_item_id);
|
|
|
}
|
|
|
if (fu_smzqzt != NULL)
|
|
|
{
|
|
|
DOFREE(fu_smzqzt);
|
|
|
}
|
|
|
if (fu_item_revision_id != NULL)
|
|
|
{
|
|
|
DOFREE(fu_item_revision_id);
|
|
|
}
|
|
|
if (fu_object_name != NULL)
|
|
|
{
|
|
|
DOFREE(fu_object_name);
|
|
|
}
|
|
|
if (fu_cph != NULL)
|
|
|
{
|
|
|
DOFREE(fu_cph);
|
|
|
}
|
|
|
if (fu_scgc != NULL)
|
|
|
{
|
|
|
DOFREE(fu_scgc);
|
|
|
}
|
|
|
if (fu_object_type != NULL)
|
|
|
{
|
|
|
DOFREE(fu_object_type);
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//处理子件单位转换逻辑
|
|
|
if (strstr(zi_uom, "比例系数") != NULL) {
|
|
|
strcat(parameters, "\"parentItemBase\":1,");
|
|
|
}
|
|
|
else {
|
|
|
WriteLog("zi_uom111 = %s \n", zi_uom);
|
|
|
WriteLog("classCode111 = %s \n", classCode);
|
|
|
if (classCode != NULL) {
|
|
|
if (strcmp("IN07", classCode) == 0 && strstr("L(粒)", zi_uom) != NULL)
|
|
|
{
|
|
|
zi_uom = "WL(万粒)";
|
|
|
strcat(parameters, "\"parentItemBase\":10000,");
|
|
|
}
|
|
|
else if ((strcmp("IN01", classCode) == 0 || strcmp("IN56", classCode) == 0 || strcmp("IN59", classCode) == 0) && strstr("GM(克)", zi_uom) != NULL)
|
|
|
{
|
|
|
zi_uom = "T(吨)";
|
|
|
strcat(parameters, "\"parentItemBase\":1000000,");
|
|
|
}
|
|
|
else if (strcmp("IN12", classCode) == 0 && strstr("GM(克)", zi_uom) != NULL)
|
|
|
{
|
|
|
zi_uom = "KG(千克)";
|
|
|
strcat(parameters, "\"parentItemBase\":1000,");
|
|
|
}
|
|
|
else {
|
|
|
strcat(parameters, "\"parentItemBase\":1,");
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
strcat(parameters, "\"parentItemBase\":1,");
|
|
|
}
|
|
|
}
|
|
|
strcat(parameters, "\"bomUnit\":\"");
|
|
|
if (unitMap.find(zi_uom) != unitMap.end()) {
|
|
|
strcat(parameters, unitMap[zi_uom].c_str());
|
|
|
}
|
|
|
else {
|
|
|
strcat(parameters, zi_uom);
|
|
|
}
|
|
|
strcat(parameters, "\"");
|
|
|
strcat(parameters, "}");
|
|
|
//WriteLog("parameters%d:%s\n", i,parameters);
|
|
|
if (i < count - 1) {
|
|
|
strcat(parameters, ",");
|
|
|
}
|
|
|
if (zi_item_id != NULL)
|
|
|
{
|
|
|
DOFREE(fu_item_id);
|
|
|
}
|
|
|
if (zi_smzqzt != NULL)
|
|
|
{
|
|
|
DOFREE(fu_smzqzt);
|
|
|
}
|
|
|
if (zi_item_revision_id != NULL)
|
|
|
{
|
|
|
DOFREE(fu_item_revision_id);
|
|
|
}
|
|
|
if (zi_object_name != NULL)
|
|
|
{
|
|
|
DOFREE(fu_object_name);
|
|
|
}
|
|
|
if (zi_cph != NULL)
|
|
|
{
|
|
|
DOFREE(fu_cph);
|
|
|
}
|
|
|
if (zi_uom != NULL)
|
|
|
{
|
|
|
DOFREE(zi_uom);
|
|
|
}
|
|
|
if (zi_quantity != NULL)
|
|
|
{
|
|
|
DOFREE(zi_quantity);
|
|
|
}
|
|
|
if (classCode != NULL)
|
|
|
{
|
|
|
DOFREE(classCode);
|
|
|
}
|
|
|
if (itemType != NULL) {
|
|
|
DOFREE(itemType);
|
|
|
}
|
|
|
}
|
|
|
if (fu_item_id != NULL)
|
|
|
{
|
|
|
DOFREE(fu_item_id);
|
|
|
}
|
|
|
if (fu_smzqzt != NULL)
|
|
|
{
|
|
|
DOFREE(fu_smzqzt);
|
|
|
}
|
|
|
if (fu_item_revision_id != NULL)
|
|
|
{
|
|
|
DOFREE(fu_item_revision_id);
|
|
|
}
|
|
|
if (fu_object_name != NULL)
|
|
|
{
|
|
|
DOFREE(fu_object_name);
|
|
|
}
|
|
|
if (fu_cph != NULL)
|
|
|
{
|
|
|
DOFREE(fu_cph);
|
|
|
}
|
|
|
if (fu_scgc != NULL)
|
|
|
{
|
|
|
DOFREE(fu_scgc);
|
|
|
}
|
|
|
if (fu_object_type != NULL)
|
|
|
{
|
|
|
DOFREE(fu_object_type);
|
|
|
}
|
|
|
strcat(parameters, "]}");
|
|
|
parameters_vec->push_back(parameters);
|
|
|
free(parameters);
|
|
|
}
|
|
|
for (int i = 0; i < count; i++)
|
|
|
{
|
|
|
int child_count = 0;
|
|
|
tag_t* zi_children_line = NULLTAG;
|
|
|
BOM_line_ask_all_child_lines(children_line[i], &child_count, &zi_children_line);
|
|
|
if (child_count > 0) {
|
|
|
getBomLinePropertyNewRule(children_line[i], c_sql_values, parameters_vec, classMap, factoryMap, unitMap,errMsg,itemId1);
|
|
|
}
|
|
|
}
|
|
|
if (children_line != NULL)
|
|
|
{
|
|
|
DOFREE(children_line);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int RB_SendErpBom_New_Rule(EPM_rule_message_t msg)
|
|
|
{
|
|
|
|
|
|
char* log_file = NULL;
|
|
|
printf("创建日志文件\n");
|
|
|
//char* TO_SRM = (char*)malloc(sizeof("TO_SRM"));
|
|
|
char tc_log_file_name[200] = "";
|
|
|
strcpy(tc_log_file_name, "RB_SendErpBom_New_Rule");
|
|
|
CreateLogFile(tc_log_file_name, &log_file);
|
|
|
|
|
|
|
|
|
WriteLog("=========================BOM下发到ERP rule Start===================\n");
|
|
|
string errMsg = "";
|
|
|
|
|
|
//POM_AM__set_application_bypass(true);
|
|
|
int ifail = EPM_go;
|
|
|
int attachments_num = 0;
|
|
|
tag_t rootTask = NULLTAG, * attachments = NULLTAG;
|
|
|
//获取任务对象
|
|
|
EPM_ask_root_task(msg.task, &rootTask);
|
|
|
//获取任务目标对象
|
|
|
EPM_ask_attachments(rootTask, EPM_target_attachment, &attachments_num, &attachments);
|
|
|
char* job_name = NULL;
|
|
|
ITKCALL(AOM_ask_value_string(rootTask, "job_name", &job_name));
|
|
|
WriteLog("流程名称:%s\n", job_name);
|
|
|
int email_count = 0;
|
|
|
char** email_values;
|
|
|
ITKCALL(PREF_ask_char_values("RB_SEND_ERP_EMAIL", &email_count, &email_values));
|
|
|
|
|
|
vector<string> mail_addrs;
|
|
|
|
|
|
if (email_count > 0) {
|
|
|
|
|
|
int valueCount = 0;
|
|
|
char** valueChar = new char* [128];
|
|
|
//分割字符串
|
|
|
split(email_values[0], ";", valueChar, &valueCount);
|
|
|
for (int i = 0; i < valueCount; i++) {
|
|
|
mail_addrs.push_back(valueChar[i]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
int user_cnt = mail_addrs.size();
|
|
|
WriteLog("user_cnt===%d\n", user_cnt);
|
|
|
|
|
|
int c_sql_value_count = 0;
|
|
|
char** c_sql_values;
|
|
|
ITKCALL(PREF_ask_char_values("RB3_SQL_Connect2", &c_sql_value_count, &c_sql_values));
|
|
|
if (c_sql_value_count != 3)
|
|
|
{
|
|
|
WriteLog("首选项 RB3_SQL_Connect2 配置错误 数量%d ", c_sql_value_count);
|
|
|
CloseLog();
|
|
|
return 1;
|
|
|
}
|
|
|
int unit_pref_cnt = 0;
|
|
|
char** unit_pref_vals = NULL;
|
|
|
//获取首选项的值
|
|
|
PREF_ask_char_values("RB_SEND_UNIT_MATCHING", &unit_pref_cnt, &unit_pref_vals);
|
|
|
map<string, string> unitMap;
|
|
|
for (int i = 0; i < unit_pref_cnt; i++)
|
|
|
{
|
|
|
if (strstr(unit_pref_vals[i], "=") != NULL)
|
|
|
{
|
|
|
//按照-进行拆分。拆分条件
|
|
|
int valueCount = 0;
|
|
|
char** valueChar = new char* [64];
|
|
|
//分割字符串
|
|
|
split(unit_pref_vals[i], "=", valueChar, &valueCount);
|
|
|
unitMap[valueChar[0]] = valueChar[1];
|
|
|
DOFREE(valueChar);
|
|
|
}
|
|
|
}
|
|
|
char* tc_root_file = getenv("tc_root"); //C:\Siemens\Teamcenter11
|
|
|
|
|
|
char errorMessage[100000] = "";//写入到文件的值
|
|
|
for (int i = 0; i < attachments_num; i++)
|
|
|
{
|
|
|
char* itemType = NULL;
|
|
|
AOM_ask_value_string(attachments[i], "object_type", &itemType);
|
|
|
WriteLog("itemType:%s\n", itemType);
|
|
|
|
|
|
//过滤掉非版本的对象
|
|
|
//20250721 增加传递类型
|
|
|
if (strcmp(itemType, "RB3_BZJBJRevision") == 0 || strcmp(itemType, "RB3_BZJRevision") == 0 || strcmp(itemType, "RB3_GNLBJRevision") == 0 || strcmp(itemType, "RB3_GNZCRevision") == 0 || strcmp(itemType, "RB3_GQBJRevision") == 0 || strcmp(itemType, "RB3_GQRevision") == 0 || strcmp(itemType, "RB3_GZBJRevision") == 0 || strcmp(itemType, "RB3_GZRevision") == 0 || strcmp(itemType, "RB3_LBJRevision") == 0 || strcmp(itemType, "RB3_SLRevision") == 0 || strcmp(itemType, "RB3_TJJRevision") == 0 || strcmp(itemType, "RB3_TXTRevision") == 0 || strcmp(itemType, "RB3_WJTLRevision") == 0 || strcmp(itemType, "RB3_XJRevision") == 0 || strcmp(itemType, "RB3_XZCPRevision") == 0 || strcmp(itemType, "RB3_XZLBJRevision") == 0 || strcmp(itemType, "RB3_YCLRevision") == 0 || strcmp(itemType, "RB3_YZRevision") == 0 || strcmp(itemType, "RB3_ZCRevision") == 0)
|
|
|
{
|
|
|
char* itemId1 = NULL;
|
|
|
AOM_ask_value_string(attachments[i], "item_id", &itemId1);
|
|
|
WriteLog("itemId1:%s\n", itemId1);
|
|
|
//获取子项
|
|
|
tag_t top_line = NULLTAG, window = NULLTAG;
|
|
|
BOM_create_window(&window);
|
|
|
//设置顶层BOM
|
|
|
BOM_set_window_top_line(window, NULLTAG, attachments[i], NULLTAG, &top_line);
|
|
|
//获取单个的json字符串
|
|
|
vector<string> parameters_vec;
|
|
|
map<string, map<string, int>> classMap;
|
|
|
map<string, vector<string>> factoryMap;
|
|
|
WriteLog("=========================遍历获取子件信息===================\n");
|
|
|
getBomLinePropertyNewRule(top_line, c_sql_values, ¶meters_vec, classMap, factoryMap, unitMap, errMsg,itemId1);
|
|
|
if (errMsg.size() > 0) {
|
|
|
//EMH_store_error_s2(EMH_severity_error, 919031, errMsg.c_str(), "失败");
|
|
|
EMH_store_error_s2(EMH_severity_error, 919031, errMsg.c_str(), "失败");
|
|
|
DOFREE(itemType);
|
|
|
MEM_free(attachments);
|
|
|
MEM_free(c_sql_values);
|
|
|
|
|
|
|
|
|
//发邮件
|
|
|
WriteLog("发送邮件:%d", user_cnt);
|
|
|
for (int i = 0; i < user_cnt; i++) {
|
|
|
char cmd[10240] = ""; // 64KB
|
|
|
char jarfile[512] = "";
|
|
|
string mail_addr = mail_addrs[i];
|
|
|
if (mail_addr.size() > 0) {
|
|
|
WriteLog(">> %d. 发送邮件给[%s]", i + 1, mail_addr.c_str());
|
|
|
sprintf(jarfile, "%s\\bin\\EMailSender.jar", getenv("TC_ROOT"));
|
|
|
strcpy_s(cmd, "java -jar ");
|
|
|
strcat_s(cmd, jarfile);
|
|
|
strcat_s(cmd, " \"");
|
|
|
strcat_s(cmd, mail_addr.c_str());
|
|
|
strcat_s(cmd, "\" \"【TeamCenter】传递ERP-BOM提醒\" \"");
|
|
|
strcat_s(cmd, job_name);
|
|
|
strcat_s(cmd, ":组织数据失败->");
|
|
|
strcat_s(cmd, errMsg.c_str());
|
|
|
strcat_s(cmd, "\"");
|
|
|
WriteLog("CMD:%s", cmd);
|
|
|
system(cmd);
|
|
|
WriteLog("执行完成");
|
|
|
}
|
|
|
DOFREE(cmd);
|
|
|
}
|
|
|
|
|
|
return EPM_go;
|
|
|
}
|
|
|
|
|
|
|
|
|
DOFREE(itemType);
|
|
|
char parameters[100000] = "";//写入到文件的值
|
|
|
strcat(parameters, "{\"data\":[");
|
|
|
for (int i = 0; i < parameters_vec.size(); i++)
|
|
|
{
|
|
|
strcat(parameters, parameters_vec[i].c_str());
|
|
|
if (i < parameters_vec.size() - 1) {
|
|
|
strcat(parameters, ",");
|
|
|
}
|
|
|
}
|
|
|
strcat(parameters, "],\"control\":{\"keydata\":null,\"ifid\": null,\"ifno\":\"JDE_MDM_BOM_01\",\"suser\": null,\"sysid\": null}}");
|
|
|
//获取当前时间
|
|
|
time_t now = time(0);
|
|
|
tm* p = localtime(&now);
|
|
|
|
|
|
char date[128] = "";
|
|
|
sprintf_s(date, "%04d%02d%02d%02d%02d%02d", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
|
|
|
|
|
|
//把数据用写入文件
|
|
|
char data_file[SS_MAXPATHLEN] = "";
|
|
|
strcat(data_file, tc_root_file);
|
|
|
strcat(data_file, "\\");
|
|
|
strcat(data_file, date);
|
|
|
strcat(data_file, ".txt");
|
|
|
WriteLog("data_file: %s\n", data_file);
|
|
|
ofstream file;
|
|
|
file.open(data_file);
|
|
|
file << parameters << endl; // 使用与cout同样的方式进行写入
|
|
|
file.close();
|
|
|
|
|
|
string strResult;
|
|
|
|
|
|
//cmd指令
|
|
|
char cmd[256] = "";
|
|
|
strcpy(cmd, "java -jar \"");
|
|
|
////strcat(cmd, jar_file);
|
|
|
strcat(cmd, tc_root_file);
|
|
|
strcat(cmd, "\\portal\\plugins\\");
|
|
|
strcat(cmd, "RB_SendErp_New.jar");
|
|
|
strcat(cmd, "\" ");
|
|
|
//传参
|
|
|
//cout << data_file << endl;
|
|
|
strcat(cmd, data_file);
|
|
|
//用来传递本流程的流程名称(@分割)
|
|
|
strcat(cmd, "@BOM");
|
|
|
//strcat(cmd,handler_name);
|
|
|
//WriteLog("路径:\n%s\n", cmd);
|
|
|
char buf[8000] = { 0 };
|
|
|
FILE* pf = NULL;
|
|
|
if ((pf = _popen(cmd, "r")) == NULL) {
|
|
|
WriteLog("接口返回:\n%s", "1");
|
|
|
}
|
|
|
|
|
|
while (fgets(buf, sizeof buf, pf)) {
|
|
|
strResult += buf;
|
|
|
}
|
|
|
_pclose(pf);
|
|
|
|
|
|
cout << strResult << endl;
|
|
|
unsigned int iSize = strResult.size();
|
|
|
if (iSize > 0 && strResult[iSize - 1] == '\n' && strlen(parameters) > 0)
|
|
|
{
|
|
|
strResult = strResult.substr(0, iSize - 1);
|
|
|
cout << strResult << endl;
|
|
|
if (strstr(strResult.c_str(), "\"code\":200") != NULL)
|
|
|
{
|
|
|
WriteLog("下发成功\n");
|
|
|
|
|
|
|
|
|
}
|
|
|
else {
|
|
|
ifail = EPM_go;
|
|
|
strcat(errorMessage, strResult.c_str());
|
|
|
|
|
|
|
|
|
WriteLog("发送邮件:%d", user_cnt);
|
|
|
for (int i = 0; i < user_cnt; i++) {
|
|
|
char cmd[10240] = ""; // 64KB
|
|
|
char jarfile[512] = "";
|
|
|
string mail_addr = mail_addrs[i];
|
|
|
if (mail_addr.size() > 0) {
|
|
|
WriteLog(">> %d. 发送邮件给[%s]", i + 1, mail_addr.c_str());
|
|
|
sprintf(jarfile, "%s\\bin\\EMailSender.jar", getenv("TC_ROOT"));
|
|
|
strcpy_s(cmd, "java -jar ");
|
|
|
strcat_s(cmd, jarfile);
|
|
|
strcat_s(cmd, " \"");
|
|
|
strcat_s(cmd, mail_addr.c_str());
|
|
|
strcat_s(cmd, "\" \"【TeamCenter】传递ERP-BOM提醒\" \"");
|
|
|
strcat_s(cmd, job_name);
|
|
|
strcat_s(cmd, ":发送数据失败->");
|
|
|
strcat_s(cmd, errorMessage);
|
|
|
strcat_s(cmd, "\"");
|
|
|
WriteLog("CMD:%s", cmd);
|
|
|
system(cmd);
|
|
|
WriteLog("执行完成");
|
|
|
}
|
|
|
DOFREE(cmd);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
DOFREE(itemType);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
MEM_free(attachments);
|
|
|
MEM_free(c_sql_values);
|
|
|
/*if (ifail == EPM_nogo)
|
|
|
{
|
|
|
EMH_store_error_s1(EMH_severity_user_error, EMH_USER_error_base, errorMessage);
|
|
|
|
|
|
}*/
|
|
|
WriteLog("=========================BOM下发到ERP rule End===================\n");
|
|
|
CloseLog();
|
|
|
return ifail;
|
|
|
} |