Fixed add case bug
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package com.cygnus.cloud.platform.api;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public record ScopedDataItem(
|
||||
Object value,
|
||||
String label,
|
||||
String group) {
|
||||
String group,
|
||||
Map<String, Object> data) {
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.cygnus.cloud.platform.api.ScopedDataItem;
|
||||
import io.vertx.sqlclient.Row;
|
||||
import io.vertx.sqlclient.Tuple;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -46,6 +47,16 @@ public class ScopedDataRepository {
|
||||
AND o.description = ANY($5::text[])
|
||||
ORDER BY o.description, ov.val_description
|
||||
""";
|
||||
private static final String REPORT_DEFINITION = """
|
||||
SELECT r.report_key, r.report_title, r.hide_leading_zero_columns,
|
||||
c.column_key, c.column_label, c.display_order, c.alignment,
|
||||
c.column_width, c.is_visible, c.is_totalled
|
||||
FROM platform.report_definition r
|
||||
JOIN platform.report_column_definition c ON c.report_key = r.report_key
|
||||
WHERE r.report_key = $1
|
||||
AND r.enabled = true
|
||||
ORDER BY c.display_order
|
||||
""";
|
||||
|
||||
private final ReactiveDatabaseClient database;
|
||||
|
||||
@@ -66,6 +77,22 @@ public class ScopedDataRepository {
|
||||
descriptions.toArray(String[]::new)));
|
||||
}
|
||||
|
||||
public Flux<ScopedDataItem> reportDefinition(String reportKey) {
|
||||
return database.preparedQuery(REPORT_DEFINITION, Tuple.of(reportKey))
|
||||
.flatMapMany(result -> Flux.fromIterable(result))
|
||||
.map(row -> new ScopedDataItem(null, null, null, Map.of(
|
||||
"reportKey", row.getString("report_key"),
|
||||
"reportTitle", row.getString("report_title"),
|
||||
"hideLeadingZeroColumns", row.getBoolean("hide_leading_zero_columns"),
|
||||
"columnKey", row.getString("column_key"),
|
||||
"columnLabel", row.getString("column_label"),
|
||||
"displayOrder", row.getInteger("display_order"),
|
||||
"alignment", row.getString("alignment"),
|
||||
"columnWidth", row.getInteger("column_width"),
|
||||
"visible", row.getBoolean("is_visible"),
|
||||
"totalled", row.getBoolean("is_totalled"))));
|
||||
}
|
||||
|
||||
private Flux<ScopedDataItem> rows(String sql, Tuple parameters) {
|
||||
return database.preparedQuery(sql, parameters)
|
||||
.flatMapMany(result -> Flux.fromIterable(result))
|
||||
@@ -74,6 +101,6 @@ public class ScopedDataRepository {
|
||||
|
||||
private ScopedDataItem item(Row row) {
|
||||
return new ScopedDataItem(
|
||||
row.getValue("value"), row.getString("label"), row.getString("group_name"));
|
||||
row.getValue("value"), row.getString("label"), row.getString("group_name"), Map.of());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import reactor.core.publisher.Flux;
|
||||
public class ScopedDataService {
|
||||
public static final String COMPANY_OPTIONS = "company-options";
|
||||
public static final String PORTFOLIO_OPTIONS = "portfolio-options";
|
||||
public static final String REPORT_DEFINITION = "report-definition";
|
||||
|
||||
private final ScopedDataRepository repository;
|
||||
|
||||
@@ -23,9 +24,13 @@ public class ScopedDataService {
|
||||
|
||||
public Flux<ScopedDataItem> fetch(UUID tenantId, ScopedDataRequest request) {
|
||||
Map<String, Object> data = request.data();
|
||||
String scope = request.scope().trim().toLowerCase(Locale.ROOT);
|
||||
if (REPORT_DEFINITION.equals(scope)) {
|
||||
return repository.reportDefinition(textValue(data, "reportKey"));
|
||||
}
|
||||
short companyId = shortValue(data, "companyId");
|
||||
List<String> descriptions = descriptions(data);
|
||||
return switch (request.scope().trim().toLowerCase(Locale.ROOT)) {
|
||||
return switch (scope) {
|
||||
case COMPANY_OPTIONS -> repository.companyOptions(tenantId, companyId, descriptions);
|
||||
case PORTFOLIO_OPTIONS -> repository.portfolioOptions(
|
||||
tenantId, companyId, shortValue(data, "branchId"),
|
||||
@@ -34,6 +39,14 @@ public class ScopedDataService {
|
||||
};
|
||||
}
|
||||
|
||||
private String textValue(Map<String, Object> data, String name) {
|
||||
String value = String.valueOf(data.getOrDefault(name, "")).trim();
|
||||
if (value.isEmpty() || value.length() > 100 || !value.matches("[a-z0-9-]+")) {
|
||||
throw new ScopedDataException(name + " is invalid");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private UUID uuidValue(Map<String, Object> data, String name) {
|
||||
try {
|
||||
return UUID.fromString(String.valueOf(data.get(name)));
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
CREATE TABLE IF NOT EXISTS platform.report_definition (
|
||||
report_key varchar(100) PRIMARY KEY,
|
||||
report_title varchar(200) NOT NULL,
|
||||
hide_leading_zero_columns boolean NOT NULL DEFAULT false,
|
||||
enabled boolean NOT NULL DEFAULT true,
|
||||
updated_at timestamptz NOT NULL DEFAULT current_timestamp
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS platform.report_column_definition (
|
||||
report_key varchar(100) NOT NULL REFERENCES platform.report_definition(report_key) ON DELETE CASCADE,
|
||||
column_key varchar(100) NOT NULL,
|
||||
column_label varchar(100) NOT NULL,
|
||||
display_order integer NOT NULL,
|
||||
alignment varchar(10) NOT NULL DEFAULT 'left',
|
||||
column_width integer NOT NULL DEFAULT 80,
|
||||
is_visible boolean NOT NULL DEFAULT true,
|
||||
is_totalled boolean NOT NULL DEFAULT false,
|
||||
PRIMARY KEY (report_key, column_key)
|
||||
);
|
||||
|
||||
INSERT INTO platform.report_definition(report_key, report_title, hide_leading_zero_columns)
|
||||
VALUES ('hourly-mis', 'HOURLY MIS (EDP)', true)
|
||||
ON CONFLICT (report_key) DO NOTHING;
|
||||
|
||||
INSERT INTO platform.report_column_definition
|
||||
(report_key,column_key,column_label,display_order,alignment,column_width,is_visible,is_totalled)
|
||||
VALUES ('hourly-mis','date','Date',0,'left',110,true,false),
|
||||
('hourly-mis','total','Total',25,'center',70,true,true)
|
||||
ON CONFLICT (report_key,column_key) DO NOTHING;
|
||||
|
||||
INSERT INTO platform.report_column_definition
|
||||
(report_key,column_key,column_label,display_order,alignment,column_width,is_visible,is_totalled)
|
||||
SELECT 'hourly-mis', 'hour'||hour, hour::text, hour+1, 'center', 55, true, true
|
||||
FROM generate_series(0,23) hour
|
||||
ON CONFLICT (report_key,column_key) DO NOTHING;
|
||||
|
||||
DELETE FROM platform.application_query
|
||||
WHERE query_key = 'report-definition';
|
||||
Reference in New Issue
Block a user