1. 文件
  2. 数据库
  3. HTTP

WechatIMG83.png

准备

  1. 创建demo_source数据库,为防止中文乱码(选项characterEncoding-utf8)
  2. 准备商品表(order.sql),该表用来演示从数据库导入数据

从Excel文件导入数据

  1. 准备订单表.xlxs
  2. 拖出Excel插件
  3. 获取工作表名称->选择订单表,起始行:0 起始列:A
  4. 字段:收件人号码—String,订单创建时间:格式

order表建表语句:

  1. CREATE TABLE `order` (
  2. `id` int(11) NOT NULL AUTO_INCREMENT,
  3. `title` varchar(255) DEFAULT NULL,
  4. `receiver_name` varchar(255) DEFAULT NULL,
  5. `receive_address` varchar(255) DEFAULT NULL,
  6. `receiver_phone` varchar(255) DEFAULT NULL,
  7. `create_time` datetime DEFAULT NULL,
  8. PRIMARY KEY (`id`)
  9. ) ENGINE=InnoDB DEFAULT CHARSET=utf8

复制一份上面的流程:

order_goods建表语句:

  1. CREATE TABLE `order_goods` (
  2. `id` int(11) NOT NULL AUTO_INCREMENT,
  3. `order_id` int(11) DEFAULT NULL,
  4. `goods_id` int(11) DEFAULT NULL,
  5. PRIMARY KEY (`id`)
  6. ) ENGINE=InnoDB DEFAULT CHARSET=utf8

注意: 在excel插件中把订单ID类型改成Integer

从数据库导入数据

源表:demo_source.goods,商品表

建表语句:

  1. CREATE TABLE `goods` (
  2. `id` int(11) NOT NULL AUTO_INCREMENT,
  3. `category` varchar(255) DEFAULT NULL,
  4. `name` varchar(255) DEFAULT NULL,
  5. `description` varchar(255) DEFAULT NULL,
  6. `vendor_id` int(11) DEFAULT NULL,
  7. `price` decimal(10,2) DEFAULT NULL,
  8. PRIMARY KEY (`id`)
  9. ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  10. ## 初始化数据
  11. INSERT INTO goods (`category`,`name`,`description`,`vendor_id`,`price`) VALUES
  12. ("肉类","猪肉","**",1,14),
  13. ("肉类","鸡肉","**",1,10),
  14. ("粮油","花生油","**",2,80.99),
  15. ("粮油","菜籽油","**",2,76.49)

从接口导入数据

目标:导入厂商数据。

源接口:http://localhost:8888/octopus/demo/vendors

响应:

  1. {
  2. "data": [
  3. {
  4. "id": 1,
  5. "name": "某某粮油公司",
  6. "address": "苏州工业园区金鸡湖景区李公堤西入口腾龙桥西",
  7. "telephone": "18765438909"
  8. },
  9. {
  10. "id": 2,
  11. "name": "生擒活虾",
  12. "address": "虎丘路28号(近桐泾北路)",
  13. "telephone": "18765438908"
  14. }
  15. ],
  16. "status": 200
  17. }

目标表vendor厂商:

  1. CREATE TABLE `vendor` (
  2. `id` int(11) NOT NULL auto_increment,
  3. `name` varchar(255) DEFAULT NULL,
  4. `address` varchar(255) DEFAULT NULL,
  5. `telephone` varchar(255) DEFAULT NULL,
  6. PRIMARY KEY (`id`)
  7. ) ENGINE=InnoDB DEFAULT CHARSET=utf8

json插件:
$.data[*]name

流程图:
WechatIMG82.png

查询语句(模拟BI)

  1. SELECT o.id,o.title,o.receiver_name,o.receive_address,o.receiver_phone,o.create_time,
  2. g.category,g.`name`,g.price,v.`name` as vendor_name,v.address
  3. FROM `demo`.`order` as o
  4. INNER JOIN `demo`.`order_goods` as og on o.id = og.`order_id`
  5. INNER JOIN `demo`.`goods` as g ON og.`goods_id` = g.id
  6. INNER JOIN `demo`.`vendor` as v on g.vendor_id = v.id

接口调用:

获取某张表的所有数据: /db/projects/{project}/{name}/all

  1. {
  2. "calculation": "sum",
  3. "dimension": "title",
  4. "restricts": [
  5. ],
  6. "series": "",
  7. "value": "price"
  8. }