Files
2025-06-09 13:37:06 +02:00

143 lines
5.9 KiB
Java

/**
*
*/
package com.tarisan.util;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import com.tarisan.log.LogTarisan;
import com.tarisan.log.NivelLog;
import com.tarisan.persistencia.OracleParametros;
import com.tarisan.servlets.*;
import com.tarisan.control.ParametrosConfiguracion;
/**
* @author csm_jjripaper
*
*/
public class Generar_pdfs {
/**
* @param Llamaremos a esta clase una vez al día, por ejemplo a las 6:00 am para que genere los pdf de las peticiones que se realizaron ayer
*
*/
public static void main(String[] args) {
// Hay que definir la consulta para que nos devuelva los request id de las peticiones
// que se hicieron ayer
String peticion_izasa = new String();
String peticion_his = new String();
String strSql = new String();
try
{
/* Con esta consulta obtengo todos los request_id de izasa y los num_peti de novahis para las peticiones
* del pagador IMQ que tienen resultados finalizados en izasa, en los últimos seis meses
*
* select mg.request.requestid, MG.REQUEST.ISCOMPLETE, MG.REQUEST.REQUESTDATE, MG.REQUEST.REQUESTLABEL
from mg.request, NHGP_PETICION_CAB pet
where to_date(mg.request.requestdate, 'dd/mm/yyyy') > to_date(sysdate-180, 'dd/mm/yyyy')
and MG.REQUEST.ISCOMPLETE = 'Y'
and to_number(pet.NHGP_PETC_ID) = to_number(MG.REQUEST.REQUESTLABEL)
and pet.NHGP_PETC_TACT = 2
and pet.nhgp_petc_pag = 120
order by MG.REQUEST.REQUESTDATE
*/
//strSql = "select mg.request.requestid, MG.REQUEST.ISCOMPLETE, MG.REQUEST.REQUESTDATE, MG.REQUEST.REQUESTLABEL from mg.request, NHGP_PETICION_CAB pet where to_date(mg.request.requestdate, 'dd/mm/yyyy') > to_date(sysdate-180, 'dd/mm/yyyy') and MG.REQUEST.ISCOMPLETE = 'Y' and to_number(pet.NHGP_PETC_ID) = to_number(MG.REQUEST.REQUESTLABEL) and pet.NHGP_PETC_TACT = 2 and pet.nhgp_petc_pag = 120 and nhgp_petc_ambito = 2 order by MG.REQUEST.REQUESTDATE";
strSql = "select mg.request.requestid, MG.REQUEST.ISCOMPLETE, MG.REQUEST.REQUESTDATE, MG.REQUEST.REQUESTLABEL from mg.request, novahis.NHGP_PETICION_CAB pet where mg.request.requestdate > sysdate-180 and MG.REQUEST.ISCOMPLETE = 'Y' and to_number(pet.NHGP_PETC_ID) = to_number(MG.REQUEST.REQUESTLABEL) and pet.NHGP_PETC_TACT = 2 and pet.nhgp_petc_pag = 120 and nhgp_petc_ambito = 2 order by MG.REQUEST.REQUESTDATE";
//strSql = "select requestid, requestlabel from mg.request where requestlabel = 00109755";
ParametrosConfiguracion.cargarPropiedades();
//Connection conexion_izasa = Parametros
//Class.forName(OracleParametros.driverJdbc);
String url = "";
StringBuffer cadenaConexion = new StringBuffer();
cadenaConexion.append("jdbc:oracle:thin:");
cadenaConexion.append(ParametrosConfiguracion.dbhis_usuario);
cadenaConexion.append("/");
cadenaConexion.append(ParametrosConfiguracion.dbhis_password);
cadenaConexion.append("@");
cadenaConexion.append(ParametrosConfiguracion.dbhis_maquina);
cadenaConexion.append(":");
cadenaConexion.append(ParametrosConfiguracion.dbhis_puerto);
cadenaConexion.append(":");
cadenaConexion.append(ParametrosConfiguracion.dbhis_instancia);
LogTarisan.logger.log(NivelLog.INFO,cadenaConexion.toString());
url = cadenaConexion.toString();
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection conexion_izasa = DriverManager.getConnection(url);
//conexion_izasa = DriverManager.getConnection("jdbc:oracle:thin:novahis/novahis@192.168.2.205:1521:csmreal");
Statement st = conexion_izasa.prepareStatement(strSql);
System.out.println("Se ha abierto la conexión bbdd->"+st.toString());
ResultSet rs = st.executeQuery(strSql);
System.out.println("Se ha ejecutado la consulta" + strSql);
while(rs.next())
{
System.out.println("La consulta ha devuelto resultados.");
peticion_izasa = rs.getString("requestid");
peticion_his = rs.getString("requestlabel");
System.out.println("requestid izasa = " + rs.getString("requestid"));
System.out.println("peticion_izasa.length() = " + peticion_izasa.length());
if(peticion_izasa.length()>0)
{
//para cada request_id
//String ruta = LogTarisan.getPathFichero();
System.out.println("La ruta es: " + WorkingDirectory.get());
String sisop = System.getProperty("os.name");
String slash = "\\";
if(sisop.contains("indows"))
{
slash = "\\";
}
else{
slash = "/";
}
//String ruta = "C:" + slash + "temp"+ slash +"resultados";
String ruta = WorkingDirectory.get().getAbsolutePath();
System.out.println("Vamos a generar el pdf en :" + ruta);
File pdf = new File(ruta + slash + ".." + slash + "resultados" + slash + peticion_his +".pdf");
System.out.println("Creamos el fichero pdf");
if(!pdf.exists())
{
System.out.println("Como no existe vamos a parsear el xml al pdf");
resultados_analisis.conexionPOST("https://192.168.2.102/modulab/servlet/GetXMLRequestServlet?username=admin&password=service&requestID=" + peticion_izasa, "HTTPS", ruta);
System.out.println("Obtenido XML");
System.out.println("el xml es: " + peticion_izasa + ".xml");
File xml = new File(ruta + slash + ".." + slash + "resultados" + slash + peticion_izasa +".xml");
if(xml.exists())
{
System.out.println("El xml se ha guardado en: " + ruta + slash + peticion_izasa +".xml");
}
else
{
System.out.println("No ha podido guardar el xml en: " + ruta + slash + peticion_izasa +".xml");
}
XML2PDF.transformar(peticion_izasa + ".xml", "resultados_izasa.xsl", peticion_his + ".pdf", ruta);
System.out.println("Transformado a pdf");
}
}
}
System.out.println("Final de la conexión...");
rs.close();
conexion_izasa.close();
}
catch(Exception e)
{
System.out.println("Error al obtener el requestid de izasa: "+strSql);
e.printStackTrace();
}
}
}