- 文件
- 数据库
- HTTP
准备
- 创建demo_source数据库,为防止中文乱码(选项characterEncoding-utf8)
- 准备商品表(order.sql),该表用来演示从数据库导入数据
从Excel文件导入数据
- 准备订单表.xlxs
- 拖出Excel插件
- 获取工作表名称->选择订单表,起始行:0 起始列:A
- 字段:收件人号码—String,订单创建时间:格式
order表建表语句:
CREATE TABLE `order` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) DEFAULT NULL,
`receiver_name` varchar(255) DEFAULT NULL,
`receive_address` varchar(255) DEFAULT NULL,
`receiver_phone` varchar(255) DEFAULT NULL,
`create_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
复制一份上面的流程:
order_goods建表语句:
CREATE TABLE `order_goods` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` int(11) DEFAULT NULL,
`goods_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
注意: 在excel插件中把订单ID类型改成Integer
从数据库导入数据
源表:demo_source.goods,商品表
建表语句:
CREATE TABLE `goods` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category` varchar(255) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`description` varchar(255) DEFAULT NULL,
`vendor_id` int(11) DEFAULT NULL,
`price` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
## 初始化数据
INSERT INTO goods (`category`,`name`,`description`,`vendor_id`,`price`) VALUES
("肉类","猪肉","**",1,14),
("肉类","鸡肉","**",1,10),
("粮油","花生油","**",2,80.99),
("粮油","菜籽油","**",2,76.49)
从接口导入数据
目标:导入厂商数据。
源接口:http://localhost:8888/octopus/demo/vendors
响应:
{
"data": [
{
"id": 1,
"name": "某某粮油公司",
"address": "苏州工业园区金鸡湖景区李公堤西入口腾龙桥西",
"telephone": "18765438909"
},
{
"id": 2,
"name": "生擒活虾",
"address": "虎丘路28号(近桐泾北路)",
"telephone": "18765438908"
}
],
"status": 200
}
目标表vendor厂商:
CREATE TABLE `vendor` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) DEFAULT NULL,
`address` varchar(255) DEFAULT NULL,
`telephone` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
json插件:$.data[*]name
流程图:
查询语句(模拟BI)
SELECT o.id,o.title,o.receiver_name,o.receive_address,o.receiver_phone,o.create_time,
g.category,g.`name`,g.price,v.`name` as vendor_name,v.address
FROM `demo`.`order` as o
INNER JOIN `demo`.`order_goods` as og on o.id = og.`order_id`
INNER JOIN `demo`.`goods` as g ON og.`goods_id` = g.id
INNER JOIN `demo`.`vendor` as v on g.vendor_id = v.id
接口调用:
获取某张表的所有数据: /db/projects/{project}/{name}/all
{
"calculation": "sum",
"dimension": "title",
"restricts": [
],
"series": "",
"value": "price"
}