ITK根据特征码获取TC系统流水

ITK根据特征码获取TC系统流水


1.IKT代码

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "epm_handler_common.h"

int get_serial_number( int val_len, char **val, char **project_id );

int userservice_serial_number_by_code(void * returnValueType){

	
	char **tzm_array;
	int array_len;
	int code_len;
	char *newID;
	char **val;
	//获取参数
	ITKCALL(USERARG_get_string_array_argument(&array_len,&tzm_array));//特征码数组
	ITKCALL(USERARG_get_int_argument(&code_len));//流水码长度
	
	val = (char**)MEM_alloc((array_len+1)*sizeof(char*));
	for (int i = 0; i < array_len; i++)
	{
		val[i] = (char*)MEM_alloc( (tc_strlen(tzm_array[i])+1 ) * sizeof(char));
		tc_strcpy( val[i], tzm_array[i]);
	}
	

	val[array_len] = (char*)MEM_alloc( (code_len+1) * sizeof(char));
	for (int i = 0; i < code_len; i++)
	{
		if(i == code_len-1)
			tc_strcat( val[array_len], "1");
		else
			tc_strcat( val[array_len], "0");
	}
	printf("初始化流水号:%s\n",val[array_len]);

	
	get_serial_number(array_len+1,val,&newID);
	
	printf("newid:%s\n",newID);

	char* returnData;
	returnData = (char *)MEM_alloc((ITEM_id_size_c + 1)*sizeof(char));
	strcpy( returnData, newID );
	*((char**) returnValueType)=returnData;

	for (int i = 0; i < array_len+1; i++)
	{
		DOFREE(val[i])
	}
	DOFREE(val)

	return ITK_ok;
}


int get_serial_number( int val_len, char **val, char **project_id )
{
	int customError = ITK_ok,
		nval        = 0,
		tc_id_len   = 0,
		sep         = 0,
		temp_len    = 0,
		ix          = 0;

	char dig_sep[10] = "";

	tag_t class_id   = NULLTAG,
		  attr_id    = NULLTAG,
		  enq_id     = NULLTAG,
		  tc_id_tag  = NULLTAG,
		  *enq_instance_tags = NULL;
	
	ITKCALL( POM_class_id_of_class( "ImanIDCreator", &class_id ) );
	if ( class_id )
	{
		ITKCALL( POM_attr_id_of_attr( "start_value", "ImanIDCreator", &attr_id ) );
		
		ITKCALL( POM_create_enquiry_on_strings( class_id, attr_id, POM_is_equal_to, 0, val_len, val, &enq_id ) );
		
		ITKCALL( POM_execute_enquiry( enq_id, &nval, &enq_instance_tags ) );
		
		if ( nval )
		{
			ITKCALL( TCID_get_next_value( enq_instance_tags[0], project_id ));	
		}
		else
		{
			for ( ix = 0; ix  < val_len; ix ++)
			{
				if ( val[ix] )
				{
					tc_id_len+=STRLEN(val[ix]);
				}
			}
			
			printf("ID长度:%d\n",tc_id_len);
			ITKCALL( TCID_create( tc_id_len, &tc_id_tag ) );
			for ( ix = 0; ix  < val_len-1; ix ++)
			{
				
				if ( val[ix] )
				{
					temp_len = STRLEN(val[ix]);
					if (temp_len == 1)
					{
						sep+=temp_len;
						sprintf( dig_sep, "%d", sep);
						printf("dig_sep:%s=====val[%d]:%s\n",dig_sep,ix,val[ix]);
						ITKCALL(TCID_add_sequence( tc_id_tag, dig_sep, val[ix], STATIC ));
					}
					else
					{
						sprintf( dig_sep, "%d-%d", sep+1, sep+temp_len );
						printf("dig_sep:%s=====val[%d]:%s\n",dig_sep,ix,val[ix]);
						ITKCALL(TCID_add_sequence( tc_id_tag, dig_sep, val[ix], STATIC ));
						sep+=temp_len;
					}
				}
			}
			
			temp_len = STRLEN(val[val_len-1]);
			sprintf( dig_sep, "%d-%d", sep+1, sep+temp_len );
			printf("dig_sep:%s=====value:%s\n",dig_sep,val[val_len-1]);
			ITKCALL(TCID_add_sequence( tc_id_tag, dig_sep, val[val_len-1], RUNNING ));
			ITKCALL( TCID_save( tc_id_tag ) );
			ITKCALL( TCID_get_next_value( tc_id_tag, project_id ));
		}
		DOFREE( enq_instance_tags );
	}
	return customError;
}

2.客户端调用代码

String[] codeArray = new String[]{
					"特征码分段1",
					"特征码分段2",
					"特征码分段3",
					"特征码分段4",
					"特征码分段5",
					"特征码分段6"};
			
Object call = command.getTcSession().getUserService()
			.call("userservice_serial_number_by_code",new Object[] {codeArray,5});

5是流水码长度

你可能感兴趣的:(teamcenter)