The present invention discloses a nitrogen-containing fused heterocyclic compound, as well as a preparation method, intermediate, composition and application thereof. The nitrogen-containing fused heterocyclic compound of the present invention as represented by formula (I), as well as the pharmaceutically acceptable salt, enantiomer, diastereomer, tautomer, solvate, metabolite or drug precursor thereof, exhibit a high selectivity and a high inhibitory activity with respect to CDK4 and CDK6 at a molecular level, an excellent inhibitory activity with respect to breast cancer cells at a cellular level, and significant inhibition of tumor cell proliferation associated with cyclin-dependent kinase activity at an animal level. The invention also exhibits a good stability with respect to human or mouse liver microsomes without significant inhibition of metabolic enzymes, good in vivo absorption in mice and rats, a high bioavailability and good druggability.