1 Star 2 Fork 1

阀门科技有限公司 / lockgate-autoapi-example

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

AutoApi(自动化接口)

产品宗旨:通过配置的方式自动化处理项目开发中简单重复的内容,解放生产力,使其更加专注产品业务逻辑;快速标准化输出,缩短项目研发周期


1. 产品简介

  • 通过简单的接口规则配置,自动生成13个单表crud接口 + 3个主子表关联接口,基本覆盖单表crud的所有场景
  • 支持各种场景自定义,在crud基础之上增加对复杂业务场景的自定义支持

2. 架构说明

2.1 系统架构

系统架构图

2.2 技术栈

seq 选型 版本
1 spring boot 2.7.3
2 spring-web 5.3.22
3 javax.servlet-api 4.0.1
4 spring-boot-starter-log4j2 2.7.3
5 springdoc-openapi-ui 1.6.11
6 spring-boot-starter-jdbc 2.7.3
7 groovy-all 3.0.9
8 velocity 1.7
9 jackson-datatype-jdk8 2.13.3

3. 功能说明

3.1 接口全景展示

接口全景图

3.2 部分接口示例

3.2.1 分页查询接口

分页查询接口示例图

3.2.2 单对象保存接口

单对象保存接口示例图

3.3 自定义场景支持

seq 场景 状态
1 自定义排序字段配置 支持
2 查询操作自定义,比如like等 支持
3 自定义id生成(默认数据库自增) 支持
4 公共字段赋值的支持,如create_time/create_user等 支持
5 自定义service实现的支持(复杂业务场景支持) 支持
6 事务前事务后,非事务前非事务后自定义操作的支持 支持
7 sql打印和级别定义(方便定位问题) 支持
8 自定义基础实体类支持 支持
9 主子表关联,支持定义对应的主表字段和字表字段 支持
10 mysql数据库支持 支持
11 postgres数据库支持 研发中
12 接口定义配置支持数据库持久化(默认为配置文件) 研发中

4. 开发指引

4.1 注意事项

本产品仅支持数值类型的id,比如int/long等,可以是多个字段的组合id,但要求至少有一个是数值类型

4.2 基础功能配置

基础的api功能,只需要执行以下几个简单的步骤,即可完成

4.2.1 配置步骤
(1) 创建数据库表,范例如下

注意事项:表字段说明会直接提现在接口上,所以表注解越详细易懂,接口说明则越清晰,沟通成本越低

-- 订单主表
CREATE TABLE `mall_order` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID编号',
  `user_id` bigint NOT NULL COMMENT '用户表的用户ID',
  `order_no` varchar(63) NOT NULL COMMENT '订单编码',
  `order_status` smallint DEFAULT NULL COMMENT '订单状态',
  `consignee` varchar(63) DEFAULT NULL COMMENT '收货人名称',
  `mobile` varchar(63) DEFAULT NULL COMMENT '收货人手机号',
  `address` varchar(127) DEFAULT NULL COMMENT '收货具体地址',
  `message` varchar(512) DEFAULT '' COMMENT '用户订单留言',
  `goods_price` decimal(12,4) DEFAULT NULL COMMENT '商品总金额',
  `freight_price` decimal(12,4) DEFAULT NULL COMMENT '配送金额',
  `coupon_price` decimal(12,4) DEFAULT NULL COMMENT '优惠券减免金额',
  `integral_price` decimal(12,4) DEFAULT NULL COMMENT '用户积分减免金额',
  `groupon_price` decimal(12,4) DEFAULT NULL COMMENT '团购优惠价减免金额',
  `order_price` decimal(12,4) DEFAULT NULL COMMENT '订单金额',
  `actual_price` decimal(12,4) DEFAULT NULL COMMENT '实付金额',
  `pay_id` varchar(63) DEFAULT NULL COMMENT '微信付款编号',
  `pay_time` datetime DEFAULT NULL COMMENT '微信付款时间',
  `deleted` tinyint(1) DEFAULT '0' COMMENT '软删除',
  `org_code` varchar(63) DEFAULT NULL COMMENT '组织机构编码',
  `tenant` varchar(32) DEFAULT NULL COMMENT '租户标识',
  `app_id` varchar(32) DEFAULT NULL COMMENT '应用标识 - 一般是创建者应用标识',
  `create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `create_user` varchar(32) DEFAULT NULL COMMENT '创建人标识',
  `create_user_name` varchar(255) DEFAULT NULL COMMENT '创建人名称',
  `update_time` timestamp NULL DEFAULT NULL COMMENT '最后更新时间',
  `update_user` varchar(32) DEFAULT NULL COMMENT '最后更新人标识',
  `update_user_name` varchar(255) DEFAULT NULL COMMENT '最后更新人名称',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1574 DEFAULT CHARSET=utf8mb4 COMMENT='订单表';

-- 订单明细表
CREATE TABLE `mall_order_item` (
   `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID编号',
   `order_id` bigint NOT NULL DEFAULT '0' COMMENT '订单表的订单ID',
   `brand_id` bigint DEFAULT NULL COMMENT '店铺编码',
   `goods_id` bigint NOT NULL DEFAULT '0' COMMENT '商品表的商品ID',
   `goods_name` varchar(127) DEFAULT '' COMMENT '商品名称',
   `goods_sn` varchar(63) DEFAULT '' COMMENT '商品编号',
   `product_id` int DEFAULT '0' COMMENT '货品ID',
   `number` smallint DEFAULT '0' COMMENT '购买数量',
   `price` decimal(12,4) DEFAULT '0.0000' COMMENT '售价',
   `specifications` text COMMENT '规格',
   `pic_url` varchar(255) DEFAULT '' COMMENT '图片地址',
   `comment` bigint DEFAULT '0' COMMENT '评价id',
   `deleted` tinyint(1) DEFAULT '0' COMMENT '软删除',
   `refund_id` bigint DEFAULT NULL COMMENT '退款跟踪ID',
   `org_code` varchar(63) DEFAULT NULL COMMENT '组织机构编码',
   `tenant` varchar(32) DEFAULT NULL COMMENT '租户标识',
   `app_id` varchar(32) DEFAULT NULL COMMENT '应用标识 - 一般是创建者应用标识',
   `create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间',
   `create_user` varchar(32) DEFAULT NULL COMMENT '创建人标识',
   `create_user_name` varchar(255) DEFAULT NULL COMMENT '创建人名称',
   `update_time` timestamp NULL DEFAULT NULL COMMENT '最后更新时间',
   `update_user` varchar(32) DEFAULT NULL COMMENT '最后更新人标识',
   `update_user_name` varchar(255) DEFAULT NULL COMMENT '最后更新人名称',
   PRIMARY KEY (`id`) USING BTREE,
   KEY `idx_01_order_item` (`order_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='订单明细表';
(2) maven仓库地址配置:settings.xml

仓库认证

  <servers>
    <server>
        <id>lockgate-releases</id>
        <username>63704d6128b61c88e75b4600</username>
        <password>7669WMzm=HrM</password>
    </server>
  </servers>

仓库profile

  <profiles>
    <profile>
      <id>lockgate</id>
      <repositories>
        <repository>
          <id>lockgate-releases</id>
          <name>lockgate dependences</name>
          <url>https://packages.aliyun.com/maven/repository/2139326-release-jtDdoi/</url>
        </repository>
      </repositories>
    </profile>
  </profiles>

激活profile

  <activeProfiles>
    <activeProfile>lockgate</activeProfile>
  </activeProfiles>

完整范例

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  
  <localRepository>D:\repository\lockgate</localRepository>
  
  <servers>
    <server>
      <id>lockgate-releases</id>
      <username>63704d6128b61c88e75b4600</username>
      <password>7669WMzm=HrM</password>
    </server>
  </servers>

  <mirrors>
    <mirror>
      <id>AliRepo-aliyun</id>
      <mirrorOf>*,!lockgate-releases</mirrorOf>
      <name>Mirror Name for the Alirepo.</name>
      <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <id>lockgate</id>
      <repositories>
        <repository>
          <id>lockgate-releases</id>
          <name>lockgate dependences</name>
          <url>https://packages.aliyun.com/maven/repository/2139326-release-jtDdoi/</url>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <activeProfiles>
    <!-- 可以激活多个 -->
    <activeProfile>lockgate</activeProfile>
  </activeProfiles>
</settings>
(3) 创建springboot工程,添加如下依赖

当前仅支持mysql数据库,所以依赖mysql支持包即可

<dependency>
    <groupId>cn.lockgate</groupId>
    <artifactId>lockgate-autoapi-support-mysql</artifactId>
    <version>2.0.0</version>
