Provided herein are a dihydropyrimidine compound and a pharmaceutical application thereof, especially the application used for treating and preventing HBV diseases. Specifically, provided herein is a compound having Formula (I) or (Ia), or an enantiomer, a diastereoisomer, a tautomer, a hydrate, a solvate, or a pharmaceutically acceptable salt thereof, wherein the variables of the formulas are as defined in the specification. Also provided herein is use of the compound having Formula (I) or (Ia), or an enantiomer, a diastereoisomer, a tautomer, a hydrate, a solvate, or a pharmaceutically acceptable salt thereof as a medicine, especially for treating and preventing HBV diseases.