循环复杂列表减去日期时间并期望持续时间但收到空值时出现问题

问题描述 投票:0回答:1

我正在尝试循环遍历具有 Start 和 End DateTime 属性的复杂列表,并返回持续时间列表。 使用 FEEL 表达式

for t in Times return t.End - t.Start
它返回 null。

为了验证我是否拉回了正确的值,我刚刚返回了

t.End
并且返回了预期的日期时间。

接下来,我尝试了同样的操作,但从复杂对象中删除了列表

Time.End - Time.Start
持续时间对象按预期返回。

{
  "Times": [
    {
      "Start": "2024-06-05T11:35:02.534Z",
      "End": "2024-06-05T11:40:02.534Z"
    },
    {
      "Start": "2024-06-05T11:35:02.534Z",
      "End": "2024-06-05T11:45:02.534Z"
    }
  ],
  "Time": {
    "Start": "2024-06-05T11:35:02.534Z",
    "End": "2024-06-05T11:40:02.534Z"
  }
}
<?xml version="1.0" encoding="UTF-8"?>
<dmn:definitions xmlns:dmn="http://www.omg.org/spec/DMN/20180521/MODEL/" xmlns="https://kiegroup.org/dmn/_6B49457F-BD43-44B8-A8D1-C16C038AF388" xmlns:feel="http://www.omg.org/spec/DMN/20180521/FEEL/" xmlns:kie="http://www.drools.org/kie/dmn/1.2" xmlns:dmndi="http://www.omg.org/spec/DMN/20180521/DMNDI/" xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" id="_6D154B1D-07A7-45FB-8072-5CF69CB00FE5" name="Tester" typeLanguage="http://www.omg.org/spec/DMN/20180521/FEEL/" namespace="https://kiegroup.org/dmn/_6B49457F-BD43-44B8-A8D1-C16C038AF388">
  <dmn:extensionElements/>
  <dmn:itemDefinition id="_32787051-6A12-4E8B-9660-29D507705E74" name="tTimes" isCollection="true">
    <dmn:itemComponent id="_05BFFE04-32F4-4C50-9D09-769769DDC843" name="Start" isCollection="false">
      <dmn:typeRef>date and time</dmn:typeRef>
    </dmn:itemComponent>
    <dmn:itemComponent id="_434FDD08-E9E2-4A21-88F9-388812F5B8C9" name="End" isCollection="false">
      <dmn:typeRef>date and time</dmn:typeRef>
    </dmn:itemComponent>
  </dmn:itemDefinition>
  <dmn:itemDefinition id="_21E922DF-5B8D-475E-B623-E6F7A7EDD431" name="tTime" isCollection="false">
    <dmn:itemComponent id="_8814111B-8DA8-47CD-80EC-EA1505D47BCB" name="Start" isCollection="false">
      <dmn:typeRef>date and time</dmn:typeRef>
    </dmn:itemComponent>
    <dmn:itemComponent id="_847C3435-1A87-4480-B831-34535015CB99" name="End" isCollection="false">
      <dmn:typeRef>date and time</dmn:typeRef>
    </dmn:itemComponent>
  </dmn:itemDefinition>
  <dmn:inputData id="_D9E2AF83-1AED-4D85-81A2-6D59ACDBAC40" name="Times">
    <dmn:extensionElements/>
    <dmn:variable id="_539A4E07-D776-4FDB-846E-7D8B12D6F8D8" name="Times" typeRef="tTimes"/>
  </dmn:inputData>
  <dmn:decision id="_147DD60D-E174-4B3B-9C35-A429F0579CB9" name="Durations">
    <dmn:extensionElements/>
    <dmn:variable id="_2F30572C-E7C5-4B99-851A-1BADDDC9C30E" name="Durations" typeRef="Any"/>
    <dmn:informationRequirement id="_ECE5C11A-757A-407D-9F5B-697E051D5A13">
      <dmn:requiredInput href="#_D9E2AF83-1AED-4D85-81A2-6D59ACDBAC40"/>
    </dmn:informationRequirement>
    <dmn:literalExpression id="_20333D57-43F5-43E4-AC58-8AAE36BC85F2">
      <dmn:text>for t in Times
  return t.End - t.Start</dmn:text>
    </dmn:literalExpression>
  </dmn:decision>
  <dmn:inputData id="_78ACBCC1-676A-4D7F-8EE4-9B133A3CE231" name="Time">
    <dmn:extensionElements/>
    <dmn:variable id="_3646CB83-CE3D-4806-913D-DBE43D72FD5E" name="Time" typeRef="tTime"/>
  </dmn:inputData>
  <dmn:decision id="_08F0D84D-4813-46E7-9A9D-E2745E1BDBF5" name="Duration">
    <dmn:extensionElements/>
    <dmn:variable id="_9C554CEE-F0C9-4CEE-B068-3741A4B68184" name="Duration" typeRef="days and time duration"/>
    <dmn:informationRequirement id="_4B6DEFEF-89FA-4C48-8022-4D306A53074D">
      <dmn:requiredInput href="#_78ACBCC1-676A-4D7F-8EE4-9B133A3CE231"/>
    </dmn:informationRequirement>
    <dmn:literalExpression id="_F9CB76A7-9D1D-49B0-9A79-5BC8D8E80D25">
      <dmn:text>Time.End - Time.Start</dmn:text>
    </dmn:literalExpression>
  </dmn:decision>
  <dmndi:DMNDI>
    <dmndi:DMNDiagram id="_5858630C-D84E-4CF8-A9D0-A45135368536" name="DRG">
      <di:extension>
        <kie:ComponentsWidthsExtension>
          <kie:ComponentWidths dmnElementRef="_20333D57-43F5-43E4-AC58-8AAE36BC85F2">
            <kie:width>520</kie:width>
          </kie:ComponentWidths>
          <kie:ComponentWidths dmnElementRef="_F9CB76A7-9D1D-49B0-9A79-5BC8D8E80D25">
            <kie:width>524</kie:width>
          </kie:ComponentWidths>
        </kie:ComponentsWidthsExtension>
      </di:extension>
      <dmndi:DMNShape id="dmnshape-drg-_D9E2AF83-1AED-4D85-81A2-6D59ACDBAC40" dmnElementRef="_D9E2AF83-1AED-4D85-81A2-6D59ACDBAC40" isCollapsed="false">
        <dmndi:DMNStyle>
          <dmndi:FillColor red="255" green="255" blue="255"/>
          <dmndi:StrokeColor red="0" green="0" blue="0"/>
          <dmndi:FontColor red="0" green="0" blue="0"/>
        </dmndi:DMNStyle>
        <dc:Bounds x="342" y="329" width="100" height="50"/>
        <dmndi:DMNLabel/>
      </dmndi:DMNShape>
      <dmndi:DMNShape id="dmnshape-drg-_147DD60D-E174-4B3B-9C35-A429F0579CB9" dmnElementRef="_147DD60D-E174-4B3B-9C35-A429F0579CB9" isCollapsed="false">
        <dmndi:DMNStyle>
          <dmndi:FillColor red="255" green="255" blue="255"/>
          <dmndi:StrokeColor red="0" green="0" blue="0"/>
          <dmndi:FontColor red="0" green="0" blue="0"/>
        </dmndi:DMNStyle>
        <dc:Bounds x="343" y="229" width="100" height="50"/>
        <dmndi:DMNLabel/>
      </dmndi:DMNShape>
      <dmndi:DMNShape id="dmnshape-drg-_78ACBCC1-676A-4D7F-8EE4-9B133A3CE231" dmnElementRef="_78ACBCC1-676A-4D7F-8EE4-9B133A3CE231" isCollapsed="false">
        <dmndi:DMNStyle>
          <dmndi:FillColor red="255" green="255" blue="255"/>
          <dmndi:StrokeColor red="0" green="0" blue="0"/>
          <dmndi:FontColor red="0" green="0" blue="0"/>
        </dmndi:DMNStyle>
        <dc:Bounds x="512" y="329" width="100" height="50"/>
        <dmndi:DMNLabel/>
      </dmndi:DMNShape>
      <dmndi:DMNShape id="dmnshape-drg-_08F0D84D-4813-46E7-9A9D-E2745E1BDBF5" dmnElementRef="_08F0D84D-4813-46E7-9A9D-E2745E1BDBF5" isCollapsed="false">
        <dmndi:DMNStyle>
          <dmndi:FillColor red="255" green="255" blue="255"/>
          <dmndi:StrokeColor red="0" green="0" blue="0"/>
          <dmndi:FontColor red="0" green="0" blue="0"/>
        </dmndi:DMNStyle>
        <dc:Bounds x="513" y="229" width="100" height="50"/>
        <dmndi:DMNLabel/>
      </dmndi:DMNShape>
      <dmndi:DMNEdge id="dmnedge-drg-_ECE5C11A-757A-407D-9F5B-697E051D5A13" dmnElementRef="_ECE5C11A-757A-407D-9F5B-697E051D5A13">
        <di:waypoint x="392" y="354"/>
        <di:waypoint x="393" y="279"/>
      </dmndi:DMNEdge>
      <dmndi:DMNEdge id="dmnedge-drg-_4B6DEFEF-89FA-4C48-8022-4D306A53074D" dmnElementRef="_4B6DEFEF-89FA-4C48-8022-4D306A53074D">
        <di:waypoint x="562" y="354"/>
        <di:waypoint x="563" y="279"/>
      </dmndi:DMNEdge>
    </dmndi:DMNDiagram>
  </dmndi:DMNDI>
</dmn:definitions>

因此,总之,当我有一个具有开始日期时间和结束日期时间的结构化对象时,我可以使用“Time.End - Time.Start”返回一个持续时间,但我不能对“for t”的复杂列表执行相同的操作in Times 返回 t.End - t.Start。给定上述 Times 对象,我如何循环遍历列表并返回持续时间列表?

drools dmn feel-language
1个回答
0
投票

您好,应该可以,我正在发送评估成功的图片。请注意,我使用了日期和时间函数来确保字符串转换为日期和时间 daenter image description hereta 类型。

© www.soinside.com 2019 - 2024. All rights reserved.