The present invention provides a nitrogen heteroaryl derivative having CSF1R inhibitory activity, and a preparation method therefor and an application thereof. Compounds in the present invention has a structure represented by formula (I) as below, and the definition on substituents is as stated in the description and the claims. The compounds in the present invention can be widely applied to preparation of drugs for treating cancer, tumor, autoimmune disease, metabolic disease, or metastatic disease, in particular ovarian cancer, pancreatic cancer, prostate cancer, breast cancer, cervical cancer, glioblastoma, multiple myeloma, metabolic disease, neurodegenerative disease, metastasis of primary tumor sites, or osseous metastatic cancer, and a new generation of CSF1R inhibitor drugs is expected to be developed.