function formatMenuData(data, parentId = null) {
	return data
		.filter((item) => item.parentId == parentId)
		.map((item) => ({
			...item,
			children: formatMenuData(data, item.menuId),
		}));
}

function main() {
	// 验证用户权限
	'use api/user/acl/excerpt.js'

	const result = SQL.query(DB_NAME, `SELECT menu_id,menu_name,parent_id FROM sys_menus WHERE delete_time IS NULL ORDER BY sort ASC`);
	// 格式化数据
	const newResult = result.map((itemO) => {
		const newObj = {};
		Object.keys(itemO).forEach((item) => {
			newObj[underscoreToCamel(item)] = itemO[item];
		});
		return {
			...newObj,
			parentId: newObj.parentId == 0 ? null : newObj.parentId
		};
	});
	const formatRes = formatMenuData(newResult);
	return okMsg(formatRes);
}
