Versões comparadas

Chave

  • Esta linha foi adicionada.
  • Esta linha foi removida.
  • A formatação mudou.

As dicas abaixo tem o objetivo de agilizar e auxiliar a geração de API baseada em DataServer no RM.

Vantagens:

1 - Garantia de que os nomes entre as classes e o schema serão iguais, evitar possíveis erros de digitação.

2 - Garantia de que as definições do esquema seguem corretamente as definições do RM já informadas na GDIC.

3 - Documenta as próprias informações de Api no dicionario de dados do RM.

4 - Possibilita a padronização de campos conforme a base de dados RM, exemplo evitar que em uma tabela o CODCOLIGADA seja CompanyId e em outra seja AffiliateId, ou CreatedUserCode para RecCreatedBy tenha outros nomes em outras Api por exemplo RecCreatedCod.


Etapas:

1 - Na tabela base para disponibilização da API verificar a existência do preenchimento da coluna APIName.

Exemplo:

SELECT APINAME,* FROM HATENDIMENTOBASE

Exemplo:

Image Added

2 - Montar um script com updates para preencher o campo API Name para as colunas que serão expostas. 

Dicas na criação de API RM.

1 - Criar campo APINAME na GDIC:

Bloco de código
        ALTER TABLE GDIC ADD APINAME VARCHAR(50)

     Este campo vai armazenar o nome do campo na API.

Exemplo:

Image Removed

2 - Select abaixo cria script de update para preencher na gdic o nome dos campos na API Rest.


Bloco de código
languagesql
titleGera Script GDIC
SELECT 'UPDATE GDIC SET APINAME = '''' WHERE TABELA = ''HATENDIMENTOBASE'' AND COLUNA = '''+GDIC.COLUNA+''' -- '+GDIC.DESCRICAO+'''' 
FROM GDIC (nolock) 
WHERE 
--Tabela API
TABELA = 'HATENDIMENTOBASE' 
--colunas que não estaram disponiveis na api.
AND COLUNA NOT IN ('CODATENDIMENTO','ID','CODATENDIMENTO')

...

UPDATE GDIC SET APINAME = StartDate WHERE TABELA = 'HATENDIMENTOBASE' AND COLUNA = 'ABERTURA' -- Data de abertura do atendimento.'
UPDATE GDIC SET APINAME = ScheduleDate WHERE TABELA = 'HATENDIMENTOBASE' AND COLUNA = 'AGENDADOPARA' -- Data de agendamento.'
UPDATE GDIC SET APINAME = PreviousScheduleDate WHERE TABELA = 'HATENDIMENTOBASE' AND COLUNA = 'AGENDADOPARAANTERIOR' -- Data de agendamento anterior.'


3 - Consulta para gerar os campos a serem definidos no Schema.

Com isto alem da definição correta do nome já é gerado o preenchimento de tags de documentação bem como o tipo dos campos conforme definição da propria GDIC RM.

Bloco de código
languagesql
titleSchema JSon
DECLARE @NOMETABELA VARCHAR(MAX) = 'HATENDIMENTOARQUIVOSANEXOS'

SELECT cast( ',"'+GDIC.APINAME+
       '": {"description": "'+GDIC.DESCRICAO+
       '","type": '+
	   case c.name 
	     when 'int' then '"integer", "format": "int32"' 
	     when 'varchar' then '"string", "maxLength": "'+convert(varchar(5),b.length) +'"'
	     when 'decimal' then  '"number", "format":"double"'
		 when 'datetime' then '"string","format": "date-time"'
		 when 'smallint' then '"integer", "format": "int32"'
	     else '"string"' 
	   end+
	   ', "x-totvs": [{ "product": "RM", "field": "' + @NOMETABELA +'.'+GDIC.COLUNA+
	   '", "required": false,"type": '+
	   
	    case c.name 
	     when 'int' then '"integer"' 
	     when 'varchar' then '"varchar", "maxLength": "'+convert(varchar(5),b.length) +'"'
	     when 'decimal' then  '"decimal"'
		 when 'datetime' then '"datetime"'
		 when 'smallint' then '"smallint"'
	     else '"string"' 
	   end+
	   ',"note" : "", "available": true, "canUpdate": true}]}'as VarChar(Max)) campos

 FROM GDIC, SYSOBJECTS A, SYSCOLUMNS B, SYSTYPES C
WHERE GDIC.TABELA = @NOMETABELA
  AND GDIC.APINAME IS NOT NULL 
  AND A.NAME = GDIC.TABELA
  AND B.ID = A.ID
  AND B.NAME = GDIC.COLUNA
  AND C.XUSERTYPE = B.XTYPE

ORDER BY GDIC.COLUNA

Exemplo Resultado:

Bloco de código
languagejs
,"FileCode": {"description": "Código do arquivo","type": "integer", "format": "int32", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.CODARQUIVO", "required": false,"type": "integer","note" : "", "available": true, "canUpdate": true}]}
,"AttendantCode": {"description": "Código do atendente","type": "integer", "format": "int32", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.CODATENDENTE", "required": false,"type": "integer","note" : "", "available": true, "canUpdate"
,"AttendantInCurrentCode": {"description": "Atendente que alterou","type": "integer", "format": "int32", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.CODATENDENTEATUAL", "required": false,"type": "integer","note" : "", "available": t
,"TicketCode": {"description": "Código do atendimento","type": "integer", "format": "int32", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.CODATENDIMENTO", "required": false,"type": "integer","note" : "", "available": true, "canUpdate
,"CompanyCode": {"description": "Código da coligada","type": "integer", "format": "int32", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.CODCOLIGADA", "required": false,"type": "smallint","note" : "", "available": true, "canUpdate": t
,"CompanyAttendantCurrentCode": {"description": "Coligada do atendente que alterou","type": "integer", "format": "int32", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.CODCOLIGADAATENDATUAL", "required": false,"type": "smallint","note
,"CompanyAttendantCode": {"description": "Coligada do atendente","type": "integer", "format": "int32", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.CODCOLIGADAATENDENTE", "required": false,"type": "smallint","note" : "", "available":
,"LocationCode": {"description": "Código do local","type": "integer", "format": "int32", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.CODLOCAL", "required": false,"type": "integer","note" : "", "available": true, "canUpdate": true}]}
,"LastTicketChangeDate": {"description": "Data alteração","type": "string","format": "date-time", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.DATAULTIMAALTERACAO", "required": false,"type": "datetime","note" : "", "available": true,
,"DetailsFile": {"description": "Detalhes do arquivo","type": "string", "maxLength": "255", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.DETALHESARQUIVO", "required": false,"type": "varchar", "maxLength": "255","note" : "", "availabl
,"Name": {"description": "Nome do arquivo","type": "string", "maxLength": "255", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.NOMEARQUIVO", "required": false,"type": "varchar", "maxLength": "255","note" : "", "available": true, "canU
,"CreatedUserCode": {"description": "Usuário criador do registro","type": "string", "maxLength": "50", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.RECCREATEDBY", "required": false,"type": "varchar", "maxLength": "50","note" : "", "a
,"ModifiedDate": {"description": "Data de criação do registro","type": "string","format": "date-time", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.RECCREATEDON", "required": false,"type": "datetime","note" : "", "available": true, "
,"ModifiedUserCode": {"description": "Autor da última modificação no registro","type": "string", "maxLength": "50", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.RECMODIFIEDBY", "required": false,"type": "varchar", "maxLength": "50","
,"ModifiedDate": {"description": "Data da última modificação no registro","type": "string","format": "date-time", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.RECMODIFIEDON", "required": false,"type": "datetime","note" : "", "availab
,"size": {"description": "Tamanho do arquivo","type": "string", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.TAMANHOARQUIVO", "required": false,"type": "string","note" : "", "available": true, "canUpdate": true}]}
,"Status": {"description": "Status","type": "string", "maxLength": "20", "x-totvs": [{ "product": "RM", "field": "HATENDIMENTOARQUIVOSANEXOS.TIPOALTERACAO", "required": false,"type": "varchar", "maxLength": "20","note" : "", "available": true, "canUpdate":

4 - Consulta que gera a classe referente ao Schema da API.

Bloco de código
languagesql
SELECT  char(10)+'///'+char(10)+ '/// '+ GDIC.DESCRICAO + ' - '+ GDIC.COLUNA + char(10)+ '///'
        +char(10)+'public '+
	    case c.name 
	     when 'int' then 'int' 
	     when 'varchar' then 'string'
	     when 'decimal' then  'decimal'
		 when 'datetime' then 'DateTime'
		 when 'smallint' then 'short'
	     else '"string"' 
	   end + ' ' + GDIC.APINAME -- concat(Upper(substring (GDIC.APINAME, 1,1)), lower(substring(GDIC.COLUNA, 2,len(GDIC.COLUNA))))
	   + ' { get; set; } ' as prop

 FROM GDIC, SYSOBJECTS A, SYSCOLUMNS B, SYSTYPES C
WHERE GDIC.TABELA = 'HATENDIMENTOBASE' 
  AND GDIC.APINAME IS NOT NULL 
  AND A.NAME = GDIC.TABELA
  AND B.ID = A.ID
  AND B.NAME = GDIC.COLUNA
  AND C.XUSERTYPE = B.XTYPE

ORDER BY GDIC.COLUNA

Exemplo de resultado gerado:

Bloco de código
languagejs
///
/// Autor da última modificação no registro - RECMODIFIEDBY
///
public string ModifiedUserCode { get; set; } 

///
/// Data da última modificação no registro - RECMODIFIEDON
///
public DateTime ModifiedDate { get; set; } 

///
/// Tamanho do arquivo - TAMANHOARQUIVO
///
public string size { get; set; } 

///
/// Status - TIPOALTERACAO
///
public string Status { get; set; } 

5 - Gerar código de atribuição dos captions do props necessário para API.

Executar o Informativus

Quem quiser instalar o Informativus, segue o caminho:

  • \\tecnologiabh.bh01.local\rmflex$\Outros\Ferramentas\Informativus
    • InformativusSetup.msi;


Informativus possui vários Plugins de customização.

Image Added

CAMINHO: \\tecnologiabh.bh01.local\rmflex$\Outros\Ferramentas\Informativus\Plugins

Image Added

Image Added


  • NA ABA LISTA DE TABELAS BOTÃO DIRETO NA TABELA CARREGAR DICIONÁRIO DE DADOS.

Image Added

Image AddedSELECT '// '+gdic.coluna, ' , ColProps.ApiName, "'+gdic.apiname+'"); //donotlocalize' FROM GDIC WHERE TABELA = 'HATENDIMENTOARQUIVOSANEXOS' AND APINAME IS NOT NULL