# Gradle-DSL **Repository Path**: sudot/Gradle-DSL ## Basic Information - **Project Name**: Gradle-DSL - **Description**: 用 Groovy 实现 Gradle 的 DSL Task 定义 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-02-17 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Groovy 实现的 DSL 处理 ## 本地运行 执行 Application.main 启动系统,默认监听本地 8080 端口 演示接口: http://127.0.0.1:8080/spdb/CreateBill http://127.0.0.1:8080/spdb/GiveupApply ## 开发说明 ### 接口转换 在 `resources/transform` 目录下添加脚本即完成了一个接口的转发处理。 ### 接口规则 添加脚本后,接口请求地址为 `http://127.0.0.1:8080/<脚本路径>` 格式 脚本路径:从 `resources/transform` 下级目录开始。 | 脚本路径 | 接口地址 | | ---------------------------------- | ----------------------------- | | resources/transform/aaa.groovy | http://127.0.0.1:8080/aaa | | resources/transform/a/b/ccc.groovy | http://127.0.0.1:8080/a/b/ccc | 脚本格式如下: ``` import org.springframework.http.HttpMethod // 接口名称 name "浦发_(浦发信用卡)保单生成接口" // 请求信息 request { // 请求目的地 url "http://127.0.0.1:8080/mock" method HttpMethod.POST // 请求参数转换(将接口请求过来的参数转换后发送到【请求目的地】) handler { inputData -> return [ accountAllotId: inputData.accountAllotId, status : inputData.status ] } } // 响应处理 response { // 响应数据转换(将【请求目的地】返回的参数转换并最终输出到请求方) handler { responseData, inputData -> def policyNums = [] for (i in 0..3) { policyNums.add([ policyNum: UUID.randomUUID().toString() ]) } return [ code : '200', message : '成功', data : policyNums, success : true, timestamp: System.currentTimeMillis(), traceId : UUID.randomUUID().toString(), version : '1.0.0', ] } } ``` ## 执行过程 ```mermaid sequenceDiagram API ->> Entrance.groovy : 处理请求数据 Entrance.groovy ->> 自定义DSL脚本 : 构建 DSL 对象和执行流程并执行转换脚本 自定义DSL脚本 -->> Entrance.groovy : 转换请求和响应数据 Entrance.groovy -->> API : 数据返回 ```