worktile/docs/database/oa_update.sql
2021-05-08 19:58:22 +08:00

46 lines
978 B
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 0. 注意修改所有关联的表编码统一,不统一的话查询不会走索引
-- 1. 任务用户关联表添加项目id作为key提高查询效率
alter table project_task_user add key `key_projectid` (`_project_id`);
-- 2. 查询函数
-- ----------------------------
-- Function structure for `queryUserIdsByDeptId`
-- 根据部门ID递归查询所有子部门ID,返回结果包含当前查询的部门id
-- ----------------------------
DROP FUNCTION IF EXISTS queryDeptIdsByDeptId;
DELIMITER ;;
CREATE FUNCTION queryDeptIdsByDeptId(deptId VARCHAR(50))
RETURNS VARCHAR(500)
BEGIN
DECLARE sTemp VARCHAR(500);
DECLARE sTempChd VARCHAR(200);
SET sTemp='';
SET sTempChd = deptId;
WHILE sTempChd IS NOT NULL DO
IF sTemp='' THEN SET sTemp = sTempChd;
ELSE SET sTemp = CONCAT(sTemp,',',sTempChd);
END IF;
SELECT GROUP_CONCAT(Id) INTO sTempChd FROM qywx_party WHERE FIND_IN_SET(ParentId, sTempChd)>0;
END WHILE;
RETURN sTemp;
END
;;
DELIMITER ;