|
|
#include "epm_handler_common.h"
|
|
|
#include <tc\tc_macros.h>
|
|
|
#include <tc\emh.h>
|
|
|
#include <tc\preferences.h>
|
|
|
#include <property\propdesc.h>
|
|
|
#include <epm\epm.h>
|
|
|
#include <epm\epm_toolkit_tc_utils.h>
|
|
|
#include <tccore\item.h>
|
|
|
#include <tccore\grmtype.h>
|
|
|
#include <tccore\grm.h>
|
|
|
#include <tccore\imantype.h>
|
|
|
#include <sa\am.h>
|
|
|
#include <sa\sa.h>
|
|
|
#include <tccore\aom.h>
|
|
|
#include <tccore\aom_prop.h>
|
|
|
#include <property\prop_errors.h>
|
|
|
#include <tccore\workspaceobject.h>
|
|
|
#include <qry\qry.h>
|
|
|
#include <bom\bom_attr.h>
|
|
|
#include <bom\bom.h>
|
|
|
#include <epm\signoff.h>
|
|
|
#include <pom\pom\pom.h>
|
|
|
#include <pom\pom\pom_errors.h>
|
|
|
#include <fclasses\tc_date.h>
|
|
|
#include <epm\cr.h>
|
|
|
#include <cfm\cfm.h>
|
|
|
#include <sa\am.h>
|
|
|
#include "tc/envelope.h"
|
|
|
#include <stdio.h>
|
|
|
#include "ae/dataset.h"
|
|
|
#include <ctype.h>
|
|
|
#include <string.h>
|
|
|
#include <string>
|
|
|
#include <iostream>
|
|
|
#include <iterator>
|
|
|
#include <map>
|
|
|
#include <vector>
|
|
|
#include "ce/ce.h"
|
|
|
#include <time.h>
|
|
|
#include <windows.h>
|
|
|
#include <iostream>
|
|
|
#include <sql.h>
|
|
|
#include <sqlext.h>
|
|
|
#include "string"
|
|
|
#include "sstream"
|
|
|
#include <sa/tcfile.h>
|
|
|
#include <tccore/aom.h>
|
|
|
#include <sa/tcfile_cache.h>
|
|
|
#include "ctime"
|
|
|
#include "tchar.h"
|
|
|
#include "jni.h"
|
|
|
|
|
|
using namespace std;
|
|
|
extern "C" int POM_AM__set_application_bypass(logical bypass);
|
|
|
bool isTypeOf(tag_t objtag, const char * type_name) {
|
|
|
tag_t type = NULLTAG;
|
|
|
TCTYPE_ask_object_type(objtag, &type);
|
|
|
tag_t item_type = NULLTAG;
|
|
|
TCTYPE_find_type(type_name, "", &item_type);
|
|
|
bool is_type = false;
|
|
|
if (item_type != NULLTAG) {
|
|
|
logical isok = FALSE;
|
|
|
TCTYPE_is_type_of(type, item_type, &isok);
|
|
|
if (isok) {
|
|
|
is_type = true;
|
|
|
}
|
|
|
}
|
|
|
return is_type;
|
|
|
}
|
|
|
|
|
|
string GBKToUTF8(const char* strGBK)
|
|
|
{
|
|
|
int len = MultiByteToWideChar(CP_ACP, 0, strGBK, -1, NULL, 0);
|
|
|
wchar_t* wstr = new wchar_t[len+1];
|
|
|
memset(wstr, 0, len+1);
|
|
|
MultiByteToWideChar(CP_ACP, 0, strGBK, -1, wstr, len);
|
|
|
len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
|
|
|
char* str = new char[len+1];
|
|
|
memset(str, 0, len+1);
|
|
|
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);
|
|
|
string strTemp = str;
|
|
|
if(wstr) delete[] wstr;
|
|
|
if(str) delete[] str;
|
|
|
return strTemp;
|
|
|
}
|
|
|
|
|
|
int sap(EPM_action_message_t msg)
|
|
|
{
|
|
|
printf("start sap\n");
|
|
|
int ifail = ITK_ok, att_count;
|
|
|
tag_t rootTask, *attachments, user_tag,relation_type;
|
|
|
char *action_string, *user_name, *task_name;
|
|
|
|
|
|
EPM_ask_root_task(msg.task, &rootTask);
|
|
|
|
|
|
EPM_ask_attachments(rootTask,EPM_target_attachment, &att_count, &attachments);
|
|
|
TC_argument_list_t * arguments = msg.arguments;
|
|
|
int arg_cnt = TC_number_of_arguments(arguments), status = 0;
|
|
|
map<string, string> paras;
|
|
|
|
|
|
for (auto i = 0; i<arg_cnt; i++)
|
|
|
{
|
|
|
char *temp_key, *temp_val;
|
|
|
ITK_ask_argument_named_value(TC_next_argument(arguments), &temp_key, &temp_val);
|
|
|
paras[temp_key] = temp_val;
|
|
|
}
|
|
|
int pref_cnt;
|
|
|
char **pref_vals;
|
|
|
|
|
|
printf("11");
|
|
|
wstringstream wss;
|
|
|
wss << getenv("JRE_HOME") << "\\bin\\server\\jvm.dll";
|
|
|
|
|
|
JavaVMInitArgs vmArgs;
|
|
|
vmArgs.version = JNI_VERSION_1_6;
|
|
|
const int OPTION_COUNT = 2;
|
|
|
vmArgs.nOptions = OPTION_COUNT;
|
|
|
JavaVMOption options[OPTION_COUNT] = { 0 };
|
|
|
options[0].optionString = "-Djava.class.path=..\\portal\\plugins\\sap.jar";
|
|
|
options[1].optionString = "-Xmx1024m";
|
|
|
vmArgs.options = options;
|
|
|
vmArgs.ignoreUnrecognized = JNI_TRUE;
|
|
|
printf("before load dll\n");
|
|
|
HMODULE hModule = LoadLibrary(wss.str().c_str());
|
|
|
if (hModule == NULL)
|
|
|
{
|
|
|
printf("error load dll");
|
|
|
return -1;
|
|
|
}
|
|
|
printf("after load dll\n");
|
|
|
typedef jint(JNICALL *CreateJavaVMFuncPtr)(JavaVM **pvm, void **penv, void *args);
|
|
|
CreateJavaVMFuncPtr CreateJavaVM = (CreateJavaVMFuncPtr)GetProcAddress(hModule, "JNI_CreateJavaVM");
|
|
|
JavaVM *jvm = nullptr;
|
|
|
JNIEnv *env = nullptr;
|
|
|
jint res = (*CreateJavaVM)(&jvm, (void**)&env, &vmArgs);
|
|
|
if (res < 0)
|
|
|
{
|
|
|
printf("error load jvm");
|
|
|
return -1;
|
|
|
}
|
|
|
printf("after load jvm\n");
|
|
|
jclass class_Test = env->FindClass("zplm_interface/SAPTest");
|
|
|
jmethodID methodId_main = env->GetStaticMethodID(class_Test, "sap", "([Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)Z");
|
|
|
jobjectArray info = env->NewObjectArray(2, env->FindClass("Ljava/lang/String;"), NULL);
|
|
|
|
|
|
|
|
|
int index=0;
|
|
|
|
|
|
PREF_ask_char_values("Origin_SAP_URL",&pref_cnt,&pref_vals);
|
|
|
jstring url=env->NewStringUTF(pref_vals[0]);
|
|
|
PREF_ask_char_values("Origin_SAP_PassWord",&pref_cnt,&pref_vals);
|
|
|
env->SetObjectArrayElement(info, 0, env->NewStringUTF(pref_vals[0]));
|
|
|
env->SetObjectArrayElement(info, 1, env->NewStringUTF(pref_vals[1]));
|
|
|
|
|
|
vector<string> vec;
|
|
|
vec.push_back("cdc_Partnum");
|
|
|
vec.push_back("CustName");
|
|
|
vec.push_back("DCM_specification");
|
|
|
vec.push_back("cdc_Specsize1");
|
|
|
vec.push_back("DCM_Weight");
|
|
|
vec.push_back("DCM_SurfState");
|
|
|
vec.push_back("cdc_WetherTSTM");
|
|
|
vec.push_back("cdc_InWPTDT");
|
|
|
vec.push_back("cdc_WithWPTSTM");
|
|
|
|
|
|
printf("start\n");
|
|
|
GRM_find_relation_type(IMAN_master_form_rtype, &relation_type);
|
|
|
printf("type:%s\n",paras["itemRev_type"].c_str());
|
|
|
for(int i=0;i<att_count;i++){
|
|
|
if(isTypeOf(attachments[i],paras["itemRev_type"].c_str())){
|
|
|
int rel_cnt;
|
|
|
tag_t *rels;
|
|
|
GRM_list_secondary_objects_only(attachments[i], relation_type, &rel_cnt, &rels);
|
|
|
jobjectArray strs= env->NewObjectArray(vec.size(), env->FindClass("Ljava/lang/String;"), NULL);
|
|
|
|
|
|
for(auto j=0;j<vec.size();j++){
|
|
|
char *val;
|
|
|
AOM_UIF_ask_value(rels[0],vec[j].c_str(),&val);
|
|
|
string temp=val;
|
|
|
if(j==5||j==8){
|
|
|
int temp_index=temp.find(':');
|
|
|
if(temp_index!=-1){
|
|
|
temp=temp.substr(0,temp_index);
|
|
|
}
|
|
|
}else if(j==1&&temp.length()>3){
|
|
|
temp=temp.substr(3);
|
|
|
}
|
|
|
printf("args:%s\n",temp.c_str());
|
|
|
temp=GBKToUTF8(temp.c_str());
|
|
|
env->SetObjectArrayElement(strs, j, env->NewStringUTF(temp.c_str()));
|
|
|
}
|
|
|
printf("pass11");
|
|
|
jboolean result= env->CallStaticBooleanMethod(class_Test, methodId_main, strs, url,info);
|
|
|
printf("result:%d\n",result==JNI_TRUE);
|
|
|
if(result==JNI_FALSE){
|
|
|
printf("error\n");
|
|
|
EMH_store_error_s1(EMH_severity_error, EMH_ATTR_error_base, "SAP<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SAPϵͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>ϵ");
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
jvm->DestroyJavaVM();
|
|
|
FreeLibrary(hModule);
|
|
|
return 0;
|
|
|
}
|
|
|
|