It means that there are many beautiful women in the emperor's harem, but he only dotes on one of them. The "three thousand" here is an approximate number, which means a lot.
This poem means that there are countless beauties in the harem of Emperor Xuanzong of the Tang Dynasty, but Yang Guifei is the only one who dotes on her.
It's from Song of Eternal Sorrow by Bai Juyi, a poet in the Tang Dynasty. Song of Eternal Sorrow is a long narrative poem by Bai Juyi, a poet in the Tang Dynasty. The whole poem vividly describes the love tragedy between Xuanzong of Tang Dynasty and Yang Guifei. With the help of historical figures and legends, the poet created a moving story, and through the artistic image he created, he reappeared the truth of real life, infecting readers for thousands of years. The theme of the poem was "long hatred". This poem had a far-reaching influence on many literary works in later generations.
Extended information:
In the first year of Yuanhe, Tang Xianzong (86), Bai Juyi was appointed as a county marshal (now zhouzhi county, Xi 'an). One day, I visited Xianyou Temple near Mayiyi with my friends Chen Hong and Wang Zhifu, and talked about Li Longji and Yang Guifei. Wang Zhifu believes that outstanding things like this will disappear with the passage of time if they are not polished. He encouraged Bai Juyi: "Lotte is deeper than poetry, and more than love. How about trying to be a song?" So Bai Juyi wrote this long poem.
Because the last two sentences of the long poem are "earth endures, heaven endures; some time both shall end, while this unending sorrow goes on and on for ever", they call this poem "Song of Eternal Sorrow". At the same time, Chen Hong wrote a legendary novel "The Song of Eternal Sorrow".
In this long narrative poem, the author narrates the love tragedy of Tang Xuanzong and Yang Guifei in the Anshi Rebellion with refined language, beautiful image, narrative and lyric: their love was ruined by their own rebellion and they are endlessly eating the bitter fruit of this spirit.
Tang Xuanzong and Yang Guifei are both figures in history. Poets don't stick to history, but rely on a little shadow of history. According to people's legends at that time, the singing of the neighborhood degenerated into a tortuous and moving story, which was described and sung in a roundabout and touching art form. Because the stories and characters in the poems are artistic, and they are the complex and true reappearance of people in reality, they can ripple in the hearts of readers in past dynasties.
Reference: Baidu Encyclopedia-Song of Eternal Sorrow