A compound represented by formula or a pharmaceutically acceptable salt thereof, wherein, G is selected from ring A is selected from C 3-10 cycloalkyl, 3- to 10-membered heterocycloalkyl, C 6-10 aryl and 5- to 10-membered heteroaryl; R 1 is each independently selected from halogen, OR 11, CN, CH 3 S m -, -NH(R 12), C 1-3 alkyl and C 1-3 haloalkyl; R 11 is selected from H, C 1-3 alkyl, C 1-3 haloalkyl, CH 3 (OCH 2 CH 2) p - and H(OCH 2 CH 2) q -; R 12 is selected from C 1-3 alkyl, C 1-3 haloalkyl, CH 3 CO- and CH 3 SO 2 -; m is selected from 0, 1 and 2; p and q are selected from 1, 2, 3, 4, 5 and 6; n is selected from 0, 1, 2, 3 and 4; X is selected from -CH(R 3)- and -CH 2 CH 2 -, and the -CH 2 CH 2 - is optionally substituted by 1, 2, 3 or 4 R; R is each independently selected from halogen, OH, NH 2, CN, C 1-3 alkyl and C 1-3 haloalkyl; R 3 is each independently selected from H, C 1-3 alkyl, C 1-3 alkoxy, C 1-3 haloalkyl, C 1-3 haloalkoxy, C 6-10 aryl and 5- to 10-membered heteroaryl, and the C 6-10 aryl and 5- to 10-membered heteroaryl are optionally substituted by 1, 2 or 3 R 31; R 2 and R 4 together with the atoms to which they are attached form C 5-8 cycloalkyl, and the C 5-8 cycloalkyl is optionally and independently substituted by 1 or 2 R a; R a is each independently selected from H, halogen, C 1-3 alkyl, C 1-3 alkoxy, C 1-3 haloalkoxy, C 3-6 cycloalkyl, C 6-10 aryl and 5- to 10-membered heteroaryl, and the C 3-6 cycloalkyl, C 6-10 aryl and 5- to 10-membered heteroaryl are optionally substituted by 1, 2 or 3 R 41; R 31 and R 41 are each independently selected from halogen, OH, NH 2, CN, C 1-3 alkyl, C 1-3 alkoxy, C 1-3 haloalkyl and C 1-3 haloalkoxy; R 5 is selected from C 1-3 alkyl, C 1-3 haloalkyl, C 1-3 alkoxy, C 1-3 haloalkoxy, -CH 2 -R 6 and -CH 2 -O-R 6; R 6 is selected from phenyl, and the phenyl is optionally substituted by 1, 2 or 3 R 61; R 61 is selected from halogen, C 1-3 alkyl, C 1-3 haloalkyl, C 1-3 alkoxy and C 1-3 haloalkoxy. G is selected from ring A is selected from C 3-10 cycloalkyl, 3- to 10-membered heterocycloalkyl, C 6-10 aryl and 5- to 10-membered heteroaryl; R 1 is each independently selected from halogen, OR 11, CN, CH 3 S m -, -NH(R 12), C 1-3 alkyl and C 1-3 haloalkyl; R 11 is selected from H, C 1-3 alkyl, C 1-3 haloalkyl, CH 3 (OCH 2 CH 2) p - and H(OCH 2 CH 2) q -; R 12 is selected from C 1-3 alkyl, C 1-3 haloalkyl, CH 3 CO- and CH 3 SO 2 -; m is selected from 0, 1 and 2; p and q are selected from 1, 2, 3, 4, 5 and 6; n is selected from 0, 1, 2, 3 and 4; X is selected from -CH(R 3)- and -CH 2 CH 2 -, and the -CH 2 CH 2 - is optionally substituted by 1, 2, 3 or 4 R; R is each independently selected from halogen, OH, NH 2, CN, C 1-3 alkyl and C 1-3 haloalkyl; R 3 is each independently selected from H, C 1-3 alkyl, C 1-3 alkoxy, C 1-3 haloalkyl, C 1-3 haloalkoxy, C 6-10 aryl and 5- to 10-membered heteroaryl, and the C 6-10 aryl and 5- to 10-membered heteroaryl are optionally substituted by 1, 2 or 3 R 31; R 2 and R 4 together with the atoms to which they are attached form C 5-8 cycloalkyl, and the C 5-8 cycloalkyl is optionally and independently substituted by 1 or 2 R a; R a is each independently selected from H, halogen, C 1-3 alkyl, C 1-3 alkoxy, C 1-3 haloalkoxy, C 3-6 cycloalkyl, C 6-10 aryl and 5- to 10-membered heteroaryl, and the C 3-6 cycloalkyl, C 6-10 aryl and 5- to 10-membered heteroaryl are optionally substituted by 1, 2 or 3 R 41; R 31 and R 41 are each independently selected from halogen, OH, NH 2, CN, C 1-3 alkyl, C 1-3 alkoxy, C 1-3 haloalkyl and C 1-3 haloalkoxy; R 5 is selected from C 1-3 alkyl, C 1-3 haloalkyl, C 1-3 alkoxy, C 1-3 haloalkoxy, -CH 2 -R 6 and -CH 2 -O-R 6; R 6 is selected from phenyl, and the phenyl is optionally substituted by 1, 2 or 3 R 61; R 61 is selected from halogen, C 1-3 alkyl, C 1-3 haloalkyl, C 1-3 alkoxy and C 1-3 haloalkoxy.