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.

2049 lines
56 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "wf_custom.h"
#include "tccore\iman_msg.h"
extern "C" int POM_AM__set_application_bypass(logical bypass);
int len(char *p)
{
int i=0;
while(*p++)i++;
return i;
}
void split(char *src,const char *separator,char **dest,int *num) {
/*
src 源字符串的首地址(buf的地址)
separator 指定的分割字符
dest 接收子字符串的数组
num 分割后子字符串的个数
*/
char *pNext;
int count = 0;
if (src == NULL || strlen(src) == 0) //如果传入的地址为空或长度为0直接终止
return;
if (separator == NULL || strlen(separator) == 0) //如未指定分割的字符串,直接终止
return;
pNext = (char *)strtok(src,separator); //必须使用(char *)进行强制类型转换(虽然不写有的编译器中不会出现指针错误)
while(pNext != NULL) {
*dest++ = pNext;
++count;
pNext = (char *)strtok(NULL,separator); //必须使用(char *)进行强制类型转换
}
*num = count;
}
int Connor_set_bypass(void *returnValue)
{
POM_AM__set_application_bypass(true);
return 0;
}
int Connor_close_bypass(void *returnValue)
{
POM_AM__set_application_bypass(false);
return 0;
}
/**
* bypass
*/
int Connor_bypass(EPM_action_message_t msg){
ECHO("==================bypass START =======================\n");
int ifail = ITK_ok, arg_cnt;
char *argflag =NULL,*argvalue=NULL ,*arg = NULL;
int i=0, j=0;
BOOL bypass = FALSE;
arg_cnt = TC_number_of_arguments(msg.arguments);
ECHO("参数个数为:%d\n",arg_cnt);
POM_AM__set_application_bypass(true);
if (arg_cnt > 0)
{
for (i=0;i<arg_cnt;i++)
{
arg = TC_next_argument(msg.arguments);
ifail = ITK_ask_argument_named_value((const char*)arg, &argflag, &argvalue);
if(stricmp(argflag,"bypass") == 0)
{
if(stricmp(argvalue,"true") == 0){
bypass=TRUE;
}else if(stricmp(argvalue,"false") == 0){
bypass = FALSE;
}
}
}
if(argflag!=NULL){
MEM_free(argflag);
argflag=NULL;
}
if(argvalue!=NULL){
MEM_free(argvalue);
argvalue=NULL;
}
}
printf("bypass=%d /n",bypass);
POM_AM__set_application_bypass(bypass);
ECHO("==================bypass END =======================\n");
return ifail;
}
//java调用发布 参数1:发布的对象 参数2:发布的类型()
//public void setReleaseStatus(TCComponent item, String statusName)
// throws TCException {
// TCUserService userservice = this.session.getUserService();
//
// Object[] obj = new Object[2];
// obj[0] = item;
// obj[1] = statusName;
// userservice.call("connor_set_release_status", obj);
//
// }
int connor_set_release_status(void * returnValue){
int ifail = ITK_ok;
tag_t item = NULL_TAG,release_status =NULL_TAG;
char * release_name = NULL;
tag_t * release_objs = NULL;
USERARG_get_tag_argument(&item);
USERARG_get_string_argument(&release_name);
int temp_count = 1;
release_objs = (tag_t *)MEM_alloc(temp_count*sizeof(tag_t));
release_objs[0] = item;
ITKCALL(ifail = CR_create_release_status(release_name,&release_status));
ITKCALL(ifail = EPM_add_release_status(release_status,temp_count,release_objs,TRUE));
if(release_name !=NULL){
MEM_free(release_name);
}
return ITK_ok;
}
/**
* 时间表流程显示项目名称
*/
int tm_show_object_name(EPM_action_message_t msg){
printf("===================================\n");
printf("设置时间表名称 开始\n");
printf("===================================\n");
printf("开超级权限\n");
POM_AM__set_application_bypass(true);
int ifail = ITK_ok;
tag_t tast_tag = NULL_TAG,job;
tast_tag = msg.task;
if(tast_tag != NULL_TAG){
char * task_name = NULL;
int count = 0 ;
tag_t * schdule_task_nodes = NULL;
printf("开始获取SCHDULE任务 \n");
AOM_ask_value_tags(tast_tag,"project_task_attachments",&count,&schdule_task_nodes);
printf("获取SCHDULE任务 count =[%d] \n",count);
//printf("task_name:%s\n",task_name);
printf("task_name-------------\n");
if(count >0 ){
char * schdule_task_node_type = NULL;
AOM_ask_value_string(schdule_task_nodes[0],"object_type",&schdule_task_node_type);
char * scheduleTaskName =NULL;
char finish_date_str[300] = "";
printf("object_type:%s\n",schdule_task_node_type);
if(strcmp(schdule_task_node_type,"ScheduleTask")==0){
tag_t schdule = NULL_TAG;
// date_t finish_date ;
AOM_ask_value_tag(schdule_task_nodes[0],"schedule_tag",&schdule);
AOM_ask_value_string(schdule_task_nodes[0], "object_name", &scheduleTaskName);
printf("scheduleTaskName:%s\n",scheduleTaskName);
if(schdule != NULL_TAG){
//char * schdule_name = NULL;
char * job_name = NULL;
char * project_id = NULL;
char * project_name = NULL;
//date_t time;
//char * d_value=NULL;
int num=0;
tag_t * projects;
//AOM_ask_value_date(schdule_task_nodes[0],"finish_date", &time);
//DATE_date_to_string(time,"%Y-%m-%d",&d_value);
EPM_ask_job(tast_tag, &job);
AOM_ask_value_string(job,"object_name",&job_name);
//AOM_ask_value_string(schdule,"object_name",&schdule_name);
AOM_ask_value_tags(schdule,"project_list",&num,&projects);
//printf("shcedule_name:%s\n",schdule_name);
//sprintf(finish_date_str,"%s-%s-%s",schdule_name,scheduleTaskName,d_value);
if (num>0)
{
AOM_ask_value_string(projects[0],"project_id",&project_id);
AOM_ask_value_string(projects[0],"object_name",&project_name);
sprintf(finish_date_str,"%s-%s-%s",scheduleTaskName,project_id,project_name);
}else
{
sprintf(finish_date_str,"%s-%s-%s",scheduleTaskName,"","");
}
AOM_lock(job);
AOM_set_value_string(job,"object_name",finish_date_str);
printf("str:%s\n",finish_date_str);
printf("设置属性\n");
AOM_save(job);
AOM_unlock(job);
if(job_name !=NULL){
MEM_free(job_name);
job_name = NULL;
}
if(project_id !=NULL){
MEM_free(project_id);
project_id = NULL;
}
if(project_name !=NULL){
MEM_free(project_name);
project_name = NULL;
}
/*if(schdule_name !=NULL){
MEM_free(schdule_name);
schdule_name = NULL;
}*/
}
}
if(schdule_task_node_type !=NULL){
MEM_free(schdule_task_node_type);
schdule_task_node_type = NULL;
}
}
if(task_name != NULL){
MEM_free(task_name);
task_name = NULL;
}
if(schdule_task_nodes != NULL){
MEM_free(schdule_task_nodes);
schdule_task_nodes = NULL;
}
}
printf("关超级权限\n");
POM_AM__set_application_bypass(false);
printf("===================================\n");
printf("设置时间表名称 结束\n");
printf("===================================\n");
return ifail;
}
int WF_schedule_has_baseline(EPM_rule_message_t msg){
printf("===================================\n");
printf("根据时间表是否基线,限制流程发起 开始\n");
printf("===================================\n");
int ifail = EPM_go,att_cnt=0;
tag_t task_tag = NULL_TAG,
root_task_tag=NULLTAG,
*attachments=NULLTAG;;
task_tag = msg.task;
char err[1024]="\0";
if(task_tag == NULLTAG)
{
return EPM_nogo;
}
EPM_ask_root_task(task_tag, &root_task_tag);
EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnt, &attachments);
if(att_cnt<=0){
printf("目标为空 退出\n");
return EPM_nogo;
}else{
for (int i = 0; i < att_cnt; i++)
{
tag_t tagt=NULLTAG,tag_tags=NULLTAG;
char *type=NULL,*name=NULL,*item_id=NULL;
tagt=attachments[i];//
ITKCALL(AOM_ask_value_string(tagt,"object_type",&type));
ITKCALL(AOM_ask_value_string(tagt,"object_name",&name));
printf("对象类型:%s\n",type);
if ((strcmp(type,"Schedule") == 0)){
printf("对象类型符合,继续\n");
}else{
printf("对象类型不符合\n");
ifail=EPM_nogo;
sprintf(err,"对象%s不是时间表,无法执行流程!!",name);
break;
}
ITKCALL(AOM_ask_value_tag(tagt,"activeschbaseline_tag",&tag_tags));//活动的基线
if(tag_tags==NULLTAG){
printf("未找到基线,不能执行\n");
ifail=EPM_nogo;
sprintf(err,"时间表%s不存在基线,请基线后再执行该流程!!",name);
continue;
}
if(type!=NULL){
MEM_free(type);
type = NULL;
}
if(name!=NULL){
MEM_free(name);
name = NULL;
}
}
printf("2222ifail:%d\n",ifail);
}
if(strcmp(err, "") != 0){
ifail=EPM_nogo;
printf("错误:%s\n",err);
EMH_store_error_s1(EMH_severity_information,278701,err);//错误弹窗
}
printf("ifail:%d\n",ifail);
printf("===================================\n");
printf("根据时间表是否基线,限制流程发起 结束\n");
printf("===================================\n");
return ifail;
}
//设置文档的项目相关属性
//参数:-type 值:Document
int WF_set_project_prop(EPM_action_message_t msg){
printf("===================================\n");
printf("设置文档的项目相关属性 开始\n");
printf("===================================\n");
int ifail = ITK_ok;
int att_cnt=0,isas=0;
tag_t task_tag = NULLTAG,
root_task_tag=NULLTAG,
*attachments=NULL;
vector<string> type_vec;
char arg1value[1024] = "";
char *argflag =NULL,*argvalue=NULL ,*arg = NULL;
int arg_cnt = 0;
int arg_col=0;
//获取handler的参数的个数
arg_cnt = TC_number_of_arguments(msg.arguments);
ECHO("参数个数为:%d\n",arg_cnt);
if (arg_cnt > 0)
{
for (int i=0;i<arg_cnt;i++)
{
//获取下一个参数从0开始
arg = TC_next_argument(msg.arguments);
//获取参数的名称和值
ifail = ITK_ask_argument_named_value((const char*)arg, &argflag, &argvalue);
if (stricmp(argflag, "type") == 0)
{
if(argvalue != NULL)
{
strcpy(arg1value,argvalue);
Split(arg1value,",",type_vec);
}
}
}
MEM_free(argflag);
MEM_free(argvalue);
}
printf("开超级权限\n");
POM_AM__set_application_bypass(true);
task_tag = msg.task;
EPM_ask_root_task(task_tag, &root_task_tag);
EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnt, &attachments);
if(att_cnt>0){
for (int i = 0; i < att_cnt; i++)
{
tag_t tagt=NULLTAG,*tag_tags=NULL;
char* type=NULL;
int tag_col=0;
ITKCALL(AOM_ask_value_string(attachments[i],"object_type",&type));
printf("对象类型:%s\n",type);
if (strcmp(type,"Folder")==0)
{
int doc_num=0;
tag_t *doc_tags=NULL;
ITKCALL(AOM_ask_value_tags(attachments[i],"contents",&doc_num,&doc_tags));
for (int j = 0; j < doc_num; j++)
{
tagt=doc_tags[j];
boolean istype=false;
for (int t = 0; t < type_vec.size(); t++)
{
char typevalue[64] = "";
strcpy(typevalue,type_vec[t].c_str());
int is=checkIsTypeOrSubtype(tagt,typevalue);
if(is==1){
printf("类型符合\n");
istype=true;
break;
}
}
printf("111\n");
if (istype)
{
printf("222\n");
int numtask=0,numpro=0;
tag_t *tasks=NULL,*pro_tags=NULL;
tag_t schedule_tag;
ITKCALL(AOM_ask_value_tags(root_task_tag,"fnd0RootScheduleTask",&numtask,&tasks));
printf("任务数量:%d\n",numtask);
if (numtask>0)
{
ITKCALL(AOM_ask_value_tag(tasks[0],"schedule_tag",&schedule_tag));
ITKCALL(AOM_ask_value_tags(schedule_tag,"project_list",&numpro,&pro_tags));
printf("项目数量:%d\n",numpro);
if (numpro>0)
{
tag_t rev_tagt;
ITKCALL(ITEM_ask_latest_rev(tagt,&rev_tagt));//获得最新版本
char * proname=NULL, *proid=NULL ,*khmc=NULL;
ITKCALL(AOM_ask_value_string(pro_tags[0],"object_name",&proname));
ITKCALL(AOM_ask_value_string(pro_tags[0],"project_id",&proid));
ITKCALL(AOM_ask_value_string(pro_tags[0],"wf2_customerName",&khmc));
printf("项目名称:%s\n",proname);
printf("项目id:%s\n",proid);
printf("客户名称:%s\n",khmc);
ITKCALL(AOM_lock(rev_tagt));
ITKCALL(AOM_set_value_string(rev_tagt,"wf2_projectName",proname));
ITKCALL(AOM_set_value_string(rev_tagt,"wf2_projectNumber",proid));
ITKCALL(AOM_set_value_string(rev_tagt,"wf2_customerName",khmc));
ITKCALL(AOM_save(rev_tagt));
ITKCALL(AOM_unlock(rev_tagt));
if(proname !=NULL){
MEM_free(proname);
proname = NULL;
}
if(proid !=NULL){
MEM_free(proid);
proid = NULL;
}
}else{
printf("指定时间表找不到项目!");
}
}
if(tasks !=NULL){
MEM_free(tasks);
tasks = NULL;
}
if(pro_tags !=NULL){
MEM_free(pro_tags);
pro_tags = NULL;
}
}
}
}
if(tag_tags !=NULL){
MEM_free(tag_tags);
tag_tags = NULL;
}
if(type !=NULL){
MEM_free(type);
type = NULL;
}
}
}
if(attachments !=NULL){
MEM_free(attachments);
attachments = NULL;
}
printf("关超级权限\n");
POM_AM__set_application_bypass(false);
printf("===================================\n");
printf("设置文档的项目相关属性 结束\n");
printf("===================================\n");
return ifail;
}
int WF_project_has_folder(EPM_rule_message_t msg){
printf("===================================\n");
printf("项目交付物检查 开始\n");
printf("===================================\n");
int ifail = EPM_go;
int att_cnt=0;
tag_t task_tag = NULLTAG,
root_task_tag=NULLTAG,
*attachments=NULL;
char err[1024]="\0";
task_tag = msg.task;
EPM_ask_root_task(task_tag, &root_task_tag);
EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnt, &attachments);
if(att_cnt>0){
for (int i = 0; i < att_cnt; i++)
{
tag_t tagt=NULLTAG;
char* type=NULL;
int tag_col=0;
ITKCALL(AOM_ask_value_string(attachments[i],"object_type",&type));
printf("对象类型:%s\n",type);
if (strcmp(type,"Folder")==0)
{
int doc_num=0;
tag_t *doc_tags=NULL;
ITKCALL(AOM_ask_value_tags(attachments[i],"contents",&doc_num,&doc_tags));
if(doc_num>0)
{
int num = 0;
tag_t *num_tags = NULL;
tag_t rev_tagt;
for (int j = 0; j < doc_num; j++)
{
tagt = doc_tags[j];
int is=checkIsTypeOrSubtype(tagt,"Item");
if(is == 1){
ITKCALL(ITEM_ask_latest_rev(tagt,&rev_tagt));
}else{
ifail = EPM_nogo;
sprintf(err,"上传对象不是Item对象请重新上传!!");
}
ITKCALL(AOM_ask_value_tags(rev_tagt,"release_status_list",&num,&num_tags));
if(num == 0)
{
ifail = EPM_nogo;
sprintf(err,"交付物对象版本没有发布,请发布!!");
}
}
if(num_tags !=NULL){
MEM_free(num_tags);
num_tags = NULL;
}
}else{
ifail = EPM_nogo;
sprintf(err,"交付物文件夹为空,请上传交付物对象!!");
}
if(doc_tags !=NULL){
MEM_free(doc_tags);
doc_tags = NULL;
}
}
if(type !=NULL){
MEM_free(type);
type = NULL;
}
}
}
if(attachments !=NULL){
MEM_free(attachments);
attachments = NULL;
}
if(strcmp(err, "") != 0){
ifail=EPM_nogo;
printf("错误:%s\n",err);
EMH_store_error_s1(EMH_severity_information,278701,err);//错误弹窗
}
return ifail;
}
int BOM_CHI_ISRELEASE(EPM_rule_message_t msg){
printf("===================================\n");
printf("根据BOM子件是否发布,限制流程发起 开始\n");
printf("===================================\n");
int ifail = EPM_go,att_cnt=0;
tag_t task_tag = NULL_TAG,
root_task_tag=NULLTAG,
*attachments;;
task_tag = msg.task;
char errs[2500]="\0";
char err[2000]="\0";
if(task_tag == NULLTAG)
{
return EPM_nogo;
}
EPM_ask_root_task(task_tag, &root_task_tag);
EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnt, &attachments);
if(att_cnt<=0){
printf("目标为空 退出\n");
return EPM_go;
}else{
POM_AM__set_application_bypass(true);
for (int i = 0; i < att_cnt; i++)
{
tag_t tagt=NULLTAG;
char *name=NULL;
int form_c=0;
tagt=attachments[i];//
if (checkIsTypeOrSubtype(tagt,"PSBOMViewRevision")!=1)
{
printf("类型不是PSBOMViewRevision\n");
continue;
}
printf("类型是PSBOMViewRevision,继续\n");
ITKCALL(AOM_ask_value_string(tagt,"object_string",&name));
int m=0,c_line_count = 0;
tag_t bom_window_tag = NULLTAG,
top_line_tag = NULLTAG,
*c_line_tags;
ITKCALL(BOM_create_window(&bom_window_tag));//创建window视图
ITKCALL(BOM_set_window_top_line_bvr(bom_window_tag,tagt,&top_line_tag));//获取顶层bomline
ITKCALL(BOM_line_ask_all_child_lines(top_line_tag,&c_line_count,&c_line_tags));
if(c_line_count == 0){
printf("没有BOM结构\n");
}else{
getchibomline_isrelease(top_line_tag,err);
if (strcmp(err,"")!=0)
{
sprintf(errs,"存在BOM对象%s子件%s未发布!!",name,err);
EMH_store_error_s1(EMH_severity_information,278701,errs);//错误弹窗
ifail=EPM_nogo;
}
}
ITKCALL(BOM_close_window(bom_window_tag));
if(name!=NULL){
MEM_free(name);
name = NULL;
}
}
POM_AM__set_application_bypass(false);
}
printf("ifail:%d\n",ifail);
printf("===================================\n");
printf("根据BOM子件是否发布,限制流程发起 结束\n");
printf("===================================\n");
return ifail;
}
//递归bom 判断子是否发布
boolean getchibomline_isrelease(tag_t top_line_tag, char* err){
int m=0,status_count = 0 ,
rev_form_cnt=0,
c_line_count = 0 ,
tuzhi_col=0;
tag_t bom_window_tag = NULLTAG,
*c_line_tags = NULL,
*rev_form_tags = NULL,
*tuzhi_tags= NULL;
printf("nnnn\n");
ITKCALL(BOM_line_ask_all_child_lines(top_line_tag,&c_line_count,&c_line_tags));
printf("c_line_count=%d\n"+c_line_count);
if(c_line_count == 0){
printf("下面没有BOM结构\n");
}else{
for (int m = 0; m < c_line_count; m++)
{
tag_t rev_tag =NULLTAG;
char * name="\0";
ITKCALL(AOM_ask_value_tag(c_line_tags[m],"bl_line_object",&rev_tag));//获取BOMLINE关联的版本
ITKCALL(AOM_ask_value_string(rev_tag,"object_string",&name));
int wl_release_count=0;
tag_t *wl_release_tags=NULL;
ITKCALL(AOM_ask_value_tags(rev_tag,"release_status_list",&wl_release_count,&wl_release_tags));
if(wl_release_count > 0)
{
printf("版本已发布\n");
}else{
printf("版本未发布\n");
strcat(err,"[");
strcat(err,name);
strcat(err,"]");
}
getchibomline_isrelease(c_line_tags[m],err);
}
}
return true;
}
int WF_check_item_rev(EPM_rule_message_t msg){
printf("===================================\n");
printf("变更对象是否发布检查 开始\n");
printf("===================================\n");
int ifail = EPM_go;
int att_cnt=0,isas=0;
tag_t task_tag = NULLTAG,
root_task_tag=NULLTAG,
*attachments=NULL,
*relations=NULL;
char item1value[1024] = "";
char relationvalue[1024] = "";
char item2value[1024] = "";
char *argflag =NULL,*argvalue=NULL ,*arg = NULL;
int arg_cnt = 0;
int arg_col=0;
int rel_cnt = 0;
//获取handler的参数的个数
arg_cnt = TC_number_of_arguments(msg.arguments);
ECHO("参数个数为:%d\n",arg_cnt);
if (arg_cnt > 0)
{
for (int i=0;i<arg_cnt;i++)
{
//获取下一个参数从0开始
arg = TC_next_argument(msg.arguments);
//获取参数的名称和值
ITK_ask_argument_named_value((const char*)arg, &argflag, &argvalue);
if (strcmp(argflag, "itemRevision") == 0)
{
if(argvalue != NULL)
{
strcpy(item1value,argvalue);
}
}
if (strcmp(argflag, "relation") == 0)
{
if(argvalue != NULL)
{
strcpy(relationvalue,argvalue);
}
}
if (strcmp(argflag, "itemRevision2") == 0)
{
if(argvalue != NULL)
{
strcpy(item2value,argvalue);
}
}
}
MEM_free(argflag);
MEM_free(argvalue);
}
task_tag = msg.task;
EPM_ask_root_task(task_tag, &root_task_tag);
EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnt, &attachments);
if(att_cnt>0)
{
for (int i = 0; i < att_cnt; i++)
{
tag_t tagt=NULLTAG,*tag_tags=NULL;
char* type=NULL;
int tag_col=0;
int num = 0;
tag_t *num_tags = NULL;
char* tagType=NULL;
ITKCALL(AOM_ask_value_string(attachments[i],"object_type",&type));
printf("对象类型:%s\n",type);
printf("对象类型:%s\n",item1value);
if(checkIsTypeOrSubtype(attachments[i],item1value) == 1)
{
ITKCALL(AOM_ask_value_tags(attachments[i],relationvalue,&rel_cnt,&relations));
if(rel_cnt>0)
{
for (int j = 0; j < rel_cnt; j++)
{
if (checkIsTypeOrSubtype(relations[j],item2value) == 1){
ITKCALL(AOM_ask_value_tags(relations[j],"release_status_list",&num,&num_tags));
if(num <= 0)
{
ifail = EPM_nogo;
EMH_store_error_s1(EMH_severity_information,278701,"对象版本没有发布,请发布!!");//错误弹窗
return ifail;
}
}
}
}else{
ifail = EPM_nogo;
EMH_store_error_s1(EMH_severity_information,278701,"关系文件夹下没有版本对象!!");//错误弹窗
return ifail;
}
}
}
}
return ifail;
}
int BOM_CHI_HASNUMBER(EPM_rule_message_t msg){
printf("===================================\n");
printf("根据BOM子件数量是否填写,限制流程发起 开始\n");
printf("===================================\n");
int ifail = EPM_go,att_cnt=0;
tag_t task_tag = NULL_TAG,
root_task_tag=NULLTAG,
*attachments;;
task_tag = msg.task;
char errs[2500]="\0";
char err[2000]="\0";
if(task_tag == NULLTAG)
{
return EPM_nogo;
}
EPM_ask_root_task(task_tag, &root_task_tag);
EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnt, &attachments);
if(att_cnt<=0){
printf("目标为空 退出\n");
return EPM_go;
}else{
POM_AM__set_application_bypass(true);
for (int i = 0; i < att_cnt; i++)
{
tag_t tagt=NULLTAG;
char *name=NULL;
int form_c=0;
tagt=attachments[i];//
if (checkIsTypeOrSubtype(tagt,"PSBOMViewRevision")!=1)
{
printf("类型不是PSBOMViewRevision\n");
continue;
}
printf("类型是PSBOMViewRevision,继续\n");
ITKCALL(AOM_ask_value_string(tagt,"object_string",&name));
int m=0,c_line_count = 0;
tag_t bom_window_tag = NULLTAG,
top_line_tag = NULLTAG,
*c_line_tags;
ITKCALL(BOM_create_window(&bom_window_tag));//创建window视图
ITKCALL(BOM_set_window_top_line_bvr(bom_window_tag,tagt,&top_line_tag));//获取顶层bomline
ITKCALL(BOM_line_ask_all_child_lines(top_line_tag,&c_line_count,&c_line_tags));
if(c_line_count == 0){
printf("没有BOM结构\n");
}else{
getchibomline_num(top_line_tag,err);
if (strcmp(err,"")!=0)
{
sprintf(errs,"存在BOM行%s%s未填写数量!!",name,err);
EMH_store_error_s1(EMH_severity_information,278701,errs);//错误弹窗
ifail=EPM_nogo;
}
}
ITKCALL(BOM_close_window(bom_window_tag));
if(name!=NULL){
MEM_free(name);
name = NULL;
}
}
POM_AM__set_application_bypass(false);
}
printf("ifail:%d\n",ifail);
printf("===================================\n");
printf("根据BOM子件数量是否填写,限制流程发起 结束\n");
printf("===================================\n");
return ifail;
}
//递归bom 判断子是否填数量
boolean getchibomline_num(tag_t top_line_tag, char* err){
int m=0,status_count = 0 ,
rev_form_cnt=0,
c_line_count = 0 ,
tuzhi_col=0;
tag_t bom_window_tag = NULLTAG,
*c_line_tags = NULL,
*rev_form_tags = NULL,
*tuzhi_tags= NULL;
printf("nnnn\n");
ITKCALL(BOM_line_ask_all_child_lines(top_line_tag,&c_line_count,&c_line_tags));
printf("c_line_count=%d\n"+c_line_count);
if(c_line_count == 0){
printf("下面没有BOM结构\n");
}else{
for (int m = 0; m < c_line_count; m++)
{
tag_t rev_tag =NULLTAG;
char * name="\0";
char * num="\0";
ITKCALL(AOM_ask_value_string(c_line_tags[m],"bl_indented_title",&name));//获取BOMLINE行
ITKCALL(AOM_ask_value_string(c_line_tags[m],"WF2_number",&num));
if(strcmp("",num) == 0 || strcmp(" ",num) == 0)
{
strcat(err,"[");
strcat(err,name);
strcat(err,"]");
}else{
}
getchibomline_num(c_line_tags[m],err);
}
}
return true;
}
//word文档插入印章图片
int WF_set_picture(EPM_action_message_t msg){
printf("===================================\n");
printf("word文档插入印章图片 开始\n");
printf("===================================\n");
int ifail = ITK_ok;
int att_cnt=0,jpg_count=0;
tag_t task_tag = NULLTAG,
root_task_tag=NULLTAG,
*attachments=NULL;
char** jpg_values;
tag_t jpg_tag=NULLTAG;
tag_t *pathFile=NULLTAG;
int Num = 0;
printf("开超级权限\n");
POM_AM__set_application_bypass(true);
task_tag = msg.task;
EPM_ask_root_task(task_tag, &root_task_tag);
EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnt, &attachments);
ITKCALL(PREF_ask_char_values("WF2_JPG_PATH",&jpg_count,&jpg_values));
ITK__convert_uid_to_tag(jpg_values[0],&jpg_tag);
ITKCALL(AOM_ask_value_tags(jpg_tag,"ref_list",&Num,&pathFile));
char jpg_path[SS_MAXPATHLEN] = "";
ITKCALL(IMF_ask_file_pathname(pathFile[0], SS_WNT_MACHINE, jpg_path));
if(att_cnt>0){
for (int i = 0; i < att_cnt; i++)
{
int doc_num=0;
tag_t *doc_tags=NULL;
tag_t * dataFile = NULL;
int fileNum = 0;
char* tag_type;
char * type;
char * name;
ITKCALL(AOM_ask_value_string(attachments[i],"object_type",&tag_type));
printf("tag_type=%s\n",tag_type);
if (strstr(tag_type,"Revision") != NULL && strstr(tag_type,"Master") == NULL)
{
ITKCALL(AOM_ask_value_tags(attachments[i],"IMAN_specification",&doc_num,&doc_tags));
if (doc_num > 0)
{
for (int i = 0; i < doc_num; i++)
{
ITKCALL(AOM_ask_value_string(doc_tags[i],"object_type",&type));
printf("type=%s\n",type);
if (strcmp(type,"MSWordX")==0){
//ITKCALL(AOM_ask_value_tags(doc_tags[i],"ref_list",&fileNum,&dataFile));
tag_t spec_dataset_rev = NULLTAG , ref_object = NULLTAG;
AE_reference_type_t reference_type;
AE_ask_dataset_latest_rev(doc_tags[i], &spec_dataset_rev);
char ref_name[WSO_name_size_c + 1] = "Fnd0word";
AE_ask_dataset_named_ref(spec_dataset_rev, ref_name, &reference_type, &ref_object);
if(reference_type == AE_PART_OF)
{
char pathname[SS_MAXPATHLEN] = "";
ITKCALL(IMF_ask_file_pathname(ref_object, SS_WNT_MACHINE, pathname));
char origin_file_name[IMF_filename_size_c + 1] = "";
IMF_ask_original_file_name(ref_object, origin_file_name);
char new_ds_name[WSO_name_size_c + 1] = "";
char *new_file_name = USER_new_file_name(new_ds_name, ref_name, "docm", 0);
char *temp_dir = getenv("temp");
char temp_file[SS_MAXPATHLEN] = "";
strcpy(temp_file, temp_dir);
strcat(temp_file, "\\");
strcat(temp_file, new_file_name);
IMF_export_file(ref_object, temp_file);
char path[128] = "\0";
strcat(path,getenv("TEMP"));
strcat(path, "\\");
strcat(path, new_file_name);
strcat(path,".txt");
FILE *fpWrite=fopen(path,"w");
fprintf(fpWrite,"%s","受控印章=");
fprintf(fpWrite,"%s\n",jpg_path);
fclose(fpWrite);
char cmd[256] = "";
strcpy(cmd, "SubstMacros-MSWord.wsf");
strcat(cmd, " \"");
strcat(cmd, temp_file);
strcat(cmd, "\" \"");
strcat(cmd, path);
strcat(cmd, "\"");
printf("\n%s\n",cmd);
system(cmd);
tag_t new_file_tag = NULLTAG;
IMF_file_t file_descriptor;
IMF_import_file(temp_file, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor);
IMF_set_original_file_name(new_file_tag, origin_file_name);
IMF_close_file(file_descriptor);
AOM_save(new_file_tag);
AOM_unlock(new_file_tag);
AOM_lock(spec_dataset_rev);
AE_remove_dataset_named_ref_by_tag(spec_dataset_rev, ref_name, ref_object);
AE_add_dataset_named_ref(spec_dataset_rev, ref_name, AE_PART_OF, new_file_tag);
AOM_save(spec_dataset_rev);
AOM_unlock(spec_dataset_rev);
}
}else if (strcmp(type,"MSExcelX")==0)
{
//ITKCALL(AOM_ask_value_tags(doc_tags[i],"ref_list",&fileNum,&dataFile));
tag_t spec_dataset_rev = NULLTAG , ref_object = NULLTAG;
AE_reference_type_t reference_type;
AE_ask_dataset_latest_rev(doc_tags[i], &spec_dataset_rev);
char ref_name[WSO_name_size_c + 1] = "excel";
AE_ask_dataset_named_ref(spec_dataset_rev, ref_name, &reference_type, &ref_object);
if(reference_type == AE_PART_OF)
{
char pathname[SS_MAXPATHLEN] = "";
ITKCALL(IMF_ask_file_pathname(ref_object, SS_WNT_MACHINE, pathname));
char origin_file_name[IMF_filename_size_c + 1] = "";
IMF_ask_original_file_name(ref_object, origin_file_name);
char new_ds_name[WSO_name_size_c + 1] = "";
char *new_file_name = USER_new_file_name(new_ds_name, ref_name, "xlsm", 0);
char *temp_dir = getenv("temp");
char temp_file[SS_MAXPATHLEN] = "";
strcpy(temp_file, temp_dir);
strcat(temp_file, "\\");
strcat(temp_file, new_file_name);
IMF_export_file(ref_object, temp_file);
char path[128] = "\0";
strcat(path,getenv("TEMP"));
strcat(path, "\\");
strcat(path, new_file_name);
strcat(path,".txt");
FILE *fpWrite=fopen(path,"w");
fprintf(fpWrite,"%s","受控印章=");
fprintf(fpWrite,"%s\n",jpg_path);
fclose(fpWrite);
char cmd[256] = "";
strcpy(cmd, "SubstMacros-MSExcel.wsf");
strcat(cmd, " \"");
strcat(cmd, temp_file);
strcat(cmd, "\" \"");
strcat(cmd, path);
strcat(cmd, "\"");
printf("\n%s\n",cmd);
system(cmd);
tag_t new_file_tag = NULLTAG;
IMF_file_t file_descriptor;
IMF_import_file(temp_file, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor);
IMF_set_original_file_name(new_file_tag, origin_file_name);
IMF_close_file(file_descriptor);
AOM_save(new_file_tag);
AOM_unlock(new_file_tag);
AOM_lock(spec_dataset_rev);
AE_remove_dataset_named_ref_by_tag(spec_dataset_rev, ref_name, ref_object);
AE_add_dataset_named_ref(spec_dataset_rev, ref_name, AE_PART_OF, new_file_tag);
AOM_save(spec_dataset_rev);
AOM_unlock(spec_dataset_rev);
}
}
}
}
}
}
}
printf("关超级权限\n");
POM_AM__set_application_bypass(false);
printf("===================================\n");
printf("word文档插入印章图片 结束\n");
printf("===================================\n");
return ifail;
}
//word文档插入文件下发顺序号
int WF_set_ID(EPM_action_message_t msg){
printf("===================================\n");
printf("word文档插入文件下发顺序号 开始\n");
printf("===================================\n");
int ifail = ITK_ok;
int att_cnt=0;
tag_t task_tag = NULLTAG,
item_tag = NULLTAG,
root_task_tag=NULLTAG,
*attachments=NULL;
char *message;
char** entries;
char** values;
tag_t* results;
char * rev;
char * item_type;
char * ID;
char WF_time[32] = "\0"; //当前时间
int doc_num=0;
tag_t *doc_tags=NULL;
tag_t * dataFile = NULL;
int fileNum = 0;
char* tag_type;
char * type;
char * name;
printf("开超级权限\n");
POM_AM__set_application_bypass(true);
task_tag = msg.task;
EPM_ask_root_task(task_tag, &root_task_tag);
EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnt, &attachments);
ITKCALL(AOM_ask_value_string(attachments[0],"item_revision_id",&rev));
ITKCALL(ITEM_ask_item_of_rev(attachments[0],&item_tag));
ITKCALL(AOM_ask_value_string(item_tag,"wf2_time_id",&ID));
ITKCALL(AOM_ask_value_string(attachments[0],"object_type",&item_type));
time_t t;
struct tm * lt;
time (&t);//获取Unix时间戳。
lt = localtime (&t);//转为时间结构。
int lenth = 0;
lenth = len(ID);
printf("lenth=【%d】\n", lenth );
char str[20] = {""};
strcpy(str, ID);
char dest[20] = {""};
strncpy(dest, str, 4);
printf("dest=【%s】\n", dest );
char year[32] = "\0"; //当前年份
sprintf(year,"%d",lt->tm_year+1900);
printf("year=【%s】\n", year );
if(strcmp("",ID)!=0 && strcmp(year,dest)==0){
printf("顺序号不为空\n");
strcat(WF_time,ID);
strcat(WF_time,rev);
printf("文件下发顺序号为:%s\n",WF_time);
}else{
printf("顺序号为空\n");
char before_time[32] = "\0"; //早于时间
char after_time[32] = "\0"; //晚于时间
sprintf(before_time,"%d-%d-%d %d%d:%d%d",lt->tm_year+1900,12,31,0,0,0,0);
sprintf(after_time,"%d-%d-%d %d%d:%d%d",lt->tm_year+1900,1,1,0,0,0,0);
//构建器
const char query_name_product[1][QRY_name_size_c + 1]={"文件下发查询"};
tag_t query_tag=NULLTAG;
int Num = 0;
int entry_count1=0;
char** entries1;
char** values1;
char *other_values1[4];
char *other_entrys1[4];
for (int i = 0; i < 4; i++)
{
other_values1[i] = (char*)calloc(48,sizeof(char));
other_entrys1[i] = (char*)calloc(48,sizeof(char));
}
ITKCALL(QRY_find(query_name_product[0],&query_tag));
if(query_tag==NULLTAG)
{
printf("query_tag=NULLTAG,没找到 [%s]查询构建器!\n",query_name_product[0] );
ITK_exit_module(1);
return 1;
}
else
{
printf("找到查询构建器\n");
}
ITKCALL(QRY_find_user_entries(query_tag,&entry_count1,&entries1,&values1));//entries1查询条件表达式values1查询条件值MEM_free释放
if(entry_count1==0)
{
printf("entry_count1=0,查询构建器中没有配置查询条件!\n");
//ITK_exit_module(1);
if(entries!=NULL){
MEM_free(entries1);
entries1= NULL;
}
if(values1!=NULL){
MEM_free(values1);
values1= NULL;
}
return 1;
}
//date_tag.second = p->tm_sec ;
for(int n=0;n<entry_count1;n++)
{
printf("entries1[%d]=%s\n",n,entries1[n]);
if(tc_strcmp(entries1[n],"类型")==0){
//strcpy(values[n],nowtime1);
tc_strcpy(other_entrys1[n],"类型");
tc_strcpy(other_values1[n],item_type);//*
printf("other_values1[%d] %s\n",n,other_values1[n]);
}
if(tc_strcmp(entries1[n],"版本")==0){
//strcpy(values[n],nowtime1);
tc_strcpy(other_entrys1[n],"版本");
tc_strcpy(other_values1[n],"A");//*
printf("other_values1[%d] %s\n",n,other_values1[n]);
}
if(tc_strcmp(entries1[n],"发布时间早于")==0){
//strcpy(values[n],nowtime1);
tc_strcpy(other_entrys1[n],"发布时间早于");
tc_strcpy(other_values1[n],before_time);//*
printf("other_values1[%d] %s\n",n,other_values1[n]);
}
if(tc_strcmp(entries1[n],"发布时间晚于")==0){
//strcpy(values[n],nowtime1);
tc_strcpy(other_entrys1[n],"发布时间晚于");
tc_strcpy(other_values1[n],after_time);//*
printf("other_values1[%d] %s\n",n,other_values1[n]);
}
printf("other_values1[%d]=%s\n",n,other_values1[n]);
}
ITKCALL(ifail = QRY_execute(query_tag,4,other_entrys1,other_values1,&Num,&results));
if(ifail !=ITK_ok){
EMH_ask_error_text(ifail, &message);
printf("程序异常 : \"%d\",\"%s\"\n",ifail,message);
MEM_free(message);
if(entries1!=NULL){
MEM_free(entries1);
entries1= NULL;
}
if(values1!=NULL){
MEM_free(values1);
values1= NULL;
}
return 1;
}
if(Num==0)
{
printf("Num=0,查询构建器中没找到满足条件的数据!\n");
//ITK_exit_module(1);
if(entries1!=NULL){
MEM_free(entries1);
entries1= NULL;
}
if(values1!=NULL){
MEM_free(values1);
values1= NULL;
}
}
//开始获取产品信息
printf("查询构建器得到ITEM数num_found1: \"%d\" \n", Num);
if (Num<10)
{
if (lt->tm_mon+1 < 10)
{
sprintf(WF_time,"%d%s%d-%s%s%d-",lt->tm_year+1900,"0",lt->tm_mon+1,"0","0",Num+1);
}else
{
sprintf(WF_time,"%d%d-%s%s%d-",lt->tm_year+1900,lt->tm_mon+1,"0","0",Num+1);
}
}else if(Num < 100 && Num > 10)
{
if (lt->tm_mon+1 < 10)
{
sprintf(WF_time,"%d%s%d-%s%d-",lt->tm_year+1900,"0",lt->tm_mon+1,"0",Num+1);
}else
{
sprintf(WF_time,"%d%d-%s%d-",lt->tm_year+1900,lt->tm_mon+1,"0",Num+1);
}
}else
{
if (lt->tm_mon+1 < 10)
{
sprintf(WF_time,"%d%s%d-%d-",lt->tm_year+1900,"0",lt->tm_mon+1,Num+1);
}else
{
sprintf(WF_time,"%d%d-%d-",lt->tm_year+1900,lt->tm_mon+1,Num+1);
}
}
printf("文件编号为: \"%s\" \n", WF_time);
AOM_lock(item_tag);
ITKCALL(ifail = AOM_set_value_string(item_tag,"wf2_time_id",WF_time));
AOM_save(item_tag);
AOM_unlock(item_tag);
if(ifail !=ITK_ok){
printf("属性设值异常 \n");
return 1;
}
strcat(WF_time,rev);
printf ( "%d/%d/%d %d:%d:%d\n",lt->tm_year+1900, lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec);//输出结果
printf("文件下发顺序号为:%s\n",WF_time);
}
ITKCALL(AOM_ask_value_tags(attachments[0],"IMAN_specification",&doc_num,&doc_tags));
if (doc_num > 0)
{
for (int i = 0; i < doc_num; i++)
{
ITKCALL(AOM_ask_value_string(doc_tags[i],"object_type",&type));
if (strcmp(type,"MSWordX")==0)
{
printf("type=%s\n",type);
//ITKCALL(AOM_ask_value_tags(doc_tags[i],"ref_list",&fileNum,&dataFile));
tag_t spec_dataset_rev = NULLTAG , ref_object = NULLTAG;
AE_reference_type_t reference_type;
AE_ask_dataset_latest_rev(doc_tags[i], &spec_dataset_rev);
char ref_name[WSO_name_size_c + 1] = "Fnd0word";
AE_ask_dataset_named_ref(spec_dataset_rev, ref_name, &reference_type, &ref_object);
if(reference_type == AE_PART_OF)
{
char pathname[SS_MAXPATHLEN] = "";
ITKCALL(IMF_ask_file_pathname(ref_object, SS_WNT_MACHINE, pathname));
char origin_file_name[IMF_filename_size_c + 1] = "";
IMF_ask_original_file_name(ref_object, origin_file_name);
char new_ds_name[WSO_name_size_c + 1] = "";
char *new_file_name = USER_new_file_name(new_ds_name, ref_name, "docm", 0);
char *temp_dir = getenv("temp");
char temp_file[SS_MAXPATHLEN] = "";
strcpy(temp_file, temp_dir);
strcat(temp_file, "\\");
strcat(temp_file, new_file_name);
IMF_export_file(ref_object, temp_file);
char path[128] = "\0";
char doc_id[128] = "\0";
strcat(path,getenv("TEMP"));
strcat(path, "\\");
strcat(path, new_file_name);
strcat(path, "-文件编号");
strcat(path,".txt");
printf("path为%s\n",path);
FILE *fpWrite=fopen(path,"w");
fprintf(fpWrite,"%s","文件编号=");
strcat(doc_id,WF_time);
fprintf(fpWrite,"%s\n",doc_id);
fclose(fpWrite);
printf("文件编号存储成功\n");
char cmd[256] = "";
strcpy(cmd, "SetID-MSWord.wsf");
strcat(cmd, " \"");
strcat(cmd, temp_file);
strcat(cmd, "\" \"");
strcat(cmd, path);
strcat(cmd, "\"");
printf("\n%s\n",cmd);
system(cmd);
tag_t new_file_tag = NULLTAG;
IMF_file_t file_descriptor;
IMF_import_file(temp_file, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor);
IMF_set_original_file_name(new_file_tag, origin_file_name);
IMF_close_file(file_descriptor);
AOM_save(new_file_tag);
AOM_unlock(new_file_tag);
AOM_lock(spec_dataset_rev);
AE_remove_dataset_named_ref_by_tag(spec_dataset_rev, ref_name, ref_object);
AE_add_dataset_named_ref(spec_dataset_rev, ref_name, AE_PART_OF, new_file_tag);
AOM_save(spec_dataset_rev);
AOM_unlock(spec_dataset_rev);
}
}
}
}
printf("关超级权限\n");
POM_AM__set_application_bypass(false);
printf("===================================\n");
printf("word文档插入文件下发顺序号 结束\n");
printf("===================================\n");
return ifail;
}
//对象自动指派项目
int WF_item_to_Project(EPM_rule_message_t msg){
ECHO("==================目标对象指派项目=======================\n");
int ifail = EPM_go ,
att_cnt=0,
pro_col=0,
i = 0 ,
j=0,
n=0;
tag_t task_tag = NULLTAG ,
root_task_tag =NULLTAG ,
* pro_tags=NULL,
pro_tag=NULL,
*attachments = NULL;
boolean isadmin=false;
boolean istaskname=false;
char errs[10240] = "\0";
task_tag = msg.task;
if(task_tag == NULLTAG)
{
printf("对象为空,退出\n");
return EPM_nogo;
}
EPM_ask_root_task(task_tag, &root_task_tag);
EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnt, &attachments);
int count = 0 ;
tag_t * schdule_task_nodes = NULL;
char * schdule_task_name=NULL;
printf("开始获取SCHDULE任务 \n");
AOM_ask_value_tags(task_tag,"fnd0RootScheduleTask",&count,&schdule_task_nodes);
printf("count=%d \n",count);
if(count>0){
tag_t schdule = NULL_TAG;
int couwork_all=0,
couwork_sta=0;
tag_t * work_tag_all=NULL,
* work_tag_sta=NULL;
char * workname;
char * workname1;
ITKCALL(AOM_ask_value_tag(schdule_task_nodes[0],"schedule_tag",&schdule));
ITKCALL(AOM_ask_value_string(schdule_task_nodes[0],"object_name",&schdule_task_name));
ITKCALL(AOM_ask_value_tags(schdule,"fnd0AllWorkflows",&couwork_all,&work_tag_all));//总工作流程
ITKCALL(AOM_ask_value_tags(schdule,"fnd0StartedWorkflowTasks",&couwork_sta,&work_tag_sta));//已开始的工作流程
ITKCALL(AOM_ask_value_tags(schdule,"project_list",&pro_col,&pro_tags));//项目
if(pro_col>0){
pro_tag=pro_tags[0];
}else{
EMH_store_error_s1(EMH_severity_information,278701,"该任务所关联时间表未指派项目,无法完成任务!!!");//错误弹窗
printf("该任务所关联时间表未指派项目,无法完成任务\n");
return EPM_nogo;
}
int prouser_col_1=0,
prouser_col_2=0,
prouser_col_3=0;
tag_t aUserTag=NULLTAG,
* prouser_tag_1=NULL,
* prouser_tag_2=NULL,
* prouser_tag_3=NULL;
char * userName=NULL,
//person_name[SA_name_size_c+1]="",
* person_name=NULL,
* user_name1=NULL,
* user_name2=NULL,
* user_name3=NULL;
PROJ_ask_team(pro_tag,&prouser_col_1,&prouser_tag_1,&prouser_col_2,&prouser_tag_2,&prouser_col_3,&prouser_tag_3);//获得项目成员
printf("prouser_col_1=%d prouser_col_2=%d prouser_col_3=%d\n ",prouser_col_1,prouser_col_2,prouser_col_3);
//获取当前的用户
POM_get_user(&userName,&aUserTag);
//获取personname
ITKCALL(AOM_ask_value_string(aUserTag,"user_name",&person_name));
//SA_ask_user_person_name(aUserTag,person_name);
printf("当前用户person_name=%s\n",person_name);
if (prouser_col_2>0) //管理员用户
{
for (int i = 0; i < prouser_col_2; i++)
{
ITKCALL(AOM_ask_value_string(prouser_tag_2[i],"user_name",&user_name2));
printf("prouser_tag_2=%s\n",user_name2);
if(strcmp( user_name2, person_name ) == 0){
isadmin=true;
}
}
}
if(userName !=NULL){
MEM_free(userName);
userName = NULL;
}
if(person_name !=NULL){
MEM_free(person_name);
userName = NULL;
}
if(user_name1 !=NULL){
MEM_free(user_name1);
user_name1 = NULL;
}
if(user_name2 !=NULL){
MEM_free(user_name2);
user_name2 = NULL;
}
if(user_name3 !=NULL){
MEM_free(user_name3);
user_name3 = NULL;
}
}
printf("开始指派项目\n");
strcat(errs, "存在目标对象");
for(i = 0 ;i < att_cnt;i++){
tag_t target_tag = attachments[i];//目标下 文件夹
char * task_type = NULL;
char err[100]="\0";
//ITKCALL(AOM_ask_value_string(target_tag,"object_string",&item_id_temp));
int item_count=0;
tag_t *item_tags=NULL;
printf("111\n");
ITKCALL(AOM_ask_value_string(target_tag,"object_type",&task_type));
printf("current task type = %s\n", task_type);
if((strstr(task_type,"Folder") != NULL)){//判断是否文件夹
ITKCALL(AOM_ask_value_tags(target_tag,"contents",&item_count,&item_tags));
if(item_count>0){
for(j=0;j<item_count;j++){
char * item_id_temp=NULL,*object_type=NULL;
int rev_count=0;
tag_t *rev_tags=NULL,items_tag=NULL;
int projectlen=0;
tag_t *projects=NULL;
if (checkIsTypeOrSubtype(item_tags[j],"Item")!=1)
{
EMH_store_error_s1(EMH_severity_information,278701,"文件夹下存在不符的类型!!!");//错误弹窗
printf("文件夹下存在不符的类型\n");
return EPM_nogo;
}
ITKCALL(AOM_ask_value_string(item_tags[j],"item_id",&item_id_temp));
ITKCALL(AOM_ask_value_string(item_tags[j],"object_type",&object_type));
ITKCALL(AOM_ask_value_tags(item_tags[j],"project_list",&projectlen,&projects));//获得项目
if(projectlen==0){
tag_t * release_objs = NULL;
int temp_count = 1;
release_objs = (tag_t *)MEM_alloc(temp_count*sizeof(tag_t));
release_objs[0] = item_tags[j];
printf("对象[%s]未指派项目,开始指派\n",item_id_temp);
PROJ_assign_objects(pro_col,pro_tags,temp_count,release_objs);//指派项目
printf("对象[%s]指派完成\n",item_id_temp);
}else{
printf("对象[%s]已指派项目\n",item_id_temp);
}
if(item_id_temp !=NULL){
MEM_free(item_id_temp);
item_id_temp = NULL;
}
if(rev_tags !=NULL){
MEM_free(rev_tags);
rev_tags = NULL;
}
if(object_type !=NULL){
MEM_free(object_type);
object_type = NULL;
}
}
}else{
if(istaskname&&isadmin){
printf("是管理员且为首选项配置的特殊任务\n");
}else{
EMH_store_error_s1(EMH_severity_information,278701,"文件夹下没有对象不允许完成!!!");//错误弹窗
printf("文件夹下没有对象不允许完成\n");
return EPM_nogo;
}
}
}
printf("ifail_1=%d \n",ifail);
if(task_type !=NULL){
MEM_free(task_type);
task_type = NULL;
}
if(item_tags !=NULL){
MEM_free(item_tags);
item_tags = NULL;
}
}
printf("ifail_2=%d \n",ifail);
if(ifail==EPM_nogo){
//PROP_unable_to_set_cp_value ERROR_ERRORSTORE_NOERRORS//919002
printf("%s \n",errs);
EMH_store_error_s1(EMH_severity_information,278701,errs);//错误弹窗
}
ECHO("==================对象自动指派项目完成 =======================\n");
return ifail;
}
//机加工计划插入图纸图片
int WF_into_picture(EPM_action_message_t msg){
printf("===================================\n");
printf("机加工计划插入图纸图片 开始\n");
printf("===================================\n");
int ifail = ITK_ok;
int att_cnt=0,jpg_count=0;
tag_t task_tag = NULLTAG,
root_task_tag=NULLTAG,
*attachments=NULL;
char** jpg_values;
tag_t jpg_tag=NULLTAG;
tag_t *pathFile=NULLTAG;
int Num = 0;
printf("开超级权限\n");
POM_AM__set_application_bypass(true);
task_tag = msg.task;
EPM_ask_root_task(task_tag, &root_task_tag);
EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnt, &attachments);
if(att_cnt>0){
for (int i = 0; i < att_cnt; i++)
{
int doc_num=0;
tag_t *doc_tags=NULL;
tag_t * dataFile = NULL;
int fileNum = 0;
char* tag_type;
char* project_id;
char * type;
char * name;
ITKCALL(AOM_ask_value_string(attachments[i],"object_type",&tag_type));
printf("tag_type=%s\n",tag_type);
if (strstr(tag_type,"Revision") != NULL)
{
ITKCALL(AOM_ask_value_string(attachments[i],"project_ids",&project_id));
printf("project_id=%s\n",project_id);
char id[512]="";
strcpy(id,"T");
strcat(id,project_id);
printf("id=%s\n",id);
const char query_name_product[1][QRY_name_size_c + 1]={"零组件 ID"};
char *message;
tag_t* results;
tag_t query_tag1=NULLTAG;
int entry_count1=0;
char** entries1;
char** values1;
char *other_values1[1];
char *other_entrys1[1];
other_values1[0] = (char*)calloc(48,sizeof(char));
other_entrys1[0] = (char*)calloc(48,sizeof(char));
int num_found1=0;
ITKCALL(QRY_find(query_name_product[0],&query_tag1));
if(query_tag1==NULLTAG)
{
WriteLog("query_tag=NULLTAG,没找到 [%s]查询构建器!\n",query_name_product[0] );
ITK_exit_module(1);
return 0;
}else
{
WriteLog("找到查询构建器\n");
}
ITKCALL(QRY_find_user_entries(query_tag1,&entry_count1,&entries1,&values1));//entries1查询条件表达式values1查询条件值MEM_free释放
if(entry_count1==0)
{
WriteLog("entry_count1=0,查询构建器中没有配置查询条件!\n");
//ITK_exit_module(1);
if(entries1!=NULL){
MEM_free(entries1);
entries1= NULL;
}
if(values1!=NULL){
MEM_free(values1);
values1= NULL;
}
return 0;
}
for(int n=0;n<entry_count1;n++)
{
printf("entries1[%d]=%s\n",n,entries1[n]);
if(tc_strcmp(entries1[n],"零组件 ID")==0){
//strcpy(values[n],nowtime1);
tc_strcpy(other_entrys1[0],"零组件 ID");
tc_strcpy(other_values1[0],id);//* 2012-05 NBJF16025 Test001 NBJF16046 16C104
printf("other_values1[0] %s\n",other_values1[0]);
}
printf("values[%d]=%s\n",n,values1[n]);
}
ITKCALL(QRY_execute(query_tag1,1,other_entrys1,other_values1,&num_found1,&results));
if(num_found1==0)
{
printf("num_found=0,查询构建器中没找到满足条件的数据!\n");
//ITK_exit_module(1);
if(entries1!=NULL){
MEM_free(entries1);
entries1= NULL;
}
if(values1!=NULL){
MEM_free(values1);
values1= NULL;
}
}
//开始获取产品信息
printf("查询构建器得到ITEM数num_found1: \"%d\" \n", num_found1);
char path[512]=""; //产品图片路径
for(int k=0;k<num_found1;k++)
{
tag_t itemtag= results[k];
char * uid;
int prodDraw_count=0;
tag_t * prodDraw_tags = NULL;
char * type;
int dataset_count=0;
tag_t * dataset_tags = NULL;
tag_t latest_tag = NULL;
char uid1[512]="";
char target_type1[512]="";
ITK__convert_tag_to_uid(itemtag, &uid);
strcpy(uid1,uid);
ITKCALL(ITEM_ask_latest_rev(itemtag,&latest_tag));
ITKCALL(AOM_ask_value_tags(latest_tag,"IMAN_specification",&dataset_count,&dataset_tags));
char * type1;
for (int i = 0; i < dataset_count; i++)
{
ITKCALL(AOM_ask_value_string(dataset_tags[i],"object_type",&type1));
if (tc_strcmp("TIF",type1)==0)
{
strcpy(path,"D:\\picPath\\");
strcat(path,uid1);
int target_count=0;
tag_t * target_tags = NULL;
char * target_type;
ITKCALL(AOM_ask_value_tags(dataset_tags[i],"ref_list",&target_count,&target_tags));
ITKCALL(AOM_ask_value_string(target_tags[0],"file_ext",&target_type));
strcpy(target_type1,target_type);
strcat(path,".");
strcat(path,target_type1);
IMF_export_file(target_tags[0],path);
}
}
}
ITKCALL(AOM_ask_value_tags(attachments[i],"IMAN_specification",&doc_num,&doc_tags));
if (doc_num > 0)
{
for (int i = 0; i < doc_num; i++)
{
ITKCALL(AOM_ask_value_string(doc_tags[i],"object_type",&type));
printf("type=%s\n",type);
if (strcmp(type,"MSExcelX")==0)
{
//ITKCALL(AOM_ask_value_tags(doc_tags[i],"ref_list",&fileNum,&dataFile));
tag_t spec_dataset_rev = NULLTAG , ref_object = NULLTAG;
AE_reference_type_t reference_type;
AE_ask_dataset_latest_rev(doc_tags[i], &spec_dataset_rev);
char ref_name[WSO_name_size_c + 1] = "excel";
AE_ask_dataset_named_ref(spec_dataset_rev, ref_name, &reference_type, &ref_object);
if(reference_type == AE_PART_OF)
{
char pathname[SS_MAXPATHLEN] = "";
ITKCALL(IMF_ask_file_pathname(ref_object, SS_WNT_MACHINE, pathname));
char origin_file_name[IMF_filename_size_c + 1] = "";
IMF_ask_original_file_name(ref_object, origin_file_name);
char new_ds_name[WSO_name_size_c + 1] = "";
char *new_file_name = USER_new_file_name(new_ds_name, ref_name, "xlsm", 0);
char *temp_dir = getenv("temp");
char temp_file[SS_MAXPATHLEN] = "";
strcpy(temp_file, temp_dir);
strcat(temp_file, "\\");
strcat(temp_file, new_file_name);
IMF_export_file(ref_object, temp_file);
char path1[128] = "\0";
strcat(path1,getenv("TEMP"));
strcat(path1, "\\");
strcat(path1, new_file_name);
strcat(path1,".txt");
FILE *fpWrite=fopen(path1,"w");
fprintf(fpWrite,"%s","样品图片=");
fprintf(fpWrite,"%s\n",path);
fclose(fpWrite);
char cmd[256] = "";
strcpy(cmd, "SetPicture-MSExcel.wsf");
strcat(cmd, " \"");
strcat(cmd, temp_file);
strcat(cmd, "\" \"");
strcat(cmd, path1);
strcat(cmd, "\"");
printf("\n%s\n",cmd);
system(cmd);
remove(path);
tag_t new_file_tag = NULLTAG;
IMF_file_t file_descriptor;
IMF_import_file(temp_file, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor);
IMF_set_original_file_name(new_file_tag, origin_file_name);
IMF_close_file(file_descriptor);
AOM_save(new_file_tag);
AOM_unlock(new_file_tag);
AOM_lock(spec_dataset_rev);
AE_remove_dataset_named_ref_by_tag(spec_dataset_rev, ref_name, ref_object);
AE_add_dataset_named_ref(spec_dataset_rev, ref_name, AE_PART_OF, new_file_tag);
AOM_save(spec_dataset_rev);
AOM_unlock(spec_dataset_rev);
}
}
}
}
}
}
}
printf("关超级权限\n");
POM_AM__set_application_bypass(false);
printf("===================================\n");
printf("机加工计划插入图纸图片图片 结束\n");
printf("===================================\n");
return ifail;
}
//复制流程到当前home目录下的文件夹
int WF_LC_Folder_System(EPM_action_message_t msg) {
printf("===================================\n");
printf("复制流程到当前home目录下的文件夹 开始 \n");
printf("===================================\n");
int ifail = ITK_ok;
printf("开超级权限\n");
POM_AM__set_application_bypass(true);
char *userName;
tag_t aUserTag = NULLTAG;//当前用户对象
tag_t homefolder = NULLTAG; //拿到当前用户的home文件夹对象
tag_t targetfolder = NULLTAG; //获取指定文件夹对象
tag_t *folder; //
int item_count = 0;
tag_t newcopyFolder = NULLTAG; //复制的到的新的文件夹对象
char *task_name;
int s = 0;
//流程节点相关
tag_t root_task = NULLTAG, *sub_tasks = NULL, current_task = NULLTAG, type_tag = NULLTAG;
printf("流程节点相关\n");
int sub_task_count = 0;
//EPM_ask_root_task(task_tag, &root_task_tag);
// EPM_ask_attachments(root_task_tag, EPM_target_attachment, &att_cnd, &attachments);
printf("获取用户\n");
s = POM_get_user(&userName, &aUserTag);
//获取当前用户的home文件夹
ITKCALL(SA_ask_user_home_folder(aUserTag, &homefolder));
//获取指定的文件夹对象
ITKCALL(AOM_ask_value_tags(homefolder,"contents",&item_count,&folder));
for (int i = 0; i < item_count; i++)
{
char *name;
ITKCALL(AOM_ask_value_string(folder[i],"object_name",&name));
if(strcmp("我的文件夹",name)==0){
targetfolder = folder[i];
break;
}
if(name != NULL){
MEM_free(name);
}
}
//得到触发handler的节点
//msg.task;
current_task = msg.task;
//判断当前节点
if (current_task != NULLTAG)
{
printf("%%%%%%%%%%%%++++++++++++++ 当前节点不为空");
char *task_name;
ITKCALL(AOM_ask_value_string(current_task, "object_name", &task_name));
ECHO("task_name = %s\n", task_name);
if(strstr(task_name,"编制")!=NULL){
if(targetfolder != NULL){
ITKCALL(FL_insert(targetfolder, current_task, 999));
ITKCALL(AOM_save(targetfolder));
}else
{
ITKCALL(FL_insert(homefolder, current_task, 999));
ITKCALL(AOM_save(homefolder));
}
}else{
int count = 0,perform_count = 0,usr_item_count = 0;
tag_t *be_tag = NULLTAG,*usr_folder;
char *node_task_name;
tag_t *perform_attaches = NULLTAG,memberTag = NULLTAG,user_tag = NULLTAG,usr_homefolder = NULLTAG;
int *attach_type;
SIGNOFF_TYPE_t memberType;
ITKCALL(AOM_ask_value_tags(current_task,"predecessors",&count, &be_tag));
for (int j = 0; j < count; j++)
{
EPM_ask_name2(be_tag[j], &node_task_name);
ECHO("node_task_name = %s\n", node_task_name);
if (stricmp(node_task_name, "select-signoff-team") == 0) {
EPM_ask_all_attachments(be_tag[j], &perform_count, &perform_attaches, &attach_type);
ECHO("perform_count=%d\n", perform_count);
for (int i = 0; i<perform_count; i++)
{
EPM_ask_signoff_member(perform_attaches[i], &memberTag, &memberType);
SA_ask_groupmember_user(memberTag, &user_tag);
//获取当前用户的home文件夹
ITKCALL(SA_ask_user_home_folder(user_tag, &usr_homefolder));
//获取指定的文件夹对象
ITKCALL(AOM_ask_value_tags(usr_homefolder,"contents",&usr_item_count,&usr_folder));
for (int i = 0; i < usr_item_count; i++)
{
char *name1;
ITKCALL(AOM_ask_value_string(usr_folder[i],"object_name",&name1));
if(strcmp("我的文件夹",name1)==0){
targetfolder = usr_folder[i];
break;
}
if(name1 != NULL){
MEM_free(name1);
}
}
//得到父节点
tag_t tempTask = NULLTAG;
char *cur_task_name;
EPM_ask_parent_task( current_task, &tempTask );
EPM_ask_name2( tempTask, &cur_task_name );
ECHO("cur_task_name=%s\n", cur_task_name);
if(targetfolder != NULL){
ITKCALL(FL_insert(targetfolder, tempTask, 999));
ITKCALL(AOM_save(targetfolder));
}else
{
ITKCALL(FL_insert(usr_homefolder, tempTask, 999));
ITKCALL(AOM_save(usr_homefolder));
}
}
break;
}
}
}
//ITKCALL(FL_copy2(current_task, task_name, &newcopyFolder));
printf("将任务节点对象保存到当前用户的Home文件夹下\n");
}
printf("关闭级权限\n");
POM_AM__set_application_bypass(false);
printf("=====================\n");
printf("复制流程到当前home目录下的文件夹 结束 \n");
printf("=====================\n");
return ifail;
}