SUPPORT-8590: parse for client time zone
This commit is contained in:
parent
f7afc15c18
commit
76772df530
5 changed files with 51 additions and 32 deletions
|
|
@ -1,9 +1,8 @@
|
|||
package ervu.service.fileupload;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -30,7 +29,8 @@ import ru.micord.ervu.security.esia.service.UlDataService;
|
|||
import ru.micord.ervu.security.webbpm.jwt.model.Token;
|
||||
import ru.micord.ervu.security.webbpm.jwt.service.JwtTokenService;
|
||||
import ru.micord.ervu.service.InteractionService;
|
||||
import ru.micord.ervu.util.DateUtil;
|
||||
|
||||
import static ru.micord.ervu.util.StringUtils.convertToFio;
|
||||
|
||||
/**
|
||||
* @author Alexandr Shalaginov
|
||||
|
|
@ -73,7 +73,7 @@ public class EmployeeInfoFileUploadService {
|
|||
public boolean saveEmployeeInformationFile(MultipartFile multipartFile, String formType,
|
||||
String accessToken, String authToken, String offset) {
|
||||
String fileUploadUrl = this.url + "/" + getNewFilename(multipartFile.getOriginalFilename());
|
||||
String departureDateTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern(FORMAT));
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
if (this.fileWebDavUploadClient.webDavUploadFile(fileUploadUrl, username, password, multipartFile)) {
|
||||
FileStatus fileStatus = new FileStatus();
|
||||
|
|
@ -87,6 +87,7 @@ public class EmployeeInfoFileUploadService {
|
|||
PersonModel personModel = employeeModel.getPerson();
|
||||
Token token = jwtTokenService.getToken(authToken);
|
||||
String[] ids = token.getUserAccountId().split(":");
|
||||
String departureDateTime = now.format(DateTimeFormatter.ofPattern(FORMAT));
|
||||
String jsonMessage = getJsonKafkaMessage(
|
||||
employeeInfoKafkaMessageService.getKafkaMessage(
|
||||
fileId,
|
||||
|
|
@ -102,10 +103,10 @@ public class EmployeeInfoFileUploadService {
|
|||
personModel
|
||||
)
|
||||
);
|
||||
interactionService.setStatus(fileId, fileStatus.getStatus(), fileName, employeeInfoFileFormType.getFilePatternCode(),
|
||||
DateUtil.convertToTimestamp(Instant.now(), ZoneOffset.of(offset)),
|
||||
personModel.getLastName() + " " + personModel.getFirstName().charAt(0) + ". " + personModel.getMiddleName().charAt(0) + ".", (int) multipartFile.getSize(),
|
||||
ids[1]);
|
||||
interactionService.setStatus(fileId, fileStatus.getStatus(), fileName,
|
||||
employeeInfoFileFormType.getFilePatternCode(), Timestamp.valueOf(now),
|
||||
convertToFio(personModel.getFirstName(), personModel.getMiddleName(), personModel.getLastName()),
|
||||
(int) multipartFile.getSize(), ids[1]);
|
||||
return sendMessage(jsonMessage);
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
package ru.micord.ervu.journal.mapper;
|
||||
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import ervu_lkrp_ul.ervu_lkrp_ul.db_beans.public_.tables.records.InteractionLogRecord;
|
||||
import ru.micord.ervu.journal.JournalDto;
|
||||
import ru.micord.ervu.journal.JournalFileInfo;
|
||||
import ru.micord.ervu.journal.SenderInfo;
|
||||
|
||||
import static ru.micord.ervu.util.DateUtil.convertToTimestamp;
|
||||
import static ru.micord.ervu.util.StringUtils.convertToFio;
|
||||
|
||||
public class JournalDtoMapper {
|
||||
|
|
@ -16,9 +14,7 @@ public class JournalDtoMapper {
|
|||
public static JournalDto mapToJournalDto(JournalFileInfo journalFileInfo) {
|
||||
SenderInfo senderInfo = journalFileInfo.getSenderInfo();
|
||||
return new JournalDto()
|
||||
.setDepartureDateTime(convertToTimestamp(
|
||||
ZonedDateTime.of(journalFileInfo.getDepartureDateTime(), ZoneOffset.systemDefault()).toInstant(),
|
||||
ZoneOffset.of(journalFileInfo.getTimeZone())).toString())
|
||||
.setDepartureDateTime(Timestamp.valueOf(journalFileInfo.getDepartureDateTime()).toString())
|
||||
.setFileName(journalFileInfo.getFileName())
|
||||
.setFilePatternCode(journalFileInfo.getFilePatternCode())
|
||||
.setSenderFio(convertToFio(senderInfo.getFirstName(), senderInfo.getMiddleName(),
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
package ru.micord.ervu.util;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.springframework.util.StringUtils.hasText;
|
||||
|
|
@ -41,8 +37,4 @@ public final class DateUtil {
|
|||
public static String convertToString(LocalDate date, DateTimeFormatter formatter) {
|
||||
return date == null ? "" : date.format(formatter);
|
||||
}
|
||||
|
||||
public static Timestamp convertToTimestamp(@NotNull Instant instant, ZoneOffset zoneOffset) {
|
||||
return Timestamp.valueOf(LocalDateTime.ofInstant(instant, zoneOffset));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
import {DateTimeUtil, DefaultValueFormatter, GridValueFormatter} from "@webbpm/base-package";
|
||||
import {ValueFormatterParams} from "ag-grid-community";
|
||||
|
||||
export class ClientDateTimeFormatter extends DefaultValueFormatter implements GridValueFormatter {
|
||||
|
||||
public dateFormat: string = '';
|
||||
|
||||
format(params: ValueFormatterParams): string {
|
||||
if (this.isValueEmpty(params)) {
|
||||
return super.format(params);
|
||||
}
|
||||
|
||||
// don't apply formatter to row with aggregation function
|
||||
if (params.node.isRowPinned()) {
|
||||
return params.value;
|
||||
}
|
||||
|
||||
if (!this.dateFormat) {
|
||||
return ClientDateTimeFormatter.parseForClientTimeZoneAndFormat(params.value, DateTimeUtil.TIMESTAMP_FORMAT);
|
||||
}
|
||||
|
||||
if (!ClientDateTimeFormatter.isValidFormat(this.dateFormat)) {
|
||||
throw new Error('Invalid date format = ' + this.dateFormat);
|
||||
}
|
||||
|
||||
return ClientDateTimeFormatter.parseForClientTimeZoneAndFormat(params.value, this.dateFormat);
|
||||
}
|
||||
|
||||
private static isValidFormat(format: string): boolean {
|
||||
const validCharsRegex = /^[YyMmDdHhSsTZ.:\[\] -]*$/;
|
||||
return format && validCharsRegex.test(format);
|
||||
}
|
||||
|
||||
private static parseForClientTimeZoneAndFormat(value: string, dateFormat: string): string {
|
||||
let timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
return DateTimeUtil.parseIsoDateTime(value).tz(timezone).format(dateFormat);
|
||||
}
|
||||
}
|
||||
|
|
@ -682,17 +682,9 @@
|
|||
<entry>
|
||||
<key>valueFormatter</key>
|
||||
<value>
|
||||
<complex>
|
||||
<entry>
|
||||
<key>dateFormat</key>
|
||||
<value>
|
||||
<simple>"DD.MM.YYYY HH:mm:ss"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
</complex>
|
||||
<implRef type="TS">
|
||||
<className>DateTimeFormatter</className>
|
||||
<packageName>component.grid.formatters</packageName>
|
||||
<className>ClientDateTimeFormatter</className>
|
||||
<packageName>ervu.component.grid.formatter</packageName>
|
||||
</implRef>
|
||||
</value>
|
||||
</entry>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue