|
|
#include "dfl_custom.h"
|
|
|
#include <tc/envelope.h>
|
|
|
#include <base_utils/IFail.hxx>
|
|
|
#include <base_utils/TcResultStatus.hxx>
|
|
|
#include <tccore/aom_prop.h>
|
|
|
#include <tccore/project.h>
|
|
|
#include "ado.h"
|
|
|
#include <tccore\aom.h>
|
|
|
#include <tccore\aom_prop.h>
|
|
|
#include "rapidjson/document.h"
|
|
|
#include <tccore/uom.h>
|
|
|
#include "rapidjson/writer.h"
|
|
|
#include <sstream>
|
|
|
#include <iostream>
|
|
|
#include <fstream>
|
|
|
#include <regex>
|
|
|
#include <tccore/grm.h>
|
|
|
#include <property/nr.h>
|
|
|
#include "CRUL_server_call_httpserver.h"
|
|
|
#define ITK_err 919012
|
|
|
#include "spdlog/spdlog.h"
|
|
|
#include "spdlog/sinks/basic_file_sink.h"
|
|
|
#include "ocilib.h"
|
|
|
#include "SAPZYGG2.h"
|
|
|
#include "util.h"
|
|
|
//#include "SendSap.h"
|
|
|
using namespace spdlog;
|
|
|
#define PREF_ML_DB "Meling_dbinfo"
|
|
|
using namespace std;
|
|
|
using namespace rapidjson;
|
|
|
|
|
|
string startLog(char* userName) {
|
|
|
tag_t current_member = NULLTAG, current_user = NULLTAG;
|
|
|
string userId = userName;
|
|
|
//获取当前时间
|
|
|
time_t now = time(0);
|
|
|
tm* p = localtime(&now);
|
|
|
char dateNow[128] = "";
|
|
|
sprintf_s(dateNow, "%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);
|
|
|
string dateString = dateNow;
|
|
|
string logPath = "C:/logs/" + userId + "_" + dateString + ".log";
|
|
|
auto file_logger = basic_logger_mt("import_logger", logPath);
|
|
|
set_default_logger(file_logger);
|
|
|
log("begin connor_import_object");
|
|
|
return logPath;
|
|
|
}
|
|
|
|
|
|
string uploadMinio(string jarName, string logPath) {
|
|
|
char cmd[1024] = "";
|
|
|
strcpy(cmd, "java -jar \"");
|
|
|
//strcat(cmd, jar_file);
|
|
|
strcat(cmd, getenv("TC_ROOT"));
|
|
|
strcat(cmd, "\\bin\\");
|
|
|
strcat(cmd, jarName.c_str());
|
|
|
strcat(cmd, "\" ");
|
|
|
string strResult;
|
|
|
strcat(cmd, logPath.c_str());
|
|
|
char buf[8000] = { 0 };
|
|
|
log("cmd:\n%s\n", cmd);
|
|
|
FILE* pf = NULL;
|
|
|
if ((pf = _popen(cmd, "r")) == NULL) {
|
|
|
log("接口返回1\n");
|
|
|
}
|
|
|
else {
|
|
|
log("接口返回2\n");
|
|
|
while (fgets(buf, sizeof buf, pf)) {
|
|
|
strResult += buf;
|
|
|
}
|
|
|
_pclose(pf);
|
|
|
}
|
|
|
log("strResult:%s\n", strResult.c_str());
|
|
|
return strResult;
|
|
|
//return;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据产成品获取出厂编号 和电气设计下的BOM
|
|
|
* @param ccpVector 产成品的集合
|
|
|
* @param groupName 用户所在的组
|
|
|
* @param projectUid 项目的UID
|
|
|
* @param code 传递的编号code
|
|
|
* @param userName 用户ID
|
|
|
*/
|
|
|
int readBomMsg(vector<tag_t> ccpVector, char * groupName, char* projectUid, char*code, char *userName) {
|
|
|
char* revUid;
|
|
|
int ifail = ITK_ok, num = 0;
|
|
|
//startLog();
|
|
|
//链接TC数据库
|
|
|
|
|
|
string errorBuff;
|
|
|
tag_t project;
|
|
|
time_t now = time(0);
|
|
|
tm* p = localtime(&now);
|
|
|
char fileDate[128] = "";
|
|
|
sprintf_s(fileDate, "%04d%02d%02d", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday);
|
|
|
string nowTime = fileDate;
|
|
|
|
|
|
log("projectUid:%s\n", projectUid);
|
|
|
char* projectNo = NULL, *zt2_WBSNo = NULL, *objectName = NULL;
|
|
|
if (projectUid && tc_strlen(projectUid) > 0 && tc_strcmp(projectUid, "null") != 0) {
|
|
|
ITK__convert_uid_to_tag(projectUid, &project);
|
|
|
//project.getProperty("zt2_ProjectNo");
|
|
|
ITKCALL(AOM_ask_value_string(project, "zt2_ProjectNo", &projectNo));
|
|
|
ITKCALL(AOM_ask_value_string(project, "object_name", &objectName));
|
|
|
ITKCALL(AOM_ask_value_string(project, "zt2_WBSNo", &zt2_WBSNo));
|
|
|
}
|
|
|
else {
|
|
|
ITKCALL(AOM_ask_value_string(ccpVector[0], "zt2_WBSNo", &zt2_WBSNo));
|
|
|
}
|
|
|
|
|
|
log("ccpVector%d\n", ccpVector.size());
|
|
|
|
|
|
//查询传递类型
|
|
|
char* transfer = (char*)"电气设计";
|
|
|
string sql = "select transfer from CHINT_BOM_TO_SAP_SUM where code = ";
|
|
|
sql.append(code);
|
|
|
int outputColumn1 = 0, outputValueCount1 = 0;
|
|
|
char*** outputValue1 = NULL;
|
|
|
log("search3 ===> %s\n", sql.c_str());
|
|
|
QuerySQLNoInputParam((char*)sql.c_str(), &outputColumn1, &outputValueCount1, &outputValue1);
|
|
|
if (outputValueCount1 > 0) {
|
|
|
transfer = outputValue1[0][0];
|
|
|
}
|
|
|
log("transfer ===> %s\n", transfer);
|
|
|
int pref_cnt = 0;
|
|
|
char **pref = NULL;
|
|
|
ITKCALL(PREF_ask_char_values("CHINT_TYBOMTOSAP", &pref_cnt, &pref));
|
|
|
string fa = "";
|
|
|
for (int i = 0; i < pref_cnt; i++) {
|
|
|
vector<string> v1, v2;
|
|
|
Split(pref[i], ":", v1);
|
|
|
Split(v1[1], ";", v2);
|
|
|
for (int j = 0; j < v2.size(); j++) {
|
|
|
if (tc_strcmp(v2[j].c_str(), groupName) == 0) {
|
|
|
fa = v1[0];
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (fa.size() > 0)
|
|
|
break;
|
|
|
}
|
|
|
log("fa ===>%s\n", fa.c_str());
|
|
|
if (tc_strcmp(transfer, "部件传递") == 0) {
|
|
|
if (tc_strcmp(groupName, "M060") == 0) {
|
|
|
BomSapWhBjOp(ccpVector[0], groupName, fileDate, code, zt2_WBSNo, userName, "");
|
|
|
}
|
|
|
else if (tc_strcmp(fa.c_str(), "B") == 0 || tc_strcmp(fa.c_str(), "D") == 0) {
|
|
|
SAPZYGGOperation(ccpVector[0], groupName, fileDate, code, zt2_WBSNo, userName, "");
|
|
|
}
|
|
|
else if (tc_strcmp(fa.c_str(), "C") == 0) {
|
|
|
SAPBYOperation(ccpVector[0], groupName, fileDate, code, zt2_WBSNo, userName, "");
|
|
|
}
|
|
|
}
|
|
|
else if (tc_strcmp(groupName, "M060") == 0) {
|
|
|
BomSapWh(ccpVector, projectNo, groupName, zt2_WBSNo,
|
|
|
fileDate, errorBuff, code, transfer, userName, (char*)fa.c_str());
|
|
|
}
|
|
|
else if (tc_strcmp(fa.c_str(), "C") == 0) {
|
|
|
vector<string> dists;
|
|
|
int pref_cnt = 0;
|
|
|
char **pref = NULL;
|
|
|
ITKCALL(PREF_ask_char_values("M005_task_distribute", &pref_cnt, &pref));
|
|
|
for (int i = 0; i < pref_cnt; i++) {
|
|
|
vector<string> vec;
|
|
|
Split(pref[i], "|", vec);
|
|
|
if (vec.size() != 3) {
|
|
|
continue;
|
|
|
}
|
|
|
if (tc_strstr(vec[1].c_str(), "总装") != NULL) {
|
|
|
continue;
|
|
|
}
|
|
|
dists.push_back(vec[0]);
|
|
|
}
|
|
|
SAPZZNewOp(ccpVector, projectNo, groupName, zt2_WBSNo,
|
|
|
fileDate, errorBuff, code, transfer, userName, (char*)fa.c_str(), dists, objectName);
|
|
|
}
|
|
|
else if (tc_strcmp(transfer, "壳体方案传递") == 0) {
|
|
|
getKTBom(ccpVector, projectNo, groupName, zt2_WBSNo,
|
|
|
fileDate, errorBuff, code, transfer, userName, objectName);
|
|
|
}
|
|
|
else if (tc_strcmp(transfer, "产成品BOM传递") == 0 && tc_strcmp(fa.c_str(), "D") == 0) {
|
|
|
SAPZYGG2(ccpVector, projectNo, groupName, zt2_WBSNo,
|
|
|
fileDate, errorBuff, code, transfer, userName, objectName);
|
|
|
}
|
|
|
else if (tc_strcmp(transfer, "产成品BOM传递") == 0 && tc_strcmp(fa.c_str(), "B") == 0) {
|
|
|
SAPZYGG2(ccpVector, projectNo, groupName, zt2_WBSNo,
|
|
|
fileDate, errorBuff, code, transfer, userName, objectName);
|
|
|
}
|
|
|
else if (tc_strcmp(transfer, "产成品BOM传递") == 0 && tc_strcmp(fa.c_str(), "E") == 0) {
|
|
|
vector<string> dists;
|
|
|
SAPPartZYOp2(ccpVector, projectNo, groupName, zt2_WBSNo,
|
|
|
fileDate, errorBuff, code, transfer, userName, (char*)fa.c_str(), objectName);
|
|
|
SAPZZNewOp(ccpVector, projectNo, groupName, zt2_WBSNo,
|
|
|
fileDate, errorBuff, code, transfer, userName, (char*)fa.c_str(), dists, objectName);
|
|
|
}
|
|
|
else if (tc_strcmp(transfer, "电气设计") == 0 && tc_strcmp(fa.c_str(), "B") == 0) {
|
|
|
getCcpAndBom(ccpVector, projectNo, groupName, zt2_WBSNo,
|
|
|
fileDate, errorBuff, code, transfer, userName, objectName, true);
|
|
|
}
|
|
|
else {
|
|
|
getCcpAndBom(ccpVector, projectNo, groupName, zt2_WBSNo,
|
|
|
fileDate, errorBuff, code, transfer, userName, objectName, false);
|
|
|
}
|
|
|
/*log("errorBuff ===>%s\n", errorBuff.c_str());
|
|
|
*((char**)returnValue) = (char*)MEM_alloc((strlen(errorBuff.c_str()) + 1) * sizeof(char));
|
|
|
tc_strcpy(*((char**)returnValue), errorBuff.c_str());*/
|
|
|
|
|
|
log("end connor_import_object");
|
|
|
//spdlog::drop_all();
|
|
|
return ITK_ok;
|
|
|
}
|
|
|
|
|
|
int ITK_user_main(int argc, char* argv[])
|
|
|
{
|
|
|
int ifail = ITK_ok;
|
|
|
char* tc_name, *tc_pwd, *tc_group, *code, *groupId, *projectUid, *uids, *userName;
|
|
|
tc_name = (char*)"dcproxy";//ITK_ask_cli_argument("-u=");
|
|
|
tc_pwd = (char*)"dcproxy";// ITK_ask_cli_argument("-p=");
|
|
|
tc_group = (char*)"";// ITK_ask_cli_argument("-g=");
|
|
|
code = ITK_ask_cli_argument("-a="); //编号
|
|
|
groupId = ITK_ask_cli_argument("-b="); //编号
|
|
|
projectUid = ITK_ask_cli_argument("-c="); //编号
|
|
|
uids = ITK_ask_cli_argument("-d="); //编号
|
|
|
userName = ITK_ask_cli_argument("-e="); //编号
|
|
|
ITKCALL(ifail = TC_init_module(tc_name, tc_pwd, tc_group));
|
|
|
if (ifail != ITK_ok) {
|
|
|
log("login fail! \n");
|
|
|
return ifail;
|
|
|
}
|
|
|
else {
|
|
|
log("login2222>>>>> \n");
|
|
|
}
|
|
|
string logPath = startLog(userName);
|
|
|
vector<string> uidVector;
|
|
|
vector<tag_t> ccpVector;
|
|
|
Split(uids, ":", uidVector);
|
|
|
log("uidVector>>>>> %d \n", uidVector.size());
|
|
|
for (int i = 0; i < uidVector.size(); i++) {
|
|
|
tag_t ccp;
|
|
|
log("idVector[i].c_str() %s \n", uidVector[i].c_str());
|
|
|
ITK__convert_uid_to_tag(uidVector[i].c_str(), &ccp);
|
|
|
ccpVector.push_back(ccp);
|
|
|
}
|
|
|
int url_num = 0;
|
|
|
char** url_vals = NULL;
|
|
|
ITKCALL(PREF_ask_char_values("database_tc", &url_num, &url_vals));
|
|
|
string url = url_vals[0];
|
|
|
url.append("/").append(url_vals[2]);
|
|
|
|
|
|
|
|
|
log("url ==>%s", url.c_str());
|
|
|
if (ConnServer(url_vals[3], url_vals[4], (char*)url.c_str()) == -1)
|
|
|
{
|
|
|
log("提示:中间数据表访问失败");
|
|
|
ifail = 1;
|
|
|
}
|
|
|
if (open("PLMUser", "PLMUser", "BDP2020", "10.128.20.35")) {
|
|
|
printf("链接SQLSERVER失败\n");
|
|
|
}
|
|
|
else {
|
|
|
printf("链接SQLSERVER成功\n");
|
|
|
}
|
|
|
readBomMsg(ccpVector, groupId, projectUid, code, userName);//,char * groupName,char* groupUid,char*code
|
|
|
|
|
|
//log("产成品UID: {%s} " , uids);
|
|
|
|
|
|
string str = uploadMinio("uploadMinio.jar", logPath);
|
|
|
|
|
|
//string minioPath = "/plmichi/SapBomLog/" + logPath;
|
|
|
//char updateSum[1024] = "update CHINT_BOM_TO_SAP_SUM set \"LOGURL\" = '%s' where code = '%s' ";
|
|
|
char selectRxfs[1024];
|
|
|
sprintf(selectRxfs, "update CHINT_BOM_TO_SAP_SUM set \"LOGURL\" = '%s' where code = '%s' ", str.c_str(), code);
|
|
|
log("selectRecord3 ===> %s\n", selectRxfs);
|
|
|
ExecuteSQLNoInputParam(selectRxfs);
|
|
|
ExecuteSQLNoInputParam((char*)"commit");
|
|
|
//上传文件
|
|
|
close();
|
|
|
DisConnServer();
|
|
|
ITK_exit_module(true);
|
|
|
spdlog::drop_all();
|
|
|
return ifail;
|
|
|
}
|