# 功能描述

实现kettle数据导入导出功能。

# Service接口

提示

需在application.yml中设置sei.cloud.exchange.enabled为true才能开启exchange服务

# 第一步 引入包

<dependency>
    <groupId>sei-cloud</groupId>
    <artifactId>exchange</artifactId>
</dependency>
1
2
3
4

# 第二步 引入接口

@Resource
    ExchangeService exchangeService;
1
2

# 第三步 使用接口

/**
 * 数据交换服务
 * @author xiong
 */
public interface ExchangeService {

    /**
     * 执行ktr格式文件数据导入
     * @param configFile: ktr模板文件
     * @param params: 参数表
     * @throws KettleException 异常
     */
    void runKtr(@NonNull String configFile, @Nullable Map<String, String> params) throws KettleException;

    /**
     * 执行kjb格式文件数据导入
     * @param configFile: kjb模板文件
     * @param params: 参数表
     * @throws KettleException 异常
     */
    void runKjb(@NonNull String configFile, @Nullable Map<String, String> params) throws KettleException;

    /**
     * 获取xml模板文件中的变量
     * @param fileName: 文件名
     * @return 字符串数组String[]
     * @throws IOException 异常
     */
    String[] getVarFroXml(@NonNull String fileName) throws IOException;

    /**
     * kettle数据导入
     * @param configFileUUID: 模板文件在sys_import_kettle_config表中的uuid,同时用于确定二级目录
     * @param module: 所属模块,用于确定一级目录
     * @param dataFileName: 要导入的数据文件
     * @throws IOException 异常
     * @throws KettleException 异常
     * @throws SQLException 异常
     */
    void importKettleData(@NonNull String configFileUUID, @NonNull String module, @NonNull String dataFileName) throws IOException, KettleException, SQLException;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

# Controller接口

/**
 * 数据交换服务
 * @author xiong
 */
@ConditionalOnProperty(name = "sei.cloud.exchange.enabled", havingValue = "true")
@Api(description = "数据交换服务")
@RequestMapping(value = "/api/exchange/")
public class ExchangeController {

    @ApiOperation(value = "获得xml中变量",response = ResMsg.class)
    @RequestMapping(value = "/getVarFroXml",method = {RequestMethod.POST},produces = { MediaType.APPLICATION_JSON_VALUE })
    public @ResponseBody ResMsg getVarFroXml(@RequestBody JSONObject json) throws Exception;

    @ApiOperation(value = "数据导入",response = ResMsg.class)
    @RequestMapping(value = "/importKettleData",method = {RequestMethod.POST},produces = { MediaType.APPLICATION_JSON_VALUE })
    public @ResponseBody ResMsg importKettleData(@RequestBody JSONObject json) throws Exception;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18