Skip to content

优化接口

长耗时优化接口

数据库改动

1. 增加业务名称(business_name)
2. 增加大分类(sort)
3. 增加进度(progress)

修改后的数据库表结构

表名: tbl_async_task
    id                      bigint           not null       任务id
    user_task_id            varchar(64)                     用户任务id
    name                    varchar(64)      not null       任务名称(任务处理函数名称)
    station_id              varchar(16)      not null       站点id
    input                   text             not null       业务请求输入数据
    result                  json                            业务处理结果
    status                  tinyint(4)       not null       任务状态, 1-已经提交, 2-正在执行, 3-已经完成
    repeat                  tinyint(1)                      是否可重复
    message_show            tinyint(1)                      是否展示
    run_count               int(11)          not null       执行次数
    creat_time              datetime         not null       创建时间
    modify_time             datetime         not null       修改时间
    start_time              datetime                        任务开始时间
    end_time                datetime                        任务结束时间
    business_id             int              not null       任务类型id
    business_name           str              not null       业务名称(前端展示所用)
    type                    int              not null       分类(0-导入, 1-导出, 2-处理)
    progress                int                             任务进度(0-100)

gm_service工程

/task/list 任务列表查询

接口描述: 批量任务查看
Method: Get
响应:
    code                    M       int             0为成功, 其它为失败
    msg                     M       str             错误提示信息
    data                    M       json            返回数据容器
    {
        finish              M       bool            True表示全部完成, 反之未完成
        tasks               M       list            任务列表
        [{
            task_id         M       int             任务id
            user_task_id    M       str             用户任务id
            task_name       M       str             任务名称
            status          M       int             任务状态, 1-已经提交, 2-正在执行, 3-已经完成, 4-部分成功, 停止执行, 5-执行失败(全部失败), 停止执行
            progress        M       int             任务进度(1-100之间)
            type            M       int             任务类型(0-导入, 1-导出, 2-处理)
            result          M       json            返回数据容器
            {
                link        O       str             导出时候下载地址
                msg         M       str             结果消息
                target      O       int             前后端约定, 表示前端路由跳转地址
            }
        }]
    }

/task/clear_show 清空已经完成任务

接口: 不展示已经完成的任务
Method: Post
请求:
    task_ids            O       list            任务id列表(task_ids与user_task_ids二者必有其一)
    user_task_ids       O       list            用户自定义id列表
响应:
    code                M       int             0为成功, 其它为失败
    msg                 M       str             错误提示信息
    data                M       null            返回数据容器

/station/sales_analysis/orderdetail 订单列表导出(智能判断接口)

缺陷:
    1. get_categories查询当前group的所有分类慢
    2. get_order_employee 获取指定员工的订单慢
结论:
    1. get_categories 查询操作以后并没有用, 以前用的部分已经被注释了, 现在可以删除
    2. get_order_employee 初步判断可能是由于连表查询加上in查询导致查询慢, 已经使用索引, 需异步
Method: Get
请求:
    ---- params ----
    query_type          M       int             查询类型(1-下单日期, 2-运营周期, 3-收货日期)
    start_date          C       date            下单开始日期(查询类型为1时候必须存在)
    end_date            C       date            下单结束日期(查询类型为1时候必须存在)
    format              O       str             用友格式(yongyou)
    time_config_id      C       str             运营周期id(查询类型为2时候必须存在)
    cycle_start_time    C       datetime        运营开始时间(查询类型为2时候必须存在)
    cycle_end_time      C       datetime        运营结束时间(查询类型为2时候必须存在)
    status              O       int             订单状态
    search_text         O       str             搜索字段
    search_area         O       str             地理标签
响应:
    code                M       int             0为成功, 其它为失败
    msg                 M       str             错误提示信息
    data                M       json            返回数据容器
    {
        async           M       boolean         0表示同步, 1表示异步
        task_url        C       str             任务结果返回地址(异步返回)
        link            C       str             业务数据结果(同步返回)
    }

/station/order/batch/upload 上传导入订单文件

响应:
    code                M       int             0为成功, 其它为失败
    msg                 M       str             错误提示信息
    data                M       json            返回数据容器
    {
        ...
        file_name       M       str             文件名
    }
逻辑:
    返回增加文件名

/station/order/batch/submit 批量提交订单(异步接口)

接口描述:   异步批量提交订单
Method: POST
请求:
    ---- params ----
    task_id             M       str             任务id
    time_config_id      M       str             运营周期id
    order_data          M       list            订单数据
    file_name           M       str             上传文件名
响应:
    code                M       int             0为成功, 其它为失败
    msg                 M       str             错误提示信息
    data                M       json            返回数据容器
    {
        task_url        M       str             任务结果返回地址
    }

/station/stock/in_stock_sheet/modify 提交入库单

问题:
    1. 循环中做更新订单, 删除记录, 插入记录和修改入库等操作数据库操作, 加锁也多
    2. insert_batch_stock 插入批次库存中, 查询条件未做索引
解决办法:
    1. station_id和batch_number加上索引, 以观后效

/station/stock/in_stock_sheet/import 入库商品批量提交(单词导入不超过1000条)

问题:
    1. get_branch 耗时最多
    2. create_batch_number 调用次数最多, 循环中创建批次号
解决办法:
    1. create_batch_number 改为批量创建批次号
    2. 其余数据均是批量操作无需优化

/station/stock/out_stock_sheet/submit/batch 批量出库

接口: 批量提交出库单
Method: POST
请求:
    type                    M       int             参数类型
    start                   O       date            下单开始日期
    end                     O       date            下单结束日期
    time_config_id          O       str             运营周期id
    cycle_start_time        O       datetime        运营开始时间
    cycle_end_time          O       datetime        运营结束时间
响应:
    code                    M       int             0为成功, 其它为失败
    msg                     M       str             错误提示信息
    data                    M       json            返回数据容器
    {
        task_url            M       str             任务结果返回地址
    }