From dc67e681dd8426e6683ef002871b89a2e10d824b Mon Sep 17 00:00:00 2001 From: Alexandr Shalaginov Date: Wed, 18 Dec 2024 15:35:27 +0300 Subject: [PATCH] ERVU-226: add start/end dates in ConfigExecuteBtn.ts --- .../main/java/dto/ConfigExecuteRequest.java | 48 +++++++++++++++++++ .../java/rpc/ConfigExecutorRpcService.java | 7 ++- .../java/service/ConfigExecutorService.java | 22 ++++----- frontend/src/ts/ervu/ConfigExecuteBtn.ts | 25 ++++++++-- 4 files changed, 83 insertions(+), 19 deletions(-) create mode 100644 backend/src/main/java/dto/ConfigExecuteRequest.java diff --git a/backend/src/main/java/dto/ConfigExecuteRequest.java b/backend/src/main/java/dto/ConfigExecuteRequest.java new file mode 100644 index 0000000..4553afe --- /dev/null +++ b/backend/src/main/java/dto/ConfigExecuteRequest.java @@ -0,0 +1,48 @@ +package dto; + +import java.time.LocalDate; +import java.util.List; + +/** + * @author Alexandr Shalaginov + */ +public class ConfigExecuteRequest { + public List ids; + + public LocalDate startDate; + + public LocalDate endDate; + + public List getIds() { + return ids; + } + + public void setIds(List ids) { + this.ids = ids; + } + + public LocalDate getStartDate() { + return startDate; + } + + public void setStartDate(LocalDate startDate) { + this.startDate = startDate; + } + + public LocalDate getEndDate() { + return endDate; + } + + public void setEndDate(LocalDate endDate) { + this.endDate = endDate; + } + + @Override + public String toString() { + return "ConfigExecuteRequest{" + + "ids=" + ids + + ", startDate=" + startDate + + ", endDate=" + endDate + + '}'; + } +} diff --git a/backend/src/main/java/rpc/ConfigExecutorRpcService.java b/backend/src/main/java/rpc/ConfigExecutorRpcService.java index ad8ba1c..9c52623 100644 --- a/backend/src/main/java/rpc/ConfigExecutorRpcService.java +++ b/backend/src/main/java/rpc/ConfigExecutorRpcService.java @@ -1,7 +1,6 @@ package rpc; -import java.util.List; - +import dto.ConfigExecuteRequest; import org.springframework.beans.factory.annotation.Autowired; import service.ConfigExecutorService; @@ -22,7 +21,7 @@ public class ConfigExecutorRpcService extends Behavior { } @RpcCall - public String callConfigExecutor(String methodPath, List ids) { - return configExecutorService.call(methodPath, ids); + public String callConfigExecutor(String methodPath, ConfigExecuteRequest configExecuteRequest) { + return configExecutorService.call(methodPath, configExecuteRequest); } } diff --git a/backend/src/main/java/service/ConfigExecutorService.java b/backend/src/main/java/service/ConfigExecutorService.java index 4a92b8e..1d000e7 100644 --- a/backend/src/main/java/service/ConfigExecutorService.java +++ b/backend/src/main/java/service/ConfigExecutorService.java @@ -8,10 +8,10 @@ import java.util.Date; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.stream.Collectors; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import dto.ConfigExecuteRequest; import dto.ExportDataRequest; import model.FileModel; import org.slf4j.Logger; @@ -63,19 +63,19 @@ public class ConfigExecutorService { return fileModel; } - public String call(String methodPath, List ids) { + public String call(String methodPath, ConfigExecuteRequest configExecuteRequest) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity> entity = new HttpEntity<>(ids, headers); - LOGGER.info("Starts call config executor service with method: {}, for ids: {}", methodPath, - ids + HttpEntity entity = new HttpEntity<>(configExecuteRequest, headers); + LOGGER.info("Starts call config executor service with method: {}, for request: {}", methodPath, + configExecuteRequest ); try { ResponseEntity response = restTemplate.exchange(url.concat(methodPath), HttpMethod.POST, entity, String.class ); - LOGGER.info("Method: {}, executed with status: {}, for ids:{}", methodPath, - response.getStatusCode().value(), ids + LOGGER.info("Method: {}, executed with status: {}, for request:{}", methodPath, + response.getStatusCode().value(), configExecuteRequest ); return response.getBody(); } @@ -94,15 +94,15 @@ public class ConfigExecutorService { } else { throw new RuntimeException( - String.format("Failed call config executor service method: %s for ids: %s with error", - methodPath, ids + String.format("Failed call config executor service method: %s for request: %s with error", + methodPath, configExecuteRequest ), e); } } catch (Exception e) { throw new RuntimeException( - String.format("Failed call config executor service method: %s for ids: %s with error", - methodPath, ids + String.format("Failed call config executor service method: %s for request: %s with error", + methodPath, configExecuteRequest ), e); } } diff --git a/frontend/src/ts/ervu/ConfigExecuteBtn.ts b/frontend/src/ts/ervu/ConfigExecuteBtn.ts index 9c0f0b6..eeb6da0 100644 --- a/frontend/src/ts/ervu/ConfigExecuteBtn.ts +++ b/frontend/src/ts/ervu/ConfigExecuteBtn.ts @@ -1,6 +1,14 @@ import {ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef} from "@angular/core"; -import {AbstractButton, MessagesService, NotNull, ObjectRef, TextArea} from "@webbpm/base-package"; +import { + AbstractButton, + DateTimePicker, + MessagesService, + NotNull, + ObjectRef, + TextArea +} from "@webbpm/base-package"; import {ConfigExecutorRpcService} from "../generated/rpc/ConfigExecutorRpcService"; +import {ConfigExecuteRequest} from "../generated/dto/ConfigExecuteRequest"; /** * @author: a.petrov @@ -16,6 +24,10 @@ export class ConfigExecuteBtn extends AbstractButton { @ObjectRef() @NotNull() public ervuIdField: TextArea; + @ObjectRef() + public startDate: DateTimePicker; + @ObjectRef() + public endDate: DateTimePicker; @NotNull() public methodPath: string; private script: ConfigExecutorRpcService; @@ -32,13 +44,18 @@ export class ConfigExecuteBtn extends AbstractButton { } doClickActions(): Promise { - const value = this.ervuIdField.getValue(); + const value: string = this.ervuIdField.getValue(); if (value && this.methodPath.trim().length !== 0) { - const ids = value.replace(/[{}]/g, '') + const ids: string[] = value.replace(/[{}]/g, '') .split(',') .map(id => id.trim().replace(/"/g, '')); - return this.script.callConfigExecutor(this.methodPath, ids, true) + let configExecuteRequest: ConfigExecuteRequest = new ConfigExecuteRequest(); + configExecuteRequest.ids = ids; + configExecuteRequest.startDate = this.startDate ? this.startDate.getDateValue() : null; + configExecuteRequest.endDate = this.endDate ? this.endDate.getDateValue() : null; + + return this.script.callConfigExecutor(this.methodPath, configExecuteRequest, true) .then(successMsg => this.messagesService.success(successMsg)) .catch(error => Promise.reject(error)); }