1.service中
2.dao中
3.mapper.xml
4.数据库
DELIMITER $$
USE `maventest`$$
DROP FUNCTION IF EXISTS `getOrganizationChildList`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `getOrganizationChildList`(rootId VARCHAR(4000)) RETURNS VARCHAR(4000) CHARSET utf8
BEGIN
DECLARE sTemp VARCHAR(4000);
DECLARE sTempChd VARCHAR(4000);
SET sTempChd = rootId;
WHILE sTempChd IS NOT NULL DO
IF(sTemp IS NOT NULL) THEN
SET sTemp = CONCAT(sTemp,',',sTempChd);
ELSE
SET sTemp = CONCAT(sTempChd);
END IF;
SELECT GROUP_CONCAT(id) INTO sTempChd FROM t_organization WHERE FIND_IN_SET(pid,sTempChd)>0;
END WHILE;
RETURN sTemp;
END$$
DELIMITER ;