一、相关说明


  • 数据库查询组件说明:
    数据库查询就是数据库里面的左连接。
    左连接就是两张表执行左关联查询,把左边的表数据全部查询出来。

  • 需求说明:
    从sys_user表中读取数据,根据dep_id从sys_dept表获取dep_name,保存到Excel中。

  • 源表sys_user和sys_dept建表语句及数据如下:
    sys_user表:

    CREATE TABLE `sys_user` (
      `user_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '用户ID',
      `dept_id` bigint(20) DEFAULT NULL COMMENT '部门ID',
      `user_name` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '用户账号',
      `nick_name` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '用户昵称',
      `user_type` varchar(2) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '00' COMMENT '用户类型(00系统用户)',
      `email` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '' COMMENT '用户邮箱',
      `phonenumber` varchar(11) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '' COMMENT '手机号码',
      `sex` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '0' COMMENT '用户性别(0男 1女 2未知)',
      `avatar` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '' COMMENT '头像地址',
      `password` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '' COMMENT '密码',
      `status` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '0' COMMENT '帐号状态(0正常 1停用)',
      `del_flag` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)',
      `login_ip` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '' COMMENT '最后登录IP',
      `login_date` datetime DEFAULT NULL COMMENT '最后登录时间',
      `create_by` varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '' COMMENT '创建者',
      `create_time` datetime DEFAULT NULL COMMENT '创建时间',
      `update_by` varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '' COMMENT '更新者',
      `update_time` datetime DEFAULT NULL COMMENT '更新时间',
      `remark` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '备注',
      PRIMARY KEY (`user_id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=104 DEFAULT CHARSET=utf8 COMMENT='用户信息表';
    insert  into `sys_user`(`user_id`,`dept_id`,`user_name`,`nick_name`,`user_type`,`email`,`phonenumber`,`sex`,`avatar`,`password`,`status`,`del_flag`,`login_ip`,`login_date`,`create_by`,`create_time`,`update_by`,`update_time`,`remark`) values (1,1000,'admin','苏江明','00','jiangming.su@niit.com.cn','18275128970','1','','$2a$10$hGYly8AzJ16SwMdEoeXrJ.y7E4Fa8xGUJOQAASukgN3omvRimdMFS','0','0','127.0.0.1','2021-02-05 00:07:00','admin','2021-02-05 00:07:00','',NULL,'管理员'),(2,1009,'ry','若依','00','ry@qq.com','15666666666','1','','$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2','0','0','127.0.0.1','2021-02-05 00:07:00','admin','2021-02-05 00:07:00','',NULL,'测试员'),(3,100,'suben','若兰幽竹','00','18275128970@163.com','18275128970','0','','$2a$10$EEcxXsKxffLdiPixY9ZBUuj6wSCKI.5IvCRs9iq.PJU62hucOQivy','0','0','',NULL,'admin','2021-02-05 23:35:07','',NULL,'我是测试'),(100,1009,'sjm','测试','00','cs@163.com','18276125432','0','','$2a$10$Ere5immfiBQv0mw8vAQPhu1FH6cgSB2t5/6GWxvPlk3lnVG8AlkVq','0','0','',NULL,'admin','2021-02-09 01:12:14','',NULL,NULL),(101,1003,'subenjiang','若兰幽竹','00','18275128971@163.com','18275128971','0','','$2a$10$hGYly8AzJ16SwMdEoeXrJ.y7E4Fa8xGUJOQAASukgN3omvRimdMFS','0','0','',NULL,'admin','2021-02-09 02:03:45','Santy','2021-02-09 02:12:52',NULL),(102,1003,'Santy','GNU-Leader','00','','','0','','$2a$10$OK5I7lynBI/KyXANgDthGuoVIKcxvzyp7gR5c5uPEuJSWSg1Pcff2','0','0','',NULL,'admin','2021-02-09 02:09:09','',NULL,NULL),(103,1010,'test001','test','00','','','0','','$2a$10$szYG85pPvjAv2W/YyvjoeOoHNHlSZkTfq2CDdASvJKJF2.qGwLmWi','0','0','',NULL,'admin','2021-02-16 16:24:30','',NULL,NULL);
    

    数据自行添加,可以参考如下:
    在这里插入图片描述

    sys_dept表:

    CREATE TABLE `sys_dept` (
      `dept_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '部门id',
      `parent_id` bigint(20) DEFAULT '0' COMMENT '父部门id',
      `ancestors` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '' COMMENT '祖级列表',
      `dept_name` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '' COMMENT '部门名称',
      `order_num` int(4) DEFAULT '0' COMMENT '显示顺序',
      `leader` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '负责人',
      `phone` varchar(11) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '联系电话',
      `email` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '邮箱',
      `status` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '0' COMMENT '部门状态(0正常 1停用)',
      `del_flag` char(1) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)',
      `create_by` varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '' COMMENT '创建者',
      `create_time` datetime DEFAULT NULL COMMENT '创建时间',
      `update_by` varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '' COMMENT '更新者',
      `update_time` datetime DEFAULT NULL COMMENT '更新时间',
      PRIMARY KEY (`dept_id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=1012 DEFAULT CHARSET=utf8 COMMENT='部门表';
    INSERT  INTO `sys_dept`(`dept_id`,`parent_id`,`ancestors`,`dept_name`,`order_num`,`leader`,`phone`,`email`,`status`,`del_flag`,`create_by`,`create_time`,`update_by`,`update_time`) VALUES (100,0,'0','若依科技',0,'若依','15888888888','ry@qq.com','0','2','admin','2021-02-05 00:06:59','',NULL),(101,100,'0,100','深圳总公司',1,'若依','15888888888','ry@qq.com','0','2','admin','2021-02-05 00:06:59','',NULL),(102,100,'0,100','长沙分公司',2,'若依','15888888888','ry@qq.com','0','2','admin','2021-02-05 00:06:59','',NULL),(103,101,'0,100,101','研发部门',1,'若依','15888888888','ry@qq.com','0','2','admin','2021-02-05 00:06:59','',NULL),(104,101,'0,100,101','市场部门',2,'若依','15888888888','ry@qq.com','0','2','admin','2021-02-05 00:06:59','',NULL),(105,101,'0,100,101','测试部门',3,'若依','15888888888','ry@qq.com','0','2','admin','2021-02-05 00:07:00','',NULL),(106,101,'0,100,101','财务部门',4,'若依','15888888888','ry@qq.com','0','2','admin','2021-02-05 00:07:00','',NULL),(107,101,'0,100,101','运维部门',5,'若依','15888888888','ry@qq.com','0','2','admin','2021-02-05 00:07:00','',NULL),(108,102,'0,100,102','市场部门',1,'若依','15888888888','ry@qq.com','0','2','admin','2021-02-05 00:07:00','',NULL),(109,102,'0,100,102','财务部门',2,'若依','15888888888','ry@qq.com','0','2','admin','2021-02-05 00:07:00','',NULL),(1000,0,'0','NIIT中国',0,'Kamal','18616522950','kamal.dhuper@niit.com.cn','0','0','admin','2021-02-06 00:30:19','Santy','2021-02-16 16:02:53'),(1001,1000,'0,1000','贵州中心',6,'Santy','15261525132','santosh.pal@niit.com.cn','0','0','admin','2021-02-06 00:32:08','Santy','2021-02-16 16:02:53'),(1002,1000,'0,1000','重庆中心',2,'路易斯','18272727272','1616162@niit.com.cn','0','0','admin','2021-02-06 00:33:09','',NULL),(1003,1001,'0,1000,1001','贵州师范大学',1,'Santy','15261525132','santosh.pal@niit.com.cn','0','0','admin','2021-02-06 00:33:56','Santy','2021-02-16 16:02:53'),(1004,1001,'0,1000,1001','贵州电子校',2,'Santy','15261525132','santosh.pal@niit.com.cn','0','0','admin','2021-02-06 00:34:28','',NULL),(1005,1001,'0,1000,1001','贵州职业技术学院',3,'Santy','15261525132','santosh.pal@niit.com.cn','0','0','admin','2021-02-06 00:35:01','',NULL),(1006,1000,'0,1000','青岛中心',3,'王剑','18272828282','18181818@163.com','0','0','admin','2021-02-08 05:00:20','',NULL),(1007,1000,'0,1000','宁夏中心',4,'张三','18276542435','1872622@niit.com.cn','0','0','admin','2021-02-08 05:01:21','',NULL),(1008,1000,'0,1000','海南中心',5,'刘德才','17282727283','71171717@niit.com.cn','0','0','admin','2021-02-08 05:02:16','',NULL),(1009,1000,'0,1000','上海总部',1,'James','18276544567','james.li@niit.com.cn','0','0','admin','2021-02-08 05:22:46','',NULL),(1010,1003,'0,1000,1001,1003','教学部',1,'suben','18275128977',NULL,'0','0','Santy','2021-02-16 16:02:34','Santy','2021-02-16 16:02:53'),(1011,1003,'0,1000,1001,1003','教务部',2,'Nancy','18275128966',NULL,'0','0','Santy','2021-02-16 16:03:16','',NULL);
    

    数据自行添加,如下所示
    在这里插入图片描述

二、设计转换


  • 输入:表输入
  • 查询: 数据库查询
  • 输出:Excel输出
    在这里插入图片描述

三、转换配置


  • Step1:表组件配置

    • 双击组件,写上步骤名称等
    • 相关配置如下所示:
      在这里插入图片描述在这里插入图片描述
      在这里插入图片描述
  • Step2:数据库查询组件配置

    • 双击打开,设置步骤名称
    • 配置信息,如下
      在这里插入图片描述
      在这里插入图片描述
  • Step3:Excel输出组件配置

    • 双击打开,设置步骤名称
    • 配置信息,如下
      在这里插入图片描述
  • Step4:保存转换
    上述配置好后,点击确定即可!

四、运行转换


  • 点击运行按钮,成功运行如下:
    在这里插入图片描述

五、结果分析


  • 在Excel中查看结果
    在这里插入图片描述

  • Preview data 中查看结果
    切换到“Preview data页面”

    • 点击“数据库查询”,看到有请求结果数据
      在这里插入图片描述
  • 结果简单分析
    数据库查询组件本质上就添加了SQL语句的条件语句部分的值,取出前一个表输入的结果集中的某个关键字段的值作为其本身所查询的数据表的条件。本案例等价于如下的SQL语句:

    SELECT u.`dept_id`,u.`user_name`,u.`nick_name`,d.`dept_name` FROM sys_user u LEFT JOIN sys_dept d ON u.`dept_id` = d.`dept_id`
    

    其实表输入组件就可以完成这样的功能。但是在一些场景下亦可以使用数据库查询来完成复杂的功能。

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