准备表----费用类型
fee_type
建表语句
CREATE TABLE `fee_type` (
`id` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '记录的主键',
`created` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间',
`created_by` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '创建人',
`last_upd` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '最后更新时间',
`last_upd_by` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '最后更新人',
`org_id` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '组织id',
`postn_id` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '职位id',
`row_version` bigint(19) NOT NULL DEFAULT 1 COMMENT '版本id',
`cost_type_code` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '费用类型编号',
`cost_type_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '费用类型名称',
`cost_type_level` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '费用类型级别',
`parent_cost_code` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '父费用类型编号',
`effectived` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '是否有效',
PRIMARY KEY (`id`) USING BTREE,
INDEX `LNK_FEE_TYPE_N1`(`cost_type_code`) USING BTREE,
INDEX `LNK_FEE_TYPE_N4`(`effectived`) USING BTREE,
INDEX `LNK_FEE_TYPE_N5`(`cost_type_level`, `effectived`, `parent_cost_code`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '费用类型、活动类型共用' ROW_FORMAT = Dynamic;
插入数据测试
INSERT INTO `fee_type` VALUES ('278487513579263763', '2020-12-08 11:29:57', 'W-30DB903', '2021-04-14 17:12:35', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100001', '渠道建设', '1', NULL, 'Y');
INSERT INTO `fee_type` VALUES ('278487513868670740', '2020-12-08 11:29:57', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100002', '消费者建设', '1', NULL, 'Y');
INSERT INTO `fee_type` VALUES ('278487514174723596', '2020-12-08 11:29:57', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100003', '团队建设', '1', NULL, 'Y');
INSERT INTO `fee_type` VALUES ('278487514468324877', '2020-12-08 11:29:57', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100004', '品牌推广', '1', NULL, 'Y');
INSERT INTO `fee_type` VALUES ('278487514762057493', '2020-12-08 11:29:57', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100005', '特殊支持', '1', NULL, 'Y');
INSERT INTO `fee_type` VALUES ('278487515055658774', '2020-12-08 11:29:57', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100006', '销售奖励', '2', '100001', 'Y');
INSERT INTO `fee_type` VALUES ('278576284291043763', '2020-12-08 17:22:41', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100007', '渠道专项支持', '2', '100001', 'Y');
INSERT INTO `fee_type` VALUES ('278576284567998864', '2020-12-08 17:22:41', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100008', '包装物回收', '2', '100001', 'Y');
INSERT INTO `fee_type` VALUES ('278576284840628625', '2020-12-08 17:22:42', 'W-30DB903', '2021-08-16 17:52:27', '313639993816126100', 'W-5GJLF', 'W-5GJLE', 1, '100009', '进场陈列', '2', '100001', 'Y');
INSERT INTO `fee_type` VALUES ('278576285125710260', '2020-12-08 17:22:42', 'W-30DB903', '2021-07-26 14:03:25', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100010', '渠道工作会议', '2', '100001', 'Y');
INSERT INTO `fee_type` VALUES ('278576285402534325', '2020-12-08 17:22:42', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100011', '渠道客情维护', '2', '100001', 'Y');
INSERT INTO `fee_type` VALUES ('278576285675295122', '2020-12-08 17:22:42', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100012', '渠道运营补贴费用', '2', '100001', 'Y');
INSERT INTO `fee_type` VALUES ('278576285960507795', '2020-12-08 17:22:42', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100013', '消费者客情维护', '2', '100002', 'Y');
INSERT INTO `fee_type` VALUES ('278576286245589430', '2020-12-08 17:22:42', 'W-30DB903', '2021-06-11 10:05:52', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100014', '参观旅游', '2', '100002', 'Y');
INSERT INTO `fee_type` VALUES ('278576286530802103', '2020-12-08 17:22:42', 'W-30DB903', '2021-06-11 10:11:53', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100015', '消费者买赠', '2', '100002', 'Y');
INSERT INTO `fee_type` VALUES ('278576286816014776', '2020-12-08 17:22:42', 'W-30DB903', '2021-06-11 10:05:52', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100016', '小众传播', '2', '100002', 'Y');
INSERT INTO `fee_type` VALUES ('278576287092969876', '2020-12-08 17:22:42', 'W-30DB903', '2021-06-11 10:05:52', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100017', '会战费用', '2', '100003', 'Y');
INSERT INTO `fee_type` VALUES ('278576287361405333', '2020-12-08 17:22:42', 'W-30DB903', '2021-06-11 10:05:52', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100018', '促销人员补贴', '2', '100003', 'Y');
INSERT INTO `fee_type` VALUES ('278576287650681273', '2020-12-08 17:22:42', 'W-30DB903', '2021-06-11 10:05:52', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100019', '销售提成及奖励', '2', '100003', 'Y');
INSERT INTO `fee_type` VALUES ('278576287927505338', '2020-12-08 17:22:42', 'W-30DB903', '2021-06-11 10:05:52', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100020', '活动类', '2', '100004', 'Y');
INSERT INTO `fee_type` VALUES ('278576288208654742', '2020-12-08 17:22:42', 'W-30DB903', '2021-08-03 16:21:55', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100021', '广宣促销品类', '2', '100004', 'Y');
INSERT INTO `fee_type` VALUES ('278576288485478807', '2020-12-08 17:22:42', 'W-30DB903', '2021-06-11 10:05:52', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100022', '终端形象建设类', '2', '100004', 'Y');
INSERT INTO `fee_type` VALUES ('278576288749588923', '2020-12-08 17:22:42', 'W-30DB903', '2021-06-11 10:05:52', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100023', '下属客户打包费用', '2', '100005', 'Y');
INSERT INTO `fee_type` VALUES ('278576289030607292', '2020-12-08 17:22:43', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100024', '其他费用投入', '2', '100005', 'Y');
INSERT INTO `fee_type` VALUES ('278576289307562392', '2020-12-08 17:22:43', 'W-30DB903', '2022-04-13 10:19:42', '390110232119742891', 'W-5GJLF', 'W-5GJLE', 1, '100025', '经销商销售奖励', '3', '100006', 'Y');
INSERT INTO `fee_type` VALUES ('278576289584386457', '2020-12-08 17:22:43', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100026', '其他销售奖励', '3', '100006', 'Y');
INSERT INTO `fee_type` VALUES ('278576289856885181', '2020-12-08 17:22:43', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100027', '招商奖励', '3', '100007', 'Y');
INSERT INTO `fee_type` VALUES ('278576290129514942', '2020-12-08 17:22:43', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100028', '经销商随货支持', '3', '100007', 'Y');
INSERT INTO `fee_type` VALUES ('278576290469384602', '2020-12-08 17:22:43', 'W-30DB903', '2021-04-14 17:12:51', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100029', '二维码扫码奖励', '3', '100007', 'Y');
INSERT INTO `fee_type` VALUES ('278576290775568795', '2020-12-08 17:22:43', 'W-30DB903', '2022-08-12 10:09:04', '496252475579495099', 'W-5GJLF', 'W-5GJLE', 1, '100030', '包装物回收费', '3', '100008', 'Y');
INSERT INTO `fee_type` VALUES ('278576291056587164', '2020-12-08 17:22:43', 'W-30DB903', '2021-08-16 17:52:23', '313639993816126100', 'W-5GJLF', 'W-5GJLE', 1, '100031', '进场陈列费', '3', '100009', 'Y');
INSERT INTO `fee_type` VALUES ('278576291333280191', '2020-12-08 17:22:43', 'W-30DB903', '2021-07-26 14:03:21', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100032', '渠道工作会议', '3', '100010', 'Y');
INSERT INTO `fee_type` VALUES ('278576291614298560', '2020-12-08 17:22:43', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100033', '渠道客情维护', '3', '100011', 'Y');
INSERT INTO `fee_type` VALUES ('278576291887059357', '2020-12-08 17:22:43', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100034', '运营补贴', '3', '100012', 'Y');
INSERT INTO `fee_type` VALUES ('278576292172272030', '2020-12-08 17:22:43', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100035', 'VIP(顾问)赠酒及赠品', '3', '100013', 'Y');
INSERT INTO `fee_type` VALUES ('278576292507685313', '2020-12-08 17:22:43', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100036', '消费者联谊活动', '3', '100013', 'Y');
INSERT INTO `fee_type` VALUES ('278576292792897986', '2020-12-08 17:22:43', 'W-30DB903', '2021-06-03 22:50:23', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100037', '赠饮及免品活动', '3', '100013', 'Y');
INSERT INTO `fee_type` VALUES ('278576293069853087', '2020-12-08 17:22:44', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100038', '泸州游-旅游费用', '3', '100014', 'Y');
INSERT INTO `fee_type` VALUES ('278576293338288544', '2020-12-08 17:22:44', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100039', '泸州游-用酒及服务费', '3', '100014', 'Y');
INSERT INTO `fee_type` VALUES ('278576293610787267', '2020-12-08 17:22:44', 'W-30DB903', '2021-06-03 22:50:23', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100040', '其他参观旅游', '3', '100014', 'Y');
INSERT INTO `fee_type` VALUES ('278576293900194244', '2020-12-08 17:22:44', 'W-30DB903', '2022-07-04 14:32:54', '365863757483873176', 'W-5GJLF', 'W-5GJLE', 1, '100041', '常规买赠', '3', '100015', 'Y');
INSERT INTO `fee_type` VALUES ('278576294181343649', '2020-12-08 17:22:44', 'W-30DB903', '2021-06-11 11:36:41', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100042', '宴席买赠', '3', '100015', 'Y');
INSERT INTO `fee_type` VALUES ('278576294458167714', '2020-12-08 17:22:44', 'W-30DB903', '2022-11-03 16:11:33', '456849390927278321', 'W-5GJLF', 'W-5GJLE', 1, '100043', '品鉴会', '3', '100016', 'Y');
INSERT INTO `fee_type` VALUES ('278576294730666437', '2020-12-08 17:22:44', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100044', '会战生活补贴', '3', '100017', 'Y');
INSERT INTO `fee_type` VALUES ('278576295032656326', '2020-12-08 17:22:44', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100045', '会战综合费用', '3', '100017', 'Y');
INSERT INTO `fee_type` VALUES ('278576295301222819', '2020-12-08 17:22:44', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100046', '经销商团队补贴', '3', '100018', 'Y');
INSERT INTO `fee_type` VALUES ('278576295569658276', '2020-12-08 17:22:44', 'W-30DB903', '2021-04-14 17:12:30', '203974814799364097', 'W-5GJLF', 'W-5GJLE', 1, '100047', '销售提成及奖励', '3', '100019', 'Y');
INSERT INTO `fee_type` VALUES ('278576295842156999', '2020-12-08 17:22:44', 'W-30DB903', '2021-07-09 16:26:18', '274312196195225712', 'W-5GJLF', 'W-5GJLE', 1, '100048', '品牌级俱乐部活动', '3', '100020', 'Y');
INSERT INTO `fee_type` VALUES ('278576296106398152', '2020-12-08 17:22:44', 'W-30DB903', '2021-06-03 22:50:22', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100049', '区域级俱乐部活动', '3', '100020', 'Y');
INSERT INTO `fee_type` VALUES ('278576296404324773', '2020-12-08 17:22:44', 'W-30DB903', '2021-06-03 22:50:22', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100050', '整合营销活动', '3', '100020', 'Y');
INSERT INTO `fee_type` VALUES ('278576296685343142', '2020-12-08 17:22:44', 'W-30DB903', '2021-06-03 22:50:22', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100051', '事件营销活动', '3', '100020', 'Y');
INSERT INTO `fee_type` VALUES ('278576296962036169', '2020-12-08 17:22:44', 'W-30DB903', '2021-08-03 16:21:55', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100052', '销售促进类广宣促销品', '3', '100021', 'Y');
INSERT INTO `fee_type` VALUES ('278576297234796967', '2020-12-08 17:22:45', 'W-30DB903', '2021-08-03 16:21:55', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100053', '客情维护类广宣促销品', '3', '100021', 'Y');
INSERT INTO `fee_type` VALUES ('278576297511621032', '2020-12-08 17:22:45', 'W-30DB903', '2021-11-04 11:27:25', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100054', '品牌形象类广宣促销品', '3', '100021', 'Y');
INSERT INTO `fee_type` VALUES ('278576297809285578', '2020-12-08 17:22:45', 'W-30DB903', '2021-06-09 18:07:20', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100055', '形象店建设', '3', '100022', 'Y');
INSERT INTO `fee_type` VALUES ('278576298086109643', '2020-12-08 17:22:45', 'W-30DB903', '2021-06-09 18:07:20', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100056', '门头店招', '3', '100022', 'Y');
INSERT INTO `fee_type` VALUES ('278576298367259049', '2020-12-08 17:22:45', 'W-30DB903', '2021-06-09 18:07:20', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100057', '终端物料及展陈', '3', '100022', 'Y');
INSERT INTO `fee_type` VALUES ('278576298635694506', '2020-12-08 17:22:45', 'W-30DB903', '2021-06-09 18:07:20', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100058', '下属客户打包费用', '3', '100023', 'Y');
INSERT INTO `fee_type` VALUES ('278576298908193228', '2020-12-08 17:22:45', 'W-30DB903', '2021-06-09 18:07:20', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100059', '样品酒费用', '3', '100024', 'Y');
INSERT INTO `fee_type` VALUES ('278576299176628685', '2020-12-08 17:22:45', 'W-30DB903', '2021-06-09 18:07:20', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100060', '渠道政策促销奖励', '2', '100001', 'Y');
INSERT INTO `fee_type` VALUES ('278576299445195179', '2020-12-08 17:22:45', 'W-30DB903', '2021-06-09 18:07:20', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100061', '渠道政策促销奖励', '3', '100060', 'Y');
INSERT INTO `fee_type` VALUES ('278576299730407852', '2020-12-08 17:22:45', 'W-30DB903', '2021-06-09 18:07:20', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100062', '促销品及促销用酒预投', '3', '100015', 'Y');
INSERT INTO `fee_type` VALUES ('406506275765882910', '2021-11-26 17:50:48', 'W-30DB903', '2022-05-17 15:37:51', '456849390927278321', 'W-5GJLF', 'W-5GJLE', 1, '100065', '线上运营建设', '1', NULL, 'Y');
INSERT INTO `fee_type` VALUES ('406506384238841882', '2021-11-26 17:51:14', 'W-30DB903', '2022-08-01 16:03:17', '496252475579495099', 'W-5GJLF', 'W-5GJLE', 1, '100066', '平台费用', '2', '100065', 'Y');
INSERT INTO `fee_type` VALUES ('406506529454559271', '2021-11-26 17:51:49', 'W-30DB903', '2021-11-26 17:51:49', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100067', '流量购买费', '2', '100065', 'Y');
INSERT INTO `fee_type` VALUES ('406506643530846239', '2021-11-26 17:52:16', 'W-30DB903', '2022-05-17 14:54:38', '456849390927278321', 'W-5GJLF', 'W-5GJLE', 1, '100068', '第三方服务费', '2', '100065', 'Y');
INSERT INTO `fee_type` VALUES ('406506790713036830', '2021-11-26 17:52:51', 'W-30DB903', '2022-08-01 16:03:47', '496252475579495099', 'W-5GJLF', 'W-5GJLE', 1, '100069', '佣金及手续费', '3', '100066', 'Y');
INSERT INTO `fee_type` VALUES ('406506929133981737', '2021-11-26 17:53:24', 'W-30DB903', '2022-08-29 15:18:14', '496252475579495099', 'W-5GJLF', 'W-5GJLE', 1, '100070', '平台工具使用费用', '3', '100066', 'Y');
INSERT INTO `fee_type` VALUES ('406507122553786399', '2021-11-26 17:54:10', 'W-30DB903', '2021-11-26 17:54:10', 'W-30DB903', 'W-5GJLF', 'W-5GJLE', 1, '100071', '营销流量推广', '3', '100067', 'Y');
INSERT INTO `fee_type` VALUES ('406507233833390122', '2021-11-26 17:54:37', 'W-30DB903', '2022-05-17 15:37:49', '456849390927278321', 'W-5GJLF', 'W-5GJLE', 1, '100072', '短信营销', '3', '100067', 'Y');
INSERT INTO `fee_type` VALUES ('406507351395012641', '2021-11-26 17:55:05', 'W-30DB903', '2022-05-17 15:57:44', '456849390927278321', 'W-5GJLF', 'W-5GJLE', 1, '100073', '第三方服务费', '3', '100068', 'Y');
INSERT INTO `fee_type` VALUES ('468801644001685507', '2022-05-17 15:30:21', '456849390927278321', '2022-08-29 15:18:08', '496252475579495099', '365628015105151465', '384761491879628917', 1, '100074', '测试费用001', '3', '100073', 'Y');
INSERT INTO `fee_type` VALUES ('496358084731664229', '2022-08-01 16:29:49', '496252475579495099', '2022-08-29 15:18:06', '496252475579495099', '369513139651088616', '390916900831105488', 1, '10075', '测试', '3', '100012', 'Y');
INSERT INTO `fee_type` VALUES ('496368858384627505', '2022-08-01 17:12:37', '496252475579495099', '2022-08-01 17:12:37', '496252475579495099', '369513139651088616', '390916900831105488', 1, '10075', 'ceshi AY', '3', '100067', 'Y');
INSERT INTO `fee_type` VALUES ('529629692048896115', '2022-11-01 11:59:18', '456849390927278321', '2022-11-01 11:59:18', '456849390927278321', '96900004282531112', '443798252648398988', 1, '123', '123', '3', '100062', 'Y');
表数据关系简介
费用大类----费用中类-----费用小类
区分字段 费用层级 cost_type_level :大类(1),中类(2),小类(3)
大中小类父子关系关联字段 parent_cost_code
业务需求
采用层级方式展示查询费用大类及其子层级
实现代码,xml子集映射关系
方式一
<select id="queryTreeList" parameterType="com.model.FeeType" resultMap="feeTypeTree">
SELECT
t1.id AS id,
t1.cost_type_code AS largeTypeCode,
t1.cost_type_name AS largeTypeName,
t1.cost_type_level AS largeTypeLevel,
t2.middleId AS middleId,
t2.middleTypeCode AS middleTypeCode,
t2.middleTypeName AS middleTypeName,
t2.middleTypeLevel AS middleTypeLevel,
t2.smallId AS smallId,
t2.smallTypeCode AS smallTypeCode,
t2.smallTypeName AS smallTypeName,
t2.smallTypelevel AS smallTypeLevel
FROM
fee_type t1
LEFT JOIN (
SELECT
s1.id AS middleId,
s1.cost_type_code AS middleTypeCode,
s1.cost_type_name AS middleTypeName,
s1.cost_type_level AS middleTypeLevel,
s1.PARENT_COST_CODE AS parentCostCode,
s2.id AS smallId,
s2.costTypeCode AS smallTypeCode,
s2.costTypeName AS smallTypeName,
s2.costTypeLevel AS smallTypelevel
FROM
fee_type s1
LEFT JOIN (
SELECT
m1.id AS id,
m1.cost_type_code AS costTypeCode,
m1.cost_type_name AS costTypeName,
m1.cost_type_level AS costTypeLevel,
m1.PARENT_COST_CODE AS parentCostCode
FROM
fee_type m1
WHERE
m1.cost_type_level = '3'
AND m1.effectived = 'Y'
) s2 ON s1.cost_type_code = s2.parentCostCode
WHERE
s1.cost_type_level = '2'
AND s1.effectived = 'Y'
) t2 ON t1.cost_type_code = t2.parentCostCode
WHERE
t1.cost_type_level = '1'
AND t1.effectived = 'Y'
GROUP BY
t1.id,
t2.middleId,
t2.smallId
</select>
<resultMap type="com.model.FeeType" id="feeTypeTree">
<result column="id" property="id" jdbcType="VARCHAR" />
<result column="largeTypeCode" property="costTypeCode" jdbcType="VARCHAR" />
<result column="largeTypeName" property="costTypeName" jdbcType="VARCHAR" />
<result column="largeTypeLevel" property="costTypeLevel" jdbcType="VARCHAR" />
<collection property="children" ofType="com.model.FeeType">
<result column="middleId" property="id" jdbcType="VARCHAR" />
<result column="middleTypeCode" property="costTypeCode" jdbcType="VARCHAR" />
<result column="middleTypeName" property="costTypeName" jdbcType="VARCHAR" />
<result column="middleTypeLevel" property="costTypeLevel" jdbcType="VARCHAR" />
<collection property="children" ofType="com.model.FeeType">
<result column="smallId" property="id" jdbcType="VARCHAR" />
<result column="smallTypeCode" property="costTypeCode" jdbcType="VARCHAR" />
<result column="smallTypeName" property="costTypeName" jdbcType="VARCHAR" />
<result column="smallTypeLevel" property="costTypeLevel" jdbcType="VARCHAR" />
</collection>
</collection>
</resultMap>
方式二
<select id="queryTreeList" resultMap="costTypeTree"
resultType="com.model.FeeType">
SELECT
t1.id AS id,
t1.cost_type_code AS costLargeTypeCode,
t1.cost_type_name AS costLargeTypeName,
t1.cost_type_level AS largeTypeLevel,
t2.id AS middleId,
t2.cost_type_code AS costMiddleTypeCode,
t2.cost_type_name AS costMiddleTypeName,
t2.cost_type_level AS middleTypeLevel,
t3.id AS smallId,
t3.cost_type_code AS costTypeCode,
t3.cost_type_name AS costTypeName,
t3.cost_type_level AS smallTypeLevel
FROM
lnk_fee_type t1
LEFT JOIN lnk_fee_type t2 ON t1.cost_type_code = t2.parent_cost_code
LEFT JOIN lnk_fee_type t3 ON t2.cost_type_code = t3.parent_cost_code
WHERE
t1.cost_type_level = '1'
AND t1.effectived = 'Y'
</select>
<resultMap type="com.model.FeeType" id="costTypeTree">
<result column="id" property="id" jdbcType="VARCHAR" />
<result column="costLargeTypeCode" property="costTypeCode" jdbcType="VARCHAR" />
<result column="costLargeTypeName" property="costTypeName" jdbcType="VARCHAR" />
<result column="largeTypeLevel" property="costTypeLevel" jdbcType="VARCHAR" />
<collection property="children" ofType="com.model.FeeType">
<result column="middleId" property="id" jdbcType="VARCHAR" />
<result column="costMiddleTypeCode" property="costTypeCode" jdbcType="VARCHAR" />
<result column="costMiddleTypeName" property="costTypeName" jdbcType="VARCHAR" />
<result column="middleTypeLevel" property="costTypeLevel" jdbcType="VARCHAR" />
<collection property="children" ofType="com.model.FeeType">
<result column="smallId" property="id" jdbcType="VARCHAR" />
<result column="costTypeCode" property="costTypeCode" jdbcType="VARCHAR" />
<result column="costTypeName" property="costTypeName" jdbcType="VARCHAR" />
<result column="smallTypeLevel" property="costTypeLevel" jdbcType="VARCHAR" />
</collection>
</collection>
</resultMap>
对应的实体类
public class FeeType {
private String id;
/**
* 费用类型编号
*/
private String costTypeCode;
/**
* 费用类型名称
*/
private String costTypeName;
/**
* 费用类型级别
*/
private String costTypeLevel;
/**
* 父费用类型编号
*/
private String parentCostCode;
/**
* 是否有效
*/
private String effectived;
List<FeeType> children;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCostTypeCode() {
return costTypeCode;
}
public void setCostTypeCode(String costTypeCode) {
this.costTypeCode = costTypeCode;
}
public String getCostTypeName() {
return costTypeName;
}
public void setCostTypeName(String costTypeName) {
this.costTypeName = costTypeName;
}
public String getCostTypeLevel() {
return costTypeLevel;
}
public void setCostTypeLevel(String costTypeLevel) {
this.costTypeLevel = costTypeLevel;
}
public String getParentCostCode() {
return parentCostCode;
}
public void setParentCostCode(String parentCostCode) {
this.parentCostCode = parentCostCode;
}
public String getEffectived() {
return effectived;
}
public void setEffectived(String effectived) {
this.effectived = effectived;
}
public List<FeeType> getChildren() {
return children;
}
public void setChildren(List<FeeType> children) {
this.children = children;
}
}
查询层级效果