feat: add flux services

pull/5/head
Frédérik Benoist 2023-12-22 06:39:56 +01:00
parent a9837bf4f1
commit 405d1302ac
2 changed files with 322 additions and 0 deletions

View File

@ -0,0 +1,116 @@
package com.example.services;
import com.example.services.flux.bl.*;
import com.example.services.store.Store;
import com.example.services.store.StoreVersion;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Path("/flux")
public class FluxService {
private static final Logger logger = LoggerFactory.getLogger(DatabaseConnectDOTSOFT.class);
/**
* Retrieves the FluxBlNotSent object from the server.
*
* @return the FluxBlNotSent object obtained from the server
*/
@GET
@Path("/bl/notsent")
@Produces(MediaType.APPLICATION_JSON)
public Response getFluxBlNotSent() {
DriverManager.setLoginTimeout(5); // Définir le timeout à 5 secondes
try (DatabaseConnectDOTSOFT databaseConnection = new DatabaseConnectDOTSOFT("com02")) {
String query = "WITH err_bl AS (" +
"SELECT id_bon_livraison FROM omni.aspd_xsto_adrr_bl WHERE job_id = (" +
"SELECT MAX(job_id) FROM omni.aspd_xsto_adrr_bl))" +
"SELECT DISTINCT s.id_distrib, dis.libelle AS libelle_dis, s.id_structure, TRIM(s.nom) AS nom, s.enseigne, mq.code AS marque, m.code_saison, p.code_reference AS ref_r," +
"p.code_reference || '-' || pavc.code_externe AS ref_rc, p.code_reference || '-' || pavc.code_externe || '-' || TRIM(p.troc_axe2) AS ref_rct, p.nom AS nom_produit," +
"p.id_produit, bl.code_externe, bl.id_bon_livraison, bl.fdate AS date_bl, bl.id_structure AS id_expediteur, TRIM(st2.nom) AS expediteur, bl.remarques " +
"FROM COM02.bon_livraison bl " +
"JOIN err_bl ON err_bl.id_bon_livraison = bl.id_bon_livraison " +
"JOIN COM02.structure s ON s.id_structure = bl.id_destinataire " +
"LEFT OUTER JOIN COM02.STRUCTURE st2 ON st2.id_structure = bl.id_structure " +
"JOIN COM02.distributeur dis ON dis.id_distrib = s.id_distrib " +
"JOIN COM02.bon_livraison_colis blc ON blc.id_bordereau = bl.id_bon_livraison " +
"JOIN COM02.bon_livraison_colis_ligne blcl ON blcl.id_colis = blc.id_colis " +
"JOIN COM02.produit p ON p.id_produit = blcl.id_produit " +
"JOIN COM02.param_axe_valeur pavc ON pavc.id = p.id_type_axe_valeur1 " +
"JOIN COM02.modele m ON m.id_modele = p.code_modele " +
"JOIN COM02.marque mq ON mq.id_marque = m.id_marque " +
"LEFT OUTER JOIN OMNI.xst_produit xp ON (xp.id_distrib = s.id_distrib AND xp.id_produit = blcl.id_produit) " +
"WHERE bl.date_envoi_bl_numerique IS NULL AND blc.id_etat = 4 AND blcl.quantite != 0 AND xp.id_produit IS NULL " +
"ORDER BY s.id_distrib, dis.libelle, s.id_structure, TRIM(s.nom), m.code_saison";
logger.info(query);
try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) {
ResultSet resultSet = statement.executeQuery();
List<FluxBlNotSent> blNotSentList = new ArrayList<>();
while (resultSet.next()) {
FluxBlNotSent blnotsent = mapResultSetToBlNotSent(resultSet);
blNotSentList.add(blnotsent);
}
ObjectMapper objectMapper = new ObjectMapper();
String jsonResponse;
try {
jsonResponse = objectMapper.writeValueAsString(blNotSentList);
return Response.ok(jsonResponse).build();
} catch (JsonProcessingException e) {
e.printStackTrace();
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{\"error\":\"Error processing JSON\"}").build();
}
}
} catch (SQLException e) {
e.printStackTrace();
String errorResponse = "{\"error\":\"" + e.getMessage() + "\"}";
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorResponse).build();
}
}
private FluxBlNotSent mapResultSetToBlNotSent(ResultSet resultSet) throws SQLException {
FluxBlNotSent blNotSent = new FluxBlNotSent();
blNotSent.setIdDistrib(resultSet.getInt("id_distrib"));
blNotSent.setLibelleDis(resultSet.getString("libelle_dis"));
blNotSent.setIdStructure(resultSet.getInt("id_structure"));
blNotSent.setNomStructure(resultSet.getString("nom"));
blNotSent.setEnseigne(resultSet.getString("enseigne"));
blNotSent.setMarque(resultSet.getString("marque"));
blNotSent.setCodeSaison(resultSet.getString("code_saison"));
blNotSent.setRefR(resultSet.getString("ref_r"));
blNotSent.setRefRc(resultSet.getString("ref_rc"));
blNotSent.setRefRct(resultSet.getString("ref_rct"));
blNotSent.setNomProduit(resultSet.getString("nom_produit"));
blNotSent.setIdProduit(resultSet.getInt("id_produit"));
blNotSent.setCodeExterne(resultSet.getString("code_externe"));
blNotSent.setIdBonLivraison(resultSet.getInt("id_bon_livraison"));
blNotSent.setDateBl(resultSet.getDate("date_bl"));
blNotSent.setIdExpediteur(resultSet.getInt("id_expediteur"));
blNotSent.setExpediteur(resultSet.getString("expediteur"));
blNotSent.setRemarques(resultSet.getString("remarques"));
return blNotSent;
}
}

View File

@ -0,0 +1,206 @@
package com.example.services.flux.bl;
import java.sql.Date;
import java.text.SimpleDateFormat;
public class FluxBlNotSent {
private Integer id_distrib;
private String libelle_dis;
private Integer id_structure;
private String nom_structure;
private String enseigne;
private String marque;
private String code_saison;
private String ref_r;
private String ref_rc;
private String ref_rct;
private String nom_produit;
private Integer id_produit;
private String code_externe;
private Integer id_bon_livraison;
private Date date_bl;
private Integer id_expediteur;
private String expediteur;
private String remarques;
// Default constructor
public FluxBlNotSent() {
// Default constructor implementation
}
// Constructor with parameters
public FluxBlNotSent(Integer idDistrib, String libelleDis, Integer idStructure, String nomStructure,
String enseigne, String marque, String codeSaison, String refR,
String refRc, String refRct, String nomProduit, Integer idProduit,
String codeExterne, Integer idBonLivraison, Date dateBl,
Integer idExpediteur, String expediteur, String remarques) {
this.id_distrib = idDistrib;
this.libelle_dis = libelleDis;
this.id_structure = idStructure;
this.nom_structure = nomStructure;
this.enseigne = enseigne;
this.marque = marque;
this.code_saison = codeSaison;
this.ref_r = refR;
this.ref_rc = refRc;
this.ref_rct = refRct;
this.nom_produit = nomProduit;
this.id_produit = idProduit;
this.code_externe = codeExterne;
this.id_bon_livraison = idBonLivraison;
this.date_bl = dateBl;
this.id_expediteur = idExpediteur;
this.expediteur = expediteur;
this.remarques = remarques;
}
// getters and setters
public Integer getIdDistrib() {
return id_distrib;
}
public void setIdDistrib(Integer idDistrib) {
this.id_distrib = idDistrib;
}
public String getLibelleDis() {
return id_distrib + " - " + libelle_dis;
}
public void setLibelleDis(String libelleDis) {
this.libelle_dis = libelleDis;
}
public Integer getIdStructure() {
return id_structure;
}
public void setIdStructure(Integer idStructure) {
this.id_structure = idStructure;
}
public String getNomStructure() {
return id_structure + " - " + nom_structure;
}
public void setNomStructure(String nom) {
this.nom_structure = nom;
}
public String getEnseigne() {
return enseigne;
}
public void setEnseigne(String enseigne) {
this.enseigne = enseigne;
}
public String getMarque() {
return marque;
}
public void setMarque(String marque) {
this.marque = marque;
}
public String getCodeSaison() {
return code_saison;
}
public void setCodeSaison(String codeSaison) {
this.code_saison = codeSaison;
}
public String getRefR() {
return ref_r;
}
public void setRefR(String refR) {
this.ref_r = refR;
}
public String getRefRc() {
return ref_rc;
}
public void setRefRc(String refRc) {
this.ref_rc = refRc;
}
public String getRefRct() {
return ref_rct;
}
public void setRefRct(String refRct) {
this.ref_rct = refRct;
}
public String getNomProduit() {
return nom_produit;
}
public void setNomProduit(String nomProduit) {
this.nom_produit = nomProduit;
}
public Integer getIdProduit() {
return id_produit;
}
public void setIdProduit(Integer idProduit) {
this.id_produit = idProduit;
}
public String getCodeExterne() {
return code_externe;
}
public void setCodeExterne(String codeExterne) {
this.code_externe = codeExterne;
}
public Integer getIdBonLivraison() {
return id_bon_livraison;
}
public void setIdBonLivraison(Integer idBonLivraison) {
this.id_bon_livraison = idBonLivraison;
}
public String getDateBl() {
if (date_bl != null) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
return dateFormat.format(date_bl);
} else {
return "";
}
}
public void setDateBl(Date dateBl) {
this.date_bl = dateBl;
}
public Integer getIdExpediteur() {
return id_expediteur;
}
public void setIdExpediteur(Integer idExpediteur) {
this.id_expediteur = idExpediteur;
}
public String getExpediteur() {
return id_expediteur + " - " + expediteur;
}
public void setExpediteur(String expediteur) {
this.expediteur = expediteur;
}
public String getRemarques() {
return remarques;
}
public void setRemarques(String remarques) {
this.remarques = remarques;
}
}