【发布时间】:2023-03-19 00:20:02
【问题描述】:
我必须对来自 excel 的输入数据进行一级标准化。[输入 Excel][1]。
现在输出应该类似于[输出文件][2]。我尝试结合 Dataweave 使用 MEL(将方法定义为全局配置)。在 dataweave 内部,我试图将上面定义的方法称为全局配置。这种方法不起作用,因为生成的文件是空白的。任何人都可以在这种方法中提出更好的方法或问题。 下面是代码 @马尼克:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
<configuration doc:name="Configuration">
<expression-language>
<global-functions>
def getCompanyName(name){
if (flowVars.companyList contains name) {
return "";
} else {
flowVars.companyList.add(name);
return name;
}
}
</global-functions>
</expression-language>
</configuration>
<file:connector name="File" autoDelete="true" streaming="true" validateConnections="true" doc:name="File" readFromDirectory="C:\Users\Desktop\Mule-Doc"/>
<file:connector name="File1" autoDelete="true" outputAppend="true" streaming="true" validateConnections="true" doc:name="File"/>
<flow name="csvnormalizationFlow">
<file:inbound-endpoint path="C:\Users\Desktop\Mule-Doc" connector-ref="File" responseTimeout="10000" doc:name="File"/>
<set-variable value="#[[]]" variableName="companyList" doc:name="Variable" mimeType="application/csv"/>
<logger message="The payload is-----------------------#[payload]" level="INFO" doc:name="Logger"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/csv header=true
---
payload map {
CompanyName: getCompanyName($.Company),
location:$.Location
}]]></dw:set-payload>
</dw:transform-message>
<file:outbound-endpoint path="C:\Users\Desktop\Output" outputPattern="test.csv" connector-ref="File1" responseTimeout="10000" doc:name="File"/>
</flow>
</mule>
【问题讨论】:
-
能否请您发布您的 MEL 函数和 dataweave 脚本
-
MEL 函数是
def getCompanyName(name){ if (flowVars.companyList contains name) { return "" ; } else { flowVars.companyList.add(name);返回名称; } } -
数据编织代码是