Herramientas de usuario

Herramientas del sitio


ada:howto:sicoferp:factory:goodsoftwaredevelopmentpractices:org

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
ada:howto:sicoferp:factory:goodsoftwaredevelopmentpractices:org [2023/11/06 17:55]
192.168.177.82
ada:howto:sicoferp:factory:goodsoftwaredevelopmentpractices:org [2023/11/06 19:01] (actual)
192.168.177.82
Línea 381: Línea 381:
 </​code>​ </​code>​
  
 +==== Directorio: Repository ====
 +Contiene clases de repositorio que se ocupan del acceso a datos. Estas clases suelen utilizar un marco ORM (Object-Relational Mapping) o JPA (Java Persistence API) para interactuar con la base de datos.
 +
 +<code java>
 +/**
 + * Copyright © 2023 ADA Corporation. All rights reserved.
 + *
 + * This component is protected by copyright.
 + *
 + * Use of this component is subject to the terms of the license agreement.
 + */
 +package co.ada.sicof.mobile.repository;​
 +
 +import co.ada.core.db.config.repository.JpaAdaRepository;​
 +import co.ada.sicof.mobile.entity.Empresa;​
 +
 +/**
 + * The Interface EmpresaRepository.
 + */
 +public interface EmpresaRepository extends JpaAdaRepository<​Empresa,​ Long> {
 +
 + /**
 + * Find by codigo empresa.
 + *
 + * @param codigoEmpresa the codigo empresa
 + * @return the empresa
 + */
 + public Empresa findByCodigoEmpresa(Long codigoEmpresa);​
 +
 + /**
 + * Find by codigo mempresa.
 + *
 + * @param codigoMempresa the codigo mempresa
 + * @return the empresa
 + */
 + public Empresa findByCodigoMempresa(String codigoMempresa);​
 +}
 +</​code>​
 +
 +==== Directorio: Service ====
 +Contiene clases de servicio que implementan la lógica empresarial. Los controladores utilizan estos servicios para realizar operaciones con datos.
 +
 +<code java>
 +/**
 + * Copyright © 2023 ADA Corporation. All rights reserved.
 + *
 + * This component is protected by copyright.
 + *
 + * Use of this component is subject to the terms of the license agreement.
 + */
 +package com.ada.viatico.proceso.service.v2;​
 +
 +import org.slf4j.Logger;​
 +import org.slf4j.LoggerFactory;​
 +import org.springframework.beans.factory.annotation.Autowired;​
 +import org.springframework.stereotype.Service;​
 +import org.springframework.transaction.annotation.Transactional;​
 +
 +import com.ada.viatico.proceso.component.LegalizacionComponentV2;​
 +import com.ada.viatico.proceso.component.SolicitudComponentV2;​
 +import com.ada.viatico.proceso.dto.DatosGenerarAprobacion;​
 +import com.ada.viatico.proceso.dto.GenericResponseDto;​
 +import com.ada.viatico.proceso.repository.ITmpCompromisoRepository;​
 +import com.ada.viatico.proceso.service.Impl.TicketsImp;​
 +import com.ada.viatico.proceso.service.Impl.ViaticoSolicitudImpl;​
 +import com.ada.viatico.proceso.sfcomercial.dto.AprobacionLegalizacionDto;​
 +import com.ada.viatico.proceso.utiliti.ViaticosException;​
 +
 +/**
 + * The Class ViaticosServiceV2.
 + * @version 2.0
 + */
 +@Service
 +public class ViaticosServiceV2 {
 +
 + /** The log. */
 + Logger log = LoggerFactory.getLogger(ViaticosServiceV2.class);​
 +
 + /** The Constant APROBRAR. */
 + private static final String APROBRAR = "​A";​
 +
 + /** The ticketsimpl. */
 + @Autowired
 + private TicketsImp ticketsimpl;​
 +
 + /** The solicitud repo. */
 + @Autowired
 + private ViaticoSolicitudImpl solicitudRepo;​
 +
 + /** The compromiso tmp. */
 + @Autowired
 + public ITmpCompromisoRepository compromisoTmp;​
 +
 + /** The legalizacion component V 2. */
 + @Autowired
 + private LegalizacionComponentV2 legalizacionComponentV2;​
 +
 + /** The solicitud component. */
 + @Autowired
 + private SolicitudComponentV2 solicitudComponentV2;​
 +
 + /**
 + * Aprobar solicitud.
 + *
 + * @param datos the datos
 + * @return the generic response dto
 + * @throws ViaticosException the viaticos exception
 + */
 + @Transactional(rollbackFor = ViaticosException.class)
 + public GenericResponseDto aprobarSolicitud(DatosGenerarAprobacion datos) throws ViaticosException {
 + if (datos.getEstadoSolicitudTipo().equals(APROBRAR)) {
 + return solicitudComponentV2.realizarAprobacion(datos);​
 + } else {
 + return solicitudComponentV2.cancelarAprobacion(datos);​
 + }
 + }
 +
 + /**
 + * Aprobar legalizacion.
 + *
 + * @param aprobacionLegalizacionDto the aprobacion legalizacion dto
 + * @param viaticoDetalleSolicitud the viatico detalle solicitud
 + * @param viaticoDetalleAprobacion the viatico detalle aprobacion
 + * @return the generic response dto
 + * @throws ViaticosException the viaticos exception
 + */
 + @Transactional(rollbackFor = ViaticosException.class)
 + public GenericResponseDto aprobarLegalizacion(AprobacionLegalizacionDto aprobacionLegalizacionDto) throws ViaticosException {
 + if(aprobacionLegalizacionDto.getEstadoTipo().equals("​A"​)) {
 + GenericResponseDto genericResponseDto = legalizacionComponentV2.generarProcesoInterfaz(aprobacionLegalizacionDto);​
 + if(genericResponseDto.getCode() == 1L) {
 + solicitudRepo.generarUpdateEstadoTipo("​A",​ aprobacionLegalizacionDto.getIdTicket());​
 + ticketsimpl.generarUpdateEstadoTicket("​A",​ aprobacionLegalizacionDto.getIdTicketLegalizado(),​ aprobacionLegalizacionDto.getDescripcion());​
 + compromisoTmp.actualizarOrdenador(0L,​ aprobacionLegalizacionDto.getIdTicket());​
 + }
 + return genericResponseDto;​
 + }else {
 + solicitudRepo.generarUpdateEstadoTipo("​V",​ aprobacionLegalizacionDto.getIdTicket());​
 + ticketsimpl.generarUpdateEstadoTicket("​V",​ aprobacionLegalizacionDto.getIdTicketLegalizado(),​ aprobacionLegalizacionDto.getDescripcion());​
 + compromisoTmp.actualizarOrdenador(aprobacionLegalizacionDto.getKaNlTerceroFuncionario(),​aprobacionLegalizacionDto.getIdTicket());​
 + }
 + return new GenericResponseDto(1L,​ "El documento sigue pendiente por proceso de aprobación."​);​
 + }
 +}
 +</​code>​
 +
 +==== Directorio: Utils(Utilidades) ====
 +Es un directorio general donde se registran clases de utilidad para mantener la base de código organizada y modular.
 +
 +<code java>
 +/**
 + * Copyright © 2023 ADA Corporation. All rights reserved.
 + *
 + * This component is protected by copyright.
 + *
 + * Use of this component is subject to the terms of the license agreement.
 + */
 +package com.ada.viatico.proceso.sfcomercial;​
 +
 +import java.text.ParseException;​
 +import java.text.SimpleDateFormat;​
 +import java.time.LocalDateTime;​
 +import java.time.format.DateTimeFormatter;​
 +import java.util.Date;​
 +
 +/**
 + * The Class Utility.
 + */
 +public class Utility {
 +
 + /** The instance. */
 + private static Utility instance;
 +
 + /** The Constant colombia. */
 + // Create a new Locale
 + //public static final Locale colombia =new Locale("​es",​ "​CO"​);​
 +
 + /** The Constant pesoFormat. */
 + // Create a formatter given the Locale
 +    //public static final NumberFormat pesoFormat = NumberFormat.getCurrencyInstance(colombia);​
 +
 + public static final Long PRESUPUESTO=1L;​
 + public static final Long TESORERIA=2L;​
 + public static final Long CONTABILIDAD=2L;​
 +
 +
 + public static final Long COMPROMISO=2L;​
 + public static final Long COMPROBANTE_EGRESO=1L;​
 + public static final Long COMPROBANTE_INGRESO=2L;​
 +
 + /**
 + * Instantiates a new utility.
 + */
 + private Utility() {
 + }
 +
 + /**
 + * Gets the single instance of Utility.
 + *
 + * @return single instance of Utility
 + */
 + public static Utility getInstance() {
 + if (instance == null)
 + instance = new Utility();
 + return instance;
 + }
 +
 + /**
 + * Convert from util date.
 + *
 + * @param utilDate the util date
 + * @return the java.sql. date
 + */
 + public static java.sql.Date convertFromUtilDate(java.util.Date utilDate) {
 + if (utilDate == null)
 + return null;
 + return new java.sql.Date(utilDate.getTime());​
 + }
 +
 + /**
 + * Convert from sql date.
 + *
 + * @param sqlDate the sql date
 + * @return the java.util. date
 + */
 + public static java.util.Date convertFromSqlDate(java.sql.Date sqlDate) {
 + if (sqlDate == null)
 + return null;
 + return new java.util.Date(sqlDate.getTime());​
 + }
 +
 + /**
 + * Gets the date without time using format.
 + *
 + * @return the date without time using format
 + * @throws ParseException the parse exception
 + */
 + public static Date getDateWithoutTimeUsingFormat() throws ParseException {
 + SimpleDateFormat formatter = new SimpleDateFormat("​dd/​MM/​yyyy"​);​
 + // Formatear la fecha actual sin hora y convertirla a Date
 + return formatter.parse(formatter.format(new Date()));
 + }
 +
 + /**
 + * Gets the numero.
 + *
 + * @return the numero
 + */
 + public static String getNumero() {
 + String formato = "​yyyyMMddHHmmss";​
 + DateTimeFormatter formateador = DateTimeFormatter.ofPattern(formato);​
 + LocalDateTime ahora = LocalDateTime.now();​
 + return formateador.format(ahora);​
 + }
 +}
 +</​code>​
 +
 +==== Otros Directorios ====
 +Además de las carpetas src/​main/​java,​ hay otras carpetas que deben tenerse en una aplicación Springboot. ​
 +
 +  * **src/​main/​resources**:​ esta carpeta contiene recursos que no son Java, como archivos estáticos, plantillas y archivos de configuración.
 +  * **src/​test**:​ esta carpeta contiene todas sus clases de prueba. Dentro de esta carpeta hay otra carpeta que es igual a la estructura de carpetas //​src/​main/​java//​. Como ejemplo, la carpeta //​src/​test/​java/​service//​ contiene clases de prueba para probar las clases de servicio de las clases //​src/​main/​java/​service//​.
 +
 +==== Nota ====
 +La estructura de carpetas puede variar de una empresa a otra. Pero esta es la estructura de carpetas básica de una aplicación Spring Boot que se recomienda se implemente en la mayoria de proyectos.
  
 [[ada:​howto:​sicoferp:​factory:​goodsoftwaredevelopmentpractices|←Volver atras]] [[ada:​howto:​sicoferp:​factory:​goodsoftwaredevelopmentpractices|←Volver atras]]
 +
 +Contenido adaptado desde el sitio web: https://​malshani-wijekoon.medium.com/​spring-boot-folder-structure-best-practices-18ef78a81819
  
ada/howto/sicoferp/factory/goodsoftwaredevelopmentpractices/org.1699293303.txt.gz · Última modificación: 2023/11/06 17:55 por 192.168.177.82