feat: obi visualization
parent
0065ac650c
commit
2b26a17035
|
|
@ -53,6 +53,8 @@ public class ItemService {
|
|||
try (DatabaseConnectXSTORE databaseConnection = new DatabaseConnectXSTORE(dbHost, "dtv")) {
|
||||
String query = "SELECT * FROM dtv.ITM_ITEM WHERE ORGANIZATION_ID = 1 AND ITEM_ID LIKE ?";
|
||||
|
||||
logger.info(query);
|
||||
|
||||
try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) {
|
||||
// Concatenate % to parameter itemId
|
||||
statement.setString(1, itemId + "%");
|
||||
|
|
@ -105,6 +107,8 @@ public class ItemService {
|
|||
"FROM dtv.ITM_ITEM_OPTIONS " +
|
||||
"WHERE ORGANIZATION_ID = 1 AND ITEM_ID LIKE ?";
|
||||
|
||||
logger.info(query);
|
||||
|
||||
try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) {
|
||||
// Concatenate % to parameter itemId
|
||||
statement.setString(1, itemId + "%");
|
||||
|
|
@ -157,6 +161,8 @@ public class ItemService {
|
|||
"FROM dtv.itm_item_prices " +
|
||||
"WHERE organization_id = 1 AND item_id LIKE ?";
|
||||
|
||||
logger.info(query);
|
||||
|
||||
try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) {
|
||||
// Concatenate % to parameter itemId
|
||||
statement.setString(1, itemId + "%");
|
||||
|
|
@ -209,6 +215,8 @@ public class ItemService {
|
|||
"FROM dtv.inv_stock_ledger_acct " +
|
||||
"WHERE organization_id = 1 AND item_id LIKE ?";
|
||||
|
||||
logger.info(query);
|
||||
|
||||
try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) {
|
||||
// Concatenate % to parameter itemId
|
||||
statement.setString(1, itemId + "%");
|
||||
|
|
|
|||
|
|
@ -4,12 +4,16 @@ import com.example.services.order.Order;
|
|||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -35,28 +39,58 @@ public class OrderService {
|
|||
@Path("/order")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getAllOrders(@QueryParam("q") String q,
|
||||
@QueryParam("page") int page,
|
||||
@QueryParam("itemsPerPage") int itemsPerPage,
|
||||
@QueryParam("sortBy") String sortBy,
|
||||
@QueryParam("orderBy") String orderBy) {
|
||||
@QueryParam("page") int page,
|
||||
@QueryParam("itemsPerPage") int itemsPerPage,
|
||||
@QueryParam("sortBy") String sortBy,
|
||||
@QueryParam("orderBy") String orderBy,
|
||||
@QueryParam("status") String status,
|
||||
@QueryParam("type") String type,
|
||||
@QueryParam("minDate") String minDate,
|
||||
@QueryParam("maxDate") String maxDate) {
|
||||
|
||||
DriverManager.setLoginTimeout(5); // Définir le timeout à 5 secondes
|
||||
|
||||
try (DatabaseConnectOBI databaseConnection = new DatabaseConnectOBI()) {
|
||||
String countQuery = "SELECT COUNT(*) FROM obi_order oo ";
|
||||
String countQuery = "SELECT COUNT(*), "
|
||||
+ "SUM (CASE WHEN oo.status = 'new_order' THEN 1 ELSE 0 END) AS stat_status1, "
|
||||
+ "SUM (CASE WHEN oo.status = 'polled' THEN 1 ELSE 0 END) AS stat_status2, "
|
||||
+ "SUM (CASE WHEN oo.status = 'fulfilled' THEN 1 ELSE 0 END) AS stat_status3, "
|
||||
+ "SUM (CASE WHEN oo.status = 'received' THEN 1 ELSE 0 END) AS stat_status4, "
|
||||
+ "SUM (CASE WHEN oo.status = 'unfulfillable' THEN 1 ELSE 0 END) AS stat_status5, "
|
||||
+ "SUM (CASE WHEN oo.status = 'canceled' THEN 1 ELSE 0 END) AS stat_status6 "
|
||||
+ "FROM obi_order oo "
|
||||
+ "JOIN obi_transaction_type ott on ott.transaction_type_id = oo.transaction_type_id";
|
||||
|
||||
String query =
|
||||
"SELECT oo.request_id, " +
|
||||
"oo.order_id, " +
|
||||
"oo.transaction_date, " +
|
||||
"oo.status as status, " +
|
||||
"ott.transaction_type_description " +
|
||||
"FROM obi_order oo " +
|
||||
"JOIN obi_transaction_type ott on ott.transaction_type_id = oo.transaction_type_id";
|
||||
"SELECT oo.request_id, "
|
||||
+ "oo.order_id, "
|
||||
+ "oo.transaction_date, "
|
||||
+ "oo.status as status, "
|
||||
+ "ott.transaction_type_description "
|
||||
+ "FROM obi_order oo "
|
||||
+ "JOIN obi_transaction_type ott on ott.transaction_type_id = oo.transaction_type_id";
|
||||
|
||||
List<String> conditions = new ArrayList<>();
|
||||
if (q != null && !q.isEmpty()) {
|
||||
conditions.add(" oo.order_id LIKE ? ");
|
||||
}
|
||||
|
||||
if (status != null && !status.isEmpty()) {
|
||||
conditions.add(" oo.status = ? ");
|
||||
}
|
||||
|
||||
if (type != null && !type.isEmpty()) {
|
||||
conditions.add(" ott.transaction_type_code = ? ");
|
||||
}
|
||||
|
||||
if (minDate != null && !minDate.isEmpty()) {
|
||||
conditions.add(" oo.transaction_date >= ? ");
|
||||
}
|
||||
|
||||
if (maxDate != null && !maxDate.isEmpty()) {
|
||||
conditions.add(" oo.transaction_date <= ? ");
|
||||
}
|
||||
|
||||
if (!conditions.isEmpty()) {
|
||||
countQuery += " WHERE " + String.join(" AND ", conditions);
|
||||
query += " WHERE " + String.join(" AND ", conditions);
|
||||
|
|
@ -83,9 +117,54 @@ public class OrderService {
|
|||
statement.setString(index++, "%" + q + "%");
|
||||
}
|
||||
|
||||
if(status != null && !status.isEmpty()) {
|
||||
countStatement.setString(index, status );
|
||||
statement.setString(index++, status );
|
||||
}
|
||||
|
||||
if (type != null && !type.isEmpty()) {
|
||||
countStatement.setString(index, type);
|
||||
statement.setString(index++, type);
|
||||
}
|
||||
|
||||
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
|
||||
if (minDate != null && !minDate.isEmpty()) {
|
||||
logger.info("minDate: " + minDate);
|
||||
try {
|
||||
java.util.Date parsedMinDate = dateFormat.parse(minDate);
|
||||
java.sql.Date sqlMinDate = new java.sql.Date(parsedMinDate.getTime());
|
||||
|
||||
countStatement.setDate(index, sqlMinDate);
|
||||
statement.setDate(index++, sqlMinDate);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (maxDate != null && !maxDate.isEmpty()) {
|
||||
logger.info("maxDate: " + maxDate);
|
||||
try {
|
||||
java.util.Date parsedMaxDate = dateFormat.parse(maxDate);
|
||||
java.sql.Date sqlMaxDate = new java.sql.Date(parsedMaxDate.getTime());
|
||||
|
||||
countStatement.setDate(index, sqlMaxDate);
|
||||
statement.setDate(index++, sqlMaxDate);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
ResultSet countResultSet = countStatement.executeQuery();
|
||||
countResultSet.next();
|
||||
int total = countResultSet.getInt(1);
|
||||
int statStatus1 = countResultSet.getInt(2);
|
||||
int statStatus2 = countResultSet.getInt(3);
|
||||
int statStatus3 = countResultSet.getInt(4);
|
||||
int statStatus4 = countResultSet.getInt(5);
|
||||
int statStatus5 = countResultSet.getInt(6);
|
||||
int statStatus6 = countResultSet.getInt(7);
|
||||
|
||||
ResultSet resultSet = statement.executeQuery(); {
|
||||
List<Order> orderList = new ArrayList<>();
|
||||
|
|
@ -98,6 +177,21 @@ public class OrderService {
|
|||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ObjectNode responseNode = objectMapper.createObjectNode();
|
||||
responseNode.put("total", total);
|
||||
|
||||
ArrayNode statisticsArray = objectMapper.createArrayNode();
|
||||
String[] titles = {"new_order", "polled", "fulfilled", "received","unfulfillable","canceled"};
|
||||
String[] icons = {"tabler-calendar-stats", "tabler-progress-check", "tabler-checks", "tabler-checks","tabler-wallet","tabler-circle-x"};
|
||||
int[] counts = {statStatus1, statStatus2, statStatus3, statStatus4, statStatus5, statStatus6};
|
||||
|
||||
for (int i = 0; i < titles.length; i++) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("title", titles[i]);
|
||||
node.put("value", counts[i]);
|
||||
node.put("icon", icons[i]);
|
||||
statisticsArray.add(node);
|
||||
}
|
||||
responseNode.set("statistics", statisticsArray);
|
||||
|
||||
responseNode.set("orders", objectMapper.valueToTree(orderList));
|
||||
|
||||
String jsonResponse;
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ public class StoreService {
|
|||
" WHERE st.id_structure = ?";
|
||||
|
||||
logger.info(query);
|
||||
|
||||
try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) {
|
||||
statement.setString(1, storeId);
|
||||
|
||||
|
|
@ -186,7 +187,8 @@ public class StoreService {
|
|||
" WHERE axs.date_stock is not null AND st.ID_NIVEAU=4 AND st.STATUT=2 AND st.id_canal_distribution = 1 and st.magasin_demo = 0" +
|
||||
" ORDER BY st.id_structure";
|
||||
|
||||
logger.info(query);
|
||||
logger.info(query);
|
||||
|
||||
try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query);
|
||||
ResultSet resultSet = statement.executeQuery()) {
|
||||
|
||||
|
|
@ -230,6 +232,7 @@ public class StoreService {
|
|||
"ORDER BY WKSTN_ID, SEQUENCE_ID";
|
||||
|
||||
logger.info(query);
|
||||
|
||||
try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) {
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
|
||||
|
|
@ -282,6 +285,7 @@ public class StoreService {
|
|||
"ORDER BY WKSTN_ID";
|
||||
|
||||
logger.info(query);
|
||||
|
||||
try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) {
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
|
||||
|
|
@ -335,7 +339,8 @@ public class StoreService {
|
|||
"WHERE organization_id = 1 AND customer IS NOT NULL " +
|
||||
"ORDER BY seq DESC";
|
||||
|
||||
logger.info(query);
|
||||
logger.info(query);
|
||||
|
||||
try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) {
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
|
||||
|
|
@ -449,6 +454,7 @@ public class StoreService {
|
|||
"ORDER BY cel.CREATE_DATE DESC";
|
||||
|
||||
logger.info(query);
|
||||
|
||||
try (PreparedStatement statement = databaseConnection.getConnection().prepareStatement(query)) {
|
||||
statement.setString(1, logDate + " 00:00:00");
|
||||
statement.setString(2, logDate + " 23:59:59");
|
||||
|
|
@ -659,6 +665,7 @@ public class StoreService {
|
|||
" WHERE st.id_structure = ?";
|
||||
|
||||
logger.info(storeQuery);
|
||||
|
||||
try (PreparedStatement storeStatement = databaseConnectionDS.getConnection().prepareStatement(storeQuery)) {
|
||||
storeStatement.setInt(1, storeId); // Set the value of the parameter
|
||||
|
||||
|
|
@ -685,6 +692,7 @@ public class StoreService {
|
|||
|
||||
for (StorePos pos : storeDetails.getPos()) {
|
||||
logger.info(boTransactionQuery);
|
||||
|
||||
try (PreparedStatement boTransactionStatement = databaseConnectionDS.getConnection().prepareStatement(boTransactionQuery)) {
|
||||
boTransactionStatement.setInt(1, storeId);
|
||||
boTransactionStatement.setInt(2, pos.getWorkstationId());
|
||||
|
|
@ -720,6 +728,7 @@ public class StoreService {
|
|||
"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);
|
||||
|
|
@ -746,7 +755,8 @@ public class StoreService {
|
|||
"AND lsj.STRING_VALUE = 'OPEN'";
|
||||
|
||||
logger.info(openingQuery);
|
||||
try (PreparedStatement openingStatement = databaseConnection.getConnection().prepareStatement(openingQuery)) {
|
||||
|
||||
try (PreparedStatement openingStatement = databaseConnection.getConnection().prepareStatement(openingQuery)) {
|
||||
openingStatement.setInt(1, storeId);
|
||||
openingStatement.setInt(2, workstationId);
|
||||
|
||||
|
|
@ -771,7 +781,8 @@ public class StoreService {
|
|||
"AND lsj.STRING_VALUE = 'CLOSED'";
|
||||
|
||||
logger.info(closingQuery);
|
||||
try (PreparedStatement closingStatement = databaseConnection.getConnection().prepareStatement(closingQuery)) {
|
||||
|
||||
try (PreparedStatement closingStatement = databaseConnection.getConnection().prepareStatement(closingQuery)) {
|
||||
closingStatement.setInt(1, storeId);
|
||||
closingStatement.setInt(2, workstationId);
|
||||
|
||||
|
|
@ -797,7 +808,8 @@ public class StoreService {
|
|||
"AND tt.trans_TYPCODE = 'RETAIL_SALE' " +
|
||||
"AND tt.TRANS_STATCODE = 'COMPLETE'";
|
||||
|
||||
logger.info(saleTransactionQuery);
|
||||
logger.info(saleTransactionQuery);
|
||||
|
||||
try (PreparedStatement saleTransactionStatement = databaseConnection.getConnection().prepareStatement(saleTransactionQuery)) {
|
||||
saleTransactionStatement.setInt(1, storeId);
|
||||
saleTransactionStatement.setDate(2, pos.getBusinessDate());
|
||||
|
|
@ -823,6 +835,7 @@ public class StoreService {
|
|||
"AND cel.LOG_LEVEL = 'FATAL'";
|
||||
|
||||
logger.info(logQuery);
|
||||
|
||||
try (PreparedStatement logStatement = databaseConnection.getConnection().prepareStatement(logQuery)) {
|
||||
logStatement.setInt(1, storeId);
|
||||
logStatement.setInt(2, workstationId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue