SUPPORT-9337: fix last recording date
This commit is contained in:
parent
4ade43f2c2
commit
342239dd64
8 changed files with 65 additions and 41 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package ru.micord.ervu_dashboard.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import ru.micord.ervu_dashboard.service.DataDateService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
|
@ -17,7 +18,7 @@ public class DataDateController {
|
|||
}
|
||||
|
||||
@GetMapping("/data-date")
|
||||
public String getDataDate() {
|
||||
return dataDateService.getDataDate();
|
||||
public String getDataDate(@RequestHeader("Client-Time-Zone") String clientTimeZone) {
|
||||
return dataDateService.getDataDate(clientTimeZone);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,11 +58,6 @@ public class LastRecordingDate extends TableImpl<LastRecordingDateRecord> {
|
|||
*/
|
||||
public final TableField<LastRecordingDateRecord, String> ENTRY = createField(DSL.name("entry"), SQLDataType.CLOB, this, "");
|
||||
|
||||
/**
|
||||
* The column <code>public.last_recording_date.start_time</code>.
|
||||
*/
|
||||
public final TableField<LastRecordingDateRecord, Timestamp> START_TIME = createField(DSL.name("start_time"), SQLDataType.TIMESTAMP(0), this, "");
|
||||
|
||||
private LastRecordingDate(Name alias, Table<LastRecordingDateRecord> aliased) {
|
||||
this(alias, aliased, (Field<?>[]) null, null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,20 +47,6 @@ public class LastRecordingDateRecord extends TableRecordImpl<LastRecordingDateRe
|
|||
return (String) get(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>public.last_recording_date.start_time</code>.
|
||||
*/
|
||||
public void setStartTime(Timestamp value) {
|
||||
set(2, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>public.last_recording_date.start_time</code>.
|
||||
*/
|
||||
public Timestamp getStartTime() {
|
||||
return (Timestamp) get(2);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructors
|
||||
// -------------------------------------------------------------------------
|
||||
|
|
@ -75,12 +61,11 @@ public class LastRecordingDateRecord extends TableRecordImpl<LastRecordingDateRe
|
|||
/**
|
||||
* Create a detached, initialised LastRecordingDateRecord
|
||||
*/
|
||||
public LastRecordingDateRecord(Timestamp lastRecordingDate, String entry, Timestamp startTime) {
|
||||
public LastRecordingDateRecord(Timestamp lastRecordingDate, String entry) {
|
||||
super(LastRecordingDate.LAST_RECORDING_DATE);
|
||||
|
||||
setLastRecordingDate(lastRecordingDate);
|
||||
setEntry(entry);
|
||||
setStartTime(startTime);
|
||||
resetChangedOnNotNull();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,17 @@
|
|||
package ru.micord.ervu_dashboard.service;
|
||||
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
import ru.micord.ervu_dashboard.dao.DataDateDao;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.micord.ervu_dashboard.util.DateUtils;
|
||||
|
||||
/**
|
||||
* @author Alexandr Shalaginov
|
||||
*/
|
||||
@Service
|
||||
public class DataDateService {
|
||||
private static final String DATE_FORMAT = "d MMMM yyyy";
|
||||
|
||||
private final DataDateDao dataDateDao;
|
||||
|
||||
|
|
@ -20,19 +19,9 @@ public class DataDateService {
|
|||
this.dataDateDao = dataDateDao;
|
||||
}
|
||||
|
||||
public String getDataDate() {
|
||||
return convertDate(dataDateDao.getDataDate());
|
||||
}
|
||||
|
||||
private String convertDate(Timestamp date) {
|
||||
if (date == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Locale locale = new Locale("ru", "RU");
|
||||
String formattedDate = new SimpleDateFormat(DATE_FORMAT, locale)
|
||||
.format(new java.util.Date(date.getTime()));
|
||||
|
||||
return "Данные на " + formattedDate + " г.";
|
||||
public String getDataDate(String clientTimeZone) {
|
||||
Timestamp dataDate = dataDateDao.getDataDate();
|
||||
String formattedClientDate = DateUtils.getFormattedClientDate(dataDate, clientTimeZone);
|
||||
return "Данные на " + formattedClientDate + " г.";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
package ru.micord.ervu_dashboard.util;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class DateUtils {
|
||||
private static final DateTimeFormatter DATE_FORMATTER_RU = DateTimeFormatter.ofPattern(
|
||||
"d MMMM yyyy", new Locale("ru", "RU")
|
||||
);
|
||||
|
||||
private DateUtils() {}
|
||||
|
||||
public static String getFormattedClientDate(Timestamp timestamp, String clientTimeZone) {
|
||||
if (timestamp == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
ZoneId zoneId;
|
||||
try {
|
||||
zoneId = ZoneId.of(clientTimeZone);
|
||||
}
|
||||
catch (Exception e) {
|
||||
zoneId = ZoneId.systemDefault();
|
||||
}
|
||||
return timestamp.toInstant()
|
||||
.atZone(zoneId)
|
||||
.format(DATE_FORMATTER_RU);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<databaseChangeLog
|
||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9
|
||||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">
|
||||
|
||||
<changeSet id="0001" author="adel.ka">
|
||||
<comment>edit table</comment>
|
||||
<sql>
|
||||
ALTER TABLE public.last_recording_date
|
||||
ALTER COLUMN last_recording_date TYPE TIMESTAMP
|
||||
USING last_recording_date::timestamp;
|
||||
</sql>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
|
|
@ -26,5 +26,6 @@
|
|||
<include file="20250526-ERVU-444_additional_education_fields.xml" relativeToChangelogFile="true"/>
|
||||
<include file="20250617-ERVU-483.xml" relativeToChangelogFile="true"/>
|
||||
<include file="20250618-ERVU-481.xml" relativeToChangelogFile="true"/>
|
||||
<include file="20250821-SUPPORT-9337.xml" relativeToChangelogFile="true"/>
|
||||
|
||||
</databaseChangeLog>
|
||||
|
|
|
|||
|
|
@ -16,7 +16,13 @@ export class DataDateComponent {
|
|||
}
|
||||
|
||||
private getLastRecordDate(): void {
|
||||
this.httpClient.get("data-date").toPromise()
|
||||
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
this.httpClient.get("data-date",
|
||||
{
|
||||
headers: {
|
||||
"Client-Time-Zone": timeZone,
|
||||
}
|
||||
}).toPromise()
|
||||
.then((dataDate: string) => {
|
||||
this.dataDate = dataDate;
|
||||
this.cd.markForCheck();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue