diff --git a/RFXtoRP_HsrCarrierApt.ftl b/RFXtoRP_HsrCarrierApt.ftl index b8a39b8..ff2a9e1 100644 --- a/RFXtoRP_HsrCarrierApt.ftl +++ b/RFXtoRP_HsrCarrierApt.ftl @@ -2,7 +2,9 @@ <#-- input : message RFX --> <#-- project : projectId in ReflexPlatform --> <#-- organisation : organisationtId in ReflexPlatform --> -<#-- site : siteID in ReflexPlatform --> +<#include "ActorPrefix.ftl"> +<#include "HfRpConfig.ftl"> +<#include "ReflexUtils.ftl"> <#assign cloudEventMsg = JsonUtil.jsonToMap(input)> <#assign projectRP = project> diff --git a/RFXtoRP_HsrCarrierApt_AppointmentCarrierExpected.ftl b/RFXtoRP_HsrCarrierApt_AppointmentCarrierExpected.ftl index a3c6dae..c2ee7d6 100644 --- a/RFXtoRP_HsrCarrierApt_AppointmentCarrierExpected.ftl +++ b/RFXtoRP_HsrCarrierApt_AppointmentCarrierExpected.ftl @@ -1,5 +1,3 @@ -<#include "HfRpConfig.ftl"> -<#include "ReflexUtils.ftl"> [ <#assign ref_datetime = RfxDateTimetoUTCWithTimezone(carrier_apt.metadata.creation_datetime,time_zone_rfx) /> { diff --git a/RFXtoRP_HsrCarrierApt_ForceUpdateAppointment.ftl b/RFXtoRP_HsrCarrierApt_ForceUpdateAppointment.ftl index d951834..a6d9622 100644 --- a/RFXtoRP_HsrCarrierApt_ForceUpdateAppointment.ftl +++ b/RFXtoRP_HsrCarrierApt_ForceUpdateAppointment.ftl @@ -1,27 +1,16 @@ -<#include "HfRpConfig.ftl"> -<#include "ReflexUtils.ftl"> - - -<#-- à quoi correspond ID du transporteur dans l'API a voir avec Vincent--> - - [ { - <#assign appointment_reception_start_datetime = RfxDateTimetoUTCWithTimezone(carrier_apt.planned_unloading_start_datetime,time_zone_rfx) /> - <#assign appointment_expedition_start_datetime = RfxDateTimetoUTCWithTimezone(carrier_apt.planned_load_start_datetime,time_zone_rfx) /> - <#assign creation_datetime = RfxDateTimetoUTCWithTimezone(carrier_apt.metadata.creation_datetime,time_zone_rfx) /> - - "Header":{ + "Header":{ "ProjectID": "${projectRP}" }, "ActorID": "${carrier_apt.physical_depot}", <#if carrier_apt.unloading_appointment == "true" && carrier_apt.load_appointment == "false"> <#assign appointmentType = AppointmentType.APPOINTMENT_TYPE_RECEPTION> - <#assign duration = RfxDurationBetweenTwoDateTimetoInSeconds(carrier_apt.planned_unloading_start_datetime,carrier_apt.planned_unloading_end_datetime,time_zone_rfx) /> + <#assign duration = DurationBetweenTwoDatetimeInSeconds(carrier_apt.planned_unloading_start_datetime,carrier_apt.planned_unloading_end_datetime,time_zone_rfx) /> <#else> <#if carrier_apt.unloading_appointment == "false" && carrier_apt.load_appointment == "true" > <#assign appointmentType = AppointmentType.APPOINTMENT_TYPE_EXPEDITION> - <#assign duration = RfxDurationBetweenTwoDateTimetoInSeconds(carrier_apt.planned_load_start_datetime,carrier_apt.planned_load_end_datetime,time_zone_rfx) /> + <#assign duration = DurationBetweenTwoDatetimeInSeconds(carrier_apt.planned_load_start_datetime?datetime.iso,carrier_apt.planned_load_end_datetime?datetime.iso,time_zone_rfx) /> <#else> <#if carrier_apt.unloading_appointment == "true" && carrier_apt.load_appointment == "true"> <#assign appointmentType = AppointmentType.APPOINTMENT_TYPE_BOTH> @@ -62,7 +51,7 @@ <#if carrier_apt.unloading_appointment == "false" && carrier_apt.load_appointment == "true"> "StartDateTime": "${carrier_apt.planned_load_start_datetime}" <#else> - <#assign duration = RfxDurationBetweenTwoDateTimetoInSeconds(carrier_apt.planned_unloading_start_datetime,carrier_apt.planned_load_start_datetime,time_zone_rfx) /> + <#assign duration = DurationBetweenTwoDatetimeInSeconds(carrier_apt.planned_unloading_start_datetime,carrier_apt.planned_load_start_datetime,time_zone_rfx) /> <#if carrier_apt.unloading_appointment == "true" && carrier_apt.load_appointment == "true"> <#if duration >= 0> "StartDateTime": "${carrier_apt.planned_unloading_start_datetime}" diff --git a/RFXtoRP_HsrCarrierApt_SiteCancelAppointment.ftl b/RFXtoRP_HsrCarrierApt_SiteCancelAppointment.ftl index cb8256b..f29573d 100644 --- a/RFXtoRP_HsrCarrierApt_SiteCancelAppointment.ftl +++ b/RFXtoRP_HsrCarrierApt_SiteCancelAppointment.ftl @@ -1,8 +1,4 @@ -<#include "HfRpConfig.ftl"> -<#include "ReflexUtils.ftl"> - <#assign ref_datetime = RfxDateTimetoUTCWithTimezone(carrier_apt.metadata.last_update_datetime,time_zone_rfx) /> - [ { "AppointmentID": "${carrier_apt.appointment_reference?trim?json_string}", diff --git a/RFXtoRP_HsrCarrierApt_SiteForceBookAppointment.ftl b/RFXtoRP_HsrCarrierApt_SiteForceBookAppointment.ftl index 680573d..bcf2cd3 100644 --- a/RFXtoRP_HsrCarrierApt_SiteForceBookAppointment.ftl +++ b/RFXtoRP_HsrCarrierApt_SiteForceBookAppointment.ftl @@ -1,27 +1,18 @@ -<#include "HfRpConfig.ftl"> -<#include "ReflexUtils.ftl"> -<#include "ActorPrefix.ftl"> -<#-- à quoi correspond ID du transporteur dans l'API a voir avec Vincent--> - [ { - <#assign appointment_reception_start_datetime = RfxDateTimetoUTCWithTimezone(carrier_apt.planned_unloading_start_datetime,time_zone_rfx) /> - <#assign appointment_expedition_start_datetime = RfxDateTimetoUTCWithTimezone(carrier_apt.planned_load_start_datetime,time_zone_rfx) /> - <#assign creation_datetime = RfxDateTimetoUTCWithTimezone(carrier_apt.metadata.creation_datetime,time_zone_rfx) /> - "Header":{ "ProjectID": "${projectRP}" }, - "ActorID": "${RFXtoRPprefixDepot(carrier_apt.physical_depot?json_string)}", + "ActorID": "${RPtoRFXprefixDepot("DPF")}", "AppointmentID": "${carrier_apt.appointment_reference?json_string}", "TimeZone":"${time_zone_rfx}", <#if carrier_apt.unloading_appointment == "true" && carrier_apt.load_appointment == "false"> - <#assign appointmentType = AppointmentType.APPOINTMENT_TYPE_RECEPTION> - <#assign duration = RfxDurationBetweenTwoDateTimetoInSeconds(carrier_apt.planned_unloading_start_datetime,carrier_apt.planned_unloading_end_datetime,time_zone_rfx) /> + <#assign appointmentType = AppointmentType.APPOINTMENT_TYPE_RECEPTION> + <#assign duration = DurationBetweenTwoDatetimeInSeconds(carrier_apt.planned_unloading_start_datetime?datetime.iso,carrier_apt.planned_unloading_end_datetime?datetime.iso,time_zone_rfx) /> <#else> <#if carrier_apt.unloading_appointment == "false" && carrier_apt.load_appointment == "true" > <#assign appointmentType = AppointmentType.APPOINTMENT_TYPE_EXPEDITION> - <#assign duration = RfxDurationBetweenTwoDateTimetoInSeconds(carrier_apt.planned_load_start_datetime,carrier_apt.planned_load_end_datetime,time_zone_rfx) /> + <#assign duration = DurationBetweenTwoDatetimeInSeconds(carrier_apt.planned_load_start_datetime?datetime.iso,carrier_apt.planned_load_end_datetime?datetime.iso,time_zone_rfx) /> <#else> <#if carrier_apt.unloading_appointment == "true" && carrier_apt.load_appointment == "true"> <#assign appointmentType = AppointmentType.APPOINTMENT_TYPE_BOTH> @@ -67,8 +58,8 @@ <#if carrier_apt.unloading_appointment == "false" && carrier_apt.load_appointment == "true"> "StartDateTime": "${carrier_apt.planned_load_start_datetime}" <#else> - <#assign duration = RfxDurationBetweenTwoDateTimetoInSeconds(carrier_apt.planned_unloading_start_datetime,carrier_apt.planned_load_start_datetime,time_zone_rfx) /> - <#if carrier_apt.unloading_appointment == "true" && carrier_apt.load_appointment == "true"> + <#assign duration = DurationBetweenTwoDatetimeInSeconds(carrier_apt.planned_unloading_start_datetime?datetime.iso,carrier_apt.planned_load_start_datetime?datetime.iso,time_zone_rfx) /> + <#if carrier_apt.unloading_appointment == "true" && carrier_apt.load_appointment == "true"> <#if duration >= 0> "StartDateTime": "${carrier_apt.planned_unloading_start_datetime}" <#else> diff --git a/RFXtoRP_HsrCarrierApt_SiteForceUpdateAppointment.ftl b/RFXtoRP_HsrCarrierApt_SiteForceUpdateAppointment.ftl index 571bfc4..f10c7e5 100644 --- a/RFXtoRP_HsrCarrierApt_SiteForceUpdateAppointment.ftl +++ b/RFXtoRP_HsrCarrierApt_SiteForceUpdateAppointment.ftl @@ -1,8 +1,3 @@ -<#include "HfRpConfig.ftl"> -<#include "ReflexUtils.ftl"> - - - [ { <#assign appointment_reception_start_datetime = RfxDateTimetoUTCWithTimezone(carrier_apt.planned_unloading_start_datetime,time_zone_rfx) /> @@ -15,11 +10,11 @@ "ActorID": "${carrier_apt.physical_depot}", <#if carrier_apt.unloading_appointment == "true" && carrier_apt.load_appointment == "false"> <#assign appointmentType = AppointmentType.APPOINTMENT_TYPE_RECEPTION> - <#assign duration = RfxDurationBetweenTwoDateTimetoInSeconds(carrier_apt.planned_unloading_start_datetime,carrier_apt.planned_unloading_end_datetime,time_zone_rfx) /> + <#assign duration = DurationBetweenTwoDatetimeInSeconds(carrier_apt.planned_unloading_start_datetime?datetime.iso,carrier_apt.planned_unloading_end_datetime?datetime.iso,time_zone_rfx) /> <#else> <#if carrier_apt.unloading_appointment == "false" && carrier_apt.load_appointment == "true" > <#assign appointmentType = AppointmentType.APPOINTMENT_TYPE_EXPEDITION> - <#assign duration = RfxDurationBetweenTwoDateTimetoInSeconds(carrier_apt.planned_load_start_datetime,carrier_apt.planned_load_end_datetime,time_zone_rfx) /> + <#assign duration = DurationBetweenTwoDatetimeInSeconds(carrier_apt.planned_load_start_datetime?datetime.iso,carrier_apt.planned_load_end_datetime?datetime.iso,time_zone_rfx) /> <#else> <#if carrier_apt.unloading_appointment == "true" && carrier_apt.load_appointment == "true"> <#assign appointmentType = AppointmentType.APPOINTMENT_TYPE_BOTH> @@ -60,7 +55,7 @@ <#if carrier_apt.unloading_appointment == "false" && carrier_apt.load_appointment == "true"> "StartDateTime": "${carrier_apt.planned_load_start_datetime}" <#else> - <#assign duration = RfxDurationBetweenTwoDateTimetoInSeconds(carrier_apt.planned_unloading_start_datetime,carrier_apt.planned_load_start_datetime,time_zone_rfx) /> + <#assign duration = DurationBetweenTwoDatetimeInSeconds(carrier_apt.planned_unloading_start_datetime?datetime.iso,carrier_apt.planned_load_start_datetime?datetime.iso,time_zone_rfx) /> <#if carrier_apt.unloading_appointment == "true" && carrier_apt.load_appointment == "true"> <#if duration >= 0> "StartDateTime": "${carrier_apt.planned_unloading_start_datetime}" diff --git a/RFXtoRP_RestResponse.ftl b/RFXtoRP_RestResponse.ftl index 5276881..6faa7a8 100644 --- a/RFXtoRP_RestResponse.ftl +++ b/RFXtoRP_RestResponse.ftl @@ -200,6 +200,88 @@ ] <#break> + <#case "appointment_post"> + <#switch restResponsetMsg.status!no_status> + <#case no_status> + [ + { + <#if restResponsetMsg.body?? > + <#assign restResponseBody = JsonUtil.decodeBase64(restResponsetMsg.body) /> + <#else> + <#assign restResponseBody = "${restResponsetMsg?trim?json_string}" /> + + <#assign apiReflexPlatformID = ApiReflexPlatformID.PlatformLogCreate> + "apiReflexPlatformID" : "${apiReflexPlatformID}", + "datas" : + <#include "RFXtoRP_PlatformLogCreate.ftl"> + }, + { + <#assign apiReflexPlatformID = ApiReflexPlatformID.ExecutionflowAllocationError> + "apiReflexPlatformID" : "${apiReflexPlatformID}", + "datas" : + <#include "RFXtoRP_RestResponseAllocationError.ftl"> + } + ] + <#break> + + <#case 200> + <#case 201> + <#-- *********************************************** ApiRestID = receipts_post ******************** --> + <#assign restResponseBody = JsonUtil.decodeBase64(restResponsetMsg.body) /> + <#assign preparationOrderPostResponse = JsonUtil.jsonToMap(restResponseBody)> + <#if preparationOrderPostResponse.status?? && preparationOrderPostResponse.status == "SUCCESS" > + [ + { + <# stop "Création rdz OK" > + + <#assign apiReflexPlatformID = ApiReflexPlatformID.ExecutionflowDeleted> + "apiReflexPlatformID" : "${apiReflexPlatformID}", + "datas" : + <#include "RFXtoRP_Receipt_ExecutionflowDeleted.ftl"> + } + ] + <#else> + [ + { + <#assign restResponseBody = JsonUtil.decodeBase64(restResponsetMsg.body) /> + <#assign apiReflexPlatformID = ApiReflexPlatformID.PlatformLogCreate> + "apiReflexPlatformID" : "${apiReflexPlatformID}", + "datas" : + <#include "RFXtoRP_PlatformLogCreate.ftl"> + }, + { + <#assign apiReflexPlatformID = ApiReflexPlatformID.ExecutionflowAllocationError> + "apiReflexPlatformID" : "${apiReflexPlatformID}", + "datas" : + <#include "RFXtoRP_RestResponseAllocationError.ftl"> + } + ] + + + <#break> + <#default> + [ + { + <#if restResponsetMsg.body?? > + <#assign restResponseBody = JsonUtil.decodeBase64(restResponsetMsg.body) /> + <#else> + <#assign restResponseBody = "${restResponsetMsg?trim?json_string}" /> + + <#assign apiReflexPlatformID = ApiReflexPlatformID.PlatformLogCreate> + "apiReflexPlatformID" : "${apiReflexPlatformID}", + "datas" : + <#include "RFXtoRP_PlatformLogCreate.ftl"> + }, + { + <#assign apiReflexPlatformID = ApiReflexPlatformID.ExecutionflowAllocationError> + "apiReflexPlatformID" : "${apiReflexPlatformID}", + "datas" : + <#include "RFXtoRP_RestResponseAllocationError.ftl"> + } + ] + + <#break> + <#default> <#stop> diff --git a/RPtoRFX_AppointmentEvent.ftl b/RPtoRFX_AppointmentEvent.ftl index 3ba3fb1..2647599 100644 --- a/RPtoRFX_AppointmentEvent.ftl +++ b/RPtoRFX_AppointmentEvent.ftl @@ -9,12 +9,23 @@ <#assign projectRP = project> <#assign organisationRP = organisation> -<#-- initialisation map for SegmentationKey and MetaData --> -<#assign Header_MetaData_Map = {} /> -<#assign SegmentationKeys_Map = {} /> -<#assign Line_MetaData_Map = {} /> - +<#switch eventRP.event> + <#case "Created"> + <#-- *********************************************** Action = CREATE or UPDATE ******************** --> + <#assign appointment = eventRP.data /> + [ + { + <#assign apiRestReflexID = ApiRestReflexID.appointment_post> + "apiRestReflexID" : "${apiRestReflexID}", + "datas" : + <#include "RPtoRFX_CarrierAppointment.ftl"> + } + ] + <#break> + <#default> + <#stop > + <#switch eventRP.event> <#case "Created"> <#assign appointment = eventRP.data /> diff --git a/RPtoRFX_CarrierAppointment.ftl b/RPtoRFX_CarrierAppointment.ftl new file mode 100644 index 0000000..ecd0794 --- /dev/null +++ b/RPtoRFX_CarrierAppointment.ftl @@ -0,0 +1,74 @@ +{ + "id" : {"refid" : "${eventRP.refid?json_string}"}, + "route" : "rest/public/v1/physical_depots/{physical_depot_code}/carrier_appointments", + "method" : "POST", + "uri_substitutions": { + "physical_depot_code": "${RPtoRFXprefixDepot("DPF")}" <#-- "${RPtoRFXprefixDepot(appointment.ActorID)}" --> + }, + "payload" : + { + "appointment_reference": "${appointment.a_defnir?json_string}", + + <#switch appointment.AppointmentType> + <#case "APPOINTMENT_TYPE_EXPEDITION"> + + "unloading_appointment" : "false", + "load_appointment" : "true", + "planned_load_start_datetime : "${appointment.Slot.StartDateTime?iso_nz(time_zone_rfx)}", + "planned_load_end_datetime": "${AddSecondsToDatetime(appointment.Slot.StartDateTime,appointment.Slot.DurationInSeconds)?iso_nz(time_zone_rfx)}" + + <#break> + + <#case "APPOINTMENT_TYPE_RECEPTION"> + "unloading_appointment" : "true", + "load_appointment" : "false", + "planned_unloading_start_datetime : "${appointment.Slot.StartDateTime?iso_nz(time_zone_rfx)}", + "planned_unloading_end_datetime": "${AddSecondsToDatetime(appointment.Slot.StartDateTime,appointment.Slot.DurationInSeconds)?iso_nz(time_zone_rfx)}" + <#break> + <#default> + <#stop "appointment.AppointmentType not implemented" > + + + "planned_carrier" : "${appointment.CarrierName?json_string}", + + <#if appointment.Commissions??> + "physical_receipt_list": [ + <#list appointment.Commissions as commission> + <#-- { + "receipt_activity": "str", + "originator_code": "string", + "physical_receipt_reference": "string", + "receipt_year": 0, + "receipt_number": 0, + "comment_list": [ + { + "line_number": 999, + "group_code": "str", + "text": "string" + } + ] + + { + "ProjectID": "recette-rfxdev", + "OrderID": "SPA-121125-02", + "Quantities": [ + { + "UnitID": "PAL", + "Value": 1.0 + } + ], + "OrganisationID": "recette", + "PartnerAppID": "recette-rfxdev-rfxdev", + "ExecutionflowID": "DPFALIDEPT ALIMSPA-121125-02" + } + } + --> + <#sep>, + + ], + + "constant_appointment": "false" + + + } + } diff --git a/ReflexUtils.ftl b/ReflexUtils.ftl index fbe48c5..4199deb 100644 --- a/ReflexUtils.ftl +++ b/ReflexUtils.ftl @@ -1,6 +1,6 @@ -<#-- --------------------------------------------------------------------------------------- --> +<#-- -------------------------------------------------------------------------------------------- --> <#-- Concat HARDIS WMS timestamp with HARDIS WMS time zone and format this date in ISO UTC format --> -<#-- --------------------------------------------------------------------------------------- --> +<#-- -------------------------------------------------------------------------------------------- --> <#function RfxDateTimetoUTC rfxdatetime offset > <#return ((rfxdatetime + offset)?datetime.iso?iso_utc)> @@ -9,6 +9,22 @@ <#return dateutc?datetime.iso?iso_nz(locale)> +<#-- -------------------------------------------------------------------------------------------- --> +<#-- Add second to dateTime ex: AddSecondsToDatetime("2025-11-17T09:15:00Z"?datetime.iso, 61) --> +<#-- -------------------------------------------------------------------------------------------- --> +<#function AddSecondsToDatetime date seconds> + <#assign timeInMilliseconds = (1000 * seconds) > + <#assign aDate = date?long + timeInMilliseconds?long> + <#return aDate?number_to_datetime> + + +<#-- -------------------------------------------------------------------------------------------- --> +<#-- Duration between two datetimes in second --> +<#-- -------------------------------------------------------------------------------------------- --> +<#function DurationBetweenTwoDatetimeInSeconds startDate endDate> + <#return (endDate?long - startDate?long) / 1000 > + + <#-- --------------------------------------------------------------------------------------- --> <#-- Split email HARDIS WMS into json array string --> <#-- Example : splitemail "john.doe@hardis-group.com,; name@hardis-group.com" -->