refactor: store details structure

pull/5/head
Frédérik Benoist 2023-12-24 07:44:46 +01:00
parent 3cae6f2c69
commit 819523c5ac
7 changed files with 371 additions and 286 deletions

View File

@ -15,7 +15,7 @@ public class DatabaseConnectDOTSOFT implements AutoCloseable {
private Connection connection; private Connection connection;
public DatabaseConnectDOTSOFT(String username) { public DatabaseConnectDOTSOFT(String username) throws SQLException {
String environment = loadEnvironment(); String environment = loadEnvironment();
try { try {
@ -29,6 +29,7 @@ public class DatabaseConnectDOTSOFT implements AutoCloseable {
logger.info("DOTSOFT Connection OK for user " + username + " on environment " + environment); logger.info("DOTSOFT Connection OK for user " + username + " on environment " + environment);
} catch (SQLException e) { } catch (SQLException e) {
logger.error("Failed to connect to DOTSOFT database for user " + username + " on environment " + environment, e); logger.error("Failed to connect to DOTSOFT database for user " + username + " on environment " + environment, e);
throw e; // re-throw the exception
} }
} }

View File

@ -15,7 +15,7 @@ public class DatabaseConnectXSTORE implements AutoCloseable {
private Connection connection; private Connection connection;
public DatabaseConnectXSTORE(String dbHost, String username) { public DatabaseConnectXSTORE(String dbHost, String username) throws SQLException {
try { try {
Properties dbProperties = loadDatabaseProperties(); Properties dbProperties = loadDatabaseProperties();
@ -27,6 +27,7 @@ public class DatabaseConnectXSTORE implements AutoCloseable {
logger.info("XSTORE Connection OK for user " + username + " on host " + dbHost); logger.info("XSTORE Connection OK for user " + username + " on host " + dbHost);
} catch (SQLException e) { } catch (SQLException e) {
logger.error("Failed to connect to XSTORE database for user " + username + " on host " + dbHost, e); logger.error("Failed to connect to XSTORE database for user " + username + " on host " + dbHost, e);
throw e; // re-throw the exception
} }
} }

View File

@ -389,8 +389,7 @@ public class StoreService {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response getStoreDetails( public Response getStoreDetails(
@PathParam("storeId") Integer storeId, @PathParam("storeId") Integer storeId,
@QueryParam("dbHost") String dbHost, @QueryParam("dbHost") String dbHost) {
@QueryParam("workstationId") Integer workstationId) {
if (dbHost == null) { if (dbHost == null) {
return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"dbHost parameter is required\"}").build(); return Response.status(Response.Status.BAD_REQUEST).entity("{\"error\":\"dbHost parameter is required\"}").build();
@ -401,7 +400,7 @@ public class StoreService {
} }
try { try {
StoreDetails storeDetails = retrieveStoreDetails(dbHost,storeId,workstationId); StoreDetails storeDetails = retrieveStoreDetails(dbHost,storeId);
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
try { try {
@ -428,144 +427,65 @@ public class StoreService {
* @param workstationId the ID of the workstation * @param workstationId the ID of the workstation
* @return storeDetails * @return storeDetails
*/ */
private StoreDetails retrieveStoreDetails(String dbHost, Integer storeId, Integer workstationId) { private StoreDetails retrieveStoreDetails(String dbHost, Integer storeId) {
DriverManager.setLoginTimeout(5); DriverManager.setLoginTimeout(5);
StoreDetails storeDetails = new StoreDetails(); // Declare object outside try blocks StoreDetails storeDetails = new StoreDetails(); // Declare object outside try blocks
try (DatabaseConnectXSTORE databaseConnection = new DatabaseConnectXSTORE(dbHost,"dtv")) { try (DatabaseConnectXSTORE databaseConnection = new DatabaseConnectXSTORE(dbHost,"dtv")) {
// Replication section // get Pos list
String replicationQuery = "SELECT COUNT(*) AS pendingReplications, " + String PosQuery = "SELECT cdr.RTL_LOC_ID, " +
"MIN(crq.CREATE_DATE) AS minPendingReplicationDate, " + "cdr.WKSTN_ID, " +
"MAX(crq.CREATE_DATE) AS maxPendingReplicationDate " + "cdr.IP_ADDRESS, " +
"FROM repqueue.CTL_REPLICATION_QUEUE crq"; "cdr.BUSINESS_DATE, " +
"cdr.XSTORE_VERSION, " +
"cdr.PRIMARY_REGISTER_FLAG " +
"FROM dtv.ctl_device_registration cdr " +
"WHERE cdr.ORGANIZATION_ID = 1 " +
"ORDER BY cdr.PRIMARY_REGISTER_FLAG desc, cdr.WKSTN_ID";
logger.info(replicationQuery); logger.info(PosQuery);
try (PreparedStatement storeStatement = databaseConnection.getConnection().prepareStatement(replicationQuery); try (PreparedStatement posStatement = databaseConnection.getConnection().prepareStatement(PosQuery)) {
ResultSet storeReplicationResultSet = storeStatement.executeQuery()) { try (ResultSet posResultSet = posStatement.executeQuery()) {
Integer posRtlLocId = 0;
Integer posWkstnId = 0;
String posIp = "";
String posVersion = "";
Date posBusinessDate = null;
Integer primaryRegisterFlag = 0;
if (storeReplicationResultSet.next()) { while (posResultSet.next()) {
StoreReplication storeReplication = mapResultSetToStoreReplication(storeReplicationResultSet); posRtlLocId = posResultSet.getInt("RTL_LOC_ID");
storeDetails.setReplication(storeReplication); posWkstnId = posResultSet.getInt("WKSTN_ID");
} else { posIp = posResultSet.getString("IP_ADDRESS");
// Adjust to the desired behavior if no results are found posVersion = posResultSet.getString("XSTORE_VERSION");
} posBusinessDate = posResultSet.getDate("BUSINESS_DATE");
} primaryRegisterFlag = posResultSet.getInt("PRIMARY_REGISTER_FLAG");
// opening transation section StorePos pos = new StorePos();
String openingTransactionQuery = "SELECT"+
" COUNT(*) AS counter,"+
" MIN(tt.END_DATETIME) AS minDate,"+
" MAX(tt.END_DATETIME) AS maxDate"+
" FROM"+
" trn_trans tt"+
" WHERE"+
" tt.BUSINESS_DATE = ("+
" SELECT"+
" MAX(tt_bdate.BUSINESS_DATE) as bd"+
" FROM"+
" trn_trans tt_bdate"+
" WHERE"+
" tt_bdate.trans_TYPCODE = 'WORKSTATION_OPEN'"+
" AND tt_bdate.TRANS_STATCODE = 'COMPLETE'"+
" )"+
" AND tt.trans_TYPCODE = 'WORKSTATION_OPEN'"+
" AND tt.TRANS_STATCODE = 'COMPLETE'" ;
logger.info(openingTransactionQuery); // add new pos object
try (PreparedStatement storeStatement = databaseConnection.getConnection().prepareStatement(openingTransactionQuery); storeDetails.getPos().add(pos);
ResultSet openingTransactionResultSet = storeStatement.executeQuery()) { pos.setWorkstationId(posWkstnId);
pos.setIp(posIp);
pos.setVersion(posVersion);
pos.setBusinessDate(posBusinessDate);
pos.setPrimaryRegister(primaryRegisterFlag);
pos.setFatalError(1);
if (openingTransactionResultSet.next()) { // retrieve all pos details only on database of the master pos
XstoreTransaction openingTransaction = mapResultSetToXstoreOpeningTransaction(openingTransactionResultSet); retrieveStorePosDetails(databaseConnection, posRtlLocId, posWkstnId, posBusinessDate, pos);
storeDetails.setOpeningTransaction(openingTransaction);
} else {
// Adjust to the desired behavior if no results are found
}
}
// Closing transation section /* if (posResultSet.getString("IP_ADDRESS").equals(dbHost)) {
String closingTransactionQuery = "SELECT"+ retrieveStorePosDetails(databaseConnection, posRtlLocId, posWkstnId, posBusinessDate, pos);
" COUNT(*) AS counter,"+ } else {
" MIN(tt.END_DATETIME) AS minDate,"+ try (DatabaseConnectXSTORE newDatabaseConnection = new DatabaseConnectXSTORE(posIp,"dtv")) {
" MAX(tt.END_DATETIME) AS maxDate"+ retrieveStorePosDetails(newDatabaseConnection, posRtlLocId, posWkstnId, posBusinessDate, pos);
" FROM"+ } catch (SQLException e) {
" trn_trans tt"+ e.printStackTrace();
" WHERE"+ // Handle exceptions correctly in a production environment
" tt.BUSINESS_DATE = ("+ }
" SELECT"+ } */
" MAX(tt_bdate.BUSINESS_DATE)"+
" FROM"+
" trn_trans tt_bdate"+
" WHERE"+
" tt_bdate.trans_TYPCODE = 'WORKSTATION_OPEN'"+
" AND tt_bdate.TRANS_STATCODE = 'COMPLETE'"+
" )"+
" AND tt.trans_TYPCODE = 'WORKSTATION_CLOSE'"+
" AND tt.TRANS_STATCODE = 'COMPLETE'";
logger.info(closingTransactionQuery);
try (PreparedStatement storeStatement = databaseConnection.getConnection().prepareStatement(closingTransactionQuery);
ResultSet closingTransactionResultSet = storeStatement.executeQuery()) {
if (closingTransactionResultSet.next()) {
XstoreTransaction closingTransaction = mapResultSetToXstoreClosingTransaction(closingTransactionResultSet);
storeDetails.setClosingTransaction(closingTransaction);
} else {
// Adjust to the desired behavior if no results are found
}
}
// sale transation section
String saleTransactionQuery = "SELECT"+
" COUNT(*) AS counter,"+
" MIN(tt.END_DATETIME) AS minDate,"+
" MAX(tt.END_DATETIME) AS maxDate"+
" FROM"+
" trn_trans tt"+
" WHERE"+
" tt.BUSINESS_DATE = ("+
" SELECT"+
" MAX(tt_bdate.BUSINESS_DATE)"+
" FROM"+
" trn_trans tt_bdate"+
" WHERE"+
" tt_bdate.trans_TYPCODE = 'WORKSTATION_OPEN'"+
" AND tt_bdate.TRANS_STATCODE = 'COMPLETE'"+
" )"+
" AND tt.trans_TYPCODE = 'RETAIL_SALE'"+
" AND tt.TRANS_STATCODE = 'COMPLETE'";
logger.info(saleTransactionQuery);
try (PreparedStatement storeStatement = databaseConnection.getConnection().prepareStatement(saleTransactionQuery);
ResultSet saleTransactionResultSet = storeStatement.executeQuery()) {
if (saleTransactionResultSet.next()) {
XstoreTransaction saleTransaction = mapResultSetToXstoreSaleTransaction(saleTransactionResultSet);
storeDetails.setSaleTransaction(saleTransaction);
} else {
// Adjust to the desired behavior if no results are found
}
}
// version section
String versionQuery = "SELECT * FROM ( " +
" SELECT CUSTOMER,CUSTOMER_SCHEMA_VERSION,CUSTOMER_SCHEMA_DATE" +
" FROM dtv.CTL_VERSION_HISTORY" +
" WHERE organization_id = 1 AND customer IS NOT NULL" +
" ORDER BY seq DESC" +
" ) " +
" WHERE ROWNUM = 1";
logger.info(versionQuery);
try (PreparedStatement versionStatement = databaseConnection.getConnection().prepareStatement(versionQuery)) {
try (ResultSet versionResultSet = versionStatement.executeQuery()) {
if (versionResultSet.next()) {
storeDetails.setXstoreVersion(versionResultSet.getString("CUSTOMER_SCHEMA_VERSION"));
storeDetails.setXstoreVersionDate(versionResultSet.getDate("CUSTOMER_SCHEMA_DATE"));
storeDetails.setXstoreVersionCustomer(versionResultSet.getString("CUSTOMER"));
} else {
// Adjust to the desired behavior if no results are found
} }
} }
} }
@ -574,9 +494,9 @@ public class StoreService {
// Handle exceptions correctly in a production environment // Handle exceptions correctly in a production environment
} }
try (DatabaseConnectDOTSOFT databaseConnection = new DatabaseConnectDOTSOFT("com02")) { try (DatabaseConnectDOTSOFT databaseConnectionDS = new DatabaseConnectDOTSOFT("com02")) {
// Store section // Store section
String storeQuery = "SELECT st.id_structure," + String storeQuery = "SELECT st.id_structure," +
" TRIM(st.nom) as nom," + " TRIM(st.nom) as nom," +
" st.tel1 as telephone," + " st.tel1 as telephone," +
" st.enseigne," + " st.enseigne," +
@ -600,7 +520,7 @@ public class StoreService {
" WHERE st.id_structure = ?"; " WHERE st.id_structure = ?";
logger.info(storeQuery); logger.info(storeQuery);
try (PreparedStatement storeStatement = databaseConnection.getConnection().prepareStatement(storeQuery)) { try (PreparedStatement storeStatement = databaseConnectionDS.getConnection().prepareStatement(storeQuery)) {
storeStatement.setInt(1, storeId); // Set the value of the parameter storeStatement.setInt(1, storeId); // Set the value of the parameter
try (ResultSet storeResultSet = storeStatement.executeQuery()) { try (ResultSet storeResultSet = storeStatement.executeQuery()) {
@ -614,26 +534,33 @@ public class StoreService {
} }
// Transaction section // Transaction section
String transactionQuery = "SELECT COUNT(*) as backOfficeTransactions, " + String boTransactionQuery =
" MIN(cf.fdate_integration) AS minBackOfficeTransactionDate, " + "SELECT COUNT(*) AS backOfficeTransactions, " +
" MAX(cf.fdate_integration) AS maxBackOfficeTransactionDate, " + " MIN(cf.fdate_integration) AS minBackOfficeTransactionDate, " +
" TRUNC(MAX(cf.fdate)) AS backOfficeBusinessDate " + " MAX(cf.fdate_integration) AS maxBackOfficeTransactionDate " +
"FROM com02.client_facture cf " + "FROM com02.client_facture cf " +
"WHERE cf.id_structure = ? " + "WHERE cf.id_structure = ? " +
"AND TRUNC(cf.fdate_integration) = TRUNC(SYSDATE) " + //TODO : changer la date " AND cf.id_caisse = ? " +
"AND cf.version_info = 'XSTORE'"; " AND TRUNC(cf.fdate) = ? " +
" AND cf.version_info = 'XSTORE'";
logger.info(transactionQuery); for (StorePos pos : storeDetails.getPos()) {
try (PreparedStatement transactionStatement = databaseConnection.getConnection().prepareStatement(transactionQuery)) { logger.info(boTransactionQuery);
transactionStatement.setInt(1, storeId); // Set the value of the parameter try (PreparedStatement boTransactionStatement = databaseConnectionDS.getConnection().prepareStatement(boTransactionQuery)) {
boTransactionStatement.setInt(1, storeId);
boTransactionStatement.setInt(2, pos.getWorkstationId());
boTransactionStatement.setDate(3, pos.getBusinessDate());
try (ResultSet transactionResultSet = transactionStatement.executeQuery()) { try (ResultSet boTransactionResultSet = boTransactionStatement.executeQuery()) {
if (transactionResultSet.next()) { if (boTransactionResultSet.next()) {
BackOfficeTransaction storetransaction = mapResultSetToBackOfficetransaction(transactionResultSet); BackOfficeTransaction boTransaction = mapResultSetToBoTransaction(boTransactionResultSet);
storeDetails.setTransaction(storetransaction); pos.setBoTransaction(boTransaction);
} else { } else {
// Adjust to the desired behavior if no results are found // Adjust to the desired behavior if no results are found
}
} }
} catch (SQLException e) {
// Handle exception
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -645,6 +572,132 @@ public class StoreService {
return storeDetails; return storeDetails;
} }
private void retrieveStorePosDetails(DatabaseConnectXSTORE databaseConnection, Integer storeId, Integer workstationId, Date businessDate, StorePos pos) throws SQLException {
// Replication section
String replicationQuery = "SELECT COUNT(*) AS pendingReplications, " +
"MIN(crq.CREATE_DATE) AS minPendingReplicationDate, " +
"MAX(crq.CREATE_DATE) AS maxPendingReplicationDate " +
"FROM repqueue.CTL_REPLICATION_QUEUE crq " +
"WHERE crq.organization_id = 1 AND crq.RTL_LOC_ID = ? and crq.WKSTN_ID = ?";
logger.info(replicationQuery);
try (PreparedStatement replicationStatement = databaseConnection.getConnection().prepareStatement(replicationQuery)) {
replicationStatement.setInt(1, storeId);
replicationStatement.setInt(2, workstationId);
try (ResultSet replicationResultSet = replicationStatement.executeQuery()) {
if (replicationResultSet.next()) {
PosReplication posReplication = mapResultSetToPosReplication(replicationResultSet);
pos.setReplication(posReplication);
} else {
// Adjust to the desired behavior if no results are found
}
}
}
// opening transation section
String openingQuery =
"SELECT MIN(lsj.TIME_STAMP) AS minOpeningDate " +
"FROM loc_state_journal lsj " +
"WHERE lsj.TIME_STAMP BETWEEN TRUNC(SYSDATE) AND TRUNC(SYSDATE + 1) " +
"AND lsj.ORGANIZATION_ID = 1 " +
"AND lsj.RTL_LOC_ID = ? " +
"AND lsj.WKSTN_ID = ? " +
"AND lsj.STATUS_TYPCODE = 'WKSTN_STATE' " +
"AND lsj.STRING_VALUE = 'OPEN'";
logger.info(openingQuery);
try (PreparedStatement openingStatement = databaseConnection.getConnection().prepareStatement(openingQuery)) {
openingStatement.setInt(1, storeId);
openingStatement.setInt(2, workstationId);
try (ResultSet openingResultSet = openingStatement.executeQuery()) {
if (openingResultSet.next()) {
pos.setOpeningDate(openingResultSet.getTimestamp("minOpeningDate"));
} else {
// Adjust to the desired behavior if no results are found
}
}
}
// closing transation section
String closingQuery =
"SELECT MAX(lsj.TIME_STAMP) AS maxClosingDate " +
"FROM loc_state_journal lsj " +
"WHERE lsj.TIME_STAMP BETWEEN TRUNC(SYSDATE) AND TRUNC(SYSDATE + 1) " +
"AND lsj.ORGANIZATION_ID = 1 " +
"AND lsj.RTL_LOC_ID = ? " +
"AND lsj.WKSTN_ID = ? " +
"AND lsj.STATUS_TYPCODE = 'WKSTN_STATE' " +
"AND lsj.STRING_VALUE = 'CLOSED'";
logger.info(closingQuery);
try (PreparedStatement closingStatement = databaseConnection.getConnection().prepareStatement(closingQuery)) {
closingStatement.setInt(1, storeId);
closingStatement.setInt(2, workstationId);
try (ResultSet closingResultSet = closingStatement.executeQuery()) {
if (closingResultSet.next()) {
pos.setClosingDate(closingResultSet.getTimestamp("maxClosingDate"));
} else {
// Adjust to the desired behavior if no results are found
}
}
}
// sale transation section
String saleTransactionQuery =
"SELECT COUNT(*) AS counter, " +
"MIN(tt.END_DATETIME) AS minDate, " +
"MAX(tt.END_DATETIME) AS maxDate " +
"FROM dtv.trn_trans tt " +
"WHERE tt.ORGANIZATION_ID = 1 "+
"AND tt.RTL_LOC_ID = ? " +
"AND tt.BUSINESS_DATE = ? " +
"AND tt.WKSTN_ID = ? " +
"AND tt.trans_TYPCODE = 'RETAIL_SALE' " +
"AND tt.TRANS_STATCODE = 'COMPLETE'";
logger.info(saleTransactionQuery);
try (PreparedStatement saleTransactionStatement = databaseConnection.getConnection().prepareStatement(saleTransactionQuery)) {
saleTransactionStatement.setInt(1, storeId);
saleTransactionStatement.setDate(2, pos.getBusinessDate());
saleTransactionStatement.setInt(3, workstationId);
try (ResultSet saleTransactionResultSet = saleTransactionStatement.executeQuery()) {
if (saleTransactionResultSet.next()) {
XstoreTransaction saleTransaction = mapResultSetToSaleTransaction(saleTransactionResultSet);
pos.setSaleTransaction(saleTransaction);
} else {
// Adjust to the desired behavior if no results are found
}
}
}
// sale transation section
String logQuery = "SELECT COUNT(*) as counter " +
"FROM dtv.CTL_EVENT_LOG cel " +
"WHERE cel.CREATE_DATE BETWEEN TRUNC(SYSDATE) AND TRUNC(SYSDATE + 1) " +
"AND cel.ORGANIZATION_ID = 1 " +
"AND cel.RTL_LOC_ID = ? " +
"AND cel.WKSTN_ID = ? " +
"AND cel.LOG_LEVEL = 'FATAL'";
logger.info(logQuery);
try (PreparedStatement logStatement = databaseConnection.getConnection().prepareStatement(logQuery)) {
logStatement.setInt(1, storeId);
logStatement.setInt(2, workstationId);
try (ResultSet logResultSet = logStatement.executeQuery()) {
if (logResultSet.next()) {
pos.setFatalError(logResultSet.getInt("counter"));
} else {
// Adjust to the desired behavior if no results are found
}
}
}
}
private Store mapResultSetToStore(ResultSet resultSet) throws SQLException { private Store mapResultSetToStore(ResultSet resultSet) throws SQLException {
Integer id_structure = resultSet.getInt("id_structure"); Integer id_structure = resultSet.getInt("id_structure");
String nom = resultSet.getString("nom"); String nom = resultSet.getString("nom");
@ -659,15 +712,15 @@ public class StoreService {
return new Store(id_structure, nom, telephone, photoLink, enseigne, pays, caisses, adresse, date_migration); return new Store(id_structure, nom, telephone, photoLink, enseigne, pays, caisses, adresse, date_migration);
} }
private StoreReplication mapResultSetToStoreReplication(ResultSet resultSet) throws SQLException { private PosReplication mapResultSetToPosReplication(ResultSet resultSet) throws SQLException {
int pendingReplications = resultSet.getInt("pendingReplications"); int pendingReplications = resultSet.getInt("pendingReplications");
Date minPendingReplicationDate = resultSet.getDate("minPendingReplicationDate"); Date minPendingReplicationDate = resultSet.getDate("minPendingReplicationDate");
Date maxPendingReplicationDate = resultSet.getDate("maxPendingReplicationDate"); Date maxPendingReplicationDate = resultSet.getDate("maxPendingReplicationDate");
return new StoreReplication(pendingReplications, minPendingReplicationDate, maxPendingReplicationDate); return new PosReplication(pendingReplications, minPendingReplicationDate, maxPendingReplicationDate);
} }
private XstoreTransaction mapResultSetToXstoreOpeningTransaction(ResultSet resultSet) throws SQLException { private XstoreTransaction mapResultSetToSaleTransaction(ResultSet resultSet) throws SQLException {
int count = resultSet.getInt("counter"); int count = resultSet.getInt("counter");
Date minDate = resultSet.getDate("minDate"); Date minDate = resultSet.getDate("minDate");
Date maxDate = resultSet.getDate("maxDate"); Date maxDate = resultSet.getDate("maxDate");
@ -675,29 +728,12 @@ public class StoreService {
return new XstoreTransaction(count, minDate, maxDate); return new XstoreTransaction(count, minDate, maxDate);
} }
private XstoreTransaction mapResultSetToXstoreClosingTransaction(ResultSet resultSet) throws SQLException { private BackOfficeTransaction mapResultSetToBoTransaction(ResultSet resultSet) throws SQLException {
int count = resultSet.getInt("counter");
Date minDate = resultSet.getDate("minDate");
Date maxDate = resultSet.getDate("maxDate");
return new XstoreTransaction(count, minDate, maxDate);
}
private XstoreTransaction mapResultSetToXstoreSaleTransaction(ResultSet resultSet) throws SQLException {
int count = resultSet.getInt("counter");
Date minDate = resultSet.getDate("minDate");
Date maxDate = resultSet.getDate("maxDate");
return new XstoreTransaction(count, minDate, maxDate);
}
private BackOfficeTransaction mapResultSetToBackOfficetransaction(ResultSet resultSet) throws SQLException {
int backofficeTransactions = resultSet.getInt("backOfficeTransactions"); int backofficeTransactions = resultSet.getInt("backOfficeTransactions");
Date minBackofficeTransactionDate = resultSet.getDate("minBackOfficeTransactionDate"); Date minBackofficeTransactionDate = resultSet.getDate("minBackOfficeTransactionDate");
Date maxBackofficeTransactionDate = resultSet.getDate("maxBackOfficeTransactionDate"); Date maxBackofficeTransactionDate = resultSet.getDate("maxBackOfficeTransactionDate");
Date backOfficeBusinessDate = resultSet.getDate("backOfficeBusinessDate");
return new BackOfficeTransaction(backofficeTransactions, minBackofficeTransactionDate, maxBackofficeTransactionDate, backOfficeBusinessDate); return new BackOfficeTransaction(backofficeTransactions, minBackofficeTransactionDate, maxBackofficeTransactionDate);
} }
private StoreVersion mapResultSetToStoreVersion(ResultSet resultSet) throws SQLException { private StoreVersion mapResultSetToStoreVersion(ResultSet resultSet) throws SQLException {

View File

@ -7,7 +7,6 @@ public class BackOfficeTransaction {
private int backOfficeTransactions; private int backOfficeTransactions;
private Date minBackOfficeTransactionDate; private Date minBackOfficeTransactionDate;
private Date maxBackOfficeTransactionDate; private Date maxBackOfficeTransactionDate;
private Date backOfficeBusinessDate;
// Default constructor // Default constructor
@ -16,11 +15,10 @@ public class BackOfficeTransaction {
} }
// Constructor with parameters // Constructor with parameters
public BackOfficeTransaction(int backOfficeTransactions, Date minbackOfficeTransactionDate, Date maxbackOfficeTransactionDate, Date backOfficeBusinessDate) { public BackOfficeTransaction(int backOfficeTransactions, Date minbackOfficeTransactionDate, Date maxbackOfficeTransactionDate) {
this.backOfficeTransactions = backOfficeTransactions; this.backOfficeTransactions = backOfficeTransactions;
this.minBackOfficeTransactionDate = minbackOfficeTransactionDate; this.minBackOfficeTransactionDate = minbackOfficeTransactionDate;
this.maxBackOfficeTransactionDate = maxbackOfficeTransactionDate; this.maxBackOfficeTransactionDate = maxbackOfficeTransactionDate;
this.backOfficeBusinessDate = backOfficeBusinessDate;
} }
// Getters et setters // Getters et setters
@ -57,18 +55,4 @@ public class BackOfficeTransaction {
public void setMaxBackOfficeTransactionDate(Date maxBackOfficeTransactionDate) { public void setMaxBackOfficeTransactionDate(Date maxBackOfficeTransactionDate) {
this.maxBackOfficeTransactionDate = maxBackOfficeTransactionDate; this.maxBackOfficeTransactionDate = maxBackOfficeTransactionDate;
} }
public String getBackOfficeBusinessDate() {
if (backOfficeBusinessDate != null) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
return dateFormat.format(backOfficeBusinessDate);
} else {
return "";
}
}
public void setBackOfficeBusinessDate(Date backOfficeBusinessDate) {
this.backOfficeBusinessDate = backOfficeBusinessDate;
}
} }

View File

@ -3,18 +3,18 @@ package com.example.services.store;
import java.sql.Date; import java.sql.Date;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
public class StoreReplication { public class PosReplication {
private int pendingReplications; private int pendingReplications;
private Date minPendingReplicationDate; private Date minPendingReplicationDate;
private Date maxPendingReplicationDate; private Date maxPendingReplicationDate;
// Constructeur par défaut // Default constructor
public StoreReplication() { public PosReplication() {
// Default constructor required for JSON deserialization // Default constructor required for JSON deserialization
} }
// Constructeur avec paramètres // Constructor with parameters
public StoreReplication(int pendingReplications, Date minPendingReplicationDate, Date maxPendingReplicationDate) { public PosReplication(int pendingReplications, Date minPendingReplicationDate, Date maxPendingReplicationDate) {
this.pendingReplications = pendingReplications; this.pendingReplications = pendingReplications;
this.minPendingReplicationDate = minPendingReplicationDate; this.minPendingReplicationDate = minPendingReplicationDate;
this.maxPendingReplicationDate = maxPendingReplicationDate; this.maxPendingReplicationDate = maxPendingReplicationDate;

View File

@ -1,34 +1,20 @@
package com.example.services.store; package com.example.services.store;
import java.sql.Date; import java.util.ArrayList;
import java.text.SimpleDateFormat; import java.util.List;
public class StoreDetails { public class StoreDetails {
private Store store; private Store store;
private StoreReplication replication; private List<StorePos> pos;
private BackOfficeTransaction transaction;
private XstoreTransaction openingTransaction;
private XstoreTransaction closingTransaction;
private XstoreTransaction saleTransaction;
private String xstoreVersion;
private Date xstoreVersionDate;
private String xstoreVersionCustomer;
public StoreDetails() { public StoreDetails() {
// Constructeur par défaut nécessaire pour la désérialisation JSON // Constructeur par défaut nécessaire pour la désérialisation JSON
this.pos = new ArrayList<>();
} }
public StoreDetails(Store store, StoreReplication replication, BackOfficeTransaction transaction, XstoreTransaction openingTransaction, XstoreTransaction closingTransaction, XstoreTransaction saleTransaction, String xstoreVersion, Date xstoreVersionDate, String xstoreVersionCustomer) { public StoreDetails(Store store, List<StorePos> pos) {
this.store = store; this.store = store;
this.replication = replication; this.pos = pos != null ? pos : new ArrayList<>();
this.transaction = transaction;
this.openingTransaction = openingTransaction;
this.closingTransaction = closingTransaction;
this.saleTransaction = saleTransaction;
this.xstoreVersion = xstoreVersion;
this.xstoreVersionDate = xstoreVersionDate;
this.xstoreVersionCustomer = xstoreVersionCustomer;
} }
public Store getStore() { public Store getStore() {
@ -39,73 +25,12 @@ public class StoreDetails {
this.store = store; this.store = store;
} }
public StoreReplication getReplication() { public List<StorePos> getPos() {
return replication; return pos;
} }
public void setReplication(StoreReplication replication) { public void setPos(List<StorePos> pos) {
this.replication = replication; this.pos = pos;
}
public BackOfficeTransaction getTransaction() {
return transaction;
}
public void setTransaction(BackOfficeTransaction transaction) {
this.transaction = transaction;
}
public XstoreTransaction getOpeningTransaction() {
return openingTransaction;
}
public void setOpeningTransaction(XstoreTransaction openingTransaction) {
this.openingTransaction = openingTransaction;
}
public XstoreTransaction getClosingTransaction() {
return closingTransaction;
}
public void setClosingTransaction(XstoreTransaction closingTransaction) {
this.closingTransaction = closingTransaction;
}
public XstoreTransaction getSaleTransaction() {
return saleTransaction;
}
public void setSaleTransaction(XstoreTransaction saleTransaction) {
this.saleTransaction = saleTransaction;
}
public String getXstoreVersion() {
return xstoreVersion;
}
public void setXstoreVersion(String xstoreVersion) {
this.xstoreVersion = xstoreVersion;
}
public String getXstoreVersionDate() {
if (xstoreVersionDate != null) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
return dateFormat.format(xstoreVersionDate);
} else {
return "";
}
}
public void setXstoreVersionDate(Date xstoreVersionDate) {
this.xstoreVersionDate = xstoreVersionDate;
}
public String getXstoreVersionCustomer() {
return xstoreVersionCustomer;
}
public void setXstoreVersionCustomer(String xstoreVersionCustomer) {
this.xstoreVersionCustomer = xstoreVersionCustomer;
} }
} }

View File

@ -0,0 +1,138 @@
package com.example.services.store;
import java.sql.Date;
import java.text.SimpleDateFormat;
public class StorePos {
private int workstationId;
private String ip;
private String version;
private Date businessDate;
private String openingDate;
private String closingDate;
private BackOfficeTransaction boTransaction;
private PosReplication replication;
private XstoreTransaction saleTransaction;
private boolean primaryRegister = false;
private boolean fatalError = false;
// Default constructor
public StorePos() {
// Default constructor required for JSON deserialization
}
// Constructor with parameters
public StorePos( int workstationId, String ip, String version, Date businessDate, String openingDate, String closingDate ,BackOfficeTransaction boTransaction, PosReplication replication, XstoreTransaction saleTransaction, boolean primaryRegister, boolean fatalError) {
this.workstationId = workstationId;
this.ip = ip;
this.version = version;
this.businessDate = businessDate;
this.openingDate = openingDate;
this.closingDate = closingDate;
this.boTransaction = boTransaction;
this.replication = replication;
this.saleTransaction = saleTransaction;
this.primaryRegister = primaryRegister;
this.fatalError = fatalError;
}
// Getters et setters
public int getWorkstationId() {
return workstationId;
}
public void setWorkstationId(int workstationId) {
this.workstationId = workstationId;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getBusinessDateS() {
if (businessDate != null) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
return dateFormat.format(businessDate);
} else {
return "";
}
}
public Date getBusinessDate() {
return businessDate;
}
public void setBusinessDate(Date businessDate) {
this.businessDate = businessDate;
}
public String getOpeningDate() {
return openingDate;
}
public void setOpeningDate(java.sql.Timestamp openingDate) {
if (openingDate != null) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
String strOpeningDate = dateFormat.format(openingDate);
this.openingDate = strOpeningDate;
}
}
public String getClosingDate() {
return closingDate;
}
public void setClosingDate(java.sql.Timestamp closingDate) {
if (closingDate != null) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
String strClosingDate = dateFormat.format(closingDate);
this.closingDate = strClosingDate;
}
}
public BackOfficeTransaction getBoTransaction() {
return boTransaction;
}
public void setBoTransaction(BackOfficeTransaction boTransaction) {
this.boTransaction = boTransaction;
}
public PosReplication getReplication() {
return replication;
}
public void setReplication(PosReplication replication) {
this.replication = replication;
}
public XstoreTransaction getSaleTransaction() {
return saleTransaction;
}
public void setSaleTransaction(XstoreTransaction saleTransaction) {
this.saleTransaction = saleTransaction;
}
public boolean isPrimaryRegister() {
return primaryRegister;
}
public void setPrimaryRegister(int primaryRegister) {
this.primaryRegister = (primaryRegister == 1);
}
public boolean isFatalError() {
return fatalError;
}
public void setFatalError(int fatalError) {
this.fatalError = (fatalError > 0);
}
}