</dependency>
(4) 配置application.yml或者bootstrap.yml
# 基础配置,略
# 数据源配置,略
# autoapi接口配置,如下
autoapi:
  config:
    # resource -> 配置文件, db -> 数据库
    configReaderType: "resource"
    # api的包路径
    # autoPackage: "com.nolink.demo.codeless.auto.api"
    # 是否强制为post
    forcePosting: false
    # 是否开启自动接口,default true
    autoApiEnable: true
    # 开启sql日志打印级别,默认为info
    sqlLogLevel: info
    # 自定义基础类
    # baseDTOClass: cc.nolink.framework.dto.BaseResponseDTO
    # 自定义查询基础类
    # baseQueryDTOClass: cc.nolink.framework.dto.BaseRequestDTO
    # 批处理批次大小
    jdbc:
      batchSize: 500
      maxPageSize: 1000
  api:
    apis:
      - domain: "retails" # 领域,构成接口path的组成部分,规则:/domain/service/entity/action
        services:
          - service: "mall" # 服务,构成接口path的组成部分
            entities:
              - entity: "order" # 实体,构成接口path的组成部分
                table: "mall_order" # 实体对应的数据库表名
                tags: 
                  tagName: "订单头表API" # 接口归类名称,默认为:entity + "API"
                  tagDesc: "订单头表:mall_order增删改查接口" # 接口归类描述,默认为:table + "API"
                actions: # 支持的action,all为全部,为空则表示一个也不支持,可以自定义选择需要的接口。支持的接口全集如下
                  - all
                  #- add # 新增一条记录
                  #- adds  # 批量新增
                  #- updateById  # 依据ID更新
                  #- updateByIds # 依据ID列表批量更新
                  #- updateByQueries # 依据自定义条件批量更新
                  #- save  # 单个:id == null?新增:修改
                  #- saves # 批量:id == null?新增:修改
                  #- deleteById  # 依据ID删除
                  #- deleteByIds # 依据ID列表批量删除
                  #- deleteByQueries # 依据自定义条件批量删除
                  #- findById  # 依据ID查询
                  #- queryByIds  # 依据ID列表查询列表,不带分页
                  #- query # 依据自定义条件查询列表,带分页
                  #- addWithItems  # 主子表关联新增
                  #- deleteWithItemsById # 依据主表ID级联删除主子表
                  #- findWithItemsById # 依据主表ID级联查询主子表
                orders: # map格式的排序规则配置,多个字段按定义的顺序进行排序
                  - order_no: desc # 数据库字段名:排序规则(asc/desc)
                  - create_time: asc
                items: # 主子表关联配置,可以配置多个,如果没有,则不配置该items项
                  - tableName: "mall_order_item" # 子表名称
                    foreignKey: "order_id" # 子表关联字段名称
                    parentKey: "id" # 对应主表字段名称,默认是id
              - entity: "order/item" # 实体,为了path显示更合理,entity支持定义成order/item这样的格式
                table: "mall_order_item"
                actions: # 自定义选择的action,最终接口仅仅展示选择的内容
                  - add
                  - adds
                  - updateById
                  - save
                  - saves
                  - deleteById
          - service: "customer"
            entities:
              - entity: "customer"
                table: "eg_customer"
                actions:
                  - all
      - domain: "marketing"
(5) 启动工程,打开swagger-ui接口列表,即可提交前端进行调试

例如范例工程打开:http://127.0.0.1:8080/swagger-ui.html swagger效果示例


更多开发说明请参考产品说明文档
https://www.jianshu.com/p/f4139dde9e97


版权说明

  • 这是一个范例工程,产品本身并不提供源码,但是提供完整功能
  • 产品规划目标是全行业的低代码平台,包含前后端的全功能配置,当前仅仅是后端自动接口部分的功能,请持续关注这里的变化
  • 如果需要源码进行定制二开,可以联系我们

联系我们

  • 如果使用过程中遇到问题或者建议,请通过issue提交,我们会即时处理和回复
  • 需要源码或者其他商务合作,请通过邮件联系我们,邮箱地址:lockgate@163.com
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [2022] [lockgate.cn] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

自动化api接口框架,通过配置的方式自动化处理项目开发中简单重复的内容,解放生产力,使其更加专注产品业务逻辑;快速标准化输出,缩短项目研发周期 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/lockgate/lockgate-autoapi-example.git
git@gitee.com:lockgate/lockgate-autoapi-example.git
lockgate
lockgate-autoapi-example
lockgate-autoapi-example
master

搜索帮助