flow.xml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE flow PUBLIC "liteflow" "liteflow.dtd">
  3. <flow>
  4. <nodes>
  5. <node id="s1" name="普通脚本1" type="script" language="java">
  6. <![CDATA[
  7. import cn.hutool.core.collection.ListUtil;
  8. import com.yomahub.liteflow.core.NodeComponent;
  9. import com.yomahub.liteflow.slot.DefaultContext;
  10. import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
  11. import com.yomahub.liteflow.test.script.javaxpro.common.cmp.Person;
  12. import com.yomahub.liteflow.test.script.javaxpro.common.cmp.TestDomain;
  13. import java.util.List;
  14. public class Demo extends NodeComponent {
  15. @Override
  16. public void process() throws Exception {
  17. int v1 = 2;
  18. int v2 = 3;
  19. DefaultContext ctx = this.getFirstContextBean();
  20. ctx.setData("s1", v1 * v2);
  21. TestDomain domain = ContextAwareHolder.loadContextAware().getBean(TestDomain.class);
  22. System.out.println(domain);
  23. String str = domain.sayHello("jack");
  24. ctx.setData("hi", str);
  25. List<Person> personList = ListUtil.toList(
  26. new Person("jack", 15000),
  27. new Person("tom", 13500),
  28. new Person("peter", 18600)
  29. );
  30. int totalSalary = personList.stream().mapToInt(Person::getSalary).sum();
  31. System.out.println(totalSalary);
  32. ctx.setData("salary", 47100);
  33. }
  34. }
  35. ]]>
  36. </node>
  37. <node id="s2" name="循环脚本1" type="for_script" language="java">
  38. <![CDATA[
  39. import com.yomahub.liteflow.core.NodeForComponent;
  40. public class Demo extends NodeForComponent {
  41. @Override
  42. public int processFor() throws Exception {
  43. return 2;
  44. }
  45. }
  46. ]]>
  47. </node>
  48. <node id="s3" name="选择脚本" type="switch_script" language="java">
  49. <![CDATA[
  50. import com.yomahub.liteflow.core.NodeSwitchComponent;
  51. public class Demo extends NodeSwitchComponent {
  52. @Override
  53. public String processSwitch() throws Exception {
  54. return "b";
  55. }
  56. }
  57. ]]>
  58. </node>
  59. <node id="t1" name="测试脚本T1" type="script" language="java">
  60. <![CDATA[
  61. import com.yomahub.liteflow.core.NodeComponent;
  62. import com.yomahub.liteflow.core.NodeSwitchComponent;
  63. public class Demo extends NodeComponent {
  64. @Override
  65. public void process() throws Exception {
  66. System.out.println(this.getTag());
  67. }
  68. @Override
  69. public void beforeProcess() {
  70. System.out.println("beforeProcess:" + this.getTag());
  71. }
  72. @Override
  73. public void onSuccess() throws Exception {
  74. System.out.println("success! oh yeah");
  75. }
  76. }
  77. ]]>
  78. </node>
  79. <node id="t2" name="测试脚本T2" type="script" language="java">
  80. <![CDATA[
  81. import com.yomahub.liteflow.core.NodeComponent;
  82. import com.yomahub.liteflow.core.NodeSwitchComponent;
  83. import java.util.Map;
  84. public class Demo extends NodeComponent {
  85. @Override
  86. public void process() throws Exception {
  87. Map map = this.getCmpData(Map.class);
  88. System.out.println(map.get("age"));
  89. }
  90. }
  91. ]]>
  92. </node>
  93. </nodes>
  94. <chain name="chain1">
  95. THEN(FOR(s2).DO(THEN(a, b, c, s1)), SWITCH(s3).TO(a,b));
  96. </chain>
  97. <chain name="chain2">
  98. THEN(t1.tag("1111"), t2.data("{\"name\":\"jack\",\"age\":31}"));
  99. </chain>
  100. </flow>