Commit 0255ecf3 by GERMAN PATRICIO ROMERO QUISHPE

Merge branch 'GERM-MAYO-2023' into 'master'

Germ mayo 2023

See merge request !2
parents 89387b33 8daa85b9
......@@ -43,6 +43,7 @@
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
<dependency>
......@@ -77,7 +78,7 @@
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13.3</version>
<version>5.1.0</version>
</dependency>
......@@ -86,7 +87,31 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1200-jdbc41</version>
<version>42.5.4</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
......
package ec.edu.epn.consumosriautorizacion;
import ec.edu.epn.consumosriautorizacion.config.SchPublicConfig;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionException;
......@@ -10,12 +11,14 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
@SpringBootApplication
@EnableAsync
@Import(SchPublicConfig.class)
public class ConsumoSriAutorizacionApplication extends SpringBootServletInitializer {
@Override
......
......@@ -5,11 +5,14 @@ import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.List;
@Component
public class Task_Ftp implements Tasklet {
......@@ -27,7 +30,7 @@ public class Task_Ftp implements Tasklet {
List<String> fileNames = new ArrayList<>();
for (MultipartFile file : files) {
String fileName = file.getOriginalFilename();
ftpService.uploadFileToFTP(file.getInputStream(), pathFtp, fileName);
// ftpService.uploadFileToFTP(file.getInputStream(), pathFtp, fileName);
fileNames.add(fileName);
}
ftpService.disconnectFTP();
......
......@@ -28,7 +28,7 @@ public class Task_SendEmail implements Tasklet {
String subject = "Correo electrónico masivo de prueba";
String text = "Este es un correo electrónico masivo de prueba enviado desde Spring Boot.";
emailService.sendEmail(to, subject, text);
//emailService.sendEmail(to, subject, text);
System.out.println("Estado del trabajo: ");
......
package ec.edu.epn.consumosriautorizacion.config;
import ec.edu.epn.consumosriautorizacion.Tasks.Tarea3;
import ec.edu.epn.consumosriautorizacion.Tasks.Task_Ftp;
import ec.edu.epn.consumosriautorizacion.Tasks.Task_SendEmail;
import ec.edu.epn.consumosriautorizacion.Tasks.*;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
......@@ -29,27 +27,27 @@ public class BatchTareasConfig {
@Bean
public Step step1() {
return stepBuilderFactory.get("paso1").tasklet(new Task_Ftp()).build();
return stepBuilderFactory.get("paso1").tasklet(new Task_autorizacion()).build();
}
@Bean
public Step step2() {
return stepBuilderFactory.get("paso2").tasklet(new Task_SendEmail()).build();
return stepBuilderFactory.get("paso2").tasklet(new Task_cargaDocumentacion()).build();
}
@Bean
/* @Bean
public Step step3() {
return stepBuilderFactory.get("paso3").tasklet(new Tarea3()).build();
}
}*/
@Bean
Job autorizacionLotesJob() {
return jobBuilderFactory.get("autorizacionLotesJob")
.start(step3())
//.next(step2())
.start(step1())
.next(step2())
//.next(step3())
.build();
......
package ec.edu.epn.consumosriautorizacion.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import javax.sql.DataSource;
@Configuration
public class SchPublicConfig {
/*
@Value("${spring.datasource.url}")
private String url;
@Value("${spring.datasource.username}")
private String username;
@Value("${spring.datasource.password}")
private String password;
@Value("${spring.datasource.driver-class-name}")
private String drivers;
public JdbcTemplate jdbcTemplate;
@Primary
@Bean(name = "pubDataSource")
public DataSource adminDatasource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
/* dataSource.setUrl(env.getProperty("spring.datasource.url"));
dataSource.setUsername(env.getProperty("spring.datasource.username"));
dataSource.setPassword(env.getProperty("spring.datasource.password"));
dataSource.setDriverClassName(env.getProperty("spring.datasource.driver-class-name"));*/
/* dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
dataSource.setDriverClassName(drivers);
return dataSource;
}
@Autowired
public SchPublicConfig(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
/* @Bean
public JdbcTemplate jdbcTemplate() {
return new JdbcTemplate(adminDatasource());
}*/
}
......@@ -35,14 +35,20 @@ import ec.edu.epn.consumosriautorizacion.dto.DetallefacturaDTO;
import ec.edu.epn.consumosriautorizacion.dto.FacturaDTO;
import ec.edu.epn.consumosriautorizacion.dto.PagosDTO;
import ec.edu.epn.consumosriautorizacion.dto.ServicioDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
public class GeneracionFactOfflinePDF {
//@Value("${es.edu.epn.direccion}")
// String locate;
public String generarPDFFacturaOffline(FacturaDTO factura,
List<DetallefacturaDTO> detalle, Double total, Collection<PagosDTO> pagos
List<DetallefacturaDTO> detalle, List<PagosDTO> pagos
) {
String url = "";
......@@ -53,7 +59,7 @@ public class GeneracionFactOfflinePDF {
DateFormat fecha = new SimpleDateFormat("dd/MM/yyyy");
DateFormat fechaMs = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
hoyFecha = fecha.format(hoy);
String locate = "/FacturaUtils/";
String locate = "/datos/FacturaUtils/";
//String locate = "C:/facturacion_electronica/facturaUtils/";
System.out.println("-->" + locate);
......@@ -114,12 +120,12 @@ public class GeneracionFactOfflinePDF {
"R.U.C.: 1760005620001" + "\n\n"
+ "FACTURA" + "\n\n"
+ "No. " + factura.getIdFactura() + "\n\n"
+ "N�MERO DE AUTORIZACI�N" + "\n\n"
+ "NÚMERO DE AUTORIZACIÓN" + "\n\n"
+ factura.getNumautoriza() + "\n\n"
+ "FECHA Y HORA DE " + factura.getFechaautoriza() + "\n"
+ "AUTORIZACIN:" + "\n\n"
+ "AUTORIZACIÓN:" + "\n\n"
+ "AMBIENTE: " + factura.getAmbiente() + "\n\n"
+ "EMISIN: " + factura.getEmision() + "\n\n"
+ "EMISIÓN: " + factura.getEmision() + "\n\n"
+ " CLAVE DE ACCESO" + "\n\n"));
......@@ -144,8 +150,8 @@ public class GeneracionFactOfflinePDF {
datoscabecera.setWidthPercentage(100);
datoscabecera.addCell(createLabelCell3(
"Raz�n Social/ Nombres y Apellidos:\t\t\t\t\t\t\t\t\t " + factura.getNombreCli() + "\n"
+ "\t\t\t\tidentificaci�n:" + factura.getRucCli() + "\n\n"
+ "Fecha Emisi�n: " + hoyFecha));
+ "\t\t\t\tidentificación:" + factura.getRucCli() + "\n\n"
+ "Fecha Emisión: " + hoyFecha));
document.add(datoscabecera);
......@@ -192,11 +198,8 @@ public class GeneracionFactOfflinePDF {
+ "\n\n"));
}
} else {
ConsultasFacturacionController consultas= new ConsultasFacturacionController();
ServicioDTO servicio = consultas.consumoServicio(det.getIdServicio());
if(servicio==null){
if(det.getConcepto()!=null){
if(det.getServicioDTO()==null){
if(det.getIdConcepto()!=null){
datosfactura.addCell(createLabelCell4(det.getConceptoDTO().getIdConcepto()));
datosfactura.addCell(createLabelCell4(det.getConceptoDTO().getIdConcepto()));
datosfactura.addCell(createLabelCell4(det.getUnidadesDf().toString()));
......@@ -206,7 +209,7 @@ public class GeneracionFactOfflinePDF {
datosfactura.addCell(createLabelCell4(det.getIdServicio()));
datosfactura.addCell(createLabelCell4(det.getIdServicio()));
datosfactura.addCell(createLabelCell4(det.getUnidadesDf().toString()));
datosfactura.addCell(createLabelCell4(servicio.getNombreS()));
datosfactura.addCell(createLabelCell4(det.getServicioDTO().getNombreS()));
}
}
......@@ -242,9 +245,9 @@ public class GeneracionFactOfflinePDF {
com.itextpdf.text.Font fuente1 = FontFactory.getFont(
FontFactory.TIMES_ROMAN, 9);
String text = " Informacin Adicional " + "\n\n"
+ "Direccin: " + factura.getDireccionCli() + "\n\n"
+ "Tel�fono: " + factura.getTelefonoCli() + "\n\n"
String text = " Información Adicional " + "\n\n"
+ "Dirección: " + factura.getDireccionCli() + "\n\n"
+ "Teléfono: " + factura.getTelefonoCli() + "\n\n"
+ "Email: " + factura.getEmailCl() + "\n\n"
+ "Forma de Pago: " + pagosF;
celdaInfAdicional = new PdfPCell(new Phrase(text, fuente1));
......
......@@ -3,6 +3,7 @@ package ec.edu.epn.consumosriautorizacion.controller;
import ec.edu.epn.consumosriautorizacion.dto.FacturaDTO;
import org.springframework.beans.factory.annotation.Value;
import java.io.BufferedWriter;
import java.io.File;
......@@ -12,13 +13,17 @@ import java.io.IOException;
public class GeneracionFactOfflineXML {
public String generacionXml(FacturaDTO factura) throws IOException {
String pathXml= "";
// String pathXml= "";
BufferedWriter writer = null;
String pathXml="";
pathXml = "/FacturaUtils/" + factura.getRucCli().trim() + "-" + factura.getIdFactura().trim() + ".xml";
//pathXml = "C:/facturacion_electronica/facturaUtils/" + factura.getRucCli().trim() + "-" + factura.getIdFactura().trim() + ".xml";
pathXml = "/datos/FacturaUtils/" + factura.getRucCli().trim() + "-" + factura.getIdFactura().trim() + ".xml";
File file = new File(pathXml);
try {
......
......@@ -23,6 +23,7 @@ public class JobController {
@PostMapping("/inciarCron")
public String iniciar(@RequestBody RequestJob taskDefinition) {
taskDefinitionBean.setTaskDefinition(taskDefinition);
return taskSchedulingService.scheduleATask(taskDefinitionBean, taskDefinition.getCronExpression());
}
......
......@@ -18,13 +18,15 @@ public class DetallefacturaDTO {
private String mesArriendo;
private String nombreser;
private BigDecimal porcentajeiva;
private double subtotal = 0;
private double subtotal;
private Integer unidadesDf;
private double valorIva;
private String concepto;
private String idConcepto;
private ConceptoDTO conceptoDTO;
private ServicioDTO servicioDTO;
public String getIdDetallefactura() {
return idDetallefactura;
......@@ -138,12 +140,12 @@ public class DetallefacturaDTO {
this.valorIva = valorIva;
}
public String getConcepto() {
return concepto;
public String getIdConcepto() {
return idConcepto;
}
public void setConcepto(String concepto) {
this.concepto = concepto;
public void setIdConcepto(String idConcepto) {
this.idConcepto = idConcepto;
}
public ConceptoDTO getConceptoDTO() {
......@@ -153,4 +155,12 @@ public class DetallefacturaDTO {
public void setConceptoDTO(ConceptoDTO conceptoDTO) {
this.conceptoDTO = conceptoDTO;
}
public ServicioDTO getServicioDTO() {
return servicioDTO;
}
public void setServicioDTO(ServicioDTO servicioDTO) {
this.servicioDTO = servicioDTO;
}
}
package ec.edu.epn.consumosriautorizacion.dto;
public class UserFactDTO {
private String usuario;
private String clave;
public String getUsuario() {
return usuario;
}
public void setUsuario(String usuario) {
this.usuario = usuario;
}
public String getClave() {
return clave;
}
public void setClave(String clave) {
this.clave = clave;
}
}
package ec.edu.epn.consumosriautorizacion.service;
import ec.edu.epn.consumosriautorizacion.dto.DetallefacturaDTO;
import ec.edu.epn.consumosriautorizacion.dto.FacturaDTO;
import ec.edu.epn.consumosriautorizacion.dto.PagosDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.*;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.activation.DataSource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import javax.mail.util.ByteArrayDataSource;
import java.io.*;
import java.util.List;
import java.util.Properties;
......@@ -15,34 +26,87 @@ import java.util.Properties;
public class EmailService {
@Autowired
private JavaMailSender javaMailSender;
@Value("${spring.mail.host}")
private String host;
@Value("${spring.mail.port}")
private int port;
@Value("${spring.mail.username}")
private String username;
@Value("${spring.mail.password}")
private String password;
@Async
public void sendEmail(List<String> to, String subject, String text) {
public void sendEmail(List<String> to, String subject, String text, String attachment, String idFactura) {
try {
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
javaMailSender.setHost(host);
javaMailSender.setPort(port);
javaMailSender.setUsername(username);
javaMailSender.setPassword(password);
javaMailSender.setHost("smtp.office365.com");
javaMailSender.setPort(587);
javaMailSender.setUsername("facturacion.electronica@epn.edu.ec");
javaMailSender.setPassword("Epndgip2023*$");
Properties props = javaMailSender.getJavaMailProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.debug", "true");
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(to.toArray(new String[to.size()]));
message.setSubject(subject);
message.setText(text);
javaMailSender.send(message);
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, "utf-8");
mimeMessage.setContent(text.toString(), "text/html;charset=utf-8");
messageHelper.setTo(to.toArray(new String[to.size()]));
messageHelper.setFrom("facturacion.electronica@epn.edu.ec");
messageHelper.setSubject(subject);
//// AGREGAR FACTURA PARA ENVIO
if(!attachment.equals("")){
System.out.println("ARCHIVOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO" + attachment);
File initialFile = new File(attachment);
InputStream targetStream = new FileInputStream(initialFile);
DataSource content = new ByteArrayDataSource(targetStream, "application/octet-stream");
messageHelper.addAttachment("pruebas.pdf",
content);
javaMailSender.send(mimeMessage);
System.out.printf("SEND MAILIN PE..");
}
javaMailSender.send(mimeMessage);
}catch(Exception e){
e.getMessage();
}
}
public String remplazarCaracteresHTML(String valor) {
try {
String A = "&#193;";
String E = "&#201;";
String I = "&#205;";
String O = "&#211;";
String U = "&#218;";
String a = "&#225;";
String e = "&#233;";
String i = "&#237;";
String o = "&#243;";
String u = "&#250;";
String Ñ = "&#209;";
String ñ = "&#241;";
valor = valor.replace("á", a).replace("é", e).replace("í", i).replace("ó", o).replace("ú", u)
.replace("Á", A).replace("É", E);
valor = valor.replace("Í", I).replace("Ó", O).replace("Ú", U).replace("Ñ", Ñ).replace("ñ", ñ);
} catch (Exception e) {
e.printStackTrace();
}
return valor;
}
}
......@@ -4,6 +4,7 @@ package ec.edu.epn.consumosriautorizacion.service;
import ec.edu.epn.consumosriautorizacion.exceptions.FTPErrors;
import org.springframework.stereotype.Service;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
......@@ -11,7 +12,7 @@ import java.io.InputStream;
public interface FTPService {
void connectToFTP() throws FTPErrors, FTPErrors;
void uploadFileToFTP(InputStream input, String ftpHostDir, String serverFilename) throws FTPErrors;
void uploadFileToFTP(BufferedInputStream input, String ftpHostDir, String serverFilename) throws FTPErrors;
void downloadFileFromFTP(String ftpRelativePath, String copytoPath) throws FTPErrors;
......
......@@ -67,6 +67,7 @@ public class FileServiceImp implements FTPService {
}
try {
ftpconnection.login(ftpUserName, ftpuserPassword);
} catch (IOException e) {
ErrorMessage errorMessage = new ErrorMessage(-3, "El usuario=" + ftpUserName + ", y el pass=**** no fueron válidos para la autenticación.");
logger.error(errorMessage.toString());
......@@ -80,6 +81,8 @@ public class FileServiceImp implements FTPService {
throw new FTPErrors(errorMessage);
}
ftpconnection.enterLocalPassiveMode();
System.out.println("CONEXION EXITOSA");
}
public String stripAccents(String s)
......@@ -107,10 +110,17 @@ public class FileServiceImp implements FTPService {
// @Async("threadPoolTaskExecutor")
@Async
@Override
public void uploadFileToFTP(InputStream input, String ftpHostDir, String serverFilename) throws FTPErrors {
public void uploadFileToFTP(BufferedInputStream input, String ftpHostDir, String serverFilename) throws FTPErrors {
try {
serverFilename = new String(serverFilename.getBytes("utf-8"));
this.ftpconnection.storeFile(ftpHostDir + serverFilename, input);
int creacion= this.ftpconnection.mkd(ftpHostDir);
this.ftpconnection.changeWorkingDirectory("\\" + ftpHostDir);
this.ftpconnection.setFileType(FTP.BINARY_FILE_TYPE);
this.ftpconnection.storeFile(serverFilename, input);
this.ftpconnection.logout();
this.ftpconnection.disconnect();
} catch (Exception e) {
ErrorMessage errorMessage = new ErrorMessage(-5, "No se pudo subir el archivo al servidor.");
......
......@@ -7,10 +7,7 @@ import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.ScheduledFuture;
@Service
......@@ -25,7 +22,8 @@ public class TaskSchedulingService {
UUID uuid = UUID.randomUUID();
String jobId = uuid.toString();
System.out.println("Cron con job id: " + jobId + " y cron : " + cronExpression);
ScheduledFuture<?> scheduledTask = taskScheduler.schedule(tasklet, new CronTrigger(cronExpression, TimeZone.getTimeZone(TimeZone.getDefault().getID())));
//ScheduledFuture<?> scheduledTask = taskScheduler.schedule(tasklet, new CronTrigger(cronExpression, TimeZone.getTimeZone(TimeZone.getDefault().getID())));
ScheduledFuture<?> scheduledTask = taskScheduler.schedule(tasklet, new CronTrigger("0 0/5 8,9,10,11,12,13,14,15,16,17,18 * * ?"));
jobsMap.put(jobId, scheduledTask);
return "CRON-JOB:{id: " + jobId + ", cron : " + cronExpression + "}";
}
......
......@@ -12,8 +12,8 @@ spring.mail.properties.mail.smtp.from=smtp.office365.com
##### SMTP #####
spring.mail.host=smtp.office365.com
spring.mail.port=587
spring.mail.username=desarrollo.dgip@epn.edu.ec
spring.mail.password=Generico2022**
spring.mail.username=facturacion.electronica@epn.edu.ec
spring.mail.password=Epndgip2023*$
##### CONEXION FTP #####
#Multipart file config
......@@ -24,13 +24,31 @@ spring.servlet.multipart.file-size-threshold=2KB
spring.servlet.multipart.max-file-size=800MB
# Max Request Size
spring.servlet.multipart.max-request-size=800MB
ftp.server=localhost
ftp.server=172.31.5.24
ftp.port=21
ftp.userName=epnFtp
ftp.userPassword=epn-test
ftp.userName=facturaciona
ftp.userPassword=12345678
spring.messages.encoding=UTF-8
server.tomcat.uri-encoding=UTF-8
####CONEXION A BDDCORPEPN
spring.datasource.url=jdbc:postgresql://172.31.5.10:5432/bddcorpepn
spring.datasource.username=seguridad
spring.datasource.password=seguridad
##### SOPORTE DRIVERS POSTGRES #####
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL93Dialect
spring.batch.jdbc.initialize-schema=always
####### CARGA ARCHIVOS FACTURACION
#es.edu.epn.direccion=/FacturaUtils/
#### PARA LOS SCHEDULE #####
# ------- 0 * * * * * se traduce en:
# El método se ejecutará cuando los segundos sean igual a 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment